]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibrationData.cxx
fb0c0860d6560be524b4621b723aa7f6cb91d6da
[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)
119 {
120   /// Create capa store from OCDB for a given run
121   
122   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Capacitances"));
123 }
124
125 //_____________________________________________________________________________
126 AliMUONVStore*
127 AliMUONCalibrationData::CreateGains(Int_t runNumber)
128 {
129   /// Create a new gain store from the OCDB for a given run
130   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Gains"));
131 }
132
133 //_____________________________________________________________________________
134 AliMUONGlobalCrateConfig*
135 AliMUONCalibrationData::CreateGlobalTriggerCrateConfig(Int_t runNumber)
136 {
137   /// Create the internal store for GlobalTriggerCrateConfig from OCDB
138   
139   return dynamic_cast<AliMUONGlobalCrateConfig*>(CreateObject(runNumber,"MUON/Calib/GlobalTriggerCrateConfig"));
140 }
141
142
143
144 //_____________________________________________________________________________
145 TMap*
146 AliMUONCalibrationData::CreateHV(Int_t runNumber)
147 {
148   /// Create a new HV map from the OCDB for a given run
149   return dynamic_cast<TMap*>(CreateObject(runNumber,"MUON/Calib/HV"));
150 }
151
152 //_____________________________________________________________________________
153 AliMUONVStore*
154 AliMUONCalibrationData::CreateLocalTriggerBoardMasks(Int_t runNumber)
155 {
156   /// Get the internal store for LocalTriggerBoardMasks from OCDB
157   
158   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/LocalTriggerBoardMasks"));
159 }
160
161 //_____________________________________________________________________________
162 AliMUONVStore*
163 AliMUONCalibrationData::CreateNeighbours(Int_t runNumber)
164 {
165   /// Create a neighbour store from the OCDB for a given run
166   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Neighbours"));
167 }
168
169 //_____________________________________________________________________________
170 TObject*
171 AliMUONCalibrationData::CreateObject(Int_t runNumber, const char* path)
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   if (entry)
195   {
196     TObject* object = entry->GetObject();
197     entry->SetOwner(kFALSE);
198     delete entry;
199     return object;
200   }
201   
202   return 0x0;
203 }
204
205 //_____________________________________________________________________________
206 AliMUONVStore*
207 AliMUONCalibrationData::CreatePedestals(Int_t runNumber)
208 {
209   /// Create a new pedestal store from the OCDB for a given run
210   return dynamic_cast<AliMUONVStore*>(CreateObject(runNumber,"MUON/Calib/Pedestals"));
211 }
212
213
214 //_____________________________________________________________________________
215 AliMUONRegionalTriggerConfig*
216 AliMUONCalibrationData::CreateRegionalTriggerConfig(Int_t runNumber)
217 {
218   /// Create the internal store for RegionalTriggerConfig from OCDB
219   
220   return dynamic_cast<AliMUONRegionalTriggerConfig*>(CreateObject(runNumber,"MUON/Calib/RegionalTriggerConfig"));
221 }
222
223 //_____________________________________________________________________________
224 AliMUONTriggerEfficiencyCells* 
225 AliMUONCalibrationData::CreateTriggerEfficiency(Int_t runNumber)
226 {
227   /// Create trigger efficiency object from OCBD
228   
229   return dynamic_cast<AliMUONTriggerEfficiencyCells*>(CreateObject(runNumber,"MUON/Calib/TriggerEfficiency"));
230 }
231
232 //_____________________________________________________________________________
233 AliMUONTriggerLut* 
234 AliMUONCalibrationData::CreateTriggerLut(Int_t runNumber)
235 {
236   /// Create trigger LUT from OCDB
237   
238   return dynamic_cast<AliMUONTriggerLut*>(CreateObject(runNumber,"MUON/Calib/TriggerLut"));
239 }
240
241 //_____________________________________________________________________________
242 AliMUONVStore*
243 AliMUONCalibrationData::Gains() const
244 {
245   /// Create (if needed) and return the internal store for gains.
246   if (!fGains)
247   {
248     fGains = CreateGains(fRunNumber);
249   }
250   return fGains;
251 }
252
253 //_____________________________________________________________________________
254 AliMUONVCalibParam*
255 AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
256 {
257 /// Return the gains for a given (detElemId, manuId) pair
258 /// Note that, unlike the DeadChannel case, if the result is 0x0, that's an
259 /// error (meaning that we should get gains for all channels).
260
261   AliMUONVStore* gains = Gains();
262   if (!gains)
263   {
264     return 0x0;
265   }
266   
267   return static_cast<AliMUONVCalibParam*>(gains->FindObject(detElemId,manuId));
268 }
269
270 //_____________________________________________________________________________
271 AliMUONGlobalCrateConfig* 
272 AliMUONCalibrationData::GlobalTriggerCrateConfig() const
273 {
274   /// Return the config for the global trigger board.
275   
276   if (!fGlobalTriggerCrateConfig)
277   {
278     fGlobalTriggerCrateConfig = CreateGlobalTriggerCrateConfig(fRunNumber);
279   }
280   return fGlobalTriggerCrateConfig;
281 }
282
283
284 //_____________________________________________________________________________
285 TMap*
286 AliMUONCalibrationData::HV() const
287 {
288   /// Return the calibration for a given (detElemId, manuId) pair
289   
290   if (!fHV)
291   {
292     fHV = CreateHV(fRunNumber);
293   }
294   return fHV;
295 }
296
297 //_____________________________________________________________________________
298 AliMUONVStore*
299 AliMUONCalibrationData::Neighbours() const
300 {
301   /// Create (if needed) and return the internal store for neighbours.
302   if (!fNeighbours)
303   {
304     fNeighbours = CreateNeighbours(fRunNumber);
305   }
306   return fNeighbours;
307 }
308
309 //_____________________________________________________________________________
310 AliMUONVCalibParam* 
311 AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
312 {
313 /// Return the masks for a given trigger local board.
314
315   if (!fLocalTriggerBoardMasks)
316   {
317     fLocalTriggerBoardMasks = CreateLocalTriggerBoardMasks(fRunNumber);
318   }
319
320   if ( fLocalTriggerBoardMasks ) 
321   {
322     AliMUONVCalibParam* ltbm = 
323       static_cast<AliMUONVCalibParam*>(fLocalTriggerBoardMasks->FindObject(localBoardNumber));
324     if (!ltbm)
325     {
326       AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
327     }
328     return ltbm;  
329   }
330   return 0x0;
331 }
332
333 //_____________________________________________________________________________
334 AliMUONVStore*
335 AliMUONCalibrationData::Pedestals() const
336 {
337   /// Return pedestals
338   if (!fPedestals)
339   {
340     fPedestals = CreatePedestals(fRunNumber);
341   }
342   return fPedestals;
343 }
344
345 //_____________________________________________________________________________
346 AliMUONVCalibParam*
347 AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
348 {
349   /// Return the pedestals for a given (detElemId, manuId) pair.
350   /// A return value of 0x0 is considered an error, meaning we should get
351   /// pedestals for all channels.
352   
353   AliMUONVStore* pedestals = Pedestals();
354   if (!pedestals) 
355   {
356     return 0x0;
357   }
358   
359   return static_cast<AliMUONVCalibParam*>(pedestals->FindObject(detElemId,manuId));
360 }
361
362 //_____________________________________________________________________________
363 void
364 AliMUONCalibrationData::Print(Option_t*) const
365 {
366   /// A very basic dump of our guts.
367
368   cout << "RunNumber " << RunNumber()
369   << " fGains=" << fGains
370   << " fPedestals=" << fPedestals
371   << " fHV=" << fHV
372   << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
373   << " fRegionalTriggerConfig=" << fRegionalTriggerConfig
374   << " fGlobalTriggerCrateConfig=" << fGlobalTriggerCrateConfig
375   << " fTriggerLut=" << fTriggerLut
376   << endl;
377 }
378
379
380 //_____________________________________________________________________________
381 AliMUONRegionalTriggerConfig* 
382 AliMUONCalibrationData::RegionalTriggerConfig() const
383 {
384   /// Return the config for the regional trigger board.
385   
386   if (!fRegionalTriggerConfig)
387   {
388     fRegionalTriggerConfig = CreateRegionalTriggerConfig(fRunNumber);
389     }
390   return fRegionalTriggerConfig;
391 }
392
393
394 //_____________________________________________________________________________
395 AliMUONTriggerEfficiencyCells*
396 AliMUONCalibrationData::TriggerEfficiency() const
397 {
398 /// Return the trigger efficiency.
399
400   if (!fTriggerEfficiency)
401   {
402     fTriggerEfficiency = CreateTriggerEfficiency(fRunNumber);
403   }
404   return fTriggerEfficiency;
405 }
406
407
408 //_____________________________________________________________________________
409 AliMUONTriggerLut*
410 AliMUONCalibrationData::TriggerLut() const
411 {
412 /// Return the trigger look up table.
413
414   if (!fTriggerLut)
415   {
416     fTriggerLut = CreateTriggerLut(fRunNumber);
417   }
418   return fTriggerLut;
419 }
420
421 //_____________________________________________________________________________
422 void
423 AliMUONCalibrationData::Reset()
424 {
425 /// Reset all data
426
427   delete fPedestals;
428   fPedestals = 0x0;
429   delete fGains;
430   fGains = 0x0;
431   delete fHV;
432   fHV = 0x0;
433   delete fLocalTriggerBoardMasks;
434   fLocalTriggerBoardMasks = 0x0;
435   delete fRegionalTriggerConfig;
436   fRegionalTriggerConfig = 0x0;
437   delete fGlobalTriggerCrateConfig;
438   fGlobalTriggerCrateConfig = 0x0;
439   
440   delete fTriggerLut;
441   fTriggerLut = 0x0;
442   delete fTriggerEfficiency;
443   fTriggerEfficiency = 0x0;
444   delete fCapacitances;
445   fCapacitances = 0x0;
446   delete fNeighbours;
447   fNeighbours = 0x0;
448 }
449
450
451