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 if ( ! AliMpSegmentation::Instance(false) )
221 LoadMpSegmentation(warn);
223 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingRunData");
224 if ( ! cdbEntryObject ) return kFALSE;
226 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
227 AliMpDataStreams dataStreams(dataMap);
228 AliMpManuStore::ReadData(dataStreams);
232 AliDebugClassStream(1)
233 << "Loading Manu store from MUON/Calib/ManuStore" << endl;
236 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/ManuStore");
237 return cdbEntryObject != 0x0;
240 //______________________________________________________________________________
241 Bool_t AliMpCDB::LoadMpSegmentation2(const char* cdbpath, Int_t runNumber,
244 /// Load the sementation from the CDB if it does not yet exist;
245 /// return false only in case loading from CDB failed.
246 /// In difference from LoadMpSegmentation(), in this method the CDB path
247 /// and run is set directly via arguments.
250 if ( AliMpSegmentation::Instance(false) ) {
252 AliWarningClass("Segmentation has been already loaded.");
256 if ( fgLoadFromData ) {
257 AliDebugClassStream(1)
258 << "Loading segmentation from MUON/Calib/MappingData" << endl;
260 TObject* cdbEntryObject
261 = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
262 if ( ! cdbEntryObject ) return kFALSE;
264 // Pass the map to the streams and then read segmentation
266 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
267 AliMpDataStreams dataStreams(dataMap);
268 AliMpSegmentation::ReadData(dataStreams);
272 AliDebugClassStream(1)
273 << "Loading segmentation from MUON/Calib/Mapping" << endl;
275 TObject* cdbEntryObject
276 = GetCDBEntryObject("MUON/Calib/Mapping", cdbpath, runNumber);
277 return cdbEntryObject != 0x0;
281 //______________________________________________________________________________
282 Bool_t AliMpCDB::LoadDDLStore2(const char* cdbpath, Int_t runNumber,
285 /// Load the DDL store from the CDB if it does not yet exist
286 /// return false only in case loading from CDB failed
287 /// In difference from LoadDDLStore(), in this method the CDB path
288 /// and run is set directly via arguments.
290 if ( AliMpDDLStore::Instance(false) ) {
292 AliWarningClass("DDL Store has been already loaded.");
296 if ( fgLoadFromData ) {
297 AliDebugClassStream(1)
298 << "Loading DDL store from MUON/Calib/MappingData" << endl;
300 TObject* cdbEntryObject
301 = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
302 if ( ! cdbEntryObject ) return kFALSE;
304 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
305 AliMpDataStreams dataStreams(dataMap);
306 AliMpDDLStore::ReadData(dataStreams);
310 AliDebugClassStream(1)
311 << "Loading DDL store from MUON/Calib/DDLStore" << endl;
314 LoadMpSegmentation2(cdbpath, runNumber, warn);
317 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/DDLStore");
318 return cdbEntryObject != 0x0;
322 //______________________________________________________________________________
323 Bool_t AliMpCDB::LoadManuStore2(const char* cdbpath, Int_t runNumber,
326 /// Load the DDL store from the CDB if it does not yet exist
327 /// return false only in case loading from CDB failed
328 /// In difference from LoadDDLStore(), in this method the CDB path
329 /// and run is set directly via arguments.
331 if ( AliMpManuStore::Instance(false) ) {
333 AliWarningClass("Manu Store has been already loaded.");
337 if ( fgLoadFromData ) {
338 AliDebugClassStream(1)
339 << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
342 LoadMpSegmentation2(cdbpath, runNumber, warn);
344 TObject* cdbEntryObject
345 = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
346 if ( ! cdbEntryObject ) return kFALSE;
348 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
349 AliMpDataStreams dataStreams(dataMap);
350 AliMpManuStore::ReadData(dataStreams);
354 AliDebugClassStream(1)
355 << "Loading Manu store from MUON/Calib/ManuStore" << endl;
358 TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/ManuStore");
359 return cdbEntryObject != 0x0;
363 //______________________________________________________________________________
364 Bool_t AliMpCDB::WriteMpData()
366 /// Write mapping data in OCDB
368 AliCDBManager* cdbManager = AliCDBManager::Instance();
369 if ( ! cdbManager->GetDefaultStorage() )
370 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
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());
378 AliMpDataProcessor mp;
379 AliMpDataMap* map = mp.CreateDataMap("data");
380 return cdbManager->Put(map, id, cdbData);
383 //______________________________________________________________________________
384 Bool_t AliMpCDB::WriteMpRunData()
386 /// Write mapping data in OCDB
388 AliCDBManager* cdbManager = AliCDBManager::Instance();
389 if ( ! cdbManager->GetDefaultStorage() )
390 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
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());
398 AliMpDataProcessor mp;
399 AliMpDataMap* map = mp.CreateDataMap("data_run");
400 return cdbManager->Put(map, id, cdbData);
403 //______________________________________________________________________________
404 Bool_t AliMpCDB::WriteMpSegmentation(Bool_t readData)
406 /// Write mapping segmentation in OCDB
408 if ( ! readData && ! AliMpSegmentation::Instance() ) return false;
410 AliCDBManager* cdbManager = AliCDBManager::Instance();
411 if ( ! cdbManager->GetDefaultStorage() )
412 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
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());
421 AliMpDataStreams dataStreams;
422 AliMpSegmentation::ReadData(dataStreams, false);
423 AliMpDDLStore::ReadData(dataStreams, false);
426 return cdbManager->Put(AliMpSegmentation::Instance(), id, cdbData);
429 //______________________________________________________________________________
430 Bool_t AliMpCDB::WriteDDLStore(Bool_t readData)
432 /// Write mapping DDL store in OCDB
434 if ( ! readData && ! AliMpDDLStore::Instance() ) return false;
436 AliCDBManager* cdbManager = AliCDBManager::Instance();
437 if ( ! cdbManager->GetDefaultStorage() )
438 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
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());
447 AliMpDataStreams dataStreams;
448 AliMpSegmentation::ReadData(dataStreams, false);
449 AliMpDDLStore::ReadData(dataStreams, false);
451 return cdbManager->Put(AliMpDDLStore::Instance(), id, cdbData);
454 //______________________________________________________________________________
455 Bool_t AliMpCDB::WriteManuStore(Bool_t readData)
457 /// Write mapping Manu store in OCDB
459 if ( ! readData && ! AliMpManuStore::Instance() ) return false;
461 AliCDBManager* cdbManager = AliCDBManager::Instance();
462 if ( ! cdbManager->GetDefaultStorage() )
463 cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
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());
472 AliMpDataStreams dataStreams;
473 AliMpSegmentation::ReadData(dataStreams, false);
474 AliMpManuStore::ReadData(dataStreams, false);
476 return cdbManager->Put(AliMpManuStore::Instance(), id, cdbData);
479 //______________________________________________________________________________
480 Bool_t AliMpCDB::GenerateMpData(const char* cdbpath, Int_t runNumber)
482 /// Generate mapping data ASCII files from OCDB
484 TObject* cdbEntryObject
485 = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
486 if ( ! cdbEntryObject ) return kFALSE;
488 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
489 AliMpDataProcessor mp;
490 return mp.GenerateData(dataMap);
493 //______________________________________________________________________________
494 Bool_t AliMpCDB::GenerateMpRunData(const char* cdbpath, Int_t runNumber)
496 /// Generate mapping data ASCII files from OCDB
498 TObject* cdbEntryObject
499 = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
500 if ( ! cdbEntryObject ) return kFALSE;
502 AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
503 AliMpDataProcessor mp;
504 return mp.GenerateData(dataMap);
507 //______________________________________________________________________________
508 void AliMpCDB::UnloadAll()
510 /// Unload all the mapping from the memory
511 delete AliMpDDLStore::Instance(false);
512 delete AliMpSegmentation::Instance(false);
513 delete AliMpDEStore::Instance(false);
514 delete AliMpManuStore::Instance(false);