AliRoot Core  v5-06-15 (45dab64)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMpCDB.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: The ALICE Off-line Project. *
5  * Contributors are mentioned in the code where appropriate. *
6  * *
7  * Permission to use, copy, modify and distribute this software and its *
8  * documentation strictly for non-commercial purposes is hereby granted *
9  * without fee, provided that the above copyright notice appears in all *
10  * copies and that both the copyright notice and this permission notice *
11  * appear in the supporting documentation. The authors make no claims *
12  * about the suitability of this software for any purpose. It is *
13  * provided "as is" without express or implied warranty. *
14  **************************************************************************/
15 
16 // $Id$
17 // $MpId: $
18 // Category: management
19 
20 //-----------------------------------------------------------------------------
21 // Class AliMpCDB
22 // -----------------------
23 // Manager class for mapping CDB IO
24 // Author: Ivana Hrivnacova, IPN Orsay
25 //-----------------------------------------------------------------------------
26 
27 #include "AliMpCDB.h"
28 
29 #include "AliCDBEntry.h"
30 #include "AliCDBManager.h"
31 #include "AliLog.h"
32 #include "AliMpDDLStore.h"
33 #include "AliMpDEStore.h"
34 #include "AliMpDataMap.h"
35 #include "AliMpDataProcessor.h"
36 #include "AliMpDataStreams.h"
37 #include "AliMpManuStore.h"
38 #include "AliMpSegmentation.h"
39 #include <Riostream.h>
40 #include <TClass.h>
41 #include <TSystem.h>
42 
46 
47 Bool_t AliMpCDB::fgLoadFromData = kTRUE;
48 
49 //
50 // private static methods
51 //
52 
53 //______________________________________________________________________________
54 TObject* AliMpCDB::GetCDBEntryObject(const char* dataPath)
55 {
57 
58  AliCDBManager* cdbManager = AliCDBManager::Instance();
59 
60  Int_t run = cdbManager->GetRun();
61  if ( run < 0 ) {
62  AliErrorClassStream() << "Cannot get run number from CDB manager." << endl;
63  return 0;
64  }
65 
66  AliCDBEntry* cdbEntry = cdbManager->Get(dataPath, run);
67  if ( ! cdbEntry ) {
68  AliErrorClassStream() << "Cannot get cdbEntry." << endl;
69  return 0;
70  }
71 
72  TObject* object = cdbEntry->GetObject();
73  if ( ! object ) {
74  AliErrorClassStream() << "Cannot get object from cdbEntry." << endl;
75  return 0;
76  }
77 
78  return object;
79 }
80 
81 
82 //______________________________________________________________________________
83 TObject* AliMpCDB::GetCDBEntryObject(const char* dataPath,
84  const char* cdbpath,
85  Int_t runNumber )
86 {
88 
89  AliCDBManager* cdbManager = AliCDBManager::Instance();
90  cdbManager->SetDefaultStorage(cdbpath);
91 
92  AliCDBEntry* cdbEntry = cdbManager->Get(dataPath, runNumber);
93  if ( ! cdbEntry ) {
94  AliErrorClassStream() << "Cannot get cdbEntry." << endl;
95  return 0;
96  }
97 
98  TObject* object = cdbEntry->GetObject();
99  if ( ! object ) {
100  AliErrorClassStream() << "Cannot get object from cdbEntry." << endl;
101  return 0;
102  }
103 
104  return object;
105 }
106 
107 //
108 // public static methods
109 //
110 
111 
112 //______________________________________________________________________________
113 Bool_t AliMpCDB::LoadMpSegmentation(Bool_t warn)
114 {
118 
119  if ( AliMpSegmentation::Instance(false) ) {
120  if ( warn )
121  AliWarningClass("Segmentation has been already loaded.");
122  return true;
123  }
124 
125  if ( fgLoadFromData ) {
126  AliDebugClassStream(1)
127  << "Loading segmentation from MUON/Calib/MappingData" << endl;
128 
129  TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingData");
130  if ( ! cdbEntryObject ) return kFALSE;
131 
132  // Pass the map to the streams and then read segmentation
133  // from data map
134  AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
135  AliMpDataStreams dataStreams(dataMap);
136  AliMpSegmentation::ReadData(dataStreams);
137  return kTRUE;
138  }
139  else {
140  AliDebugClassStream(1)
141  << "Loading segmentation from MUON/Calib/Mapping" << endl;
142 
143  TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/Mapping");
144  return cdbEntryObject != 0x0;
145  }
146 }
147 
148 //______________________________________________________________________________
149 Bool_t AliMpCDB::LoadDDLStore(Bool_t warn)
150 {
154 
155  if ( AliMpDDLStore::Instance(false) ) {
156  if ( warn )
157  AliWarningClass("DDL Store has been already loaded.");
158  return true;
159  }
160 
161  if ( fgLoadFromData ) {
162  AliDebugClassStream(1)
163  << "Loading DDL store from MUON/Calib/MappingData" << endl;
164 
165  TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingData");
166  if ( ! cdbEntryObject ) return kFALSE;
167 
168  AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
169  AliMpDataStreams dataStreams(dataMap);
170  AliMpDDLStore::ReadData(dataStreams);
171  return kTRUE;
172  }
173  else {
174  AliDebugClassStream(1)
175  << "Loading DDL store from MUON/Calib/DDLStore" << endl;
176 
177  // Load segmentation
178  LoadMpSegmentation(warn);
179 
180  // Load DDL store
181  TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/DDLStore");
182  return cdbEntryObject != 0x0;
183  }
184 }
185 
186 //______________________________________________________________________________
187 Bool_t AliMpCDB::LoadAll2(const char* cdbpath, Int_t runNumber, Bool_t warn)
188 {
190  return
191  LoadDDLStore2(cdbpath,runNumber,warn) &&
192  LoadManuStore2(cdbpath,runNumber,warn);
193 }
194 
195 //______________________________________________________________________________
196 Bool_t AliMpCDB::LoadAll(Bool_t warn)
197 {
199  return LoadDDLStore(warn) && LoadManuStore(warn);
200 }
201 
202 //______________________________________________________________________________
203 Bool_t AliMpCDB::LoadManuStore(Bool_t warn)
204 {
208 
209  if ( AliMpManuStore::Instance(false) ) {
210  if ( warn )
211  AliWarningClass("Manu Store has been already loaded.");
212  return true;
213  }
214 
215  if ( fgLoadFromData ) {
216  AliDebugClassStream(1)
217  << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
218 
219  // Load segmentation
220  if ( ! AliMpSegmentation::Instance(false) )
221  LoadMpSegmentation(warn);
222 
223  TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingRunData");
224  if ( ! cdbEntryObject ) return kFALSE;
225 
226  AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
227  AliMpDataStreams dataStreams(dataMap);
228  AliMpManuStore::ReadData(dataStreams);
229  return kTRUE;
230  }
231  else {
232  AliDebugClassStream(1)
233  << "Loading Manu store from MUON/Calib/ManuStore" << endl;
234 
235  // Load Manu store
236  TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/ManuStore");
237  return cdbEntryObject != 0x0;
238  }
239 }
240 //______________________________________________________________________________
241 Bool_t AliMpCDB::LoadMpSegmentation2(const char* cdbpath, Int_t runNumber,
242  Bool_t warn)
243 {
248 
249 
250  if ( AliMpSegmentation::Instance(false) ) {
251  if ( warn )
252  AliWarningClass("Segmentation has been already loaded.");
253  return true;
254  }
255 
256  if ( fgLoadFromData ) {
257  AliDebugClassStream(1)
258  << "Loading segmentation from MUON/Calib/MappingData" << endl;
259 
260  TObject* cdbEntryObject
261  = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
262  if ( ! cdbEntryObject ) return kFALSE;
263 
264  // Pass the map to the streams and then read segmentation
265  // from data map
266  AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
267  AliMpDataStreams dataStreams(dataMap);
268  AliMpSegmentation::ReadData(dataStreams);
269  return kTRUE;
270  }
271  else {
272  AliDebugClassStream(1)
273  << "Loading segmentation from MUON/Calib/Mapping" << endl;
274 
275  TObject* cdbEntryObject
276  = GetCDBEntryObject("MUON/Calib/Mapping", cdbpath, runNumber);
277  return cdbEntryObject != 0x0;
278  }
279 }
280 
281 //______________________________________________________________________________
282 Bool_t AliMpCDB::LoadDDLStore2(const char* cdbpath, Int_t runNumber,
283  Bool_t warn)
284 {
289 
290  if ( AliMpDDLStore::Instance(false) ) {
291  if ( warn )
292  AliWarningClass("DDL Store has been already loaded.");
293  return true;
294  }
295 
296  if ( fgLoadFromData ) {
297  AliDebugClassStream(1)
298  << "Loading DDL store from MUON/Calib/MappingData" << endl;
299 
300  TObject* cdbEntryObject
301  = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
302  if ( ! cdbEntryObject ) return kFALSE;
303 
304  AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
305  AliMpDataStreams dataStreams(dataMap);
306  AliMpDDLStore::ReadData(dataStreams);
307  return kTRUE;
308  }
309  else {
310  AliDebugClassStream(1)
311  << "Loading DDL store from MUON/Calib/DDLStore" << endl;
312 
313  // Load segmentation
314  LoadMpSegmentation2(cdbpath, runNumber, warn);
315 
316  // Load DDL store
317  TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/DDLStore");
318  return cdbEntryObject != 0x0;
319  }
320 }
321 
322 //______________________________________________________________________________
323 Bool_t AliMpCDB::LoadManuStore2(const char* cdbpath, Int_t runNumber,
324  Bool_t warn)
325 {
330 
331  if ( AliMpManuStore::Instance(false) ) {
332  if ( warn )
333  AliWarningClass("Manu Store has been already loaded.");
334  return true;
335  }
336 
337  if ( fgLoadFromData ) {
338  AliDebugClassStream(1)
339  << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
340 
341  // Load segmentation
342  LoadMpSegmentation2(cdbpath, runNumber, warn);
343 
344  TObject* cdbEntryObject
345  = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
346  if ( ! cdbEntryObject ) return kFALSE;
347 
348  AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
349  AliMpDataStreams dataStreams(dataMap);
350  AliMpManuStore::ReadData(dataStreams);
351  return kTRUE;
352  }
353  else {
354  AliDebugClassStream(1)
355  << "Loading Manu store from MUON/Calib/ManuStore" << endl;
356 
357  // Load Manu store
358  TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/ManuStore");
359  return cdbEntryObject != 0x0;
360  }
361 }
362 
363 //______________________________________________________________________________
365 {
367 
368  AliCDBManager* cdbManager = AliCDBManager::Instance();
369  if ( ! cdbManager->GetDefaultStorage() )
370  cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
371 
372  AliCDBMetaData* cdbData = new AliCDBMetaData();
373  cdbData->SetResponsible("Dimuon Offline project");
374  cdbData->SetComment("MUON mapping");
375  cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
376  AliCDBId id("MUON/Calib/MappingData", 0, AliCDBRunRange::Infinity());
377 
379  AliMpDataMap* map = mp.CreateDataMap("data");
380  return cdbManager->Put(map, id, cdbData);
381 }
382 
383 //______________________________________________________________________________
385 {
387 
388  AliCDBManager* cdbManager = AliCDBManager::Instance();
389  if ( ! cdbManager->GetDefaultStorage() )
390  cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
391 
392  AliCDBMetaData* cdbData = new AliCDBMetaData();
393  cdbData->SetResponsible("Dimuon Offline project");
394  cdbData->SetComment("MUON run-dependent mapping");
395  cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
396  AliCDBId id("MUON/Calib/MappingRunData", 0, AliCDBRunRange::Infinity());
397 
399  AliMpDataMap* map = mp.CreateDataMap("data_run");
400  return cdbManager->Put(map, id, cdbData);
401 }
402 
403 //______________________________________________________________________________
404 Bool_t AliMpCDB::WriteMpSegmentation(Bool_t readData)
405 {
407 
408  if ( ! readData && ! AliMpSegmentation::Instance() ) return false;
409 
410  AliCDBManager* cdbManager = AliCDBManager::Instance();
411  if ( ! cdbManager->GetDefaultStorage() )
412  cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
413 
414  AliCDBMetaData* cdbData = new AliCDBMetaData();
415  cdbData->SetResponsible("Dimuon Offline project");
416  cdbData->SetComment("MUON mapping");
417  cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
418  AliCDBId id("MUON/Calib/Mapping", 0, AliCDBRunRange::Infinity());
419 
420  if ( readData ) {
421  AliMpDataStreams dataStreams;
422  AliMpSegmentation::ReadData(dataStreams, false);
423  AliMpDDLStore::ReadData(dataStreams, false);
424  }
425 
426  return cdbManager->Put(AliMpSegmentation::Instance(), id, cdbData);
427 }
428 
429 //______________________________________________________________________________
430 Bool_t AliMpCDB::WriteDDLStore(Bool_t readData)
431 {
433 
434  if ( ! readData && ! AliMpDDLStore::Instance() ) return false;
435 
436  AliCDBManager* cdbManager = AliCDBManager::Instance();
437  if ( ! cdbManager->GetDefaultStorage() )
438  cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
439 
440  AliCDBMetaData* cdbData = new AliCDBMetaData();
441  cdbData->SetResponsible("Dimuon Offline project");
442  cdbData->SetComment("MUON DDL store");
443  cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
444  AliCDBId id("MUON/Calib/DDLStore", 0, AliCDBRunRange::Infinity());
445 
446  if ( readData ) {
447  AliMpDataStreams dataStreams;
448  AliMpSegmentation::ReadData(dataStreams, false);
449  AliMpDDLStore::ReadData(dataStreams, false);
450  }
451  return cdbManager->Put(AliMpDDLStore::Instance(), id, cdbData);
452 }
453 
454 //______________________________________________________________________________
455 Bool_t AliMpCDB::WriteManuStore(Bool_t readData)
456 {
458 
459  if ( ! readData && ! AliMpManuStore::Instance() ) return false;
460 
461  AliCDBManager* cdbManager = AliCDBManager::Instance();
462  if ( ! cdbManager->GetDefaultStorage() )
463  cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
464 
465  AliCDBMetaData* cdbData = new AliCDBMetaData();
466  cdbData->SetResponsible("Dimuon Offline project");
467  cdbData->SetComment("MUON Manu store");
468  cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
469  AliCDBId id("MUON/Calib/ManuStore", 0, AliCDBRunRange::Infinity());
470 
471  if ( readData ) {
472  AliMpDataStreams dataStreams;
473  AliMpSegmentation::ReadData(dataStreams, false);
474  AliMpManuStore::ReadData(dataStreams, false);
475  }
476  return cdbManager->Put(AliMpManuStore::Instance(), id, cdbData);
477 }
478 
479 //______________________________________________________________________________
480 Bool_t AliMpCDB::GenerateMpData(const char* cdbpath, Int_t runNumber)
481 {
483 
484  TObject* cdbEntryObject
485  = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
486  if ( ! cdbEntryObject ) return kFALSE;
487 
488  AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
490  return mp.GenerateData(dataMap);
491 }
492 
493 //______________________________________________________________________________
494 Bool_t AliMpCDB::GenerateMpRunData(const char* cdbpath, Int_t runNumber)
495 {
497 
498  TObject* cdbEntryObject
499  = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
500  if ( ! cdbEntryObject ) return kFALSE;
501 
502  AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
504  return mp.GenerateData(dataMap);
505 }
506 
507 //______________________________________________________________________________
509 {
511  delete AliMpDDLStore::Instance(false);
512  delete AliMpSegmentation::Instance(false);
513  delete AliMpDEStore::Instance(false);
514  delete AliMpManuStore::Instance(false);
515 }
516 
static Bool_t WriteMpSegmentation(Bool_t readData=true)
Definition: AliMpCDB.cxx:404
static AliMpManuStore * ReadData(const AliMpDataStreams &dataStreams, Bool_t warn=true)
static AliMpDEStore * Instance(Bool_t warn=true)
static Bool_t WriteMpData()
Definition: AliMpCDB.cxx:364
static AliMpSegmentation * Instance(Bool_t warn=true)
static Bool_t fgLoadFromData
option for loading from CDB mapping data or from CDB mapping objects
Definition: AliMpCDB.h:96
AliMpDataMap * CreateDataMap(const TString &dataDir="data")
static AliMpSegmentation * ReadData(const AliMpDataStreams &dataStreams, Bool_t warn=true)
static Bool_t WriteMpRunData()
Definition: AliMpCDB.cxx:384
static Bool_t LoadDDLStore(Bool_t warn=false)
Definition: AliMpCDB.cxx:149
static Bool_t LoadDDLStore2(const char *cdbpath="local://$ALICE_ROOT/OCDB", Int_t runNumber=0, Bool_t warn=false)
Definition: AliMpCDB.cxx:282
static AliMpManuStore * Instance(Bool_t warn=true)
static Bool_t LoadManuStore(Bool_t warn=false)
Definition: AliMpCDB.cxx:203
static Bool_t WriteManuStore(Bool_t readData=true)
Definition: AliMpCDB.cxx:455
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
static Bool_t GenerateMpData(const char *cdbpath="local://$ALICE_ROOT/OCDB", Int_t runNumber=0)
Definition: AliMpCDB.cxx:480
static AliMpDDLStore * Instance(Bool_t warn=true)
Manager class for mapping CDB IO.
Definition: AliMpCDB.h:35
TObject class containing a map of strings to strings.
Definition: AliMpDataMap.h:21
Class for converting ASCII data files in the map of string.
static AliMpDDLStore * ReadData(const AliMpDataStreams &dataStreams, Bool_t warn=true)
static Bool_t LoadManuStore2(const char *cdbpath="local://$ALICE_ROOT/OCDB", Int_t runNumber=0, Bool_t warn=false)
Definition: AliMpCDB.cxx:323
static TObject * GetCDBEntryObject(const char *dataPath)
Definition: AliMpCDB.cxx:54
static Bool_t WriteDDLStore(Bool_t readData=true)
Definition: AliMpCDB.cxx:430
static void UnloadAll()
Definition: AliMpCDB.cxx:508
static Bool_t LoadMpSegmentation2(const char *cdbpath="local://$ALICE_ROOT/OCDB", Int_t runNumber=0, Bool_t warn=false)
Definition: AliMpCDB.cxx:241
static Bool_t LoadAll2(const char *cdbpath="local://$ALICE_ROOT/OCDB", Int_t runNumber=0, Bool_t warn=false)
Definition: AliMpCDB.cxx:187
Bool_t GenerateData(AliMpDataMap *dataMap, const TString &outputDataDir="data_new")
static Bool_t GenerateMpRunData(const char *cdbpath="local://$ALICE_ROOT/OCDB", Int_t runNumber=0)
Definition: AliMpCDB.cxx:494
static Bool_t LoadAll(Bool_t warn=false)
Definition: AliMpCDB.cxx:196
static Bool_t LoadMpSegmentation(Bool_t warn=false)
Definition: AliMpCDB.cxx:113
Mapping data streams provider.