]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALPreprocessor.cxx
adding a comment on the event-by-event eta-phi histogram for general use
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALPreprocessor.cxx
CommitLineData
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 44const Int_t kValCutTemp = 100; // discard temperatures > 100 degrees
45const Int_t kDiffCutTemp = 5; // discard temperature differences > 5 degrees
46const TString kPedestalRunType = "PEDESTAL"; // pedestal run identifier
47const TString kPhysicsRunType = "PHYSICS"; // physics run identifier
8bc94fba 48const TString kStandAloneRunType = "STANDALONE_BC"; // standalone run identifier
32fbe941 49const TString kAmandaTemp = "PT_%02d.Temperature"; // Amanda string for temperature entries
132753b5 50//const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required
51const Double_t kFitFraction = -1.0; // Don't require minimum number of fits during commissioning
9e788b10 52
132753b5 53const TString kMetaResponsible = "David Silvermyr";
54//legacy comments and return codes from TPC
55const TString kMetaComment = "Preprocessor AliEMCAL data base entries.";
56const int kReturnCodeNoInfo = 9;
57const int kReturnCodeNoObject = 2;
58const int kReturnCodeNoEntries = 1;
59
60ClassImp(AliEMCALPreprocessor)
61
9e788b10 62//_______________________________________________________________________________________
63AliEMCALPreprocessor::AliEMCALPreprocessor() :
132753b5 64 AliPreprocessor("EMC",0),
65 fConfEnv(0),
66 fTemp(0),
67 fConfigOK(kTRUE)
9e788b10 68{
69 //default constructor
70}
71
72//_______________________________________________________________________________________
80c68391 73AliEMCALPreprocessor::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//______________________________________________________________________________________________
87AliEMCALPreprocessor::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//______________________________________________________________________________________________
96AliEMCALPreprocessor& 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//____________________________________________________________________________
106AliEMCALPreprocessor::~AliEMCALPreprocessor()
107{
108 // destructor
109 if (fTemp) delete fTemp;
110}
111
112//______________________________________________________________________________________________
113void 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//______________________________________________________________________________________________
155UInt_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;
170 if (dcsAliasMap->GetEntries() == 0 ) dcsResult = kReturnCodeNoEntries;
171 status = new TParameter<int>("dcsResult",dcsResult);
172 resultArray->Add(status);
173 }
174 else {
175 if (!dcsAliasMap) return kReturnCodeNoInfo;
176 if (dcsAliasMap->GetEntries() == 0 ) return kReturnCodeNoInfo;
177 }
178
179 TString runType = GetRunType();
180
181 // Temperature sensors are processed by AliEMCALCalTemp
182 TString tempConf = fConfEnv->GetValue("Temperature","ON");
183 tempConf.ToUpper();
184 if (tempConf != "OFF" ) {
185 UInt_t tempResult = MapTemperature(dcsAliasMap);
186 result=tempResult;
187 status = new TParameter<int>("tempResult",tempResult);
188 resultArray->Add(status);
189 }
190
191 // Other calibration information will be retrieved through FXS files
192 // examples:
193 // TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
194 // const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
195 //
196 // TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
197 // const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
198
199 // PEDESTAL ENTRIES:
200
541176c5 201 if ( runType == kPedestalRunType ) {
132753b5 202 Int_t numSources = 1;
203 Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ, AliShuttleInterface::kHLT} ;
204 TString source = fConfEnv->GetValue("Pedestal","DAQ");
205 source.ToUpper();
206 if (source != "OFF" ) {
207 if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
208 if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
209 if (source == "HLTDAQ" ) {
210 numSources=2;
211 pedestalSource[0] = AliShuttleInterface::kHLT;
212 pedestalSource[1] = AliShuttleInterface::kDAQ;
213 }
214 if (source == "DAQHLT" ) numSources=2;
215 UInt_t pedestalResult=0;
216 for (Int_t i=0; i<numSources; i++ ) {
217 pedestalResult = ExtractPedestals(pedestalSource[i]);
218 if ( pedestalResult == 0 ) break;
219 }
220 result += pedestalResult;
221 status = new TParameter<int>("pedestalResult",pedestalResult);
222 resultArray->Add(status);
09744db4 223 }
132753b5 224 }
225
226 // SIGNAL/LED ENTRIES:
541176c5 227 if( runType == kPhysicsRunType ) {
132753b5 228 Int_t numSources = 1;
229 Int_t signalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
230 TString source = fConfEnv->GetValue("Signal","DAQ");
231 source.ToUpper();
232 if ( source != "OFF") {
233 if ( source == "HLT") signalSource[0] = AliShuttleInterface::kHLT;
234 if (!GetHLTStatus()) signalSource[0] = AliShuttleInterface::kDAQ;
235 if (source == "HLTDAQ" ) {
236 numSources=2;
237 signalSource[0] = AliShuttleInterface::kHLT;
238 signalSource[1] = AliShuttleInterface::kDAQ;
239 }
240 if (source == "DAQHLT" ) numSources=2;
241 UInt_t signalResult=0;
242 for (Int_t i=0; i<numSources; i++ ) {
243 signalResult = ExtractSignal(signalSource[i]);
244 if ( signalResult == 0 ) break;
09744db4 245 }
132753b5 246 result += signalResult;
247 status = new TParameter<int>("signalResult",signalResult);
248 resultArray->Add(status);
09744db4 249 }
132753b5 250 }
251
252
253 // overall status at the end
254 if (errorHandling == "OFF" ) {
255 AliCDBMetaData metaData;
256 metaData.SetBeamPeriod(0);
257 metaData.SetResponsible(kMetaResponsible);
258 metaData.SetComment("Preprocessor AliEMCAL status.");
259 Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
260 resultArray->Delete();
261 return 0;
262 }
263 else {
264 return result;
265 }
266
267}
268//______________________________________________________________________________________________
269UInt_t AliEMCALPreprocessor::MapTemperature(TMap* dcsAliasMap)
270{
271 // extract DCS temperature maps. Perform fits to save space
272 UInt_t result=0;
273
274 TMap *map = fTemp->ExtractDCS(dcsAliasMap);
275 if (map) {
276 fTemp->MakeSplineFit(map);
277 Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors();
278 if (fitFraction > kFitFraction ) {
279 AliInfo(Form("Temperature values extracted, fits performed.\n"));
280 }
281 else {
282 Log ("Too few temperature maps fitted. \n");
283 result = kReturnCodeNoInfo;
284 }
285 }
286 else {
287 Log("No temperature map extracted. \n");
288 result = kReturnCodeNoInfo;
289 }
290 delete map;
291 // Now store the final CDB file
292
293 if ( result == 0 ) { // some info was found
294 AliCDBMetaData metaData;
295 metaData.SetBeamPeriod(0);
296 metaData.SetResponsible(kMetaResponsible);
297 metaData.SetComment(kMetaComment);
09744db4 298
132753b5 299 Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
300 if ( !storeOK ) result=1;
301 }
302
303 return result;
304}
305
306//______________________________________________________________________________________________
307UInt_t AliEMCALPreprocessor::ExtractPedestals(Int_t sourceFXS)
308{
309 UInt_t result=0;
310 //
311 // Read pedestal file from file exchange server
4eef2cc9 312 // Only store if new pedestal info is available
132753b5 313 //
4eef2cc9 314 AliCaloCalibPedestal *calibPed = new AliCaloCalibPedestal(AliCaloCalibPedestal::kEmCal);
132753b5 315
316 TList* list = GetFileSources(sourceFXS,"pedestals");
317 if (list && list->GetEntries()>0) {
318
132753b5 319 // loop through all files from LDCs
320
321 int changes = 0;
322 UInt_t index = 0;
323 while (list->At(index)!=NULL) {
324 TObjString* fileNameEntry = (TObjString*) list->At(index);
325 if (fileNameEntry!=NULL) {
326 TString fileName = GetFile(sourceFXS, "pedestals",
327 fileNameEntry->GetString().Data());
328 TFile *f = TFile::Open(fileName);
329 if (!f) {
330 Log ("Error opening pedestal file.");
331 result = kReturnCodeNoObject;
332 break;
333 }
334 AliCaloCalibPedestal *calPed;
335 f->GetObject("emcCalibPedestal",calPed);
336 if ( !calPed ) {
337 Log ("No pedestal calibration object in file.");
338 result = kReturnCodeNoObject;
339 break;
340 }
341 if ( calPed->GetNEvents()>0 && calPed->GetNChanFills()>0 ) {
342 // add info for the modules available in the present file
343 Bool_t status = calibPed->AddInfo(calPed);
344 if (status) { changes++; }
b3204f43 345 }
132753b5 346
347 delete calPed;
348 f->Close();
09744db4 349 }
132753b5 350 index++;
351 } // while(list)
352
353 //
354 // Store updated pedestal entry to OCDB
355 //
356 if (changes>0) {
357 AliCDBMetaData metaData;
358 metaData.SetBeamPeriod(0);
359 metaData.SetResponsible(kMetaResponsible);
360 metaData.SetComment(kMetaComment);
361
362 Bool_t storeOK = StoreReferenceData("Calib", "Pedestals", calibPed, &metaData);
363 if ( !storeOK ) result++;
09744db4 364 }
132753b5 365 }
366 else {
367 Log ("Error: no entries in input file list!");
368 result = kReturnCodeNoEntries;
369 }
b3204f43 370
132753b5 371 return result;
372}
373
374//______________________________________________________________________________________________
375UInt_t AliEMCALPreprocessor::ExtractSignal(Int_t sourceFXS)
376{
377 UInt_t result=0;
378 //
379 // Read signal file from file exchange server
4eef2cc9 380 // Only store if new signal info is available
132753b5 381 //
4eef2cc9 382 AliCaloCalibSignal *calibSig = new AliCaloCalibSignal(AliCaloCalibSignal::kEmCal);
b3204f43 383
132753b5 384 TList* list = GetFileSources(sourceFXS,"signal");
385 if (list && list->GetEntries()>0) {
32fbe941 386
132753b5 387 // loop through all files from LDCs
388
389 int changes = 0;
390 UInt_t index = 0;
391 while (list->At(index)!=NULL) {
392 TObjString* fileNameEntry = (TObjString*) list->At(index);
393 if (fileNameEntry!=NULL) {
394 TString fileName = GetFile(sourceFXS, "signal",
395 fileNameEntry->GetString().Data());
396 TFile *f = TFile::Open(fileName);
397 if (!f) {
398 Log ("Error opening signal file.");
399 result = kReturnCodeNoObject;
400 break;
401 }
402 AliCaloCalibSignal *calSig;
403 f->GetObject("emcCalibSignal",calSig);
404 if ( !calSig ) {
405 Log ("No signal calibration object in file.");
406 result = kReturnCodeNoObject;
407 break;
408 }
409 if ( calSig->GetNEvents()>0 ) {
410 // add info for the modules available in the present file
411 Bool_t status = calibSig->AddInfo(calSig);
412 if (status) { changes++; }
413 }
414
415 delete calSig;
416 f->Close();
417 }
418 index++;
419 } // while(list)
420
421 //
422 // Store updated signal entry to OCDB
423 //
424 if (changes>0) {
425 AliCDBMetaData metaData;
426 metaData.SetBeamPeriod(0);
427 metaData.SetResponsible(kMetaResponsible);
428 metaData.SetComment(kMetaComment);
429
81c4c29b 430 Bool_t storeOK = Store("Calib", "LED", calibSig, &metaData, 0, kFALSE);
132753b5 431 if ( !storeOK ) result++;
432 }
433 }
434 else {
435 Log ("Error: no entries in input file list!");
436 result = kReturnCodeNoEntries;
437 }
438
439 return result;
9e788b10 440}
132753b5 441
442