]>
Commit | Line | Data |
---|---|---|
3551db50 | 1 | #ifndef ALITRDCALIBDB_H |
2 | #define ALITRDCALIBDB_H | |
3 | /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
4 | * See cxx source for full Copyright notice */ | |
5 | ||
6 | /////////////////////////////////////////////////////////////////////////////// | |
7 | // // | |
8 | // Class providing the calibration parameters by accessing the CDB // | |
9 | // // | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | /* $Id$ */ | |
13 | ||
14 | #include <iostream> | |
15 | #include "TObject.h" | |
16 | ||
17 | #include "AliLog.h" | |
18 | #include "AliTRDgeometry.h" | |
19 | ||
20 | #include <AliCDBStorage.h> | |
21 | #include <AliCDBEntry.h> | |
22 | ||
23 | //includes neccessary here for compiliation of dynamic_cast | |
24 | #include "AliTRDCalPad.h" | |
25 | #include "AliTRDCalDet.h" | |
26 | ||
27 | class AliTRDCalChamber; | |
28 | class AliTRDCalStack; | |
29 | class AliTRDCalGlobals; | |
30 | ||
dde59437 | 31 | // defines call to function by providing plane, chamber, sector instead of detector |
3551db50 | 32 | #define HEADER_PAD(funcname) \ |
33 | Float_t funcname(Int_t plane, Int_t chamber, Int_t sector, Int_t col, Int_t row) \ | |
34 | { return funcname(AliTRDgeometry::GetDetector(plane, chamber, sector), col, row); } | |
35 | ||
dde59437 | 36 | // defines call to function by providing plane, chamber, sector instead of detector |
3551db50 | 37 | #define HEADER_CHAMBER(funcname) \ |
38 | Bool_t funcname(Int_t plane, Int_t chamber, Int_t sector, Float_t* xyz) \ | |
39 | { return funcname(AliTRDgeometry::GetDetector(plane, chamber, sector), xyz); } | |
40 | ||
3551db50 | 41 | class AliTRDcalibDB : public TObject |
42 | { | |
43 | public: | |
6a739e92 | 44 | enum { kNplan = 6, kNcham = 5, kNsect = 18, kNdet = 540 }; |
45 | ||
3551db50 | 46 | static AliTRDcalibDB* Instance(); |
47 | static void Terminate(); | |
48 | ||
49 | void SetRun(Long64_t run); | |
50 | ||
51 | Bool_t GetChamberPos(Int_t det, Float_t* xyz); | |
52 | HEADER_CHAMBER(GetChamberPos); | |
53 | ||
54 | Bool_t GetChamberRot(Int_t det, Float_t* xyz); | |
55 | HEADER_CHAMBER(GetChamberRot); | |
56 | ||
57 | Bool_t GetStackPos(Int_t chamber, Int_t sector, Float_t* xyz); | |
58 | Bool_t GetStackRot(Int_t chamber, Int_t sector, Float_t* xyz); | |
59 | ||
60 | Float_t GetVdrift(Int_t det, Int_t col, Int_t row); | |
61 | HEADER_PAD(GetVdrift); | |
62 | ||
63 | Float_t GetT0(Int_t det, Int_t col, Int_t row); | |
64 | HEADER_PAD(GetT0); | |
65 | ||
66 | Float_t GetGainFactor(Int_t det, Int_t col, Int_t row); | |
67 | HEADER_PAD(GetGainFactor); | |
68 | ||
6a739e92 | 69 | Float_t GetPRFWidth(Int_t det, Int_t col, Int_t row); |
70 | HEADER_PAD(GetPRFWidth); | |
71 | ||
3551db50 | 72 | Float_t GetSamplingFrequency(); |
73 | Int_t GetNumberOfTimeBins(); | |
74 | ||
75 | //Related functions, these depend on calibration data | |
dde59437 | 76 | static Float_t GetOmegaTau(Float_t vdrift); |
6a739e92 | 77 | Int_t PadResponse(Double_t signal, Double_t dist, Int_t plane, Double_t *pad) const; |
3551db50 | 78 | |
79 | protected: | |
3551db50 | 80 | enum { kCDBCacheSize = 7 }; // Number of cached objects |
81 | enum { kIDVdrift = 0, kIDT0 = 1, kIDGainFactor = 2, kIDPRFWidth = 3, kIDGlobals = 4, kIDChamber = 5, kIDStack = 6 }; // IDs of cached objects | |
82 | ||
3551db50 | 83 | TObject* GetCachedCDBObject(Int_t id) |
84 | { | |
85 | // | |
6a739e92 | 86 | // Retrieves a cdb object with the given id. The objects are cached as long as the run number is not changed. |
3551db50 | 87 | // |
dde59437 | 88 | // Put together the available objects here by using the lines |
89 | // a) For usual calibration objects: | |
90 | // ase kID<Name> : return CacheCDBEntry(kID<Name>, "TRD/Calib/<Path>"); break; | |
91 | // See function CacheCDBEntry for details. | |
92 | // and | |
6a739e92 | 93 | // b) For calibration data which depends on two objects: One containing a value per detector and one the local fluctuations per pad: |
94 | // case kID<Name> : return CacheMergeCDBEntry(kID<Name>, "TRD/Calib/<padPath>", "TRD/Calib/<chamberPath>"); break; | |
dde59437 | 95 | // See function CacheMergeCDBEntry for details. |
3551db50 | 96 | // |
97 | ||
98 | switch (id) | |
99 | { | |
dde59437 | 100 | // parameters defined per pad and chamber |
101 | case kIDVdrift : return CacheMergeCDBEntry(kIDVdrift, "TRD/Calib/LocalVdrift", "TRD/Calib/ChamberVdrift"); break; | |
102 | case kIDT0 : return CacheMergeCDBEntry(kIDT0, "TRD/Calib/LocalT0", "TRD/Calib/ChamberT0"); break; | |
103 | ||
3551db50 | 104 | // parameters defined per pad |
dde59437 | 105 | case kIDGainFactor : return CacheCDBEntry(kIDGainFactor, "TRD/Calib/GainFactor"); break; |
106 | case kIDPRFWidth : return CacheCDBEntry(kIDPRFWidth, "TRD/Calib/PRFWidth"); break; | |
3551db50 | 107 | |
108 | // global parameters | |
dde59437 | 109 | case kIDGlobals : return CacheCDBEntry(kIDGlobals, "TRD/Calib/Globals"); break; |
110 | case kIDChamber : return CacheCDBEntry(kIDChamber, "TRD/Calib/Chamber"); break; | |
111 | case kIDStack : return CacheCDBEntry(kIDStack, "TRD/Calib/Stack"); break; | |
3551db50 | 112 | } |
113 | return 0; | |
114 | } | |
115 | ||
6a739e92 | 116 | void Invalidate(); |
117 | void SamplePRF(); | |
118 | ||
119 | inline AliCDBEntry* GetCDBEntry(const char* cdbPath); | |
120 | inline TObject* CacheCDBEntry(Int_t id, const char* cdbPath); | |
121 | inline TObject* CacheMergeCDBEntry(Int_t id, const char* cdbPadPath, const char* cdbChamberPath); | |
122 | ||
123 | static AliTRDcalibDB* fgInstance; // Instance of this class (singleton implementation) | |
124 | static Bool_t fgTerminated; // Defines if this class has already been terminated and therefore does not return instances in GetInstance anymore | |
125 | ||
126 | AliCDBStorage* fLocator; // Storage locator retrieved from AliCDBManager | |
127 | ||
128 | AliCDBEntry* fCDBEntries[kCDBCacheSize]; // Cache for CDB entries | |
129 | TObject* fCDBCache[kCDBCacheSize]; // Cache for calibration objects. | |
130 | ||
3551db50 | 131 | Long64_t fRun; |
132 | ||
6a739e92 | 133 | struct |
134 | { | |
135 | Float_t *fPRFsmp; //! Sampled pad response | |
136 | Int_t fPRFbin; // Number of bins for the PRF | |
137 | Float_t fPRFlo; // Lower boundary of the PRF | |
138 | Float_t fPRFhi; // Higher boundary of the PRF | |
139 | Float_t fPRFwid; // Bin width of the sampled PRF | |
140 | Int_t fPRFpad; // Distance to next pad in PRF | |
141 | } fPadResponse; | |
142 | ||
3551db50 | 143 | private: |
144 | // this is a singleton, constructor is private! | |
145 | AliTRDcalibDB(); | |
146 | virtual ~AliTRDcalibDB(); | |
147 | ||
148 | ClassDef(AliTRDcalibDB, 0) | |
149 | }; | |
150 | ||
dde59437 | 151 | AliCDBEntry* AliTRDcalibDB::GetCDBEntry(const char* cdbPath) |
152 | { | |
153 | // | |
154 | // Retrieves an entry with path <cdbPath> from the CDB. | |
155 | // | |
156 | ||
157 | if (fRun < 0) | |
158 | { | |
159 | AliFatal("AliTRDcalibDB: Run number not set! Use AliTRDcalibDB::SetRun."); | |
160 | //std::cerr << "AliTRDcalibDB: Run number not set! Use AliTRDcalibDB::SetRun." << std::endl; | |
161 | return 0; | |
162 | } | |
163 | if (!fLocator) | |
164 | { | |
165 | std::cerr << "AliTRDcalibDB: Storage Locator not available." << std::endl; | |
166 | return 0; | |
167 | } | |
168 | AliCDBEntry* entry = fLocator->Get(cdbPath, fRun); | |
169 | if (!entry) | |
170 | { | |
171 | std::cerr << "AliTRDcalibDB: Failed to get entry: " << cdbPath << std::endl; | |
172 | return 0; | |
173 | } | |
174 | ||
175 | std::cout << "AliTRDcalibDB: Retrieved object: " << cdbPath << std::endl; | |
176 | return entry; | |
177 | } | |
178 | ||
179 | TObject* AliTRDcalibDB::CacheCDBEntry(Int_t id, const char* cdbPath) | |
180 | { | |
181 | // | |
182 | // Caches the entry <id> with cdb path <cdbPath> | |
183 | // | |
184 | ||
185 | if (!fCDBCache[id]) | |
186 | { | |
187 | fCDBEntries[id] = GetCDBEntry(cdbPath); | |
188 | if (fCDBEntries[id]) | |
189 | fCDBCache[id] = fCDBEntries[id]->GetObject(); | |
190 | } | |
191 | return fCDBCache[id]; | |
192 | } | |
193 | ||
194 | TObject* AliTRDcalibDB::CacheMergeCDBEntry(Int_t id, const char* cdbPadPath, const char* cdbChamberPath) | |
195 | { | |
196 | // | |
6a739e92 | 197 | // Retrieves and caches an object (id <id>) from the CDB. This function is specialized for parameters which are stored |
198 | // as local variation at pad level of a global variable defined per detector chamber. It uses the classes AliTRDCalPad and AliTRDCalDet. | |
199 | // Before storing the object it retrieves the local variations (cdbPadPath) and the global variable (cdbChamberPath) and merges them using | |
200 | // the AliTRDCalPad::ScaleROCs. | |
dde59437 | 201 | // |
202 | ||
203 | if (!fCDBCache[id]) | |
204 | { | |
205 | AliTRDCalPad* padObject = 0; | |
206 | AliTRDCalDet* detObject = 0; | |
207 | ||
208 | fCDBEntries[id] = GetCDBEntry(cdbPadPath); | |
209 | if (fCDBEntries[id]) | |
210 | padObject = dynamic_cast<AliTRDCalPad*>(fCDBEntries[id]->GetObject()); | |
211 | ||
212 | AliCDBEntry* mergeEntry = GetCDBEntry(cdbChamberPath); | |
213 | if (mergeEntry) | |
214 | detObject = dynamic_cast<AliTRDCalDet*>(mergeEntry->GetObject()); | |
215 | ||
216 | if (!padObject || !detObject) | |
217 | { | |
218 | if (fCDBEntries[id]) { | |
219 | if (fCDBEntries[id]->IsOwner() == kFALSE && padObject) | |
220 | delete padObject; | |
221 | delete fCDBEntries[id]; | |
222 | fCDBEntries[id] = 0; | |
223 | } | |
224 | if (mergeEntry) | |
225 | { | |
226 | if (mergeEntry->IsOwner() == kFALSE && detObject) | |
227 | delete detObject; | |
228 | delete mergeEntry; | |
229 | } | |
230 | return 0; | |
231 | } | |
232 | ||
233 | padObject->ScaleROCs(detObject); | |
234 | if (mergeEntry->IsOwner() == kFALSE) | |
235 | delete detObject; | |
236 | delete mergeEntry; | |
237 | ||
238 | fCDBCache[id] = padObject; | |
239 | } | |
240 | ||
241 | return fCDBCache[id]; | |
242 | } | |
243 | ||
3551db50 | 244 | #undef HEADER_PAD |
245 | #undef HEADER_CHAMBER | |
3551db50 | 246 | |
247 | #endif |