1 /**************************************************************************
2 * Copyright(c) 2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 #include "AliTPCPreprocessor.h"
18 #include "AliShuttleInterface.h"
20 #include "AliCDBMetaData.h"
21 #include "AliDCSValue.h"
23 #include "AliTPCSensorTempArray.h"
24 #include "AliTPCROC.h"
25 #include "AliTPCCalROC.h"
26 #include "AliTPCCalPad.h"
27 #include "AliTPCCalibPedestal.h"
28 #include "AliTPCCalibPulser.h"
29 #include "AliTPCCalibCE.h"
33 #include "TParameter.h"
35 #include <TTimeStamp.h>
37 const Int_t kValCutTemp = 100; // discard temperatures > 100 degrees
38 const Int_t kDiffCutTemp = 5; // discard temperature differences > 5 degrees
39 const TString kPedestalRunType = "PEDESTAL"; // pedestal run identifier
40 const TString kPulserRunType = "PULSER"; // pulser run identifier
41 const TString kPhysicsRunType = "PHYSICS"; // physics run identifier
42 const TString kStandAloneRunType = "STANDALONE"; // standalone run identifier
43 const TString kDaqRunType = "DAQ"; // DAQ run identifier
44 const TString kAmandaTemp = "tpc_PT_%d.Temperature"; // Amanda string for temperature entries
45 //const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required
46 const Double_t kFitFraction = -1.0; // Don't require minimum number of fits in commissioning run
49 // This class is the SHUTTLE preprocessor for the TPC detector.
52 ClassImp(AliTPCPreprocessor)
54 //______________________________________________________________________________________________
55 AliTPCPreprocessor::AliTPCPreprocessor(AliShuttleInterface* shuttle) :
56 AliPreprocessor("TPC",shuttle),
57 fConfEnv(0), fTemp(0), fHighVoltage(0), fConfigOK(kTRUE), fROC(0)
60 fROC = AliTPCROC::Instance();
62 //______________________________________________________________________________________________
63 // AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor& org) :
64 // AliPreprocessor(org),
65 // fConfEnv(0), fTemp(0), fHighVoltage(0), fConfigOK(kTRUE)
67 // // copy constructor not implemented
68 // // -- missing underlying copy constructor in AliPreprocessor
70 // Fatal("AliTPCPreprocessor", "copy constructor not implemented");
72 // // fTemp = new AliTPCSensorTempArray(*(org.fTemp));
75 //______________________________________________________________________________________________
76 AliTPCPreprocessor::~AliTPCPreprocessor()
83 //______________________________________________________________________________________________
84 AliTPCPreprocessor& AliTPCPreprocessor::operator = (const AliTPCPreprocessor& )
86 Fatal("operator =", "assignment operator not implemented");
91 //______________________________________________________________________________________________
92 void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
95 // Creates AliTestDataDCS object
97 UInt_t startTimeLocal = startTime-3600;
99 AliPreprocessor::Initialize(run, startTimeLocal, endTime);
101 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
102 TTimeStamp(startTime).AsString(),
103 TTimeStamp(endTime).AsString()));
105 // Preprocessor configuration
107 AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor");
108 if (entry) fConfEnv = (TEnv*) entry->GetObject();
110 Log("AliTPCPreprocsessor: Preprocessor Config OCDB entry missing.\n");
115 // Temperature sensors
119 TString tempConf = fConfEnv->GetValue("Temperature","ON");
121 if (tempConf != "OFF" ) {
122 entry = GetFromOCDB("Config", "Temperature");
123 if (entry) confTree = (TTree*) entry->GetObject();
125 Log("AliTPCPreprocsessor: Temperature Config OCDB entry missing.\n");
129 fTemp = new AliTPCSensorTempArray(startTimeLocal, endTime, confTree, kAmandaTemp);
130 fTemp->SetValCut(kValCutTemp);
131 fTemp->SetDiffCut(kDiffCutTemp);
134 // High voltage measurements
136 TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
138 if (hvConf != "OFF" ) {
141 entry = GetFromOCDB("Config", "HighVoltage");
142 if (entry) confTree = (TTree*) entry->GetObject();
144 Log("AliTPCPreprocsessor: High Voltage Config OCDB entry missing.\n");
148 fHighVoltage = new AliDCSSensorArray(startTimeLocal, endTime, confTree);
152 //______________________________________________________________________________________________
153 UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
155 // Fills data into TPC calibrations objects
157 // Amanda servers provide information directly through dcsAliasMap
159 if (!fConfigOK) return 9;
161 TObjArray *resultArray = new TObjArray();
162 TString errorHandling = fConfEnv->GetValue("ErrorHandling","ON");
163 errorHandling.ToUpper();
167 if (errorHandling == "OFF" ) {
168 if (!dcsAliasMap) dcsResult=1;
169 if (dcsAliasMap->GetEntries() == 0 ) dcsResult=1;
170 status = new TParameter<int>("dcsResult",dcsResult);
171 resultArray->Add(status);
173 if (!dcsAliasMap) return 9;
174 if (dcsAliasMap->GetEntries() == 0 ) return 9;
177 TString runType = GetRunType();
179 // Temperature sensors are processed by AliTPCCalTemp
181 TString tempConf = fConfEnv->GetValue("Temperature","ON");
183 if (tempConf != "OFF" ) {
184 UInt_t tempResult = MapTemperature(dcsAliasMap);
186 status = new TParameter<int>("tempResult",tempResult);
187 resultArray->Add(status);
190 // High Voltage recordings
193 TString hvConf = fConfEnv->GetValue("HighVoltage","ON");
195 if (hvConf != "OFF" ) {
196 UInt_t hvResult = MapHighVoltage(dcsAliasMap);
198 status = new TParameter<int>("hvResult",hvResult);
199 resultArray->Add(status);
202 // Other calibration information will be retrieved through FXS files
204 // TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
205 // const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
207 // TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
208 // const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
212 if(runType == kPedestalRunType) {
213 Int_t numSources = 1;
214 Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
215 TString source = fConfEnv->GetValue("Pedestal","DAQ");
217 if (source != "OFF" ) {
218 if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
219 if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
220 if (source == "HLTDAQ" ) {
222 pedestalSource[0] = AliShuttleInterface::kHLT;
223 pedestalSource[1] = AliShuttleInterface::kDAQ;
225 if (source == "DAQHLT" ) numSources=2;
226 UInt_t pedestalResult=0;
227 for (Int_t i=0; i<numSources; i++ ) {
228 UInt_t pedestalResult = ExtractPedestals(pedestalSource[i]);
229 if ( pedestalResult == 0 ) break;
231 result += pedestalResult;
232 status = new TParameter<int>("pedestalResult",pedestalResult);
233 resultArray->Add(status);
237 // pulser trigger processing
239 if(runType == kPulserRunType) {
240 Int_t numSources = 1;
241 Int_t pulserSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
242 TString source = fConfEnv->GetValue("Pulser","DAQ");
244 if ( source != "OFF") {
245 if ( source == "HLT") pulserSource[0] = AliShuttleInterface::kHLT;
246 if (!GetHLTStatus()) pulserSource[0] = AliShuttleInterface::kDAQ;
247 if (source == "HLTDAQ" ) {
249 pulserSource[0] = AliShuttleInterface::kHLT;
250 pulserSource[1] = AliShuttleInterface::kDAQ;
252 if (source == "DAQHLT" ) numSources=2;
253 UInt_t pulserResult=0;
254 for (Int_t i=0; i<numSources; i++ ) {
255 pulserResult = ExtractPulser(pulserSource[i]);
256 if ( pulserResult == 0 ) break;
258 result += pulserResult;
259 status = new TParameter<int>("pulserResult",pulserResult);
260 resultArray->Add(status);
266 // Central Electrode processing
268 if( runType == kPhysicsRunType || runType == kStandAloneRunType ||
269 runType == kDaqRunType ) {
271 Int_t numSources = 1;
272 Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
273 TString source = fConfEnv->GetValue("CE","DAQ");
275 if ( source != "OFF" ) {
276 if ( source == "HLT") ceSource[0] = AliShuttleInterface::kHLT;
277 if (!GetHLTStatus()) ceSource[0] = AliShuttleInterface::kDAQ;
278 if (source == "HLTDAQ" ) {
280 ceSource[0] = AliShuttleInterface::kHLT;
281 ceSource[1] = AliShuttleInterface::kDAQ;
283 if (source == "DAQHLT" ) numSources=2;
285 for (Int_t i=0; i<numSources; i++ ) {
286 ceResult = ExtractCE(ceSource[i]);
287 if ( ceResult == 0 ) break;
290 status = new TParameter<int>("ceResult",ceResult);
291 resultArray->Add(status);
295 if (errorHandling == "OFF" ) {
296 AliCDBMetaData metaData;
297 metaData.SetBeamPeriod(0);
298 metaData.SetResponsible("Haavard Helstrup");
299 metaData.SetComment("Preprocessor AliTPC status.");
300 Store("Calib", "PreprocStatus", resultArray, &metaData, 0, kFALSE);
301 resultArray->Delete();
307 //______________________________________________________________________________________________
308 UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
311 // extract DCS temperature maps. Perform fits to save space
314 TMap *map = fTemp->ExtractDCS(dcsAliasMap);
316 fTemp->MakeSplineFit(map);
317 Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors();
318 if (fitFraction > kFitFraction ) {
319 AliInfo(Form("Temperature values extracted, fits performed.\n"));
321 Log ("Too few temperature maps fitted. \n");
325 Log("No temperature map extracted. \n");
329 // Now store the final CDB file
332 AliCDBMetaData metaData;
333 metaData.SetBeamPeriod(0);
334 metaData.SetResponsible("Haavard Helstrup");
335 metaData.SetComment("Preprocessor AliTPC data base entries.");
337 Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
338 if ( !storeOK ) result=1;
346 //______________________________________________________________________________________________
347 UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
350 // extract DCS HV maps. Perform fits to save space
353 TMap *map = fHighVoltage->ExtractDCS(dcsAliasMap);
355 fHighVoltage->MakeSplineFit(map);
356 Double_t fitFraction = 1.0*fHighVoltage->NumFits()/fHighVoltage->NumSensors();
357 if (fitFraction > kFitFraction ) {
358 AliInfo(Form("High voltage recordings extracted, fits performed.\n"));
360 Log ("Too few high voltage recordings fitted. \n");
364 Log("No high voltage recordings extracted. \n");
368 // Now store the final CDB file
371 AliCDBMetaData metaData;
372 metaData.SetBeamPeriod(0);
373 metaData.SetResponsible("Haavard Helstrup");
374 metaData.SetComment("Preprocessor AliTPC data base entries.");
376 Bool_t storeOK = Store("Calib", "HighVoltage", fHighVoltage, &metaData, 0, kFALSE);
377 if ( !storeOK ) result=1;
386 //______________________________________________________________________________________________
388 UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
391 // Read pedestal file from file exchage server
392 // Keep original entry from OCDB in case no new pedestals are available
394 AliTPCCalPad *calPadPed=0;
395 AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
396 if (entry) calPadPed = (AliTPCCalPad*)entry->GetObject();
397 if ( calPadPed==NULL ) {
398 Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
399 calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
402 AliTPCCalPad *calPadRMS=0;
403 entry = GetFromOCDB("Calib", "Noise");
404 if (entry) calPadRMS = (AliTPCCalPad*)entry->GetObject();
405 if ( calPadRMS==NULL ) {
406 Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
407 calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
413 Int_t nSectors = fROC->GetNSectors();
414 TList* list = GetFileSources(sourceFXS,"pedestals");
416 if (list && list->GetEntries()>0) {
418 // loop through all files from LDCs
420 Bool_t changed=false;
422 while (list->At(index)!=NULL) {
423 TObjString* fileNameEntry = (TObjString*) list->At(index);
424 if (fileNameEntry!=NULL) {
425 TString fileName = GetFile(sourceFXS, "pedestals",
426 fileNameEntry->GetString().Data());
427 TFile *f = TFile::Open(fileName);
429 Log ("Error opening pedestal file.");
433 AliTPCCalibPedestal *calPed;
434 f->GetObject("AliTPCCalibPedestal",calPed);
436 Log ("No pedestal calibration object in file.");
441 // replace entries for the sectors available in the present file
444 for (Int_t sector=0; sector<nSectors; sector++) {
445 AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
446 if ( rocPed ) calPadPed->SetCalROC(rocPed,sector);
447 AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
448 if ( rocRMS ) calPadRMS->SetCalROC(rocRMS,sector);
454 // Store updated pedestal entry to OCDB
457 AliCDBMetaData metaData;
458 metaData.SetBeamPeriod(0);
459 metaData.SetResponsible("Haavard Helstrup");
460 metaData.SetComment("Preprocessor AliTPC data base entries.");
462 Bool_t storeOK = Store("Calib", "Pedestals", calPadPed, &metaData, 0, kTRUE);
463 if ( !storeOK ) ++result;
464 storeOK = Store("Calib", "PadNoise", calPadRMS, &metaData, 0, kTRUE);
465 if ( !storeOK ) ++result;
468 Log ("Error: no entries in input file list!");
475 //______________________________________________________________________________________________
478 UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
481 // Read pulser calibration file from file exchage server
482 // Keep original entry from OCDB in case no new pulser calibration is available
484 TObjArray *pulserObjects=0;
485 AliTPCCalPad *pulserTmean=0;
486 AliTPCCalPad *pulserTrms=0;
487 AliTPCCalPad *pulserQmean=0;
488 AliCDBEntry* entry = GetFromOCDB("Calib", "Pulser");
489 if (entry) pulserObjects = (TObjArray*)entry->GetObject();
490 if ( pulserObjects==NULL ) {
491 Log("AliTPCPreprocsessor: No previous TPC pulser entry available.\n");
492 pulserObjects = new TObjArray;
495 pulserTmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserTmean");
496 if ( !pulserTmean ) {
497 pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
498 pulserObjects->Add(pulserTmean);
500 pulserTrms = (AliTPCCalPad*)pulserObjects->FindObject("PulserTrms");
502 pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
503 pulserObjects->Add(pulserTrms);
505 pulserQmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserQmean");
506 if ( !pulserQmean ) {
507 pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
508 pulserObjects->Add(pulserQmean);
514 Int_t nSectors = fROC->GetNSectors();
515 TList* list = GetFileSources(sourceFXS,"pulser");
517 if (list && list->GetEntries()>0) {
519 // loop through all files from LDCs
521 Bool_t changed=false;
523 while (list->At(index)!=NULL) {
524 TObjString* fileNameEntry = (TObjString*) list->At(index);
525 if (fileNameEntry!=NULL) {
526 TString fileName = GetFile(sourceFXS, "pulser",
527 fileNameEntry->GetString().Data());
528 TFile *f = TFile::Open(fileName);
530 Log ("Error opening pulser file.");
534 AliTPCCalibPulser *calPulser;
535 f->GetObject("AliTPCCalibPulser",calPulser);
537 Log ("No pulser calibration object in file.");
542 // replace entries for the sectors available in the present file
545 for (Int_t sector=0; sector<nSectors; sector++) {
546 AliTPCCalROC *rocTmean=calPulser->GetCalRocT0(sector);
547 if ( rocTmean ) pulserTmean->SetCalROC(rocTmean,sector);
548 AliTPCCalROC *rocTrms=calPulser->GetCalRocRMS(sector);
549 if ( rocTrms ) pulserTrms->SetCalROC(rocTrms,sector);
550 AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
551 if ( rocQmean ) pulserQmean->SetCalROC(rocQmean,sector);
557 // Store updated pedestal entry to OCDB
560 AliCDBMetaData metaData;
561 metaData.SetBeamPeriod(0);
562 metaData.SetResponsible("Haavard Helstrup");
563 metaData.SetComment("Preprocessor AliTPC data base entries.");
565 Bool_t storeOK = Store("Calib", "Pulser", pulserObjects, &metaData, 0, kTRUE);
566 if ( !storeOK ) ++result;
569 Log ("Error: no entries in input file list!");
576 UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
579 // Read Central Electrode file from file exchage server
580 // Keep original entry from OCDB in case no new CE calibration is available
582 TObjArray *ceObjects=0;
583 AliTPCCalPad *ceTmean=0;
584 AliTPCCalPad *ceTrms=0;
585 AliTPCCalPad *ceQmean=0;
586 AliCDBEntry* entry = GetFromOCDB("Calib", "CE");
587 if (entry) ceObjects = (TObjArray*)entry->GetObject();
588 if ( ceObjects==NULL ) {
589 Log("AliTPCPreprocsessor: No previous TPC central electrode entry available.\n");
590 ceObjects = new TObjArray;
593 ceTmean = (AliTPCCalPad*)ceObjects->FindObject("CETmean");
595 ceTmean = new AliTPCCalPad("CETmean","CETmean");
596 ceObjects->Add(ceTmean);
598 ceTrms = (AliTPCCalPad*)ceObjects->FindObject("CETrms");
600 ceTrms = new AliTPCCalPad("CETrms","CETrms");
601 ceObjects->Add(ceTrms);
603 ceQmean = (AliTPCCalPad*)ceObjects->FindObject("CEQmean");
605 ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
606 ceObjects->Add(ceQmean);
612 Int_t nSectors = fROC->GetNSectors();
613 TList* list = GetFileSources(sourceFXS,"CE");
615 if (list && list->GetEntries()>0) {
617 // loop through all files from LDCs
620 while (list->At(index)!=NULL) {
621 TObjString* fileNameEntry = (TObjString*) list->At(index);
622 if (fileNameEntry!=NULL) {
623 TString fileName = GetFile(sourceFXS, "CE",
624 fileNameEntry->GetString().Data());
625 TFile *f = TFile::Open(fileName);
627 Log ("Error opening central electrode file.");
631 AliTPCCalibCE *calCE;
632 f->GetObject("AliTPCCalibCE",calCE);
634 // replace entries for the sectors available in the present file
636 for (Int_t sector=0; sector<nSectors; sector++) {
637 AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
638 if ( rocTmean ) ceTmean->SetCalROC(rocTmean,sector);
639 AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
640 if ( rocTrms ) ceTrms->SetCalROC(rocTrms,sector);
641 AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
642 if ( rocQmean ) ceQmean->SetCalROC(rocQmean,sector);
648 // Store updated pedestal entry to OCDB
650 AliCDBMetaData metaData;
651 metaData.SetBeamPeriod(0);
652 metaData.SetResponsible("Haavard Helstrup");
653 metaData.SetComment("Preprocessor AliTPC data base entries.");
655 Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
656 if ( !storeOK ) ++result;
659 Log ("Error: no entries!");