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