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"
40 #include "AliTOFcalibHisto.h"
43 // TOF preprocessor class.
44 // It takes data from DCS and passes them to the class AliTOFDataDCS, which
45 // processes them. The result is then written to the CDB.
46 // Analogously, it takes data form DAQ (both at Run level and inclusive -
47 // of all the runs - level, processes them, and stores both Reference Data
48 // and Online Calibration files in the CDB.
49 // Processing of Pulser/Noise Run data and of TOF FEE DCS map included also.
53 // return=1 : no DCS input data Map
54 // return=2 : no DCS input data processing
55 // return=3 : no DCS processed data was stored in Ref Data
56 // return=4 : no DAQ input for Ref Data
57 // return=5 : failed to store DAQ Ref Data
58 // return=6 : failed to retrieve DAQ data for calibration
59 // return=7 : problems in processing histos in the input DAQ file
60 // return=8 : failed to store Online Delays
61 // return=9 : failed to store Reference Data for Pulser
62 // return=10: failed to retrieve Pulser data
63 // return=11: failed to store Pulser map in OCDB
64 // return=12: failed to store Reference Data for Noise
65 // return=13: failed to retrieve Noise data
66 // return=14: failed to store Noise map in OCDB
67 // return=15: failed to retrieve FEE data from FXS
68 // return=16: failed to retrieve FEE data from OCDB
69 // return=17: failed to store FEE data in OCDB
70 // return=18: failed to store FEE reference data in OCDB
71 // return=20: failed in retrieving status variable
73 ClassImp(AliTOFPreprocessor)
75 const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean
76 const Double_t AliTOFPreprocessor::fgkIntegralThr = 100; // min number of entries to perform computation of delay per channel
77 const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay
79 //_____________________________________________________________________________
81 AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
82 AliPreprocessor("TOF", shuttle),
92 AddRunType("PHYSICS");
98 //_____________________________________________________________________________
100 AliTOFPreprocessor::~AliTOFPreprocessor()
105 //______________________________________________________________________________
106 void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
109 // Creates AliTOFDataDCS object
111 AliPreprocessor::Initialize(run, startTime, endTime);
113 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
114 TTimeStamp(startTime).AsString(),
115 TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
117 fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
118 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
120 //_____________________________________________________________________________
121 Bool_t AliTOFPreprocessor::ProcessDCS(){
123 // check whether DCS should be processed or not...
125 TString runType = GetRunType();
126 Log(Form("RunType %s",runType.Data()));
128 if (runType != "PHYSICS"){
134 //_____________________________________________________________________________
136 UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap* dcsAliasMap)
138 // Fills data into a AliTOFDataDCS object
141 Log("Processing DCS DP");
142 TH1::AddDirectory(0);
144 Bool_t resultDCSMap=kFALSE;
145 Bool_t resultDCSStore=kFALSE;
149 fData->SetFDRFlag(fFDRFlag);
152 Log("No DCS map found: TOF exiting from Shuttle");
157 return 1;// return error Code for DCS input data not found
161 // The processing of the DCS input data is forwarded to AliTOFDataDCS
162 resultDCSMap=fData->ProcessData(*dcsAliasMap);
164 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
169 return 2;// return error Code for processed DCS data not stored
172 AliCDBMetaData metaDataDCS;
173 metaDataDCS.SetBeamPeriod(0);
174 metaDataDCS.SetResponsible("Chiara Zampolli");
175 metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
176 AliInfo("Storing DCS Data");
177 resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
178 if (!resultDCSStore){
179 Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
184 return 3;// return error Code for processed DCS data not stored
197 //_____________________________________________________________________________
199 UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
201 // Processing data from DAQ for online calibration
203 Bool_t updateOCDB = kFALSE;
204 Log("Processing DAQ delays");
206 // reading configuration map
207 TString compDelays = "kFALSE";
208 Int_t deltaStartingRun = fRun;
209 Int_t startingRun = fRun-deltaStartingRun;
210 Int_t binRangeAve = fgkBinRangeAve;
211 Double_t integralThr = fgkIntegralThr;
212 Double_t thrPar = fgkThrPar;
214 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Config");
216 Log(Form("No Configuration entry found in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
219 TMap *configMap = (TMap*)cdbEntry->GetObject();
221 Log(Form("No map found in Config entry in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
224 TObjString *strDelays = (TObjString*)configMap->GetValue("ComputingDelays");
226 compDelays = (TString) strDelays->GetString();
229 Log(Form("No ComputingDelays value found in Map from Config entry in CDB, using default value: ComputingDelays = %s",compDelays.Data()));
231 TObjString *strRun = (TObjString*)configMap->GetValue("StartingRun");
233 TString tmpstr = strRun->GetString();
234 startingRun = tmpstr.Atoi();
235 deltaStartingRun = fRun - startingRun;
238 Log(Form("No StartingRun value found in Map from Config entry in CDB, using default value: StartingRun = %i",startingRun));
240 TObjString *strBinRangeAve = (TObjString*)configMap->GetValue("BinRangeAve");
241 if (strBinRangeAve) {
242 TString tmpstr = strBinRangeAve->GetString();
243 binRangeAve = tmpstr.Atoi();
246 Log(Form("No BinRangeAve value found in Map from Config entry in CDB, using default value: BinRangeAve = %i",binRangeAve));
248 TObjString *strIntegralThr = (TObjString*)configMap->GetValue("IntegralThr");
249 if (strIntegralThr) {
250 TString tmpstr = strIntegralThr->GetString();
251 integralThr = tmpstr.Atof();
254 Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %i",integralThr));
256 TObjString *strThrPar = (TObjString*)configMap->GetValue("ThrPar");
258 TString tmpstr = strThrPar->GetString();
259 thrPar = tmpstr.Atof();
262 Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %i",thrPar));
266 if (compDelays == "kTRUE") fFDRFlag = kFALSE;
267 else fFDRFlag = kTRUE;
272 Log(Form("ComputingDelays = %s, StartingRun = %i",compDelays.Data(),startingRun));
274 /* init array with current calibration, if any */
275 fCal = new AliTOFChannelOnlineArray(fNChannels);
276 AliTOFChannelOnlineArray *curCal = NULL;
278 AliCDBEntry *cdbEntry2 = GetFromOCDB("Calib","ParOnlineDelay");
279 if (!cdbEntry2 || !cdbEntry2->GetObject()) {
280 /* no CDB entry found. set update flag */
281 Log(" ************ WARNING ************");
282 Log("No CDB ParOnlineDelay entry found, creating a new one!");
283 Log(" *********************************");
287 Log("Found previous ParOnlineDelay entry. Using it to init calibration");
288 curCal = (AliTOFChannelOnlineArray *)cdbEntry2->GetObject();
289 for (Int_t i = 0; i < fNChannels; i++)
290 fCal->SetDelay(i, curCal->GetDelay(i));
294 TH1::AddDirectory(0);
296 Bool_t resultDAQRef=kFALSE;
297 Bool_t resultTOFPP=kFALSE;
304 //retrieving data at Run level
305 TList* list = GetFileSources(kDAQ, "RUNLevel");
306 if (list !=0x0 && list->GetEntries()!=0)
308 AliInfo("The following sources produced files with the id RUNLevel");
310 for (Int_t jj=0;jj<list->GetEntries();jj++){
311 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
312 AliInfo(Form("found source %s", str->String().Data()));
313 // file to be stored run per run
314 TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
315 if (fileNameRun.Length()>0){
316 AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
317 daqFile = new TFile(fileNameRun.Data(),"READ");
318 h2 = (TH2S*) daqFile->Get("htof");
319 AliCDBMetaData metaDataHisto;
320 metaDataHisto.SetBeamPeriod(0);
321 metaDataHisto.SetResponsible("Chiara Zampolli");
322 metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
323 AliInfo("Storing Reference Data");
324 resultDAQRef = StoreReferenceData("Calib","DAQData",h2, &metaDataHisto);
326 Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
331 return 5;//return error code for failure in storing Ref Data
338 Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
342 return 4;//return error code for failure in retrieving Ref Data
348 Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
351 return 4;//return error code for failure in retrieving Ref Data
356 //Total files, with cumulative histos
358 TList* listTot = GetFileSources(kDAQ, "DELAYS");
359 if (listTot !=0x0 && listTot->GetEntries()!=0)
361 AliInfo("The following sources produced files with the id DELAYS");
363 for (Int_t jj=0;jj<listTot->GetEntries();jj++){
364 TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
365 AliInfo(Form("found source %s", str->String().Data()));
367 // file with summed histos, to extract calib params
368 TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
369 if (fileName.Length()>0){
370 AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
372 daqFile = new TFile(fileName.Data(),"READ");
374 h2 = (TH2S*) daqFile->Get("htoftot");
376 Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
381 return 7; //return error code for histograms not existing/junky
384 static const Int_t kSize=h2->GetNbinsX();
385 static const Int_t kNBins=h2->GetNbinsY();
386 static const Double_t kXBinmin=h2->GetYaxis()->GetBinLowEdge(1);
387 if (kSize != fNChannels){
388 Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
394 return 7; //return error code for histograms not existing/junky
396 Int_t nNotStatistics = 0; // number of channel with not enough statistics
398 /* FDR flag set. do not compute delays, use nominal cable delays */
401 Log(" Not computing delays according to flag set in Config entry in OCDB!");
402 FillWithCosmicCalibration(fCal);
404 /* check whether the new calibration is different from the previous one */
405 if (curCal) { /* well, check also whether we have a previous calibration */
406 for (Int_t i = 0; i < fNChannels; i++) {
407 if (fCal->GetDelay(i) != curCal->GetDelay(i)) {
413 else /* otherwise update OCDB */
418 else { // computing delays if not in FDR runs
420 updateOCDB = kTRUE; /* always update OCDB when computing delays */
422 for (Int_t ich=0;ich<kSize;ich++){
423 /* check whether channel has been read out during current run.
424 * if the status is bad it means it has not been read out.
425 * in this case skip channel in order to not affect the mean */
426 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad){
427 AliDebug(2,Form(" Channel %i found bad according to FEEmap, (HW status = %i), skipping from delay computing",ich, (Int_t)fStatus->GetHWStatus(ich)));
430 AliDebug(2,Form(" Channel %i found ok according to FEEmap, starting delay computing",ich));
431 TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
432 for (Int_t ibin=0;ibin<kNBins;ibin++){
433 h1->SetBinContent(ibin+1,h2->GetBinContent(ich+1,ibin+1));
435 if(h1->Integral()<integralThr) {
437 Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs
443 Float_t minContent=h1->Integral()*thrPar;
444 Int_t nbinsX = h1->GetNbinsX();
446 for (Int_t j=1; j<=nbinsX; j++){
448 h1->GetBinContent(j) +
449 h1->GetBinContent(j+1)+
450 h1->GetBinContent(j+2)+
451 h1->GetBinContent(j+3))>minContent){
457 if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
458 // Now calculate the mean over the interval.
462 for(Int_t k=0;k<binRangeAve;k++){
463 mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);
464 nent=nent+h1->GetBinContent(startBin+k);
465 sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
467 mean= mean/nent; //<x>
468 sumw2=sumw2/nent; //<x^2>
470 rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
471 if (ich<fNChannels) {
472 Float_t delay = mean*AliTOFGeometry::TdcBinWidth()*1.E-3; // delay in ns
473 fCal->SetDelay(ich,delay); // delay in ns
474 AliDebug(2,Form("Setting delay %f (ns) for channel %i",delay,ich));
480 if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics));
487 Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
491 return 6;//return error code for problems in retrieving DAQ data
497 Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
500 return 6; //return error code for problems in retrieving DAQ data
503 /* check whether we don't need to update OCDB.
504 * in this case we can return without errors and
505 * the current FEE is stored in the fStatus object. */
507 AliInfo("update OCDB flag not set. Do not overwrite stored file.");
508 return 0; /* return ok */
512 AliCDBMetaData metaData;
513 metaData.SetBeamPeriod(0);
514 metaData.SetResponsible("Chiara Zampolli");
515 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineArray object for online calibration - delays.");
516 AliInfo("Storing Calibration Data");
517 resultTOFPP = Store("Calib","ParOnlineDelay",fCal, &metaData,deltaStartingRun,kTRUE);
519 Log("Some problems occurred while storing online object resulting from DAQ data processing");
522 return 8;//return error code for problems in storing DAQ data
532 //_____________________________________________________________________________
534 UInt_t AliTOFPreprocessor::ProcessPulserData()
536 // Processing Pulser Run data for TOF channel status
538 Log("Processing Pulser");
541 AliError("No valid fStatus found, some errors must have occurred!!");
545 TH1::AddDirectory(0);
547 Bool_t resultPulserRef=kFALSE;
548 Bool_t resultPulser=kFALSE;
550 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
551 TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5);
552 for (Int_t ibin =1;ibin<=kSize;ibin++){
553 htofPulser->SetBinContent(ibin,-1);
561 //retrieving Pulser data
562 TList* listPulser = GetFileSources(kDAQ, "PULSER");
563 if (listPulser !=0x0 && listPulser->GetEntries()!=0)
565 AliInfo("The following sources produced files with the id PULSER");
568 for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
569 Int_t nPulserSource = 0;
570 TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
571 AliInfo(Form("found source %s", str->String().Data()));
572 // file to be stored run per run
573 TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
574 if (fileNamePulser.Length()>0){
575 // storing refernce data
576 AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data()));
577 daqFile = new TFile(fileNamePulser.Data(),"READ");
578 h1 = (TH1S*) daqFile->Get("hTOFpulser");
579 for (Int_t ibin=0;ibin<kSize;ibin++){
580 if ((h1->GetBinContent(ibin+1))!=-1){
581 if ((htofPulser->GetBinContent(ibin+1))==-1){
582 htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
585 Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin));
593 Int_t nreadNotEmpty=0;
594 for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){
596 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)));
597 /* check whether channel has been read out during current run.
598 * if the status is bad it means it has not been read out.
599 * in this case skip channel in order to not affect the mean */
600 if (fStatus->GetHWStatus(ientry-1) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
604 if (h1->GetBinContent(ientry)==-1) continue;
606 if (h1->GetBinContent(ientry)>0) {
608 AliDebug(2,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty));
610 mean+=h1->GetBinContent(ientry);
616 AliDebug(2,Form(" nread = %i , nreadNotEmpty = %i, mean = %f",nread,nreadNotEmpty,mean));
617 for (Int_t ich =0;ich<fNChannels;ich++){
618 if (h1->GetBinContent(ich+1)==-1) continue;
619 AliDebug(3,Form(" channel %i pulser status before pulser = %i",ich,(Int_t)fStatus->GetPulserStatus(ich)));
621 /* check whether channel has been read out during current run.
622 * if the status is bad it means it has not been read out.
623 * in this case skip channel in order to leave its status
625 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
628 if (h1->GetBinContent(ich+1)<0.05*mean){
629 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserBad); // bad status for pulser
630 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)));
633 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserOk); // good status for pulser
634 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)));
639 Log("No channels read!! No action taken, keeping old status");
648 Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle ");
656 return 10;//return error code for failure in retrieving Ref Data
658 AliDebug(2,Form(" Number of channels processed during pulser run from source %i = %i",jj, nPulserSource));
660 AliDebug(2,Form(" Number of channels processed during pulser run = %i",nPulser));
665 Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle ");
672 return 10;//return error code for failure in retrieving Ref Data
677 AliCDBMetaData metaData;
678 metaData.SetBeamPeriod(0);
679 metaData.SetResponsible("Chiara Zampolli");
680 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Pulser run.");
681 AliInfo("Storing Calibration Data from Pulser Run");
682 resultPulser = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
684 Log("Some problems occurred while storing online object resulting from Pulser data processing");
691 return 11;//return error code for problems in storing Pulser data
696 AliCDBMetaData metaDataHisto;
697 metaDataHisto.SetBeamPeriod(0);
698 metaDataHisto.SetResponsible("Chiara Zampolli");
700 sprintf(comment,"This preprocessor stores the Ref data from a pulser run.");
701 metaDataHisto.SetComment(comment);
702 AliInfo("Storing Reference Data");
703 resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
704 if (!resultPulserRef){
705 Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle");
712 return 9;//return error code for failure in storing Ref Data
728 //_____________________________________________________________________________
730 UInt_t AliTOFPreprocessor::ProcessNoiseData()
733 // Processing Noise Run data for TOF channel status
735 Log("Processing Noise");
738 AliError("No valid fStatus found, some errors must have occurred!!");
742 Float_t noiseThr = 1; // setting default threshold for noise to 1 Hz
743 // reading config map
744 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
746 Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %d",noiseThr));
749 TMap *configMap = (TMap*)cdbEntry->GetObject();
751 Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %d", noiseThr));
754 TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
756 TString tmpstr = strNoiseThr->GetString();
757 noiseThr = tmpstr.Atoi();
760 Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %i",noiseThr));
768 TH1::AddDirectory(0);
770 Bool_t resultNoiseRef=kFALSE;
771 Bool_t resultNoise=kFALSE;
773 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
774 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", kSize,-0.5,kSize-0.5);
775 for (Int_t ibin =1;ibin<=kSize;ibin++){
776 htofNoise->SetBinContent(ibin,-1);
786 Int_t nNoisyChannels = 0;
787 Int_t nNotNoisyChannels = 0;
788 Int_t nChannelsFromDA = 0;
789 Int_t nMatchingWindowNullNonZero = 0;
790 Int_t nMatchingWindowNullEqualZero = 0;
792 // retrieving Noise data
793 TList* listNoise = GetFileSources(kDAQ, "NOISE");
794 if (listNoise !=0x0 && listNoise->GetEntries()!=0)
796 AliInfo("The following sources produced files with the id NOISE");
798 for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
799 Int_t nNoiseSource = 0;
800 TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
801 AliInfo(Form("found source %s", str->String().Data()));
802 // file to be stored run per run
803 TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
804 if (fileNameNoise.Length()>0){
805 // storing reference data
806 AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data()));
807 daqFile = new TFile(fileNameNoise.Data(),"READ");
808 h1 = (TH1F*) daqFile->Get("hTOFnoise");
809 for (Int_t ibin=0;ibin<kSize;ibin++){
810 if ((h1->GetBinContent(ibin+1))!=-1){
812 // checking the matching window for current channel
813 if (fMatchingWindow[ibin] == 0){
814 Log(Form("Matching window for channel %i null, but the channel was read by the LDC! skipping channel, BUT Please check!",ibin));
815 if ((h1->GetBinContent(ibin+1))!=0) nMatchingWindowNullNonZero++;
816 if ((h1->GetBinContent(ibin+1))==0) nMatchingWindowNullEqualZero++;
819 if ((htofNoise->GetBinContent(ibin+1))==-1){
820 htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)/(fMatchingWindow[ibin]*1.E-9));
821 if ((h1->GetBinContent(ibin+1))!= 0) AliDebug(2,Form("Channel = %i, Matching window = %i, Content = %f", ibin, fMatchingWindow[ibin], htofNoise->GetBinContent(ibin+1)));
824 Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin));
829 Log(Form(" Number of channels processed during noise run from source %i = %i",jj, nNoiseSource));
838 Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle ");
847 if (fMatchingWindow){
848 delete [] fMatchingWindow;
851 return 13;//return error code for failure in retrieving Ref Data
857 Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle ");
864 if (fMatchingWindow){
865 delete [] fMatchingWindow;
868 return 13;//return error code for failure in retrieving Ref Data
871 // elaborating infos to set NOISE status
872 for (Int_t ich =0;ich<fNChannels;ich++){
873 if (htofNoise->GetBinContent(ich+1)== -1) continue;
877 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)));
878 //AliDebug(2,Form( " channel %i status before noise = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich)));
880 /* check whether channel has been read out during current run.
881 * if the status is bad it means it has not been read out.
882 * in this case skip channel in order to leave its status
885 if ((fStatus->GetHWStatus(ich)) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
889 if (htofNoise->GetBinContent(ich+1) >= noiseThr){
890 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseBad); // bad status for noise
891 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)));
895 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseOk); // good 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)));
901 Log(Form(" Number of channels processed by DA during noise run, independetly from TOFFEE = %i",nChannelsFromDA));
902 Log(Form(" Number of channels processed during noise run (that were ON according to TOFFEE) = %i",nNoise));
903 Log(Form(" Number of noisy channels found during noise run = %i",nNoisyChannels));
904 Log(Form(" Number of not noisy channels found during noise run = %i",nNotNoisyChannels));
905 Log(Form(" Number of channels with matching window NULL (so skipped), but Non Zero content = %i",nMatchingWindowNullNonZero));
906 Log(Form(" Number of channels with matching window NULL (so skipped), and Zero content = %i",nMatchingWindowNullEqualZero));
914 AliCDBMetaData metaData;
915 metaData.SetBeamPeriod(0);
916 metaData.SetResponsible("Chiara Zampolli");
917 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Noise run.");
918 AliInfo("Storing Calibration Data from Noise Run");
919 resultNoise = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
921 Log("Some problems occurred while storing online object resulting from Noise data processing");
928 if (fMatchingWindow){
929 delete [] fMatchingWindow;
932 return 14;//return error code for problems in storing Noise data
937 AliCDBMetaData metaDataHisto;
938 metaDataHisto.SetBeamPeriod(0);
939 metaDataHisto.SetResponsible("Chiara Zampolli");
941 sprintf(comment,"This preprocessor stores the Ref data from a noise run. ");
942 metaDataHisto.SetComment(comment);
943 AliInfo("Storing Reference Data");
944 resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
945 if (!resultNoiseRef){
946 Log("some problems occurred::No Reference Data for noise stored");
953 if (fMatchingWindow){
954 delete [] fMatchingWindow;
957 return 12;//return error code for failure in storing Ref Data
969 if (fMatchingWindow){
970 delete [] fMatchingWindow;
976 //_____________________________________________________________________________
978 UInt_t AliTOFPreprocessor::ProcessFEEData()
980 // Processing Pulser Run data for TOF channel status
981 // dummy for the time being
983 Log("Processing FEE");
985 Bool_t updateOCDB = kFALSE;
986 AliTOFFEEReader feeReader;
988 TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels);
990 /* load current TOF FEE config from DCS FXS, parse,
991 * fill current FEE histogram and set FEE status */
993 const char * nameFile = GetFile(kDCS,"TofFeeLightMap","");
994 AliInfo(Form("nameFile = %s",nameFile));
995 if (nameFile == NULL) {
998 feeReader.LoadFEElightConfig(nameFile);
999 Int_t parseFee = feeReader.ParseFEElightConfig();
1000 AliDebug(2,Form("%i enabled channels found in FEElight configuration",parseFee));
1001 /* load stored TOF FEE from OCDB and compare it with current FEE.
1002 * if stored FEE is different from current FEE set update flag.
1003 * if there is no stored FEE in OCDB set update flag */
1005 fMatchingWindow = new Int_t[fNChannels];
1007 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Status");
1009 /* no CDB entry found. set update flag */
1010 Log(" ************ WARNING ************");
1011 Log("No CDB Status entry found, creating a new one!");
1012 Log(" *********************************");
1013 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1017 if (cdbEntry) cdbEntry->SetOwner(kFALSE);
1018 /* CDB entry OK. loop over channels */
1019 fStatus = (AliTOFChannelOnlineStatusArray*) cdbEntry->GetObject();
1023 for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){
1024 //AliDebug(2,Form("********** channel %i",iChannel));
1025 /* compare current FEE channel status with stored one
1026 * if different set update flag and break loop */
1027 //AliDebug(2,Form( " channel %i status before FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1028 fMatchingWindow[iChannel] = feeReader.GetMatchingWindow(iChannel);
1029 if (feeReader.IsChannelEnabled(iChannel)) {
1030 hCurrentFEE.SetBinContent(iChannel + 1, 1);
1031 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWOk){
1033 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWOk);
1034 AliDebug(3,Form( " changed into enabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1038 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWBad){
1040 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWBad);
1041 AliDebug(3,Form( " changed into disabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1047 /* check whether we don't have to store reference data.
1048 * in this case we return without errors. */
1049 if (fStoreRefData) {
1050 /* store reference data */
1051 AliCDBMetaData metaDataHisto;
1052 metaDataHisto.SetBeamPeriod(0);
1053 metaDataHisto.SetResponsible("Roberto Preghenella");
1054 metaDataHisto.SetComment("This preprocessor stores the FEE Ref data of the current run.");
1055 AliInfo("Storing FEE reference data");
1056 /* store FEE reference data */
1057 if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) {
1059 Log("problems while storing FEE reference data");
1064 return 18; /* error return code for problems while storing FEE reference data */
1068 /* check whether we don't need to update OCDB.
1069 * in this case we can return without errors and
1070 * the current FEE is stored in the fStatus object. */
1072 AliInfo("TOF FEE config has not changed. Do not overwrite stored file.");
1073 return 0; /* return ok */
1076 TString runType = GetRunType();
1077 if (runType != "PHYSICS") {
1078 AliInfo(Form("Run Type = %s, waiting to store status map",GetRunType()));
1079 return 0; /* return ok */
1082 /* update the OCDB with the current FEE since even
1083 * a little difference has been detected. */
1085 AliCDBMetaData metaData;
1086 metaData.SetBeamPeriod(0);
1087 metaData.SetResponsible("Roberto Preghenella");
1088 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object from FEE data.");
1089 AliInfo("Storing Status data from current run after FEE parsing");
1090 /* store FEE data */
1091 if (!Store("Calib", "Status", fStatus, &metaData, 0, kTRUE)) {
1093 Log("problems while storing FEE data object");
1098 return 17; /* return error code for problems while storing FEE data */
1101 /* everything fine. return */
1112 //_____________________________________________________________________________
1114 UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
1120 TString runType = GetRunType();
1121 Log(Form("RunType %s",runType.Data()));
1125 /* always process FEE data */
1126 Int_t iresultFEE = ProcessFEEData();
1127 if (iresultFEE != 0)
1130 if (runType == "PULSER") {
1131 Int_t iresultPulser = ProcessPulserData();
1132 return iresultPulser;
1135 if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined
1136 Int_t iresultNoise = ProcessNoiseData();
1137 return iresultNoise;
1140 if (runType == "PHYSICS") {
1141 Int_t iresultDAQ = ProcessOnlineDelays();
1142 if (iresultDAQ != 0) {
1146 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
1156 //_____________________________________________________________________________
1159 AliTOFPreprocessor::FillWithCosmicCalibration(AliTOFChannelOnlineArray *cal)
1162 * fill with cosmic calibration
1165 Log(" Using cosmic-ray calibration.");
1167 AliTOFcalibHisto calibHisto;
1168 Log(Form(" loading calibration histograms from %s", calibHisto.GetCalibHistoFileName()));
1169 Log(Form(" loading calibration parameters from %s", calibHisto.GetCalibParFileName()));
1170 calibHisto.LoadCalibPar();
1172 /* loop over channel index */
1173 for (Int_t iIndex = 0; iIndex < fNChannels; iIndex++) {
1174 cal->SetDelay(iIndex, calibHisto.GetFullCorrection(iIndex));
1179 //_____________________________________________________________________________
1182 AliTOFPreprocessor::FillWithCableLengthMap(AliTOFChannelOnlineArray *cal)
1185 * fill with cosmic calibration
1188 Log(" Using cable-length map.");
1189 AliTOFRawStream tofrs;
1190 Int_t det[5], dummy, index;
1191 Float_t cableTimeShift;
1193 /* temporarly disable warnings */
1194 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
1195 AliLog::SetGlobalLogLevel(AliLog::kError);
1197 /* loop over EO indeces */
1198 for (Int_t iddl = 0; iddl < 72; iddl++)
1199 for (Int_t islot = 3; islot <= 12; islot++)
1200 for (Int_t ichain = 0; ichain < 2; ichain++)
1201 for (Int_t itdc = 0; itdc < 15; itdc++)
1202 for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
1205 tofrs.EquipmentId2VolumeId(iddl, islot, ichain, itdc, ichannel, det);
1207 /* swap det[3] and det[4] indeces (needed to obtain correct channel index) */
1212 /* check DO index */
1213 if (det[0] < 0 || det[0] > 17 ||
1214 det[1] < 0 || det[1] > 4 ||
1215 det[2] < 0 || det[2] > 18 ||
1216 det[3] < 0 || det[3] > 1 ||
1217 det[4] < 0 || det[4] > 47)
1220 /* get channel index */
1221 index = AliTOFGeometry::GetIndex(det);
1223 /* get cable time shift */
1224 cableTimeShift = AliTOFCableLengthMap::GetCableTimeShift(iddl, islot, ichain, itdc);
1227 if (index<fNChannels) {
1228 cal->SetDelay(index,cableTimeShift); // delay in ns
1229 AliDebug(2,Form("Setting delay %f (ns) for channel %i",cableTimeShift,index));
1232 } /* loop over EO indeces */
1234 /* re-enable warnings */
1235 AliLog::SetGlobalLogLevel(logLevel);