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