Bug fix
[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"
a0eca509 25#include "AliMUONVStore.h"
26#include "AliMUONVStore.h"
c3ce65fd 27#include "AliMUONVCalibParam.h"
c5bdf179 28#include "Riostream.h"
48ed403b 29#include "TMap.h"
c5bdf179 30
3d1463c8 31//-----------------------------------------------------------------------------
5398f946 32/// \class AliMUONCalibrationData
33///
48ed403b 34/// For the moment, this class stores pedestals, gains, hv (for tracker)
35/// and lut, masks and efficiencies (for trigger) that are fetched from the CDB.
e7d7fa47 36///
37/// This class is to be considered as a convenience class.
38/// Its aim is to ease retrieval of calibration data from the
39/// condition database.
40///
41/// It acts as a "facade" to a bunch of underlying
42/// containers/calibration classes.
43///
5398f946 44/// \author Laurent Aphecetche
3d1463c8 45//-----------------------------------------------------------------------------
e7d7fa47 46
5398f946 47/// \cond CLASSIMP
c5bdf179 48ClassImp(AliMUONCalibrationData)
5398f946 49/// \endcond
c5bdf179 50
51//_____________________________________________________________________________
52AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber,
53 Bool_t deferredInitialization)
54: TObject(),
55fIsValid(kTRUE),
56fRunNumber(runNumber),
57fGains(0x0),
c3ce65fd 58fPedestals(0x0),
48ed403b 59fHV(0x0),
e7d7fa47 60fLocalTriggerBoardMasks(0x0),
61fRegionalTriggerBoardMasks(0x0),
62fGlobalTriggerBoardMasks(0x0),
63fTriggerLut(0x0),
c1bbaf66 64fTriggerEfficiency(0x0),
d067ba7c 65fCapacitances(0x0),
66fNeighbours(0x0)
c5bdf179 67{
5398f946 68/// Default ctor.
69
c3ce65fd 70 // If deferredInitialization is false, we read *all* calibrations
71 // at once.
72 // So when using this class to access only one kind of calibrations (e.g.
73 // only pedestals), you should put deferredInitialization to kTRUE, which
74 // will instruct this object to fetch the data only when neeeded.
5398f946 75
c5bdf179 76 if ( deferredInitialization == kFALSE )
77 {
5562688f 78 Gains();
79 Pedestals();
80 HV();
81 LocalTriggerBoardMasks(0);
82 RegionalTriggerBoardMasks(0);
83 GlobalTriggerBoardMasks();
84 TriggerLut();
85 TriggerEfficiency();
86 Capacitances();
87 Neighbours();
c5bdf179 88 }
89}
90
c5bdf179 91//_____________________________________________________________________________
92AliMUONCalibrationData::~AliMUONCalibrationData()
93{
c1bbaf66 94 /// Destructor. Note that we're the owner of our pointers.
95 Reset();
c3ce65fd 96}
c3ce65fd 97
98//_____________________________________________________________________________
5562688f 99AliMUONVStore*
100AliMUONCalibrationData::Capacitances() const
c3ce65fd 101{
5562688f 102 /// Create (if needed) and return the internal store for capacitances.
103
104 if (!fCapacitances)
c3ce65fd 105 {
5562688f 106 fCapacitances = CreateCapacitances(fRunNumber);
c3ce65fd 107 }
5562688f 108 return fCapacitances;
c5bdf179 109}
110
111//_____________________________________________________________________________
5562688f 112AliMUONVStore*
113AliMUONCalibrationData::CreateCapacitances(Int_t runNumber)
c5bdf179 114{
5562688f 115 /// Create capa store from OCDB for a given run
116
117 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Capacitances"));
118}
5398f946 119
5562688f 120//_____________________________________________________________________________
121AliMUONVStore*
122AliMUONCalibrationData::CreateGains(Int_t runNumber)
123{
124 /// Create a new gain store from the OCDB for a given run
125 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Gains"));
c5bdf179 126}
127
128//_____________________________________________________________________________
c3ce65fd 129AliMUONVCalibParam*
5562688f 130AliMUONCalibrationData::CreateGlobalTriggerBoardMasks(Int_t runNumber)
c5bdf179 131{
5562688f 132 /// Create the internal store for GlobalTriggerBoardMasks from OCDB
48ed403b 133
5562688f 134 return dynamic_cast<AliMUONVCalibParam*>(CreateObject(runNumber,"MUON/Calib/GlobalTriggerBoardMasks"));
48ed403b 135}
136
c1bbaf66 137//_____________________________________________________________________________
5562688f 138TMap*
139AliMUONCalibrationData::CreateHV(Int_t runNumber)
c1bbaf66 140{
5562688f 141 /// Create a new HV map from the OCDB for a given run
142 return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV"));
c1bbaf66 143}
144
d067ba7c 145//_____________________________________________________________________________
a0eca509 146AliMUONVStore*
5562688f 147AliMUONCalibrationData::CreateLocalTriggerBoardMasks(Int_t runNumber)
d067ba7c 148{
5562688f 149 /// Get the internal store for LocalTriggerBoardMasks from OCDB
150
151 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/LocalTriggerBoardMasks"));
d067ba7c 152}
153
48ed403b 154//_____________________________________________________________________________
a0eca509 155AliMUONVStore*
5562688f 156AliMUONCalibrationData::CreateNeighbours(Int_t runNumber)
48ed403b 157{
5562688f 158 /// Create a neighbour store from the OCDB for a given run
159 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Neighbours"));
c5bdf179 160}
161
d067ba7c 162//_____________________________________________________________________________
5562688f 163TObject*
164AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path)
d067ba7c 165{
5562688f 166 /// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
167 /// and return the corresponding TObject.
d067ba7c 168
5562688f 169 AliCDBManager* man = AliCDBManager::Instance();
170
171 Bool_t cacheStatus = man->GetCacheFlag();
172
173 man->SetCacheFlag(kFALSE);
174
175 AliCDBEntry* entry = AliCDBManager::Instance()->Get(path,runNumber);
176
177 man->SetCacheFlag(cacheStatus);
178
179 if (entry)
d067ba7c 180 {
5562688f 181 return entry->GetObject();
d067ba7c 182 }
5562688f 183
184 return 0x0;
d067ba7c 185}
186
c1bbaf66 187//_____________________________________________________________________________
a0eca509 188AliMUONVStore*
5562688f 189AliMUONCalibrationData::CreatePedestals(Int_t runNumber)
c1bbaf66 190{
5562688f 191 /// Create a new pedestal store from the OCDB for a given run
192 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Pedestals"));
c1bbaf66 193}
194
c5bdf179 195//_____________________________________________________________________________
a0eca509 196AliMUONVStore*
5562688f 197AliMUONCalibrationData::CreateRegionalTriggerBoardMasks(Int_t runNumber)
198{
199 /// Create the internal store for RegionalTriggerBoardMasks from OCDB
200
201 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/RegionalTriggerBoardMasks"));
202}
203
204//_____________________________________________________________________________
205AliMUONTriggerEfficiencyCells*
206AliMUONCalibrationData::CreateTriggerEfficiency(Int_t runNumber)
c5bdf179 207{
5562688f 208 /// Create trigger efficiency object from OCBD
209
210 return dynamic_cast<AliMUONTriggerEfficiencyCells*>(CreateObject(runNumber,"MUON/Calib/TriggerEfficiency"));
211}
5398f946 212
5562688f 213//_____________________________________________________________________________
214AliMUONTriggerLut*
215AliMUONCalibrationData::CreateTriggerLut(Int_t runNumber)
216{
217 /// Create trigger LUT from OCDB
218
219 return dynamic_cast<AliMUONTriggerLut*>(CreateObject(runNumber,"MUON/Calib/TriggerLut"));
220}
221
222//_____________________________________________________________________________
223AliMUONVStore*
224AliMUONCalibrationData::Gains() const
225{
226 /// Create (if needed) and return the internal store for gains.
c5bdf179 227 if (!fGains)
228 {
5562688f 229 fGains = CreateGains(fRunNumber);
c5bdf179 230 }
231 return fGains;
232}
233
e7d7fa47 234//_____________________________________________________________________________
5562688f 235AliMUONVCalibParam*
236AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
e7d7fa47 237{
5562688f 238/// Return the gains for a given (detElemId, manuId) pair
239/// Note that, unlike the DeadChannel case, if the result is 0x0, that's an
240/// error (meaning that we should get gains for all channels).
5398f946 241
5562688f 242 AliMUONVStore* gains = Gains();
243 if (!gains)
244 {
245 return 0x0;
246 }
247
248 return static_cast<AliMUONVCalibParam*>(gains->FindObject(detElemId,manuId));
e7d7fa47 249}
250
251//_____________________________________________________________________________
5562688f 252AliMUONVCalibParam*
253AliMUONCalibrationData::GlobalTriggerBoardMasks() const
e7d7fa47 254{
5562688f 255 /// Return the masks for the global trigger board.
256
e7d7fa47 257 if (!fGlobalTriggerBoardMasks)
258 {
5562688f 259 fGlobalTriggerBoardMasks = CreateGlobalTriggerBoardMasks(fRunNumber);
e7d7fa47 260 }
261 return fGlobalTriggerBoardMasks;
262}
263
264//_____________________________________________________________________________
5562688f 265TMap*
266AliMUONCalibrationData::HV() const
e7d7fa47 267{
5562688f 268 /// Return the calibration for a given (detElemId, manuId) pair
48ed403b 269
5562688f 270 if (!fHV)
e7d7fa47 271 {
5562688f 272 fHV = CreateHV(fRunNumber);
e7d7fa47 273 }
5562688f 274 return fHV;
e7d7fa47 275}
276
277//_____________________________________________________________________________
a0eca509 278AliMUONVStore*
5562688f 279AliMUONCalibrationData::Neighbours() const
e7d7fa47 280{
5562688f 281 /// Create (if needed) and return the internal store for neighbours.
282 if (!fNeighbours)
283 {
284 fNeighbours = CreateNeighbours(fRunNumber);
285 }
286 return fNeighbours;
287}
288
289//_____________________________________________________________________________
290AliMUONVCalibParam*
291AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
292{
293/// Return the masks for a given trigger local board.
5398f946 294
e7d7fa47 295 if (!fLocalTriggerBoardMasks)
296 {
5562688f 297 fLocalTriggerBoardMasks = CreateLocalTriggerBoardMasks(fRunNumber);
298 }
299
300 if ( fLocalTriggerBoardMasks )
301 {
302 AliMUONVCalibParam* ltbm =
303 static_cast<AliMUONVCalibParam*>(fLocalTriggerBoardMasks->FindObject(localBoardNumber));
304 if (!ltbm)
e7d7fa47 305 {
5562688f 306 AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
e7d7fa47 307 }
5562688f 308 return ltbm;
e7d7fa47 309 }
5562688f 310 return 0x0;
e7d7fa47 311}
312
c5bdf179 313//_____________________________________________________________________________
a0eca509 314AliMUONVStore*
5562688f 315AliMUONCalibrationData::Pedestals() const
c5bdf179 316{
5562688f 317 /// Return pedestals
c5bdf179 318 if (!fPedestals)
319 {
5562688f 320 fPedestals = CreatePedestals(fRunNumber);
c5bdf179 321 }
322 return fPedestals;
323}
324
5562688f 325//_____________________________________________________________________________
326AliMUONVCalibParam*
327AliMUONCalibrationData::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 AliMUONVStore* pedestals = Pedestals();
334 if (!pedestals)
335 {
336 return 0x0;
337 }
338
339 return static_cast<AliMUONVCalibParam*>(pedestals->FindObject(detElemId,manuId));
340}
341
c5bdf179 342//_____________________________________________________________________________
343void
344AliMUONCalibrationData::Print(Option_t*) const
345{
5562688f 346 /// A very basic dump of our guts.
5398f946 347
c5bdf179 348 cout << "RunNumber " << RunNumber()
e7d7fa47 349 << " fGains=" << fGains
350 << " fPedestals=" << fPedestals
48ed403b 351 << " fHV=" << fHV
e7d7fa47 352 << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
353 << " fRegionalTriggerBoardMasks=" << fRegionalTriggerBoardMasks
354 << " fGlobalTriggerBoardMasks=" << fGlobalTriggerBoardMasks
355 << " fTriggerLut=" << fTriggerLut
c5bdf179 356 << endl;
357}
358
e7d7fa47 359//_____________________________________________________________________________
360AliMUONVCalibParam*
5562688f 361AliMUONCalibrationData::RegionalTriggerBoardMasks(Int_t regionalBoardNumber) const
e7d7fa47 362{
5398f946 363/// Return the masks for a given trigger regional board.
364
5562688f 365 if ( !fRegionalTriggerBoardMasks )
48ed403b 366 {
5562688f 367 fRegionalTriggerBoardMasks = CreateRegionalTriggerBoardMasks(fRunNumber);
48ed403b 368 }
369
5562688f 370 if ( fRegionalTriggerBoardMasks )
e7d7fa47 371 {
5562688f 372 AliMUONVCalibParam* rtbm =
373 static_cast<AliMUONVCalibParam*>(fRegionalTriggerBoardMasks->FindObject(regionalBoardNumber));
374
375 if (!rtbm)
e7d7fa47 376 {
bafc927b 377 AliError(Form("Could not get mask for regionalBoard index=%d",regionalBoardNumber));
e7d7fa47 378 }
5562688f 379 return rtbm;
e7d7fa47 380 }
5562688f 381 return 0x0;
e7d7fa47 382}
383
384//_____________________________________________________________________________
385AliMUONTriggerEfficiencyCells*
386AliMUONCalibrationData::TriggerEfficiency() const
387{
5398f946 388/// Return the trigger efficiency.
389
e7d7fa47 390 if (!fTriggerEfficiency)
391 {
5562688f 392 fTriggerEfficiency = CreateTriggerEfficiency(fRunNumber);
e7d7fa47 393 }
394 return fTriggerEfficiency;
395}
396
5562688f 397
e7d7fa47 398//_____________________________________________________________________________
399AliMUONTriggerLut*
400AliMUONCalibrationData::TriggerLut() const
401{
5398f946 402/// Return the trigger look up table.
403
e7d7fa47 404 if (!fTriggerLut)
405 {
5562688f 406 fTriggerLut = CreateTriggerLut(fRunNumber);
e7d7fa47 407 }
408 return fTriggerLut;
409}
410
c1bbaf66 411//_____________________________________________________________________________
412void
413AliMUONCalibrationData::Reset()
414{
415/// Reset all data
416
417 delete fPedestals;
418 fPedestals = 0x0;
419 delete fGains;
420 fGains = 0x0;
421 delete fHV;
422 fHV = 0x0;
423 delete fLocalTriggerBoardMasks;
424 fLocalTriggerBoardMasks = 0x0;
425 delete fRegionalTriggerBoardMasks;
426 fRegionalTriggerBoardMasks = 0x0;
427 delete fGlobalTriggerBoardMasks;
428 fGlobalTriggerBoardMasks = 0x0;
429 delete fTriggerLut;
430 fTriggerLut = 0x0;
431 delete fTriggerEfficiency;
432 fTriggerEfficiency = 0x0;
433 delete fCapacitances;
434 fCapacitances = 0x0;
d067ba7c 435 delete fNeighbours;
436 fNeighbours = 0x0;
c1bbaf66 437}
438
e7d7fa47 439
c5bdf179 440