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 "AliTOFDCSmaps.h"
39 #include "AliTOFLvHvDataPoints.h"
40 #include "AliTOFGeometry.h"
41 #include "AliTOFPreprocessor.h"
42 #include "AliTOFFEEReader.h"
43 #include "AliTOFRawStream.h"
44 #include "AliTOFCableLengthMap.h"
45 #include "AliTOFcalibHisto.h"
46 #include "AliTOFFEEDump.h"
48 #include "AliTOFDeltaBCOffset.h"
49 #include "AliTOFCTPLatency.h"
50 #include "AliTOFRunParams.h"
51 #include "AliTOFT0FillOnlineCalib.h"
52 #include "AliTOFHitField.h"
53 #include "AliTOFChannelOffline.h"
55 #include "TGeoManager.h"
56 #include "AliGeomManager.h"
57 #include "AliTOFReadoutInfo.h"
59 // TOF preprocessor class.
60 // It takes data from DCS and passes them to the class AliTOFDataDCS, which
61 // processes them. The result is then written to the CDB.
62 // Analogously, it takes data form DAQ (both at Run level and inclusive -
63 // of all the runs - level, processes them, and stores both Reference Data
64 // and Online Calibration files in the CDB.
65 // Processing of Pulser/Noise Run data and of TOF FEE DCS map included also.
69 // return=1 : no DCS input data Map
70 // return=2 : no DCS input data processing
71 // return=3 : no DCS processed data was stored in Ref Data
72 // return=4 : no DAQ input for Ref Data
73 // return=5 : failed to store DAQ Ref Data
74 // return=6 : failed to retrieve DAQ data for calibration
75 // return=7 : problems in processing histos in the input DAQ file
76 // return=8 : failed to store Online Delays
77 // return=9 : failed to store Reference Data for Pulser
78 // return=10: failed to retrieve Pulser data
79 // return=11: failed to store Pulser map in OCDB
80 // return=12: failed to store Reference Data for Noise
81 // return=13: failed to retrieve Noise data
82 // return=14: failed to store Noise map in OCDB
83 // return=15: failed to retrieve FEE data from FXS
84 // return=16: failed to retrieve FEE data from OCDB
85 // return=17: failed to store FEE data in OCDB
86 // return=18: failed to store FEE reference data in OCDB
87 // return=20: failed in retrieving status variable
88 // return=100 : no DCS input data Map (HV and LV status)
89 // return=200 : no DCS input data processing (HV and LV status)
90 // return=300 : no DCS processed data was stored in Ref Data (HV and LV status)
92 ClassImp(AliTOFPreprocessor)
94 const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean
95 const Double_t AliTOFPreprocessor::fgkIntegralThr = 100; // min number of entries to perform computation of delay per channel
96 const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay
98 //_____________________________________________________________________________
100 AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
101 AliPreprocessor("TOF", shuttle),
106 fStoreRefData(kTRUE),
111 fIsStatusMapChanged(0)
114 AddRunType("PHYSICS");
115 AddRunType("PULSER");
120 //_____________________________________________________________________________
122 AliTOFPreprocessor::~AliTOFPreprocessor()
127 //______________________________________________________________________________
128 void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
131 // Creates AliTOFDataDCS object
133 AliPreprocessor::Initialize(run, startTime, endTime);
135 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
136 TTimeStamp(startTime).AsString(),
137 TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
139 fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
140 fHVLVmaps = new AliTOFLvHvDataPoints(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
141 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
143 //_____________________________________________________________________________
144 Bool_t AliTOFPreprocessor::ProcessDCS(){
146 // check whether DCS should be processed or not...
148 TString runType = GetRunType();
149 Log(Form("RunType %s",runType.Data()));
151 if (runType != "PHYSICS"){
157 //_____________________________________________________________________________
159 UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap *dcsAliasMap)
161 // Fills data into a AliTOFDataDCS object
164 Log("Processing DCS DP");
165 TH1::AddDirectory(0);
167 Bool_t resultDCSMap=kFALSE;
168 Bool_t resultDCSStore=kFALSE;
172 fData->SetFDRFlag(fFDRFlag);
175 Log("No DCS map found: TOF exiting from Shuttle");
180 return 1;// return error Code for DCS input data not found
184 // The processing of the DCS input data is forwarded to AliTOFDataDCS
185 resultDCSMap=fData->ProcessData(*dcsAliasMap);
187 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
192 return 2;// return error Code for processed DCS data not stored
195 AliCDBMetaData metaDataDCS;
196 metaDataDCS.SetBeamPeriod(0);
197 metaDataDCS.SetResponsible("Chiara Zampolli");
198 metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
199 AliInfo("Storing DCS Data");
200 resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
201 if (!resultDCSStore){
202 Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
207 return 3;// return error Code for processed DCS data not stored
220 //_____________________________________________________________________________
222 UInt_t AliTOFPreprocessor::ProcessHVandLVdps(TMap *dcsAliasMap)
225 //Fills data into a AliTOFLvHvDataPoints object
226 // Merges fStatus object with LV and HV status at SOR
227 // Updates fStatus object with LV and HV status
228 // at EOR in case of correct end of run
229 // at last but two value in case of end-of-run caused by TOF detector.
232 Log("Processing HV and LV DCS DPs");
233 TH1::AddDirectory(0);
235 Bool_t resultDCSMap=kFALSE;
237 // processing DCS HV and LV data points
239 fHVLVmaps->SetFDRFlag(fFDRFlag);
242 Log("No DCS map found: TOF exiting from Shuttle");
247 return 100;// return error Code for DCS input data not found
251 // The processing of the DCS input data is forwarded to AliTOFDataDCS
253 resultDCSMap = fHVLVmaps->ProcessData(*dcsAliasMap);
255 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
260 return 200;// return error Code for processed DCS data not stored
264 // check with plots. Start...
266 TH1F *hROsor = new TH1F("hROsor","RO status map at SOR",91*96*18,-0.5,91*96*18-0.5);
267 for (Int_t ii=1; ii<=91*96*18; ii++) hROsor->SetBinContent(ii,-1);
268 for (Int_t ii=0; ii<91*96*18; ii++) {
269 if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
270 hROsor->SetBinContent(ii+1,0);
271 else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
272 hROsor->SetBinContent(ii+1,1);
275 TH1F *hROandHVandLVsor = new TH1F("hROandHVandLVsor","RO.and.HV.andLV status map at SOR",91*96*18,-0.5,91*96*18-0.5);
276 for (Int_t ii=1; ii<=91*96*18; ii++) hROandHVandLVsor->SetBinContent(ii,-1);
277 TH1F *hROandHVandLVeor = new TH1F("hROandHVandLVeor","RO.and.HV.andLV status map at EOR",91*96*18,-0.5,91*96*18-0.5);
278 for (Int_t ii=1; ii<=91*96*18; ii++) hROandHVandLVeor->SetBinContent(ii,-1);
281 AliTOFDCSmaps * lvANDhvMap = (AliTOFDCSmaps*)fHVLVmaps->GetHVandLVmapAtSOR(); // Get LV.and.HV status map at SOR
282 for (Int_t index=0; index<fNChannels; index++) {
283 if ( ( lvANDhvMap->GetCellValue(index)==0 &&
284 fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWBad ) ||
285 ( lvANDhvMap->GetCellValue(index)==1 &&
286 fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWOk ) ) {
287 fStatus->SetHWStatus(index, AliTOFChannelOnlineStatusArray::kTOFHWBad);
288 fIsStatusMapChanged=kTRUE;
292 // check with plots. Start...
294 for (Int_t ii=0; ii<91*96*18; ii++) {
295 if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
296 hROandHVandLVsor->SetBinContent(ii+1,0);
297 else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
298 hROandHVandLVsor->SetBinContent(ii+1,1);
302 lvANDhvMap = (AliTOFDCSmaps*)fHVLVmaps->GetHVandLVmapAtEOR(); // Get LV.and.HV status map at EOR
303 for (Int_t index=0; index<fNChannels; index++) {
304 if ( ( lvANDhvMap->GetCellValue(index)==0 &&
305 fStatus->GetHWStatus(index)!=AliTOFChannelOnlineStatusArray::kTOFHWBad ) ||
306 ( lvANDhvMap->GetCellValue(index)==1 &&
307 fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWOk ) ) {
308 fStatus->SetHWStatus(index, AliTOFChannelOnlineStatusArray::kTOFHWBad);
309 fIsStatusMapChanged=kTRUE;
313 // check with plots. Start...
315 for (Int_t ii=0; ii<91*96*18; ii++) {
316 if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
317 hROandHVandLVeor->SetBinContent(ii+1,0);
318 else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
319 hROandHVandLVeor->SetBinContent(ii+1,1);
322 TCanvas *canvas = new TCanvas("canvas","",10,10,1000,1000);
323 canvas->SetFillColor(0);
326 hROsor->SetLineWidth(2);
329 hROandHVandLVsor->SetLineWidth(2);
330 hROandHVandLVsor->Draw();
332 hROandHVandLVeor->SetLineWidth(2);
333 hROandHVandLVeor->Draw();
342 /* check whether we don't need to update OCDB.
343 * in this case we can return without errors. */
345 if (!fIsStatusMapChanged) {
346 AliInfo("TOF HW status config has not changed. Do not overwrite stored file.");
347 return 0; // return ok
350 TString runType = GetRunType();
351 if (runType != "PHYSICS") {
352 AliInfo(Form("Run Type = %s, waiting to store status map",GetRunType()));
353 return 0; // return ok
356 // update the OCDB with the current FEE.and.HV.and.LV
357 // since even a little difference has been detected.
359 AliCDBMetaData metaData;
360 metaData.SetBeamPeriod(0);
361 metaData.SetResponsible("Roberto Preghenella");
362 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object from FEE.and.HV.and.LV data.");
363 AliInfo("Storing Status data from current run. Collected RO.and.HV.and.LV infos @ EOR");
364 // store TOF channel status
365 if (!Store("Calib", "Status", fStatus, &metaData, 0, kTRUE)) {
367 Log("problems while storing RO.and.HV.and.LV Status data object");
376 return 17; // return error code for problems while TOF channel status
379 // everything fine. return
394 //_____________________________________________________________________________
396 UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
398 // Processing data from DAQ for online calibration
400 Bool_t updateOCDB = kFALSE;
401 Log("Processing DAQ delays");
403 // reading configuration map
404 TString compDelays = "kFALSE";
405 Int_t deltaStartingRun = fRun;
406 Int_t startingRun = fRun-deltaStartingRun;
407 Int_t binRangeAve = fgkBinRangeAve;
408 Double_t integralThr = fgkIntegralThr;
409 Double_t thrPar = fgkThrPar;
411 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Config");
413 Log(Form("No Configuration entry found in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
416 TMap *configMap = (TMap*)cdbEntry->GetObject();
418 Log(Form("No map found in Config entry in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
421 TObjString *strDelays = (TObjString*)configMap->GetValue("ComputingDelays");
423 compDelays = (TString) strDelays->GetString();
426 Log(Form("No ComputingDelays value found in Map from Config entry in CDB, using default value: ComputingDelays = %s",compDelays.Data()));
428 TObjString *strRun = (TObjString*)configMap->GetValue("StartingRun");
430 TString tmpstr = strRun->GetString();
431 startingRun = tmpstr.Atoi();
432 deltaStartingRun = fRun - startingRun;
435 Log(Form("No StartingRun value found in Map from Config entry in CDB, using default value: StartingRun = %i",startingRun));
437 TObjString *strBinRangeAve = (TObjString*)configMap->GetValue("BinRangeAve");
438 if (strBinRangeAve) {
439 TString tmpstr = strBinRangeAve->GetString();
440 binRangeAve = tmpstr.Atoi();
443 Log(Form("No BinRangeAve value found in Map from Config entry in CDB, using default value: BinRangeAve = %i",binRangeAve));
445 TObjString *strIntegralThr = (TObjString*)configMap->GetValue("IntegralThr");
446 if (strIntegralThr) {
447 TString tmpstr = strIntegralThr->GetString();
448 integralThr = tmpstr.Atof();
451 Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %f",integralThr));
453 TObjString *strThrPar = (TObjString*)configMap->GetValue("ThrPar");
455 TString tmpstr = strThrPar->GetString();
456 thrPar = tmpstr.Atof();
459 Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %f",thrPar));
463 if (compDelays == "kTRUE") fFDRFlag = kFALSE;
464 else fFDRFlag = kTRUE;
469 Log(Form("ComputingDelays = %s, StartingRun = %i",compDelays.Data(),startingRun));
471 /* init array with current calibration, if any */
472 fCal = new AliTOFChannelOnlineArray(fNChannels);
473 AliTOFChannelOnlineArray *curCal = NULL;
475 AliCDBEntry *cdbEntry2 = GetFromOCDB("Calib","ParOnlineDelay");
476 if (!cdbEntry2 || !cdbEntry2->GetObject()) {
477 /* no CDB entry found. set update flag */
478 Log(" ************ WARNING ************");
479 Log("No CDB ParOnlineDelay entry found, creating a new one!");
480 Log(" *********************************");
484 Log("Found previous ParOnlineDelay entry. Using it to init calibration");
485 curCal = (AliTOFChannelOnlineArray *)cdbEntry2->GetObject();
486 for (Int_t i = 0; i < fNChannels; i++)
487 fCal->SetDelay(i, curCal->GetDelay(i));
491 TH1::AddDirectory(0);
493 Bool_t resultDAQRef=kFALSE;
494 Bool_t resultTOFPP=kFALSE;
501 //retrieving data at Run level
502 TList* list = GetFileSources(kDAQ, "RUNLevel");
503 if (list !=0x0 && list->GetEntries()!=0)
505 AliInfo("The following sources produced files with the id RUNLevel");
507 for (Int_t jj=0;jj<list->GetEntries();jj++){
508 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
510 AliError("dynamic_cast returned NULL");
513 AliInfo(Form("found source %s", str->String().Data()));
514 // file to be stored run per run
515 TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
516 if (fileNameRun.Length()>0){
517 AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
518 daqFile = new TFile(fileNameRun.Data(),"READ");
519 h2 = (TH2S*) daqFile->Get("htof");
520 AliCDBMetaData metaDataHisto;
521 metaDataHisto.SetBeamPeriod(0);
522 metaDataHisto.SetResponsible("Chiara Zampolli");
523 metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
524 AliInfo("Storing Reference Data");
525 resultDAQRef = StoreReferenceData("Calib","DAQData",h2, &metaDataHisto);
527 Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
532 return 5;//return error code for failure in storing Ref Data
539 Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
543 return 4;//return error code for failure in retrieving Ref Data
549 Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
552 return 4;//return error code for failure in retrieving Ref Data
557 //Total files, with cumulative histos
559 TList* listTot = GetFileSources(kDAQ, "DELAYS");
560 if (listTot !=0x0 && listTot->GetEntries()!=0)
562 AliInfo("The following sources produced files with the id DELAYS");
564 for (Int_t jj=0;jj<listTot->GetEntries();jj++){
565 TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
567 AliError("dynamic_cast returned NULL");
570 AliInfo(Form("found source %s", str->String().Data()));
572 // file with summed histos, to extract calib params
573 TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
574 if (fileName.Length()>0){
575 AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
577 daqFile = new TFile(fileName.Data(),"READ");
579 h2 = (TH2S*) daqFile->Get("htoftot");
581 Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
586 return 7; //return error code for histograms not existing/junky
589 static const Int_t kSize=h2->GetNbinsX();
590 static const Int_t kNBins=h2->GetNbinsY();
591 static const Double_t kXBinmin=h2->GetYaxis()->GetBinLowEdge(1);
592 if (kSize != fNChannels){
593 Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
599 return 7; //return error code for histograms not existing/junky
601 Int_t nNotStatistics = 0; // number of channel with not enough statistics
603 /* FDR flag set. do not compute delays, use nominal cable delays */
606 Log(" Not computing delays according to flag set in Config entry in OCDB!");
607 FillWithCosmicCalibration(fCal);
609 /* check whether the new calibration is different from the previous one */
610 if (curCal) { /* well, check also whether we have a previous calibration */
611 for (Int_t i = 0; i < fNChannels; i++) {
612 if (fCal->GetDelay(i) != curCal->GetDelay(i)) {
618 else /* otherwise update OCDB */
623 else { // computing delays if not in FDR runs
625 updateOCDB = kTRUE; /* always update OCDB when computing delays */
627 for (Int_t ich=0;ich<kSize;ich++){
628 /* check whether channel has been read out during current run.
629 * if the status is bad it means it has not been read out.
630 * in this case skip channel in order to not affect the mean */
631 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad){
632 AliDebug(2,Form(" Channel %i found bad according to FEEmap, (HW status = %i), skipping from delay computing",ich, (Int_t)fStatus->GetHWStatus(ich)));
635 AliDebug(2,Form(" Channel %i found ok according to FEEmap, starting delay computing",ich));
636 TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
637 for (Int_t ibin=0;ibin<kNBins;ibin++){
638 h1->SetBinContent(ibin+1,h2->GetBinContent(ich+1,ibin+1));
640 if(h1->Integral()<integralThr) {
642 Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs
648 Float_t minContent=h1->Integral()*thrPar;
649 Int_t nbinsX = h1->GetNbinsX();
651 for (Int_t j=1; j<=nbinsX; j++){
653 h1->GetBinContent(j) +
654 h1->GetBinContent(j+1)+
655 h1->GetBinContent(j+2)+
656 h1->GetBinContent(j+3))>minContent){
662 if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
663 // Now calculate the mean over the interval.
667 for(Int_t k=0;k<binRangeAve;k++){
668 mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);
669 nent=nent+h1->GetBinContent(startBin+k);
670 sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
672 mean= mean/nent; //<x>
673 sumw2=sumw2/nent; //<x^2>
675 rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
676 if (ich<fNChannels) {
677 Float_t delay = mean*AliTOFGeometry::TdcBinWidth()*1.E-3; // delay in ns
678 fCal->SetDelay(ich,delay); // delay in ns
679 AliDebug(2,Form("Setting delay %f (ns) for channel %i",delay,ich));
685 if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics));
692 Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
696 return 6;//return error code for problems in retrieving DAQ data
702 Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
705 return 6; //return error code for problems in retrieving DAQ data
708 /* check whether we don't need to update OCDB.
709 * in this case we can return without errors and
710 * the current FEE is stored in the fStatus object. */
712 AliInfo("update OCDB flag not set. Do not overwrite stored file.");
713 return 0; /* return ok */
717 AliCDBMetaData metaData;
718 metaData.SetBeamPeriod(0);
719 metaData.SetResponsible("Chiara Zampolli");
720 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineArray object for online calibration - delays.");
721 AliInfo("Storing Calibration Data");
722 resultTOFPP = Store("Calib","ParOnlineDelay",fCal, &metaData,deltaStartingRun,kTRUE);
724 Log("Some problems occurred while storing online object resulting from DAQ data processing");
727 return 8;//return error code for problems in storing DAQ data
738 //_____________________________________________________________________________
741 AliTOFPreprocessor::ProcessT0Fill()
743 // Processing data from DAQ for T0-fill measurement
745 Log("Processing T0-fill");
748 /* instance and setup CDB manager */
749 AliCDBManager *cdb = AliCDBManager::Instance();
751 if (!gGeoManager) AliGeomManager::LoadGeometry();
754 /* get params from OCDB */
755 AliCDBEntry *cdbe = NULL;
758 * check UseLHCClockPhase flag in RunParams.
759 * if set do nothing and return successfully
761 cdbe = GetFromOCDB("Calib", "RunParams");
763 Log("cannot get \"RunParams\" entry from OCDB");
766 AliTOFRunParams *runparams = (AliTOFRunParams *)cdbe->GetObject();
767 if (runparams->GetUseLHCClockPhase()) {
768 Log("UseLHCClockPhase flag is set in RunParams: online T0-fill not computed");
773 * at this stage status object is not on OCDB yet
774 * since it will be stored later. nevertheless we
775 * should have the array in memory since it has been
776 * already setup by ProcessFEF.
779 /* check status and latency window available */
780 if (!fStatus || !fLatencyWindow){
781 AliError("No valid fStatus or fLatencyWindow found, some errors must have occurred!!");
785 /* get offline calibration from OCDB */
786 cdbe = GetFromOCDB("Calib", "ParOffline");
788 Log("cannot get \"ParOffline\" entry from OCDB");
791 TObjArray *offlineArray = (TObjArray *)cdbe->GetObject();
792 AliTOFChannelOffline *channelOffline;
794 Log("cannot get \"ParOffline\" object from CDB entry");
797 Log("got \"ParOffline\" object");
799 /* get deltaBC offset from OCDB */
800 cdbe = GetFromOCDB("Calib", "DeltaBCOffset");
802 Log("cannot get \"DeltaBCOffset\" entry from OCDB");
805 AliTOFDeltaBCOffset *deltaBCOffsetObject = (AliTOFDeltaBCOffset *)cdbe->GetObject();
806 if (!deltaBCOffsetObject) {
807 Log("cannot get \"DeltaBCOffset\" object from CDB entry");
810 Int_t deltaBCOffset = deltaBCOffsetObject->GetDeltaBCOffset();
811 Log(Form("got \"DeltaBCOffset\" object: deltaBCOffset=%d (BC bins)", deltaBCOffset));
813 /* get CTP latency from OCDB */
814 cdbe = GetFromOCDB("Calib", "CTPLatency");
816 Log("cannot get \"CTPLatency\" entry from OCDB");
819 AliTOFCTPLatency *ctpLatencyObject = (AliTOFCTPLatency *)cdbe->GetObject();
820 if (!ctpLatencyObject) {
821 Log("cannot get \"CTPLatency\" object from CDB entry");
824 Float_t ctpLatency = ctpLatencyObject->GetCTPLatency();
825 Log(Form("got \"CTPLatency\" object: ctpLatency=%f (ps)", ctpLatency));
827 /* get file sources from FXS */
828 TList *fileList = GetFileSources(kDAQ, "HITS");
829 if (!fileList || fileList->GetEntries() == 0) {
830 Log("cannot get DAQ source file list or empty list");
833 Log(Form("got DAQ source file list: %d files", fileList->GetEntries()));
836 /* create tree chain using file sources */
837 TChain chain("hitTree");
838 for (Int_t ifile = 0; ifile < fileList->GetEntries(); ifile++) {
839 TObjString *str = (TObjString *)fileList->At(ifile);
840 TString filename = GetFile(kDAQ, "HITS", str->GetName());
842 Log(Form("file added to input chain: source=%s, filename=%s", str->String().Data(), filename.Data()));
844 Int_t nhits = chain.GetEntries();
845 Log(Form("input chain ready: %d hits", nhits));
847 /* setup input chain */
848 AliTOFHitField *hit = new AliTOFHitField();
849 chain.SetBranchAddress("hit", &hit);
851 /* create calib histo and geometry */
852 AliTOFcalibHisto calibHisto;
853 calibHisto.LoadCalibHisto();
854 AliTOFGeometry tofGeo;
857 Float_t c = TMath::C() * 1.e2 / 1.e12; /* cm/ps */
858 Float_t c_1 = 1. / c;
860 Int_t index, timebin, totbin, deltaBC, l0l1latency, det[5];
861 Float_t timeps, totns, corrps, length, timeexp, timezero, pos[3], latencyWindow;
864 TH1F *hT0Fill = new TH1F("hT0Fill", "T0 fill;t - t_{exp}^{(c)} (ps);", 2000, -24400., 24400.);
867 for (Int_t ihit = 0; ihit < nhits; ihit++) {
870 chain.GetEntry(ihit);
873 index = hit->GetIndex();
874 timebin = hit->GetTimeBin();
875 totbin = hit->GetTOTBin();
876 deltaBC = hit->GetDeltaBC();
877 l0l1latency = hit->GetL0L1Latency();
878 latencyWindow = fLatencyWindow[index] * 1.e3;
880 /* convert time in ps and tot in ns */
881 timeps = timebin * AliTOFGeometry::TdcBinWidth();
882 totns = totbin * AliTOFGeometry::ToTBinWidth() * 1.e-3;
883 /* get calibration correction in ps */
886 channelOffline = (AliTOFChannelOffline *)offlineArray->At(index);
887 if (totns < AliTOFGeometry::SlewTOTMin()) totns = AliTOFGeometry::SlewTOTMin();
888 if (totns > AliTOFGeometry::SlewTOTMax()) totns = AliTOFGeometry::SlewTOTMax();
890 for (Int_t ipar = 0; ipar < 6; ipar++) corrps += channelOffline->GetSlewPar(ipar) * TMath::Power(totns, ipar);
892 /* perform time correction */
893 // timeps = timeps + (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth() + l0l1latency * AliTOFGeometry::BunchCrossingBinWidth() + ctpLatency - latencyWindow - corrps; /* deltaBC correction removed for the time being */
894 timeps = timeps + l0l1latency * AliTOFGeometry::BunchCrossingBinWidth() + ctpLatency - latencyWindow - corrps;
895 /* compute length and expected time */
896 tofGeo.GetVolumeIndices(index, det);
897 tofGeo.GetPosPar(det, pos);
899 for (Int_t i = 0; i < 3; i++) length += pos[i] * pos[i];
900 length = TMath::Sqrt(length);
901 timeexp = length * c_1;
902 /* compute time zero */
903 timezero = timeps - timeexp;
906 hT0Fill->Fill(timezero);
909 /* rebin until maximum bin has required minimum entries */
910 Int_t maxBin = hT0Fill->GetMaximumBin();
911 Float_t maxBinContent = hT0Fill->GetBinContent(maxBin);
912 Float_t binWidth = hT0Fill->GetBinWidth(maxBin);
913 while (maxBinContent < 400 && binWidth < 90.) {
915 maxBin = hT0Fill->GetMaximumBin();
916 maxBinContent = hT0Fill->GetBinContent(maxBin);
917 binWidth = hT0Fill->GetBinWidth(maxBin);
919 Float_t maxBinCenter = hT0Fill->GetBinCenter(maxBin);
921 /* rough fit of the edge */
922 TF1 *gaus = (TF1 *)gROOT->GetFunction("gaus");
923 gaus->SetParameter(1, maxBinCenter);
924 Float_t fitMin = maxBinCenter - 1000.; /* fit from 1 ns before max */
925 Float_t fitMax = maxBinCenter + 1000.; /* fit until 1 ns above max */
926 hT0Fill->Fit("gaus", "q0", "", fitMin, fitMax);
927 /* better fit of the edge */
929 for (Int_t istep = 0; istep < 10; istep++) {
930 mean = gaus->GetParameter(1);
931 sigma = gaus->GetParameter(2);
932 fitMin = mean - 3. * sigma;
934 hT0Fill->Fit("gaus", "q0", "", fitMin, fitMax);
937 mean = gaus->GetParameter(1);
938 sigma = gaus->GetParameter(2);
939 Float_t meane = gaus->GetParError(1);
940 Float_t sigmae = gaus->GetParError(2);
941 Log(Form("edge fit: mean = %f +- %f ps", mean, meane));
942 Log(Form("edge fit: sigma = %f +- %f ps", sigma, sigmae));
945 Log("error on mean is large: store default T0-fill value (0 ps)");
949 Log("error on sigma is large: store default TOFreso value (200 ps)");
953 /* scratch values from the fit and use max bin center as t0-fill */
956 Log(Form("do not care about fitted value, just use max bin as t0-fill: %f ps", mean));
958 /* create RunParams object */
959 UInt_t timestamp[1] = {0};
960 Float_t t0[1] = {mean};
961 Float_t tofReso[1] = {sigma};
962 Float_t t0Spread[1] = {-1.};
963 AliTOFRunParams *runParamsObject = new AliTOFRunParams(1);
964 runParamsObject->SetTimestamp(timestamp);
965 runParamsObject->SetT0(t0);
966 runParamsObject->SetTOFResolution(tofReso);
967 runParamsObject->SetT0Spread(t0Spread);
968 runParamsObject->SetUseLHCClockPhase(kFALSE);
970 /* store reference data */
972 AliCDBMetaData metaDataHisto;
973 metaDataHisto.SetBeamPeriod(0);
974 metaDataHisto.SetResponsible("Roberto Preghenella");
975 metaDataHisto.SetComment("online T0-fill histogram");
976 if (!StoreReferenceData("Calib","T0Fill", hT0Fill, &metaDataHisto)) {
977 Log("error while storing reference data");
980 delete runParamsObject;
983 Log("reference data successfully stored");
986 AliCDBMetaData metaData;
987 metaData.SetBeamPeriod(0);
988 metaData.SetResponsible("Roberto Preghenella");
989 metaData.SetComment("online RunParams measurement");
990 if (!Store("Calib", "RunParams", runParamsObject, &metaData, 0, kFALSE)) {
991 Log("error while storing RunParams object");
994 delete runParamsObject;
997 Log("RunParams object successfully stored");
1001 delete runParamsObject;
1006 //_____________________________________________________________________________
1009 AliTOFPreprocessor::ProcessNoiseCalibTrg()
1011 // Processing data from DAQ using calibration triggers for noise measurement
1013 Log("Processing Noise (calibration trigger)");
1015 /* check status and matching window available */
1016 if (!fStatus || !fMatchingWindow){
1017 AliError("No valid fStatus or fMatchingWindow found, some errors must have occurred!!");
1021 Float_t noiseThr = 1000.; // setting default threshold for noise to 1000 Hz
1022 // reading config map
1023 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
1024 if (!cdbEntry) Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %f",noiseThr));
1026 TMap *configMap = (TMap*)cdbEntry->GetObject();
1027 if (!configMap) Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %f", noiseThr));
1029 TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
1031 TString tmpstr = strNoiseThr->GetString();
1032 noiseThr = tmpstr.Atoi();
1034 else Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %f",noiseThr));
1038 /* get file sources from FXS */
1039 TList *fileList = GetFileSources(kDAQ, "CALIB");
1040 if (!fileList || fileList->GetEntries() == 0) {
1041 Log("cannot get DAQ source file list or empty list");
1044 Log(Form("got DAQ source file list: %d files", fileList->GetEntries()));
1047 /* open input file (only one expected) */
1048 TObjString *str = (TObjString *)fileList->At(0);
1049 TString filename = GetFile(kDAQ, "CALIB", str->GetName());
1050 Log(Form("opening input file: source=%s, filename=%s", str->String().Data(), filename.Data()));
1051 TFile *filein = TFile::Open(filename.Data());
1052 if (!filein || !filein->IsOpen()) {
1053 Log("cannot open input file");
1057 /* get histo from input file */
1058 TH1F *hCalibHit = (TH1F *)filein->Get("hCalibHit");
1060 Log("cannot get \"hCalibHit\" histo");
1064 /* create and set noise rate histo and check rate */
1065 TH1F *hNoiseRate = new TH1F("hNoiseRate", ";index;rate (Hz)", fNChannels, 0., fNChannels);
1066 Float_t rate, rate_err;
1067 for (Int_t ich = 0; ich < fNChannels; ich++) {
1068 /* check channel enabled */
1069 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad) continue;
1070 /* set noise rate histo */
1071 rate = hCalibHit->GetBinContent(ich + 1);
1072 rate_err = hCalibHit->GetBinError(ich + 1);
1073 rate /= fMatchingWindow[ich] * 1.e-9;
1074 rate_err /= fMatchingWindow[ich] * 1.e-9;
1075 hNoiseRate->SetBinContent(ich + 1, rate);
1076 hNoiseRate->SetBinError(ich + 1, rate_err);
1078 if (rate_err == 0.) continue;
1079 /* check noise rate and set noise flags */
1080 if ((rate - 3. * rate_err) > noiseThr) {
1081 Log(Form("channel %d detected as noisy: rate = (%f +- %f) Hz", ich, rate, rate_err));
1082 if (fStatus->GetNoiseStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFNoiseOk) {
1083 Log(Form("channel %d noise status changed from Ok to Bad", ich));
1084 fStatus->SetNoiseStatus(ich, AliTOFChannelOnlineStatusArray::kTOFNoiseBad);
1085 fIsStatusMapChanged = kTRUE;
1087 else Log(Form("channel %d noise status unchanged", ich));
1089 else if ((rate + 3. * rate_err) < noiseThr) {
1090 if (fStatus->GetNoiseStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) {
1091 Log(Form("channel %d noise status changed from Bad to Ok", ich));
1092 fStatus->SetNoiseStatus(ich, AliTOFChannelOnlineStatusArray::kTOFNoiseOk);
1093 fIsStatusMapChanged = kTRUE;
1098 /* store reference data */
1100 AliCDBMetaData metaDataHisto;
1101 metaDataHisto.SetBeamPeriod(0);
1102 metaDataHisto.SetResponsible("Roberto Preghenella");
1103 metaDataHisto.SetComment("calibration trigger noise rate histogram");
1104 if (!StoreReferenceData("Calib","CalibNoise", hNoiseRate, &metaDataHisto)) {
1105 Log("error while storing reference data");
1110 Log("reference data successfully stored");
1118 //_____________________________________________________________________________
1121 AliTOFPreprocessor::ProcessReadout()
1123 // Processing data from DAQ to compute reaodut efficiency
1125 Log("Processing Readout");
1127 /* get file sources from FXS */
1128 TList *fileList = GetFileSources(kDAQ, "READOUT");
1129 if (!fileList || fileList->GetEntries() == 0) {
1130 Log("cannot get DAQ source file list or empty list");
1133 Log(Form("got DAQ source file list: %d files", fileList->GetEntries()));
1136 /* open input file (only one expected) */
1137 TObjString *str = (TObjString *)fileList->At(0);
1138 TString filename = GetFile(kDAQ, "READOUT", str->GetName());
1139 Log(Form("opening input file: source=%s, filename=%s", str->String().Data(), filename.Data()));
1140 TFile *filein = TFile::Open(filename.Data());
1141 if (!filein || !filein->IsOpen()) {
1142 Log("cannot open input file");
1146 /* get histo from input file */
1147 TH1F *hChainEfficiency = (TH1F *)filein->Get("hChainEfficiency");
1148 if (!hChainEfficiency) {
1149 Log("cannot get \"hChainEfficiency\" histo");
1153 /* fill channel efficiency histo */
1155 /* temporarly disable warnings */
1156 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
1157 AliLog::SetGlobalLogLevel(AliLog::kError);
1159 TH1F *hChannelEfficiency = new TH1F("hChannelEfficiency", "Channel readout efficiency;index;efficiency", fNChannels, 0., fNChannels);
1160 Int_t chainIndex, det[5], dummy, index;
1161 Float_t effi, effi_err;
1162 /* loop over DDLs */
1163 for (Int_t iddl = 0; iddl < 72; iddl++) {
1164 /* loop over TRMs */
1165 for (Int_t itrm = 0; itrm < 10; itrm++) {
1166 /* loop over chains */
1167 for (Int_t ichain = 0; ichain < 2; ichain++) {
1168 chainIndex = ichain + 2 * itrm + 20 * iddl;
1169 effi = hChainEfficiency->GetBinContent(chainIndex + 1);
1170 effi_err = hChainEfficiency->GetBinError(chainIndex + 1);
1171 /* loop over TDCs */
1172 for (Int_t itdc = 0; itdc < 15; itdc++) {
1173 /* loop over channels */
1174 for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
1176 /* get channel index */
1177 AliTOFRawStream::EquipmentId2VolumeId(iddl, itrm + 3, ichain, itdc, ichannel, det);
1181 /* check valid index */
1182 if (det[0] < 0 || det[0] > 17 ||
1183 det[1] < 0 || det[1] > 5 ||
1184 det[2] < 0 || det[2] > 18 ||
1185 det[3] < 0 || det[3] > 1 ||
1186 det[4] < 0 || det[4] > 47) continue;
1187 index = AliTOFGeometry::GetIndex(det);
1189 /* set channel efficiency */
1190 hChannelEfficiency->SetBinContent(index + 1, effi);
1191 hChannelEfficiency->SetBinError(index + 1, effi_err);
1199 /* re-enable warnings */
1200 AliLog::SetGlobalLogLevel(logLevel);
1202 /* store reference data */
1204 /* setup TOF readout info object */
1205 AliTOFReadoutInfo readoutInfo;
1206 readoutInfo.SetChainEfficiency((TH1F *)filein->Get("hChainEfficiency"));
1207 readoutInfo.SetTRMData((TH1F *)filein->Get("hTRMData"));
1208 readoutInfo.SetTRMEmptyEvent((TH1F *)filein->Get("hTRMEmptyEvent"));
1209 readoutInfo.SetTRMBadEventCounter((TH1F *)filein->Get("hTRMBadEventCounter"));
1210 readoutInfo.SetTRMBadCRC((TH1F *)filein->Get("hTRMBadCRC"));
1211 readoutInfo.SetChainData((TH1F *)filein->Get("hChainData"));
1212 readoutInfo.SetChainBadStatus((TH1F *)filein->Get("hChainBadStatus"));
1213 readoutInfo.SetChainBadEventCounter((TH1F *)filein->Get("hChainBadEventCounter"));
1214 readoutInfo.SetTDCError((TH1F *)filein->Get("hTDCError"));
1215 readoutInfo.SetTDCErrorFlags((TH2F *)filein->Get("hTDCErrorFlags"));
1217 AliCDBMetaData metaDataHisto;
1218 metaDataHisto.SetBeamPeriod(0);
1219 metaDataHisto.SetResponsible("Roberto Preghenella");
1220 metaDataHisto.SetComment("readout info data");
1221 if (!StoreReferenceData("Calib","ReadoutInfo", &readoutInfo, &metaDataHisto)) {
1222 Log("error while storing reference data");
1226 Log("reference data successfully stored");
1229 AliCDBMetaData metaData;
1230 metaData.SetBeamPeriod(0);
1231 metaData.SetResponsible("Roberto Preghenella");
1232 metaData.SetComment("online ReadoutEfficiency measurement");
1233 if (!Store("Calib", "ReadoutEfficiency", hChannelEfficiency, &metaData, 0, kFALSE)) {
1234 Log("error while storing ReadoutEfficiency object");
1235 delete hChannelEfficiency;
1239 Log("ReadoutEfficiency object successfully stored");
1241 delete hChannelEfficiency;
1246 //_____________________________________________________________________________
1248 UInt_t AliTOFPreprocessor::ProcessPulserData()
1250 // Processing Pulser Run data for TOF channel status
1252 Log("Processing Pulser");
1255 AliError("No valid fStatus found, some errors must have occurred!!");
1259 TH1::AddDirectory(0);
1261 Bool_t resultPulserRef=kFALSE;
1262 Bool_t resultPulser=kFALSE;
1264 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
1265 TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5);
1266 for (Int_t ibin =1;ibin<=kSize;ibin++){
1267 htofPulser->SetBinContent(ibin,-1);
1270 // processing pulser
1272 TFile * daqFile=0x0;
1275 //retrieving Pulser data
1276 TList* listPulser = GetFileSources(kDAQ, "PULSER");
1277 if (listPulser !=0x0 && listPulser->GetEntries()!=0)
1279 AliInfo("The following sources produced files with the id PULSER");
1280 listPulser->Print();
1282 for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
1283 Int_t nPulserSource = 0;
1284 TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
1286 AliError("dynamic_cast returned NULL");
1289 AliInfo(Form("found source %s", str->String().Data()));
1290 // file to be stored run per run
1291 TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
1292 if (fileNamePulser.Length()>0){
1293 // storing refernce data
1294 AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data()));
1295 daqFile = new TFile(fileNamePulser.Data(),"READ");
1296 h1 = (TH1S*) daqFile->Get("hTOFpulser");
1297 for (Int_t ibin=0;ibin<kSize;ibin++){
1298 if ((h1->GetBinContent(ibin+1))!=-1){
1299 if ((htofPulser->GetBinContent(ibin+1))==-1){
1300 htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
1303 Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin));
1308 // elaborating infos
1311 Int_t nreadNotEmpty=0;
1312 for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){
1314 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)));
1315 /* check whether channel has been read out during current run.
1316 * if the status is bad it means it has not been read out.
1317 * in this case skip channel in order to not affect the mean */
1318 if (fStatus->GetHWStatus(ientry-1) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1322 if (h1->GetBinContent(ientry)==-1) continue;
1324 if (h1->GetBinContent(ientry)>0) {
1326 AliDebug(2,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty));
1328 mean+=h1->GetBinContent(ientry);
1334 AliDebug(2,Form(" nread = %i , nreadNotEmpty = %i, mean = %f",nread,nreadNotEmpty,mean));
1335 for (Int_t ich =0;ich<fNChannels;ich++){
1336 if (h1->GetBinContent(ich+1)==-1) continue;
1337 AliDebug(3,Form(" channel %i pulser status before pulser = %i",ich,(Int_t)fStatus->GetPulserStatus(ich)));
1339 /* check whether channel has been read out during current run.
1340 * if the status is bad it means it has not been read out.
1341 * in this case skip channel in order to leave its status
1343 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1346 if (h1->GetBinContent(ich+1)<0.05*mean){
1347 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserBad); // bad status for pulser
1348 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)));
1351 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserOk); // good status for pulser
1352 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)));
1357 Log("No channels read!! No action taken, keeping old status");
1366 Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle ");
1374 return 10;//return error code for failure in retrieving Ref Data
1376 AliDebug(2,Form(" Number of channels processed during pulser run from source %i = %i",jj, nPulserSource));
1378 AliDebug(2,Form(" Number of channels processed during pulser run = %i",nPulser));
1383 Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle ");
1390 return 10;//return error code for failure in retrieving Ref Data
1395 AliCDBMetaData metaData;
1396 metaData.SetBeamPeriod(0);
1397 metaData.SetResponsible("Chiara Zampolli");
1398 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Pulser run.");
1399 AliInfo("Storing Calibration Data from Pulser Run");
1400 resultPulser = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
1402 Log("Some problems occurred while storing online object resulting from Pulser data processing");
1409 return 11;//return error code for problems in storing Pulser data
1414 AliCDBMetaData metaDataHisto;
1415 metaDataHisto.SetBeamPeriod(0);
1416 metaDataHisto.SetResponsible("Chiara Zampolli");
1417 metaDataHisto.SetComment("This preprocessor stores the Ref data from a pulser run.");
1418 AliInfo("Storing Reference Data");
1419 resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
1420 if (!resultPulserRef){
1421 Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle");
1428 return 9;//return error code for failure in storing Ref Data
1444 //_____________________________________________________________________________
1446 UInt_t AliTOFPreprocessor::ProcessNoiseData()
1449 // Processing Noise Run data for TOF channel status
1451 Log("Processing Noise");
1454 AliError("No valid fStatus found, some errors must have occurred!!");
1458 Float_t noiseThr = 1; // setting default threshold for noise to 1 Hz
1459 // reading config map
1460 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
1462 Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %f",noiseThr));
1465 TMap *configMap = (TMap*)cdbEntry->GetObject();
1467 Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %f", noiseThr));
1470 TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
1472 TString tmpstr = strNoiseThr->GetString();
1473 noiseThr = tmpstr.Atoi();
1476 Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %f",noiseThr));
1484 TH1::AddDirectory(0);
1486 Bool_t resultNoiseRef=kFALSE;
1487 Bool_t resultNoise=kFALSE;
1489 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
1490 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", kSize,-0.5,kSize-0.5);
1491 for (Int_t ibin =1;ibin<=kSize;ibin++){
1492 htofNoise->SetBinContent(ibin,-1);
1497 TFile * daqFile=0x0;
1502 Int_t nNoisyChannels = 0;
1503 Int_t nNotNoisyChannels = 0;
1504 Int_t nChannelsFromDA = 0;
1505 Int_t nMatchingWindowNullNonZero = 0;
1506 Int_t nMatchingWindowNullEqualZero = 0;
1508 // retrieving Noise data
1509 TList* listNoise = GetFileSources(kDAQ, "NOISE");
1510 if (listNoise !=0x0 && listNoise->GetEntries()!=0)
1512 AliInfo("The following sources produced files with the id NOISE");
1514 for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
1515 Int_t nNoiseSource = 0;
1516 TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
1518 AliError("dynamic_cast returned NULL");
1521 AliInfo(Form("found source %s", str->String().Data()));
1522 // file to be stored run per run
1523 TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
1524 if (fileNameNoise.Length()>0){
1525 // storing reference data
1526 AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data()));
1527 daqFile = new TFile(fileNameNoise.Data(),"READ");
1528 h1 = (TH1F*) daqFile->Get("hTOFnoise");
1529 for (Int_t ibin=0;ibin<kSize;ibin++){
1530 if ((h1->GetBinContent(ibin+1))!=-1){
1532 // checking the matching window for current channel
1533 if (fMatchingWindow[ibin] == 0){
1534 Log(Form("Matching window for channel %i null, but the channel was read by the LDC! skipping channel, BUT Please check!",ibin));
1535 if ((h1->GetBinContent(ibin+1))!=0) nMatchingWindowNullNonZero++;
1536 if ((h1->GetBinContent(ibin+1))==0) nMatchingWindowNullEqualZero++;
1539 if ((htofNoise->GetBinContent(ibin+1))==-1){
1540 htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)/(fMatchingWindow[ibin]*1.E-9));
1541 if ((h1->GetBinContent(ibin+1))!= 0) AliDebug(2,Form("Channel = %i, Matching window = %i, Content = %f", ibin, fMatchingWindow[ibin], htofNoise->GetBinContent(ibin+1)));
1544 Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin));
1549 Log(Form(" Number of channels processed during noise run from source %i = %i",jj, nNoiseSource));
1558 Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle ");
1567 if (fMatchingWindow){
1568 delete [] fMatchingWindow;
1569 fMatchingWindow = 0;
1571 return 13;//return error code for failure in retrieving Ref Data
1577 Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle ");
1584 if (fMatchingWindow){
1585 delete [] fMatchingWindow;
1586 fMatchingWindow = 0;
1588 return 13;//return error code for failure in retrieving Ref Data
1591 // elaborating infos to set NOISE status
1592 for (Int_t ich =0;ich<fNChannels;ich++){
1593 if (htofNoise->GetBinContent(ich+1)== -1) continue;
1597 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)));
1598 //AliDebug(2,Form( " channel %i status before noise = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich)));
1600 /* check whether channel has been read out during current run.
1601 * if the status is bad it means it has not been read out.
1602 * in this case skip channel in order to leave its status
1605 if ((fStatus->GetHWStatus(ich)) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1609 if (htofNoise->GetBinContent(ich+1) >= noiseThr){
1610 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseBad); // bad status for noise
1611 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)));
1615 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseOk); // good status for noise
1616 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)));
1617 nNotNoisyChannels++;
1621 Log(Form(" Number of channels processed by DA during noise run, independetly from TOFFEE = %i",nChannelsFromDA));
1622 Log(Form(" Number of channels processed during noise run (that were ON according to TOFFEE) = %i",nNoise));
1623 Log(Form(" Number of noisy channels found during noise run = %i",nNoisyChannels));
1624 Log(Form(" Number of not noisy channels found during noise run = %i",nNotNoisyChannels));
1625 Log(Form(" Number of channels with matching window NULL (so skipped), but Non Zero content = %i",nMatchingWindowNullNonZero));
1626 Log(Form(" Number of channels with matching window NULL (so skipped), and Zero content = %i",nMatchingWindowNullEqualZero));
1634 AliCDBMetaData metaData;
1635 metaData.SetBeamPeriod(0);
1636 metaData.SetResponsible("Chiara Zampolli");
1637 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Noise run.");
1638 AliInfo("Storing Calibration Data from Noise Run");
1639 resultNoise = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
1641 Log("Some problems occurred while storing online object resulting from Noise data processing");
1648 if (fMatchingWindow){
1649 delete [] fMatchingWindow;
1650 fMatchingWindow = 0;
1652 return 14;//return error code for problems in storing Noise data
1657 AliCDBMetaData metaDataHisto;
1658 metaDataHisto.SetBeamPeriod(0);
1659 metaDataHisto.SetResponsible("Chiara Zampolli");
1660 metaDataHisto.SetComment("This preprocessor stores the Ref data from a noise run. ");
1661 AliInfo("Storing Reference Data");
1662 resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
1663 if (!resultNoiseRef){
1664 Log("some problems occurred::No Reference Data for noise stored");
1671 if (fMatchingWindow){
1672 delete [] fMatchingWindow;
1673 fMatchingWindow = 0;
1675 return 12;//return error code for failure in storing Ref Data
1687 if (fMatchingWindow){
1688 delete [] fMatchingWindow;
1689 fMatchingWindow = 0;
1694 //_____________________________________________________________________________
1696 UInt_t AliTOFPreprocessor::ProcessFEEData()
1698 // Processing Pulser Run data for TOF channel status
1699 // dummy for the time being
1701 Log("Processing FEE");
1703 //Bool_t updateOCDB = kFALSE;
1704 AliTOFFEEReader feeReader;
1706 TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels);
1708 /* load current TOF FEE(dump) from DCS FXS,
1709 * setup TOFFEEdump object */
1711 const char * toffeeFileName = GetFile(kDCS,"TofFeeMap","");
1712 AliInfo(Form("toffee file name = %s", toffeeFileName));
1713 if (toffeeFileName == NULL) {
1716 AliTOFFEEDump feedump;
1717 feedump.ReadFromFile(toffeeFileName);
1719 /* load current TOF FEE(light) config from DCS FXS, parse,
1720 * fill current FEE histogram and set FEE status */
1722 const char * nameFile = GetFile(kDCS,"TofFeeLightMap","");
1723 AliInfo(Form("toffeeLight file name = %s",nameFile));
1724 if (nameFile == NULL) {
1727 feeReader.LoadFEElightConfig(nameFile);
1728 Int_t parseFee = feeReader.ParseFEElightConfig();
1729 AliDebug(2,Form("%i enabled channels found in FEElight configuration",parseFee));
1730 /* load stored TOF FEE from OCDB and compare it with current FEE.
1731 * if stored FEE is different from current FEE set update flag.
1732 * if there is no stored FEE in OCDB set update flag */
1734 fMatchingWindow = new Int_t[fNChannels];
1735 fLatencyWindow = new Int_t[fNChannels];
1737 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Status");
1739 /* no CDB entry found. set update flag */
1740 Log(" ************ WARNING ************");
1741 Log("No CDB Status entry found, creating a new one!");
1742 Log(" *********************************");
1743 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1744 //updateOCDB = kTRUE;
1745 fIsStatusMapChanged = kTRUE;
1748 if (cdbEntry) cdbEntry->SetOwner(kFALSE);
1749 /* CDB entry OK. loop over channels */
1750 fStatus = (AliTOFChannelOnlineStatusArray*) cdbEntry->GetObject();
1753 /* cehck whether status object has latency window data */
1754 if (!fStatus->HasLatencyWindow()) {
1755 /* create new status object and update OCDB */
1756 Log(" ************ WARNING ************");
1757 Log("CDB Status entry found but has no latency window data, creating a new one!");
1758 Log(" *********************************");
1760 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1761 //updateOCDB = kTRUE;
1762 fIsStatusMapChanged = kTRUE;
1765 for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){
1766 //AliDebug(2,Form("********** channel %i",iChannel));
1767 /* compare current FEE channel status with stored one
1768 * if different set update flag and break loop */
1769 //AliDebug(2,Form( " channel %i status before FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1770 fMatchingWindow[iChannel] = feeReader.GetMatchingWindow(iChannel);
1771 fLatencyWindow[iChannel] = feeReader.GetLatencyWindow(iChannel);
1772 if (feeReader.IsChannelEnabled(iChannel)) {
1773 hCurrentFEE.SetBinContent(iChannel + 1, 1);
1774 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWOk){
1775 //updateOCDB = kTRUE;
1776 fIsStatusMapChanged = kTRUE;
1777 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWOk);
1778 AliDebug(3,Form( " changed into enabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1780 if (fStatus->GetLatencyWindow(iChannel)!=fLatencyWindow[iChannel]){
1781 //updateOCDB = kTRUE;
1782 fIsStatusMapChanged = kTRUE;
1783 fStatus->SetLatencyWindow(iChannel,fLatencyWindow[iChannel]);
1784 AliDebug(3,Form( " changed latency window: channel %i latency window after FEE = %i",iChannel,fStatus->GetLatencyWindow(iChannel)));
1788 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWBad){
1789 //updateOCDB = kTRUE;
1790 fIsStatusMapChanged = kTRUE;
1791 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWBad);
1792 AliDebug(3,Form( " changed into disabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1798 /* check whether we don't have to store reference data.
1799 * in this case we return without errors. */
1800 if (fStoreRefData) {
1801 /* store reference data */
1802 AliCDBMetaData metaDataHisto;
1803 metaDataHisto.SetBeamPeriod(0);
1804 metaDataHisto.SetResponsible("Roberto Preghenella");
1805 metaDataHisto.SetComment("This preprocessor stores the FEE Ref data of the current run.");
1806 AliInfo("Storing FEE reference data");
1807 /* store FEE reference data */
1808 if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) {
1810 Log("problems while storing FEE reference data");
1815 return 18; /* error return code for problems while storing FEE reference data */
1818 /* store TOF FEE dump reference data */
1819 AliCDBMetaData metaDatadump;
1820 metaDatadump.SetBeamPeriod(0);
1821 metaDatadump.SetResponsible("Roberto Preghenella");
1822 metaDatadump.SetComment("This preprocessor stores the TOF FEE dump Ref data of the current run.");
1823 AliInfo("Storing TOF FEE dump reference data");
1824 /* store FEE reference data */
1825 if (!StoreReferenceData("Calib", "FEEDump", &feedump, &metaDatadump)) {
1827 Log("problems while storing TOF FEE dump reference data");
1828 return 18; /* error return code for problems while storing FEE reference data */
1836 //_____________________________________________________________________________
1838 UInt_t AliTOFPreprocessor::Process(TMap *dcsAliasMap)
1841 // Main AliTOFPreprocessor method called by SHUTTLE
1844 TString runType = GetRunType();
1845 Log(Form("RunType %s",runType.Data()));
1849 /* always process FEE data */
1850 Int_t iresultFEE = ProcessFEEData();
1851 if (iresultFEE != 0)
1854 if (runType == "PULSER") {
1855 Int_t iresultPulser = ProcessPulserData();
1856 return iresultPulser;
1859 if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined
1860 Int_t iresultNoise = ProcessNoiseData();
1861 return iresultNoise;
1864 if (runType == "PHYSICS") {
1865 // Int_t iresultDAQ = ProcessOnlineDelays();
1866 Int_t iresultDAQ = ProcessT0Fill();
1867 Int_t iresultNoiseCalib = ProcessNoiseCalibTrg();
1868 Int_t iresultReadout = ProcessReadout();
1869 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
1870 Int_t iResultHVandLVdps = ProcessHVandLVdps(dcsAliasMap);
1871 return iresultDAQ+iresultNoiseCalib+iresultDCS+iResultHVandLVdps+iresultReadout;
1879 //_____________________________________________________________________________
1882 AliTOFPreprocessor::FillWithCosmicCalibration(AliTOFChannelOnlineArray *cal)
1885 * fill with cosmic calibration
1888 Log(" Using cosmic-ray calibration.");
1890 AliTOFcalibHisto calibHisto;
1891 calibHisto.SetFullCorrectionFlag(AliTOFcalibHisto::kTimeSlewingCorr, kFALSE);
1892 Log(Form(" loading calibration histograms from %s", calibHisto.GetCalibHistoFileName()));
1893 Log(Form(" loading calibration parameters from %s", calibHisto.GetCalibParFileName()));
1894 calibHisto.LoadCalibPar();
1896 /* loop over channel index */
1897 for (Int_t iIndex = 0; iIndex < fNChannels; iIndex++) {
1898 cal->SetDelay(iIndex, calibHisto.GetFullCorrection(iIndex));
1903 //_____________________________________________________________________________
1906 AliTOFPreprocessor::FillWithCableLengthMap(AliTOFChannelOnlineArray *cal)
1909 * fill with cosmic calibration
1912 Log(" Using cable-length map.");
1913 AliTOFRawStream tofrs;
1914 Int_t det[5], dummy, index;
1915 Float_t cableTimeShift;
1917 /* temporarly disable warnings */
1918 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
1919 AliLog::SetGlobalLogLevel(AliLog::kError);
1921 /* loop over EO indeces */
1922 for (Int_t iddl = 0; iddl < 72; iddl++)
1923 for (Int_t islot = 3; islot <= 12; islot++)
1924 for (Int_t ichain = 0; ichain < 2; ichain++)
1925 for (Int_t itdc = 0; itdc < 15; itdc++)
1926 for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
1929 tofrs.EquipmentId2VolumeId(iddl, islot, ichain, itdc, ichannel, det);
1931 /* swap det[3] and det[4] indeces (needed to obtain correct channel index) */
1936 /* check DO index */
1937 if (det[0] < 0 || det[0] > 17 ||
1938 det[1] < 0 || det[1] > 4 ||
1939 det[2] < 0 || det[2] > 18 ||
1940 det[3] < 0 || det[3] > 1 ||
1941 det[4] < 0 || det[4] > 47)
1944 /* get channel index */
1945 index = AliTOFGeometry::GetIndex(det);
1946 if (index < 0) continue;
1948 /* get cable time shift */
1949 cableTimeShift = AliTOFCableLengthMap::GetCableTimeShift(iddl, islot, ichain, itdc);
1952 if (index<fNChannels) {
1953 cal->SetDelay(index,cableTimeShift); // delay in ns
1954 AliDebug(2,Form("Setting delay %f (ns) for channel %i",cableTimeShift,index));
1957 } /* loop over EO indeces */
1959 /* re-enable warnings */
1960 AliLog::SetGlobalLogLevel(logLevel);