]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALPreprocessor.cxx
corrected OCDB storage path for trigger info + added few AliInfo lines for now
[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"
70ee04f5 39#include "AliDCSValue.h"
80c68391 40#include "AliCDBMetaData.h"
70ee04f5 41#include "AliEMCALTriggerTRUDCSConfig.h"
42#include "AliEMCALTriggerDCSConfig.h"
132753b5 43#include "AliCaloCalibPedestal.h"
44#include "AliCaloCalibSignal.h"
45#include "AliEMCALSensorTempArray.h"
9e788b10 46
132753b5 47const Int_t kValCutTemp = 100; // discard temperatures > 100 degrees
48const Int_t kDiffCutTemp = 5; // discard temperature differences > 5 degrees
49const TString kPedestalRunType = "PEDESTAL"; // pedestal run identifier
50const TString kPhysicsRunType = "PHYSICS"; // physics run identifier
8bc94fba 51const TString kStandAloneRunType = "STANDALONE_BC"; // standalone run identifier
32fbe941 52const TString kAmandaTemp = "PT_%02d.Temperature"; // Amanda string for temperature entries
132753b5 53//const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required
54const Double_t kFitFraction = -1.0; // Don't require minimum number of fits during commissioning
9e788b10 55
132753b5 56const TString kMetaResponsible = "David Silvermyr";
57//legacy comments and return codes from TPC
58const TString kMetaComment = "Preprocessor AliEMCAL data base entries.";
59const int kReturnCodeNoInfo = 9;
60const int kReturnCodeNoObject = 2;
61const int kReturnCodeNoEntries = 1;
62
70ee04f5 63const int kNTRU = 30; // From 2011; 10 SuperModules (SM) * 3 TRU per SM
64
132753b5 65ClassImp(AliEMCALPreprocessor)
66
9e788b10 67//_______________________________________________________________________________________
68AliEMCALPreprocessor::AliEMCALPreprocessor() :
132753b5 69 AliPreprocessor("EMC",0),
70 fConfEnv(0),
71 fTemp(0),
72 fConfigOK(kTRUE)
9e788b10 73{
74 //default constructor
75}
76
77//_______________________________________________________________________________________
80c68391 78AliEMCALPreprocessor::AliEMCALPreprocessor(AliShuttleInterface* shuttle):
132753b5 79 AliPreprocessor("EMC",shuttle),
80 fConfEnv(0),
81 fTemp(0),
82 fConfigOK(kTRUE)
9e788b10 83{
132753b5 84 // Constructor AddRunType(kPedestalRunType);
85
86 // define run types to be processed
87 AddRunType(kPedestalRunType);
88 AddRunType(kPhysicsRunType);
132753b5 89}
6c0734ce 90
132753b5 91//______________________________________________________________________________________________
92AliEMCALPreprocessor::AliEMCALPreprocessor(const AliEMCALPreprocessor& ) :
93 AliPreprocessor("EMCAL",0),
94 fConfEnv(0), fTemp(0), fConfigOK(kTRUE)
95{
96 Fatal("AliEMCALPreprocessor", "copy constructor not implemented");
9e788b10 97}
98
132753b5 99// assignment operator; use copy ctor to make life easy.
100//______________________________________________________________________________________________
101AliEMCALPreprocessor& AliEMCALPreprocessor::operator = (const AliEMCALPreprocessor &source )
9e788b10 102{
132753b5 103 // assignment operator; use copy ctor
104 if (&source == this) return *this;
b3204f43 105
132753b5 106 new (this) AliEMCALPreprocessor(source);
107 return *this;
108}
09744db4 109
132753b5 110//____________________________________________________________________________
111AliEMCALPreprocessor::~AliEMCALPreprocessor()
112{
113 // destructor
114 if (fTemp) delete fTemp;
115}
116
117//______________________________________________________________________________________________
118void AliEMCALPreprocessor::Initialize(Int_t run, UInt_t startTime,
119 UInt_t endTime)
120{
121 // Creates AliTestDataDCS object -- start maps half an hour beforre actual run start
122 UInt_t startTimeLocal = startTime-1800;
123 AliPreprocessor::Initialize(run, startTimeLocal, endTime);
80c68391 124
132753b5 125 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
126 TTimeStamp((time_t)startTime,0).AsString(),
127 TTimeStamp((time_t)endTime,0).AsString()));
80c68391 128
132753b5 129 // Preprocessor configuration
130 AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor");
131 if (entry) fConfEnv = (TEnv*) entry->GetObject();
132 if ( fConfEnv==0 ) {
8f79a6d7 133 Log("AliEMCALPreprocessor: Preprocessor Config OCDB entry missing.\n");
132753b5 134 fConfigOK = kFALSE;
135 return;
09744db4 136 }
137
132753b5 138 // Temperature sensors
139 TTree *confTree = 0;
09744db4 140
132753b5 141 TString tempConf = fConfEnv->GetValue("Temperature","ON");
142 tempConf.ToUpper();
143 if (tempConf != "OFF" ) {
144 entry = GetFromOCDB("Config", "Temperature");
145 if (entry) confTree = (TTree*) entry->GetObject();
146 if ( confTree==0 ) {
8f79a6d7 147 Log("AliEMCALPreprocessor: Temperature Config OCDB entry missing.\n");
132753b5 148 fConfigOK = kFALSE;
149 return;
09744db4 150 }
132753b5 151 fTemp = new AliEMCALSensorTempArray(startTimeLocal, fEndTime, confTree, kAmandaTemp);
152 fTemp->SetValCut(kValCutTemp);
153 fTemp->SetDiffCut(kDiffCutTemp);
154 }
155
156 return;
157}
09744db4 158
132753b5 159//______________________________________________________________________________________________
160UInt_t AliEMCALPreprocessor::Process(TMap* dcsAliasMap)
161{
162 // Fills data into EMCAL calibrations objects
163 // Amanda servers provide information directly through dcsAliasMap
164
165 if (!fConfigOK) return kReturnCodeNoInfo;
166 UInt_t result = 0;
167 TObjArray *resultArray = new TObjArray();
168 TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON");
169 errorHandling.ToUpper();
170 TObject * status;
171
172 UInt_t dcsResult=0;
173 if (errorHandling == "OFF" ) {
174 if (!dcsAliasMap) dcsResult = kReturnCodeNoEntries;
a51e676d 175 else if (dcsAliasMap->GetEntries() == 0 ) dcsResult = kReturnCodeNoEntries;
132753b5 176 status = new TParameter<int>("dcsResult",dcsResult);
177 resultArray->Add(status);
178 }
179 else {
180 if (!dcsAliasMap) return kReturnCodeNoInfo;
6ce4e2ed 181 else if (dcsAliasMap->GetEntries() == 0 ) return kReturnCodeNoInfo;
132753b5 182 }
183
6ce4e2ed 184
132753b5 185 TString runType = GetRunType();
186
187 // Temperature sensors are processed by AliEMCALCalTemp
188 TString tempConf = fConfEnv->GetValue("Temperature","ON");
189 tempConf.ToUpper();
6ce4e2ed 190 if (tempConf != "OFF" && dcsAliasMap ) {
132753b5 191 UInt_t tempResult = MapTemperature(dcsAliasMap);
192 result=tempResult;
193 status = new TParameter<int>("tempResult",tempResult);
194 resultArray->Add(status);
195 }
c967e257 196 // Trigger configuration processing: only for Physics runs
70ee04f5 197 TString triggerConf = fConfEnv->GetValue("Trigger","ON");
198 triggerConf.ToUpper();
c967e257 199 if( runType == kPhysicsRunType ) {
200 // if (triggerConf != "OFF" && dcsAliasMap ) {
201 if ( dcsAliasMap ) {
202 UInt_t triggerResult = MapTriggerConfig(dcsAliasMap);
203 AliInfo(Form("triggerConf %s\n", triggerConf.Data()));
204 result+=triggerResult;
205 status = new TParameter<int>("triggerResult",triggerResult);
206 resultArray->Add(status);
207 }
70ee04f5 208 }
132753b5 209
210 // Other calibration information will be retrieved through FXS files
211 // examples:
212 // TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
213 // const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
214 //
215 // TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
216 // const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
217
218 // PEDESTAL ENTRIES:
219
541176c5 220 if ( runType == kPedestalRunType ) {
132753b5 221 Int_t numSources = 1;
222 Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ, AliShuttleInterface::kHLT} ;
223 TString source = fConfEnv->GetValue("Pedestal","DAQ");
224 source.ToUpper();
225 if (source != "OFF" ) {
226 if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
227 if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
228 if (source == "HLTDAQ" ) {
a51e676d 229 numSources=2;
230 pedestalSource[0] = AliShuttleInterface::kHLT;
231 pedestalSource[1] = AliShuttleInterface::kDAQ;
132753b5 232 }
233 if (source == "DAQHLT" ) numSources=2;
234 UInt_t pedestalResult=0;
235 for (Int_t i=0; i<numSources; i++ ) {
a51e676d 236 pedestalResult = ExtractPedestals(pedestalSource[i]);
237 if ( pedestalResult == 0 ) break;
132753b5 238 }
239 result += pedestalResult;
240 status = new TParameter<int>("pedestalResult",pedestalResult);
241 resultArray->Add(status);
09744db4 242 }
132753b5 243 }
244
245 // SIGNAL/LED ENTRIES:
541176c5 246 if( runType == kPhysicsRunType ) {
132753b5 247 Int_t numSources = 1;
248 Int_t signalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
249 TString source = fConfEnv->GetValue("Signal","DAQ");
250 source.ToUpper();
251 if ( source != "OFF") {
252 if ( source == "HLT") signalSource[0] = AliShuttleInterface::kHLT;
253 if (!GetHLTStatus()) signalSource[0] = AliShuttleInterface::kDAQ;
254 if (source == "HLTDAQ" ) {
a51e676d 255 numSources=2;
256 signalSource[0] = AliShuttleInterface::kHLT;
257 signalSource[1] = AliShuttleInterface::kDAQ;
132753b5 258 }
259 if (source == "DAQHLT" ) numSources=2;
260 UInt_t signalResult=0;
261 for (Int_t i=0; i<numSources; i++ ) {
a51e676d 262 signalResult = ExtractSignal(signalSource[i]);
263 if ( signalResult == 0 ) break;
09744db4 264 }
132753b5 265 result += signalResult;
266 status = new TParameter<int>("signalResult",signalResult);
267 resultArray->Add(status);
09744db4 268 }
132753b5 269 }
270
271
272 // overall status at the end
273 if (errorHandling == "OFF" ) {
274 AliCDBMetaData metaData;
275 metaData.SetBeamPeriod(0);
276 metaData.SetResponsible(kMetaResponsible);
277 metaData.SetComment("Preprocessor AliEMCAL status.");
b48d1356 278 Bool_t storeOK = Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
132753b5 279 resultArray->Delete();
b48d1356 280 result = 0;
281 if ( !storeOK ) result=1;
282 return result;
132753b5 283 }
284 else {
285 return result;
286 }
287
288}
289//______________________________________________________________________________________________
290UInt_t AliEMCALPreprocessor::MapTemperature(TMap* dcsAliasMap)
70ee04f5 291{ // extract DCS temperature maps. Perform fits to save space
132753b5 292 UInt_t result=0;
293
294 TMap *map = fTemp->ExtractDCS(dcsAliasMap);
295 if (map) {
296 fTemp->MakeSplineFit(map);
297 Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors();
298 if (fitFraction > kFitFraction ) {
299 AliInfo(Form("Temperature values extracted, fits performed.\n"));
300 }
301 else {
302 Log ("Too few temperature maps fitted. \n");
303 result = kReturnCodeNoInfo;
304 }
305 }
306 else {
307 Log("No temperature map extracted. \n");
308 result = kReturnCodeNoInfo;
309 }
310 delete map;
311 // Now store the final CDB file
312
313 if ( result == 0 ) { // some info was found
314 AliCDBMetaData metaData;
315 metaData.SetBeamPeriod(0);
316 metaData.SetResponsible(kMetaResponsible);
317 metaData.SetComment(kMetaComment);
09744db4 318
132753b5 319 Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
320 if ( !storeOK ) result=1;
321 }
322
323 return result;
324}
325
70ee04f5 326//______________________________________________________________________________________________
327UInt_t AliEMCALPreprocessor::MapTriggerConfig(TMap* dcsAliasMap)
328{ // extract DCS trigger info
c967e257 329 AliInfo(Form("Get TRU info from DCS DPs.\n"));
70ee04f5 330 Int_t i, iTRU;
331 char buf[100];
332
333 AliDCSValue *dcsVal;
334 TObjArray *arrL0ALGSEL, *arrPEAKFINDER, *arrGLOBALTHRESH, *arrCOSMTHRESH;
335 TObjArray *arrMASK[6];
336
337 // overall object to hold STU and DCS config info
338 // DS comment: for now only holds TRU info, i.e. only partially filled
339 // (STU info only in raw data header; unfortunately not also picked up via DCS DPs)
340 AliEMCALTriggerDCSConfig *trigConfig = new AliEMCALTriggerDCSConfig();
341
342 // loop through all TRUs
343 for( iTRU = 0; iTRU < kNTRU; iTRU++){
344
345 // get the shuttled values
346 sprintf( buf, "EMC_TRU%02d_L0ALGSEL", iTRU );
347 arrL0ALGSEL = (TObjArray*) dcsAliasMap->GetValue( buf );
348 sprintf( buf, "EMC_TRU%02d_PEAKFINDER", iTRU );
349 arrPEAKFINDER = (TObjArray*) dcsAliasMap->GetValue( buf );
350 sprintf( buf, "EMC_TRU%02d_GLOBALTHRESH", iTRU );
351 arrGLOBALTHRESH = (TObjArray*) dcsAliasMap->GetValue( buf );
352 sprintf( buf, "EMC_TRU%02d_COSMTHRESH", iTRU );
353 arrCOSMTHRESH = (TObjArray*) dcsAliasMap->GetValue( buf );
354
355 for( i = 0; i < 6; i++ ){
356 sprintf( buf, "EMC_TRU%02d_MASK%d", iTRU, i );
357 arrMASK[i] = (TObjArray*) dcsAliasMap->GetValue( buf );
358 }
359
360 // fill the objects
361 AliEMCALTriggerTRUDCSConfig* truConfig = trigConfig->GetTRUDCSConfig(iTRU);
362
363 // get last entries. fill the TRU object
364 if( ! arrL0ALGSEL ){
365 AliWarning( Form("EMC DCS TRU%02d L0ALGSEL alias not found!\n", iTRU ));
366 }
367 else{
368 dcsVal = (AliDCSValue *) arrL0ALGSEL->At( arrL0ALGSEL->GetEntries() - 1 );
369 truConfig->SetL0SEL( dcsVal->GetUInt() );
370 }
371 if( ! arrPEAKFINDER ){
372 AliWarning( Form("EMC DCS TRU%02d PEAKFINDER alias not found!\n", iTRU ));
373 }
374 else{
375 dcsVal = (AliDCSValue *) arrPEAKFINDER->At( arrPEAKFINDER->GetEntries() - 1 );
376 truConfig->SetSELPF( dcsVal->GetUInt() );
377 }
378 if( ! arrGLOBALTHRESH ){
379 AliWarning( Form("EMC DCS TRU%02d GLOBALTHRESH alias not found!\n", iTRU ));
380 }
381 else{
382 dcsVal = (AliDCSValue *) arrGLOBALTHRESH->At( arrGLOBALTHRESH->GetEntries() - 1 );
383 truConfig->SetGTHRL0( dcsVal->GetUInt() );
384 }
385 if( ! arrCOSMTHRESH ){
386 AliWarning( Form("EMC DCS TRU%02d COSMTHRESH alias not found!\n", iTRU ));
387 }
388 else{
389 dcsVal = (AliDCSValue *) arrCOSMTHRESH->At( arrCOSMTHRESH->GetEntries() - 1 );
390 truConfig->SetL0COSM( dcsVal->GetUInt() );
391 }
392
393 for( i = 0; i < 6; i++ ){
394 if( ! arrMASK[i] ){
395 AliWarning( Form("EMC DCS TRU%02d MASK%d alias not found!\n", iTRU, i ));
396 }
397 else{
398 dcsVal = (AliDCSValue *) arrMASK[i]->At( arrMASK[i]->GetEntries() - 1 );
399 truConfig->SetMaskReg( dcsVal->GetUInt(), i );
400 }
401 }
402
403 } // TRUs
c967e257 404 AliInfo(Form("TRU info retrieved.\n"));
70ee04f5 405 // save the objects
406 AliCDBMetaData metaData;
407 metaData.SetBeamPeriod(0);
408 metaData.SetResponsible(kMetaResponsible);
409 metaData.SetComment(kMetaComment);
410
c967e257 411 Bool_t retCode = Store("Calib", "Trigger", trigConfig, &metaData, 0, kFALSE);
412 AliInfo(Form("TRU info stored.\n"));
70ee04f5 413 return retCode;
414}
415
132753b5 416//______________________________________________________________________________________________
417UInt_t AliEMCALPreprocessor::ExtractPedestals(Int_t sourceFXS)
418{
132753b5 419 // Read pedestal file from file exchange server
4eef2cc9 420 // Only store if new pedestal info is available
132753b5 421 //
70ee04f5 422 UInt_t result=0;
423
4eef2cc9 424 AliCaloCalibPedestal *calibPed = new AliCaloCalibPedestal(AliCaloCalibPedestal::kEmCal);
d500a49b 425 calibPed->Init();
426
132753b5 427 TList* list = GetFileSources(sourceFXS,"pedestals");
428 if (list && list->GetEntries()>0) {
429
132753b5 430 // loop through all files from LDCs
431
432 int changes = 0;
433 UInt_t index = 0;
434 while (list->At(index)!=NULL) {
435 TObjString* fileNameEntry = (TObjString*) list->At(index);
436 if (fileNameEntry!=NULL) {
437 TString fileName = GetFile(sourceFXS, "pedestals",
438 fileNameEntry->GetString().Data());
439 TFile *f = TFile::Open(fileName);
440 if (!f) {
441 Log ("Error opening pedestal file.");
442 result = kReturnCodeNoObject;
443 break;
444 }
445 AliCaloCalibPedestal *calPed;
446 f->GetObject("emcCalibPedestal",calPed);
447 if ( !calPed ) {
448 Log ("No pedestal calibration object in file.");
449 result = kReturnCodeNoObject;
450 break;
451 }
452 if ( calPed->GetNEvents()>0 && calPed->GetNChanFills()>0 ) {
453 // add info for the modules available in the present file
454 Bool_t status = calibPed->AddInfo(calPed);
455 if (status) { changes++; }
b3204f43 456 }
132753b5 457
458 delete calPed;
459 f->Close();
09744db4 460 }
132753b5 461 index++;
462 } // while(list)
463
464 //
465 // Store updated pedestal entry to OCDB
466 //
467 if (changes>0) {
468 AliCDBMetaData metaData;
469 metaData.SetBeamPeriod(0);
470 metaData.SetResponsible(kMetaResponsible);
471 metaData.SetComment(kMetaComment);
472
473 Bool_t storeOK = StoreReferenceData("Calib", "Pedestals", calibPed, &metaData);
474 if ( !storeOK ) result++;
09744db4 475 }
132753b5 476 }
477 else {
478 Log ("Error: no entries in input file list!");
479 result = kReturnCodeNoEntries;
480 }
b3204f43 481
132753b5 482 return result;
483}
484
485//______________________________________________________________________________________________
486UInt_t AliEMCALPreprocessor::ExtractSignal(Int_t sourceFXS)
70ee04f5 487{ // Read signal file from file exchange server
4eef2cc9 488 // Only store if new signal info is available
132753b5 489 //
70ee04f5 490 UInt_t result=0;
4eef2cc9 491 AliCaloCalibSignal *calibSig = new AliCaloCalibSignal(AliCaloCalibSignal::kEmCal);
b3204f43 492
132753b5 493 TList* list = GetFileSources(sourceFXS,"signal");
494 if (list && list->GetEntries()>0) {
32fbe941 495
132753b5 496 // loop through all files from LDCs
497
498 int changes = 0;
499 UInt_t index = 0;
500 while (list->At(index)!=NULL) {
501 TObjString* fileNameEntry = (TObjString*) list->At(index);
502 if (fileNameEntry!=NULL) {
503 TString fileName = GetFile(sourceFXS, "signal",
504 fileNameEntry->GetString().Data());
505 TFile *f = TFile::Open(fileName);
506 if (!f) {
507 Log ("Error opening signal file.");
508 result = kReturnCodeNoObject;
509 break;
510 }
511 AliCaloCalibSignal *calSig;
512 f->GetObject("emcCalibSignal",calSig);
513 if ( !calSig ) {
514 Log ("No signal calibration object in file.");
515 result = kReturnCodeNoObject;
516 break;
517 }
518 if ( calSig->GetNEvents()>0 ) {
519 // add info for the modules available in the present file
520 Bool_t status = calibSig->AddInfo(calSig);
521 if (status) { changes++; }
522 }
523
524 delete calSig;
525 f->Close();
526 }
527 index++;
528 } // while(list)
529
530 //
531 // Store updated signal entry to OCDB
532 //
533 if (changes>0) {
534 AliCDBMetaData metaData;
535 metaData.SetBeamPeriod(0);
536 metaData.SetResponsible(kMetaResponsible);
537 metaData.SetComment(kMetaComment);
538
81c4c29b 539 Bool_t storeOK = Store("Calib", "LED", calibSig, &metaData, 0, kFALSE);
132753b5 540 if ( !storeOK ) result++;
541 }
542 }
543 else {
544 Log ("Error: no entries in input file list!");
545 result = kReturnCodeNoEntries;
546 }
547
548 return result;
9e788b10 549}
132753b5 550
551