]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibrationData.cxx
Fixing Coverity reported problems (REVERSE INULL, UNIT_CTOR, FORWARD_NULL)
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibrationData.cxx
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"
22 #include "AliCodeTimer.h"
23 #include "AliLog.h"
24 #include "AliMUONRejectList.h"
25 #include "AliMUONTriggerEfficiencyCells.h"
26 #include "AliMUONTriggerLut.h"
27 #include "AliMUONVStore.h"
28 #include "AliMUONVStore.h"
29 #include "AliMUONVCalibParam.h"
30 #include "AliMUONGlobalCrateConfig.h"
31 #include "AliMUONRegionalTriggerConfig.h"
32
33 #include <Riostream.h>
34 #include <TClass.h>
35 #include <TMap.h>
36
37 //-----------------------------------------------------------------------------
38 /// \class AliMUONCalibrationData
39 ///
40 /// For the moment, this class stores pedestals, gains, hv (for tracker)
41 /// and lut, masks and efficiencies (for trigger) that are fetched from the CDB.
42 ///
43 /// This class is to be considered as a convenience class.
44 /// Its aim is to ease retrieval of calibration data from the 
45 /// condition database.
46 ///
47 /// It acts as a "facade" to a bunch of underlying 
48 /// containers/calibration classes.
49 ///
50 /// \author Laurent Aphecetche
51 //-----------------------------------------------------------------------------
52
53 /// \cond CLASSIMP
54 ClassImp(AliMUONCalibrationData)
55 /// \endcond
56
57 AliMUONVStore* AliMUONCalibrationData::fgBypassPedestals(0x0);
58 AliMUONVStore* AliMUONCalibrationData::fgBypassGains(0x0);
59
60 //_____________________________________________________________________________
61 AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber, 
62                                                Bool_t deferredInitialization) 
63 : TObject(), 
64 fIsValid(kTRUE),
65 fRunNumber(runNumber), 
66 fGains(0x0), 
67 fPedestals(0x0),
68 fHV(0x0),
69 fTriggerDCS(0x0),
70 fLocalTriggerBoardMasks(0x0),
71 fRegionalTriggerConfig(0x0),
72 fGlobalTriggerCrateConfig(0x0),
73 fTriggerLut(0x0),
74 fTriggerEfficiency(0x0),
75 fCapacitances(0x0),
76 fNeighbours(0x0),
77 fOccupancyMap(0x0),
78 fRejectList(0x0),
79 fConfig(0x0)
80 {
81 /// Default ctor.
82
83   // If deferredInitialization is false, we read *all* calibrations
84   // at once.
85   // So when using this class to access only one kind of calibrations (e.g.
86   // only pedestals), you should put deferredInitialization to kTRUE, which
87   // will instruct this object to fetch the data only when neeeded.
88
89   if ( deferredInitialization == kFALSE )
90   {
91     Gains();
92     Pedestals();
93     OccupancyMap();
94     RejectList();
95     HV();
96     TriggerDCS();
97     LocalTriggerBoardMasks(0);
98     RegionalTriggerConfig();
99     GlobalTriggerCrateConfig();
100     TriggerLut();
101     TriggerEfficiency();
102     Capacitances();
103     Neighbours();
104     Config();
105   }
106 }
107
108 //_____________________________________________________________________________
109 AliMUONCalibrationData::~AliMUONCalibrationData()
110 {
111   /// Destructor. Note that we're the owner of our pointers if the OCDB cache
112   /// is not set. Otherwise the cache is supposed to take care of them...
113   if (!(AliCDBManager::Instance()->GetCacheFlag())) Reset();
114 }
115
116 //_____________________________________________________________________________
117 AliMUONVStore*
118 AliMUONCalibrationData::Capacitances() const
119 {
120   /// Create (if needed) and return the internal store for capacitances.
121   
122   if (!fCapacitances)
123   {
124     fCapacitances = CreateCapacitances(fRunNumber);
125   }
126   return fCapacitances;
127 }
128
129 //_____________________________________________________________________________
130 AliMUONVStore*
131 AliMUONCalibrationData::CreateCapacitances(Int_t runNumber, Int_t* startOfValidity)
132 {
133   /// Create capa store from OCDB for a given run
134   
135   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Capacitances",startOfValidity));
136 }
137
138 //_____________________________________________________________________________
139 AliMUONVStore*
140 AliMUONCalibrationData::CreateGains(Int_t runNumber, Int_t* startOfValidity)
141 {
142   /// Create a new gain store from the OCDB for a given run
143   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Gains",startOfValidity));
144 }
145
146 //_____________________________________________________________________________
147 AliMUONGlobalCrateConfig*
148 AliMUONCalibrationData::CreateGlobalTriggerCrateConfig(Int_t runNumber, Int_t* startOfValidity)
149 {
150   /// Create the internal store for GlobalTriggerCrateConfig from OCDB
151   
152   return dynamic_cast<AliMUONGlobalCrateConfig*>(CreateObject(runNumber,"MUON/Calib/GlobalTriggerCrateConfig",startOfValidity));
153 }
154
155
156
157 //_____________________________________________________________________________
158 TMap*
159 AliMUONCalibrationData::CreateHV(Int_t runNumber, Int_t* startOfValidity)
160 {
161   /// Create a new HV map from the OCDB for a given run
162   return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV",startOfValidity));
163 }
164
165 //_____________________________________________________________________________
166 TMap*
167 AliMUONCalibrationData::CreateTriggerDCS(Int_t runNumber, Int_t* startOfValidity)
168 {
169   /// Create a new Trigger HV and curent map from the OCDB for a given run
170   return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/TriggerDCS",startOfValidity));
171 }
172
173 //_____________________________________________________________________________
174 AliMUONVStore*
175 AliMUONCalibrationData::CreateLocalTriggerBoardMasks(Int_t runNumber, Int_t* startOfValidity)
176 {
177   /// Get the internal store for LocalTriggerBoardMasks from OCDB
178   
179   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/LocalTriggerBoardMasks",startOfValidity));
180 }
181
182 //_____________________________________________________________________________
183 AliMUONVStore*
184 AliMUONCalibrationData::CreateNeighbours(Int_t runNumber, Int_t* startOfValidity)
185 {
186   /// Create a neighbour store from the OCDB for a given run
187   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Neighbours",startOfValidity));
188 }
189
190 //_____________________________________________________________________________
191 TObject*
192 AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path, Int_t* startOfValidity)
193 {
194   /// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
195   /// and return the corresponding TObject.
196   
197   AliCodeTimerAutoClass(Form("%d : %s",runNumber,path),0);
198   
199   AliCDBManager* man = AliCDBManager::Instance();
200   
201   AliCDBEntry* entry =  man->Get(path,runNumber);
202   
203   if (entry)
204   {
205                 if ( startOfValidity ) *startOfValidity = entry->GetId().GetFirstRun();
206                 
207     TObject* object = entry->GetObject();
208     if (!(man->GetCacheFlag()))
209     {
210       entry->SetOwner(kFALSE);
211       delete entry;      
212     }
213     return object;
214   }
215         else
216         {
217                 if ( startOfValidity )  *startOfValidity = AliCDBRunRange::Infinity();
218   }
219         
220   {
221     
222     AliCodeTimerAutoClass(Form("Failed to get %s for run %d",path,runNumber),1);
223
224   }
225   
226   return 0x0;
227 }
228
229 //_____________________________________________________________________________
230 AliMUONVStore*
231 AliMUONCalibrationData::CreateOccupancyMap(Int_t runNumber, Int_t* startOfValidity)
232 {
233   /// Create a new occupancy map store from the OCDB for a given run
234   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/OccupancyMap",startOfValidity));
235 }
236
237 //_____________________________________________________________________________
238 AliMUONRejectList*
239 AliMUONCalibrationData::CreateRejectList(Int_t runNumber, Int_t* startOfValidity)
240 {
241   /// Create a new rejectlist store from the OCDB for a given run
242   return dynamic_cast<AliMUONRejectList*>(CreateObject(runNumber,"MUON/Calib/RejectList",startOfValidity));
243 }
244
245 //_____________________________________________________________________________
246 AliMUONVStore*
247 AliMUONCalibrationData::CreatePedestals(Int_t runNumber, Int_t* startOfValidity)
248 {
249   /// Create a new pedestal store from the OCDB for a given run
250   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Pedestals",startOfValidity));
251 }
252
253 //_____________________________________________________________________________
254 AliMUONVStore*
255 AliMUONCalibrationData::CreateConfig(Int_t runNumber, Int_t* startOfValidity)
256 {
257   /// Create a new config store from the OCDB for a given run
258   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Config",startOfValidity));
259 }
260
261
262 //_____________________________________________________________________________
263 AliMUONRegionalTriggerConfig*
264 AliMUONCalibrationData::CreateRegionalTriggerConfig(Int_t runNumber, Int_t* startOfValidity)
265 {
266   /// Create the internal store for RegionalTriggerConfig from OCDB
267   
268   return dynamic_cast<AliMUONRegionalTriggerConfig*>(CreateObject(runNumber,"MUON/Calib/RegionalTriggerConfig",startOfValidity));
269 }
270
271 //_____________________________________________________________________________
272 AliMUONTriggerEfficiencyCells* 
273 AliMUONCalibrationData::CreateTriggerEfficiency(Int_t runNumber, Int_t* startOfValidity)
274 {
275   /// Create trigger efficiency object from OCBD
276   
277   return dynamic_cast<AliMUONTriggerEfficiencyCells*>(CreateObject(runNumber,"MUON/Calib/TriggerEfficiency",startOfValidity));
278 }
279
280 //_____________________________________________________________________________
281 AliMUONTriggerLut* 
282 AliMUONCalibrationData::CreateTriggerLut(Int_t runNumber, Int_t* startOfValidity)
283 {
284   /// Create trigger LUT from OCDB
285   
286   return dynamic_cast<AliMUONTriggerLut*>(CreateObject(runNumber,"MUON/Calib/TriggerLut",startOfValidity));
287 }
288
289 //_____________________________________________________________________________
290 AliMUONVStore*
291 AliMUONCalibrationData::Gains() const
292 {
293   /// Create (if needed) and return the internal store for gains.
294   if (fgBypassGains) return fgBypassGains;
295   
296   if (!fGains)
297   {
298     fGains = CreateGains(fRunNumber);
299   }
300   return fGains;
301 }
302
303 //_____________________________________________________________________________
304 AliMUONVCalibParam*
305 AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
306 {
307 /// Return the gains for a given (detElemId, manuId) pair
308 /// Note that, unlike the DeadChannel case, if the result is 0x0, that's an
309 /// error (meaning that we should get gains for all channels).
310
311   AliMUONVStore* gains = Gains();
312   if (!gains)
313   {
314     return 0x0;
315   }
316   
317   return static_cast<AliMUONVCalibParam*>(gains->FindObject(detElemId,manuId));
318 }
319
320 //_____________________________________________________________________________
321 AliMUONGlobalCrateConfig* 
322 AliMUONCalibrationData::GlobalTriggerCrateConfig() const
323 {
324   /// Return the config for the global trigger board.
325   
326   if (!fGlobalTriggerCrateConfig)
327   {
328     fGlobalTriggerCrateConfig = CreateGlobalTriggerCrateConfig(fRunNumber);
329   }
330   return fGlobalTriggerCrateConfig;
331 }
332
333
334 //_____________________________________________________________________________
335 TMap*
336 AliMUONCalibrationData::HV() const
337 {
338   /// Return the calibration for a given (detElemId, manuId) pair
339   
340   if (!fHV)
341   {
342     fHV = CreateHV(fRunNumber);
343   }
344   return fHV;
345 }
346
347 //_____________________________________________________________________________
348 TMap*
349 AliMUONCalibrationData::TriggerDCS() const
350 {
351   /// Return the calibration for a given (detElemId, manuId) pair
352   
353   if (!fTriggerDCS)
354   {
355     fTriggerDCS = CreateTriggerDCS(fRunNumber);
356   }
357   return fTriggerDCS;
358 }
359
360 //_____________________________________________________________________________
361 AliMUONVStore*
362 AliMUONCalibrationData::Neighbours() const
363 {
364   /// Create (if needed) and return the internal store for neighbours.
365   if (!fNeighbours)
366   {
367     fNeighbours = CreateNeighbours(fRunNumber);
368   }
369   return fNeighbours;
370 }
371
372 //_____________________________________________________________________________
373 AliMUONVCalibParam* 
374 AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
375 {
376 /// Return the masks for a given trigger local board.
377
378   if (!fLocalTriggerBoardMasks)
379   {
380     fLocalTriggerBoardMasks = CreateLocalTriggerBoardMasks(fRunNumber);
381   }
382
383   if ( fLocalTriggerBoardMasks ) 
384   {
385     AliMUONVCalibParam* ltbm = 
386       static_cast<AliMUONVCalibParam*>(fLocalTriggerBoardMasks->FindObject(localBoardNumber));
387     if (!ltbm)
388     {
389       AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
390     }
391     return ltbm;  
392   }
393   return 0x0;
394 }
395
396 //_____________________________________________________________________________
397 AliMUONVStore*
398 AliMUONCalibrationData::OccupancyMap() const
399 {
400   /// Get occupancy map
401   if (!fOccupancyMap)
402   {
403     fOccupancyMap = CreateOccupancyMap(fRunNumber);
404   }
405   return fOccupancyMap;
406 }
407
408 //_____________________________________________________________________________
409 AliMUONRejectList*
410 AliMUONCalibrationData::RejectList() const
411 {
412   /// Get reject list
413   if (!fRejectList)
414   {
415     fRejectList = CreateRejectList(fRunNumber);
416   }
417   return fRejectList;
418 }
419
420 //_____________________________________________________________________________
421 void
422 AliMUONCalibrationData::BypassStores(AliMUONVStore* ped, AliMUONVStore* gain)
423 {
424   /// Force the use of those pedestals and gains
425   fgBypassPedestals = ped;
426   fgBypassGains = gain;
427   
428 }
429
430 //_____________________________________________________________________________
431 AliMUONVStore*
432 AliMUONCalibrationData::Pedestals() const
433 {
434   /// Return pedestals
435   
436   if (fgBypassPedestals) return fgBypassPedestals;
437   
438   if (!fPedestals)
439   {
440     fPedestals = CreatePedestals(fRunNumber);
441   }
442   return fPedestals;
443 }
444
445 //_____________________________________________________________________________
446 AliMUONVStore*
447 AliMUONCalibrationData::Config() const
448 {
449   /// Return config
450   
451   if (!fConfig)
452   {
453     fConfig = CreateConfig(fRunNumber);
454   }
455   return fConfig;
456 }
457
458 //_____________________________________________________________________________
459 AliMUONVCalibParam*
460 AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
461 {
462   /// Return the pedestals for a given (detElemId, manuId) pair.
463   /// A return value of 0x0 is considered an error, meaning we should get
464   /// pedestals for all channels.
465   
466   AliMUONVStore* pedestals = Pedestals();
467   if (!pedestals) 
468   {
469     return 0x0;
470   }
471   
472   return static_cast<AliMUONVCalibParam*>(pedestals->FindObject(detElemId,manuId));
473 }
474
475 //_____________________________________________________________________________
476 void
477 AliMUONCalibrationData::Print(Option_t*) const
478 {
479   /// A very basic dump of our guts.
480
481   cout << "RunNumber " << RunNumber()
482   << " fGains=" << fGains
483   << " fPedestals=" << fPedestals
484   << " fConfig=" << fConfig
485   << " fHV=" << fHV
486   << " fTriggerDCS=" << fTriggerDCS
487   << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
488   << " fRegionalTriggerConfig=" << fRegionalTriggerConfig
489   << " fGlobalTriggerCrateConfig=" << fGlobalTriggerCrateConfig
490   << " fTriggerLut=" << fTriggerLut
491   << endl;
492 }
493
494
495 //_____________________________________________________________________________
496 AliMUONRegionalTriggerConfig* 
497 AliMUONCalibrationData::RegionalTriggerConfig() const
498 {
499   /// Return the config for the regional trigger board.
500   
501   if (!fRegionalTriggerConfig)
502   {
503     fRegionalTriggerConfig = CreateRegionalTriggerConfig(fRunNumber);
504     }
505   return fRegionalTriggerConfig;
506 }
507
508
509 //_____________________________________________________________________________
510 AliMUONTriggerEfficiencyCells*
511 AliMUONCalibrationData::TriggerEfficiency() const
512 {
513 /// Return the trigger efficiency.
514
515   if (!fTriggerEfficiency)
516   {
517     fTriggerEfficiency = CreateTriggerEfficiency(fRunNumber);
518   }
519   return fTriggerEfficiency;
520 }
521
522
523 //_____________________________________________________________________________
524 AliMUONTriggerLut*
525 AliMUONCalibrationData::TriggerLut() const
526 {
527 /// Return the trigger look up table.
528
529   if (!fTriggerLut)
530   {
531     fTriggerLut = CreateTriggerLut(fRunNumber);
532   }
533   return fTriggerLut;
534 }
535
536 //_____________________________________________________________________________
537 void
538 AliMUONCalibrationData::Reset()
539 {
540 /// Reset all data
541
542   AliCodeTimerAuto("",0);
543   
544   delete fConfig;
545   fConfig = 0x0;
546   delete fPedestals;
547   fPedestals = 0x0;
548   delete fGains;
549   fGains = 0x0;
550   delete fHV;
551   fHV = 0x0;
552   delete fTriggerDCS;
553   fTriggerDCS = 0x0;
554   delete fLocalTriggerBoardMasks;
555   fLocalTriggerBoardMasks = 0x0;
556   delete fRegionalTriggerConfig;
557   fRegionalTriggerConfig = 0x0;
558   delete fGlobalTriggerCrateConfig;
559   fGlobalTriggerCrateConfig = 0x0;
560   
561   delete fTriggerLut;
562   fTriggerLut = 0x0;
563   delete fTriggerEfficiency;
564   fTriggerEfficiency = 0x0;
565   delete fCapacitances;
566   fCapacitances = 0x0;
567   delete fNeighbours;
568   fNeighbours = 0x0;
569 }
570
571 //_____________________________________________________________________________
572 void
573 AliMUONCalibrationData::Check(Int_t runNumber)
574 {
575   /// Self-check to see if we can read all data for a given run 
576   /// from the current OCDB...
577   
578   if ( ! CreateCapacitances(runNumber) )
579   {
580     AliErrorClass("Could not read capacitances");
581   }
582   else
583   {
584     AliInfoClass("Capacitances read OK");
585   }
586
587   if ( ! CreateGains(runNumber) ) 
588   {
589     AliErrorClass("Could not read gains");
590   }
591   else
592   {
593     AliInfoClass("Gains read OK");
594   }
595
596   if ( ! CreateGlobalTriggerCrateConfig(runNumber) ) 
597   {
598     AliErrorClass("Could not read Trigger Crate Config");
599   }
600   else
601   {
602     AliInfoClass("TriggerBoardMasks read OK");
603   }
604
605   if ( !  CreateHV(runNumber) )
606   {
607     AliErrorClass("Could not read HV");
608   }
609   else
610   {
611     AliInfoClass("HV read OK");
612   }
613
614   if ( !  CreateTriggerDCS(runNumber) )
615   {
616     AliErrorClass("Could not read Trigger HV and Currents");
617   }
618   else
619   {
620     AliInfoClass("Trigger HV and Currents read OK");
621   }
622
623   if ( ! CreateNeighbours(runNumber) )
624   {
625     AliErrorClass("Could not read Neighbours");
626   }
627   else
628   {
629     AliInfoClass("Neighbours read OK");
630   }
631
632   if ( !  CreateLocalTriggerBoardMasks(runNumber) )
633   {
634     AliErrorClass("Could not read LocalTriggerBoardMasks");
635   }
636   else
637   {
638     AliInfoClass("LocalTriggerBoardMasks read OK");
639   }
640   
641   if ( ! CreatePedestals(runNumber) )
642   {
643     AliErrorClass("Could not read pedestals");
644   }
645   else
646   {
647     AliInfoClass("Pedestals read OK");
648   }
649
650   if ( ! CreateConfig(runNumber) )
651   {
652     AliErrorClass("Could not read config");
653   }
654   else
655   {
656     AliInfoClass("Config read OK");
657   }
658   
659   if ( ! CreateRegionalTriggerConfig(runNumber) )
660   {
661     AliErrorClass("Could not read RegionalTriggerConfig");
662   }
663   else
664   {
665     AliInfoClass("RegionalTriggerBoardMasks read OK");
666   }
667   
668   if ( ! CreateTriggerLut(runNumber) )
669   {
670     AliErrorClass("Could not read TriggerLut");
671   }
672   else
673   {
674     AliInfoClass("TriggerLut read OK");
675   }
676
677   if ( ! CreateTriggerEfficiency(runNumber) )
678   {
679     AliErrorClass("Could not read TriggerEfficiency");
680   }
681   else    
682   {
683     AliInfoClass("TriggerEfficiency read OK");
684   }
685 }
686
687