AliRoot Core  v5-06-30 (35d6c57)
 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 {
366  return WriteMpData(0,AliCDBRunRange::Infinity());
367 }
368 
369 //______________________________________________________________________________
371 {
372  return WriteMpRunData(0,AliCDBRunRange::Infinity());
373 }
374 
375 //______________________________________________________________________________
376 Bool_t AliMpCDB::WriteMpData(Int_t startRun, Int_t endRun)
377 {
379 
380  AliCDBManager* cdbManager = AliCDBManager::Instance();
381  if ( ! cdbManager->GetDefaultStorage() )
382  cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
383 
384  AliCDBMetaData* cdbData = new AliCDBMetaData();
385  cdbData->SetResponsible("Dimuon Offline project");
386  cdbData->SetComment("MUON mapping");
387  cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
388  AliCDBId id("MUON/Calib/MappingData", startRun, endRun);
389 
391  AliMpDataMap* map = mp.CreateDataMap("data");
392  return cdbManager->Put(map, id, cdbData);
393 }
394 
395 //______________________________________________________________________________
396 Bool_t AliMpCDB::WriteMpRunData(Int_t startRun, Int_t endRun)
397 {
399 
400  AliCDBManager* cdbManager = AliCDBManager::Instance();
401  if ( ! cdbManager->GetDefaultStorage() )
402  cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
403 
404  AliCDBMetaData* cdbData = new AliCDBMetaData();
405  cdbData->SetResponsible("Dimuon Offline project");
406  cdbData->SetComment("MUON run-dependent mapping");
407  cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
408  AliCDBId id("MUON/Calib/MappingRunData", startRun, endRun);
409 
411  AliMpDataMap* map = mp.CreateDataMap("data_run");
412  return cdbManager->Put(map, id, cdbData);
413 }
414 
415 //______________________________________________________________________________
416 Bool_t AliMpCDB::WriteMpSegmentation(Bool_t readData)
417 {
419 
420  if ( ! readData && ! AliMpSegmentation::Instance() ) return false;
421 
422  AliCDBManager* cdbManager = AliCDBManager::Instance();
423  if ( ! cdbManager->GetDefaultStorage() )
424  cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
425 
426  AliCDBMetaData* cdbData = new AliCDBMetaData();
427  cdbData->SetResponsible("Dimuon Offline project");
428  cdbData->SetComment("MUON mapping");
429  cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
430  AliCDBId id("MUON/Calib/Mapping", 0, AliCDBRunRange::Infinity());
431 
432  if ( readData ) {
433  AliMpDataStreams dataStreams;
434  AliMpSegmentation::ReadData(dataStreams, false);
435  AliMpDDLStore::ReadData(dataStreams, false);
436  }
437 
438  return cdbManager->Put(AliMpSegmentation::Instance(), id, cdbData);
439 }
440 
441 //______________________________________________________________________________
442 Bool_t AliMpCDB::WriteDDLStore(Bool_t readData)
443 {
445 
446  if ( ! readData && ! AliMpDDLStore::Instance() ) return false;
447 
448  AliCDBManager* cdbManager = AliCDBManager::Instance();
449  if ( ! cdbManager->GetDefaultStorage() )
450  cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
451 
452  AliCDBMetaData* cdbData = new AliCDBMetaData();
453  cdbData->SetResponsible("Dimuon Offline project");
454  cdbData->SetComment("MUON DDL store");
455  cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
456  AliCDBId id("MUON/Calib/DDLStore", 0, AliCDBRunRange::Infinity());
457 
458  if ( readData ) {
459  AliMpDataStreams dataStreams;
460  AliMpSegmentation::ReadData(dataStreams, false);
461  AliMpDDLStore::ReadData(dataStreams, false);
462  }
463  return cdbManager->Put(AliMpDDLStore::Instance(), id, cdbData);
464 }
465 
466 //______________________________________________________________________________
467 Bool_t AliMpCDB::WriteManuStore(Bool_t readData)
468 {
470 
471  if ( ! readData && ! AliMpManuStore::Instance() ) return false;
472 
473  AliCDBManager* cdbManager = AliCDBManager::Instance();
474  if ( ! cdbManager->GetDefaultStorage() )
475  cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
476 
477  AliCDBMetaData* cdbData = new AliCDBMetaData();
478  cdbData->SetResponsible("Dimuon Offline project");
479  cdbData->SetComment("MUON Manu store");
480  cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
481  AliCDBId id("MUON/Calib/ManuStore", 0, AliCDBRunRange::Infinity());
482 
483  if ( readData ) {
484  AliMpDataStreams dataStreams;
485  AliMpSegmentation::ReadData(dataStreams, false);
486  AliMpManuStore::ReadData(dataStreams, false);
487  }
488  return cdbManager->Put(AliMpManuStore::Instance(), id, cdbData);
489 }
490 
491 //______________________________________________________________________________
492 Bool_t AliMpCDB::GenerateMpData(const char* cdbpath, Int_t runNumber)
493 {
495 
496  TObject* cdbEntryObject
497  = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
498  if ( ! cdbEntryObject ) return kFALSE;
499 
500  AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
502  return mp.GenerateData(dataMap);
503 }
504 
505 //______________________________________________________________________________
506 Bool_t AliMpCDB::GenerateMpRunData(const char* cdbpath, Int_t runNumber)
507 {
509 
510  TObject* cdbEntryObject
511  = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
512  if ( ! cdbEntryObject ) return kFALSE;
513 
514  AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
516  return mp.GenerateData(dataMap);
517 }
518 
519 //______________________________________________________________________________
521 {
523  delete AliMpDDLStore::Instance(false);
524  delete AliMpSegmentation::Instance(false);
525  delete AliMpDEStore::Instance(false);
526  delete AliMpManuStore::Instance(false);
527 }
528 
static Bool_t WriteMpSegmentation(Bool_t readData=true)
Definition: AliMpCDB.cxx:416
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:100
AliMpDataMap * CreateDataMap(const TString &dataDir="data")
static AliMpSegmentation * ReadData(const AliMpDataStreams &dataStreams, Bool_t warn=true)
static Bool_t WriteMpRunData()
Definition: AliMpCDB.cxx:370
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:467
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
static Bool_t GenerateMpData(const char *cdbpath="local://$ALICE_ROOT/OCDB", Int_t runNumber=0)
Definition: AliMpCDB.cxx:492
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:442
static void UnloadAll()
Definition: AliMpCDB.cxx:520
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:506
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.