Moving from base to calib (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibrationData.cxx
CommitLineData
c5bdf179 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"
c5bdf179 22#include "AliLog.h"
e7d7fa47 23#include "AliMUONTriggerEfficiencyCells.h"
24#include "AliMUONTriggerLut.h"
25#include "AliMUONV1DStore.h"
c3ce65fd 26#include "AliMUONV2DStore.h"
27#include "AliMUONVCalibParam.h"
c5bdf179 28#include "Riostream.h"
48ed403b 29#include "TMap.h"
c5bdf179 30
5398f946 31/// \class AliMUONCalibrationData
32///
48ed403b 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.
e7d7fa47 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///
5398f946 43/// \author Laurent Aphecetche
e7d7fa47 44
5398f946 45/// \cond CLASSIMP
c5bdf179 46ClassImp(AliMUONCalibrationData)
5398f946 47/// \endcond
c5bdf179 48
49//_____________________________________________________________________________
50AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber,
51 Bool_t deferredInitialization)
52: TObject(),
53fIsValid(kTRUE),
54fRunNumber(runNumber),
55fGains(0x0),
c3ce65fd 56fPedestals(0x0),
48ed403b 57fHV(0x0),
e7d7fa47 58fLocalTriggerBoardMasks(0x0),
59fRegionalTriggerBoardMasks(0x0),
60fGlobalTriggerBoardMasks(0x0),
61fTriggerLut(0x0),
c1bbaf66 62fTriggerEfficiency(0x0),
63fCapacitances(0x0)
c5bdf179 64{
5398f946 65/// Default ctor.
66
c3ce65fd 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.
5398f946 72
c5bdf179 73 if ( deferredInitialization == kFALSE )
74 {
e7d7fa47 75 OnDemandGains();
76 OnDemandPedestals();
48ed403b 77 OnDemandHV();
e7d7fa47 78 OnDemandLocalTriggerBoardMasks();
79 OnDemandRegionalTriggerBoardMasks();
80 OnDemandGlobalTriggerBoardMasks();
81 OnDemandTriggerLut();
82 OnDemandTriggerEfficiency();
c1bbaf66 83 OnDemandCapacitances();
c5bdf179 84 }
85}
86
e7d7fa47 87//_____________________________________________________________________________
c5bdf179 88AliMUONCalibrationData::~AliMUONCalibrationData()
89{
c1bbaf66 90 /// Destructor. Note that we're the owner of our pointers.
91 Reset();
c3ce65fd 92}
c3ce65fd 93//_____________________________________________________________________________
48ed403b 94TMap*
95AliMUONCalibrationData::HV() const
c3ce65fd 96{
5398f946 97/// Return the calibration for a given (detElemId, manuId) pair
5398f946 98
48ed403b 99 return OnDemandHV();
c3ce65fd 100}
101
102//_____________________________________________________________________________
48ed403b 103TMap*
104AliMUONCalibrationData::OnDemandHV() const
c3ce65fd 105{
5398f946 106/// Create (if needed) and return the internal store for DeadChannels.
107
48ed403b 108 if (!fHV)
c3ce65fd 109 {
48ed403b 110 AliCDBEntry* entry = GetEntry("MUON/Calib/HV");
c3ce65fd 111 if (entry)
112 {
48ed403b 113 fHV = dynamic_cast<TMap*>(entry->GetObject());
114 if (!fHV)
c3ce65fd 115 {
48ed403b 116 AliError("fHV not of the expected type !!!");
c3ce65fd 117 }
118 }
119 else
120 {
48ed403b 121 AliError("Could not get HV values !");
c3ce65fd 122 }
123 }
48ed403b 124 return fHV;
c5bdf179 125}
126
127//_____________________________________________________________________________
128AliCDBEntry*
129AliMUONCalibrationData::GetEntry(const char* path) const
130{
5398f946 131/// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
132/// and return the corresponding CDBEntry.
133
e7d7fa47 134 return AliCDBManager::Instance()->Get(path,fRunNumber);
c5bdf179 135}
136
137//_____________________________________________________________________________
c3ce65fd 138AliMUONVCalibParam*
e7d7fa47 139AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
c5bdf179 140{
5398f946 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
48ed403b 145 AliMUONV2DStore* gains = Gains();
146 if (!gains)
147 {
48ed403b 148 return 0x0;
149 }
150
56df3e46 151 return static_cast<AliMUONVCalibParam*>(gains->Get(detElemId,manuId));
48ed403b 152}
153
154//_____________________________________________________________________________
c1bbaf66 155AliMUONV1DStore*
156AliMUONCalibrationData::Capacitances() const
157{
158 /// Create (if needed) and return the internal store for capacitances.
159 return OnDemandCapacitances();
160}
161
162//_____________________________________________________________________________
48ed403b 163AliMUONV2DStore*
164AliMUONCalibrationData::Gains() const
165{
166 /// Create (if needed) and return the internal store for gains.
167 return OnDemandGains();
c5bdf179 168}
169
170//_____________________________________________________________________________
c1bbaf66 171AliMUONV1DStore*
172AliMUONCalibrationData::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//_____________________________________________________________________________
c3ce65fd 196AliMUONV2DStore*
e7d7fa47 197AliMUONCalibrationData::OnDemandGains() const
c5bdf179 198{
5398f946 199/// Create (if needed) and return the internal store for gains.
200
c5bdf179 201 if (!fGains)
202 {
203 AliCDBEntry* entry = GetEntry("MUON/Calib/Gains");
204 if (entry)
205 {
c3ce65fd 206 fGains = dynamic_cast<AliMUONV2DStore*>(entry->GetObject());
c5bdf179 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//_____________________________________________________________________________
e7d7fa47 221AliMUONVCalibParam*
222AliMUONCalibrationData::GlobalTriggerBoardMasks() const
223{
5398f946 224/// Return the masks for the global trigger board.
225
e7d7fa47 226 return OnDemandGlobalTriggerBoardMasks();
227}
228
229//_____________________________________________________________________________
230AliMUONVCalibParam*
231AliMUONCalibrationData::OnDemandGlobalTriggerBoardMasks() const
232{
5398f946 233/// Create (if needed) and return the internal store for GlobalTriggerBoardMasks.
234
e7d7fa47 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//_____________________________________________________________________________
255AliMUONVCalibParam*
256AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
257{
5398f946 258/// Return the masks for a given trigger local board.
259
48ed403b 260 AliMUONV1DStore* store = OnDemandLocalTriggerBoardMasks();
261 if (!store)
262 {
263 AliError("Could not get LocalTriggerBoardMasks");
264 return 0x0;
265 }
266
e7d7fa47 267 AliMUONVCalibParam* ltbm =
48ed403b 268 static_cast<AliMUONVCalibParam*>(store->Get(localBoardNumber));
e7d7fa47 269 if (!ltbm)
270 {
271 AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
272 }
273 return ltbm;
274}
275
276//_____________________________________________________________________________
277AliMUONV1DStore*
278AliMUONCalibrationData::OnDemandLocalTriggerBoardMasks() const
279{
5398f946 280/// Create (if needed) and return the internal store for LocalTriggerBoardMasks.
281
e7d7fa47 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//_____________________________________________________________________________
c3ce65fd 302AliMUONV2DStore*
e7d7fa47 303AliMUONCalibrationData::OnDemandPedestals() const
c5bdf179 304{
5398f946 305/// Create (if needed) and return the internal storage for pedestals.
306
c5bdf179 307 if (!fPedestals)
308 {
309 AliCDBEntry* entry = GetEntry("MUON/Calib/Pedestals");
310 if (entry)
311 {
c3ce65fd 312 fPedestals = dynamic_cast<AliMUONV2DStore*>(entry->GetObject());
c5bdf179 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//_____________________________________________________________________________
327void
328AliMUONCalibrationData::Print(Option_t*) const
329{
5398f946 330/// A very basic dump of our guts.
331
c5bdf179 332 cout << "RunNumber " << RunNumber()
e7d7fa47 333 << " fGains=" << fGains
334 << " fPedestals=" << fPedestals
48ed403b 335 << " fHV=" << fHV
e7d7fa47 336 << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
337 << " fRegionalTriggerBoardMasks=" << fRegionalTriggerBoardMasks
338 << " fGlobalTriggerBoardMasks=" << fGlobalTriggerBoardMasks
339 << " fTriggerLut=" << fTriggerLut
c5bdf179 340 << endl;
341}
342
48ed403b 343//_____________________________________________________________________________
344AliMUONV2DStore*
345AliMUONCalibrationData::Pedestals() const
346{
347 /// Return pedestals
348 return OnDemandPedestals();
349}
c5bdf179 350
351//_____________________________________________________________________________
c3ce65fd 352AliMUONVCalibParam*
e7d7fa47 353AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
c5bdf179 354{
5398f946 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
48ed403b 359 AliMUONV2DStore* pedestals = OnDemandPedestals();
360 if (!pedestals)
361 {
48ed403b 362 return 0x0;
363 }
364
56df3e46 365 return static_cast<AliMUONVCalibParam*>(pedestals->Get(detElemId,manuId));
c5bdf179 366}
367
e7d7fa47 368//_____________________________________________________________________________
369AliMUONVCalibParam*
370AliMUONCalibrationData::RegionalTriggerBoardMasks(Int_t index) const
371{
5398f946 372/// Return the masks for a given trigger regional board.
373
48ed403b 374 AliMUONV1DStore* store = OnDemandRegionalTriggerBoardMasks();
375
376 if (!store)
377 {
378 AliError("Could not get RegionalTriggerBoardMasks");
379 return 0x0;
380 }
381
e7d7fa47 382 AliMUONVCalibParam* rtbm =
48ed403b 383 static_cast<AliMUONVCalibParam*>(store->Get(index));
e7d7fa47 384 if (!rtbm)
385 {
386 AliError(Form("Could not get mask for regionalBoard index=%d",index));
387 }
388 return rtbm;
389}
390
391//_____________________________________________________________________________
392AliMUONV1DStore*
393AliMUONCalibrationData::OnDemandRegionalTriggerBoardMasks() const
394{
5398f946 395/// Create (if needed) and return the internal store for RegionalTriggerBoardMasks.
396
e7d7fa47 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//_____________________________________________________________________________
417AliMUONTriggerEfficiencyCells*
418AliMUONCalibrationData::TriggerEfficiency() const
419{
5398f946 420/// Return the trigger efficiency.
421
e7d7fa47 422 return OnDemandTriggerEfficiency();
423}
424
425//_____________________________________________________________________________
426AliMUONTriggerEfficiencyCells*
427AliMUONCalibrationData::OnDemandTriggerEfficiency() const
428{
5398f946 429/// \todo: add comment
430
e7d7fa47 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//_____________________________________________________________________________
451AliMUONTriggerLut*
452AliMUONCalibrationData::TriggerLut() const
453{
5398f946 454/// Return the trigger look up table.
455
e7d7fa47 456 return OnDemandTriggerLut();
457}
458
459//_____________________________________________________________________________
460AliMUONTriggerLut*
461AliMUONCalibrationData::OnDemandTriggerLut() const
462{
5398f946 463/// \todo: add comment
464
e7d7fa47 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
c1bbaf66 484//_____________________________________________________________________________
485void
486AliMUONCalibrationData::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
e7d7fa47 510
c5bdf179 511