]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCcalibDB.cxx
50be7ddce0cecee8c8861154cb0b5d5617b01db1
[u/mrichter/AliRoot.git] / TPC / AliTPCcalibDB.cxx
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
17 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 // Class providing the calibration parameters by accessing the CDB           //
20 //                                                                           //
21 // Request an instance with AliTPCcalibDB::Instance()                        //
22 // If a new event is processed set the event number with SetRun              //
23 // Then request the calibration data                                         // 
24 //                                                                           //
25 ///////////////////////////////////////////////////////////////////////////////
26
27
28 #include <AliCDBManager.h>
29 #include <AliCDBStorage.h>
30 #include <AliCDBEntry.h>
31 #include <AliLog.h>
32
33 #include "AliTPCcalibDB.h"
34
35 #include "AliTPCParam.h"
36 #include "AliTPCCalROC.h"
37 #include "AliTPCCalPad.h"
38 #include "AliTPCCalDet.h"
39
40 ClassImp(AliTPCcalibDB)
41
42 AliTPCcalibDB* AliTPCcalibDB::fgInstance = 0;
43 Bool_t AliTPCcalibDB::fgTerminated = kFALSE;
44
45
46 //_ singleton implementation __________________________________________________
47 AliTPCcalibDB* AliTPCcalibDB::Instance()
48 {
49   //
50   // Singleton implementation
51   // Returns an instance of this class, it is created if neccessary
52   //
53   
54   if (fgTerminated != kFALSE)
55     return 0;
56
57   if (fgInstance == 0)
58     fgInstance = new AliTPCcalibDB();
59   
60   return fgInstance;
61 }
62
63 void AliTPCcalibDB::Terminate()
64 {
65   //
66   // Singleton implementation
67   // Deletes the instance of this class and sets the terminated flag, instances cannot be requested anymore
68   // This function can be called several times.
69   //
70   
71   fgTerminated = kTRUE;
72   
73   if (fgInstance != 0)
74   {
75     delete fgInstance;
76     fgInstance = 0;
77   }
78 }
79
80 //_____________________________________________________________________________
81 AliTPCcalibDB::AliTPCcalibDB()
82               :TObject(),
83                fRun(-1),
84                fPadGainFactor(0),
85                fPadTime0(0),
86                fPadPRFWidth(0),
87                fPadNoise(0),
88                fPedestals(0),
89                fParam(0)
90 {
91   //
92   // constructor
93   //  
94   fRun = AliCDBManager::Instance()->GetRun();
95   Update();    // temporary
96 }
97
98 //_____________________________________________________________________________
99 AliTPCcalibDB::~AliTPCcalibDB() 
100 {
101   //
102   // destructor
103   //
104   
105   // don't delete anything, CDB cache is active!
106   //if (fPadGainFactor) delete fPadGainFactor;
107   //if (fPadTime0) delete fPadTime0;
108   //if (fPadPRFWidth) delete fPadPRFWidth;
109   //if (fPadNoise) delete fPadNoise;
110   if (fParam) {delete fParam; fParam = 0;}
111 }
112
113
114 //_____________________________________________________________________________
115 AliCDBEntry* AliTPCcalibDB::GetCDBEntry(const char* cdbPath)
116 {
117   // 
118   // Retrieves an entry with path <cdbPath> from the CDB.
119   //
120   char chinfo[1000];
121     
122   AliCDBEntry* entry = AliCDBManager::Instance()->Get(cdbPath, fRun); 
123   if (!entry) 
124   { 
125     sprintf(chinfo,"AliTPCcalibDB: Failed to get entry:\t%s ", cdbPath);
126     AliError(chinfo); 
127     return 0; 
128   }
129   return entry;
130 }
131
132
133 //_____________________________________________________________________________
134 void AliTPCcalibDB::SetRun(Long64_t run)
135 {
136   //
137   // Sets current run number. Calibration data is read from the corresponding file. 
138   //  
139   if (fRun == run)
140     return;  
141   fRun = run;
142   Update();
143 }
144   
145
146
147 void AliTPCcalibDB::Update(){
148   //
149   AliCDBEntry * entry=0;
150   
151   Bool_t cdbCache = AliCDBManager::Instance()->GetCacheFlag(); // save cache status
152   AliCDBManager::Instance()->SetCacheFlag(kTRUE); // activate CDB cache
153   
154   //
155   entry          = GetCDBEntry("TPC/Calib/PadGainFactor");
156   if (entry){
157     //if (fPadGainFactor) delete fPadGainFactor;
158     entry->SetOwner(kTRUE);
159     fPadGainFactor = (AliTPCCalPad*)entry->GetObject();
160   }
161   //
162   entry          = GetCDBEntry("TPC/Calib/PadTime0");
163   if (entry){
164     //if (fPadTime0) delete fPadTime0;
165     entry->SetOwner(kTRUE);
166     fPadTime0 = (AliTPCCalPad*)entry->GetObject();
167   }
168   //
169   entry          = GetCDBEntry("TPC/Calib/PadPRF");
170   if (entry){
171     //if (fPadPRFWidth) delete fPadPRFWidth;
172     entry->SetOwner(kTRUE);
173     fPadPRFWidth = (AliTPCCalPad*)entry->GetObject();
174   }
175   //
176   entry          = GetCDBEntry("TPC/Calib/PadNoise");
177   if (entry){
178     //if (fPadNoise) delete fPadNoise;
179     entry->SetOwner(kTRUE);
180     fPadNoise = (AliTPCCalPad*)entry->GetObject();
181   }
182
183   entry          = GetCDBEntry("TPC/Calib/Pedestals");
184   if (entry){
185     //if (fPedestals) delete fPedestals;
186     entry->SetOwner(kTRUE);
187     fPedestals = (AliTPCCalPad*)entry->GetObject();
188   }
189
190   entry          = GetCDBEntry("TPC/Calib/Parameters");
191   if (entry){
192     if (fParam) {delete fParam; fParam = 0;}
193     entry->SetOwner(kTRUE);
194     fParam = (AliTPCParam*)(entry->GetObject()->Clone());
195   }
196
197
198   //
199   AliCDBManager::Instance()->SetCacheFlag(cdbCache); // reset original CDB cache
200   
201 }
202
203
204 AliTPCCalPad*  AliTPCcalibDB::GetPadGainFactor() {
205   //
206   // GetPadGainFactor  
207   //
208   if (!fPadGainFactor) AliFatal("Pad gain calibration entry not available\n");  
209   return fPadGainFactor;
210 }
211 AliTPCCalPad*  AliTPCcalibDB::GetPadTime0() {
212   //
213   //   GetPadTime0
214   //
215   if (!fPadTime0) AliFatal("Time 0 calibration entry not available\n");  
216   return fPadTime0;
217 }
218
219 AliTPCCalPad*  AliTPCcalibDB::GetPadPRFWidth() {
220   //
221   // GetPRF width  
222   //
223   if (!fPadPRFWidth) AliFatal("PRF calibration entry not available\n");    
224   return fPadPRFWidth;
225 }
226
227 AliTPCCalPad*  AliTPCcalibDB::GetPadNoise() {
228   //
229   // GetPadNoise  
230   //
231   if (!fPadNoise) AliFatal("Pad noise calibration entry not available\n");  
232   return fPadNoise;
233 }
234
235 AliTPCCalPad*  AliTPCcalibDB::GetPedestals() {
236   //
237   // GetPedestal  
238   //
239   if (!fPadGainFactor) AliFatal("Pedestal calibration entry not available\n");  
240   return fPedestals;
241 }
242
243 AliTPCParam*   AliTPCcalibDB::GetParameters(){
244   //
245   // GetParameters
246   //
247   if (!fParam) AliFatal("Parameters calibration entry not available\n");  
248   return fParam;
249 }
250
251
252