1 /**************************************************************************
2 * Copyright(c) 1998-1999, 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 **************************************************************************/
18 //#include <Riostream.h>
25 #include <TObjArray.h>
26 #include <TObjString.h>
27 #include <TTimeStamp.h>
29 #include "AliCDBMetaData.h"
30 #include "AliCDBEntry.h"
32 #include "AliTOFChannelOnlineArray.h"
33 #include "AliTOFChannelOnlineStatusArray.h"
34 #include "AliTOFDataDCS.h"
35 #include "AliTOFGeometry.h"
36 #include "AliTOFPreprocessor.h"
37 #include "AliTOFFEEReader.h"
38 #include "AliTOFRawStream.h"
39 #include "AliTOFCableLengthMap.h"
42 // TOF preprocessor class.
43 // It takes data from DCS and passes them to the class AliTOFDataDCS, which
44 // processes them. The result is then written to the CDB.
45 // Analogously, it takes data form DAQ (both at Run level and inclusive -
46 // of all the runs - level, processes them, and stores both Reference Data
47 // and Online Calibration files in the CDB.
48 // Processing of Pulser/Noise Run data and of TOF FEE DCS map included also.
52 // return=1 : no DCS input data Map
53 // return=2 : no DCS input data processing
54 // return=3 : no DCS processed data was stored in Ref Data
55 // return=4 : no DAQ input for Ref Data
56 // return=5 : failed to store DAQ Ref Data
57 // return=6 : failed to retrieve DAQ data for calibration
58 // return=7 : problems in processing histos in the input DAQ file
59 // return=8 : failed to store Online Delays
60 // return=9 : failed to store Reference Data for Pulser
61 // return=10: failed to retrieve Pulser data
62 // return=11: failed to store Pulser map in OCDB
63 // return=12: failed to store Reference Data for Noise
64 // return=13: failed to retrieve Noise data
65 // return=14: failed to store Noise map in OCDB
66 // return=15: failed to retrieve FEE data from FXS
67 // return=16: failed to retrieve FEE data from OCDB
68 // return=17: failed to store FEE data in OCDB
69 // return=18: failed to store FEE reference data in OCDB
70 // return=20: failed in retrieving status variable
72 ClassImp(AliTOFPreprocessor)
74 const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean
75 const Double_t AliTOFPreprocessor::fgkIntegralThr = 100; // min number of entries to perform computation of delay per channel
76 const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay
78 //_____________________________________________________________________________
80 AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
81 AliPreprocessor("TOF", shuttle),
91 AddRunType("PHYSICS");
97 //_____________________________________________________________________________
99 AliTOFPreprocessor::~AliTOFPreprocessor()
104 //______________________________________________________________________________
105 void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
108 // Creates AliTOFDataDCS object
110 AliPreprocessor::Initialize(run, startTime, endTime);
112 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
113 TTimeStamp(startTime).AsString(),
114 TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
116 fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
117 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
119 //_____________________________________________________________________________
120 Bool_t AliTOFPreprocessor::ProcessDCS(){
122 // check whether DCS should be processed or not...
124 TString runType = GetRunType();
125 Log(Form("RunType %s",runType.Data()));
127 if (runType != "PHYSICS"){
133 //_____________________________________________________________________________
135 UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap* dcsAliasMap)
137 // Fills data into a AliTOFDataDCS object
140 Log("Processing DCS DP");
141 TH1::AddDirectory(0);
143 Bool_t resultDCSMap=kFALSE;
144 Bool_t resultDCSStore=kFALSE;
148 fData->SetFDRFlag(fFDRFlag);
151 Log("No DCS map found: TOF exiting from Shuttle");
156 return 1;// return error Code for DCS input data not found
160 // The processing of the DCS input data is forwarded to AliTOFDataDCS
161 resultDCSMap=fData->ProcessData(*dcsAliasMap);
163 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
168 return 2;// return error Code for processed DCS data not stored
171 AliCDBMetaData metaDataDCS;
172 metaDataDCS.SetBeamPeriod(0);
173 metaDataDCS.SetResponsible("Chiara Zampolli");
174 metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
175 AliInfo("Storing DCS Data");
176 resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
177 if (!resultDCSStore){
178 Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
183 return 3;// return error Code for processed DCS data not stored
196 //_____________________________________________________________________________
198 UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
200 // Processing data from DAQ for online calibration
202 Log("Processing DAQ delays");
204 // reading configuration map
205 TString compDelays = "kFALSE";
206 Int_t deltaStartingRun = fRun;
207 Int_t startingRun = fRun-deltaStartingRun;
208 Int_t binRangeAve = fgkBinRangeAve;
209 Double_t integralThr = fgkIntegralThr;
210 Double_t thrPar = fgkThrPar;
212 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Config");
214 Log(Form("No Configuration entry found in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
217 TMap *configMap = (TMap*)cdbEntry->GetObject();
219 Log(Form("No map found in Config entry in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
222 TObjString *strDelays = (TObjString*)configMap->GetValue("ComputingDelays");
224 compDelays = (TString) strDelays->GetString();
227 Log(Form("No ComputingDelays value found in Map from Config entry in CDB, using default value: ComputingDelays = %s",compDelays.Data()));
229 TObjString *strRun = (TObjString*)configMap->GetValue("StartingRun");
231 TString tmpstr = strRun->GetString();
232 startingRun = tmpstr.Atoi();
233 deltaStartingRun = fRun - startingRun;
236 Log(Form("No StartingRun value found in Map from Config entry in CDB, using default value: StartingRun = %i",startingRun));
238 TObjString *strBinRangeAve = (TObjString*)configMap->GetValue("BinRangeAve");
239 if (strBinRangeAve) {
240 TString tmpstr = strBinRangeAve->GetString();
241 binRangeAve = tmpstr.Atoi();
244 Log(Form("No BinRangeAve value found in Map from Config entry in CDB, using default value: BinRangeAve = %i",binRangeAve));
246 TObjString *strIntegralThr = (TObjString*)configMap->GetValue("IntegralThr");
247 if (strIntegralThr) {
248 TString tmpstr = strIntegralThr->GetString();
249 integralThr = tmpstr.Atof();
252 Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %i",integralThr));
254 TObjString *strThrPar = (TObjString*)configMap->GetValue("ThrPar");
256 TString tmpstr = strThrPar->GetString();
257 thrPar = tmpstr.Atof();
260 Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %i",thrPar));
264 if (compDelays == "kTRUE") fFDRFlag = kFALSE;
265 else fFDRFlag = kTRUE;
270 Log(Form("ComputingDelays = %s, StartingRun = %i",compDelays.Data(),startingRun));
272 fCal = new AliTOFChannelOnlineArray(fNChannels);
274 TH1::AddDirectory(0);
276 Bool_t resultDAQRef=kFALSE;
277 Bool_t resultTOFPP=kFALSE;
284 //retrieving data at Run level
285 TList* list = GetFileSources(kDAQ, "RUNLevel");
286 if (list !=0x0 && list->GetEntries()!=0)
288 AliInfo("The following sources produced files with the id RUNLevel");
290 for (Int_t jj=0;jj<list->GetEntries();jj++){
291 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
292 AliInfo(Form("found source %s", str->String().Data()));
293 // file to be stored run per run
294 TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
295 if (fileNameRun.Length()>0){
296 AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
297 daqFile = new TFile(fileNameRun.Data(),"READ");
298 h2 = (TH2S*) daqFile->Get("htof");
299 AliCDBMetaData metaDataHisto;
300 metaDataHisto.SetBeamPeriod(0);
301 metaDataHisto.SetResponsible("Chiara Zampolli");
302 metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
303 AliInfo("Storing Reference Data");
304 resultDAQRef = StoreReferenceData("Calib","DAQData",h2, &metaDataHisto);
306 Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
311 return 5;//return error code for failure in storing Ref Data
318 Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
322 return 4;//return error code for failure in retrieving Ref Data
328 Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
331 return 4;//return error code for failure in retrieving Ref Data
336 //Total files, with cumulative histos
338 TList* listTot = GetFileSources(kDAQ, "DELAYS");
339 if (listTot !=0x0 && listTot->GetEntries()!=0)
341 AliInfo("The following sources produced files with the id DELAYS");
343 for (Int_t jj=0;jj<listTot->GetEntries();jj++){
344 TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
345 AliInfo(Form("found source %s", str->String().Data()));
347 // file with summed histos, to extract calib params
348 TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
349 if (fileName.Length()>0){
350 AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
352 daqFile = new TFile(fileName.Data(),"READ");
354 h2 = (TH2S*) daqFile->Get("htoftot");
356 Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
361 return 7; //return error code for histograms not existing/junky
364 static const Int_t kSize=h2->GetNbinsX();
365 static const Int_t kNBins=h2->GetNbinsY();
366 static const Double_t kXBinmin=h2->GetYaxis()->GetBinLowEdge(1);
367 if (kSize != fNChannels){
368 Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
374 return 7; //return error code for histograms not existing/junky
376 Int_t nNotStatistics = 0; // number of channel with not enough statistics
378 /* FDR flag set. do not compute delays, use nominal cable delays */
381 Log(" Not computing delays according to flag set in Config entry in OCDB!");
382 Log(" Using nominal cable delays.");
384 AliTOFRawStream tofrs;
385 Int_t det[5], dummy, index;
386 Float_t cableTimeShift;
388 /* temporarly disable warnings */
389 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
390 AliLog::SetGlobalLogLevel(AliLog::kError);
392 /* loop over EO indeces */
393 for (Int_t iddl = 0; iddl < 72; iddl++)
394 for (Int_t islot = 3; islot <= 12; islot++)
395 for (Int_t ichain = 0; ichain < 2; ichain++)
396 for (Int_t itdc = 0; itdc < 15; itdc++)
397 for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
400 tofrs.EquipmentId2VolumeId(iddl, islot, ichain, itdc, ichannel, det);
402 /* swap det[3] and det[4] indeces (needed to obtain correct channel index) */
408 if (det[0] < 0 || det[0] > 17 ||
409 det[1] < 0 || det[1] > 4 ||
410 det[2] < 0 || det[2] > 18 ||
411 det[3] < 0 || det[3] > 1 ||
412 det[4] < 0 || det[4] > 47)
415 /* get channel index */
416 index = AliTOFGeometry::GetIndex(det);
418 /* get cable time shift */
419 cableTimeShift = AliTOFCableLengthMap::GetCableTimeShift(iddl, islot, ichain, itdc);
422 if (index<fNChannels) {
423 fCal->SetDelay(index,cableTimeShift); // delay in ns
424 AliDebug(2,Form("Setting delay %f (ns) for channel %i",cableTimeShift,index));
427 } /* loop over EO indeces */
429 /* re-enable warnings */
430 AliLog::SetGlobalLogLevel(logLevel);
434 else { // computing delays if not in FDR runs
435 for (Int_t ich=0;ich<kSize;ich++){
436 /* check whether channel has been read out during current run.
437 * if the status is bad it means it has not been read out.
438 * in this case skip channel in order to not affect the mean */
439 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad){
440 AliDebug(2,Form(" Channel %i found bad according to FEEmap, (HW status = %i), skipping from delay computing",ich, (Int_t)fStatus->GetHWStatus(ich)));
443 AliDebug(2,Form(" Channel %i found ok according to FEEmap, starting delay computing",ich));
444 TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
445 for (Int_t ibin=0;ibin<kNBins;ibin++){
446 h1->SetBinContent(ibin+1,h2->GetBinContent(ich+1,ibin+1));
448 if(h1->Integral()<integralThr) {
450 Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs
456 Float_t minContent=h1->Integral()*thrPar;
457 Int_t nbinsX = h1->GetNbinsX();
459 for (Int_t j=1; j<=nbinsX; j++){
461 h1->GetBinContent(j) +
462 h1->GetBinContent(j+1)+
463 h1->GetBinContent(j+2)+
464 h1->GetBinContent(j+3))>minContent){
470 if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
471 // Now calculate the mean over the interval.
475 for(Int_t k=0;k<binRangeAve;k++){
476 mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);
477 nent=nent+h1->GetBinContent(startBin+k);
478 sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
480 mean= mean/nent; //<x>
481 sumw2=sumw2/nent; //<x^2>
483 rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
484 if (ich<fNChannels) {
485 Float_t delay = mean*AliTOFGeometry::TdcBinWidth()*1.E-3; // delay in ns
486 fCal->SetDelay(ich,delay); // delay in ns
487 AliDebug(2,Form("Setting delay %f (ns) for channel %i",delay,ich));
493 if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics));
500 Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
504 return 6;//return error code for problems in retrieving DAQ data
510 Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
513 return 6; //return error code for problems in retrieving DAQ data
517 AliCDBMetaData metaData;
518 metaData.SetBeamPeriod(0);
519 metaData.SetResponsible("Chiara Zampolli");
520 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineArray object for online calibration - delays.");
521 AliInfo("Storing Calibration Data");
522 resultTOFPP = Store("Calib","ParOnlineDelay",fCal, &metaData,deltaStartingRun,kTRUE);
524 Log("Some problems occurred while storing online object resulting from DAQ data processing");
527 return 8;//return error code for problems in storing DAQ data
537 //_____________________________________________________________________________
539 UInt_t AliTOFPreprocessor::ProcessPulserData()
541 // Processing Pulser Run data for TOF channel status
543 Log("Processing Pulser");
546 AliError("No valid fStatus found, some errors must have occurred!!");
550 TH1::AddDirectory(0);
552 Bool_t resultPulserRef=kFALSE;
553 Bool_t resultPulser=kFALSE;
555 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
556 TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5);
557 for (Int_t ibin =1;ibin<=kSize;ibin++){
558 htofPulser->SetBinContent(ibin,-1);
566 //retrieving Pulser data
567 TList* listPulser = GetFileSources(kDAQ, "PULSER");
568 if (listPulser !=0x0 && listPulser->GetEntries()!=0)
570 AliInfo("The following sources produced files with the id PULSER");
573 for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
574 Int_t nPulserSource = 0;
575 TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
576 AliInfo(Form("found source %s", str->String().Data()));
577 // file to be stored run per run
578 TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
579 if (fileNamePulser.Length()>0){
580 // storing refernce data
581 AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data()));
582 daqFile = new TFile(fileNamePulser.Data(),"READ");
583 h1 = (TH1S*) daqFile->Get("hTOFpulser");
584 for (Int_t ibin=0;ibin<kSize;ibin++){
585 if ((h1->GetBinContent(ibin+1))!=-1){
586 if ((htofPulser->GetBinContent(ibin+1))==-1){
587 htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
590 Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin));
598 Int_t nreadNotEmpty=0;
599 for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){
601 AliDebug(3,Form(" channel %i pulser status before pulser = %i, with global status = %i",ientry,(Int_t)fStatus->GetPulserStatus(ientry),(Int_t)fStatus->GetStatus(ientry)));
602 /* check whether channel has been read out during current run.
603 * if the status is bad it means it has not been read out.
604 * in this case skip channel in order to not affect the mean */
605 if (fStatus->GetHWStatus(ientry-1) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
609 if (h1->GetBinContent(ientry)==-1) continue;
611 if (h1->GetBinContent(ientry)>0) {
613 AliDebug(2,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty));
615 mean+=h1->GetBinContent(ientry);
621 AliDebug(2,Form(" nread = %i , nreadNotEmpty = %i, mean = %f",nread,nreadNotEmpty,mean));
622 for (Int_t ich =0;ich<fNChannels;ich++){
623 if (h1->GetBinContent(ich+1)==-1) continue;
624 AliDebug(3,Form(" channel %i pulser status before pulser = %i",ich,(Int_t)fStatus->GetPulserStatus(ich)));
626 /* check whether channel has been read out during current run.
627 * if the status is bad it means it has not been read out.
628 * in this case skip channel in order to leave its status
630 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
633 if (h1->GetBinContent(ich+1)<0.05*mean){
634 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserBad); // bad status for pulser
635 AliDebug(2,Form( " channel %i pulser status after pulser = %i (bad, content = %f), with global status = %i",ich,(Int_t)fStatus->GetPulserStatus(ich),h1->GetBinContent(ich+1),(Int_t)fStatus->GetStatus(ich)));
638 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserOk); // good status for pulser
639 AliDebug(2,Form( " channel %i pulser status after pulser = %i (good), with global status = %i",ich,(Int_t)fStatus->GetPulserStatus(ich),(Int_t)fStatus->GetStatus(ich)));
644 Log("No channels read!! No action taken, keeping old status");
653 Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle ");
661 return 10;//return error code for failure in retrieving Ref Data
663 AliDebug(2,Form(" Number of channels processed during pulser run from source %i = %i",jj, nPulserSource));
665 AliDebug(2,Form(" Number of channels processed during pulser run = %i",nPulser));
670 Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle ");
677 return 10;//return error code for failure in retrieving Ref Data
682 AliCDBMetaData metaData;
683 metaData.SetBeamPeriod(0);
684 metaData.SetResponsible("Chiara Zampolli");
685 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Pulser run.");
686 AliInfo("Storing Calibration Data from Pulser Run");
687 resultPulser = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
689 Log("Some problems occurred while storing online object resulting from Pulser data processing");
696 return 11;//return error code for problems in storing Pulser data
701 AliCDBMetaData metaDataHisto;
702 metaDataHisto.SetBeamPeriod(0);
703 metaDataHisto.SetResponsible("Chiara Zampolli");
705 sprintf(comment,"This preprocessor stores the Ref data from a pulser run.");
706 metaDataHisto.SetComment(comment);
707 AliInfo("Storing Reference Data");
708 resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
709 if (!resultPulserRef){
710 Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle");
717 return 9;//return error code for failure in storing Ref Data
733 //_____________________________________________________________________________
735 UInt_t AliTOFPreprocessor::ProcessNoiseData()
738 // Processing Noise Run data for TOF channel status
740 Log("Processing Noise");
743 AliError("No valid fStatus found, some errors must have occurred!!");
747 Float_t noiseThr = 1; // setting default threshold for noise to 1 Hz
748 // reading config map
749 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
751 Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %d",noiseThr));
754 TMap *configMap = (TMap*)cdbEntry->GetObject();
756 Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %d", noiseThr));
759 TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
761 TString tmpstr = strNoiseThr->GetString();
762 noiseThr = tmpstr.Atoi();
765 Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %i",noiseThr));
773 TH1::AddDirectory(0);
775 Bool_t resultNoiseRef=kFALSE;
776 Bool_t resultNoise=kFALSE;
778 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
779 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", kSize,-0.5,kSize-0.5);
780 for (Int_t ibin =1;ibin<=kSize;ibin++){
781 htofNoise->SetBinContent(ibin,-1);
791 Int_t nNoisyChannels = 0;
792 Int_t nNotNoisyChannels = 0;
793 Int_t nChannelsFromDA = 0;
794 Int_t nMatchingWindowNullNonZero = 0;
795 Int_t nMatchingWindowNullEqualZero = 0;
797 // retrieving Noise data
798 TList* listNoise = GetFileSources(kDAQ, "NOISE");
799 if (listNoise !=0x0 && listNoise->GetEntries()!=0)
801 AliInfo("The following sources produced files with the id NOISE");
803 for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
804 Int_t nNoiseSource = 0;
805 TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
806 AliInfo(Form("found source %s", str->String().Data()));
807 // file to be stored run per run
808 TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
809 if (fileNameNoise.Length()>0){
810 // storing reference data
811 AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data()));
812 daqFile = new TFile(fileNameNoise.Data(),"READ");
813 h1 = (TH1F*) daqFile->Get("hTOFnoise");
814 for (Int_t ibin=0;ibin<kSize;ibin++){
815 if ((h1->GetBinContent(ibin+1))!=-1){
817 // checking the matching window for current channel
818 if (fMatchingWindow[ibin] == 0){
819 Log(Form("Matching window for channel %i null, but the channel was read by the LDC! skipping channel, BUT Please check!",ibin));
820 if ((h1->GetBinContent(ibin+1))!=0) nMatchingWindowNullNonZero++;
821 if ((h1->GetBinContent(ibin+1))==0) nMatchingWindowNullEqualZero++;
824 if ((htofNoise->GetBinContent(ibin+1))==-1){
825 htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)/(fMatchingWindow[ibin]*1.E-9));
826 if ((h1->GetBinContent(ibin+1))!= 0) AliDebug(2,Form("Channel = %i, Matching window = %i, Content = %f", ibin, fMatchingWindow[ibin], htofNoise->GetBinContent(ibin+1)));
829 Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin));
834 Log(Form(" Number of channels processed during noise run from source %i = %i",jj, nNoiseSource));
843 Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle ");
852 if (fMatchingWindow){
853 delete [] fMatchingWindow;
856 return 13;//return error code for failure in retrieving Ref Data
862 Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle ");
869 if (fMatchingWindow){
870 delete [] fMatchingWindow;
873 return 13;//return error code for failure in retrieving Ref Data
876 // elaborating infos to set NOISE status
877 for (Int_t ich =0;ich<fNChannels;ich++){
878 if (htofNoise->GetBinContent(ich+1)== -1) continue;
882 AliDebug(3,Form(" channel %i noise status before noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
883 //AliDebug(2,Form( " channel %i status before noise = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich)));
885 /* check whether channel has been read out during current run.
886 * if the status is bad it means it has not been read out.
887 * in this case skip channel in order to leave its status
890 if ((fStatus->GetHWStatus(ich)) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
894 if (htofNoise->GetBinContent(ich+1) >= noiseThr){
895 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseBad); // bad status for noise
896 AliDebug(3,Form( " channel %i noise status after noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
900 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseOk); // good status for noise
901 AliDebug(3,Form(" channel %i noise status after noise = %i, with global status = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich),(Int_t)fStatus->GetStatus(ich)));
906 Log(Form(" Number of channels processed by DA during noise run, independetly from TOFFEE = %i",nChannelsFromDA));
907 Log(Form(" Number of channels processed during noise run (that were ON according to TOFFEE) = %i",nNoise));
908 Log(Form(" Number of noisy channels found during noise run = %i",nNoisyChannels));
909 Log(Form(" Number of not noisy channels found during noise run = %i",nNotNoisyChannels));
910 Log(Form(" Number of channels with matching window NULL (so skipped), but Non Zero content = %i",nMatchingWindowNullNonZero));
911 Log(Form(" Number of channels with matching window NULL (so skipped), and Zero content = %i",nMatchingWindowNullEqualZero));
919 AliCDBMetaData metaData;
920 metaData.SetBeamPeriod(0);
921 metaData.SetResponsible("Chiara Zampolli");
922 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Noise run.");
923 AliInfo("Storing Calibration Data from Noise Run");
924 resultNoise = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
926 Log("Some problems occurred while storing online object resulting from Noise data processing");
933 if (fMatchingWindow){
934 delete [] fMatchingWindow;
937 return 14;//return error code for problems in storing Noise data
942 AliCDBMetaData metaDataHisto;
943 metaDataHisto.SetBeamPeriod(0);
944 metaDataHisto.SetResponsible("Chiara Zampolli");
946 sprintf(comment,"This preprocessor stores the Ref data from a noise run. ");
947 metaDataHisto.SetComment(comment);
948 AliInfo("Storing Reference Data");
949 resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
950 if (!resultNoiseRef){
951 Log("some problems occurred::No Reference Data for noise stored");
958 if (fMatchingWindow){
959 delete [] fMatchingWindow;
962 return 12;//return error code for failure in storing Ref Data
974 if (fMatchingWindow){
975 delete [] fMatchingWindow;
981 //_____________________________________________________________________________
983 UInt_t AliTOFPreprocessor::ProcessFEEData()
985 // Processing Pulser Run data for TOF channel status
986 // dummy for the time being
988 Log("Processing FEE");
990 Bool_t updateOCDB = kFALSE;
991 AliTOFFEEReader feeReader;
993 TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels);
995 /* load current TOF FEE config from DCS FXS, parse,
996 * fill current FEE histogram and set FEE status */
998 const char * nameFile = GetFile(kDCS,"TofFeeMap","");
999 AliInfo(Form("nameFile = %s",nameFile));
1000 if (nameFile == NULL) {
1003 feeReader.LoadFEEConfig(nameFile);
1004 Int_t parseFee = feeReader.ParseFEEConfig();
1005 AliDebug(2,Form("%i enabled channels found in FEE configuration",parseFee));
1006 /* load stored TOF FEE from OCDB and compare it with current FEE.
1007 * if stored FEE is different from current FEE set update flag.
1008 * if there is no stored FEE in OCDB set update flag */
1010 fMatchingWindow = new Int_t[fNChannels];
1012 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Status");
1014 /* no CDB entry found. set update flag */
1015 Log(" ************ WARNING ************");
1016 Log("No CDB Status entry found, creating a new one!");
1017 Log(" *********************************");
1018 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1022 if (cdbEntry) cdbEntry->SetOwner(kFALSE);
1023 /* CDB entry OK. loop over channels */
1024 fStatus = (AliTOFChannelOnlineStatusArray*) cdbEntry->GetObject();
1028 for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){
1029 //AliDebug(2,Form("********** channel %i",iChannel));
1030 /* compare current FEE channel status with stored one
1031 * if different set update flag and break loop */
1032 //AliDebug(2,Form( " channel %i status before FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1033 fMatchingWindow[iChannel] = feeReader.GetMatchingWindow(iChannel);
1034 if (feeReader.IsChannelEnabled(iChannel)) {
1035 hCurrentFEE.SetBinContent(iChannel + 1, 1);
1036 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWOk){
1038 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWOk);
1039 AliDebug(3,Form( " changed into enabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1043 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWBad){
1045 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWBad);
1046 AliDebug(3,Form( " changed into disabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1052 /* check whether we don't have to store reference data.
1053 * in this case we return without errors. */
1054 if (fStoreRefData) {
1055 /* store reference data */
1056 AliCDBMetaData metaDataHisto;
1057 metaDataHisto.SetBeamPeriod(0);
1058 metaDataHisto.SetResponsible("Roberto Preghenella");
1059 metaDataHisto.SetComment("This preprocessor stores the FEE Ref data of the current run.");
1060 AliInfo("Storing FEE reference data");
1061 /* store FEE reference data */
1062 if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) {
1064 Log("problems while storing FEE reference data");
1069 return 18; /* error return code for problems while storing FEE reference data */
1073 /* check whether we don't need to update OCDB.
1074 * in this case we can return without errors and
1075 * the current FEE is stored in the fStatus object. */
1077 AliInfo("TOF FEE config has not changed. Do not overwrite stored file.");
1078 return 0; /* return ok */
1081 TString runType = GetRunType();
1082 if (runType != "PHYSICS") {
1083 AliInfo(Form("Run Type = %s, waiting to store status map",GetRunType()));
1084 return 0; /* return ok */
1087 /* update the OCDB with the current FEE since even
1088 * a little difference has been detected. */
1090 AliCDBMetaData metaData;
1091 metaData.SetBeamPeriod(0);
1092 metaData.SetResponsible("Roberto Preghenella");
1093 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object from FEE data.");
1094 AliInfo("Storing Status data from current run after FEE parsing");
1095 /* store FEE data */
1096 if (!Store("Calib", "Status", fStatus, &metaData, 0, kTRUE)) {
1098 Log("problems while storing FEE data object");
1103 return 17; /* return error code for problems while storing FEE data */
1106 /* everything fine. return */
1117 //_____________________________________________________________________________
1119 UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
1125 TString runType = GetRunType();
1126 Log(Form("RunType %s",runType.Data()));
1130 /* always process FEE data */
1131 Int_t iresultFEE = ProcessFEEData();
1132 if (iresultFEE != 0)
1135 if (runType == "PULSER") {
1136 Int_t iresultPulser = ProcessPulserData();
1137 return iresultPulser;
1140 if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined
1141 Int_t iresultNoise = ProcessNoiseData();
1142 return iresultNoise;
1145 if (runType == "PHYSICS") {
1146 Int_t iresultDAQ = ProcessOnlineDelays();
1147 if (iresultDAQ != 0) {
1151 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);