Reverting back the TPC set branch (Marian)
[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"
4bec0403 22#include "AliCodeTimer.h"
c5bdf179 23#include "AliLog.h"
e7d7fa47 24#include "AliMUONTriggerEfficiencyCells.h"
25#include "AliMUONTriggerLut.h"
a0eca509 26#include "AliMUONVStore.h"
27#include "AliMUONVStore.h"
c3ce65fd 28#include "AliMUONVCalibParam.h"
92c23b09 29#include "AliMUONGlobalCrateConfig.h"
30#include "AliMUONRegionalTriggerConfig.h"
31
4bec0403 32#include <Riostream.h>
33#include <TClass.h>
34#include <TMap.h>
c5bdf179 35
3d1463c8 36//-----------------------------------------------------------------------------
5398f946 37/// \class AliMUONCalibrationData
38///
48ed403b 39/// For the moment, this class stores pedestals, gains, hv (for tracker)
40/// and lut, masks and efficiencies (for trigger) that are fetched from the CDB.
e7d7fa47 41///
42/// This class is to be considered as a convenience class.
43/// Its aim is to ease retrieval of calibration data from the
44/// condition database.
45///
46/// It acts as a "facade" to a bunch of underlying
47/// containers/calibration classes.
48///
5398f946 49/// \author Laurent Aphecetche
3d1463c8 50//-----------------------------------------------------------------------------
e7d7fa47 51
5398f946 52/// \cond CLASSIMP
c5bdf179 53ClassImp(AliMUONCalibrationData)
5398f946 54/// \endcond
c5bdf179 55
56//_____________________________________________________________________________
57AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber,
58 Bool_t deferredInitialization)
59: TObject(),
60fIsValid(kTRUE),
61fRunNumber(runNumber),
62fGains(0x0),
c3ce65fd 63fPedestals(0x0),
48ed403b 64fHV(0x0),
e7d7fa47 65fLocalTriggerBoardMasks(0x0),
92c23b09 66fRegionalTriggerConfig(0x0),
67fGlobalTriggerCrateConfig(0x0),
e7d7fa47 68fTriggerLut(0x0),
c1bbaf66 69fTriggerEfficiency(0x0),
d067ba7c 70fCapacitances(0x0),
71fNeighbours(0x0)
c5bdf179 72{
5398f946 73/// Default ctor.
74
c3ce65fd 75 // If deferredInitialization is false, we read *all* calibrations
76 // at once.
77 // So when using this class to access only one kind of calibrations (e.g.
78 // only pedestals), you should put deferredInitialization to kTRUE, which
79 // will instruct this object to fetch the data only when neeeded.
5398f946 80
c5bdf179 81 if ( deferredInitialization == kFALSE )
82 {
5562688f 83 Gains();
84 Pedestals();
85 HV();
86 LocalTriggerBoardMasks(0);
92c23b09 87 RegionalTriggerConfig();
88 GlobalTriggerCrateConfig();
5562688f 89 TriggerLut();
90 TriggerEfficiency();
91 Capacitances();
92 Neighbours();
c5bdf179 93 }
94}
95
e7d7fa47 96//_____________________________________________________________________________
c5bdf179 97AliMUONCalibrationData::~AliMUONCalibrationData()
98{
c1bbaf66 99 /// Destructor. Note that we're the owner of our pointers.
23b1bc04 100 //PH The owner of the objects is CDB, do not delete them!
101 // Reset();
c3ce65fd 102}
c3ce65fd 103
104//_____________________________________________________________________________
5562688f 105AliMUONVStore*
106AliMUONCalibrationData::Capacitances() const
c3ce65fd 107{
5562688f 108 /// Create (if needed) and return the internal store for capacitances.
109
110 if (!fCapacitances)
c3ce65fd 111 {
5562688f 112 fCapacitances = CreateCapacitances(fRunNumber);
c3ce65fd 113 }
5562688f 114 return fCapacitances;
c5bdf179 115}
116
117//_____________________________________________________________________________
5562688f 118AliMUONVStore*
143cd71a 119AliMUONCalibrationData::CreateCapacitances(Int_t runNumber, Int_t* startOfValidity)
c5bdf179 120{
5562688f 121 /// Create capa store from OCDB for a given run
122
143cd71a 123 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Capacitances",startOfValidity));
5562688f 124}
5398f946 125
5562688f 126//_____________________________________________________________________________
127AliMUONVStore*
143cd71a 128AliMUONCalibrationData::CreateGains(Int_t runNumber, Int_t* startOfValidity)
5562688f 129{
130 /// Create a new gain store from the OCDB for a given run
143cd71a 131 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Gains",startOfValidity));
c5bdf179 132}
133
134//_____________________________________________________________________________
92c23b09 135AliMUONGlobalCrateConfig*
143cd71a 136AliMUONCalibrationData::CreateGlobalTriggerCrateConfig(Int_t runNumber, Int_t* startOfValidity)
c5bdf179 137{
92c23b09 138 /// Create the internal store for GlobalTriggerCrateConfig from OCDB
48ed403b 139
143cd71a 140 return dynamic_cast<AliMUONGlobalCrateConfig*>(CreateObject(runNumber,"MUON/Calib/GlobalTriggerCrateConfig",startOfValidity));
48ed403b 141}
142
92c23b09 143
144
48ed403b 145//_____________________________________________________________________________
5562688f 146TMap*
143cd71a 147AliMUONCalibrationData::CreateHV(Int_t runNumber, Int_t* startOfValidity)
c1bbaf66 148{
5562688f 149 /// Create a new HV map from the OCDB for a given run
143cd71a 150 return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
c1bbaf66 151}
152
153//_____________________________________________________________________________
a0eca509 154AliMUONVStore*
143cd71a 155AliMUONCalibrationData::CreateLocalTriggerBoardMasks(Int_t runNumber, Int_t* startOfValidity)
d067ba7c 156{
5562688f 157 /// Get the internal store for LocalTriggerBoardMasks from OCDB
158
143cd71a 159 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/LocalTriggerBoardMasks",startOfValidity));
d067ba7c 160}
161
162//_____________________________________________________________________________
a0eca509 163AliMUONVStore*
143cd71a 164AliMUONCalibrationData::CreateNeighbours(Int_t runNumber, Int_t* startOfValidity)
48ed403b 165{
5562688f 166 /// Create a neighbour store from the OCDB for a given run
143cd71a 167 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Neighbours",startOfValidity));
c5bdf179 168}
169
170//_____________________________________________________________________________
5562688f 171TObject*
143cd71a 172AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path, Int_t* startOfValidity)
d067ba7c 173{
5562688f 174 /// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
175 /// and return the corresponding TObject.
d067ba7c 176
4bec0403 177 AliCodeTimerAutoClass(Form("%d : %s",runNumber,path));
178
5562688f 179 AliCDBManager* man = AliCDBManager::Instance();
180
465302eb 181 AliCDBEntry* entry = man->Get(path,runNumber);
5562688f 182
5562688f 183 if (entry)
d067ba7c 184 {
143cd71a 185 if ( startOfValidity ) *startOfValidity = entry->GetId().GetFirstRun();
186
4bec0403 187 TObject* object = entry->GetObject();
188 entry->SetOwner(kFALSE);
465302eb 189 if (!(man->GetCacheFlag())) delete entry;
4bec0403 190 return object;
191 }
143cd71a 192 else
193 {
194 if ( startOfValidity ) *startOfValidity = AliCDBRunRange::Infinity();
195 }
196
5562688f 197 return 0x0;
d067ba7c 198}
199
200//_____________________________________________________________________________
a0eca509 201AliMUONVStore*
143cd71a 202AliMUONCalibrationData::CreatePedestals(Int_t runNumber, Int_t* startOfValidity)
c1bbaf66 203{
5562688f 204 /// Create a new pedestal store from the OCDB for a given run
143cd71a 205 return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Pedestals",startOfValidity));
c1bbaf66 206}
207
92c23b09 208
c1bbaf66 209//_____________________________________________________________________________
92c23b09 210AliMUONRegionalTriggerConfig*
143cd71a 211AliMUONCalibrationData::CreateRegionalTriggerConfig(Int_t runNumber, Int_t* startOfValidity)
5562688f 212{
92c23b09 213 /// Create the internal store for RegionalTriggerConfig from OCDB
5562688f 214
143cd71a 215 return dynamic_cast<AliMUONRegionalTriggerConfig*>(CreateObject(runNumber,"MUON/Calib/RegionalTriggerConfig",startOfValidity));
5562688f 216}
217
218//_____________________________________________________________________________
219AliMUONTriggerEfficiencyCells*
143cd71a 220AliMUONCalibrationData::CreateTriggerEfficiency(Int_t runNumber, Int_t* startOfValidity)
c5bdf179 221{
5562688f 222 /// Create trigger efficiency object from OCBD
223
143cd71a 224 return dynamic_cast<AliMUONTriggerEfficiencyCells*>(CreateObject(runNumber,"MUON/Calib/TriggerEfficiency",startOfValidity));
5562688f 225}
5398f946 226
5562688f 227//_____________________________________________________________________________
228AliMUONTriggerLut*
143cd71a 229AliMUONCalibrationData::CreateTriggerLut(Int_t runNumber, Int_t* startOfValidity)
5562688f 230{
231 /// Create trigger LUT from OCDB
232
143cd71a 233 return dynamic_cast<AliMUONTriggerLut*>(CreateObject(runNumber,"MUON/Calib/TriggerLut",startOfValidity));
5562688f 234}
235
236//_____________________________________________________________________________
237AliMUONVStore*
238AliMUONCalibrationData::Gains() const
239{
240 /// Create (if needed) and return the internal store for gains.
c5bdf179 241 if (!fGains)
242 {
5562688f 243 fGains = CreateGains(fRunNumber);
c5bdf179 244 }
245 return fGains;
246}
247
248//_____________________________________________________________________________
5562688f 249AliMUONVCalibParam*
250AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
e7d7fa47 251{
5562688f 252/// Return the gains for a given (detElemId, manuId) pair
253/// Note that, unlike the DeadChannel case, if the result is 0x0, that's an
254/// error (meaning that we should get gains for all channels).
5398f946 255
5562688f 256 AliMUONVStore* gains = Gains();
257 if (!gains)
258 {
259 return 0x0;
260 }
261
262 return static_cast<AliMUONVCalibParam*>(gains->FindObject(detElemId,manuId));
e7d7fa47 263}
264
265//_____________________________________________________________________________
92c23b09 266AliMUONGlobalCrateConfig*
267AliMUONCalibrationData::GlobalTriggerCrateConfig() const
e7d7fa47 268{
92c23b09 269 /// Return the config for the global trigger board.
5562688f 270
92c23b09 271 if (!fGlobalTriggerCrateConfig)
e7d7fa47 272 {
92c23b09 273 fGlobalTriggerCrateConfig = CreateGlobalTriggerCrateConfig(fRunNumber);
e7d7fa47 274 }
92c23b09 275 return fGlobalTriggerCrateConfig;
e7d7fa47 276}
277
92c23b09 278
e7d7fa47 279//_____________________________________________________________________________
5562688f 280TMap*
281AliMUONCalibrationData::HV() const
e7d7fa47 282{
5562688f 283 /// Return the calibration for a given (detElemId, manuId) pair
48ed403b 284
5562688f 285 if (!fHV)
e7d7fa47 286 {
5562688f 287 fHV = CreateHV(fRunNumber);
e7d7fa47 288 }
5562688f 289 return fHV;
e7d7fa47 290}
291
292//_____________________________________________________________________________
a0eca509 293AliMUONVStore*
5562688f 294AliMUONCalibrationData::Neighbours() const
e7d7fa47 295{
5562688f 296 /// Create (if needed) and return the internal store for neighbours.
297 if (!fNeighbours)
298 {
299 fNeighbours = CreateNeighbours(fRunNumber);
300 }
301 return fNeighbours;
302}
303
304//_____________________________________________________________________________
305AliMUONVCalibParam*
306AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
307{
308/// Return the masks for a given trigger local board.
5398f946 309
e7d7fa47 310 if (!fLocalTriggerBoardMasks)
311 {
5562688f 312 fLocalTriggerBoardMasks = CreateLocalTriggerBoardMasks(fRunNumber);
313 }
314
315 if ( fLocalTriggerBoardMasks )
316 {
317 AliMUONVCalibParam* ltbm =
318 static_cast<AliMUONVCalibParam*>(fLocalTriggerBoardMasks->FindObject(localBoardNumber));
319 if (!ltbm)
e7d7fa47 320 {
5562688f 321 AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
e7d7fa47 322 }
5562688f 323 return ltbm;
e7d7fa47 324 }
5562688f 325 return 0x0;
e7d7fa47 326}
327
328//_____________________________________________________________________________
a0eca509 329AliMUONVStore*
5562688f 330AliMUONCalibrationData::Pedestals() const
c5bdf179 331{
5562688f 332 /// Return pedestals
c5bdf179 333 if (!fPedestals)
334 {
5562688f 335 fPedestals = CreatePedestals(fRunNumber);
c5bdf179 336 }
337 return fPedestals;
338}
339
340//_____________________________________________________________________________
5562688f 341AliMUONVCalibParam*
342AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
343{
344 /// Return the pedestals for a given (detElemId, manuId) pair.
345 /// A return value of 0x0 is considered an error, meaning we should get
346 /// pedestals for all channels.
347
348 AliMUONVStore* pedestals = Pedestals();
349 if (!pedestals)
350 {
351 return 0x0;
352 }
353
354 return static_cast<AliMUONVCalibParam*>(pedestals->FindObject(detElemId,manuId));
355}
356
357//_____________________________________________________________________________
c5bdf179 358void
359AliMUONCalibrationData::Print(Option_t*) const
360{
5562688f 361 /// A very basic dump of our guts.
5398f946 362
c5bdf179 363 cout << "RunNumber " << RunNumber()
e7d7fa47 364 << " fGains=" << fGains
365 << " fPedestals=" << fPedestals
48ed403b 366 << " fHV=" << fHV
e7d7fa47 367 << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
92c23b09 368 << " fRegionalTriggerConfig=" << fRegionalTriggerConfig
369 << " fGlobalTriggerCrateConfig=" << fGlobalTriggerCrateConfig
e7d7fa47 370 << " fTriggerLut=" << fTriggerLut
c5bdf179 371 << endl;
372}
373
92c23b09 374
48ed403b 375//_____________________________________________________________________________
92c23b09 376AliMUONRegionalTriggerConfig*
377AliMUONCalibrationData::RegionalTriggerConfig() const
e7d7fa47 378{
92c23b09 379 /// Return the config for the regional trigger board.
48ed403b 380
92c23b09 381 if (!fRegionalTriggerConfig)
e7d7fa47 382 {
92c23b09 383 fRegionalTriggerConfig = CreateRegionalTriggerConfig(fRunNumber);
e7d7fa47 384 }
92c23b09 385 return fRegionalTriggerConfig;
e7d7fa47 386}
387
92c23b09 388
e7d7fa47 389//_____________________________________________________________________________
390AliMUONTriggerEfficiencyCells*
391AliMUONCalibrationData::TriggerEfficiency() const
392{
5398f946 393/// Return the trigger efficiency.
394
e7d7fa47 395 if (!fTriggerEfficiency)
396 {
5562688f 397 fTriggerEfficiency = CreateTriggerEfficiency(fRunNumber);
e7d7fa47 398 }
399 return fTriggerEfficiency;
400}
401
5562688f 402
e7d7fa47 403//_____________________________________________________________________________
404AliMUONTriggerLut*
405AliMUONCalibrationData::TriggerLut() const
406{
5398f946 407/// Return the trigger look up table.
408
e7d7fa47 409 if (!fTriggerLut)
410 {
5562688f 411 fTriggerLut = CreateTriggerLut(fRunNumber);
e7d7fa47 412 }
413 return fTriggerLut;
414}
415
c1bbaf66 416//_____________________________________________________________________________
417void
418AliMUONCalibrationData::Reset()
419{
420/// Reset all data
421
422 delete fPedestals;
423 fPedestals = 0x0;
424 delete fGains;
425 fGains = 0x0;
426 delete fHV;
427 fHV = 0x0;
428 delete fLocalTriggerBoardMasks;
429 fLocalTriggerBoardMasks = 0x0;
92c23b09 430 delete fRegionalTriggerConfig;
431 fRegionalTriggerConfig = 0x0;
432 delete fGlobalTriggerCrateConfig;
433 fGlobalTriggerCrateConfig = 0x0;
434
c1bbaf66 435 delete fTriggerLut;
436 fTriggerLut = 0x0;
437 delete fTriggerEfficiency;
438 fTriggerEfficiency = 0x0;
439 delete fCapacitances;
440 fCapacitances = 0x0;
d067ba7c 441 delete fNeighbours;
442 fNeighbours = 0x0;
c1bbaf66 443}
444
630711ed 445//_____________________________________________________________________________
446void
447AliMUONCalibrationData::Check(Int_t runNumber)
448{
449 /// Self-check to see if we can read all data for a given run
450 /// from the current OCDB...
451
452 if ( ! CreateCapacitances(runNumber) )
453 {
454 AliErrorClass("Could not read capacitances");
455 }
456 else
457 {
458 AliInfoClass("Capacitances read OK");
459 }
460
461 if ( ! CreateGains(runNumber) )
462 {
463 AliErrorClass("Could not read gains");
464 }
465 else
466 {
467 AliInfoClass("Gains read OK");
468 }
469
470 if ( ! CreateGlobalTriggerCrateConfig(runNumber) )
471 {
472 AliErrorClass("Could not read Trigger Crate Config");
473 }
474 else
475 {
476 AliInfoClass("TriggerBoardMasks read OK");
477 }
478
479 if ( ! CreateHV(runNumber) )
480 {
481 AliErrorClass("Could not read HV");
482 }
483 else
484 {
485 AliInfoClass("HV read OK");
486 }
487
488 if ( ! CreateNeighbours(runNumber) )
489 {
490 AliErrorClass("Could not read Neighbours");
491 }
492 else
493 {
494 AliInfoClass("Neighbours read OK");
495 }
496
497 if ( ! CreateLocalTriggerBoardMasks(runNumber) )
498 {
499 AliErrorClass("Could not read LocalTriggerBoardMasks");
500 }
501 else
502 {
503 AliInfoClass("LocalTriggerBoardMasks read OK");
504 }
505
506 if ( ! CreatePedestals(runNumber) )
507 {
508 AliErrorClass("Could not read pedestals");
509 }
510 else
511 {
512 AliInfoClass("Pedestals read OK");
513 }
514
515 if ( ! CreateRegionalTriggerConfig(runNumber) )
516 {
517 AliErrorClass("Could not read RegionalTriggerConfig");
518 }
519 else
520 {
521 AliInfoClass("RegionalTriggerBoardMasks read OK");
522 }
523
524 if ( ! CreateTriggerLut(runNumber) )
525 {
526 AliErrorClass("Could not read TriggerLut");
527 }
528 else
529 {
530 AliInfoClass("TriggerLut read OK");
531 }
532
533 if ( ! CreateTriggerEfficiency(runNumber) )
534 {
535 AliErrorClass("Could not read TriggerEfficiency");
536 }
537 else
538 {
539 AliInfoClass("TriggerEfficiency read OK");
540 }
541}
e7d7fa47 542
c5bdf179 543