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