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"
34 #include <TTimeStamp.h>
36 const Int_t kValCutTemp = 100; // discard temperatures > 100 degrees
37 const Int_t kDiffCutTemp = 5; // discard temperature differences > 5 degrees
38 const TString kPedestalRunType = "PEDESTAL_RUN"; // pedestal run identifier
39 const TString kPulserRunType = "PULSER_RUN"; // pulser run identifier
40 const TString kPhysicsRunType = "PHYSICS"; // physics run identifier
41 const TString kStandAloneRunType = "STANDALONE"; // standalone run identifier
42 const TString kDaqRunType = "DAQ"; // DAQ run identifier
43 const TString kAmandaTemp = "tpc_PT_%d.Temperature"; // Amanda string for temperature entries
44 //const Double_t kFitFraction = 0.7; // Fraction of DCS sensor fits required
45 const Double_t kFitFraction = -1.0; // Don't require minimum number of fits in commissioning run
48 // This class is the SHUTTLE preprocessor for the TPC detector.
51 ClassImp(AliTPCPreprocessor)
53 //______________________________________________________________________________________________
54 AliTPCPreprocessor::AliTPCPreprocessor(AliShuttleInterface* shuttle) :
55 AliPreprocessor("TPC",shuttle),
56 fConfEnv(0), fTemp(0), fHighVoltage(0), fConfigOK(kTRUE), fROC(0)
59 fROC = AliTPCROC::Instance();
61 //______________________________________________________________________________________________
62 // AliTPCPreprocessor::AliTPCPreprocessor(const AliTPCPreprocessor& org) :
63 // AliPreprocessor(org),
64 // fConfEnv(0), fTemp(0), fHighVoltage(0), fConfigOK(kTRUE)
66 // // copy constructor not implemented
67 // // -- missing underlying copy constructor in AliPreprocessor
69 // Fatal("AliTPCPreprocessor", "copy constructor not implemented");
71 // // fTemp = new AliTPCSensorTempArray(*(org.fTemp));
74 //______________________________________________________________________________________________
75 AliTPCPreprocessor::~AliTPCPreprocessor()
82 //______________________________________________________________________________________________
83 AliTPCPreprocessor& AliTPCPreprocessor::operator = (const AliTPCPreprocessor& )
85 Fatal("operator =", "assignment operator not implemented");
90 //______________________________________________________________________________________________
91 void AliTPCPreprocessor::Initialize(Int_t run, UInt_t startTime,
94 // Creates AliTestDataDCS object
96 AliPreprocessor::Initialize(run, startTime, endTime);
98 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
99 TTimeStamp(startTime).AsString(),
100 TTimeStamp(endTime).AsString()));
102 // Preprocessor configuration
104 AliCDBEntry* entry = GetFromOCDB("Config", "Preprocessor");
105 if (entry) fConfEnv = (TEnv*) entry->GetObject();
107 Log("AliTPCPreprocsessor: Preprocessor Config OCDB entry missing.\n");
112 // Temperature sensors
115 entry = GetFromOCDB("Config", "Temperature");
116 if (entry) confTree = (TTree*) entry->GetObject();
118 Log("AliTPCPreprocsessor: Temperature Config OCDB entry missing.\n");
122 fTemp = new AliTPCSensorTempArray(fStartTime, fEndTime, confTree, kAmandaTemp);
123 fTemp->SetValCut(kValCutTemp);
124 fTemp->SetDiffCut(kDiffCutTemp);
127 // High voltage measurements
129 if (false) { // high voltage maps not yet implemented...
132 entry = GetFromOCDB("Config", "HighVoltage");
133 if (entry) confTree = (TTree*) entry->GetObject();
135 Log("AliTPCPreprocsessor: High Voltage Config OCDB entry missing.\n");
139 fHighVoltage = new AliDCSSensorArray(fStartTime, fEndTime, confTree);
143 //______________________________________________________________________________________________
144 UInt_t AliTPCPreprocessor::Process(TMap* dcsAliasMap)
146 // Fills data into TPC calibrations objects
148 // Amanda servers provide information directly through dcsAliasMap
150 if (!dcsAliasMap) return 9;
151 if (dcsAliasMap->GetEntries() == 0 ) return 9;
152 if (!fConfigOK) return 9;
154 TString runType = GetRunType();
156 // Temperature sensors are processed by AliTPCCalTemp
159 UInt_t tempResult = MapTemperature(dcsAliasMap);
160 UInt_t result=tempResult;
162 // High Voltage recordings
165 if (false) { // High Voltage maps not yet implemented..
167 UInt_t hvResult = MapHighVoltage(dcsAliasMap);
172 // Other calibration information will be retrieved through FXS files
174 // TList* fileSourcesDAQ = GetFile(AliShuttleInterface::kDAQ, "pedestals");
175 // const char* fileNamePed = GetFile(AliShuttleInterface::kDAQ, "pedestals", "LDC1");
177 // TList* fileSourcesHLT = GetFile(AliShuttleInterface::kHLT, "calib");
178 // const char* fileNameHLT = GetFile(AliShuttleInterface::kHLT, "calib", "LDC1");
182 if(runType == kPedestalRunType) {
183 Int_t numSources = 1;
184 Int_t pedestalSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
185 TString source = fConfEnv->GetValue("Pedestal","DAQ");
187 if ( source == "HLT") pedestalSource[0] = AliShuttleInterface::kHLT;
188 if (!GetHLTStatus()) pedestalSource[0] = AliShuttleInterface::kDAQ;
189 if (source == "HLTDAQ" ) {
191 pedestalSource[0] = AliShuttleInterface::kHLT;
192 pedestalSource[1] = AliShuttleInterface::kDAQ;
194 if (source == "DAQHLT" ) numSources=2;
195 UInt_t pedestalResult=0;
196 for (Int_t i=0; i<numSources; i++ ) {
197 UInt_t pedestalResult = ExtractPedestals(pedestalSource[i]);
198 if ( pedestalResult == 0 ) break;
200 result += pedestalResult;
204 // pulser trigger processing
206 if(runType == kPulserRunType) {
207 Int_t numSources = 1;
208 Int_t pulserSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
209 TString source = fConfEnv->GetValue("Pulser","DAQ");
211 if ( source == "HLT") pulserSource[0] = AliShuttleInterface::kHLT;
212 if (!GetHLTStatus()) pulserSource[0] = AliShuttleInterface::kDAQ;
213 if (source == "HLTDAQ" ) {
215 pulserSource[0] = AliShuttleInterface::kHLT;
216 pulserSource[1] = AliShuttleInterface::kDAQ;
218 if (source == "DAQHLT" ) numSources=2;
219 UInt_t pulserResult=0;
220 for (Int_t i=0; i<numSources; i++ ) {
221 pulserResult = ExtractPulser(pulserSource[i]);
222 if ( pulserResult == 0 ) break;
224 result += pulserResult;
230 // Central Electrode processing
232 if( runType == kPhysicsRunType || runType == kStandAloneRunType ||
233 runType == kDaqRunType ) {
235 Int_t numSources = 1;
236 Int_t ceSource[2] = {AliShuttleInterface::kDAQ,AliShuttleInterface::kHLT} ;
237 TString source = fConfEnv->GetValue("CE","DAQ");
239 if ( source == "HLT") ceSource[0] = AliShuttleInterface::kHLT;
240 if (!GetHLTStatus()) ceSource[0] = AliShuttleInterface::kDAQ;
241 if (source == "HLTDAQ" ) {
243 ceSource[0] = AliShuttleInterface::kHLT;
244 ceSource[1] = AliShuttleInterface::kDAQ;
246 if (source == "DAQHLT" ) numSources=2;
248 for (Int_t i=0; i<numSources; i++ ) {
249 ceResult = ExtractCE(ceSource[i]);
250 if ( ceResult == 0 ) break;
257 return 0; // Don't produce error codes during December tests
259 //______________________________________________________________________________________________
260 UInt_t AliTPCPreprocessor::MapTemperature(TMap* dcsAliasMap)
263 // extract DCS temperature maps. Perform fits to save space
266 TMap *map = fTemp->ExtractDCS(dcsAliasMap);
268 fTemp->MakeSplineFit(map);
269 Double_t fitFraction = 1.0*fTemp->NumFits()/fTemp->NumSensors();
270 if (fitFraction > kFitFraction ) {
271 AliInfo(Form("Temperature values extracted, fits performed.\n"));
273 Log ("Too few temperature maps fitted. \n");
277 Log("No temperature map extracted. \n");
281 // Now store the final CDB file
284 AliCDBMetaData metaData;
285 metaData.SetBeamPeriod(0);
286 metaData.SetResponsible("Haavard Helstrup");
287 metaData.SetComment("Preprocessor AliTPC data base entries.");
289 Bool_t storeOK = Store("Calib", "Temperature", fTemp, &metaData, 0, kFALSE);
290 if ( !storeOK ) result=1;
298 //______________________________________________________________________________________________
299 UInt_t AliTPCPreprocessor::MapHighVoltage(TMap* dcsAliasMap)
302 // extract DCS HV maps. Perform fits to save space
305 TMap *map = fHighVoltage->ExtractDCS(dcsAliasMap);
307 fHighVoltage->MakeSplineFit(map);
308 Double_t fitFraction = 1.0*fHighVoltage->NumFits()/fHighVoltage->NumSensors();
309 if (fitFraction > kFitFraction ) {
310 AliInfo(Form("High volatge recordings extracted, fits performed.\n"));
312 Log ("Too few high voltage recordings fitted. \n");
316 Log("No high voltage recordings extracted. \n");
320 // Now store the final CDB file
323 AliCDBMetaData metaData;
324 metaData.SetBeamPeriod(0);
325 metaData.SetResponsible("Haavard Helstrup");
326 metaData.SetComment("Preprocessor AliTPC data base entries.");
328 Bool_t storeOK = Store("Calib", "HighVoltage", fHighVoltage, &metaData, 0, kFALSE);
329 if ( !storeOK ) result=1;
338 //______________________________________________________________________________________________
340 UInt_t AliTPCPreprocessor::ExtractPedestals(Int_t sourceFXS)
343 // Read pedestal file from file exchage server
344 // Keep original entry from OCDB in case no new pedestals are available
346 AliTPCCalPad *calPadPed=0;
347 AliCDBEntry* entry = GetFromOCDB("Calib", "Pedestals");
348 if (entry) calPadPed = (AliTPCCalPad*)entry->GetObject();
349 if ( calPadPed==NULL ) {
350 Log("AliTPCPreprocsessor: No previous TPC pedestal entry available.\n");
351 calPadPed = new AliTPCCalPad("PedestalsMean","PedestalsMean");
354 AliTPCCalPad *calPadRMS=0;
355 entry = GetFromOCDB("Calib", "Noise");
356 if (entry) calPadRMS = (AliTPCCalPad*)entry->GetObject();
357 if ( calPadRMS==NULL ) {
358 Log("AliTPCPreprocsessor: No previous TPC noise entry available.\n");
359 calPadRMS = new AliTPCCalPad("PedestalsRMS","PedestalsRMS");
365 Int_t nSectors = fROC->GetNSectors();
366 TList* list = GetFileSources(sourceFXS,"pedestals");
368 if (list && list->GetEntries()>0) {
370 // loop through all files from LDCs
372 Bool_t changed=false;
374 while (list->At(index)!=NULL) {
375 TObjString* fileNameEntry = (TObjString*) list->At(index);
376 if (fileNameEntry!=NULL) {
377 TString fileName = GetFile(sourceFXS, "pedestals",
378 fileNameEntry->GetString().Data());
379 TFile *f = TFile::Open(fileName);
381 Log ("Error opening pedestal file.");
385 AliTPCCalibPedestal *calPed;
386 f->GetObject("AliTPCCalibPedestal",calPed);
388 Log ("No pedestal calibration object in file.");
393 // replace entries for the sectors available in the present file
396 for (Int_t sector=0; sector<nSectors; sector++) {
397 AliTPCCalROC *rocPed=calPed->GetCalRocPedestal(sector, kFALSE);
398 if ( rocPed ) calPadPed->SetCalROC(rocPed,sector);
399 AliTPCCalROC *rocRMS=calPed->GetCalRocRMS(sector, kFALSE);
400 if ( rocRMS ) calPadRMS->SetCalROC(rocRMS,sector);
406 // Store updated pedestal entry to OCDB
409 AliCDBMetaData metaData;
410 metaData.SetBeamPeriod(0);
411 metaData.SetResponsible("Haavard Helstrup");
412 metaData.SetComment("Preprocessor AliTPC data base entries.");
414 Bool_t storeOK = Store("Calib", "Pedestals", calPadPed, &metaData, 0, kTRUE);
415 if ( !storeOK ) ++result;
416 storeOK = Store("Calib", "PadNoise", calPadRMS, &metaData, 0, kTRUE);
417 if ( !storeOK ) ++result;
420 Log ("Error: no entries in input file list!");
427 //______________________________________________________________________________________________
430 UInt_t AliTPCPreprocessor::ExtractPulser(Int_t sourceFXS)
433 // Read pulser calibration file from file exchage server
434 // Keep original entry from OCDB in case no new pulser calibration is available
436 TObjArray *pulserObjects=0;
437 AliTPCCalPad *pulserTmean=0;
438 AliTPCCalPad *pulserTrms=0;
439 AliTPCCalPad *pulserQmean=0;
440 AliCDBEntry* entry = GetFromOCDB("Calib", "Pulser");
441 if (entry) pulserObjects = (TObjArray*)entry->GetObject();
442 if ( pulserObjects==NULL ) {
443 Log("AliTPCPreprocsessor: No previous TPC pulser entry available.\n");
444 pulserObjects = new TObjArray;
447 pulserTmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserTmean");
448 if ( !pulserTmean ) {
449 pulserTmean = new AliTPCCalPad("PulserTmean","PulserTmean");
450 pulserObjects->Add(pulserTmean);
452 pulserTrms = (AliTPCCalPad*)pulserObjects->FindObject("PulserTrms");
454 pulserTrms = new AliTPCCalPad("PulserTrms","PulserTrms");
455 pulserObjects->Add(pulserTrms);
457 pulserQmean = (AliTPCCalPad*)pulserObjects->FindObject("PulserQmean");
458 if ( !pulserQmean ) {
459 pulserQmean = new AliTPCCalPad("PulserQmean","PulserQmean");
460 pulserObjects->Add(pulserQmean);
466 Int_t nSectors = fROC->GetNSectors();
467 TList* list = GetFileSources(sourceFXS,"pulser");
469 if (list && list->GetEntries()>0) {
471 // loop through all files from LDCs
473 Bool_t changed=false;
475 while (list->At(index)!=NULL) {
476 TObjString* fileNameEntry = (TObjString*) list->At(index);
477 if (fileNameEntry!=NULL) {
478 TString fileName = GetFile(sourceFXS, "pulser",
479 fileNameEntry->GetString().Data());
480 TFile *f = TFile::Open(fileName);
482 Log ("Error opening pulser file.");
486 AliTPCCalibPulser *calPulser;
487 f->GetObject("AliTPCCalibPulser",calPulser);
489 Log ("No pulser calibration object in file.");
494 // replace entries for the sectors available in the present file
497 for (Int_t sector=0; sector<nSectors; sector++) {
498 AliTPCCalROC *rocTmean=calPulser->GetCalRocT0(sector);
499 if ( rocTmean ) pulserTmean->SetCalROC(rocTmean,sector);
500 AliTPCCalROC *rocTrms=calPulser->GetCalRocRMS(sector);
501 if ( rocTrms ) pulserTrms->SetCalROC(rocTrms,sector);
502 AliTPCCalROC *rocQmean=calPulser->GetCalRocQ(sector);
503 if ( rocQmean ) pulserQmean->SetCalROC(rocQmean,sector);
509 // Store updated pedestal entry to OCDB
512 AliCDBMetaData metaData;
513 metaData.SetBeamPeriod(0);
514 metaData.SetResponsible("Haavard Helstrup");
515 metaData.SetComment("Preprocessor AliTPC data base entries.");
517 Bool_t storeOK = Store("Calib", "Pulser", pulserObjects, &metaData, 0, kTRUE);
518 if ( !storeOK ) ++result;
521 Log ("Error: no entries in input file list!");
528 UInt_t AliTPCPreprocessor::ExtractCE(Int_t sourceFXS)
531 // Read Central Electrode file from file exchage server
532 // Keep original entry from OCDB in case no new CE calibration is available
534 TObjArray *ceObjects=0;
535 AliTPCCalPad *ceTmean=0;
536 AliTPCCalPad *ceTrms=0;
537 AliTPCCalPad *ceQmean=0;
538 AliCDBEntry* entry = GetFromOCDB("Calib", "CE");
539 if (entry) ceObjects = (TObjArray*)entry->GetObject();
540 if ( ceObjects==NULL ) {
541 Log("AliTPCPreprocsessor: No previous TPC central electrode entry available.\n");
542 ceObjects = new TObjArray;
545 ceTmean = (AliTPCCalPad*)ceObjects->FindObject("CETmean");
547 ceTmean = new AliTPCCalPad("CETmean","CETmean");
548 ceObjects->Add(ceTmean);
550 ceTrms = (AliTPCCalPad*)ceObjects->FindObject("CETrms");
552 ceTrms = new AliTPCCalPad("CETrms","CETrms");
553 ceObjects->Add(ceTrms);
555 ceQmean = (AliTPCCalPad*)ceObjects->FindObject("CEQmean");
557 ceQmean = new AliTPCCalPad("CEQmean","CEQmean");
558 ceObjects->Add(ceQmean);
564 Int_t nSectors = fROC->GetNSectors();
565 TList* list = GetFileSources(sourceFXS,"CE");
567 if (list && list->GetEntries()>0) {
569 // loop through all files from LDCs
572 while (list->At(index)!=NULL) {
573 TObjString* fileNameEntry = (TObjString*) list->At(index);
574 if (fileNameEntry!=NULL) {
575 TString fileName = GetFile(sourceFXS, "CE",
576 fileNameEntry->GetString().Data());
577 TFile *f = TFile::Open(fileName);
579 Log ("Error opening central electrode file.");
583 AliTPCCalibCE *calCE;
584 f->GetObject("AliTPCCalibCE",calCE);
586 // replace entries for the sectors available in the present file
588 for (Int_t sector=0; sector<nSectors; sector++) {
589 AliTPCCalROC *rocTmean=calCE->GetCalRocT0(sector);
590 if ( rocTmean ) ceTmean->SetCalROC(rocTmean,sector);
591 AliTPCCalROC *rocTrms=calCE->GetCalRocRMS(sector);
592 if ( rocTrms ) ceTrms->SetCalROC(rocTrms,sector);
593 AliTPCCalROC *rocQmean=calCE->GetCalRocQ(sector);
594 if ( rocQmean ) ceQmean->SetCalROC(rocQmean,sector);
600 // Store updated pedestal entry to OCDB
602 AliCDBMetaData metaData;
603 metaData.SetBeamPeriod(0);
604 metaData.SetResponsible("Haavard Helstrup");
605 metaData.SetComment("Preprocessor AliTPC data base entries.");
607 Bool_t storeOK = Store("Calib", "CE", ceObjects, &metaData, 0, kTRUE);
608 if ( !storeOK ) ++result;
611 Log ("Error: no entries!");