]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALTriggerDCSConfigDB.cxx
Coverity fixes (Ivana)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerDCSConfigDB.cxx
CommitLineData
fff39dd1 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
de39a0ff 16/*
17
18
19
20
21Adapted from TRD
22Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
23*/
24
fff39dd1 25#include <TClonesArray.h>
26#include <TObjArray.h>
27
28#include "AliCDBManager.h"
29#include "AliCDBEntry.h"
30#include "AliLog.h"
31
32#include "AliEMCALTriggerDCSConfigDB.h"
33#include "AliEMCALTriggerDCSConfig.h"
34#include "AliEMCALTriggerSTUDCSConfig.h"
35#include "AliEMCALTriggerTRUDCSConfig.h"
36
37ClassImp(AliEMCALTriggerDCSConfigDB)
38
39AliEMCALTriggerDCSConfigDB* AliEMCALTriggerDCSConfigDB::fgInstance = 0;
40Bool_t AliEMCALTriggerDCSConfigDB::fgTerminated = kFALSE;
41
42//_____________________________________________________________________________
43AliEMCALTriggerDCSConfigDB* AliEMCALTriggerDCSConfigDB::Instance()
44{
45 //
46 // Singleton implementation
47 // Returns an instance of this class, it is created if neccessary
48 //
49
50 if (fgTerminated != kFALSE)
51 {
52 return 0;
53 }
54
55 if (fgInstance == 0)
56 {
57 fgInstance = new AliEMCALTriggerDCSConfigDB();
58 }
59
60 return fgInstance;
61}
62
63//_____________________________________________________________________________
64void AliEMCALTriggerDCSConfigDB::Terminate()
65{
66 //
67 // Singleton implementation
68 // Deletes the instance of this class and sets the terminated flag,
69 // instances cannot be requested anymore
70 // This function can be called several times.
71 //
72
73 fgTerminated = kTRUE;
74
75 if (fgInstance != 0)
76 {
77 delete fgInstance;
78 fgInstance = 0;
79 }
80}
81
82//_____________________________________________________________________________
83AliEMCALTriggerDCSConfigDB::AliEMCALTriggerDCSConfigDB() : TObject()
84,fRun(-1)
85{
86 //
87 // Default constructor
88 //
89 // TODO Default runnumber is set to 0, this should be changed later
90 // to an invalid value (e.g. -1) to prevent
91 // TODO invalid calibration data to be used.
92 //
93
94 for (Int_t i = 0; i < kCDBCacheSize; ++i)
95 {
96 fCDBCache[i] = 0;
97 fCDBEntries[i] = 0;
98 }
99}
100
101//_____________________________________________________________________________
102AliEMCALTriggerDCSConfigDB::AliEMCALTriggerDCSConfigDB(const AliEMCALTriggerDCSConfigDB &c) : TObject(c)
103,fRun(-1)
104{
105 //
106 // Copy constructor (not that it make any sense for a singleton...)
107 //
108
109 for (Int_t i = 0; i < kCDBCacheSize; ++i)
110 {
111 fCDBCache[i] = 0;
112 fCDBEntries[i] = 0;
113 }
114}
115
116//_____________________________________________________________________________
117AliEMCALTriggerDCSConfigDB &AliEMCALTriggerDCSConfigDB::operator=(const AliEMCALTriggerDCSConfigDB &c)
118{
119 //
120 // Assignment operator (same as above ...)
121 //
122 if (this != &c)
123 {
124 AliFatal("No assignment operator defined");
125 }
126
127 return *this;
128}
129
130//_____________________________________________________________________________
131AliEMCALTriggerDCSConfigDB::~AliEMCALTriggerDCSConfigDB()
132{
133 //
134 // destructor
135 //
136 Invalidate();
137}
138
139//_____________________________________________________________________________
140const TObject *AliEMCALTriggerDCSConfigDB::GetCachedCDBObject(Int_t id)
141{
142 //
143 // Retrieves a cdb object with the given id. The objects are cached as
144 // long as the run number is not changed.
145 //
fff39dd1 146 switch (id)
147 {
148 // Parameters defined per pad and chamber
149 case kIDTriggerConfig :
714dff34 150 return CacheCDBEntry(kIDTriggerConfig, "EMCAL/Calib/Trigger");
fff39dd1 151 break;
152 default:
153 AliError("Object not found!");
154 break;
155 }
156
157 return 0x0;
158}
159
160//_____________________________________________________________________________
161AliCDBEntry* AliEMCALTriggerDCSConfigDB::GetCDBEntry(const char *cdbPath)
162{
163 //
164 // Retrieves an entry with path <cdbPath> from the CDB.
165 //
166 AliCDBEntry *entry = AliCDBManager::Instance()->Get(cdbPath,fRun);
167
168 if (!entry)
169 {
170 AliError(Form("Failed to get entry: %s",cdbPath));
171 return 0;
172 }
173
174 return entry;
175}
176
177//_____________________________________________________________________________
178const TObject *AliEMCALTriggerDCSConfigDB::CacheCDBEntry(Int_t id, const char *cdbPath)
179{
180 //
181 // Caches the entry <id> with cdb path <cdbPath>
182 //
183
184 if (!fCDBCache[id])
185 {
186 fCDBEntries[id] = GetCDBEntry(cdbPath);
187
188 if (fCDBEntries[id]) fCDBCache[id] = fCDBEntries[id]->GetObject();
189 }
190
191 return fCDBCache[id];
192}
193
194//_____________________________________________________________________________
195void AliEMCALTriggerDCSConfigDB::SetRun(Long64_t run)
196{
197 //
198 // Sets current run number. Calibration data is read from the corresponding file.
199 // When the run number changes the caching is invalidated.
200 //
201
202 if (fRun == run) return;
203
204 fRun = run;
205
206 Invalidate();
207}
208
209//_____________________________________________________________________________
210void AliEMCALTriggerDCSConfigDB::Invalidate()
211{
212 //
213 // Invalidates cache (when run number is changed).
214 //
215 for (Int_t i = 0; i < kCDBCacheSize; ++i)
216 {
217 if (fCDBEntries[i])
218 {
219 if (AliCDBManager::Instance()->GetCacheFlag() == kFALSE)
220 {
221 if ((fCDBEntries[i]->IsOwner() == kFALSE) && (fCDBCache[i])) delete fCDBCache[i];
222
223 delete fCDBEntries[i];
224 }
225
226 fCDBEntries[i] = 0;
227 fCDBCache[i] = 0;
228 }
229 }
230}
231
232//_____________________________________________________________________________
233const AliEMCALTriggerDCSConfig* AliEMCALTriggerDCSConfigDB::GetTriggerDCSConfig()
234{
235 //
236 //
237 //
238 const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));
239
240 if (!dcsConf)
241 {
242 AliError("Trigger DCS configuration not found!");
243 return 0x0;
244 }
245 else
246 return dcsConf;
247}
248
249//_____________________________________________________________________________
de39a0ff 250void AliEMCALTriggerDCSConfigDB::GetSTUSegmentation(Int_t ssg[], Int_t spg[], Int_t ssj[], Int_t spj[])
fff39dd1 251{
252 //
253 //
254 //
255 const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));
a51e676d 256 if(dcsConf){
257 AliEMCALTriggerSTUDCSConfig* stuConf = dcsConf->GetSTUDCSConfig();
258 if(stuConf){
259 Int_t fw = stuConf->GetFw();
260
261 switch ( fw )
262 {
263 case 2223:
264 ssg[0] = 1;
265 ssg[1] = 1;
266 spg[0] = 2;
267 spg[1] = 2;
268
269 ssj[0] = 4;
270 ssj[1] = 4;
271 spj[0] = 2;
272 spj[1] = 2;
273 break;
274 default:
275 AliError("Firmware version do not match!");
276 break;
277 }
278 }
279 else {
280 AliError("STUDCSConfig is null!");
281 }
282 }
283 else {
284 AliError("DCSConfig is null!");
285 }
286
fff39dd1 287}
288
de39a0ff 289//_____________________________________________________________________________
290Int_t AliEMCALTriggerDCSConfigDB::GetTRUSegmentation(Int_t iTRU)
291{
292 //
293 const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));
622e10be 294 if(dcsConf){
295 AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(iTRU);
296 if(truConf){
297 Int_t sel = truConf->GetL0SEL();
de39a0ff 298
622e10be 299 if (sel & 0x0001)
300 return 2;
301 else
302 return 1;
1c1f9d16 303 } else AliError("TRUDCSConf Null!") ;
304 }else AliError("TriggerDCSConf Null!") ;
622e10be 305
306 return -1;
de39a0ff 307}
308
fff39dd1 309//_____________________________________________________________________________
310Int_t AliEMCALTriggerDCSConfigDB::GetTRUGTHRL0(Int_t iTRU)
311{
312 //
313 //
314 //
315 const AliEMCALTriggerDCSConfig* dcsConf = dynamic_cast<const AliEMCALTriggerDCSConfig*>(GetCachedCDBObject(kIDTriggerConfig));
622e10be 316 if(dcsConf){
317 AliEMCALTriggerTRUDCSConfig* truConf = dcsConf->GetTRUDCSConfig(iTRU);
318 if(truConf){
319 return truConf->GetGTHRL0();
1c1f9d16 320 } else AliError("TRUDCSConf Null!") ;
321 }else AliError("TriggerDCSConf Null!") ;
622e10be 322
323 return -1;
fff39dd1 324}