]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/AliMpCDB.cxx
Removing a comma that gcc 3.4 does not like ;-)
[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::LoadManuStore(Bool_t warn)
188 {
189 /// Load the DDL store from the mapping data from OCDB,
190 ///  if it does not yet exist;
191 /// return false only in case loading from CDB failed
192
193   if ( AliMpManuStore::Instance(false) ) {
194     if ( warn )  
195       AliWarningClass("Manu Store has been already loaded."); 
196     return true;
197   }  
198   
199   if ( fgLoadFromData ) {
200     AliDebugClassStream(1)
201       << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
202   
203     // Load segmentation
204     LoadMpSegmentation(warn); 
205
206     TObject* cdbEntryObject = GetCDBEntryObject("MUON/Calib/MappingRunData");
207     if ( ! cdbEntryObject ) return kFALSE;
208   
209     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
210     AliMpDataStreams dataStreams(dataMap);
211     AliMpManuStore::ReadData(dataStreams);
212     return kTRUE;
213   }
214   else {
215     AliDebugClassStream(1)
216       << "Loading Manu store from MUON/Calib/ManuStore" << endl;
217   
218     // Load Manu store
219     TObject* cdbEntryObject =  GetCDBEntryObject("MUON/Calib/ManuStore");
220     return cdbEntryObject != 0x0;
221   }     
222 }    
223 //______________________________________________________________________________
224 Bool_t AliMpCDB::LoadMpSegmentation2(const char* cdbpath, Int_t runNumber, 
225                                      Bool_t warn)
226 {
227 /// Load the sementation from the CDB if it does not yet exist;
228 /// return false only in case loading from CDB failed.
229 /// In difference from LoadMpSegmentation(), in this method the CDB path
230 /// and run is set directly via arguments.
231
232
233   if ( AliMpSegmentation::Instance(false) ) {
234     if ( warn )  
235       AliWarningClass("Segmentation has been already loaded."); 
236     return true;
237   }  
238   
239   if ( fgLoadFromData ) {
240     AliDebugClassStream(1)
241       << "Loading segmentation from MUON/Calib/MappingData" << endl;
242   
243     TObject* cdbEntryObject 
244       = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
245     if ( ! cdbEntryObject ) return kFALSE;
246   
247     // Pass the map to the streams and then read segmentation
248     // from data map
249     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
250     AliMpDataStreams dataStreams(dataMap);
251     AliMpSegmentation::ReadData(dataStreams);
252     return kTRUE;
253   }
254   else {
255     AliDebugClassStream(1)
256       << "Loading segmentation from MUON/Calib/Mapping" << endl;
257   
258     TObject* cdbEntryObject 
259       = GetCDBEntryObject("MUON/Calib/Mapping", cdbpath, runNumber);
260     return cdbEntryObject != 0x0;
261   }  
262 }    
263
264 //______________________________________________________________________________
265 Bool_t AliMpCDB::LoadDDLStore2(const char* cdbpath, Int_t runNumber, 
266                                Bool_t warn)
267 {
268 /// Load the DDL store from the CDB if it does not yet exist
269 /// return false only in case loading from CDB failed
270 /// In difference from LoadDDLStore(), in this method the CDB path
271 /// and run is set directly via arguments.
272
273   if ( AliMpDDLStore::Instance(false) ) {
274     if ( warn )  
275       AliWarningClass("DDL Store has been already loaded."); 
276     return true;
277   }  
278   
279   if ( fgLoadFromData ) {
280     AliDebugClassStream(1)
281       << "Loading DDL store from MUON/Calib/MappingData" << endl;
282   
283     TObject* cdbEntryObject 
284       = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
285     if ( ! cdbEntryObject ) return kFALSE;
286   
287     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
288     AliMpDataStreams dataStreams(dataMap);
289     AliMpDDLStore::ReadData(dataStreams);
290     return kTRUE;
291   }
292   else {
293     AliDebugClassStream(1)
294       << "Loading DDL store from MUON/Calib/DDLStore" << endl;
295   
296     // Load segmentation
297     LoadMpSegmentation2(cdbpath, runNumber, warn); 
298   
299     // Load DDL store
300     TObject* cdbEntryObject =  GetCDBEntryObject("MUON/Calib/DDLStore");
301     return cdbEntryObject != 0x0;
302   }  
303 }    
304
305 //______________________________________________________________________________
306 Bool_t AliMpCDB::LoadManuStore2(const char* cdbpath, Int_t runNumber, 
307                                 Bool_t warn)
308 {
309 /// Load the DDL store from the CDB if it does not yet exist
310 /// return false only in case loading from CDB failed
311 /// In difference from LoadDDLStore(), in this method the CDB path
312 /// and run is set directly via arguments.
313
314   if ( AliMpManuStore::Instance(false) ) {
315     if ( warn )  
316       AliWarningClass("Manu Store has been already loaded."); 
317     return true;
318   }  
319   
320   if ( fgLoadFromData ) {
321     AliDebugClassStream(1)
322       << "Loading Manu store from MUON/Calib/MappingRunData" << endl;
323   
324     // Load segmentation
325     LoadMpSegmentation2(cdbpath, runNumber, warn); 
326
327     TObject* cdbEntryObject 
328       = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
329     if ( ! cdbEntryObject ) return kFALSE;
330   
331     AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
332     AliMpDataStreams dataStreams(dataMap);
333     AliMpManuStore::ReadData(dataStreams);
334     return kTRUE;
335   }
336   else {
337     AliDebugClassStream(1)
338       << "Loading Manu store from MUON/Calib/ManuStore" << endl;
339   
340     // Load Manu store
341     TObject* cdbEntryObject =  GetCDBEntryObject("MUON/Calib/ManuStore");
342     return cdbEntryObject != 0x0;
343   }  
344 }    
345
346 //______________________________________________________________________________
347 Bool_t AliMpCDB::WriteMpData()
348 {
349 /// Write mapping data in OCDB
350
351   AliCDBManager* cdbManager = AliCDBManager::Instance();
352   if ( ! cdbManager->GetDefaultStorage() )
353     cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
354   
355   AliCDBMetaData* cdbData = new AliCDBMetaData();
356   cdbData->SetResponsible("Dimuon Offline project");
357   cdbData->SetComment("MUON mapping");
358   cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
359   AliCDBId id("MUON/Calib/MappingData", 0, AliCDBRunRange::Infinity()); 
360
361   AliMpDataProcessor mp;
362   AliMpDataMap* map = mp.CreateDataMap("data");
363   return cdbManager->Put(map, id, cdbData);
364 }
365
366 //______________________________________________________________________________
367 Bool_t AliMpCDB::WriteMpRunData()
368 {
369 /// Write mapping data in OCDB
370
371   AliCDBManager* cdbManager = AliCDBManager::Instance();
372   if ( ! cdbManager->GetDefaultStorage() )
373     cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
374   
375   AliCDBMetaData* cdbData = new AliCDBMetaData();
376   cdbData->SetResponsible("Dimuon Offline project");
377   cdbData->SetComment("MUON run-dependent mapping");
378   cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
379   AliCDBId id("MUON/Calib/MappingRunData", 0, AliCDBRunRange::Infinity()); 
380
381   AliMpDataProcessor mp;
382   AliMpDataMap* map = mp.CreateDataMap("data_run");
383   return cdbManager->Put(map, id, cdbData);
384 }
385
386 //______________________________________________________________________________
387 Bool_t AliMpCDB::WriteMpSegmentation(Bool_t readData)
388 {
389 /// Write mapping segmentation in OCDB
390
391   if ( ! readData && ! AliMpSegmentation::Instance() ) return false;
392
393   AliCDBManager* cdbManager = AliCDBManager::Instance();
394   if ( ! cdbManager->GetDefaultStorage() )
395     cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
396   
397   AliCDBMetaData* cdbData = new AliCDBMetaData();
398   cdbData->SetResponsible("Dimuon Offline project");
399   cdbData->SetComment("MUON mapping");
400   cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
401   AliCDBId id("MUON/Calib/Mapping", 0, AliCDBRunRange::Infinity()); 
402
403   if ( readData ) {
404     AliMpDataStreams dataStreams;
405     AliMpSegmentation::ReadData(dataStreams, false);
406     AliMpDDLStore::ReadData(dataStreams, false);
407   }
408   
409   return cdbManager->Put(AliMpSegmentation::Instance(), id, cdbData);
410 }
411
412 //______________________________________________________________________________
413 Bool_t AliMpCDB::WriteDDLStore(Bool_t readData)
414 {
415 /// Write mapping DDL store in OCDB
416
417   if ( ! readData && ! AliMpDDLStore::Instance() ) return false;
418
419   AliCDBManager* cdbManager = AliCDBManager::Instance();
420   if ( ! cdbManager->GetDefaultStorage() )
421     cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
422   
423   AliCDBMetaData* cdbData = new AliCDBMetaData();
424   cdbData->SetResponsible("Dimuon Offline project");
425   cdbData->SetComment("MUON DDL store");
426   cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
427   AliCDBId id("MUON/Calib/DDLStore", 0, AliCDBRunRange::Infinity()); 
428
429   if ( readData ) {
430     AliMpDataStreams dataStreams;
431     AliMpSegmentation::ReadData(dataStreams, false);
432     AliMpDDLStore::ReadData(dataStreams, false);
433   }
434   return cdbManager->Put(AliMpDDLStore::Instance(), id, cdbData);
435 }   
436
437 //______________________________________________________________________________
438 Bool_t AliMpCDB::WriteManuStore(Bool_t readData)
439 {
440 /// Write mapping Manu store in OCDB
441
442   if ( ! readData && ! AliMpManuStore::Instance() ) return false;
443
444   AliCDBManager* cdbManager = AliCDBManager::Instance();
445   if ( ! cdbManager->GetDefaultStorage() )
446     cdbManager->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
447   
448   AliCDBMetaData* cdbData = new AliCDBMetaData();
449   cdbData->SetResponsible("Dimuon Offline project");
450   cdbData->SetComment("MUON Manu store");
451   cdbData->SetAliRootVersion(gSystem->Getenv("ARVERSION"));
452   AliCDBId id("MUON/Calib/ManuStore", 0, AliCDBRunRange::Infinity()); 
453
454   if ( readData ) {
455     AliMpDataStreams dataStreams;
456     AliMpSegmentation::ReadData(dataStreams, false);
457     AliMpManuStore::ReadData(dataStreams, false);
458   }
459   return cdbManager->Put(AliMpManuStore::Instance(), id, cdbData);
460 }   
461
462 //______________________________________________________________________________
463 Bool_t  AliMpCDB::GenerateMpData(const char* cdbpath, Int_t runNumber)
464 {
465 /// Generate mapping data ASCII files from OCDB
466
467   TObject* cdbEntryObject 
468     = GetCDBEntryObject("MUON/Calib/MappingData", cdbpath, runNumber);
469   if ( ! cdbEntryObject ) return kFALSE;
470   
471   AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
472   AliMpDataProcessor mp;
473   return mp.GenerateData(dataMap);
474
475
476 //______________________________________________________________________________
477 Bool_t  AliMpCDB::GenerateMpRunData(const char* cdbpath, Int_t runNumber)
478 {
479 /// Generate mapping data ASCII files from OCDB
480
481   TObject* cdbEntryObject 
482     = GetCDBEntryObject("MUON/Calib/MappingRunData", cdbpath, runNumber);
483   if ( ! cdbEntryObject ) return kFALSE;
484   
485   AliMpDataMap* dataMap = (AliMpDataMap*)cdbEntryObject;
486   AliMpDataProcessor mp;
487   return mp.GenerateData(dataMap);
488
489
490 //______________________________________________________________________________
491 void AliMpCDB::UnloadAll()
492 {
493   /// Unload all the mapping from the memory
494   delete AliMpDDLStore::Instance(false);
495   delete AliMpSegmentation::Instance(false);
496   delete AliMpDEStore::Instance(false);
497 }
498