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