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 **************************************************************************/
19 //#include <Riostream.h>
26 #include <TObjArray.h>
27 #include <TObjString.h>
28 #include <TTimeStamp.h>
30 #include "AliCDBMetaData.h"
31 #include "AliCDBEntry.h"
33 #include "AliTOFChannelOnlineArray.h"
34 #include "AliTOFChannelOnlineStatusArray.h"
35 #include "AliTOFDataDCS.h"
36 #include "AliTOFGeometry.h"
37 #include "AliTOFPreprocessor.h"
38 #include "AliTOFFEEReader.h"
39 #include "AliTOFRawStream.h"
40 #include "AliTOFCableLengthMap.h"
41 #include "AliTOFcalibHisto.h"
44 // TOF preprocessor class.
45 // It takes data from DCS and passes them to the class AliTOFDataDCS, which
46 // processes them. The result is then written to the CDB.
47 // Analogously, it takes data form DAQ (both at Run level and inclusive -
48 // of all the runs - level, processes them, and stores both Reference Data
49 // and Online Calibration files in the CDB.
50 // Processing of Pulser/Noise Run data and of TOF FEE DCS map included also.
54 // return=1 : no DCS input data Map
55 // return=2 : no DCS input data processing
56 // return=3 : no DCS processed data was stored in Ref Data
57 // return=4 : no DAQ input for Ref Data
58 // return=5 : failed to store DAQ Ref Data
59 // return=6 : failed to retrieve DAQ data for calibration
60 // return=7 : problems in processing histos in the input DAQ file
61 // return=8 : failed to store Online Delays
62 // return=9 : failed to store Reference Data for Pulser
63 // return=10: failed to retrieve Pulser data
64 // return=11: failed to store Pulser map in OCDB
65 // return=12: failed to store Reference Data for Noise
66 // return=13: failed to retrieve Noise data
67 // return=14: failed to store Noise map in OCDB
68 // return=15: failed to retrieve FEE data from FXS
69 // return=16: failed to retrieve FEE data from OCDB
70 // return=17: failed to store FEE data in OCDB
71 // return=18: failed to store FEE reference data in OCDB
72 // return=20: failed in retrieving status variable
74 ClassImp(AliTOFPreprocessor)
76 const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean
77 const Double_t AliTOFPreprocessor::fgkIntegralThr = 100; // min number of entries to perform computation of delay per channel
78 const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay
80 //_____________________________________________________________________________
82 AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
83 AliPreprocessor("TOF", shuttle),
94 AddRunType("PHYSICS");
100 //_____________________________________________________________________________
102 AliTOFPreprocessor::~AliTOFPreprocessor()
107 //______________________________________________________________________________
108 void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
111 // Creates AliTOFDataDCS object
113 AliPreprocessor::Initialize(run, startTime, endTime);
115 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
116 TTimeStamp(startTime).AsString(),
117 TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
119 fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
120 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
122 //_____________________________________________________________________________
123 Bool_t AliTOFPreprocessor::ProcessDCS(){
125 // check whether DCS should be processed or not...
127 TString runType = GetRunType();
128 Log(Form("RunType %s",runType.Data()));
130 if (runType != "PHYSICS"){
136 //_____________________________________________________________________________
138 UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap* dcsAliasMap)
140 // Fills data into a AliTOFDataDCS object
143 Log("Processing DCS DP");
144 TH1::AddDirectory(0);
146 Bool_t resultDCSMap=kFALSE;
147 Bool_t resultDCSStore=kFALSE;
151 fData->SetFDRFlag(fFDRFlag);
154 Log("No DCS map found: TOF exiting from Shuttle");
159 return 1;// return error Code for DCS input data not found
163 // The processing of the DCS input data is forwarded to AliTOFDataDCS
164 resultDCSMap=fData->ProcessData(*dcsAliasMap);
166 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
171 return 2;// return error Code for processed DCS data not stored
174 AliCDBMetaData metaDataDCS;
175 metaDataDCS.SetBeamPeriod(0);
176 metaDataDCS.SetResponsible("Chiara Zampolli");
177 metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
178 AliInfo("Storing DCS Data");
179 resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
180 if (!resultDCSStore){
181 Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
186 return 3;// return error Code for processed DCS data not stored
199 //_____________________________________________________________________________
201 UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
203 // Processing data from DAQ for online calibration
205 Bool_t updateOCDB = kFALSE;
206 Log("Processing DAQ delays");
208 // reading configuration map
209 TString compDelays = "kFALSE";
210 Int_t deltaStartingRun = fRun;
211 Int_t startingRun = fRun-deltaStartingRun;
212 Int_t binRangeAve = fgkBinRangeAve;
213 Double_t integralThr = fgkIntegralThr;
214 Double_t thrPar = fgkThrPar;
216 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Config");
218 Log(Form("No Configuration entry found in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
221 TMap *configMap = (TMap*)cdbEntry->GetObject();
223 Log(Form("No map found in Config entry in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
226 TObjString *strDelays = (TObjString*)configMap->GetValue("ComputingDelays");
228 compDelays = (TString) strDelays->GetString();
231 Log(Form("No ComputingDelays value found in Map from Config entry in CDB, using default value: ComputingDelays = %s",compDelays.Data()));
233 TObjString *strRun = (TObjString*)configMap->GetValue("StartingRun");
235 TString tmpstr = strRun->GetString();
236 startingRun = tmpstr.Atoi();
237 deltaStartingRun = fRun - startingRun;
240 Log(Form("No StartingRun value found in Map from Config entry in CDB, using default value: StartingRun = %i",startingRun));
242 TObjString *strBinRangeAve = (TObjString*)configMap->GetValue("BinRangeAve");
243 if (strBinRangeAve) {
244 TString tmpstr = strBinRangeAve->GetString();
245 binRangeAve = tmpstr.Atoi();
248 Log(Form("No BinRangeAve value found in Map from Config entry in CDB, using default value: BinRangeAve = %i",binRangeAve));
250 TObjString *strIntegralThr = (TObjString*)configMap->GetValue("IntegralThr");
251 if (strIntegralThr) {
252 TString tmpstr = strIntegralThr->GetString();
253 integralThr = tmpstr.Atof();
256 Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %i",integralThr));
258 TObjString *strThrPar = (TObjString*)configMap->GetValue("ThrPar");
260 TString tmpstr = strThrPar->GetString();
261 thrPar = tmpstr.Atof();
264 Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %i",thrPar));
268 if (compDelays == "kTRUE") fFDRFlag = kFALSE;
269 else fFDRFlag = kTRUE;
274 Log(Form("ComputingDelays = %s, StartingRun = %i",compDelays.Data(),startingRun));
276 /* init array with current calibration, if any */
277 fCal = new AliTOFChannelOnlineArray(fNChannels);
278 AliTOFChannelOnlineArray *curCal = NULL;
280 AliCDBEntry *cdbEntry2 = GetFromOCDB("Calib","ParOnlineDelay");
281 if (!cdbEntry2 || !cdbEntry2->GetObject()) {
282 /* no CDB entry found. set update flag */
283 Log(" ************ WARNING ************");
284 Log("No CDB ParOnlineDelay entry found, creating a new one!");
285 Log(" *********************************");
289 Log("Found previous ParOnlineDelay entry. Using it to init calibration");
290 curCal = (AliTOFChannelOnlineArray *)cdbEntry2->GetObject();
291 for (Int_t i = 0; i < fNChannels; i++)
292 fCal->SetDelay(i, curCal->GetDelay(i));
296 TH1::AddDirectory(0);
298 Bool_t resultDAQRef=kFALSE;
299 Bool_t resultTOFPP=kFALSE;
306 //retrieving data at Run level
307 TList* list = GetFileSources(kDAQ, "RUNLevel");
308 if (list !=0x0 && list->GetEntries()!=0)
310 AliInfo("The following sources produced files with the id RUNLevel");
312 for (Int_t jj=0;jj<list->GetEntries();jj++){
313 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
314 AliInfo(Form("found source %s", str->String().Data()));
315 // file to be stored run per run
316 TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
317 if (fileNameRun.Length()>0){
318 AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
319 daqFile = new TFile(fileNameRun.Data(),"READ");
320 h2 = (TH2S*) daqFile->Get("htof");
321 AliCDBMetaData metaDataHisto;
322 metaDataHisto.SetBeamPeriod(0);
323 metaDataHisto.SetResponsible("Chiara Zampolli");
324 metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
325 AliInfo("Storing Reference Data");
326 resultDAQRef = StoreReferenceData("Calib","DAQData",h2, &metaDataHisto);
328 Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
333 return 5;//return error code for failure in storing Ref Data
340 Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
344 return 4;//return error code for failure in retrieving Ref Data
350 Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
353 return 4;//return error code for failure in retrieving Ref Data
358 //Total files, with cumulative histos
360 TList* listTot = GetFileSources(kDAQ, "DELAYS");
361 if (listTot !=0x0 && listTot->GetEntries()!=0)
363 AliInfo("The following sources produced files with the id DELAYS");
365 for (Int_t jj=0;jj<listTot->GetEntries();jj++){
366 TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
367 AliInfo(Form("found source %s", str->String().Data()));
369 // file with summed histos, to extract calib params
370 TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
371 if (fileName.Length()>0){
372 AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
374 daqFile = new TFile(fileName.Data(),"READ");
376 h2 = (TH2S*) daqFile->Get("htoftot");
378 Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
383 return 7; //return error code for histograms not existing/junky
386 static const Int_t kSize=h2->GetNbinsX();
387 static const Int_t kNBins=h2->GetNbinsY();
388 static const Double_t kXBinmin=h2->GetYaxis()->GetBinLowEdge(1);
389 if (kSize != fNChannels){
390 Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
396 return 7; //return error code for histograms not existing/junky
398 Int_t nNotStatistics = 0; // number of channel with not enough statistics
400 /* FDR flag set. do not compute delays, use nominal cable delays */
403 Log(" Not computing delays according to flag set in Config entry in OCDB!");
404 FillWithCosmicCalibration(fCal);
406 /* check whether the new calibration is different from the previous one */
407 if (curCal) { /* well, check also whether we have a previous calibration */
408 for (Int_t i = 0; i < fNChannels; i++) {
409 if (fCal->GetDelay(i) != curCal->GetDelay(i)) {
415 else /* otherwise update OCDB */
420 else { // computing delays if not in FDR runs
422 updateOCDB = kTRUE; /* always update OCDB when computing delays */
424 for (Int_t ich=0;ich<kSize;ich++){
425 /* check whether channel has been read out during current run.
426 * if the status is bad it means it has not been read out.
427 * in this case skip channel in order to not affect the mean */
428 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad){
429 AliDebug(2,Form(" Channel %i found bad according to FEEmap, (HW status = %i), skipping from delay computing",ich, (Int_t)fStatus->GetHWStatus(ich)));
432 AliDebug(2,Form(" Channel %i found ok according to FEEmap, starting delay computing",ich));
433 TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
434 for (Int_t ibin=0;ibin<kNBins;ibin++){
435 h1->SetBinContent(ibin+1,h2->GetBinContent(ich+1,ibin+1));
437 if(h1->Integral()<integralThr) {
439 Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs
445 Float_t minContent=h1->Integral()*thrPar;
446 Int_t nbinsX = h1->GetNbinsX();
448 for (Int_t j=1; j<=nbinsX; j++){
450 h1->GetBinContent(j) +
451 h1->GetBinContent(j+1)+
452 h1->GetBinContent(j+2)+
453 h1->GetBinContent(j+3))>minContent){
459 if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
460 // Now calculate the mean over the interval.
464 for(Int_t k=0;k<binRangeAve;k++){
465 mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);
466 nent=nent+h1->GetBinContent(startBin+k);
467 sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
469 mean= mean/nent; //<x>
470 sumw2=sumw2/nent; //<x^2>
472 rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
473 if (ich<fNChannels) {
474 Float_t delay = mean*AliTOFGeometry::TdcBinWidth()*1.E-3; // delay in ns
475 fCal->SetDelay(ich,delay); // delay in ns
476 AliDebug(2,Form("Setting delay %f (ns) for channel %i",delay,ich));
482 if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics));
489 Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
493 return 6;//return error code for problems in retrieving DAQ data
499 Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
502 return 6; //return error code for problems in retrieving DAQ data
505 /* check whether we don't need to update OCDB.
506 * in this case we can return without errors and
507 * the current FEE is stored in the fStatus object. */
509 AliInfo("update OCDB flag not set. Do not overwrite stored file.");
510 return 0; /* return ok */
514 AliCDBMetaData metaData;
515 metaData.SetBeamPeriod(0);
516 metaData.SetResponsible("Chiara Zampolli");
517 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineArray object for online calibration - delays.");
518 AliInfo("Storing Calibration Data");
519 resultTOFPP = Store("Calib","ParOnlineDelay",fCal, &metaData,deltaStartingRun,kTRUE);
521 Log("Some problems occurred while storing online object resulting from DAQ data processing");
524 return 8;//return error code for problems in storing DAQ data
534 //_____________________________________________________________________________
536 UInt_t AliTOFPreprocessor::ProcessPulserData()
538 // Processing Pulser Run data for TOF channel status
540 Log("Processing Pulser");
543 AliError("No valid fStatus found, some errors must have occurred!!");
547 TH1::AddDirectory(0);
549 Bool_t resultPulserRef=kFALSE;
550 Bool_t resultPulser=kFALSE;
552 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
553 TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5);
554 for (Int_t ibin =1;ibin<=kSize;ibin++){
555 htofPulser->SetBinContent(ibin,-1);
563 //retrieving Pulser data
564 TList* listPulser = GetFileSources(kDAQ, "PULSER");
565 if (listPulser !=0x0 && listPulser->GetEntries()!=0)
567 AliInfo("The following sources produced files with the id PULSER");
570 for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
571 Int_t nPulserSource = 0;
572 TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
573 AliInfo(Form("found source %s", str->String().Data()));
574 // file to be stored run per run
575 TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
576 if (fileNamePulser.Length()>0){
577 // storing refernce data
578 AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data()));
579 daqFile = new TFile(fileNamePulser.Data(),"READ");
580 h1 = (TH1S*) daqFile->Get("hTOFpulser");
581 for (Int_t ibin=0;ibin<kSize;ibin++){
582 if ((h1->GetBinContent(ibin+1))!=-1){
583 if ((htofPulser->GetBinContent(ibin+1))==-1){
584 htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
587 Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin));
595 Int_t nreadNotEmpty=0;
596 for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){
598 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)));
599 /* check whether channel has been read out during current run.
600 * if the status is bad it means it has not been read out.
601 * in this case skip channel in order to not affect the mean */
602 if (fStatus->GetHWStatus(ientry-1) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
606 if (h1->GetBinContent(ientry)==-1) continue;
608 if (h1->GetBinContent(ientry)>0) {
610 AliDebug(2,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty));
612 mean+=h1->GetBinContent(ientry);
618 AliDebug(2,Form(" nread = %i , nreadNotEmpty = %i, mean = %f",nread,nreadNotEmpty,mean));
619 for (Int_t ich =0;ich<fNChannels;ich++){
620 if (h1->GetBinContent(ich+1)==-1) continue;
621 AliDebug(3,Form(" channel %i pulser status before pulser = %i",ich,(Int_t)fStatus->GetPulserStatus(ich)));
623 /* check whether channel has been read out during current run.
624 * if the status is bad it means it has not been read out.
625 * in this case skip channel in order to leave its status
627 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
630 if (h1->GetBinContent(ich+1)<0.05*mean){
631 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserBad); // bad status for pulser
632 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)));
635 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserOk); // good status for pulser
636 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)));
641 Log("No channels read!! No action taken, keeping old status");
650 Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle ");
658 return 10;//return error code for failure in retrieving Ref Data
660 AliDebug(2,Form(" Number of channels processed during pulser run from source %i = %i",jj, nPulserSource));
662 AliDebug(2,Form(" Number of channels processed during pulser run = %i",nPulser));
667 Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle ");
674 return 10;//return error code for failure in retrieving Ref Data
679 AliCDBMetaData metaData;
680 metaData.SetBeamPeriod(0);
681 metaData.SetResponsible("Chiara Zampolli");
682 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Pulser run.");
683 AliInfo("Storing Calibration Data from Pulser Run");
684 resultPulser = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
686 Log("Some problems occurred while storing online object resulting from Pulser data processing");
693 return 11;//return error code for problems in storing Pulser data
698 AliCDBMetaData metaDataHisto;
699 metaDataHisto.SetBeamPeriod(0);
700 metaDataHisto.SetResponsible("Chiara Zampolli");
702 sprintf(comment,"This preprocessor stores the Ref data from a pulser run.");
703 metaDataHisto.SetComment(comment);
704 AliInfo("Storing Reference Data");
705 resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
706 if (!resultPulserRef){
707 Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle");
714 return 9;//return error code for failure in storing Ref Data
730 //_____________________________________________________________________________
732 UInt_t AliTOFPreprocessor::ProcessNoiseData()
735 // Processing Noise Run data for TOF channel status
737 Log("Processing Noise");
740 AliError("No valid fStatus found, some errors must have occurred!!");
744 Float_t noiseThr = 1; // setting default threshold for noise to 1 Hz
745 // reading config map
746 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
748 Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %d",noiseThr));
751 TMap *configMap = (TMap*)cdbEntry->GetObject();
753 Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %d", noiseThr));
756 TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
758 TString tmpstr = strNoiseThr->GetString();
759 noiseThr = tmpstr.Atoi();
762 Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %i",noiseThr));
770 TH1::AddDirectory(0);
772 Bool_t resultNoiseRef=kFALSE;
773 Bool_t resultNoise=kFALSE;
775 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
776 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", kSize,-0.5,kSize-0.5);
777 for (Int_t ibin =1;ibin<=kSize;ibin++){
778 htofNoise->SetBinContent(ibin,-1);
788 Int_t nNoisyChannels = 0;
789 Int_t nNotNoisyChannels = 0;
790 Int_t nChannelsFromDA = 0;
791 Int_t nMatchingWindowNullNonZero = 0;
792 Int_t nMatchingWindowNullEqualZero = 0;
794 // retrieving Noise data
795 TList* listNoise = GetFileSources(kDAQ, "NOISE");
796 if (listNoise !=0x0 && listNoise->GetEntries()!=0)
798 AliInfo("The following sources produced files with the id NOISE");
800 for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
801 Int_t nNoiseSource = 0;
802 TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
803 AliInfo(Form("found source %s", str->String().Data()));
804 // file to be stored run per run
805 TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
806 if (fileNameNoise.Length()>0){
807 // storing reference data
808 AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data()));
809 daqFile = new TFile(fileNameNoise.Data(),"READ");
810 h1 = (TH1F*) daqFile->Get("hTOFnoise");
811 for (Int_t ibin=0;ibin<kSize;ibin++){
812 if ((h1->GetBinContent(ibin+1))!=-1){
814 // checking the matching window for current channel
815 if (fMatchingWindow[ibin] == 0){
816 Log(Form("Matching window for channel %i null, but the channel was read by the LDC! skipping channel, BUT Please check!",ibin));
817 if ((h1->GetBinContent(ibin+1))!=0) nMatchingWindowNullNonZero++;
818 if ((h1->GetBinContent(ibin+1))==0) nMatchingWindowNullEqualZero++;
821 if ((htofNoise->GetBinContent(ibin+1))==-1){
822 htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)/(fMatchingWindow[ibin]*1.E-9));
823 if ((h1->GetBinContent(ibin+1))!= 0) AliDebug(2,Form("Channel = %i, Matching window = %i, Content = %f", ibin, fMatchingWindow[ibin], htofNoise->GetBinContent(ibin+1)));
826 Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin));
831 Log(Form(" Number of channels processed during noise run from source %i = %i",jj, nNoiseSource));
840 Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle ");
849 if (fMatchingWindow){
850 delete [] fMatchingWindow;
853 return 13;//return error code for failure in retrieving Ref Data
859 Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle ");
866 if (fMatchingWindow){
867 delete [] fMatchingWindow;
870 return 13;//return error code for failure in retrieving Ref Data
873 // elaborating infos to set NOISE status
874 for (Int_t ich =0;ich<fNChannels;ich++){
875 if (htofNoise->GetBinContent(ich+1)== -1) continue;
879 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)));
880 //AliDebug(2,Form( " channel %i status before noise = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich)));
882 /* check whether channel has been read out during current run.
883 * if the status is bad it means it has not been read out.
884 * in this case skip channel in order to leave its status
887 if ((fStatus->GetHWStatus(ich)) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
891 if (htofNoise->GetBinContent(ich+1) >= noiseThr){
892 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseBad); // bad status for noise
893 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)));
897 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseOk); // good status for noise
898 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)));
903 Log(Form(" Number of channels processed by DA during noise run, independetly from TOFFEE = %i",nChannelsFromDA));
904 Log(Form(" Number of channels processed during noise run (that were ON according to TOFFEE) = %i",nNoise));
905 Log(Form(" Number of noisy channels found during noise run = %i",nNoisyChannels));
906 Log(Form(" Number of not noisy channels found during noise run = %i",nNotNoisyChannels));
907 Log(Form(" Number of channels with matching window NULL (so skipped), but Non Zero content = %i",nMatchingWindowNullNonZero));
908 Log(Form(" Number of channels with matching window NULL (so skipped), and Zero content = %i",nMatchingWindowNullEqualZero));
916 AliCDBMetaData metaData;
917 metaData.SetBeamPeriod(0);
918 metaData.SetResponsible("Chiara Zampolli");
919 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Noise run.");
920 AliInfo("Storing Calibration Data from Noise Run");
921 resultNoise = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
923 Log("Some problems occurred while storing online object resulting from Noise data processing");
930 if (fMatchingWindow){
931 delete [] fMatchingWindow;
934 return 14;//return error code for problems in storing Noise data
939 AliCDBMetaData metaDataHisto;
940 metaDataHisto.SetBeamPeriod(0);
941 metaDataHisto.SetResponsible("Chiara Zampolli");
943 sprintf(comment,"This preprocessor stores the Ref data from a noise run. ");
944 metaDataHisto.SetComment(comment);
945 AliInfo("Storing Reference Data");
946 resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
947 if (!resultNoiseRef){
948 Log("some problems occurred::No Reference Data for noise stored");
955 if (fMatchingWindow){
956 delete [] fMatchingWindow;
959 return 12;//return error code for failure in storing Ref Data
971 if (fMatchingWindow){
972 delete [] fMatchingWindow;
978 //_____________________________________________________________________________
980 UInt_t AliTOFPreprocessor::ProcessFEEData()
982 // Processing Pulser Run data for TOF channel status
983 // dummy for the time being
985 Log("Processing FEE");
987 Bool_t updateOCDB = kFALSE;
988 AliTOFFEEReader feeReader;
990 TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels);
992 /* load current TOF FEE config from DCS FXS, parse,
993 * fill current FEE histogram and set FEE status */
995 const char * nameFile = GetFile(kDCS,"TofFeeLightMap","");
996 AliInfo(Form("nameFile = %s",nameFile));
997 if (nameFile == NULL) {
1000 feeReader.LoadFEElightConfig(nameFile);
1001 Int_t parseFee = feeReader.ParseFEElightConfig();
1002 AliDebug(2,Form("%i enabled channels found in FEElight configuration",parseFee));
1003 /* load stored TOF FEE from OCDB and compare it with current FEE.
1004 * if stored FEE is different from current FEE set update flag.
1005 * if there is no stored FEE in OCDB set update flag */
1007 fMatchingWindow = new Int_t[fNChannels];
1008 fLatencyWindow = new Int_t[fNChannels];
1010 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Status");
1012 /* no CDB entry found. set update flag */
1013 Log(" ************ WARNING ************");
1014 Log("No CDB Status entry found, creating a new one!");
1015 Log(" *********************************");
1016 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1020 if (cdbEntry) cdbEntry->SetOwner(kFALSE);
1021 /* CDB entry OK. loop over channels */
1022 fStatus = (AliTOFChannelOnlineStatusArray*) cdbEntry->GetObject();
1026 for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){
1027 //AliDebug(2,Form("********** channel %i",iChannel));
1028 /* compare current FEE channel status with stored one
1029 * if different set update flag and break loop */
1030 //AliDebug(2,Form( " channel %i status before FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1031 fMatchingWindow[iChannel] = feeReader.GetMatchingWindow(iChannel);
1032 fLatencyWindow[iChannel] = feeReader.GetLatencyWindow(iChannel);
1033 if (feeReader.IsChannelEnabled(iChannel)) {
1034 hCurrentFEE.SetBinContent(iChannel + 1, 1);
1035 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWOk){
1037 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWOk);
1038 AliDebug(3,Form( " changed into enabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1040 if (fStatus->GetLatencyWindow(iChannel)!=fLatencyWindow[iChannel]){
1042 fStatus->SetLatencyWindow(iChannel,fLatencyWindow[iChannel]);
1043 AliDebug(3,Form( " changed latency window: channel %i latency window after FEE = %i",iChannel,fStatus->GetLatencyWindow(iChannel)));
1047 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWBad){
1049 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWBad);
1050 AliDebug(3,Form( " changed into disabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1056 /* check whether we don't have to store reference data.
1057 * in this case we return without errors. */
1058 if (fStoreRefData) {
1059 /* store reference data */
1060 AliCDBMetaData metaDataHisto;
1061 metaDataHisto.SetBeamPeriod(0);
1062 metaDataHisto.SetResponsible("Roberto Preghenella");
1063 metaDataHisto.SetComment("This preprocessor stores the FEE Ref data of the current run.");
1064 AliInfo("Storing FEE reference data");
1065 /* store FEE reference data */
1066 if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) {
1068 Log("problems while storing FEE reference data");
1073 return 18; /* error return code for problems while storing FEE reference data */
1077 /* check whether we don't need to update OCDB.
1078 * in this case we can return without errors and
1079 * the current FEE is stored in the fStatus object. */
1081 AliInfo("TOF FEE config has not changed. Do not overwrite stored file.");
1082 return 0; /* return ok */
1085 TString runType = GetRunType();
1086 if (runType != "PHYSICS") {
1087 AliInfo(Form("Run Type = %s, waiting to store status map",GetRunType()));
1088 return 0; /* return ok */
1091 /* update the OCDB with the current FEE since even
1092 * a little difference has been detected. */
1094 AliCDBMetaData metaData;
1095 metaData.SetBeamPeriod(0);
1096 metaData.SetResponsible("Roberto Preghenella");
1097 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object from FEE data.");
1098 AliInfo("Storing Status data from current run after FEE parsing");
1099 /* store FEE data */
1100 if (!Store("Calib", "Status", fStatus, &metaData, 0, kTRUE)) {
1102 Log("problems while storing FEE data object");
1107 return 17; /* return error code for problems while storing FEE data */
1110 /* everything fine. return */
1121 //_____________________________________________________________________________
1123 UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
1129 TString runType = GetRunType();
1130 Log(Form("RunType %s",runType.Data()));
1134 /* always process FEE data */
1135 Int_t iresultFEE = ProcessFEEData();
1136 if (iresultFEE != 0)
1139 if (runType == "PULSER") {
1140 Int_t iresultPulser = ProcessPulserData();
1141 return iresultPulser;
1144 if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined
1145 Int_t iresultNoise = ProcessNoiseData();
1146 return iresultNoise;
1149 if (runType == "PHYSICS") {
1150 Int_t iresultDAQ = ProcessOnlineDelays();
1151 if (iresultDAQ != 0) {
1155 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
1165 //_____________________________________________________________________________
1168 AliTOFPreprocessor::FillWithCosmicCalibration(AliTOFChannelOnlineArray *cal)
1171 * fill with cosmic calibration
1174 Log(" Using cosmic-ray calibration.");
1176 AliTOFcalibHisto calibHisto;
1177 calibHisto.SetFullCorrectionFlag(AliTOFcalibHisto::kTimeSlewingCorr, kFALSE);
1178 Log(Form(" loading calibration histograms from %s", calibHisto.GetCalibHistoFileName()));
1179 Log(Form(" loading calibration parameters from %s", calibHisto.GetCalibParFileName()));
1180 calibHisto.LoadCalibPar();
1182 /* loop over channel index */
1183 for (Int_t iIndex = 0; iIndex < fNChannels; iIndex++) {
1184 cal->SetDelay(iIndex, calibHisto.GetFullCorrection(iIndex));
1189 //_____________________________________________________________________________
1192 AliTOFPreprocessor::FillWithCableLengthMap(AliTOFChannelOnlineArray *cal)
1195 * fill with cosmic calibration
1198 Log(" Using cable-length map.");
1199 AliTOFRawStream tofrs;
1200 Int_t det[5], dummy, index;
1201 Float_t cableTimeShift;
1203 /* temporarly disable warnings */
1204 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
1205 AliLog::SetGlobalLogLevel(AliLog::kError);
1207 /* loop over EO indeces */
1208 for (Int_t iddl = 0; iddl < 72; iddl++)
1209 for (Int_t islot = 3; islot <= 12; islot++)
1210 for (Int_t ichain = 0; ichain < 2; ichain++)
1211 for (Int_t itdc = 0; itdc < 15; itdc++)
1212 for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
1215 tofrs.EquipmentId2VolumeId(iddl, islot, ichain, itdc, ichannel, det);
1217 /* swap det[3] and det[4] indeces (needed to obtain correct channel index) */
1222 /* check DO index */
1223 if (det[0] < 0 || det[0] > 17 ||
1224 det[1] < 0 || det[1] > 4 ||
1225 det[2] < 0 || det[2] > 18 ||
1226 det[3] < 0 || det[3] > 1 ||
1227 det[4] < 0 || det[4] > 47)
1230 /* get channel index */
1231 index = AliTOFGeometry::GetIndex(det);
1233 /* get cable time shift */
1234 cableTimeShift = AliTOFCableLengthMap::GetCableTimeShift(iddl, islot, ichain, itdc);
1237 if (index<fNChannels) {
1238 cal->SetDelay(index,cableTimeShift); // delay in ns
1239 AliDebug(2,Form("Setting delay %f (ns) for channel %i",cableTimeShift,index));
1242 } /* loop over EO indeces */
1244 /* re-enable warnings */
1245 AliLog::SetGlobalLogLevel(logLevel);