]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibrationData.cxx
f5374ec948011befb053a464cfa9cd3efd3a92d1
[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     return 0x0;
156   }
157   
158   return static_cast<AliMUONVCalibParam*>(gains->Get(detElemId,manuId));
159 }
160
161 //_____________________________________________________________________________
162 AliMUONV2DStore*
163 AliMUONCalibrationData::Gains() const
164 {
165   /// Create (if needed) and return the internal store for gains.
166   return OnDemandGains();
167 }
168
169 //_____________________________________________________________________________
170 AliMUONV2DStore*
171 AliMUONCalibrationData::OnDemandGains() const
172 {
173 /// Create (if needed) and return the internal store for gains.
174
175   if (!fGains)
176   {
177     AliCDBEntry* entry = GetEntry("MUON/Calib/Gains");
178     if (entry)
179     {
180       fGains = dynamic_cast<AliMUONV2DStore*>(entry->GetObject());
181       if (!fGains)
182       {
183         AliError("Gains not of the expected type !!!");
184       }
185     }
186     else
187     {
188       AliError("Could not get gains !");
189     }
190   }
191   return fGains;
192 }
193
194 //_____________________________________________________________________________
195 AliMUONVCalibParam* 
196 AliMUONCalibrationData::GlobalTriggerBoardMasks() const
197 {
198 /// Return the masks for the global trigger board.
199
200   return OnDemandGlobalTriggerBoardMasks();
201 }
202
203 //_____________________________________________________________________________
204 AliMUONVCalibParam*
205 AliMUONCalibrationData::OnDemandGlobalTriggerBoardMasks() const
206 {
207 /// Create (if needed) and return the internal store for GlobalTriggerBoardMasks.
208
209   if (!fGlobalTriggerBoardMasks)
210   {
211     AliCDBEntry* entry = GetEntry("MUON/Calib/GlobalTriggerBoardMasks");
212     if (entry)
213     {
214       fGlobalTriggerBoardMasks = dynamic_cast<AliMUONVCalibParam*>(entry->GetObject());
215       if (!fGlobalTriggerBoardMasks)
216       {
217         AliError("fGlobalTriggerBoardMasks not of the expected type !!!");
218       }
219     }
220     else
221     {
222       AliError("Could not get global trigger board masks !");
223     }
224   }
225   return fGlobalTriggerBoardMasks;
226 }
227
228 //_____________________________________________________________________________
229 AliMUONVCalibParam* 
230 AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
231 {
232 /// Return the masks for a given trigger local board.
233
234   AliMUONV1DStore* store = OnDemandLocalTriggerBoardMasks();
235   if (!store)
236   {
237     AliError("Could not get LocalTriggerBoardMasks");
238     return 0x0;
239   }
240   
241   AliMUONVCalibParam* ltbm = 
242     static_cast<AliMUONVCalibParam*>(store->Get(localBoardNumber));
243   if (!ltbm)
244   {
245     AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
246   }
247   return ltbm;  
248 }
249
250 //_____________________________________________________________________________
251 AliMUONV1DStore*
252 AliMUONCalibrationData::OnDemandLocalTriggerBoardMasks() const
253 {
254 /// Create (if needed) and return the internal store for LocalTriggerBoardMasks.
255
256   if (!fLocalTriggerBoardMasks)
257   {
258     AliCDBEntry* entry = GetEntry("MUON/Calib/LocalTriggerBoardMasks");
259     if (entry)
260     {
261       fLocalTriggerBoardMasks = dynamic_cast<AliMUONV1DStore*>(entry->GetObject());
262       if (!fLocalTriggerBoardMasks)
263       {
264         AliError("fLocalTriggerBoardMasks not of the expected type !!!");
265       }
266     }
267     else
268     {
269       AliError("Could not get local trigger board masks !");
270     }
271   }
272   return fLocalTriggerBoardMasks;
273 }
274
275 //_____________________________________________________________________________
276 AliMUONV2DStore*
277 AliMUONCalibrationData::OnDemandPedestals() const
278 {
279 /// Create (if needed) and return the internal storage for pedestals.
280
281   if (!fPedestals)
282   {
283     AliCDBEntry* entry = GetEntry("MUON/Calib/Pedestals");
284     if (entry)
285     {
286       fPedestals = dynamic_cast<AliMUONV2DStore*>(entry->GetObject());
287       if (!fPedestals)
288       {
289         AliError("fPedestals not of the expected type !!!");
290       }
291     }
292     else
293     {
294       AliError("Could not get pedestals !");
295     }
296   }
297   return fPedestals;
298 }
299
300 //_____________________________________________________________________________
301 void
302 AliMUONCalibrationData::Print(Option_t*) const
303 {
304 /// A very basic dump of our guts.
305
306   cout << "RunNumber " << RunNumber()
307   << " fGains=" << fGains
308   << " fPedestals=" << fPedestals
309   << " fHV=" << fHV
310   << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
311   << " fRegionalTriggerBoardMasks=" << fRegionalTriggerBoardMasks
312   << " fGlobalTriggerBoardMasks=" << fGlobalTriggerBoardMasks
313   << " fTriggerLut=" << fTriggerLut
314   << endl;
315 }
316
317 //_____________________________________________________________________________
318 AliMUONV2DStore*
319 AliMUONCalibrationData::Pedestals() const
320 {
321   /// Return pedestals
322   return OnDemandPedestals();
323 }
324
325 //_____________________________________________________________________________
326 AliMUONVCalibParam*
327 AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
328 {
329 /// Return the pedestals for a given (detElemId, manuId) pair.
330 /// A return value of 0x0 is considered an error, meaning we should get
331 /// pedestals for all channels.
332
333   AliMUONV2DStore* pedestals = OnDemandPedestals();
334   if (!pedestals) 
335   {
336     return 0x0;
337   }
338   
339   return static_cast<AliMUONVCalibParam*>(pedestals->Get(detElemId,manuId));
340 }
341
342 //_____________________________________________________________________________
343 AliMUONVCalibParam* 
344 AliMUONCalibrationData::RegionalTriggerBoardMasks(Int_t index) const
345 {
346 /// Return the masks for a given trigger regional board.
347
348   AliMUONV1DStore* store = OnDemandRegionalTriggerBoardMasks();
349   
350   if (!store)
351   {
352     AliError("Could not get RegionalTriggerBoardMasks");
353     return 0x0;
354   }
355   
356   AliMUONVCalibParam* rtbm = 
357     static_cast<AliMUONVCalibParam*>(store->Get(index));
358   if (!rtbm)
359   {
360     AliError(Form("Could not get mask for regionalBoard index=%d",index));
361   }
362   return rtbm;  
363 }
364
365 //_____________________________________________________________________________
366 AliMUONV1DStore*
367 AliMUONCalibrationData::OnDemandRegionalTriggerBoardMasks() const
368 {
369 /// Create (if needed) and return the internal store for RegionalTriggerBoardMasks.
370
371   if (!fRegionalTriggerBoardMasks)
372   {
373     AliCDBEntry* entry = GetEntry("MUON/Calib/RegionalTriggerBoardMasks");
374     if (entry)
375     {
376       fRegionalTriggerBoardMasks = dynamic_cast<AliMUONV1DStore*>(entry->GetObject());
377       if (!fRegionalTriggerBoardMasks)
378       {
379         AliError("fRegionalTriggerBoardMasks not of the expected type !!!");
380       }
381     }
382     else
383     {
384       AliError("Could not get regional trigger board masks !");
385     }
386   }
387   return fRegionalTriggerBoardMasks;
388 }
389
390 //_____________________________________________________________________________
391 AliMUONTriggerEfficiencyCells*
392 AliMUONCalibrationData::TriggerEfficiency() const
393 {
394 /// Return the trigger efficiency.
395
396   return OnDemandTriggerEfficiency();
397 }
398
399 //_____________________________________________________________________________
400 AliMUONTriggerEfficiencyCells* 
401 AliMUONCalibrationData::OnDemandTriggerEfficiency() const
402 {
403 /// \todo: add comment
404
405   if (!fTriggerEfficiency)
406   {
407     AliCDBEntry* entry = GetEntry("MUON/Calib/TriggerEfficiency");
408     if (entry)
409     {
410       fTriggerEfficiency = dynamic_cast<AliMUONTriggerEfficiencyCells*>(entry->GetObject());
411       if (!fTriggerEfficiency)
412       {
413         AliError("fTriggerEfficiency not of the expected type !!!");
414       }
415     }
416     else
417     {
418       AliError("Could not get trigger efficiency !");
419     }
420   }
421   return fTriggerEfficiency;
422 }
423
424 //_____________________________________________________________________________
425 AliMUONTriggerLut*
426 AliMUONCalibrationData::TriggerLut() const
427 {
428 /// Return the trigger look up table.
429
430   return OnDemandTriggerLut();
431 }
432
433 //_____________________________________________________________________________
434 AliMUONTriggerLut* 
435 AliMUONCalibrationData::OnDemandTriggerLut() const
436 {
437 /// \todo: add comment
438
439   if (!fTriggerLut)
440   {
441     AliCDBEntry* entry = GetEntry("MUON/Calib/TriggerLut");
442     if (entry)
443     {
444       fTriggerLut = dynamic_cast<AliMUONTriggerLut*>(entry->GetObject());
445       if (!fTriggerLut)
446       {
447         AliError("fTriggerLut not of the expected type !!!");
448       }
449     }
450     else
451     {
452       AliError("Could not get trigger lut !");
453     }
454   }
455   return fTriggerLut;
456 }
457
458
459