Coding conventions
[u/mrichter/AliRoot.git] / MUON / AliMUONCalibrationData.cxx
CommitLineData
c5bdf179 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 "AliCDBStorage.h"
c5bdf179 23#include "AliLog.h"
c3ce65fd 24#include "AliMUONV2DStore.h"
25#include "AliMUONVCalibParam.h"
c5bdf179 26#include "Riostream.h"
27
28ClassImp(AliMUONCalibrationData)
29
30//_____________________________________________________________________________
31AliMUONCalibrationData::AliMUONCalibrationData(Int_t runNumber,
32 Bool_t deferredInitialization)
33: TObject(),
34fIsValid(kTRUE),
35fRunNumber(runNumber),
36fGains(0x0),
c3ce65fd 37fPedestals(0x0),
38fDeadChannels(0x0)
c5bdf179 39{
c3ce65fd 40 //
41 // Default ctor.
42 // If deferredInitialization is false, we read *all* calibrations
43 // at once.
44 // So when using this class to access only one kind of calibrations (e.g.
45 // only pedestals), you should put deferredInitialization to kTRUE, which
46 // will instruct this object to fetch the data only when neeeded.
47 //
c5bdf179 48 if ( deferredInitialization == kFALSE )
49 {
50 Gains();
51 Pedestals();
c3ce65fd 52 DeadChannels();
c5bdf179 53 }
54}
55
884a73f1 56//______________________________________________________________________________
57AliMUONCalibrationData::AliMUONCalibrationData(const AliMUONCalibrationData& right)
58 : TObject(right)
59{
60/// Protected copy constructor (not implemented)
61
62 AliFatal("Copy constructor not provided.");
63}
c5bdf179 64
65//_____________________________________________________________________________
66AliMUONCalibrationData::~AliMUONCalibrationData()
67{
c3ce65fd 68 //
69 // dtor. Note that we're the owner of our pointers.
70 //
c5bdf179 71 delete fPedestals;
72 delete fGains;
c3ce65fd 73 delete fDeadChannels;
74}
75
884a73f1 76//______________________________________________________________________________
77AliMUONCalibrationData&
78AliMUONCalibrationData::operator=(const AliMUONCalibrationData& right)
79{
80/// Protected assignement operator (not implemented)
81
82 // check assignement to self
83 if (this == &right) return *this;
84
85 AliFatal("Assignement operator not provided.");
86
87 return *this;
88}
c3ce65fd 89
90//_____________________________________________________________________________
91AliMUONVCalibParam*
92AliMUONCalibrationData::DeadChannel(Int_t detElemId, Int_t manuId) const
93{
94 //
95 // Return the calibration for a given (detElemId, manuId) pair
96 // Note that for DeadChannel, it's "legal" to return 0x0 (e.g. if a manu
97 // is perfect, we might simply forget it in the store).
98 //
99 return
100 static_cast<AliMUONVCalibParam*>(DeadChannels()->Get(detElemId,manuId));
101}
102
103//_____________________________________________________________________________
104AliMUONV2DStore*
105AliMUONCalibrationData::DeadChannels() const
106{
107 //
108 // Create (if needed) and return the internal store for DeadChannels.
109 //
110 if (!fDeadChannels)
111 {
112 AliCDBEntry* entry = GetEntry("MUON/Calib/DeadChannels");
113 if (entry)
114 {
115 fDeadChannels = dynamic_cast<AliMUONV2DStore*>(entry->GetObject());
116 if (!fDeadChannels)
117 {
118 AliError("fDeadChannels not of the expected type !!!");
119 }
120 }
121 else
122 {
123 AliError("Could not get dead channels !");
124 }
125 }
126 return fDeadChannels;
c5bdf179 127}
128
129//_____________________________________________________________________________
130AliCDBEntry*
131AliMUONCalibrationData::GetEntry(const char* path) const
132{
c3ce65fd 133 //
134 // Access the CDB for a given path (e.g. MUON/Calib/Pedestals),
135 // and return the corresponding CDBEntry.
136 //
c5bdf179 137 AliInfo(Form("Fetching %s from Condition DataBase for run %d",path,fRunNumber));
138
139 AliCDBManager* man = AliCDBManager::Instance();
140 if (!man->IsDefaultStorageSet())
141 {
142 AliError("No default CDB storage set !");
143 fIsValid = kFALSE;
144 return 0;
145 }
146
147 AliCDBStorage* storage = man->GetDefaultStorage();
148
149 AliCDBEntry* entry = storage->Get(path,fRunNumber);
150 return entry;
151}
152
153//_____________________________________________________________________________
c3ce65fd 154AliMUONVCalibParam*
155AliMUONCalibrationData::Gain(Int_t detElemId, Int_t manuId) const
c5bdf179 156{
c3ce65fd 157 //
158 // Return the gains for a given (detElemId, manuId) pair
159 // Note that, unlike the DeadChannel case, if the result is 0x0, that's an
160 // error (meaning that we should get gains for all channels).
161 //
162 AliMUONVCalibParam* gain =
163 static_cast<AliMUONVCalibParam*>(Gains()->Get(detElemId,manuId));
c5bdf179 164 if (!gain)
165 {
c3ce65fd 166 AliError(Form("Could not get gain for detElemId=%d manuId=%d ",
167 detElemId,manuId));
c5bdf179 168 }
169 return gain;
170}
171
172//_____________________________________________________________________________
c3ce65fd 173AliMUONV2DStore*
c5bdf179 174AliMUONCalibrationData::Gains() const
175{
c3ce65fd 176 //
177 // Create (if needed) and return the internal store for gains.
178 //
c5bdf179 179 if (!fGains)
180 {
181 AliCDBEntry* entry = GetEntry("MUON/Calib/Gains");
182 if (entry)
183 {
c3ce65fd 184 fGains = dynamic_cast<AliMUONV2DStore*>(entry->GetObject());
c5bdf179 185 if (!fGains)
186 {
187 AliError("Gains not of the expected type !!!");
188 }
189 }
190 else
191 {
192 AliError("Could not get gains !");
193 }
194 }
195 return fGains;
196}
197
198//_____________________________________________________________________________
c3ce65fd 199AliMUONV2DStore*
c5bdf179 200AliMUONCalibrationData::Pedestals() const
201{
c3ce65fd 202 //
203 // Create (if needed) and return the internal storage for pedestals.
204 //
c5bdf179 205 if (!fPedestals)
206 {
207 AliCDBEntry* entry = GetEntry("MUON/Calib/Pedestals");
208 if (entry)
209 {
c3ce65fd 210 fPedestals = dynamic_cast<AliMUONV2DStore*>(entry->GetObject());
c5bdf179 211 if (!fPedestals)
212 {
213 AliError("fPedestals not of the expected type !!!");
214 }
215 }
216 else
217 {
218 AliError("Could not get pedestals !");
219 }
220 }
221 return fPedestals;
222}
223
224//_____________________________________________________________________________
225void
226AliMUONCalibrationData::Print(Option_t*) const
227{
c3ce65fd 228 //
229 // A very basic dump of our guts.
230 //
c5bdf179 231 cout << "RunNumber " << RunNumber()
232 << " fGains=" << fGains
c3ce65fd 233 << " fPedestals=" << fPedestals
234 << " fDeadChannels=" << fDeadChannels
c5bdf179 235 << endl;
236}
237
c5bdf179 238
239//_____________________________________________________________________________
c3ce65fd 240AliMUONVCalibParam*
241AliMUONCalibrationData::Pedestal(Int_t detElemId, Int_t manuId) const
c5bdf179 242{
c3ce65fd 243 //
244 // Return the pedestals for a given (detElemId, manuId) pair.
245 // A return value of 0x0 is considered an error, meaning we should get
246 // pedestals for all channels.
247 //
248 AliMUONVCalibParam* ped =
249 static_cast<AliMUONVCalibParam*>(Pedestals()->Get(detElemId,manuId));
c5bdf179 250 if (!ped)
251 {
c3ce65fd 252 AliError(Form("Could not get pedestal for detElemId=%d manuId=%d ",
253 detElemId,manuId));
c5bdf179 254 }
255 return ped;
256}
257
258