]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONCalibrationData.cxx
- Adding option for ownership of sector
[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 "AliLog.h"
23 #include "AliMUONTriggerEfficiencyCells.h"
24 #include "AliMUONTriggerLut.h"
25 #include "AliMUONV1DStore.h"
26 #include "AliMUONV2DStore.h"
27 #include "AliMUONVCalibParam.h"
28 #include "Riostream.h"
29
30 /// \class AliMUONCalibrationData
31 ///
32 /// For the moment, this class stores pedestals, gains and deadchannels
33 /// that are fetched from the CDB.
34 ///
35 /// This class is to be considered as a convenience class.
36 /// Its aim is to ease retrieval of calibration data from the 
37 /// condition database.
38 ///
39 /// It acts as a "facade" to a bunch of underlying 
40 /// containers/calibration classes.
41 ///
42 /// \author Laurent Aphecetche
43
44 /// \cond CLASSIMP
45 ClassImp(AliMUONCalibrationData)
46 /// \endcond
47
48 //_____________________________________________________________________________
49 AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber, 
50                                                Bool_t deferredInitialization) 
51 : TObject(), 
52 fIsValid(kTRUE),
53 fRunNumber(runNumber), 
54 fGains(0x0), 
55 fPedestals(0x0),
56 fDeadChannels(0x0),
57 fLocalTriggerBoardMasks(0x0),
58 fRegionalTriggerBoardMasks(0x0),
59 fGlobalTriggerBoardMasks(0x0),
60 fTriggerLut(0x0),
61 fTriggerEfficiency(0x0)
62 {
63 /// Default ctor.
64
65   // If deferredInitialization is false, we read *all* calibrations
66   // at once.
67   // So when using this class to access only one kind of calibrations (e.g.
68   // only pedestals), you should put deferredInitialization to kTRUE, which
69   // will instruct this object to fetch the data only when neeeded.
70
71   if ( deferredInitialization == kFALSE )
72   {
73     OnDemandGains();
74     OnDemandPedestals();
75     OnDemandDeadChannels();
76     OnDemandLocalTriggerBoardMasks();
77     OnDemandRegionalTriggerBoardMasks();
78     OnDemandGlobalTriggerBoardMasks();
79     OnDemandTriggerLut();
80     OnDemandTriggerEfficiency();
81   }
82 }
83
84 //_____________________________________________________________________________
85 AliMUONCalibrationData::~AliMUONCalibrationData()
86 {
87 /// Destructor. Note that we're the owner of our pointers.
88
89   delete fPedestals;
90   delete fGains;
91   delete fDeadChannels;
92   delete fLocalTriggerBoardMasks;
93   delete fRegionalTriggerBoardMasks;
94   delete fGlobalTriggerBoardMasks;
95   delete fTriggerLut;
96   delete fTriggerEfficiency;
97 }
98
99 //_____________________________________________________________________________
100 AliMUONVCalibParam*
101 AliMUONCalibrationData::DeadChannels(Int_t detElemId, Int_t manuId) const
102 {
103 /// Return the calibration for a given (detElemId, manuId) pair
104 /// Note that for DeadChannel, it's "legal" to return 0x0 (e.g. if a manu
105 /// is perfect, we might simply forget it in the store).
106
107   return
108   static_cast<AliMUONVCalibParam*>(OnDemandDeadChannels()->Get(detElemId,manuId));
109 }
110
111 //_____________________________________________________________________________
112 AliMUONV2DStore*
113 AliMUONCalibrationData::OnDemandDeadChannels() const
114 {
115 /// Create (if needed) and return the internal store for DeadChannels.
116
117   if (!fDeadChannels)
118   {
119     AliCDBEntry* entry = GetEntry("MUON/Calib/DeadChannels");
120     if (entry)
121     {
122       fDeadChannels = dynamic_cast<AliMUONV2DStore*>(entry->GetObject());
123       if (!fDeadChannels)
124       {
125         AliError("fDeadChannels not of the expected type !!!");
126       }
127     }
128     else
129     {
130       AliError("Could not get dead channels !");
131     }
132   }
133   return fDeadChannels;
134 }
135
136 //_____________________________________________________________________________
137 AliCDBEntry*
138 AliMUONCalibrationData::GetEntry(const char* path) const
139 {
140 /// Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
141 /// and return the corresponding CDBEntry.
142
143   return AliCDBManager::Instance()->Get(path,fRunNumber);
144 }
145
146 //_____________________________________________________________________________
147 AliMUONVCalibParam*
148 AliMUONCalibrationData::Gains(Int_t detElemId, Int_t manuId) const
149 {
150 /// Return the gains for a given (detElemId, manuId) pair
151 /// Note that, unlike the DeadChannel case, if the result is 0x0, that's an
152 /// error (meaning that we should get gains for all channels).
153
154   AliMUONVCalibParam* gain = 
155     static_cast<AliMUONVCalibParam*>(OnDemandGains()->Get(detElemId,manuId));
156   if (!gain)
157   {
158     AliError(Form("Could not get gain for detElemId=%d manuId=%d ",
159                     detElemId,manuId));
160   }
161   return gain;
162 }
163
164 //_____________________________________________________________________________
165 AliMUONV2DStore*
166 AliMUONCalibrationData::OnDemandGains() const
167 {
168 /// Create (if needed) and return the internal store for gains.
169
170   if (!fGains)
171   {
172     AliCDBEntry* entry = GetEntry("MUON/Calib/Gains");
173     if (entry)
174     {
175       fGains = dynamic_cast<AliMUONV2DStore*>(entry->GetObject());
176       if (!fGains)
177       {
178         AliError("Gains not of the expected type !!!");
179       }
180     }
181     else
182     {
183       AliError("Could not get gains !");
184     }
185   }
186   return fGains;
187 }
188
189 //_____________________________________________________________________________
190 AliMUONVCalibParam* 
191 AliMUONCalibrationData::GlobalTriggerBoardMasks() const
192 {
193 /// Return the masks for the global trigger board.
194
195   return OnDemandGlobalTriggerBoardMasks();
196 }
197
198 //_____________________________________________________________________________
199 AliMUONVCalibParam*
200 AliMUONCalibrationData::OnDemandGlobalTriggerBoardMasks() const
201 {
202 /// Create (if needed) and return the internal store for GlobalTriggerBoardMasks.
203
204   if (!fGlobalTriggerBoardMasks)
205   {
206     AliCDBEntry* entry = GetEntry("MUON/Calib/GlobalTriggerBoardMasks");
207     if (entry)
208     {
209       fGlobalTriggerBoardMasks = dynamic_cast<AliMUONVCalibParam*>(entry->GetObject());
210       if (!fGlobalTriggerBoardMasks)
211       {
212         AliError("fGlobalTriggerBoardMasks not of the expected type !!!");
213       }
214     }
215     else
216     {
217       AliError("Could not get global trigger board masks !");
218     }
219   }
220   return fGlobalTriggerBoardMasks;
221 }
222
223 //_____________________________________________________________________________
224 AliMUONVCalibParam* 
225 AliMUONCalibrationData::LocalTriggerBoardMasks(Int_t localBoardNumber) const
226 {
227 /// Return the masks for a given trigger local board.
228
229   AliMUONVCalibParam* ltbm = 
230   static_cast<AliMUONVCalibParam*>(OnDemandLocalTriggerBoardMasks()->Get(localBoardNumber));
231   if (!ltbm)
232   {
233     AliError(Form("Could not get mask for localBoardNumber=%d",localBoardNumber));
234   }
235   return ltbm;  
236 }
237
238 //_____________________________________________________________________________
239 AliMUONV1DStore*
240 AliMUONCalibrationData::OnDemandLocalTriggerBoardMasks() const
241 {
242 /// Create (if needed) and return the internal store for LocalTriggerBoardMasks.
243
244   if (!fLocalTriggerBoardMasks)
245   {
246     AliCDBEntry* entry = GetEntry("MUON/Calib/LocalTriggerBoardMasks");
247     if (entry)
248     {
249       fLocalTriggerBoardMasks = dynamic_cast<AliMUONV1DStore*>(entry->GetObject());
250       if (!fLocalTriggerBoardMasks)
251       {
252         AliError("fLocalTriggerBoardMasks not of the expected type !!!");
253       }
254     }
255     else
256     {
257       AliError("Could not get local trigger board masks !");
258     }
259   }
260   return fLocalTriggerBoardMasks;
261 }
262
263 //_____________________________________________________________________________
264 AliMUONV2DStore*
265 AliMUONCalibrationData::OnDemandPedestals() const
266 {
267 /// Create (if needed) and return the internal storage for pedestals.
268
269   if (!fPedestals)
270   {
271     AliCDBEntry* entry = GetEntry("MUON/Calib/Pedestals");
272     if (entry)
273     {
274       fPedestals = dynamic_cast<AliMUONV2DStore*>(entry->GetObject());
275       if (!fPedestals)
276       {
277         AliError("fPedestals not of the expected type !!!");
278       }
279     }
280     else
281     {
282       AliError("Could not get pedestals !");
283     }
284   }
285   return fPedestals;
286 }
287
288 //_____________________________________________________________________________
289 void
290 AliMUONCalibrationData::Print(Option_t*) const
291 {
292 /// A very basic dump of our guts.
293
294   cout << "RunNumber " << RunNumber()
295   << " fGains=" << fGains
296   << " fPedestals=" << fPedestals
297   << " fDeadChannels=" << fDeadChannels
298   << " fLocalTriggerBoardMasks=" << fLocalTriggerBoardMasks
299   << " fRegionalTriggerBoardMasks=" << fRegionalTriggerBoardMasks
300   << " fGlobalTriggerBoardMasks=" << fGlobalTriggerBoardMasks
301   << " fTriggerLut=" << fTriggerLut
302   << endl;
303 }
304
305
306 //_____________________________________________________________________________
307 AliMUONVCalibParam*
308 AliMUONCalibrationData::Pedestals(Int_t detElemId, Int_t manuId) const
309 {
310 /// Return the pedestals for a given (detElemId, manuId) pair.
311 /// A return value of 0x0 is considered an error, meaning we should get
312 /// pedestals for all channels.
313
314   AliMUONVCalibParam* ped = 
315     static_cast<AliMUONVCalibParam*>(OnDemandPedestals()->Get(detElemId,manuId));
316   if (!ped)
317   {
318     AliError(Form("Could not get pedestal for detElemId=%d manuId=%d ",
319                   detElemId,manuId));
320   }
321   return ped;
322 }
323
324 //_____________________________________________________________________________
325 AliMUONVCalibParam* 
326 AliMUONCalibrationData::RegionalTriggerBoardMasks(Int_t index) const
327 {
328 /// Return the masks for a given trigger regional board.
329
330   AliMUONVCalibParam* rtbm = 
331   static_cast<AliMUONVCalibParam*>(OnDemandRegionalTriggerBoardMasks()->Get(index));
332   if (!rtbm)
333   {
334     AliError(Form("Could not get mask for regionalBoard index=%d",index));
335   }
336   return rtbm;  
337 }
338
339 //_____________________________________________________________________________
340 AliMUONV1DStore*
341 AliMUONCalibrationData::OnDemandRegionalTriggerBoardMasks() const
342 {
343 /// Create (if needed) and return the internal store for RegionalTriggerBoardMasks.
344
345   if (!fRegionalTriggerBoardMasks)
346   {
347     AliCDBEntry* entry = GetEntry("MUON/Calib/RegionalTriggerBoardMasks");
348     if (entry)
349     {
350       fRegionalTriggerBoardMasks = dynamic_cast<AliMUONV1DStore*>(entry->GetObject());
351       if (!fRegionalTriggerBoardMasks)
352       {
353         AliError("fRegionalTriggerBoardMasks not of the expected type !!!");
354       }
355     }
356     else
357     {
358       AliError("Could not get regional trigger board masks !");
359     }
360   }
361   return fRegionalTriggerBoardMasks;
362 }
363
364 //_____________________________________________________________________________
365 AliMUONTriggerEfficiencyCells*
366 AliMUONCalibrationData::TriggerEfficiency() const
367 {
368 /// Return the trigger efficiency.
369
370   return OnDemandTriggerEfficiency();
371 }
372
373 //_____________________________________________________________________________
374 AliMUONTriggerEfficiencyCells* 
375 AliMUONCalibrationData::OnDemandTriggerEfficiency() const
376 {
377 /// \todo: add comment
378
379   if (!fTriggerEfficiency)
380   {
381     AliCDBEntry* entry = GetEntry("MUON/Calib/TriggerEfficiency");
382     if (entry)
383     {
384       fTriggerEfficiency = dynamic_cast<AliMUONTriggerEfficiencyCells*>(entry->GetObject());
385       if (!fTriggerEfficiency)
386       {
387         AliError("fTriggerEfficiency not of the expected type !!!");
388       }
389     }
390     else
391     {
392       AliError("Could not get trigger efficiency !");
393     }
394   }
395   return fTriggerEfficiency;
396 }
397
398 //_____________________________________________________________________________
399 AliMUONTriggerLut*
400 AliMUONCalibrationData::TriggerLut() const
401 {
402 /// Return the trigger look up table.
403
404   return OnDemandTriggerLut();
405 }
406
407 //_____________________________________________________________________________
408 AliMUONTriggerLut* 
409 AliMUONCalibrationData::OnDemandTriggerLut() const
410 {
411 /// \todo: add comment
412
413   if (!fTriggerLut)
414   {
415     AliCDBEntry* entry = GetEntry("MUON/Calib/TriggerLut");
416     if (entry)
417     {
418       fTriggerLut = dynamic_cast<AliMUONTriggerLut*>(entry->GetObject());
419       if (!fTriggerLut)
420       {
421         AliError("fTriggerLut not of the expected type !!!");
422       }
423     }
424     else
425     {
426       AliError("Could not get trigger lut !");
427     }
428   }
429   return fTriggerLut;
430 }
431
432
433