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