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 */
6 ///////////////////////////////////////////////////////////////////////////////
8 // Class providing the calibration parameters by accessing the CDB //
10 ///////////////////////////////////////////////////////////////////////////////
18 #include "AliTRDgeometry.h"
20 #include <AliCDBStorage.h>
21 #include <AliCDBEntry.h>
23 //includes neccessary here for compiliation of dynamic_cast
24 #include "AliTRDCalPad.h"
25 #include "AliTRDCalDet.h"
27 class AliTRDCalChamber;
29 class AliTRDCalGlobals;
31 // defines call to function by providing plane, chamber, sector instead of detector
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); }
36 // defines call to function by providing plane, chamber, sector instead of detector
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); }
41 class AliTRDcalibDB : public TObject
44 enum { kNplan = 6, kNcham = 5, kNsect = 18, kNdet = 540 };
46 static AliTRDcalibDB* Instance();
47 static void Terminate();
49 void SetRun(Long64_t run);
51 Bool_t GetChamberPos(Int_t det, Float_t* xyz);
52 HEADER_CHAMBER(GetChamberPos);
54 Bool_t GetChamberRot(Int_t det, Float_t* xyz);
55 HEADER_CHAMBER(GetChamberRot);
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);
60 Float_t GetVdrift(Int_t det, Int_t col, Int_t row);
61 HEADER_PAD(GetVdrift);
63 Float_t GetT0(Int_t det, Int_t col, Int_t row);
66 Float_t GetGainFactor(Int_t det, Int_t col, Int_t row);
67 HEADER_PAD(GetGainFactor);
69 Float_t GetPRFWidth(Int_t det, Int_t col, Int_t row);
70 HEADER_PAD(GetPRFWidth);
72 Float_t GetSamplingFrequency();
73 Int_t GetNumberOfTimeBins();
75 //Related functions, these depend on calibration data
76 static Float_t GetOmegaTau(Float_t vdrift);
77 Int_t PadResponse(Double_t signal, Double_t dist, Int_t plane, Double_t *pad) const;
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
83 TObject* GetCachedCDBObject(Int_t id)
86 // Retrieves a cdb object with the given id. The objects are cached as long as the run number is not changed.
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.
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;
95 // See function CacheMergeCDBEntry for details.
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;
104 // parameters defined per pad
105 case kIDGainFactor : return CacheCDBEntry(kIDGainFactor, "TRD/Calib/GainFactor"); break;
106 case kIDPRFWidth : return CacheCDBEntry(kIDPRFWidth, "TRD/Calib/PRFWidth"); break;
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;
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);
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
126 AliCDBStorage* fLocator; // Storage locator retrieved from AliCDBManager
128 AliCDBEntry* fCDBEntries[kCDBCacheSize]; // Cache for CDB entries
129 TObject* fCDBCache[kCDBCacheSize]; // Cache for calibration objects.
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
144 // this is a singleton, constructor is private!
146 virtual ~AliTRDcalibDB();
148 ClassDef(AliTRDcalibDB, 0)
151 AliCDBEntry* AliTRDcalibDB::GetCDBEntry(const char* cdbPath)
154 // Retrieves an entry with path <cdbPath> from the CDB.
159 AliFatal("AliTRDcalibDB: Run number not set! Use AliTRDcalibDB::SetRun.");
160 //std::cerr << "AliTRDcalibDB: Run number not set! Use AliTRDcalibDB::SetRun." << std::endl;
165 std::cerr << "AliTRDcalibDB: Storage Locator not available." << std::endl;
168 AliCDBEntry* entry = fLocator->Get(cdbPath, fRun);
171 std::cerr << "AliTRDcalibDB: Failed to get entry: " << cdbPath << std::endl;
175 std::cout << "AliTRDcalibDB: Retrieved object: " << cdbPath << std::endl;
179 TObject* AliTRDcalibDB::CacheCDBEntry(Int_t id, const char* cdbPath)
182 // Caches the entry <id> with cdb path <cdbPath>
187 fCDBEntries[id] = GetCDBEntry(cdbPath);
189 fCDBCache[id] = fCDBEntries[id]->GetObject();
191 return fCDBCache[id];
194 TObject* AliTRDcalibDB::CacheMergeCDBEntry(Int_t id, const char* cdbPadPath, const char* cdbChamberPath)
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.
205 AliTRDCalPad* padObject = 0;
206 AliTRDCalDet* detObject = 0;
208 fCDBEntries[id] = GetCDBEntry(cdbPadPath);
210 padObject = dynamic_cast<AliTRDCalPad*>(fCDBEntries[id]->GetObject());
212 AliCDBEntry* mergeEntry = GetCDBEntry(cdbChamberPath);
214 detObject = dynamic_cast<AliTRDCalDet*>(mergeEntry->GetObject());
216 if (!padObject || !detObject)
218 if (fCDBEntries[id]) {
219 if (fCDBEntries[id]->IsOwner() == kFALSE && padObject)
221 delete fCDBEntries[id];
226 if (mergeEntry->IsOwner() == kFALSE && detObject)
233 padObject->ScaleROCs(detObject);
234 if (mergeEntry->IsOwner() == kFALSE)
238 fCDBCache[id] = padObject;
241 return fCDBCache[id];
245 #undef HEADER_CHAMBER