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