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