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