]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibrationData.cxx
New class for AOD<->MC association
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibrationData.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
18 #include "AliMUONCalibrationData.h"
19
20 #include "AliCDBEntry.h"
21 #include "AliCDBManager.h"
22 #include "AliCodeTimer.h"
23 #include "AliLog.h"
24 #include "AliMUONTriggerEfficiencyCells.h"
25 #include "AliMUONTriggerLut.h"
26 #include "AliMUONVStore.h"
27 #include "AliMUONVStore.h"
28 #include "AliMUONVCalibParam.h"
29 #include "AliMUONGlobalCrateConfig.h"
30 #include "AliMUONRegionalTriggerConfig.h"
31
32 #include <Riostream.h>
33 #include <TClass.h>
34 #include <TMap.h>
35
36 //-----------------------------------------------------------------------------
37 /// \class AliMUONCalibrationData
38 ///
39 /// For the moment, this class stores pedestals, gains, hv (for tracker)
40 /// and lut, masks and efficiencies (for trigger) that are fetched from the CDB.
41 ///
42 /// This class is to be considered as a convenience class.
43 /// Its aim is to ease retrieval of calibration data from the 
44 /// condition database.
45 ///
46 /// It acts as a "facade" to a bunch of underlying 
47 /// containers/calibration classes.
48 ///
49 /// \author Laurent Aphecetche
50 //-----------------------------------------------------------------------------
51
52 /// \cond CLASSIMP
53 ClassImp(AliMUONCalibrationData)
54 /// \endcond
55
56 //_____________________________________________________________________________
57 AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber, 
58                                                Bool_t deferredInitialization) 
59 : TObject(), 
60 fIsValid(kTRUE),
61 fRunNumber(runNumber), 
62 fGains(0x0), 
63 fPedestals(0x0),
64 fHV(0x0),
65 fLocalTriggerBoardMasks(0x0),
66 fRegionalTriggerConfig(0x0),
67 fGlobalTriggerCrateConfig(0x0),
68 fTriggerLut(0x0),
69 fTriggerEfficiency(0x0),
70 fCapacitances(0x0),
71 fNeighbours(0x0)
72 {
73 /// Default ctor.
74
75   // If deferredInitialization is false, we read *all* calibrations
76   // at once.
77   // So when using this class to access only one kind of calibrations (e.g.
78   // only pedestals), you should put deferredInitialization to kTRUE, which
79   // will instruct this object to fetch the data only when neeeded.
80
81   if ( deferredInitialization == kFALSE )
82   {
83     Gains();
84     Pedestals();
85     HV();
86     LocalTriggerBoardMasks(0);
87     RegionalTriggerConfig();
88     GlobalTriggerCrateConfig();
89     TriggerLut();
90     TriggerEfficiency();
91     Capacitances();
92     Neighbours();
93   }
94 }
95
96 //_____________________________________________________________________________
97 AliMUONCalibrationData::~AliMUONCalibrationData()
98 {
99   /// Destructor. Note that we're the owner of our pointers.
100   //PH The owner of the objects is CDB, do not delete them!
101   //  Reset();
102 }
103
104 //_____________________________________________________________________________
105 AliMUONVStore*
106 AliMUONCalibrationData::Capacitances() const
107 {
108   /// Create (if needed) and return the internal store for capacitances.
109   
110   if (!fCapacitances)
111   {
112     fCapacitances = CreateCapacitances(fRunNumber);
113   }
114   return fCapacitances;
115 }
116
117 //_____________________________________________________________________________
118 AliMUONVStore*
119 AliMUONCalibrationData::CreateCapacitances(Int_t runNumber, Int_t* startOfValidity)
120 {
121   /// Create capa store from OCDB for a given run
122   
123   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Capacitances",startOfValidity));
124 }
125
126 //_____________________________________________________________________________
127 AliMUONVStore*
128 AliMUONCalibrationData::CreateGains(Int_t runNumber, Int_t* startOfValidity)
129 {
130   /// Create a new gain store from the OCDB for a given run
131   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Gains",startOfValidity));
132 }
133
134 //_____________________________________________________________________________
135 AliMUONGlobalCrateConfig*
136 AliMUONCalibrationData::CreateGlobalTriggerCrateConfig(Int_t runNumber, Int_t* startOfValidity)
137 {
138   /// Create the internal store for GlobalTriggerCrateConfig from OCDB
139   
140   return dynamic_cast<AliMUONGlobalCrateConfig*>(CreateObject(runNumber,"MUON/Calib/GlobalTriggerCrateConfig",startOfValidity));
141 }
142
143
144
145 //_____________________________________________________________________________
146 TMap*
147 AliMUONCalibrationData::CreateHV(Int_t runNumber, Int_t* startOfValidity)
148 {
149   /// Create a new HV map from the OCDB for a given run
150   return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
151 }
152
153 //_____________________________________________________________________________
154 AliMUONVStore*
155 AliMUONCalibrationData::CreateLocalTriggerBoardMasks(Int_t runNumber, Int_t* startOfValidity)
156 {
157   /// Get the internal store for LocalTriggerBoardMasks from OCDB
158   
159   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/LocalTriggerBoardMasks",startOfValidity));
160 }
161
162 //_____________________________________________________________________________
163 AliMUONVStore*
164 AliMUONCalibrationData::CreateNeighbours(Int_t runNumber, Int_t* startOfValidity)
165 {
166   /// Create a neighbour store from the OCDB for a given run
167   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Neighbours",startOfValidity));
168 }
169
170 //_____________________________________________________________________________
171 TObject*
172 AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path, Int_t* startOfValidity)
173 {
174   /// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
175   /// and return the corresponding TObject.
176   
177   AliCodeTimerAutoClass(Form("%d : %s",runNumber,path));
178   
179   AliCDBManager* man = AliCDBManager::Instance();
180   
181   AliCDBEntry* entry =  man->Get(path,runNumber);
182   
183   if (entry)
184   {
185                 if ( startOfValidity ) *startOfValidity = entry->GetId().GetFirstRun();
186                 
187     TObject* object = entry->GetObject();
188     entry->SetOwner(kFALSE);
189     if (!(man->GetCacheFlag())) delete entry;
190     return object;
191   }
192         else
193         {
194                 if ( startOfValidity )  *startOfValidity = AliCDBRunRange::Infinity();
195   }
196         
197   return 0x0;
198 }
199
200 //_____________________________________________________________________________
201 AliMUONVStore*
202 AliMUONCalibrationData::CreatePedestals(Int_t runNumber, Int_t* startOfValidity)
203 {
204   /// Create a new pedestal store from the OCDB for a given run
205   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Pedestals",startOfValidity));
206 }
207
208
209 //_____________________________________________________________________________
210 AliMUONRegionalTriggerConfig*
211 AliMUONCalibrationData::CreateRegionalTriggerConfig(Int_t runNumber, Int_t* startOfValidity)
212 {
213   /// Create the internal store for RegionalTriggerConfig from OCDB
214   
215   return dynamic_cast<AliMUONRegionalTriggerConfig*>(CreateObject(runNumber,"MUON/Calib/RegionalTriggerConfig",startOfValidity));
216 }
217
218 //_____________________________________________________________________________
219 AliMUONTriggerEfficiencyCells* 
220 AliMUONCalibrationData::CreateTriggerEfficiency(Int_t runNumber, Int_t* startOfValidity)
221 {
222   /// Create trigger efficiency object from OCBD
223   
224   return dynamic_cast<AliMUONTriggerEfficiencyCells*>(CreateObject(runNumber,"MUON/Calib/TriggerEfficiency",startOfValidity));
225 }
226
227 //_____________________________________________________________________________
228 AliMUONTriggerLut* 
229 AliMUONCalibrationData::CreateTriggerLut(Int_t runNumber, Int_t* startOfValidity)
230 {
231   /// Create trigger LUT from OCDB
232   
233   return dynamic_cast<AliMUONTriggerLut*>(CreateObject(runNumber,"MUON/Calib/TriggerLut",startOfValidity));
234 }
235
236 //_____________________________________________________________________________
237 AliMUONVStore*
238 AliMUONCalibrationData::Gains() const
239 {
240   /// Create (if needed) and return the internal store for gains.
241   if (!fGains)
242   {
243     fGains = CreateGains(fRunNumber);
244   }
245   return fGains;
246 }
247
248 //_____________________________________________________________________________
249 AliMUONVCalibParam*
250 AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
251 {
252 /// Return the gains for a given (detElemId, manuId) pair
253 /// Note that, unlike the DeadChannel case, if the result is 0x0, that's an
254 /// error (meaning that we should get gains for all channels).
255
256   AliMUONVStore* gains = Gains();
257   if (!gains)
258   {
259     return 0x0;
260   }
261   
262   return static_cast<AliMUONVCalibParam*>(gains->FindObject(detElemId,manuId));
263 }
264
265 //_____________________________________________________________________________
266 AliMUONGlobalCrateConfig* 
267 AliMUONCalibrationData::GlobalTriggerCrateConfig() const
268 {
269   /// Return the config for the global trigger board.
270   
271   if (!fGlobalTriggerCrateConfig)
272   {
273     fGlobalTriggerCrateConfig = CreateGlobalTriggerCrateConfig(fRunNumber);
274   }
275   return fGlobalTriggerCrateConfig;
276 }
277
278
279 //_____________________________________________________________________________
280 TMap*
281 AliMUONCalibrationData::HV() const
282 {
283   /// Return the calibration for a given (detElemId, manuId) pair
284   
285   if (!fHV)
286   {
287     fHV = CreateHV(fRunNumber);
288   }
289   return fHV;
290 }
291
292 //_____________________________________________________________________________
293 AliMUONVStore*
294 AliMUONCalibrationData::Neighbours() const
295 {
296   /// Create (if needed) and return the internal store for neighbours.
297   if (!fNeighbours)
298   {
299     fNeighbours = CreateNeighbours(fRunNumber);
300   }
301   return fNeighbours;
302 }
303
304 //_____________________________________________________________________________
305 AliMUONVCalibParam* 
306 AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
307 {
308 /// Return the masks for a given trigger local board.
309
310   if (!fLocalTriggerBoardMasks)
311   {
312     fLocalTriggerBoardMasks = CreateLocalTriggerBoardMasks(fRunNumber);
313   }
314
315   if ( fLocalTriggerBoardMasks ) 
316   {
317     AliMUONVCalibParam* ltbm = 
318       static_cast<AliMUONVCalibParam*>(fLocalTriggerBoardMasks->FindObject(localBoardNumber));
319     if (!ltbm)
320     {
321       AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
322     }
323     return ltbm;  
324   }
325   return 0x0;
326 }
327
328 //_____________________________________________________________________________
329 AliMUONVStore*
330 AliMUONCalibrationData::Pedestals() const
331 {
332   /// Return pedestals
333   if (!fPedestals)
334   {
335     fPedestals = CreatePedestals(fRunNumber);
336   }
337   return fPedestals;
338 }
339
340 //_____________________________________________________________________________
341 AliMUONVCalibParam*
342 AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
343 {
344   /// Return the pedestals for a given (detElemId, manuId) pair.
345   /// A return value of 0x0 is considered an error, meaning we should get
346   /// pedestals for all channels.
347   
348   AliMUONVStore* pedestals = Pedestals();
349   if (!pedestals) 
350   {
351     return 0x0;
352   }
353   
354   return static_cast<AliMUONVCalibParam*>(pedestals->FindObject(detElemId,manuId));
355 }
356
357 //_____________________________________________________________________________
358 void
359 AliMUONCalibrationData::Print(Option_t*) const
360 {
361   /// A very basic dump of our guts.
362
363   cout << "RunNumber " << RunNumber()
364   << " fGains=" << fGains
365   << " fPedestals=" << fPedestals
366   << " fHV=" << fHV
367   << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
368   << " fRegionalTriggerConfig=" << fRegionalTriggerConfig
369   << " fGlobalTriggerCrateConfig=" << fGlobalTriggerCrateConfig
370   << " fTriggerLut=" << fTriggerLut
371   << endl;
372 }
373
374
375 //_____________________________________________________________________________
376 AliMUONRegionalTriggerConfig* 
377 AliMUONCalibrationData::RegionalTriggerConfig() const
378 {
379   /// Return the config for the regional trigger board.
380   
381   if (!fRegionalTriggerConfig)
382   {
383     fRegionalTriggerConfig = CreateRegionalTriggerConfig(fRunNumber);
384     }
385   return fRegionalTriggerConfig;
386 }
387
388
389 //_____________________________________________________________________________
390 AliMUONTriggerEfficiencyCells*
391 AliMUONCalibrationData::TriggerEfficiency() const
392 {
393 /// Return the trigger efficiency.
394
395   if (!fTriggerEfficiency)
396   {
397     fTriggerEfficiency = CreateTriggerEfficiency(fRunNumber);
398   }
399   return fTriggerEfficiency;
400 }
401
402
403 //_____________________________________________________________________________
404 AliMUONTriggerLut*
405 AliMUONCalibrationData::TriggerLut() const
406 {
407 /// Return the trigger look up table.
408
409   if (!fTriggerLut)
410   {
411     fTriggerLut = CreateTriggerLut(fRunNumber);
412   }
413   return fTriggerLut;
414 }
415
416 //_____________________________________________________________________________
417 void
418 AliMUONCalibrationData::Reset()
419 {
420 /// Reset all data
421
422   delete fPedestals;
423   fPedestals = 0x0;
424   delete fGains;
425   fGains = 0x0;
426   delete fHV;
427   fHV = 0x0;
428   delete fLocalTriggerBoardMasks;
429   fLocalTriggerBoardMasks = 0x0;
430   delete fRegionalTriggerConfig;
431   fRegionalTriggerConfig = 0x0;
432   delete fGlobalTriggerCrateConfig;
433   fGlobalTriggerCrateConfig = 0x0;
434   
435   delete fTriggerLut;
436   fTriggerLut = 0x0;
437   delete fTriggerEfficiency;
438   fTriggerEfficiency = 0x0;
439   delete fCapacitances;
440   fCapacitances = 0x0;
441   delete fNeighbours;
442   fNeighbours = 0x0;
443 }
444
445 //_____________________________________________________________________________
446 void
447 AliMUONCalibrationData::Check(Int_t runNumber)
448 {
449   /// Self-check to see if we can read all data for a given run 
450   /// from the current OCDB...
451   
452   if ( ! CreateCapacitances(runNumber) )
453   {
454     AliErrorClass("Could not read capacitances");
455   }
456   else
457   {
458     AliInfoClass("Capacitances read OK");
459   }
460
461   if ( ! CreateGains(runNumber) ) 
462   {
463     AliErrorClass("Could not read gains");
464   }
465   else
466   {
467     AliInfoClass("Gains read OK");
468   }
469
470   if ( ! CreateGlobalTriggerCrateConfig(runNumber) ) 
471   {
472     AliErrorClass("Could not read Trigger Crate Config");
473   }
474   else
475   {
476     AliInfoClass("TriggerBoardMasks read OK");
477   }
478
479   if ( !  CreateHV(runNumber) )
480   {
481     AliErrorClass("Could not read HV");
482   }
483   else
484   {
485     AliInfoClass("HV read OK");
486   }
487
488   if ( ! CreateNeighbours(runNumber) )
489   {
490     AliErrorClass("Could not read Neighbours");
491   }
492   else
493   {
494     AliInfoClass("Neighbours read OK");
495   }
496
497   if ( !  CreateLocalTriggerBoardMasks(runNumber) )
498   {
499     AliErrorClass("Could not read LocalTriggerBoardMasks");
500   }
501   else
502   {
503     AliInfoClass("LocalTriggerBoardMasks read OK");
504   }
505   
506   if ( ! CreatePedestals(runNumber) )
507   {
508     AliErrorClass("Could not read pedestals");
509   }
510   else
511   {
512     AliInfoClass("Pedestals read OK");
513   }
514   
515   if ( ! CreateRegionalTriggerConfig(runNumber) )
516   {
517     AliErrorClass("Could not read RegionalTriggerConfig");
518   }
519   else
520   {
521     AliInfoClass("RegionalTriggerBoardMasks read OK");
522   }
523   
524   if ( ! CreateTriggerLut(runNumber) )
525   {
526     AliErrorClass("Could not read TriggerLut");
527   }
528   else
529   {
530     AliInfoClass("TriggerLut read OK");
531   }
532
533   if ( ! CreateTriggerEfficiency(runNumber) )
534   {
535     AliErrorClass("Could not read TriggerEfficiency");
536   }
537   else    
538   {
539     AliInfoClass("TriggerEfficiency read OK");
540   }
541 }
542
543