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