]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpCDB.cxx
Removal of the check for the default cdb storage - anyway it is done inside cdb manag...
[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 "AliMpSegmentation.h"
30 #include "AliMpDDLStore.h"
31 #include "AliMpManuStore.h"
32 #include "AliMpDataProcessor.h"
33 #include "AliMpDataStreams.h"
34 #include "AliMpDataMap.h"
35
36 #include "AliLog.h"
37 #include "AliCDBManager.h"
38 #include "AliCDBEntry.h"
39
40 #include <TSystem.h>
41 #include <TClass.h>
42 #include <Riostream.h>
43
44 /// \cond CLASSIMP
45 ClassImp(AliMpCDB)
46 /// \endcond
47
48 Bool_t AliMpCDB::fgLoadFromData = kTRUE;                                       
49
50 //
51 // private static methods
52 //
53
54 //______________________________________________________________________________
55 TObject*  AliMpCDB::GetCDBEntryObject(const char* dataPath)
56 {
57 /// Load CDB entry object with checks
58
59   AliCDBManager* cdbManager = AliCDBManager::Instance();
60
61   Int_t run = cdbManager->GetRun();
62   if ( run < 0 ) {
63     AliErrorClassStream() << "Cannot get run number from CDB manager." << endl; 
64     return 0;
65   }  
66
67   AliCDBEntry* cdbEntry = cdbManager->Get(dataPath, run);
68   if ( ! cdbEntry ) {
69     AliErrorClassStream() << "Cannot get cdbEntry." << endl; 
70     return 0;
71   }
72   
73   TObject* object = cdbEntry->GetObject();
74   if ( ! object ) {
75     AliErrorClassStream() << "Cannot get object from cdbEntry." << endl; 
76     return 0;
77   }  
78
79   return object;
80 }    
81   
82
83 //______________________________________________________________________________
84 TObject*  AliMpCDB::GetCDBEntryObject(const char* dataPath, 
85                                       const char* cdbpath,
86                                       Int_t runNumber )
87 {
88 /// Load CDB entry from CDB and run specified in arguments
89
90   AliCDBManager* cdbManager = AliCDBManager::Instance();
91   cdbManager->SetDefaultStorage(cdbpath);
92
93   AliCDBEntry* cdbEntry = cdbManager->Get(dataPath, runNumber);
94   if ( ! cdbEntry ) {
95     AliErrorClassStream() << "Cannot get cdbEntry." << endl; 
96     return 0;
97   }  
98     
99   TObject* object = cdbEntry->GetObject();
100   if ( ! object ) {
101     AliErrorClassStream() << "Cannot get object from cdbEntry." << endl; 
102     return 0;
103   }  
104
105   return object;
106 }    
107                                       
108 //
109 // public static methods
110 //
111
112    
113 //______________________________________________________________________________
114 Bool_t AliMpCDB::LoadMpSegmentation(Bool_t warn)
115 {
116 /// Load the sementation from the mapping data from OCDB,
117 ///  if it does not yet exist;
118 /// return false only in case loading from CDB failed
119
120   if ( AliMpSegmentation::Instance(false) ) {
121     if ( warn )  
122       AliWarningClass("Segmentation has been already loaded."); 
123     return true;
124   }  
125   
126   if ( fgLoadFromData ) {
127     AliDebugClassStream(1)
128       << "Loading segmentation from MUON/Calib/MappingData" << endl;
129   
130     TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingData");
131     if ( ! cdbEntryObject ) return kFALSE;
132   
133     // Pass the map to the streams and then read segmentation
134     // from data map
135     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
136     AliMpDataStreams dataStreams(dataMap);
137     AliMpSegmentation::ReadData(dataStreams);
138     return kTRUE;
139   }
140   else {
141     AliDebugClassStream(1)
142       << "Loading segmentation from MUON/Calib/Mapping" << endl;
143   
144     TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/Mapping");
145     return cdbEntryObject != 0x0;
146   }  
147 }    
148
149 //______________________________________________________________________________
150 Bool_t AliMpCDB::LoadDDLStore(Bool_t warn)
151 {
152 /// Load the DDL store from the mapping data from OCDB,
153 ///  if it does not yet exist;
154 /// return false only in case loading from CDB failed
155
156   if ( AliMpDDLStore::Instance(false) ) {
157     if ( warn )  
158       AliWarningClass("DDL Store has been already loaded."); 
159     return true;
160   }  
161   
162   if ( fgLoadFromData ) {
163     AliDebugClassStream(1)
164       << "Loading DDL store from MUON/Calib/MappingData" << endl;
165   
166     TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingData");
167     if ( ! cdbEntryObject ) return kFALSE;
168   
169     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
170     AliMpDataStreams dataStreams(dataMap);
171     AliMpDDLStore::ReadData(dataStreams);
172     return kTRUE;
173   }
174   else {
175     AliDebugClassStream(1)
176       << "Loading DDL store from MUON/Calib/DDLStore" << endl;
177   
178     // Load segmentation
179     LoadMpSegmentation(warn); 
180   
181     // Load DDL store
182     TObject* cdbEntryObject =  GetCDBEntryObject("MUON/Calib/DDLStore");
183     return cdbEntryObject != 0x0;
184   }     
185 }    
186
187 //______________________________________________________________________________
188 Bool_t AliMpCDB::LoadManuStore(Bool_t warn)
189 {
190 /// Load the DDL store from the mapping data from OCDB,
191 ///  if it does not yet exist;
192 /// return false only in case loading from CDB failed
193
194   if ( AliMpManuStore::Instance(false) ) {
195     if ( warn )  
196       AliWarningClass("Manu Store has been already loaded."); 
197     return true;
198   }  
199   
200   if ( fgLoadFromData ) {
201     AliDebugClassStream(1)
202       << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
203   
204     // Load segmentation
205     LoadMpSegmentation(warn); 
206
207     TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingRunData");
208     if ( ! cdbEntryObject ) return kFALSE;
209   
210     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
211     AliMpDataStreams dataStreams(dataMap);
212     AliMpManuStore::ReadData(dataStreams);
213     return kTRUE;
214   }
215   else {
216     AliDebugClassStream(1)
217       << "Loading Manu store from MUON/Calib/ManuStore" << endl;
218   
219     // Load Manu store
220     TObject* cdbEntryObject =  GetCDBEntryObject("MUON/Calib/ManuStore");
221     return cdbEntryObject != 0x0;
222   }     
223 }    
224 //______________________________________________________________________________
225 Bool_t AliMpCDB::LoadMpSegmentation2(const char* cdbpath, Int_t runNumber, 
226                                      Bool_t warn)
227 {
228 /// Load the sementation from the CDB if it does not yet exist;
229 /// return false only in case loading from CDB failed.
230 /// In difference from LoadMpSegmentation(), in this method the CDB path
231 /// and run is set directly via arguments.
232
233
234   if ( AliMpSegmentation::Instance(false) ) {
235     if ( warn )  
236       AliWarningClass("Segmentation has been already loaded."); 
237     return true;
238   }  
239   
240   if ( fgLoadFromData ) {
241     AliDebugClassStream(1)
242       << "Loading segmentation from MUON/Calib/MappingData" << endl;
243   
244     TObject* cdbEntryObject 
245       = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
246     if ( ! cdbEntryObject ) return kFALSE;
247   
248     // Pass the map to the streams and then read segmentation
249     // from data map
250     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
251     AliMpDataStreams dataStreams(dataMap);
252     AliMpSegmentation::ReadData(dataStreams);
253     return kTRUE;
254   }
255   else {
256     AliDebugClassStream(1)
257       << "Loading segmentation from MUON/Calib/Mapping" << endl;
258   
259     TObject* cdbEntryObject 
260       = GetCDBEntryObject("MUON/Calib/Mapping", cdbpath, runNumber);
261     return cdbEntryObject != 0x0;
262   }  
263 }    
264
265 //______________________________________________________________________________
266 Bool_t AliMpCDB::LoadDDLStore2(const char* cdbpath, Int_t runNumber, 
267                                Bool_t warn)
268 {
269 /// Load the DDL store from the CDB if it does not yet exist
270 /// return false only in case loading from CDB failed
271 /// In difference from LoadDDLStore(), in this method the CDB path
272 /// and run is set directly via arguments.
273
274   if ( AliMpDDLStore::Instance(false) ) {
275     if ( warn )  
276       AliWarningClass("DDL Store has been already loaded."); 
277     return true;
278   }  
279   
280   if ( fgLoadFromData ) {
281     AliDebugClassStream(1)
282       << "Loading DDL store from MUON/Calib/MappingData" << endl;
283   
284     TObject* cdbEntryObject 
285       = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
286     if ( ! cdbEntryObject ) return kFALSE;
287   
288     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
289     AliMpDataStreams dataStreams(dataMap);
290     AliMpDDLStore::ReadData(dataStreams);
291     return kTRUE;
292   }
293   else {
294     AliDebugClassStream(1)
295       << "Loading DDL store from MUON/Calib/DDLStore" << endl;
296   
297     // Load segmentation
298     LoadMpSegmentation2(cdbpath, runNumber, warn); 
299   
300     // Load DDL store
301     TObject* cdbEntryObject =  GetCDBEntryObject("MUON/Calib/DDLStore");
302     return cdbEntryObject != 0x0;
303   }  
304 }    
305
306 //______________________________________________________________________________
307 Bool_t AliMpCDB::LoadManuStore2(const char* cdbpath, Int_t runNumber, 
308                                 Bool_t warn)
309 {
310 /// Load the DDL store from the CDB if it does not yet exist
311 /// return false only in case loading from CDB failed
312 /// In difference from LoadDDLStore(), in this method the CDB path
313 /// and run is set directly via arguments.
314
315   if ( AliMpManuStore::Instance(false) ) {
316     if ( warn )  
317       AliWarningClass("Manu Store has been already loaded."); 
318     return true;
319   }  
320   
321   if ( fgLoadFromData ) {
322     AliDebugClassStream(1)
323       << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
324   
325     // Load segmentation
326     LoadMpSegmentation2(cdbpath, runNumber, warn); 
327
328     TObject* cdbEntryObject 
329       = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
330     if ( ! cdbEntryObject ) return kFALSE;
331   
332     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
333     AliMpDataStreams dataStreams(dataMap);
334     AliMpManuStore::ReadData(dataStreams);
335     return kTRUE;
336   }
337   else {
338     AliDebugClassStream(1)
339       << "Loading Manu store from MUON/Calib/ManuStore" << endl;
340   
341     // Load Manu store
342     TObject* cdbEntryObject =  GetCDBEntryObject("MUON/Calib/ManuStore");
343     return cdbEntryObject != 0x0;
344   }  
345 }    
346
347 //______________________________________________________________________________
348 Bool_t AliMpCDB::WriteMpData()
349 {
350 /// Write mapping data in OCDB
351
352   AliCDBManager* cdbManager = AliCDBManager::Instance();
353   if ( ! cdbManager->GetDefaultStorage() )
354     cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
355   
356   AliCDBMetaData* cdbData = new AliCDBMetaData();
357   cdbData->SetResponsible("Dimuon Offline project");
358   cdbData->SetComment("MUON mapping");
359   cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
360   AliCDBId id("MUON/Calib/MappingData", 0, AliCDBRunRange::Infinity()); 
361
362   AliMpDataProcessor mp;
363   AliMpDataMap* map = mp.CreateDataMap("data");
364   return cdbManager->Put(map, id, cdbData);
365 }
366
367 //______________________________________________________________________________
368 Bool_t AliMpCDB::WriteMpRunData()
369 {
370 /// Write mapping data in OCDB
371
372   AliCDBManager* cdbManager = AliCDBManager::Instance();
373   if ( ! cdbManager->GetDefaultStorage() )
374     cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
375   
376   AliCDBMetaData* cdbData = new AliCDBMetaData();
377   cdbData->SetResponsible("Dimuon Offline project");
378   cdbData->SetComment("MUON run-dependent mapping");
379   cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
380   AliCDBId id("MUON/Calib/MappingRunData", 0, AliCDBRunRange::Infinity()); 
381
382   AliMpDataProcessor mp;
383   AliMpDataMap* map = mp.CreateDataMap("data_run");
384   return cdbManager->Put(map, id, cdbData);
385 }
386
387 //______________________________________________________________________________
388 Bool_t AliMpCDB::WriteMpSegmentation(Bool_t readData)
389 {
390 /// Write mapping segmentation in OCDB
391
392   if ( ! readData && ! AliMpSegmentation::Instance() ) return false;
393
394   AliCDBManager* cdbManager = AliCDBManager::Instance();
395   if ( ! cdbManager->GetDefaultStorage() )
396     cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
397   
398   AliCDBMetaData* cdbData = new AliCDBMetaData();
399   cdbData->SetResponsible("Dimuon Offline project");
400   cdbData->SetComment("MUON mapping");
401   cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
402   AliCDBId id("MUON/Calib/Mapping", 0, AliCDBRunRange::Infinity()); 
403
404   if ( readData ) {
405     AliMpDataStreams dataStreams;
406     AliMpSegmentation::ReadData(dataStreams, false);
407     AliMpDDLStore::ReadData(dataStreams, false);
408   }
409   
410   return cdbManager->Put(AliMpSegmentation::Instance(), id, cdbData);
411 }
412
413 //______________________________________________________________________________
414 Bool_t AliMpCDB::WriteDDLStore(Bool_t readData)
415 {
416 /// Write mapping DDL store in OCDB
417
418   if ( ! readData && ! AliMpDDLStore::Instance() ) return false;
419
420   AliCDBManager* cdbManager = AliCDBManager::Instance();
421   if ( ! cdbManager->GetDefaultStorage() )
422     cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
423   
424   AliCDBMetaData* cdbData = new AliCDBMetaData();
425   cdbData->SetResponsible("Dimuon Offline project");
426   cdbData->SetComment("MUON DDL store");
427   cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
428   AliCDBId id("MUON/Calib/DDLStore", 0, AliCDBRunRange::Infinity()); 
429
430   if ( readData ) {
431     AliMpDataStreams dataStreams;
432     AliMpSegmentation::ReadData(dataStreams, false);
433     AliMpDDLStore::ReadData(dataStreams, false);
434   }
435   return cdbManager->Put(AliMpDDLStore::Instance(), id, cdbData);
436 }   
437
438 //______________________________________________________________________________
439 Bool_t AliMpCDB::WriteManuStore(Bool_t readData)
440 {
441 /// Write mapping Manu store in OCDB
442
443   if ( ! readData && ! AliMpManuStore::Instance() ) return false;
444
445   AliCDBManager* cdbManager = AliCDBManager::Instance();
446   if ( ! cdbManager->GetDefaultStorage() )
447     cdbManager->SetDefaultStorage("local://$ALICE_ROOT");
448   
449   AliCDBMetaData* cdbData = new AliCDBMetaData();
450   cdbData->SetResponsible("Dimuon Offline project");
451   cdbData->SetComment("MUON Manu store");
452   cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
453   AliCDBId id("MUON/Calib/ManuStore", 0, AliCDBRunRange::Infinity()); 
454
455   if ( readData ) {
456     AliMpDataStreams dataStreams;
457     AliMpSegmentation::ReadData(dataStreams, false);
458     AliMpManuStore::ReadData(dataStreams, false);
459   }
460   return cdbManager->Put(AliMpManuStore::Instance(), id, cdbData);
461 }   
462
463 //______________________________________________________________________________
464 Bool_t  AliMpCDB::GenerateMpData(const char* cdbpath, Int_t runNumber)
465 {
466 /// Generate mapping data ASCII files from OCDB
467
468   TObject* cdbEntryObject 
469     = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
470   if ( ! cdbEntryObject ) return kFALSE;
471   
472   AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
473   AliMpDataProcessor mp;
474   return mp.GenerateData(dataMap);
475
476
477 //______________________________________________________________________________
478 Bool_t  AliMpCDB::GenerateMpRunData(const char* cdbpath, Int_t runNumber)
479 {
480 /// Generate mapping data ASCII files from OCDB
481
482   TObject* cdbEntryObject 
483     = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
484   if ( ! cdbEntryObject ) return kFALSE;
485   
486   AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
487   AliMpDataProcessor mp;
488   return mp.GenerateData(dataMap);
489
490
491