]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALTriggerDCSConfigDB.cxx
option for mass hypothesis also on AODs
[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 //
79b05051 236 // Get DCS config
fff39dd1 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}