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