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>
28 #include <TObjArray.h>
29 #include <TObjString.h>
30 #include <TTimeStamp.h>
32 #include "AliCDBMetaData.h"
33 #include "AliCDBEntry.h"
35 #include "AliTOFChannelOnlineArray.h"
36 #include "AliTOFChannelOnlineStatusArray.h"
37 #include "AliTOFDataDCS.h"
38 #include "AliTOFLvHvDataPoints.h"
39 #include "AliTOFGeometry.h"
40 #include "AliTOFPreprocessor.h"
41 #include "AliTOFFEEReader.h"
42 #include "AliTOFRawStream.h"
43 #include "AliTOFCableLengthMap.h"
44 #include "AliTOFcalibHisto.h"
45 #include "AliTOFFEEDump.h"
48 // TOF preprocessor class.
49 // It takes data from DCS and passes them to the class AliTOFDataDCS, which
50 // processes them. The result is then written to the CDB.
51 // Analogously, it takes data form DAQ (both at Run level and inclusive -
52 // of all the runs - level, processes them, and stores both Reference Data
53 // and Online Calibration files in the CDB.
54 // Processing of Pulser/Noise Run data and of TOF FEE DCS map included also.
58 // return=1 : no DCS input data Map
59 // return=2 : no DCS input data processing
60 // return=3 : no DCS processed data was stored in Ref Data
61 // return=4 : no DAQ input for Ref Data
62 // return=5 : failed to store DAQ Ref Data
63 // return=6 : failed to retrieve DAQ data for calibration
64 // return=7 : problems in processing histos in the input DAQ file
65 // return=8 : failed to store Online Delays
66 // return=9 : failed to store Reference Data for Pulser
67 // return=10: failed to retrieve Pulser data
68 // return=11: failed to store Pulser map in OCDB
69 // return=12: failed to store Reference Data for Noise
70 // return=13: failed to retrieve Noise data
71 // return=14: failed to store Noise map in OCDB
72 // return=15: failed to retrieve FEE data from FXS
73 // return=16: failed to retrieve FEE data from OCDB
74 // return=17: failed to store FEE data in OCDB
75 // return=18: failed to store FEE reference data in OCDB
76 // return=20: failed in retrieving status variable
78 ClassImp(AliTOFPreprocessor)
80 const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean
81 const Double_t AliTOFPreprocessor::fgkIntegralThr = 100; // min number of entries to perform computation of delay per channel
82 const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay
84 //_____________________________________________________________________________
86 AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
87 AliPreprocessor("TOF", shuttle),
97 fIsStatusMapChanged(0)
100 AddRunType("PHYSICS");
101 AddRunType("PULSER");
106 //_____________________________________________________________________________
108 AliTOFPreprocessor::~AliTOFPreprocessor()
113 //______________________________________________________________________________
114 void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
117 // Creates AliTOFDataDCS object
119 AliPreprocessor::Initialize(run, startTime, endTime);
121 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
122 TTimeStamp(startTime).AsString(),
123 TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
125 fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
126 fHVLVmaps = new AliTOFLvHvDataPoints(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
127 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
129 //_____________________________________________________________________________
130 Bool_t AliTOFPreprocessor::ProcessDCS(){
132 // check whether DCS should be processed or not...
134 TString runType = GetRunType();
135 Log(Form("RunType %s",runType.Data()));
137 if (runType != "PHYSICS"){
143 //_____________________________________________________________________________
145 UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap * const dcsAliasMap)
147 // Fills data into a AliTOFDataDCS object
150 Log("Processing DCS DP");
151 TH1::AddDirectory(0);
153 Bool_t resultDCSMap=kFALSE;
154 Bool_t resultDCSStore=kFALSE;
158 fData->SetFDRFlag(fFDRFlag);
161 Log("No DCS map found: TOF exiting from Shuttle");
166 return 1;// return error Code for DCS input data not found
170 // The processing of the DCS input data is forwarded to AliTOFDataDCS
171 resultDCSMap=fData->ProcessData(*dcsAliasMap);
173 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
178 return 2;// return error Code for processed DCS data not stored
181 AliCDBMetaData metaDataDCS;
182 metaDataDCS.SetBeamPeriod(0);
183 metaDataDCS.SetResponsible("Chiara Zampolli");
184 metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
185 AliInfo("Storing DCS Data");
186 resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
187 if (!resultDCSStore){
188 Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
193 return 3;// return error Code for processed DCS data not stored
206 //_____________________________________________________________________________
208 UInt_t AliTOFPreprocessor::ProcessHVandLVdps(TMap * const dcsAliasMap)
211 //Fills data into a AliTOFLvHvDataPoints object
212 // Merges fStatus object with LV and HV status at SOR
213 // Updates fStatus object with LV and HV status
214 // at EOR in case of correct end of run
215 // at last but two value in case of end-of-run caused by TOF detector.
218 Log("Processing HV and LV DCS DPs");
219 TH1::AddDirectory(0);
221 Bool_t resultDCSMap=kFALSE;
225 fHVLVmaps->SetFDRFlag(fFDRFlag);
228 Log("No DCS map found: TOF exiting from Shuttle");
233 return 1;// return error Code for DCS input data not found
237 // The processing of the DCS input data is forwarded to AliTOFDataDCS
238 resultDCSMap = fHVLVmaps->ProcessData(*dcsAliasMap);
240 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
245 return 2;// return error Code for processed DCS data not stored
249 // check with plots. Start...
251 TH1F *hROsor = new TH1F("hROsor","RO status map at SOR",91*96*18,-0.5,91*96*18-0.5);
252 for (Int_t ii=1; ii<=91*96*18; ii++) hROsor->SetBinContent(ii,-1);
253 for (Int_t ii=0; ii<91*96*18; ii++) {
254 if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
255 hROsor->SetBinContent(ii+1,0);
256 else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
257 hROsor->SetBinContent(ii+1,1);
260 TH1F *hROandHVandLVsor = new TH1F("hROandHVandLVsor","RO.and.HV.andLV status map at SOR",91*96*18,-0.5,91*96*18-0.5);
261 for (Int_t ii=1; ii<=91*96*18; ii++) hROandHVandLVsor->SetBinContent(ii,-1);
262 TH1F *hROandHVandLVeor = new TH1F("hROandHVandLVeor","RO.and.HV.andLV status map at EOR",91*96*18,-0.5,91*96*18-0.5);
263 for (Int_t ii=1; ii<=91*96*18; ii++) hROandHVandLVeor->SetBinContent(ii,-1);
266 AliTOFDCSmaps * lvANDhvMap = (AliTOFDCSmaps*)fHVLVmaps->GetHVandLVmapAtSOR(); // Get LV.and.HV status map at SOR
267 for (Int_t index=0; index<fNChannels; index++) {
268 if ( ( lvANDhvMap->GetCellValue(index)==0 &&
269 fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWBad ) ||
270 ( lvANDhvMap->GetCellValue(index)==1 &&
271 fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWOk ) ) {
272 fStatus->SetHWStatus(index, AliTOFChannelOnlineStatusArray::kTOFHWBad);
273 fIsStatusMapChanged=kTRUE;
277 // check with plots. Start...
279 for (Int_t ii=0; ii<91*96*18; ii++) {
280 if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
281 hROandHVandLVsor->SetBinContent(ii+1,0);
282 else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
283 hROandHVandLVsor->SetBinContent(ii+1,1);
287 lvANDhvMap = (AliTOFDCSmaps*)fHVLVmaps->GetHVandLVmapAtEOR(); // Get LV.and.HV status map at EOR
288 for (Int_t index=0; index<fNChannels; index++) {
289 if ( ( lvANDhvMap->GetCellValue(index)==0 &&
290 fStatus->GetHWStatus(index)!=AliTOFChannelOnlineStatusArray::kTOFHWBad ) ||
291 ( lvANDhvMap->GetCellValue(index)==1 &&
292 fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWOk ) ) {
293 fStatus->SetHWStatus(index, AliTOFChannelOnlineStatusArray::kTOFHWBad);
294 fIsStatusMapChanged=kTRUE;
298 // check with plots. Start...
300 for (Int_t ii=0; ii<91*96*18; ii++) {
301 if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
302 hROandHVandLVeor->SetBinContent(ii+1,0);
303 else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
304 hROandHVandLVeor->SetBinContent(ii+1,1);
307 TCanvas *canvas = new TCanvas("canvas","",10,10,1000,1000);
308 canvas->SetFillColor(0);
311 hROsor->SetLineWidth(2);
314 hROandHVandLVsor->SetLineWidth(2);
315 hROandHVandLVsor->Draw();
317 hROandHVandLVeor->SetLineWidth(2);
318 hROandHVandLVeor->Draw();
326 /* check whether we don't need to update OCDB.
327 * in this case we can return without errors. */
329 if (!fIsStatusMapChanged) {
330 AliInfo("TOF FEE config has not changed. Do not overwrite stored file.");
331 return 0; // return ok
334 TString runType = GetRunType();
335 if (runType != "PHYSICS") {
336 AliInfo(Form("Run Type = %s, waiting to store status map",GetRunType()));
337 return 0; // return ok
340 // update the OCDB with the current FEE.and.HV.and.LV
341 // since even a little difference has been detected.
343 AliCDBMetaData metaData;
344 metaData.SetBeamPeriod(0);
345 metaData.SetResponsible("Roberto Preghenella");
346 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object from FEE.and.HV.and.LV data.");
347 AliInfo("Storing Status data from current run. Collected RO.and.HV.and.LV infos @ EOR");
349 if (!Store("Calib", "Status", fStatus, &metaData, 0, kTRUE)) {
351 Log("problems while storing RO.and.HV.and.LV Status data object");
360 return 17; // return error code for problems while storing FEE data
363 // everything fine. return
377 //_____________________________________________________________________________
379 UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
381 // Processing data from DAQ for online calibration
383 Bool_t updateOCDB = kFALSE;
384 Log("Processing DAQ delays");
386 // reading configuration map
387 TString compDelays = "kFALSE";
388 Int_t deltaStartingRun = fRun;
389 Int_t startingRun = fRun-deltaStartingRun;
390 Int_t binRangeAve = fgkBinRangeAve;
391 Double_t integralThr = fgkIntegralThr;
392 Double_t thrPar = fgkThrPar;
394 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Config");
396 Log(Form("No Configuration entry found in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
399 TMap *configMap = (TMap*)cdbEntry->GetObject();
401 Log(Form("No map found in Config entry in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
404 TObjString *strDelays = (TObjString*)configMap->GetValue("ComputingDelays");
406 compDelays = (TString) strDelays->GetString();
409 Log(Form("No ComputingDelays value found in Map from Config entry in CDB, using default value: ComputingDelays = %s",compDelays.Data()));
411 TObjString *strRun = (TObjString*)configMap->GetValue("StartingRun");
413 TString tmpstr = strRun->GetString();
414 startingRun = tmpstr.Atoi();
415 deltaStartingRun = fRun - startingRun;
418 Log(Form("No StartingRun value found in Map from Config entry in CDB, using default value: StartingRun = %i",startingRun));
420 TObjString *strBinRangeAve = (TObjString*)configMap->GetValue("BinRangeAve");
421 if (strBinRangeAve) {
422 TString tmpstr = strBinRangeAve->GetString();
423 binRangeAve = tmpstr.Atoi();
426 Log(Form("No BinRangeAve value found in Map from Config entry in CDB, using default value: BinRangeAve = %i",binRangeAve));
428 TObjString *strIntegralThr = (TObjString*)configMap->GetValue("IntegralThr");
429 if (strIntegralThr) {
430 TString tmpstr = strIntegralThr->GetString();
431 integralThr = tmpstr.Atof();
434 Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %i",integralThr));
436 TObjString *strThrPar = (TObjString*)configMap->GetValue("ThrPar");
438 TString tmpstr = strThrPar->GetString();
439 thrPar = tmpstr.Atof();
442 Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %i",thrPar));
446 if (compDelays == "kTRUE") fFDRFlag = kFALSE;
447 else fFDRFlag = kTRUE;
452 Log(Form("ComputingDelays = %s, StartingRun = %i",compDelays.Data(),startingRun));
454 /* init array with current calibration, if any */
455 fCal = new AliTOFChannelOnlineArray(fNChannels);
456 AliTOFChannelOnlineArray *curCal = NULL;
458 AliCDBEntry *cdbEntry2 = GetFromOCDB("Calib","ParOnlineDelay");
459 if (!cdbEntry2 || !cdbEntry2->GetObject()) {
460 /* no CDB entry found. set update flag */
461 Log(" ************ WARNING ************");
462 Log("No CDB ParOnlineDelay entry found, creating a new one!");
463 Log(" *********************************");
467 Log("Found previous ParOnlineDelay entry. Using it to init calibration");
468 curCal = (AliTOFChannelOnlineArray *)cdbEntry2->GetObject();
469 for (Int_t i = 0; i < fNChannels; i++)
470 fCal->SetDelay(i, curCal->GetDelay(i));
474 TH1::AddDirectory(0);
476 Bool_t resultDAQRef=kFALSE;
477 Bool_t resultTOFPP=kFALSE;
484 //retrieving data at Run level
485 TList* list = GetFileSources(kDAQ, "RUNLevel");
486 if (list !=0x0 && list->GetEntries()!=0)
488 AliInfo("The following sources produced files with the id RUNLevel");
490 for (Int_t jj=0;jj<list->GetEntries();jj++){
491 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
492 AliInfo(Form("found source %s", str->String().Data()));
493 // file to be stored run per run
494 TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
495 if (fileNameRun.Length()>0){
496 AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
497 daqFile = new TFile(fileNameRun.Data(),"READ");
498 h2 = (TH2S*) daqFile->Get("htof");
499 AliCDBMetaData metaDataHisto;
500 metaDataHisto.SetBeamPeriod(0);
501 metaDataHisto.SetResponsible("Chiara Zampolli");
502 metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
503 AliInfo("Storing Reference Data");
504 resultDAQRef = StoreReferenceData("Calib","DAQData",h2, &metaDataHisto);
506 Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
511 return 5;//return error code for failure in storing Ref Data
518 Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
522 return 4;//return error code for failure in retrieving Ref Data
528 Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
531 return 4;//return error code for failure in retrieving Ref Data
536 //Total files, with cumulative histos
538 TList* listTot = GetFileSources(kDAQ, "DELAYS");
539 if (listTot !=0x0 && listTot->GetEntries()!=0)
541 AliInfo("The following sources produced files with the id DELAYS");
543 for (Int_t jj=0;jj<listTot->GetEntries();jj++){
544 TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
545 AliInfo(Form("found source %s", str->String().Data()));
547 // file with summed histos, to extract calib params
548 TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
549 if (fileName.Length()>0){
550 AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
552 daqFile = new TFile(fileName.Data(),"READ");
554 h2 = (TH2S*) daqFile->Get("htoftot");
556 Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
561 return 7; //return error code for histograms not existing/junky
564 static const Int_t kSize=h2->GetNbinsX();
565 static const Int_t kNBins=h2->GetNbinsY();
566 static const Double_t kXBinmin=h2->GetYaxis()->GetBinLowEdge(1);
567 if (kSize != fNChannels){
568 Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
574 return 7; //return error code for histograms not existing/junky
576 Int_t nNotStatistics = 0; // number of channel with not enough statistics
578 /* FDR flag set. do not compute delays, use nominal cable delays */
581 Log(" Not computing delays according to flag set in Config entry in OCDB!");
582 FillWithCosmicCalibration(fCal);
584 /* check whether the new calibration is different from the previous one */
585 if (curCal) { /* well, check also whether we have a previous calibration */
586 for (Int_t i = 0; i < fNChannels; i++) {
587 if (fCal->GetDelay(i) != curCal->GetDelay(i)) {
593 else /* otherwise update OCDB */
598 else { // computing delays if not in FDR runs
600 updateOCDB = kTRUE; /* always update OCDB when computing delays */
602 for (Int_t ich=0;ich<kSize;ich++){
603 /* check whether channel has been read out during current run.
604 * if the status is bad it means it has not been read out.
605 * in this case skip channel in order to not affect the mean */
606 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad){
607 AliDebug(2,Form(" Channel %i found bad according to FEEmap, (HW status = %i), skipping from delay computing",ich, (Int_t)fStatus->GetHWStatus(ich)));
610 AliDebug(2,Form(" Channel %i found ok according to FEEmap, starting delay computing",ich));
611 TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
612 for (Int_t ibin=0;ibin<kNBins;ibin++){
613 h1->SetBinContent(ibin+1,h2->GetBinContent(ich+1,ibin+1));
615 if(h1->Integral()<integralThr) {
617 Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs
623 Float_t minContent=h1->Integral()*thrPar;
624 Int_t nbinsX = h1->GetNbinsX();
626 for (Int_t j=1; j<=nbinsX; j++){
628 h1->GetBinContent(j) +
629 h1->GetBinContent(j+1)+
630 h1->GetBinContent(j+2)+
631 h1->GetBinContent(j+3))>minContent){
637 if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
638 // Now calculate the mean over the interval.
642 for(Int_t k=0;k<binRangeAve;k++){
643 mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);
644 nent=nent+h1->GetBinContent(startBin+k);
645 sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
647 mean= mean/nent; //<x>
648 sumw2=sumw2/nent; //<x^2>
650 rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
651 if (ich<fNChannels) {
652 Float_t delay = mean*AliTOFGeometry::TdcBinWidth()*1.E-3; // delay in ns
653 fCal->SetDelay(ich,delay); // delay in ns
654 AliDebug(2,Form("Setting delay %f (ns) for channel %i",delay,ich));
660 if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics));
667 Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
671 return 6;//return error code for problems in retrieving DAQ data
677 Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
680 return 6; //return error code for problems in retrieving DAQ data
683 /* check whether we don't need to update OCDB.
684 * in this case we can return without errors and
685 * the current FEE is stored in the fStatus object. */
687 AliInfo("update OCDB flag not set. Do not overwrite stored file.");
688 return 0; /* return ok */
692 AliCDBMetaData metaData;
693 metaData.SetBeamPeriod(0);
694 metaData.SetResponsible("Chiara Zampolli");
695 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineArray object for online calibration - delays.");
696 AliInfo("Storing Calibration Data");
697 resultTOFPP = Store("Calib","ParOnlineDelay",fCal, &metaData,deltaStartingRun,kTRUE);
699 Log("Some problems occurred while storing online object resulting from DAQ data processing");
702 return 8;//return error code for problems in storing DAQ data
712 //_____________________________________________________________________________
714 UInt_t AliTOFPreprocessor::ProcessPulserData()
716 // Processing Pulser Run data for TOF channel status
718 Log("Processing Pulser");
721 AliError("No valid fStatus found, some errors must have occurred!!");
725 TH1::AddDirectory(0);
727 Bool_t resultPulserRef=kFALSE;
728 Bool_t resultPulser=kFALSE;
730 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
731 TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5);
732 for (Int_t ibin =1;ibin<=kSize;ibin++){
733 htofPulser->SetBinContent(ibin,-1);
741 //retrieving Pulser data
742 TList* listPulser = GetFileSources(kDAQ, "PULSER");
743 if (listPulser !=0x0 && listPulser->GetEntries()!=0)
745 AliInfo("The following sources produced files with the id PULSER");
748 for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
749 Int_t nPulserSource = 0;
750 TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
751 AliInfo(Form("found source %s", str->String().Data()));
752 // file to be stored run per run
753 TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
754 if (fileNamePulser.Length()>0){
755 // storing refernce data
756 AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data()));
757 daqFile = new TFile(fileNamePulser.Data(),"READ");
758 h1 = (TH1S*) daqFile->Get("hTOFpulser");
759 for (Int_t ibin=0;ibin<kSize;ibin++){
760 if ((h1->GetBinContent(ibin+1))!=-1){
761 if ((htofPulser->GetBinContent(ibin+1))==-1){
762 htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
765 Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin));
773 Int_t nreadNotEmpty=0;
774 for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){
776 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)));
777 /* check whether channel has been read out during current run.
778 * if the status is bad it means it has not been read out.
779 * in this case skip channel in order to not affect the mean */
780 if (fStatus->GetHWStatus(ientry-1) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
784 if (h1->GetBinContent(ientry)==-1) continue;
786 if (h1->GetBinContent(ientry)>0) {
788 AliDebug(2,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty));
790 mean+=h1->GetBinContent(ientry);
796 AliDebug(2,Form(" nread = %i , nreadNotEmpty = %i, mean = %f",nread,nreadNotEmpty,mean));
797 for (Int_t ich =0;ich<fNChannels;ich++){
798 if (h1->GetBinContent(ich+1)==-1) continue;
799 AliDebug(3,Form(" channel %i pulser status before pulser = %i",ich,(Int_t)fStatus->GetPulserStatus(ich)));
801 /* check whether channel has been read out during current run.
802 * if the status is bad it means it has not been read out.
803 * in this case skip channel in order to leave its status
805 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
808 if (h1->GetBinContent(ich+1)<0.05*mean){
809 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserBad); // bad status for pulser
810 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)));
813 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserOk); // good status for pulser
814 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)));
819 Log("No channels read!! No action taken, keeping old status");
828 Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle ");
836 return 10;//return error code for failure in retrieving Ref Data
838 AliDebug(2,Form(" Number of channels processed during pulser run from source %i = %i",jj, nPulserSource));
840 AliDebug(2,Form(" Number of channels processed during pulser run = %i",nPulser));
845 Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle ");
852 return 10;//return error code for failure in retrieving Ref Data
857 AliCDBMetaData metaData;
858 metaData.SetBeamPeriod(0);
859 metaData.SetResponsible("Chiara Zampolli");
860 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Pulser run.");
861 AliInfo("Storing Calibration Data from Pulser Run");
862 resultPulser = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
864 Log("Some problems occurred while storing online object resulting from Pulser data processing");
871 return 11;//return error code for problems in storing Pulser data
876 AliCDBMetaData metaDataHisto;
877 metaDataHisto.SetBeamPeriod(0);
878 metaDataHisto.SetResponsible("Chiara Zampolli");
880 sprintf(comment,"This preprocessor stores the Ref data from a pulser run.");
881 metaDataHisto.SetComment(comment);
882 AliInfo("Storing Reference Data");
883 resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
884 if (!resultPulserRef){
885 Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle");
892 return 9;//return error code for failure in storing Ref Data
908 //_____________________________________________________________________________
910 UInt_t AliTOFPreprocessor::ProcessNoiseData()
913 // Processing Noise Run data for TOF channel status
915 Log("Processing Noise");
918 AliError("No valid fStatus found, some errors must have occurred!!");
922 Float_t noiseThr = 1; // setting default threshold for noise to 1 Hz
923 // reading config map
924 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
926 Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %d",noiseThr));
929 TMap *configMap = (TMap*)cdbEntry->GetObject();
931 Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %d", noiseThr));
934 TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
936 TString tmpstr = strNoiseThr->GetString();
937 noiseThr = tmpstr.Atoi();
940 Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %i",noiseThr));
948 TH1::AddDirectory(0);
950 Bool_t resultNoiseRef=kFALSE;
951 Bool_t resultNoise=kFALSE;
953 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
954 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", kSize,-0.5,kSize-0.5);
955 for (Int_t ibin =1;ibin<=kSize;ibin++){
956 htofNoise->SetBinContent(ibin,-1);
966 Int_t nNoisyChannels = 0;
967 Int_t nNotNoisyChannels = 0;
968 Int_t nChannelsFromDA = 0;
969 Int_t nMatchingWindowNullNonZero = 0;
970 Int_t nMatchingWindowNullEqualZero = 0;
972 // retrieving Noise data
973 TList* listNoise = GetFileSources(kDAQ, "NOISE");
974 if (listNoise !=0x0 && listNoise->GetEntries()!=0)
976 AliInfo("The following sources produced files with the id NOISE");
978 for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
979 Int_t nNoiseSource = 0;
980 TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
981 AliInfo(Form("found source %s", str->String().Data()));
982 // file to be stored run per run
983 TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
984 if (fileNameNoise.Length()>0){
985 // storing reference data
986 AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data()));
987 daqFile = new TFile(fileNameNoise.Data(),"READ");
988 h1 = (TH1F*) daqFile->Get("hTOFnoise");
989 for (Int_t ibin=0;ibin<kSize;ibin++){
990 if ((h1->GetBinContent(ibin+1))!=-1){
992 // checking the matching window for current channel
993 if (fMatchingWindow[ibin] == 0){
994 Log(Form("Matching window for channel %i null, but the channel was read by the LDC! skipping channel, BUT Please check!",ibin));
995 if ((h1->GetBinContent(ibin+1))!=0) nMatchingWindowNullNonZero++;
996 if ((h1->GetBinContent(ibin+1))==0) nMatchingWindowNullEqualZero++;
999 if ((htofNoise->GetBinContent(ibin+1))==-1){
1000 htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)/(fMatchingWindow[ibin]*1.E-9));
1001 if ((h1->GetBinContent(ibin+1))!= 0) AliDebug(2,Form("Channel = %i, Matching window = %i, Content = %f", ibin, fMatchingWindow[ibin], htofNoise->GetBinContent(ibin+1)));
1004 Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin));
1009 Log(Form(" Number of channels processed during noise run from source %i = %i",jj, nNoiseSource));
1018 Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle ");
1027 if (fMatchingWindow){
1028 delete [] fMatchingWindow;
1029 fMatchingWindow = 0;
1031 return 13;//return error code for failure in retrieving Ref Data
1037 Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle ");
1044 if (fMatchingWindow){
1045 delete [] fMatchingWindow;
1046 fMatchingWindow = 0;
1048 return 13;//return error code for failure in retrieving Ref Data
1051 // elaborating infos to set NOISE status
1052 for (Int_t ich =0;ich<fNChannels;ich++){
1053 if (htofNoise->GetBinContent(ich+1)== -1) continue;
1057 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)));
1058 //AliDebug(2,Form( " channel %i status before noise = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich)));
1060 /* check whether channel has been read out during current run.
1061 * if the status is bad it means it has not been read out.
1062 * in this case skip channel in order to leave its status
1065 if ((fStatus->GetHWStatus(ich)) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1069 if (htofNoise->GetBinContent(ich+1) >= noiseThr){
1070 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseBad); // bad status for noise
1071 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)));
1075 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseOk); // good status for noise
1076 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)));
1077 nNotNoisyChannels++;
1081 Log(Form(" Number of channels processed by DA during noise run, independetly from TOFFEE = %i",nChannelsFromDA));
1082 Log(Form(" Number of channels processed during noise run (that were ON according to TOFFEE) = %i",nNoise));
1083 Log(Form(" Number of noisy channels found during noise run = %i",nNoisyChannels));
1084 Log(Form(" Number of not noisy channels found during noise run = %i",nNotNoisyChannels));
1085 Log(Form(" Number of channels with matching window NULL (so skipped), but Non Zero content = %i",nMatchingWindowNullNonZero));
1086 Log(Form(" Number of channels with matching window NULL (so skipped), and Zero content = %i",nMatchingWindowNullEqualZero));
1094 AliCDBMetaData metaData;
1095 metaData.SetBeamPeriod(0);
1096 metaData.SetResponsible("Chiara Zampolli");
1097 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Noise run.");
1098 AliInfo("Storing Calibration Data from Noise Run");
1099 resultNoise = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
1101 Log("Some problems occurred while storing online object resulting from Noise data processing");
1108 if (fMatchingWindow){
1109 delete [] fMatchingWindow;
1110 fMatchingWindow = 0;
1112 return 14;//return error code for problems in storing Noise data
1117 AliCDBMetaData metaDataHisto;
1118 metaDataHisto.SetBeamPeriod(0);
1119 metaDataHisto.SetResponsible("Chiara Zampolli");
1121 sprintf(comment,"This preprocessor stores the Ref data from a noise run. ");
1122 metaDataHisto.SetComment(comment);
1123 AliInfo("Storing Reference Data");
1124 resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
1125 if (!resultNoiseRef){
1126 Log("some problems occurred::No Reference Data for noise stored");
1133 if (fMatchingWindow){
1134 delete [] fMatchingWindow;
1135 fMatchingWindow = 0;
1137 return 12;//return error code for failure in storing Ref Data
1149 if (fMatchingWindow){
1150 delete [] fMatchingWindow;
1151 fMatchingWindow = 0;
1156 //_____________________________________________________________________________
1158 UInt_t AliTOFPreprocessor::ProcessFEEData()
1160 // Processing Pulser Run data for TOF channel status
1161 // dummy for the time being
1163 Log("Processing FEE");
1165 //Bool_t updateOCDB = kFALSE;
1166 AliTOFFEEReader feeReader;
1168 TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels);
1170 /* load current TOF FEE(dump) from DCS FXS,
1171 * setup TOFFEEdump object */
1173 const char * toffeeFileName = GetFile(kDCS,"TofFeeMap","");
1174 AliInfo(Form("toffee file name = %s", toffeeFileName));
1175 if (toffeeFileName == NULL) {
1178 AliTOFFEEDump feedump;
1179 feedump.ReadFromFile(toffeeFileName);
1181 /* load current TOF FEE(light) config from DCS FXS, parse,
1182 * fill current FEE histogram and set FEE status */
1184 const char * nameFile = GetFile(kDCS,"TofFeeLightMap","");
1185 AliInfo(Form("toffeeLight file name = %s",nameFile));
1186 if (nameFile == NULL) {
1189 feeReader.LoadFEElightConfig(nameFile);
1190 Int_t parseFee = feeReader.ParseFEElightConfig();
1191 AliDebug(2,Form("%i enabled channels found in FEElight configuration",parseFee));
1192 /* load stored TOF FEE from OCDB and compare it with current FEE.
1193 * if stored FEE is different from current FEE set update flag.
1194 * if there is no stored FEE in OCDB set update flag */
1196 fMatchingWindow = new Int_t[fNChannels];
1197 fLatencyWindow = new Int_t[fNChannels];
1199 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Status");
1201 /* no CDB entry found. set update flag */
1202 Log(" ************ WARNING ************");
1203 Log("No CDB Status entry found, creating a new one!");
1204 Log(" *********************************");
1205 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1206 //updateOCDB = kTRUE;
1207 fIsStatusMapChanged = kTRUE;
1210 if (cdbEntry) cdbEntry->SetOwner(kFALSE);
1211 /* CDB entry OK. loop over channels */
1212 fStatus = (AliTOFChannelOnlineStatusArray*) cdbEntry->GetObject();
1215 /* cehck whether status object has latency window data */
1216 if (!fStatus->HasLatencyWindow()) {
1217 /* create new status object and update OCDB */
1218 Log(" ************ WARNING ************");
1219 Log("CDB Status entry found but has no latency window data, creating a new one!");
1220 Log(" *********************************");
1222 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1223 //updateOCDB = kTRUE;
1224 fIsStatusMapChanged = kTRUE;
1227 for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){
1228 //AliDebug(2,Form("********** channel %i",iChannel));
1229 /* compare current FEE channel status with stored one
1230 * if different set update flag and break loop */
1231 //AliDebug(2,Form( " channel %i status before FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1232 fMatchingWindow[iChannel] = feeReader.GetMatchingWindow(iChannel);
1233 fLatencyWindow[iChannel] = feeReader.GetLatencyWindow(iChannel);
1234 if (feeReader.IsChannelEnabled(iChannel)) {
1235 hCurrentFEE.SetBinContent(iChannel + 1, 1);
1236 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWOk){
1237 //updateOCDB = kTRUE;
1238 fIsStatusMapChanged = kTRUE;
1239 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWOk);
1240 AliDebug(3,Form( " changed into enabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1242 if (fStatus->GetLatencyWindow(iChannel)!=fLatencyWindow[iChannel]){
1243 //updateOCDB = kTRUE;
1244 fIsStatusMapChanged = kTRUE;
1245 fStatus->SetLatencyWindow(iChannel,fLatencyWindow[iChannel]);
1246 AliDebug(3,Form( " changed latency window: channel %i latency window after FEE = %i",iChannel,fStatus->GetLatencyWindow(iChannel)));
1250 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWBad){
1251 //updateOCDB = kTRUE;
1252 fIsStatusMapChanged = kTRUE;
1253 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWBad);
1254 AliDebug(3,Form( " changed into disabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1260 /* check whether we don't have to store reference data.
1261 * in this case we return without errors. */
1262 if (fStoreRefData) {
1263 /* store reference data */
1264 AliCDBMetaData metaDataHisto;
1265 metaDataHisto.SetBeamPeriod(0);
1266 metaDataHisto.SetResponsible("Roberto Preghenella");
1267 metaDataHisto.SetComment("This preprocessor stores the FEE Ref data of the current run.");
1268 AliInfo("Storing FEE reference data");
1269 /* store FEE reference data */
1270 if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) {
1272 Log("problems while storing FEE reference data");
1277 return 18; /* error return code for problems while storing FEE reference data */
1280 /* store TOF FEE dump reference data */
1281 AliCDBMetaData metaDatadump;
1282 metaDatadump.SetBeamPeriod(0);
1283 metaDatadump.SetResponsible("Roberto Preghenella");
1284 metaDatadump.SetComment("This preprocessor stores the TOF FEE dump Ref data of the current run.");
1285 AliInfo("Storing TOF FEE dump reference data");
1286 /* store FEE reference data */
1287 if (!StoreReferenceData("Calib", "FEEDump", &feedump, &metaDatadump)) {
1289 Log("problems while storing TOF FEE dump reference data");
1290 return 18; /* error return code for problems while storing FEE reference data */
1298 //_____________________________________________________________________________
1300 UInt_t AliTOFPreprocessor::Process(TMap * const dcsAliasMap)
1303 // Main AliTOFPreprocessor method called by SHUTTLE
1306 TString runType = GetRunType();
1307 Log(Form("RunType %s",runType.Data()));
1311 /* always process FEE data */
1312 Int_t iresultFEE = ProcessFEEData();
1313 if (iresultFEE != 0)
1316 if (runType == "PULSER") {
1317 Int_t iresultPulser = ProcessPulserData();
1318 return iresultPulser;
1321 if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined
1322 Int_t iresultNoise = ProcessNoiseData();
1323 return iresultNoise;
1326 if (runType == "PHYSICS") {
1327 Int_t iresultDAQ = ProcessOnlineDelays();
1328 if (iresultDAQ != 0) {
1332 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
1333 Int_t iResultHVandLVdps = ProcessHVandLVdps(dcsAliasMap);
1334 return iresultDCS+iResultHVandLVdps;
1343 //_____________________________________________________________________________
1346 AliTOFPreprocessor::FillWithCosmicCalibration(AliTOFChannelOnlineArray *cal)
1349 * fill with cosmic calibration
1352 Log(" Using cosmic-ray calibration.");
1354 AliTOFcalibHisto calibHisto;
1355 calibHisto.SetFullCorrectionFlag(AliTOFcalibHisto::kTimeSlewingCorr, kFALSE);
1356 Log(Form(" loading calibration histograms from %s", calibHisto.GetCalibHistoFileName()));
1357 Log(Form(" loading calibration parameters from %s", calibHisto.GetCalibParFileName()));
1358 calibHisto.LoadCalibPar();
1360 /* loop over channel index */
1361 for (Int_t iIndex = 0; iIndex < fNChannels; iIndex++) {
1362 cal->SetDelay(iIndex, calibHisto.GetFullCorrection(iIndex));
1367 //_____________________________________________________________________________
1370 AliTOFPreprocessor::FillWithCableLengthMap(AliTOFChannelOnlineArray *cal)
1373 * fill with cosmic calibration
1376 Log(" Using cable-length map.");
1377 AliTOFRawStream tofrs;
1378 Int_t det[5], dummy, index;
1379 Float_t cableTimeShift;
1381 /* temporarly disable warnings */
1382 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
1383 AliLog::SetGlobalLogLevel(AliLog::kError);
1385 /* loop over EO indeces */
1386 for (Int_t iddl = 0; iddl < 72; iddl++)
1387 for (Int_t islot = 3; islot <= 12; islot++)
1388 for (Int_t ichain = 0; ichain < 2; ichain++)
1389 for (Int_t itdc = 0; itdc < 15; itdc++)
1390 for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
1393 tofrs.EquipmentId2VolumeId(iddl, islot, ichain, itdc, ichannel, det);
1395 /* swap det[3] and det[4] indeces (needed to obtain correct channel index) */
1400 /* check DO index */
1401 if (det[0] < 0 || det[0] > 17 ||
1402 det[1] < 0 || det[1] > 4 ||
1403 det[2] < 0 || det[2] > 18 ||
1404 det[3] < 0 || det[3] > 1 ||
1405 det[4] < 0 || det[4] > 47)
1408 /* get channel index */
1409 index = AliTOFGeometry::GetIndex(det);
1411 /* get cable time shift */
1412 cableTimeShift = AliTOFCableLengthMap::GetCableTimeShift(iddl, islot, ichain, itdc);
1415 if (index<fNChannels) {
1416 cal->SetDelay(index,cableTimeShift); // delay in ns
1417 AliDebug(2,Form("Setting delay %f (ns) for channel %i",cableTimeShift,index));
1420 } /* loop over EO indeces */
1422 /* re-enable warnings */
1423 AliLog::SetGlobalLogLevel(logLevel);