]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibrationData.cxx
Default recoparam object
[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   Reset();
101 }
102
103 //_____________________________________________________________________________
104 AliMUONVStore*
105 AliMUONCalibrationData::Capacitances() const
106 {
107   /// Create (if needed) and return the internal store for capacitances.
108   
109   if (!fCapacitances)
110   {
111     fCapacitances = CreateCapacitances(fRunNumber);
112   }
113   return fCapacitances;
114 }
115
116 //_____________________________________________________________________________
117 AliMUONVStore*
118 AliMUONCalibrationData::CreateCapacitances(Int_t runNumber, Int_t* startOfValidity)
119 {
120   /// Create capa store from OCDB for a given run
121   
122   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Capacitances",startOfValidity));
123 }
124
125 //_____________________________________________________________________________
126 AliMUONVStore*
127 AliMUONCalibrationData::CreateGains(Int_t runNumber, Int_t* startOfValidity)
128 {
129   /// Create a new gain store from the OCDB for a given run
130   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Gains",startOfValidity));
131 }
132
133 //_____________________________________________________________________________
134 AliMUONGlobalCrateConfig*
135 AliMUONCalibrationData::CreateGlobalTriggerCrateConfig(Int_t runNumber, Int_t* startOfValidity)
136 {
137   /// Create the internal store for GlobalTriggerCrateConfig from OCDB
138   
139   return dynamic_cast<AliMUONGlobalCrateConfig*>(CreateObject(runNumber,"MUON/Calib/GlobalTriggerCrateConfig",startOfValidity));
140 }
141
142
143
144 //_____________________________________________________________________________
145 TMap*
146 AliMUONCalibrationData::CreateHV(Int_t runNumber, Int_t* startOfValidity)
147 {
148   /// Create a new HV map from the OCDB for a given run
149   return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
150 }
151
152 //_____________________________________________________________________________
153 AliMUONVStore*
154 AliMUONCalibrationData::CreateLocalTriggerBoardMasks(Int_t runNumber, Int_t* startOfValidity)
155 {
156   /// Get the internal store for LocalTriggerBoardMasks from OCDB
157   
158   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/LocalTriggerBoardMasks",startOfValidity));
159 }
160
161 //_____________________________________________________________________________
162 AliMUONVStore*
163 AliMUONCalibrationData::CreateNeighbours(Int_t runNumber, Int_t* startOfValidity)
164 {
165   /// Create a neighbour store from the OCDB for a given run
166   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Neighbours",startOfValidity));
167 }
168
169 //_____________________________________________________________________________
170 TObject*
171 AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path, Int_t* startOfValidity)
172 {
173   /// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
174   /// and return the corresponding TObject.
175   
176   AliCodeTimerAutoClass(Form("%d : %s",runNumber,path));
177   
178   AliCDBManager* man = AliCDBManager::Instance();
179   
180   AliCDBEntry* entry =  man->Get(path,runNumber);
181   
182   if (entry)
183   {
184                 if ( startOfValidity ) *startOfValidity = entry->GetId().GetFirstRun();
185                 
186     TObject* object = entry->GetObject();
187     entry->SetOwner(kFALSE);
188     if (!(man->GetCacheFlag())) delete entry;
189     return object;
190   }
191         else
192         {
193                 if ( startOfValidity )  *startOfValidity = AliCDBRunRange::Infinity();
194   }
195         
196   return 0x0;
197 }
198
199 //_____________________________________________________________________________
200 AliMUONVStore*
201 AliMUONCalibrationData::CreatePedestals(Int_t runNumber, Int_t* startOfValidity)
202 {
203   /// Create a new pedestal store from the OCDB for a given run
204   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Pedestals",startOfValidity));
205 }
206
207
208 //_____________________________________________________________________________
209 AliMUONRegionalTriggerConfig*
210 AliMUONCalibrationData::CreateRegionalTriggerConfig(Int_t runNumber, Int_t* startOfValidity)
211 {
212   /// Create the internal store for RegionalTriggerConfig from OCDB
213   
214   return dynamic_cast<AliMUONRegionalTriggerConfig*>(CreateObject(runNumber,"MUON/Calib/RegionalTriggerConfig",startOfValidity));
215 }
216
217 //_____________________________________________________________________________
218 AliMUONTriggerEfficiencyCells* 
219 AliMUONCalibrationData::CreateTriggerEfficiency(Int_t runNumber, Int_t* startOfValidity)
220 {
221   /// Create trigger efficiency object from OCBD
222   
223   return dynamic_cast<AliMUONTriggerEfficiencyCells*>(CreateObject(runNumber,"MUON/Calib/TriggerEfficiency",startOfValidity));
224 }
225
226 //_____________________________________________________________________________
227 AliMUONTriggerLut* 
228 AliMUONCalibrationData::CreateTriggerLut(Int_t runNumber, Int_t* startOfValidity)
229 {
230   /// Create trigger LUT from OCDB
231   
232   return dynamic_cast<AliMUONTriggerLut*>(CreateObject(runNumber,"MUON/Calib/TriggerLut",startOfValidity));
233 }
234
235 //_____________________________________________________________________________
236 AliMUONVStore*
237 AliMUONCalibrationData::Gains() const
238 {
239   /// Create (if needed) and return the internal store for gains.
240   if (!fGains)
241   {
242     fGains = CreateGains(fRunNumber);
243   }
244   return fGains;
245 }
246
247 //_____________________________________________________________________________
248 AliMUONVCalibParam*
249 AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
250 {
251 /// Return the gains for a given (detElemId, manuId) pair
252 /// Note that, unlike the DeadChannel case, if the result is 0x0, that's an
253 /// error (meaning that we should get gains for all channels).
254
255   AliMUONVStore* gains = Gains();
256   if (!gains)
257   {
258     return 0x0;
259   }
260   
261   return static_cast<AliMUONVCalibParam*>(gains->FindObject(detElemId,manuId));
262 }
263
264 //_____________________________________________________________________________
265 AliMUONGlobalCrateConfig* 
266 AliMUONCalibrationData::GlobalTriggerCrateConfig() const
267 {
268   /// Return the config for the global trigger board.
269   
270   if (!fGlobalTriggerCrateConfig)
271   {
272     fGlobalTriggerCrateConfig = CreateGlobalTriggerCrateConfig(fRunNumber);
273   }
274   return fGlobalTriggerCrateConfig;
275 }
276
277
278 //_____________________________________________________________________________
279 TMap*
280 AliMUONCalibrationData::HV() const
281 {
282   /// Return the calibration for a given (detElemId, manuId) pair
283   
284   if (!fHV)
285   {
286     fHV = CreateHV(fRunNumber);
287   }
288   return fHV;
289 }
290
291 //_____________________________________________________________________________
292 AliMUONVStore*
293 AliMUONCalibrationData::Neighbours() const
294 {
295   /// Create (if needed) and return the internal store for neighbours.
296   if (!fNeighbours)
297   {
298     fNeighbours = CreateNeighbours(fRunNumber);
299   }
300   return fNeighbours;
301 }
302
303 //_____________________________________________________________________________
304 AliMUONVCalibParam* 
305 AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
306 {
307 /// Return the masks for a given trigger local board.
308
309   if (!fLocalTriggerBoardMasks)
310   {
311     fLocalTriggerBoardMasks = CreateLocalTriggerBoardMasks(fRunNumber);
312   }
313
314   if ( fLocalTriggerBoardMasks ) 
315   {
316     AliMUONVCalibParam* ltbm = 
317       static_cast<AliMUONVCalibParam*>(fLocalTriggerBoardMasks->FindObject(localBoardNumber));
318     if (!ltbm)
319     {
320       AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
321     }
322     return ltbm;  
323   }
324   return 0x0;
325 }
326
327 //_____________________________________________________________________________
328 AliMUONVStore*
329 AliMUONCalibrationData::Pedestals() const
330 {
331   /// Return pedestals
332   if (!fPedestals)
333   {
334     fPedestals = CreatePedestals(fRunNumber);
335   }
336   return fPedestals;
337 }
338
339 //_____________________________________________________________________________
340 AliMUONVCalibParam*
341 AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
342 {
343   /// Return the pedestals for a given (detElemId, manuId) pair.
344   /// A return value of 0x0 is considered an error, meaning we should get
345   /// pedestals for all channels.
346   
347   AliMUONVStore* pedestals = Pedestals();
348   if (!pedestals) 
349   {
350     return 0x0;
351   }
352   
353   return static_cast<AliMUONVCalibParam*>(pedestals->FindObject(detElemId,manuId));
354 }
355
356 //_____________________________________________________________________________
357 void
358 AliMUONCalibrationData::Print(Option_t*) const
359 {
360   /// A very basic dump of our guts.
361
362   cout << "RunNumber " << RunNumber()
363   << " fGains=" << fGains
364   << " fPedestals=" << fPedestals
365   << " fHV=" << fHV
366   << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
367   << " fRegionalTriggerConfig=" << fRegionalTriggerConfig
368   << " fGlobalTriggerCrateConfig=" << fGlobalTriggerCrateConfig
369   << " fTriggerLut=" << fTriggerLut
370   << endl;
371 }
372
373
374 //_____________________________________________________________________________
375 AliMUONRegionalTriggerConfig* 
376 AliMUONCalibrationData::RegionalTriggerConfig() const
377 {
378   /// Return the config for the regional trigger board.
379   
380   if (!fRegionalTriggerConfig)
381   {
382     fRegionalTriggerConfig = CreateRegionalTriggerConfig(fRunNumber);
383     }
384   return fRegionalTriggerConfig;
385 }
386
387
388 //_____________________________________________________________________________
389 AliMUONTriggerEfficiencyCells*
390 AliMUONCalibrationData::TriggerEfficiency() const
391 {
392 /// Return the trigger efficiency.
393
394   if (!fTriggerEfficiency)
395   {
396     fTriggerEfficiency = CreateTriggerEfficiency(fRunNumber);
397   }
398   return fTriggerEfficiency;
399 }
400
401
402 //_____________________________________________________________________________
403 AliMUONTriggerLut*
404 AliMUONCalibrationData::TriggerLut() const
405 {
406 /// Return the trigger look up table.
407
408   if (!fTriggerLut)
409   {
410     fTriggerLut = CreateTriggerLut(fRunNumber);
411   }
412   return fTriggerLut;
413 }
414
415 //_____________________________________________________________________________
416 void
417 AliMUONCalibrationData::Reset()
418 {
419 /// Reset all data
420
421   delete fPedestals;
422   fPedestals = 0x0;
423   delete fGains;
424   fGains = 0x0;
425   delete fHV;
426   fHV = 0x0;
427   delete fLocalTriggerBoardMasks;
428   fLocalTriggerBoardMasks = 0x0;
429   delete fRegionalTriggerConfig;
430   fRegionalTriggerConfig = 0x0;
431   delete fGlobalTriggerCrateConfig;
432   fGlobalTriggerCrateConfig = 0x0;
433   
434   delete fTriggerLut;
435   fTriggerLut = 0x0;
436   delete fTriggerEfficiency;
437   fTriggerEfficiency = 0x0;
438   delete fCapacitances;
439   fCapacitances = 0x0;
440   delete fNeighbours;
441   fNeighbours = 0x0;
442 }
443
444 //_____________________________________________________________________________
445 void
446 AliMUONCalibrationData::Check(Int_t runNumber)
447 {
448   /// Self-check to see if we can read all data for a given run 
449   /// from the current OCDB...
450   
451   if ( ! CreateCapacitances(runNumber) )
452   {
453     AliErrorClass("Could not read capacitances");
454   }
455   else
456   {
457     AliInfoClass("Capacitances read OK");
458   }
459
460   if ( ! CreateGains(runNumber) ) 
461   {
462     AliErrorClass("Could not read gains");
463   }
464   else
465   {
466     AliInfoClass("Gains read OK");
467   }
468
469   if ( ! CreateGlobalTriggerCrateConfig(runNumber) ) 
470   {
471     AliErrorClass("Could not read Trigger Crate Config");
472   }
473   else
474   {
475     AliInfoClass("TriggerBoardMasks read OK");
476   }
477
478   if ( !  CreateHV(runNumber) )
479   {
480     AliErrorClass("Could not read HV");
481   }
482   else
483   {
484     AliInfoClass("HV read OK");
485   }
486
487   if ( ! CreateNeighbours(runNumber) )
488   {
489     AliErrorClass("Could not read Neighbours");
490   }
491   else
492   {
493     AliInfoClass("Neighbours read OK");
494   }
495
496   if ( !  CreateLocalTriggerBoardMasks(runNumber) )
497   {
498     AliErrorClass("Could not read LocalTriggerBoardMasks");
499   }
500   else
501   {
502     AliInfoClass("LocalTriggerBoardMasks read OK");
503   }
504   
505   if ( ! CreatePedestals(runNumber) )
506   {
507     AliErrorClass("Could not read pedestals");
508   }
509   else
510   {
511     AliInfoClass("Pedestals read OK");
512   }
513   
514   if ( ! CreateRegionalTriggerConfig(runNumber) )
515   {
516     AliErrorClass("Could not read RegionalTriggerConfig");
517   }
518   else
519   {
520     AliInfoClass("RegionalTriggerBoardMasks read OK");
521   }
522   
523   if ( ! CreateTriggerLut(runNumber) )
524   {
525     AliErrorClass("Could not read TriggerLut");
526   }
527   else
528   {
529     AliInfoClass("TriggerLut read OK");
530   }
531
532   if ( ! CreateTriggerEfficiency(runNumber) )
533   {
534     AliErrorClass("Could not read TriggerEfficiency");
535   }
536   else    
537   {
538     AliInfoClass("TriggerEfficiency read OK");
539   }
540 }
541
542