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