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