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