]>
Commit | Line | Data |
---|---|---|
9e788b10 | 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 | /* $Id$ */ | |
132753b5 | 17 | |
9e788b10 | 18 | /////////////////////////////////////////////////////////////////////////////// |
19 | // EMCAL Preprocessor class. It runs by Shuttle at the end of the run, | |
132753b5 | 20 | // calculates stuff to be posted in OCDB |
9e788b10 | 21 | // |
22 | // Author: Boris Polichtchouk, 4 October 2006 | |
23 | // Adapted for EMCAL by Gustavo Conesa Balbastre, October 2006 | |
132753b5 | 24 | // Updated by David Silvermyr May 2008, based on TPC code |
9e788b10 | 25 | /////////////////////////////////////////////////////////////////////////////// |
26 | ||
80c68391 | 27 | //Root |
9e788b10 | 28 | #include "TFile.h" |
132753b5 | 29 | #include "TTree.h" |
30 | #include "TEnv.h" | |
31 | #include "TParameter.h" | |
32 | ||
33 | #include <TTimeStamp.h> | |
8e8e4fc8 | 34 | |
80c68391 | 35 | //AliRoot |
132753b5 | 36 | #include "AliShuttleInterface.h" |
80c68391 | 37 | #include "AliEMCALPreprocessor.h" |
38 | #include "AliLog.h" | |
39 | #include "AliCDBMetaData.h" | |
132753b5 | 40 | #include "AliCaloCalibPedestal.h" |
41 | #include "AliCaloCalibSignal.h" | |
42 | #include "AliEMCALSensorTempArray.h" | |
9e788b10 | 43 | |
132753b5 | 44 | const Int_t kValCutTemp = 100; // discard temperatures > 100 degrees |
45 | const Int_t kDiffCutTemp = 5; // discard temperature differences > 5 degrees | |
46 | const TString kPedestalRunType = "PEDESTAL"; // pedestal run identifier | |
47 | const TString kPhysicsRunType = "PHYSICS"; // physics run identifier | |
8bc94fba | 48 | const TString kStandAloneRunType = "STANDALONE_BC"; // standalone run identifier |
32fbe941 | 49 | const TString kAmandaTemp = "PT_%02d.Temperature"; // Amanda string for temperature entries |
132753b5 | 50 | //const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required |
51 | const Double_t kFitFraction = -1.0; // Don't require minimum number of fits during commissioning | |
9e788b10 | 52 | |
132753b5 | 53 | const TString kMetaResponsible = "David Silvermyr"; |
54 | //legacy comments and return codes from TPC | |
55 | const TString kMetaComment = "Preprocessor AliEMCAL data base entries."; | |
56 | const int kReturnCodeNoInfo = 9; | |
57 | const int kReturnCodeNoObject = 2; | |
58 | const int kReturnCodeNoEntries = 1; | |
59 | ||
60 | ClassImp(AliEMCALPreprocessor) | |
61 | ||
9e788b10 | 62 | //_______________________________________________________________________________________ |
63 | AliEMCALPreprocessor::AliEMCALPreprocessor() : | |
132753b5 | 64 | AliPreprocessor("EMC",0), |
65 | fConfEnv(0), | |
66 | fTemp(0), | |
67 | fConfigOK(kTRUE) | |
9e788b10 | 68 | { |
69 | //default constructor | |
70 | } | |
71 | ||
72 | //_______________________________________________________________________________________ | |
80c68391 | 73 | AliEMCALPreprocessor::AliEMCALPreprocessor(AliShuttleInterface* shuttle): |
132753b5 | 74 | AliPreprocessor("EMC",shuttle), |
75 | fConfEnv(0), | |
76 | fTemp(0), | |
77 | fConfigOK(kTRUE) | |
9e788b10 | 78 | { |
132753b5 | 79 | // Constructor AddRunType(kPedestalRunType); |
80 | ||
81 | // define run types to be processed | |
82 | AddRunType(kPedestalRunType); | |
83 | AddRunType(kPhysicsRunType); | |
132753b5 | 84 | } |
6c0734ce | 85 | |
132753b5 | 86 | //______________________________________________________________________________________________ |
87 | AliEMCALPreprocessor::AliEMCALPreprocessor(const AliEMCALPreprocessor& ) : | |
88 | AliPreprocessor("EMCAL",0), | |
89 | fConfEnv(0), fTemp(0), fConfigOK(kTRUE) | |
90 | { | |
91 | Fatal("AliEMCALPreprocessor", "copy constructor not implemented"); | |
9e788b10 | 92 | } |
93 | ||
132753b5 | 94 | // assignment operator; use copy ctor to make life easy. |
95 | //______________________________________________________________________________________________ | |
96 | AliEMCALPreprocessor& AliEMCALPreprocessor::operator = (const AliEMCALPreprocessor &source ) | |
9e788b10 | 97 | { |
132753b5 | 98 | // assignment operator; use copy ctor |
99 | if (&source == this) return *this; | |
b3204f43 | 100 | |
132753b5 | 101 | new (this) AliEMCALPreprocessor(source); |
102 | return *this; | |
103 | } | |
09744db4 | 104 | |
132753b5 | 105 | //____________________________________________________________________________ |
106 | AliEMCALPreprocessor::~AliEMCALPreprocessor() | |
107 | { | |
108 | // destructor | |
109 | if (fTemp) delete fTemp; | |
110 | } | |
111 | ||
112 | //______________________________________________________________________________________________ | |
113 | void AliEMCALPreprocessor::Initialize(Int_t run, UInt_t startTime, | |
114 | UInt_t endTime) | |
115 | { | |
116 | // Creates AliTestDataDCS object -- start maps half an hour beforre actual run start | |
117 | UInt_t startTimeLocal = startTime-1800; | |
118 | AliPreprocessor::Initialize(run, startTimeLocal, endTime); | |
80c68391 | 119 | |
132753b5 | 120 | AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, |
121 | TTimeStamp((time_t)startTime,0).AsString(), | |
122 | TTimeStamp((time_t)endTime,0).AsString())); | |
80c68391 | 123 | |
132753b5 | 124 | // Preprocessor configuration |
125 | AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor"); | |
126 | if (entry) fConfEnv = (TEnv*) entry->GetObject(); | |
127 | if ( fConfEnv==0 ) { | |
8f79a6d7 | 128 | Log("AliEMCALPreprocessor: Preprocessor Config OCDB entry missing.\n"); |
132753b5 | 129 | fConfigOK = kFALSE; |
130 | return; | |
09744db4 | 131 | } |
132 | ||
132753b5 | 133 | // Temperature sensors |
134 | TTree *confTree = 0; | |
09744db4 | 135 | |
132753b5 | 136 | TString tempConf = fConfEnv->GetValue("Temperature","ON"); |
137 | tempConf.ToUpper(); | |
138 | if (tempConf != "OFF" ) { | |
139 | entry = GetFromOCDB("Config", "Temperature"); | |
140 | if (entry) confTree = (TTree*) entry->GetObject(); | |
141 | if ( confTree==0 ) { | |
8f79a6d7 | 142 | Log("AliEMCALPreprocessor: Temperature Config OCDB entry missing.\n"); |
132753b5 | 143 | fConfigOK = kFALSE; |
144 | return; | |
09744db4 | 145 | } |
132753b5 | 146 | fTemp = new AliEMCALSensorTempArray(startTimeLocal, fEndTime, confTree, kAmandaTemp); |
147 | fTemp->SetValCut(kValCutTemp); | |
148 | fTemp->SetDiffCut(kDiffCutTemp); | |
149 | } | |
150 | ||
151 | return; | |
152 | } | |
09744db4 | 153 | |
132753b5 | 154 | //______________________________________________________________________________________________ |
155 | UInt_t AliEMCALPreprocessor::Process(TMap* dcsAliasMap) | |
156 | { | |
157 | // Fills data into EMCAL calibrations objects | |
158 | // Amanda servers provide information directly through dcsAliasMap | |
159 | ||
160 | if (!fConfigOK) return kReturnCodeNoInfo; | |
161 | UInt_t result = 0; | |
162 | TObjArray *resultArray = new TObjArray(); | |
163 | TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON"); | |
164 | errorHandling.ToUpper(); | |
165 | TObject * status; | |
166 | ||
167 | UInt_t dcsResult=0; | |
168 | if (errorHandling == "OFF" ) { | |
169 | if (!dcsAliasMap) dcsResult = kReturnCodeNoEntries; | |
a51e676d | 170 | else if (dcsAliasMap->GetEntries() == 0 ) dcsResult = kReturnCodeNoEntries; |
132753b5 | 171 | status = new TParameter<int>("dcsResult",dcsResult); |
172 | resultArray->Add(status); | |
173 | } | |
174 | else { | |
175 | if (!dcsAliasMap) return kReturnCodeNoInfo; | |
6ce4e2ed | 176 | else if (dcsAliasMap->GetEntries() == 0 ) return kReturnCodeNoInfo; |
132753b5 | 177 | } |
178 | ||
6ce4e2ed | 179 | |
132753b5 | 180 | TString runType = GetRunType(); |
181 | ||
182 | // Temperature sensors are processed by AliEMCALCalTemp | |
183 | TString tempConf = fConfEnv->GetValue("Temperature","ON"); | |
184 | tempConf.ToUpper(); | |
6ce4e2ed | 185 | if (tempConf != "OFF" && dcsAliasMap ) { |
132753b5 | 186 | UInt_t tempResult = MapTemperature(dcsAliasMap); |
187 | result=tempResult; | |
188 | status = new TParameter<int>("tempResult",tempResult); | |
189 | resultArray->Add(status); | |
190 | } | |
191 | ||
192 | // Other calibration information will be retrieved through FXS files | |
193 | // examples: | |
194 | // TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals"); | |
195 | // const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1"); | |
196 | // | |
197 | // TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib"); | |
198 | // const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1"); | |
199 | ||
200 | // PEDESTAL ENTRIES: | |
201 | ||
541176c5 | 202 | if ( runType == kPedestalRunType ) { |
132753b5 | 203 | Int_t numSources = 1; |
204 | Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ, AliShuttleInterface::kHLT} ; | |
205 | TString source = fConfEnv->GetValue("Pedestal","DAQ"); | |
206 | source.ToUpper(); | |
207 | if (source != "OFF" ) { | |
208 | if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT; | |
209 | if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ; | |
210 | if (source == "HLTDAQ" ) { | |
a51e676d | 211 | numSources=2; |
212 | pedestalSource[0] = AliShuttleInterface::kHLT; | |
213 | pedestalSource[1] = AliShuttleInterface::kDAQ; | |
132753b5 | 214 | } |
215 | if (source == "DAQHLT" ) numSources=2; | |
216 | UInt_t pedestalResult=0; | |
217 | for (Int_t i=0; i<numSources; i++ ) { | |
a51e676d | 218 | pedestalResult = ExtractPedestals(pedestalSource[i]); |
219 | if ( pedestalResult == 0 ) break; | |
132753b5 | 220 | } |
221 | result += pedestalResult; | |
222 | status = new TParameter<int>("pedestalResult",pedestalResult); | |
223 | resultArray->Add(status); | |
09744db4 | 224 | } |
132753b5 | 225 | } |
226 | ||
227 | // SIGNAL/LED ENTRIES: | |
541176c5 | 228 | if( runType == kPhysicsRunType ) { |
132753b5 | 229 | Int_t numSources = 1; |
230 | Int_t signalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ; | |
231 | TString source = fConfEnv->GetValue("Signal","DAQ"); | |
232 | source.ToUpper(); | |
233 | if ( source != "OFF") { | |
234 | if ( source == "HLT") signalSource[0] = AliShuttleInterface::kHLT; | |
235 | if (!GetHLTStatus()) signalSource[0] = AliShuttleInterface::kDAQ; | |
236 | if (source == "HLTDAQ" ) { | |
a51e676d | 237 | numSources=2; |
238 | signalSource[0] = AliShuttleInterface::kHLT; | |
239 | signalSource[1] = AliShuttleInterface::kDAQ; | |
132753b5 | 240 | } |
241 | if (source == "DAQHLT" ) numSources=2; | |
242 | UInt_t signalResult=0; | |
243 | for (Int_t i=0; i<numSources; i++ ) { | |
a51e676d | 244 | signalResult = ExtractSignal(signalSource[i]); |
245 | if ( signalResult == 0 ) break; | |
09744db4 | 246 | } |
132753b5 | 247 | result += signalResult; |
248 | status = new TParameter<int>("signalResult",signalResult); | |
249 | resultArray->Add(status); | |
09744db4 | 250 | } |
132753b5 | 251 | } |
252 | ||
253 | ||
254 | // overall status at the end | |
255 | if (errorHandling == "OFF" ) { | |
256 | AliCDBMetaData metaData; | |
257 | metaData.SetBeamPeriod(0); | |
258 | metaData.SetResponsible(kMetaResponsible); | |
259 | metaData.SetComment("Preprocessor AliEMCAL status."); | |
b48d1356 | 260 | Bool_t storeOK = Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE); |
132753b5 | 261 | resultArray->Delete(); |
b48d1356 | 262 | result = 0; |
263 | if ( !storeOK ) result=1; | |
264 | return result; | |
132753b5 | 265 | } |
266 | else { | |
267 | return result; | |
268 | } | |
269 | ||
270 | } | |
271 | //______________________________________________________________________________________________ | |
272 | UInt_t AliEMCALPreprocessor::MapTemperature(TMap* dcsAliasMap) | |
273 | { | |
274 | // extract DCS temperature maps. Perform fits to save space | |
275 | UInt_t result=0; | |
276 | ||
277 | TMap *map = fTemp->ExtractDCS(dcsAliasMap); | |
278 | if (map) { | |
279 | fTemp->MakeSplineFit(map); | |
280 | Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors(); | |
281 | if (fitFraction > kFitFraction ) { | |
282 | AliInfo(Form("Temperature values extracted, fits performed.\n")); | |
283 | } | |
284 | else { | |
285 | Log ("Too few temperature maps fitted. \n"); | |
286 | result = kReturnCodeNoInfo; | |
287 | } | |
288 | } | |
289 | else { | |
290 | Log("No temperature map extracted. \n"); | |
291 | result = kReturnCodeNoInfo; | |
292 | } | |
293 | delete map; | |
294 | // Now store the final CDB file | |
295 | ||
296 | if ( result == 0 ) { // some info was found | |
297 | AliCDBMetaData metaData; | |
298 | metaData.SetBeamPeriod(0); | |
299 | metaData.SetResponsible(kMetaResponsible); | |
300 | metaData.SetComment(kMetaComment); | |
09744db4 | 301 | |
132753b5 | 302 | Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE); |
303 | if ( !storeOK ) result=1; | |
304 | } | |
305 | ||
306 | return result; | |
307 | } | |
308 | ||
309 | //______________________________________________________________________________________________ | |
310 | UInt_t AliEMCALPreprocessor::ExtractPedestals(Int_t sourceFXS) | |
311 | { | |
312 | UInt_t result=0; | |
313 | // | |
314 | // Read pedestal file from file exchange server | |
4eef2cc9 | 315 | // Only store if new pedestal info is available |
132753b5 | 316 | // |
4eef2cc9 | 317 | AliCaloCalibPedestal *calibPed = new AliCaloCalibPedestal(AliCaloCalibPedestal::kEmCal); |
d500a49b | 318 | calibPed->Init(); |
319 | ||
132753b5 | 320 | TList* list = GetFileSources(sourceFXS,"pedestals"); |
321 | if (list && list->GetEntries()>0) { | |
322 | ||
132753b5 | 323 | // loop through all files from LDCs |
324 | ||
325 | int changes = 0; | |
326 | UInt_t index = 0; | |
327 | while (list->At(index)!=NULL) { | |
328 | TObjString* fileNameEntry = (TObjString*) list->At(index); | |
329 | if (fileNameEntry!=NULL) { | |
330 | TString fileName = GetFile(sourceFXS, "pedestals", | |
331 | fileNameEntry->GetString().Data()); | |
332 | TFile *f = TFile::Open(fileName); | |
333 | if (!f) { | |
334 | Log ("Error opening pedestal file."); | |
335 | result = kReturnCodeNoObject; | |
336 | break; | |
337 | } | |
338 | AliCaloCalibPedestal *calPed; | |
339 | f->GetObject("emcCalibPedestal",calPed); | |
340 | if ( !calPed ) { | |
341 | Log ("No pedestal calibration object in file."); | |
342 | result = kReturnCodeNoObject; | |
343 | break; | |
344 | } | |
345 | if ( calPed->GetNEvents()>0 && calPed->GetNChanFills()>0 ) { | |
346 | // add info for the modules available in the present file | |
347 | Bool_t status = calibPed->AddInfo(calPed); | |
348 | if (status) { changes++; } | |
b3204f43 | 349 | } |
132753b5 | 350 | |
351 | delete calPed; | |
352 | f->Close(); | |
09744db4 | 353 | } |
132753b5 | 354 | index++; |
355 | } // while(list) | |
356 | ||
357 | // | |
358 | // Store updated pedestal entry to OCDB | |
359 | // | |
360 | if (changes>0) { | |
361 | AliCDBMetaData metaData; | |
362 | metaData.SetBeamPeriod(0); | |
363 | metaData.SetResponsible(kMetaResponsible); | |
364 | metaData.SetComment(kMetaComment); | |
365 | ||
366 | Bool_t storeOK = StoreReferenceData("Calib", "Pedestals", calibPed, &metaData); | |
367 | if ( !storeOK ) result++; | |
09744db4 | 368 | } |
132753b5 | 369 | } |
370 | else { | |
371 | Log ("Error: no entries in input file list!"); | |
372 | result = kReturnCodeNoEntries; | |
373 | } | |
b3204f43 | 374 | |
132753b5 | 375 | return result; |
376 | } | |
377 | ||
378 | //______________________________________________________________________________________________ | |
379 | UInt_t AliEMCALPreprocessor::ExtractSignal(Int_t sourceFXS) | |
380 | { | |
381 | UInt_t result=0; | |
382 | // | |
383 | // Read signal file from file exchange server | |
4eef2cc9 | 384 | // Only store if new signal info is available |
132753b5 | 385 | // |
4eef2cc9 | 386 | AliCaloCalibSignal *calibSig = new AliCaloCalibSignal(AliCaloCalibSignal::kEmCal); |
b3204f43 | 387 | |
132753b5 | 388 | TList* list = GetFileSources(sourceFXS,"signal"); |
389 | if (list && list->GetEntries()>0) { | |
32fbe941 | 390 | |
132753b5 | 391 | // loop through all files from LDCs |
392 | ||
393 | int changes = 0; | |
394 | UInt_t index = 0; | |
395 | while (list->At(index)!=NULL) { | |
396 | TObjString* fileNameEntry = (TObjString*) list->At(index); | |
397 | if (fileNameEntry!=NULL) { | |
398 | TString fileName = GetFile(sourceFXS, "signal", | |
399 | fileNameEntry->GetString().Data()); | |
400 | TFile *f = TFile::Open(fileName); | |
401 | if (!f) { | |
402 | Log ("Error opening signal file."); | |
403 | result = kReturnCodeNoObject; | |
404 | break; | |
405 | } | |
406 | AliCaloCalibSignal *calSig; | |
407 | f->GetObject("emcCalibSignal",calSig); | |
408 | if ( !calSig ) { | |
409 | Log ("No signal calibration object in file."); | |
410 | result = kReturnCodeNoObject; | |
411 | break; | |
412 | } | |
413 | if ( calSig->GetNEvents()>0 ) { | |
414 | // add info for the modules available in the present file | |
415 | Bool_t status = calibSig->AddInfo(calSig); | |
416 | if (status) { changes++; } | |
417 | } | |
418 | ||
419 | delete calSig; | |
420 | f->Close(); | |
421 | } | |
422 | index++; | |
423 | } // while(list) | |
424 | ||
425 | // | |
426 | // Store updated signal entry to OCDB | |
427 | // | |
428 | if (changes>0) { | |
429 | AliCDBMetaData metaData; | |
430 | metaData.SetBeamPeriod(0); | |
431 | metaData.SetResponsible(kMetaResponsible); | |
432 | metaData.SetComment(kMetaComment); | |
433 | ||
81c4c29b | 434 | Bool_t storeOK = Store("Calib", "LED", calibSig, &metaData, 0, kFALSE); |
132753b5 | 435 | if ( !storeOK ) result++; |
436 | } | |
437 | } | |
438 | else { | |
439 | Log ("Error: no entries in input file list!"); | |
440 | result = kReturnCodeNoEntries; | |
441 | } | |
442 | ||
443 | return result; | |
9e788b10 | 444 | } |
132753b5 | 445 | |
446 |