1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 // Category: management
20 //-----------------------------------------------------------------------------
22 // -----------------------
23 // Manager class for mapping CDB IO
24 // Author: Ivana Hrivnacova, IPN Orsay
25 //-----------------------------------------------------------------------------
29 #include "AliCDBEntry.h"
30 #include "AliCDBManager.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>
47 Bool_t AliMpCDB::fgLoadFromData = kTRUE;
50 // private static methods
53 //______________________________________________________________________________
54 TObject* AliMpCDB::GetCDBEntryObject(const char* dataPath)
56 /// Load CDB entry object with checks
58 AliCDBManager* cdbManager = AliCDBManager::Instance();
60 Int_t run = cdbManager->GetRun();
62 AliErrorClassStream() << "Cannot get run number from CDB manager." << endl;
66 AliCDBEntry* cdbEntry = cdbManager->Get(dataPath, run);
68 AliErrorClassStream() << "Cannot get cdbEntry." << endl;
72 TObject* object = cdbEntry->GetObject();
74 AliErrorClassStream() << "Cannot get object from cdbEntry." << endl;
82 //______________________________________________________________________________
83 TObject* AliMpCDB::GetCDBEntryObject(const char* dataPath,
87 /// Load CDB entry from CDB and run specified in arguments
89 AliCDBManager* cdbManager = AliCDBManager::Instance();
90 cdbManager->SetDefaultStorage(cdbpath);
92 AliCDBEntry* cdbEntry = cdbManager->Get(dataPath, runNumber);
94 AliErrorClassStream() << "Cannot get cdbEntry." << endl;
98 TObject* object = cdbEntry->GetObject();
100 AliErrorClassStream() << "Cannot get object from cdbEntry." << endl;
108 // public static methods
112 //______________________________________________________________________________
113 Bool_t AliMpCDB::LoadMpSegmentation(Bool_t warn)
115 /// Load the sementation from the mapping data from OCDB,
116 /// if it does not yet exist;
117 /// return false only in case loading from CDB failed
119 if ( AliMpSegmentation::Instance(false) ) {
121 AliWarningClass("Segmentation has been already loaded.");
125 if ( fgLoadFromData ) {
126 AliDebugClassStream(1)
127 << "Loading segmentation from MUON/Calib/MappingData" << endl;
129 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingData");
130 if ( ! cdbEntryObject ) return kFALSE;
132 // Pass the map to the streams and then read segmentation
134 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
135 AliMpDataStreams dataStreams(dataMap);
136 AliMpSegmentation::ReadData(dataStreams);
140 AliDebugClassStream(1)
141 << "Loading segmentation from MUON/Calib/Mapping" << endl;
143 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/Mapping");
144 return cdbEntryObject != 0x0;
148 //______________________________________________________________________________
149 Bool_t AliMpCDB::LoadDDLStore(Bool_t warn)
151 /// Load the DDL store from the mapping data from OCDB,
152 /// if it does not yet exist;
153 /// return false only in case loading from CDB failed
155 if ( AliMpDDLStore::Instance(false) ) {
157 AliWarningClass("DDL Store has been already loaded.");
161 if ( fgLoadFromData ) {
162 AliDebugClassStream(1)
163 << "Loading DDL store from MUON/Calib/MappingData" << endl;
165 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingData");
166 if ( ! cdbEntryObject ) return kFALSE;
168 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
169 AliMpDataStreams dataStreams(dataMap);
170 AliMpDDLStore::ReadData(dataStreams);
174 AliDebugClassStream(1)
175 << "Loading DDL store from MUON/Calib/DDLStore" << endl;
178 LoadMpSegmentation(warn);
181 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/DDLStore");
182 return cdbEntryObject != 0x0;
186 //______________________________________________________________________________
187 Bool_t AliMpCDB::LoadAll2(const char* cdbpath, Int_t runNumber, Bool_t warn)
189 /// Load everything in one shot
191 LoadDDLStore2(cdbpath,runNumber,warn) &&
192 LoadManuStore2(cdbpath,runNumber,warn);
195 //______________________________________________________________________________
196 Bool_t AliMpCDB::LoadAll(Bool_t warn)
198 /// Load everything in one shot
199 return LoadDDLStore(warn) && LoadManuStore(warn);
202 //______________________________________________________________________________
203 Bool_t AliMpCDB::LoadManuStore(Bool_t warn)
205 /// Load the DDL store from the mapping data from OCDB,
206 /// if it does not yet exist;
207 /// return false only in case loading from CDB failed
209 if ( AliMpManuStore::Instance(false) ) {
211 AliWarningClass("Manu Store has been already loaded.");
215 if ( fgLoadFromData ) {
216 AliDebugClassStream(1)
217 << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
220 LoadMpSegmentation(warn);
222 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingRunData");
223 if ( ! cdbEntryObject ) return kFALSE;
225 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
226 AliMpDataStreams dataStreams(dataMap);
227 AliMpManuStore::ReadData(dataStreams);
231 AliDebugClassStream(1)
232 << "Loading Manu store from MUON/Calib/ManuStore" << endl;
235 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/ManuStore");
236 return cdbEntryObject != 0x0;
239 //______________________________________________________________________________
240 Bool_t AliMpCDB::LoadMpSegmentation2(const char* cdbpath, Int_t runNumber,
243 /// Load the sementation from the CDB if it does not yet exist;
244 /// return false only in case loading from CDB failed.
245 /// In difference from LoadMpSegmentation(), in this method the CDB path
246 /// and run is set directly via arguments.
249 if ( AliMpSegmentation::Instance(false) ) {
251 AliWarningClass("Segmentation has been already loaded.");
255 if ( fgLoadFromData ) {
256 AliDebugClassStream(1)
257 << "Loading segmentation from MUON/Calib/MappingData" << endl;
259 TObject* cdbEntryObject
260 = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
261 if ( ! cdbEntryObject ) return kFALSE;
263 // Pass the map to the streams and then read segmentation
265 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
266 AliMpDataStreams dataStreams(dataMap);
267 AliMpSegmentation::ReadData(dataStreams);
271 AliDebugClassStream(1)
272 << "Loading segmentation from MUON/Calib/Mapping" << endl;
274 TObject* cdbEntryObject
275 = GetCDBEntryObject("MUON/Calib/Mapping", cdbpath, runNumber);
276 return cdbEntryObject != 0x0;
280 //______________________________________________________________________________
281 Bool_t AliMpCDB::LoadDDLStore2(const char* cdbpath, Int_t runNumber,
284 /// Load the DDL store from the CDB if it does not yet exist
285 /// return false only in case loading from CDB failed
286 /// In difference from LoadDDLStore(), in this method the CDB path
287 /// and run is set directly via arguments.
289 if ( AliMpDDLStore::Instance(false) ) {
291 AliWarningClass("DDL Store has been already loaded.");
295 if ( fgLoadFromData ) {
296 AliDebugClassStream(1)
297 << "Loading DDL store from MUON/Calib/MappingData" << endl;
299 TObject* cdbEntryObject
300 = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
301 if ( ! cdbEntryObject ) return kFALSE;
303 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
304 AliMpDataStreams dataStreams(dataMap);
305 AliMpDDLStore::ReadData(dataStreams);
309 AliDebugClassStream(1)
310 << "Loading DDL store from MUON/Calib/DDLStore" << endl;
313 LoadMpSegmentation2(cdbpath, runNumber, warn);
316 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/DDLStore");
317 return cdbEntryObject != 0x0;
321 //______________________________________________________________________________
322 Bool_t AliMpCDB::LoadManuStore2(const char* cdbpath, Int_t runNumber,
325 /// Load the DDL store from the CDB if it does not yet exist
326 /// return false only in case loading from CDB failed
327 /// In difference from LoadDDLStore(), in this method the CDB path
328 /// and run is set directly via arguments.
330 if ( AliMpManuStore::Instance(false) ) {
332 AliWarningClass("Manu Store has been already loaded.");
336 if ( fgLoadFromData ) {
337 AliDebugClassStream(1)
338 << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
341 LoadMpSegmentation2(cdbpath, runNumber, warn);
343 TObject* cdbEntryObject
344 = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
345 if ( ! cdbEntryObject ) return kFALSE;
347 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
348 AliMpDataStreams dataStreams(dataMap);
349 AliMpManuStore::ReadData(dataStreams);
353 AliDebugClassStream(1)
354 << "Loading Manu store from MUON/Calib/ManuStore" << endl;
357 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/ManuStore");
358 return cdbEntryObject != 0x0;
362 //______________________________________________________________________________
363 Bool_t AliMpCDB::WriteMpData()
365 /// Write mapping data in OCDB
367 AliCDBManager* cdbManager = AliCDBManager::Instance();
368 if ( ! cdbManager->GetDefaultStorage() )
369 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
371 AliCDBMetaData* cdbData = new AliCDBMetaData();
372 cdbData->SetResponsible("Dimuon Offline project");
373 cdbData->SetComment("MUON mapping");
374 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
375 AliCDBId id("MUON/Calib/MappingData", 0, AliCDBRunRange::Infinity());
377 AliMpDataProcessor mp;
378 AliMpDataMap* map = mp.CreateDataMap("data");
379 return cdbManager->Put(map, id, cdbData);
382 //______________________________________________________________________________
383 Bool_t AliMpCDB::WriteMpRunData()
385 /// Write mapping data in OCDB
387 AliCDBManager* cdbManager = AliCDBManager::Instance();
388 if ( ! cdbManager->GetDefaultStorage() )
389 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
391 AliCDBMetaData* cdbData = new AliCDBMetaData();
392 cdbData->SetResponsible("Dimuon Offline project");
393 cdbData->SetComment("MUON run-dependent mapping");
394 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
395 AliCDBId id("MUON/Calib/MappingRunData", 0, AliCDBRunRange::Infinity());
397 AliMpDataProcessor mp;
398 AliMpDataMap* map = mp.CreateDataMap("data_run");
399 return cdbManager->Put(map, id, cdbData);
402 //______________________________________________________________________________
403 Bool_t AliMpCDB::WriteMpSegmentation(Bool_t readData)
405 /// Write mapping segmentation in OCDB
407 if ( ! readData && ! AliMpSegmentation::Instance() ) return false;
409 AliCDBManager* cdbManager = AliCDBManager::Instance();
410 if ( ! cdbManager->GetDefaultStorage() )
411 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
413 AliCDBMetaData* cdbData = new AliCDBMetaData();
414 cdbData->SetResponsible("Dimuon Offline project");
415 cdbData->SetComment("MUON mapping");
416 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
417 AliCDBId id("MUON/Calib/Mapping", 0, AliCDBRunRange::Infinity());
420 AliMpDataStreams dataStreams;
421 AliMpSegmentation::ReadData(dataStreams, false);
422 AliMpDDLStore::ReadData(dataStreams, false);
425 return cdbManager->Put(AliMpSegmentation::Instance(), id, cdbData);
428 //______________________________________________________________________________
429 Bool_t AliMpCDB::WriteDDLStore(Bool_t readData)
431 /// Write mapping DDL store in OCDB
433 if ( ! readData && ! AliMpDDLStore::Instance() ) return false;
435 AliCDBManager* cdbManager = AliCDBManager::Instance();
436 if ( ! cdbManager->GetDefaultStorage() )
437 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
439 AliCDBMetaData* cdbData = new AliCDBMetaData();
440 cdbData->SetResponsible("Dimuon Offline project");
441 cdbData->SetComment("MUON DDL store");
442 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
443 AliCDBId id("MUON/Calib/DDLStore", 0, AliCDBRunRange::Infinity());
446 AliMpDataStreams dataStreams;
447 AliMpSegmentation::ReadData(dataStreams, false);
448 AliMpDDLStore::ReadData(dataStreams, false);
450 return cdbManager->Put(AliMpDDLStore::Instance(), id, cdbData);
453 //______________________________________________________________________________
454 Bool_t AliMpCDB::WriteManuStore(Bool_t readData)
456 /// Write mapping Manu store in OCDB
458 if ( ! readData && ! AliMpManuStore::Instance() ) return false;
460 AliCDBManager* cdbManager = AliCDBManager::Instance();
461 if ( ! cdbManager->GetDefaultStorage() )
462 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
464 AliCDBMetaData* cdbData = new AliCDBMetaData();
465 cdbData->SetResponsible("Dimuon Offline project");
466 cdbData->SetComment("MUON Manu store");
467 cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
468 AliCDBId id("MUON/Calib/ManuStore", 0, AliCDBRunRange::Infinity());
471 AliMpDataStreams dataStreams;
472 AliMpSegmentation::ReadData(dataStreams, false);
473 AliMpManuStore::ReadData(dataStreams, false);
475 return cdbManager->Put(AliMpManuStore::Instance(), id, cdbData);
478 //______________________________________________________________________________
479 Bool_t AliMpCDB::GenerateMpData(const char* cdbpath, Int_t runNumber)
481 /// Generate mapping data ASCII files from OCDB
483 TObject* cdbEntryObject
484 = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
485 if ( ! cdbEntryObject ) return kFALSE;
487 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
488 AliMpDataProcessor mp;
489 return mp.GenerateData(dataMap);
492 //______________________________________________________________________________
493 Bool_t AliMpCDB::GenerateMpRunData(const char* cdbpath, Int_t runNumber)
495 /// Generate mapping data ASCII files from OCDB
497 TObject* cdbEntryObject
498 = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
499 if ( ! cdbEntryObject ) return kFALSE;
501 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
502 AliMpDataProcessor mp;
503 return mp.GenerateData(dataMap);
506 //______________________________________________________________________________
507 void AliMpCDB::UnloadAll()
509 /// Unload all the mapping from the memory
510 delete AliMpDDLStore::Instance(false);
511 delete AliMpSegmentation::Instance(false);
512 delete AliMpDEStore::Instance(false);
513 delete AliMpManuStore::Instance(false);