]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpCDB.cxx
Class AliMUONCDB:
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpCDB.cxx
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
43 /// \cond CLASSIMP
44 ClassImp(AliMpCDB)
45 /// \endcond
46
47 Bool_t AliMpCDB::fgLoadFromData = kTRUE;                                       
48
49 //
50 // private static methods
51 //
52
53 //______________________________________________________________________________
54 TObject*  AliMpCDB::GetCDBEntryObject(const char* dataPath)
55 {
56 /// Load CDB entry object with checks
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 {
87 /// Load CDB entry from CDB and run specified in arguments
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 {
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
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 {
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
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 {
189   /// Load everything in one shot 
190   return 
191   LoadDDLStore2(cdbpath,runNumber,warn) && 
192   LoadManuStore2(cdbpath,runNumber,warn);
193 }
194
195 //______________________________________________________________________________
196 Bool_t AliMpCDB::LoadAll(Bool_t warn)
197 {
198   /// Load everything in one shot 
199   return LoadDDLStore(warn) && LoadManuStore(warn);
200 }
201
202 //______________________________________________________________________________
203 Bool_t AliMpCDB::LoadManuStore(Bool_t warn)
204 {
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
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     LoadMpSegmentation(warn); 
221
222     TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingRunData");
223     if ( ! cdbEntryObject ) return kFALSE;
224   
225     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
226     AliMpDataStreams dataStreams(dataMap);
227     AliMpManuStore::ReadData(dataStreams);
228     return kTRUE;
229   }
230   else {
231     AliDebugClassStream(1)
232       << "Loading Manu store from MUON/Calib/ManuStore" << endl;
233   
234     // Load Manu store
235     TObject* cdbEntryObject =  GetCDBEntryObject("MUON/Calib/ManuStore");
236     return cdbEntryObject != 0x0;
237   }     
238 }    
239 //______________________________________________________________________________
240 Bool_t AliMpCDB::LoadMpSegmentation2(const char* cdbpath, Int_t runNumber, 
241                                      Bool_t warn)
242 {
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.
247
248
249   if ( AliMpSegmentation::Instance(false) ) {
250     if ( warn )  
251       AliWarningClass("Segmentation has been already loaded."); 
252     return true;
253   }  
254   
255   if ( fgLoadFromData ) {
256     AliDebugClassStream(1)
257       << "Loading segmentation from MUON/Calib/MappingData" << endl;
258   
259     TObject* cdbEntryObject 
260       = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
261     if ( ! cdbEntryObject ) return kFALSE;
262   
263     // Pass the map to the streams and then read segmentation
264     // from data map
265     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
266     AliMpDataStreams dataStreams(dataMap);
267     AliMpSegmentation::ReadData(dataStreams);
268     return kTRUE;
269   }
270   else {
271     AliDebugClassStream(1)
272       << "Loading segmentation from MUON/Calib/Mapping" << endl;
273   
274     TObject* cdbEntryObject 
275       = GetCDBEntryObject("MUON/Calib/Mapping", cdbpath, runNumber);
276     return cdbEntryObject != 0x0;
277   }  
278 }    
279
280 //______________________________________________________________________________
281 Bool_t AliMpCDB::LoadDDLStore2(const char* cdbpath, Int_t runNumber, 
282                                Bool_t warn)
283 {
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.
288
289   if ( AliMpDDLStore::Instance(false) ) {
290     if ( warn )  
291       AliWarningClass("DDL Store has been already loaded."); 
292     return true;
293   }  
294   
295   if ( fgLoadFromData ) {
296     AliDebugClassStream(1)
297       << "Loading DDL store from MUON/Calib/MappingData" << endl;
298   
299     TObject* cdbEntryObject 
300       = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
301     if ( ! cdbEntryObject ) return kFALSE;
302   
303     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
304     AliMpDataStreams dataStreams(dataMap);
305     AliMpDDLStore::ReadData(dataStreams);
306     return kTRUE;
307   }
308   else {
309     AliDebugClassStream(1)
310       << "Loading DDL store from MUON/Calib/DDLStore" << endl;
311   
312     // Load segmentation
313     LoadMpSegmentation2(cdbpath, runNumber, warn); 
314   
315     // Load DDL store
316     TObject* cdbEntryObject =  GetCDBEntryObject("MUON/Calib/DDLStore");
317     return cdbEntryObject != 0x0;
318   }  
319 }    
320
321 //______________________________________________________________________________
322 Bool_t AliMpCDB::LoadManuStore2(const char* cdbpath, Int_t runNumber, 
323                                 Bool_t warn)
324 {
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.
329
330   if ( AliMpManuStore::Instance(false) ) {
331     if ( warn )  
332       AliWarningClass("Manu Store has been already loaded."); 
333     return true;
334   }  
335   
336   if ( fgLoadFromData ) {
337     AliDebugClassStream(1)
338       << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
339   
340     // Load segmentation
341     LoadMpSegmentation2(cdbpath, runNumber, warn); 
342
343     TObject* cdbEntryObject 
344       = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
345     if ( ! cdbEntryObject ) return kFALSE;
346   
347     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
348     AliMpDataStreams dataStreams(dataMap);
349     AliMpManuStore::ReadData(dataStreams);
350     return kTRUE;
351   }
352   else {
353     AliDebugClassStream(1)
354       << "Loading Manu store from MUON/Calib/ManuStore" << endl;
355   
356     // Load Manu store
357     TObject* cdbEntryObject =  GetCDBEntryObject("MUON/Calib/ManuStore");
358     return cdbEntryObject != 0x0;
359   }  
360 }    
361
362 //______________________________________________________________________________
363 Bool_t AliMpCDB::WriteMpData()
364 {
365 /// Write mapping data in OCDB
366
367   AliCDBManager* cdbManager = AliCDBManager::Instance();
368   if ( ! cdbManager->GetDefaultStorage() )
369     cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
370   
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()); 
376
377   AliMpDataProcessor mp;
378   AliMpDataMap* map = mp.CreateDataMap("data");
379   return cdbManager->Put(map, id, cdbData);
380 }
381
382 //______________________________________________________________________________
383 Bool_t AliMpCDB::WriteMpRunData()
384 {
385 /// Write mapping data in OCDB
386
387   AliCDBManager* cdbManager = AliCDBManager::Instance();
388   if ( ! cdbManager->GetDefaultStorage() )
389     cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
390   
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()); 
396
397   AliMpDataProcessor mp;
398   AliMpDataMap* map = mp.CreateDataMap("data_run");
399   return cdbManager->Put(map, id, cdbData);
400 }
401
402 //______________________________________________________________________________
403 Bool_t AliMpCDB::WriteMpSegmentation(Bool_t readData)
404 {
405 /// Write mapping segmentation in OCDB
406
407   if ( ! readData && ! AliMpSegmentation::Instance() ) return false;
408
409   AliCDBManager* cdbManager = AliCDBManager::Instance();
410   if ( ! cdbManager->GetDefaultStorage() )
411     cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
412   
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()); 
418
419   if ( readData ) {
420     AliMpDataStreams dataStreams;
421     AliMpSegmentation::ReadData(dataStreams, false);
422     AliMpDDLStore::ReadData(dataStreams, false);
423   }
424   
425   return cdbManager->Put(AliMpSegmentation::Instance(), id, cdbData);
426 }
427
428 //______________________________________________________________________________
429 Bool_t AliMpCDB::WriteDDLStore(Bool_t readData)
430 {
431 /// Write mapping DDL store in OCDB
432
433   if ( ! readData && ! AliMpDDLStore::Instance() ) return false;
434
435   AliCDBManager* cdbManager = AliCDBManager::Instance();
436   if ( ! cdbManager->GetDefaultStorage() )
437     cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
438   
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()); 
444
445   if ( readData ) {
446     AliMpDataStreams dataStreams;
447     AliMpSegmentation::ReadData(dataStreams, false);
448     AliMpDDLStore::ReadData(dataStreams, false);
449   }
450   return cdbManager->Put(AliMpDDLStore::Instance(), id, cdbData);
451 }   
452
453 //______________________________________________________________________________
454 Bool_t AliMpCDB::WriteManuStore(Bool_t readData)
455 {
456 /// Write mapping Manu store in OCDB
457
458   if ( ! readData && ! AliMpManuStore::Instance() ) return false;
459
460   AliCDBManager* cdbManager = AliCDBManager::Instance();
461   if ( ! cdbManager->GetDefaultStorage() )
462     cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
463   
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()); 
469
470   if ( readData ) {
471     AliMpDataStreams dataStreams;
472     AliMpSegmentation::ReadData(dataStreams, false);
473     AliMpManuStore::ReadData(dataStreams, false);
474   }
475   return cdbManager->Put(AliMpManuStore::Instance(), id, cdbData);
476 }   
477
478 //______________________________________________________________________________
479 Bool_t  AliMpCDB::GenerateMpData(const char* cdbpath, Int_t runNumber)
480 {
481 /// Generate mapping data ASCII files from OCDB
482
483   TObject* cdbEntryObject 
484     = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
485   if ( ! cdbEntryObject ) return kFALSE;
486   
487   AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
488   AliMpDataProcessor mp;
489   return mp.GenerateData(dataMap);
490
491
492 //______________________________________________________________________________
493 Bool_t  AliMpCDB::GenerateMpRunData(const char* cdbpath, Int_t runNumber)
494 {
495 /// Generate mapping data ASCII files from OCDB
496
497   TObject* cdbEntryObject 
498     = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
499   if ( ! cdbEntryObject ) return kFALSE;
500   
501   AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
502   AliMpDataProcessor mp;
503   return mp.GenerateData(dataMap);
504
505
506 //______________________________________________________________________________
507 void AliMpCDB::UnloadAll()
508 {
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);
514 }
515