]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONmapping/AliMpCDB.cxx
PMD module
[u/mrichter/AliRoot.git] / MUON / MUONmapping / 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     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 {
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.
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 {
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.
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 {
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.
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 //______________________________________________________________________________
364 Bool_t AliMpCDB::WriteMpData()
365 {
366 /// Write mapping data in OCDB
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
378   AliMpDataProcessor mp;
379   AliMpDataMap* map = mp.CreateDataMap("data");
380   return cdbManager->Put(map, id, cdbData);
381 }
382
383 //______________________________________________________________________________
384 Bool_t AliMpCDB::WriteMpRunData()
385 {
386 /// Write mapping data in OCDB
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
398   AliMpDataProcessor mp;
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 {
406 /// Write mapping segmentation in OCDB
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 {
432 /// Write mapping DDL store in OCDB
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 {
457 /// Write mapping Manu store in OCDB
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 {
482 /// Generate mapping data ASCII files from OCDB
483
484   TObject* cdbEntryObject 
485     = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
486   if ( ! cdbEntryObject ) return kFALSE;
487   
488   AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
489   AliMpDataProcessor mp;
490   return mp.GenerateData(dataMap);
491
492
493 //______________________________________________________________________________
494 Bool_t  AliMpCDB::GenerateMpRunData(const char* cdbpath, Int_t runNumber)
495 {
496 /// Generate mapping data ASCII files from OCDB
497
498   TObject* cdbEntryObject 
499     = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
500   if ( ! cdbEntryObject ) return kFALSE;
501   
502   AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
503   AliMpDataProcessor mp;
504   return mp.GenerateData(dataMap);
505
506
507 //______________________________________________________________________________
508 void AliMpCDB::UnloadAll()
509 {
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);
515 }
516