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 "AliTOFT0Fill.h"
51 #include "AliTOFT0FillOnlineCalib.h"
52 #include "AliTOFHitField.h"
53 #include "AliTOFChannelOffline.h"
55 #include "TGeoManager.h"
56 #include "AliGeomManager.h"
58 // TOF preprocessor class.
59 // It takes data from DCS and passes them to the class AliTOFDataDCS, which
60 // processes them. The result is then written to the CDB.
61 // Analogously, it takes data form DAQ (both at Run level and inclusive -
62 // of all the runs - level, processes them, and stores both Reference Data
63 // and Online Calibration files in the CDB.
64 // Processing of Pulser/Noise Run data and of TOF FEE DCS map included also.
68 // return=1 : no DCS input data Map
69 // return=2 : no DCS input data processing
70 // return=3 : no DCS processed data was stored in Ref Data
71 // return=4 : no DAQ input for Ref Data
72 // return=5 : failed to store DAQ Ref Data
73 // return=6 : failed to retrieve DAQ data for calibration
74 // return=7 : problems in processing histos in the input DAQ file
75 // return=8 : failed to store Online Delays
76 // return=9 : failed to store Reference Data for Pulser
77 // return=10: failed to retrieve Pulser data
78 // return=11: failed to store Pulser map in OCDB
79 // return=12: failed to store Reference Data for Noise
80 // return=13: failed to retrieve Noise data
81 // return=14: failed to store Noise map in OCDB
82 // return=15: failed to retrieve FEE data from FXS
83 // return=16: failed to retrieve FEE data from OCDB
84 // return=17: failed to store FEE data in OCDB
85 // return=18: failed to store FEE reference data in OCDB
86 // return=20: failed in retrieving status variable
87 // return=100 : no DCS input data Map (HV and LV status)
88 // return=200 : no DCS input data processing (HV and LV status)
89 // return=300 : no DCS processed data was stored in Ref Data (HV and LV status)
91 ClassImp(AliTOFPreprocessor)
93 const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean
94 const Double_t AliTOFPreprocessor::fgkIntegralThr = 100; // min number of entries to perform computation of delay per channel
95 const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay
97 //_____________________________________________________________________________
99 AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
100 AliPreprocessor("TOF", shuttle),
105 fStoreRefData(kTRUE),
110 fIsStatusMapChanged(0)
113 AddRunType("PHYSICS");
114 AddRunType("PULSER");
119 //_____________________________________________________________________________
121 AliTOFPreprocessor::~AliTOFPreprocessor()
126 //______________________________________________________________________________
127 void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
130 // Creates AliTOFDataDCS object
132 AliPreprocessor::Initialize(run, startTime, endTime);
134 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s \n\tStartTime DCS Query %s \n\tEndTime DCS Query %s", run,
135 TTimeStamp(startTime).AsString(),
136 TTimeStamp(endTime).AsString(), ((TTimeStamp)GetStartTimeDCSQuery()).AsString(), ((TTimeStamp)GetEndTimeDCSQuery()).AsString()));
138 fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
139 fHVLVmaps = new AliTOFLvHvDataPoints(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
140 fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
142 //_____________________________________________________________________________
143 Bool_t AliTOFPreprocessor::ProcessDCS(){
145 // check whether DCS should be processed or not...
147 TString runType = GetRunType();
148 Log(Form("RunType %s",runType.Data()));
150 if (runType != "PHYSICS"){
156 //_____________________________________________________________________________
158 UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap *dcsAliasMap)
160 // Fills data into a AliTOFDataDCS object
163 Log("Processing DCS DP");
164 TH1::AddDirectory(0);
166 Bool_t resultDCSMap=kFALSE;
167 Bool_t resultDCSStore=kFALSE;
171 fData->SetFDRFlag(fFDRFlag);
174 Log("No DCS map found: TOF exiting from Shuttle");
179 return 1;// return error Code for DCS input data not found
183 // The processing of the DCS input data is forwarded to AliTOFDataDCS
184 resultDCSMap=fData->ProcessData(*dcsAliasMap);
186 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
191 return 2;// return error Code for processed DCS data not stored
194 AliCDBMetaData metaDataDCS;
195 metaDataDCS.SetBeamPeriod(0);
196 metaDataDCS.SetResponsible("Chiara Zampolli");
197 metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
198 AliInfo("Storing DCS Data");
199 resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
200 if (!resultDCSStore){
201 Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
206 return 3;// return error Code for processed DCS data not stored
219 //_____________________________________________________________________________
221 UInt_t AliTOFPreprocessor::ProcessHVandLVdps(TMap *dcsAliasMap)
224 //Fills data into a AliTOFLvHvDataPoints object
225 // Merges fStatus object with LV and HV status at SOR
226 // Updates fStatus object with LV and HV status
227 // at EOR in case of correct end of run
228 // at last but two value in case of end-of-run caused by TOF detector.
231 Log("Processing HV and LV DCS DPs");
232 TH1::AddDirectory(0);
234 Bool_t resultDCSMap=kFALSE;
236 // processing DCS HV and LV data points
238 fHVLVmaps->SetFDRFlag(fFDRFlag);
241 Log("No DCS map found: TOF exiting from Shuttle");
246 return 100;// return error Code for DCS input data not found
250 // The processing of the DCS input data is forwarded to AliTOFDataDCS
252 resultDCSMap = fHVLVmaps->ProcessData(*dcsAliasMap);
254 Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
259 return 200;// return error Code for processed DCS data not stored
263 // check with plots. Start...
265 TH1F *hROsor = new TH1F("hROsor","RO status map at SOR",91*96*18,-0.5,91*96*18-0.5);
266 for (Int_t ii=1; ii<=91*96*18; ii++) hROsor->SetBinContent(ii,-1);
267 for (Int_t ii=0; ii<91*96*18; ii++) {
268 if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
269 hROsor->SetBinContent(ii+1,0);
270 else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
271 hROsor->SetBinContent(ii+1,1);
274 TH1F *hROandHVandLVsor = new TH1F("hROandHVandLVsor","RO.and.HV.andLV status map at SOR",91*96*18,-0.5,91*96*18-0.5);
275 for (Int_t ii=1; ii<=91*96*18; ii++) hROandHVandLVsor->SetBinContent(ii,-1);
276 TH1F *hROandHVandLVeor = new TH1F("hROandHVandLVeor","RO.and.HV.andLV status map at EOR",91*96*18,-0.5,91*96*18-0.5);
277 for (Int_t ii=1; ii<=91*96*18; ii++) hROandHVandLVeor->SetBinContent(ii,-1);
280 AliTOFDCSmaps * lvANDhvMap = (AliTOFDCSmaps*)fHVLVmaps->GetHVandLVmapAtSOR(); // Get LV.and.HV status map at SOR
281 for (Int_t index=0; index<fNChannels; index++) {
282 if ( ( lvANDhvMap->GetCellValue(index)==0 &&
283 fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWBad ) ||
284 ( lvANDhvMap->GetCellValue(index)==1 &&
285 fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWOk ) ) {
286 fStatus->SetHWStatus(index, AliTOFChannelOnlineStatusArray::kTOFHWBad);
287 fIsStatusMapChanged=kTRUE;
291 // check with plots. Start...
293 for (Int_t ii=0; ii<91*96*18; ii++) {
294 if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
295 hROandHVandLVsor->SetBinContent(ii+1,0);
296 else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
297 hROandHVandLVsor->SetBinContent(ii+1,1);
301 lvANDhvMap = (AliTOFDCSmaps*)fHVLVmaps->GetHVandLVmapAtEOR(); // Get LV.and.HV status map at EOR
302 for (Int_t index=0; index<fNChannels; index++) {
303 if ( ( lvANDhvMap->GetCellValue(index)==0 &&
304 fStatus->GetHWStatus(index)!=AliTOFChannelOnlineStatusArray::kTOFHWBad ) ||
305 ( lvANDhvMap->GetCellValue(index)==1 &&
306 fStatus->GetHWStatus(index) != AliTOFChannelOnlineStatusArray::kTOFHWOk ) ) {
307 fStatus->SetHWStatus(index, AliTOFChannelOnlineStatusArray::kTOFHWBad);
308 fIsStatusMapChanged=kTRUE;
312 // check with plots. Start...
314 for (Int_t ii=0; ii<91*96*18; ii++) {
315 if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWBad)
316 hROandHVandLVeor->SetBinContent(ii+1,0);
317 else if (fStatus->GetHWStatus(ii)==AliTOFChannelOnlineStatusArray::kTOFHWOk)
318 hROandHVandLVeor->SetBinContent(ii+1,1);
321 TCanvas *canvas = new TCanvas("canvas","",10,10,1000,1000);
322 canvas->SetFillColor(0);
325 hROsor->SetLineWidth(2);
328 hROandHVandLVsor->SetLineWidth(2);
329 hROandHVandLVsor->Draw();
331 hROandHVandLVeor->SetLineWidth(2);
332 hROandHVandLVeor->Draw();
341 /* check whether we don't need to update OCDB.
342 * in this case we can return without errors. */
344 if (!fIsStatusMapChanged) {
345 AliInfo("TOF HW status config has not changed. Do not overwrite stored file.");
346 return 0; // return ok
349 TString runType = GetRunType();
350 if (runType != "PHYSICS") {
351 AliInfo(Form("Run Type = %s, waiting to store status map",GetRunType()));
352 return 0; // return ok
355 // update the OCDB with the current FEE.and.HV.and.LV
356 // since even a little difference has been detected.
358 AliCDBMetaData metaData;
359 metaData.SetBeamPeriod(0);
360 metaData.SetResponsible("Roberto Preghenella");
361 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object from FEE.and.HV.and.LV data.");
362 AliInfo("Storing Status data from current run. Collected RO.and.HV.and.LV infos @ EOR");
363 // store TOF channel status
364 if (!Store("Calib", "Status", fStatus, &metaData, 0, kTRUE)) {
366 Log("problems while storing RO.and.HV.and.LV Status data object");
375 return 17; // return error code for problems while TOF channel status
378 // everything fine. return
393 //_____________________________________________________________________________
395 UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
397 // Processing data from DAQ for online calibration
399 Bool_t updateOCDB = kFALSE;
400 Log("Processing DAQ delays");
402 // reading configuration map
403 TString compDelays = "kFALSE";
404 Int_t deltaStartingRun = fRun;
405 Int_t startingRun = fRun-deltaStartingRun;
406 Int_t binRangeAve = fgkBinRangeAve;
407 Double_t integralThr = fgkIntegralThr;
408 Double_t thrPar = fgkThrPar;
410 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Config");
412 Log(Form("No Configuration entry found in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
415 TMap *configMap = (TMap*)cdbEntry->GetObject();
417 Log(Form("No map found in Config entry in CDB, using default values: ComputingDelays = %s, StartingRun = %i",compDelays.Data(), startingRun));
420 TObjString *strDelays = (TObjString*)configMap->GetValue("ComputingDelays");
422 compDelays = (TString) strDelays->GetString();
425 Log(Form("No ComputingDelays value found in Map from Config entry in CDB, using default value: ComputingDelays = %s",compDelays.Data()));
427 TObjString *strRun = (TObjString*)configMap->GetValue("StartingRun");
429 TString tmpstr = strRun->GetString();
430 startingRun = tmpstr.Atoi();
431 deltaStartingRun = fRun - startingRun;
434 Log(Form("No StartingRun value found in Map from Config entry in CDB, using default value: StartingRun = %i",startingRun));
436 TObjString *strBinRangeAve = (TObjString*)configMap->GetValue("BinRangeAve");
437 if (strBinRangeAve) {
438 TString tmpstr = strBinRangeAve->GetString();
439 binRangeAve = tmpstr.Atoi();
442 Log(Form("No BinRangeAve value found in Map from Config entry in CDB, using default value: BinRangeAve = %i",binRangeAve));
444 TObjString *strIntegralThr = (TObjString*)configMap->GetValue("IntegralThr");
445 if (strIntegralThr) {
446 TString tmpstr = strIntegralThr->GetString();
447 integralThr = tmpstr.Atof();
450 Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %i",integralThr));
452 TObjString *strThrPar = (TObjString*)configMap->GetValue("ThrPar");
454 TString tmpstr = strThrPar->GetString();
455 thrPar = tmpstr.Atof();
458 Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %i",thrPar));
462 if (compDelays == "kTRUE") fFDRFlag = kFALSE;
463 else fFDRFlag = kTRUE;
468 Log(Form("ComputingDelays = %s, StartingRun = %i",compDelays.Data(),startingRun));
470 /* init array with current calibration, if any */
471 fCal = new AliTOFChannelOnlineArray(fNChannels);
472 AliTOFChannelOnlineArray *curCal = NULL;
474 AliCDBEntry *cdbEntry2 = GetFromOCDB("Calib","ParOnlineDelay");
475 if (!cdbEntry2 || !cdbEntry2->GetObject()) {
476 /* no CDB entry found. set update flag */
477 Log(" ************ WARNING ************");
478 Log("No CDB ParOnlineDelay entry found, creating a new one!");
479 Log(" *********************************");
483 Log("Found previous ParOnlineDelay entry. Using it to init calibration");
484 curCal = (AliTOFChannelOnlineArray *)cdbEntry2->GetObject();
485 for (Int_t i = 0; i < fNChannels; i++)
486 fCal->SetDelay(i, curCal->GetDelay(i));
490 TH1::AddDirectory(0);
492 Bool_t resultDAQRef=kFALSE;
493 Bool_t resultTOFPP=kFALSE;
500 //retrieving data at Run level
501 TList* list = GetFileSources(kDAQ, "RUNLevel");
502 if (list !=0x0 && list->GetEntries()!=0)
504 AliInfo("The following sources produced files with the id RUNLevel");
506 for (Int_t jj=0;jj<list->GetEntries();jj++){
507 TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
508 AliInfo(Form("found source %s", str->String().Data()));
509 // file to be stored run per run
510 TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
511 if (fileNameRun.Length()>0){
512 AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
513 daqFile = new TFile(fileNameRun.Data(),"READ");
514 h2 = (TH2S*) daqFile->Get("htof");
515 AliCDBMetaData metaDataHisto;
516 metaDataHisto.SetBeamPeriod(0);
517 metaDataHisto.SetResponsible("Chiara Zampolli");
518 metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
519 AliInfo("Storing Reference Data");
520 resultDAQRef = StoreReferenceData("Calib","DAQData",h2, &metaDataHisto);
522 Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
527 return 5;//return error code for failure in storing Ref Data
534 Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
538 return 4;//return error code for failure in retrieving Ref Data
544 Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
547 return 4;//return error code for failure in retrieving Ref Data
552 //Total files, with cumulative histos
554 TList* listTot = GetFileSources(kDAQ, "DELAYS");
555 if (listTot !=0x0 && listTot->GetEntries()!=0)
557 AliInfo("The following sources produced files with the id DELAYS");
559 for (Int_t jj=0;jj<listTot->GetEntries();jj++){
560 TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
561 AliInfo(Form("found source %s", str->String().Data()));
563 // file with summed histos, to extract calib params
564 TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
565 if (fileName.Length()>0){
566 AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
568 daqFile = new TFile(fileName.Data(),"READ");
570 h2 = (TH2S*) daqFile->Get("htoftot");
572 Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
577 return 7; //return error code for histograms not existing/junky
580 static const Int_t kSize=h2->GetNbinsX();
581 static const Int_t kNBins=h2->GetNbinsY();
582 static const Double_t kXBinmin=h2->GetYaxis()->GetBinLowEdge(1);
583 if (kSize != fNChannels){
584 Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
590 return 7; //return error code for histograms not existing/junky
592 Int_t nNotStatistics = 0; // number of channel with not enough statistics
594 /* FDR flag set. do not compute delays, use nominal cable delays */
597 Log(" Not computing delays according to flag set in Config entry in OCDB!");
598 FillWithCosmicCalibration(fCal);
600 /* check whether the new calibration is different from the previous one */
601 if (curCal) { /* well, check also whether we have a previous calibration */
602 for (Int_t i = 0; i < fNChannels; i++) {
603 if (fCal->GetDelay(i) != curCal->GetDelay(i)) {
609 else /* otherwise update OCDB */
614 else { // computing delays if not in FDR runs
616 updateOCDB = kTRUE; /* always update OCDB when computing delays */
618 for (Int_t ich=0;ich<kSize;ich++){
619 /* check whether channel has been read out during current run.
620 * if the status is bad it means it has not been read out.
621 * in this case skip channel in order to not affect the mean */
622 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad){
623 AliDebug(2,Form(" Channel %i found bad according to FEEmap, (HW status = %i), skipping from delay computing",ich, (Int_t)fStatus->GetHWStatus(ich)));
626 AliDebug(2,Form(" Channel %i found ok according to FEEmap, starting delay computing",ich));
627 TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
628 for (Int_t ibin=0;ibin<kNBins;ibin++){
629 h1->SetBinContent(ibin+1,h2->GetBinContent(ich+1,ibin+1));
631 if(h1->Integral()<integralThr) {
633 Log(Form(" Not enough statistics for bin %i, skipping this channel",ich)); // printing message only if not in FDR runs
639 Float_t minContent=h1->Integral()*thrPar;
640 Int_t nbinsX = h1->GetNbinsX();
642 for (Int_t j=1; j<=nbinsX; j++){
644 h1->GetBinContent(j) +
645 h1->GetBinContent(j+1)+
646 h1->GetBinContent(j+2)+
647 h1->GetBinContent(j+3))>minContent){
653 if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
654 // Now calculate the mean over the interval.
658 for(Int_t k=0;k<binRangeAve;k++){
659 mean=mean+h1->GetBinCenter(startBin+k)*h1->GetBinContent(startBin+k);
660 nent=nent+h1->GetBinContent(startBin+k);
661 sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
663 mean= mean/nent; //<x>
664 sumw2=sumw2/nent; //<x^2>
666 rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
667 if (ich<fNChannels) {
668 Float_t delay = mean*AliTOFGeometry::TdcBinWidth()*1.E-3; // delay in ns
669 fCal->SetDelay(ich,delay); // delay in ns
670 AliDebug(2,Form("Setting delay %f (ns) for channel %i",delay,ich));
676 if (nNotStatistics!=0) Log(Form("Too little statistics for %d channels!",nNotStatistics));
683 Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
687 return 6;//return error code for problems in retrieving DAQ data
693 Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
696 return 6; //return error code for problems in retrieving DAQ data
699 /* check whether we don't need to update OCDB.
700 * in this case we can return without errors and
701 * the current FEE is stored in the fStatus object. */
703 AliInfo("update OCDB flag not set. Do not overwrite stored file.");
704 return 0; /* return ok */
708 AliCDBMetaData metaData;
709 metaData.SetBeamPeriod(0);
710 metaData.SetResponsible("Chiara Zampolli");
711 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineArray object for online calibration - delays.");
712 AliInfo("Storing Calibration Data");
713 resultTOFPP = Store("Calib","ParOnlineDelay",fCal, &metaData,deltaStartingRun,kTRUE);
715 Log("Some problems occurred while storing online object resulting from DAQ data processing");
718 return 8;//return error code for problems in storing DAQ data
729 //_____________________________________________________________________________
732 AliTOFPreprocessor::ProcessT0Fill()
734 // Processing data from DAQ for T0-fill measurement
736 Log("Processing T0-fill");
739 /* instance and setup CDB manager */
740 AliCDBManager *cdb = AliCDBManager::Instance();
742 if (!gGeoManager) AliGeomManager::LoadGeometry();
745 /* get params from OCDB */
746 AliCDBEntry *cdbe = NULL;
748 /* get T0-fill calibration params */
749 cdbe = GetFromOCDB("Calib", "T0FillOnlineCalib");
751 Log("cannot get \"T0FillOnlineCalib\" entry from OCDB");
754 AliTOFT0FillOnlineCalib *t0FillOnlineCalibObject = (AliTOFT0FillOnlineCalib *)cdbe->GetObject();
755 if (!t0FillOnlineCalibObject) {
756 Log("cannot get \"T0FillOnlineCalib\" object from CDB entry");
759 Float_t t0FillCalibOffset = t0FillOnlineCalibObject->GetOffset();
760 Float_t t0FillCalibCoefficient = t0FillOnlineCalibObject->GetCoefficient();
761 Log(Form("got \"T0FillOnlineCalib\" object: offset=%f coeff=%f", t0FillCalibOffset, t0FillCalibCoefficient));
763 /* get online status from OCDB */
764 cdbe = GetFromOCDB("Calib", "Status");
766 Log("cannot get \"Status\" entry from OCDB");
769 AliTOFChannelOnlineStatusArray *statusArray = (AliTOFChannelOnlineStatusArray *)cdbe->GetObject();
771 Log("cannot get \"Status\" object from CDB entry");
774 Log("got \"Status\" object");
776 /* get offline calibration from OCDB */
777 cdbe = GetFromOCDB("Calib", "ParOffline");
779 Log("cannot get \"ParOffline\" entry from OCDB");
782 TObjArray *offlineArray = (TObjArray *)cdbe->GetObject();
783 AliTOFChannelOffline *channelOffline;
785 Log("cannot get \"ParOffline\" object from CDB entry");
788 Log("got \"ParOffline\" object");
790 /* get deltaBC offset from OCDB */
791 cdbe = GetFromOCDB("Calib", "DeltaBCOffset");
793 Log("cannot get \"DeltaBCOffset\" entry from OCDB");
796 AliTOFDeltaBCOffset *deltaBCOffsetObject = (AliTOFDeltaBCOffset *)cdbe->GetObject();
797 if (!deltaBCOffsetObject) {
798 Log("cannot get \"DeltaBCOffset\" object from CDB entry");
801 Int_t deltaBCOffset = deltaBCOffsetObject->GetDeltaBCOffset();
802 Log(Form("got \"DeltaBCOffset\" object: deltaBCOffset=%d (BC bins)", deltaBCOffset));
804 /* get CTP latency from OCDB */
805 cdbe = GetFromOCDB("Calib", "CTPLatency");
807 Log("cannot get \"CTPLatency\" entry from OCDB");
810 AliTOFCTPLatency *ctpLatencyObject = (AliTOFCTPLatency *)cdbe->GetObject();
811 if (!ctpLatencyObject) {
812 Log("cannot get \"CTPLatency\" object from CDB entry");
815 Float_t ctpLatency = ctpLatencyObject->GetCTPLatency();
816 Log(Form("got \"CTPLatency\" object: ctpLatency=%f (ps)", ctpLatency));
818 /* get file sources from FXS */
819 TList *fileList = GetFileSources(kDAQ, "HITS");
820 if (!fileList || fileList->GetEntries() == 0) {
821 Log("cannot get DAQ source file list or empty list");
824 Log(Form("got DAQ source file list: %d files", fileList->GetEntries()));
827 /* create tree chain using file sources */
828 TChain chain("hitTree");
829 for (Int_t ifile = 0; ifile < fileList->GetEntries(); ifile++) {
830 TObjString *str = (TObjString *)fileList->At(ifile);
831 TString filename = GetFile(kDAQ, "HITS", str->GetName());
833 Log(Form("file added to input chain: source=%s, filename=%s", str->String().Data(), filename.Data()));
835 Int_t nhits = chain.GetEntries();
836 Log(Form("input chain ready: %d hits", nhits));
838 /* setup input chain */
839 AliTOFHitField *hit = new AliTOFHitField();
840 chain.SetBranchAddress("hit", &hit);
842 /* create calib histo and geometry */
843 AliTOFcalibHisto calibHisto;
844 calibHisto.LoadCalibHisto();
845 AliTOFGeometry tofGeo;
848 Float_t c = TMath::C() * 1.e2 / 1.e12; /* cm/ps */
849 Float_t c_1 = 1. / c;
851 Int_t index, timebin, totbin, deltaBC, l0l1latency, det[5];
852 Float_t timeps, totns, corrps, length, timeexp, timezero, pos[3], latencyWindow;
855 TH1F *hT0Fill = new TH1F("hT0Fill", "T0 fill;t - t_{exp}^{(c)} (ps);", 2000, -24400., 24400.);
858 for (Int_t ihit = 0; ihit < nhits; ihit++) {
861 chain.GetEntry(ihit);
864 index = hit->GetIndex();
865 timebin = hit->GetTimeBin();
866 totbin = hit->GetTOTBin();
867 deltaBC = hit->GetDeltaBC();
868 l0l1latency = hit->GetL0L1Latency();
869 latencyWindow = statusArray->GetLatencyWindow(index) * 1.e3;
871 /* convert time in ps and tot in ns */
872 timeps = timebin * AliTOFGeometry::TdcBinWidth();
873 totns = totbin * AliTOFGeometry::ToTBinWidth() * 1.e-3;
874 /* get calibration correction in ps */
875 channelOffline = (AliTOFChannelOffline *)offlineArray->At(index);
876 if (totns < AliTOFGeometry::SlewTOTMin()) totns = AliTOFGeometry::SlewTOTMin();
877 if (totns > AliTOFGeometry::SlewTOTMax()) totns = AliTOFGeometry::SlewTOTMax();
879 for (Int_t ipar = 0; ipar < 6; ipar++) corrps += channelOffline->GetSlewPar(ipar) * TMath::Power(totns, ipar);
881 /* perform time correction */
882 timeps = timeps + (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth() + l0l1latency * AliTOFGeometry::BunchCrossingBinWidth() + ctpLatency - latencyWindow - corrps;
883 /* compute length and expected time */
884 tofGeo.GetVolumeIndices(index, det);
885 tofGeo.GetPosPar(det, pos);
887 for (Int_t i = 0; i < 3; i++) length += pos[i] * pos[i];
888 length = TMath::Sqrt(length);
889 timeexp = length * c_1;
890 /* compute time zero */
891 timezero = timeps - timeexp;
894 hT0Fill->Fill(timezero);
897 /* rebin until maximum bin has required minimum entries */
898 Int_t maxBin = hT0Fill->GetMaximumBin();
899 Float_t maxBinContent = hT0Fill->GetBinContent(maxBin);
900 Float_t binWidth = hT0Fill->GetBinWidth(maxBin);
901 while (maxBinContent < 400 && binWidth < 90.) {
903 maxBin = hT0Fill->GetMaximumBin();
904 maxBinContent = hT0Fill->GetBinContent(maxBin);
905 binWidth = hT0Fill->GetBinWidth(maxBin);
907 Float_t maxBinCenter = hT0Fill->GetBinCenter(maxBin);
909 /* rough landau fit of the edge */
910 TF1 *landau = (TF1 *)gROOT->GetFunction("landau");
911 landau->SetParameter(1, maxBinCenter);
912 Float_t fitMin = maxBinCenter - 1000.; /* fit from 10 ns before max */
913 Float_t fitMax = maxBinCenter + binWidth; /* fit until a bin width above max */
914 hT0Fill->Fit("landau", "q0", "", fitMin, fitMax);
915 /* get rough landau mean and sigma to set a better fit range */
916 Float_t mean = landau->GetParameter(1);
917 Float_t sigma = landau->GetParameter(2);
918 /* better landau fit of the edge */
919 fitMin = maxBinCenter - 3. * sigma;
921 hT0Fill->Fit("landau", "q0", "", fitMin, fitMax);
923 mean = landau->GetParameter(1);
924 sigma = landau->GetParameter(2);
925 Float_t meane = landau->GetParError(1);
926 Float_t sigmae = landau->GetParError(2);
927 Log(Form("edge fit: mean = %f +- %f ps", mean, meane));
928 Log(Form("edge fit: sigma = %f +- %f ps", sigma, sigmae));
929 Float_t edge = mean - 3. * sigma;
930 Float_t edgee = TMath::Sqrt(meane * meane + 3. * sigmae * 3. * sigmae);
931 Log(Form("edge fit: edge = %f +- %f ps", edge, edgee));
932 /* apply calibration to get T0-fill from egde */
933 Float_t t0Fill = edge * t0FillCalibCoefficient + t0FillCalibOffset;
934 Log(Form("estimated T0-fill: %f ps", t0Fill));
936 /* create T0-fill object */
937 AliTOFT0Fill *t0FillObject = new AliTOFT0Fill();
938 t0FillObject->SetT0Fill(t0Fill);
940 /* store reference data */
942 AliCDBMetaData metaDataHisto;
943 metaDataHisto.SetBeamPeriod(0);
944 metaDataHisto.SetResponsible("Roberto Preghenella");
945 metaDataHisto.SetComment("online T0-fill histogram");
946 if (!StoreReferenceData("Calib","T0Fill", hT0Fill, &metaDataHisto)) {
947 Log("error while storing reference data");
953 Log("reference data successfully stored");
956 AliCDBMetaData metaData;
957 metaData.SetBeamPeriod(0);
958 metaData.SetResponsible("Roberto Preghenella");
959 metaData.SetComment("online T0-fill measurement");
960 if (!Store("Calib", "T0Fill", t0FillObject, &metaData, 0, kFALSE)) {
961 Log("error while storing T0-fill object");
967 Log("T0-fill object successfully stored");
977 //_____________________________________________________________________________
979 UInt_t AliTOFPreprocessor::ProcessPulserData()
981 // Processing Pulser Run data for TOF channel status
983 Log("Processing Pulser");
986 AliError("No valid fStatus found, some errors must have occurred!!");
990 TH1::AddDirectory(0);
992 Bool_t resultPulserRef=kFALSE;
993 Bool_t resultPulser=kFALSE;
995 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
996 TH1S * htofPulser = new TH1S("hTOFpulser","histo with signals on TOF during pulser", kSize,-0.5,kSize-0.5);
997 for (Int_t ibin =1;ibin<=kSize;ibin++){
998 htofPulser->SetBinContent(ibin,-1);
1001 // processing pulser
1003 TFile * daqFile=0x0;
1006 //retrieving Pulser data
1007 TList* listPulser = GetFileSources(kDAQ, "PULSER");
1008 if (listPulser !=0x0 && listPulser->GetEntries()!=0)
1010 AliInfo("The following sources produced files with the id PULSER");
1011 listPulser->Print();
1013 for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
1014 Int_t nPulserSource = 0;
1015 TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
1016 AliInfo(Form("found source %s", str->String().Data()));
1017 // file to be stored run per run
1018 TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
1019 if (fileNamePulser.Length()>0){
1020 // storing refernce data
1021 AliInfo(Form("Got the file %s, now we can process pulser data.", fileNamePulser.Data()));
1022 daqFile = new TFile(fileNamePulser.Data(),"READ");
1023 h1 = (TH1S*) daqFile->Get("hTOFpulser");
1024 for (Int_t ibin=0;ibin<kSize;ibin++){
1025 if ((h1->GetBinContent(ibin+1))!=-1){
1026 if ((htofPulser->GetBinContent(ibin+1))==-1){
1027 htofPulser->SetBinContent(ibin+1,h1->GetBinContent(ibin+1));
1030 Log(Form("Something strange occurred during Pulser run, channel %i already read by another LDC, please check!",ibin));
1035 // elaborating infos
1038 Int_t nreadNotEmpty=0;
1039 for (Int_t ientry=1;ientry<=h1->GetNbinsX();ientry++){
1041 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)));
1042 /* check whether channel has been read out during current run.
1043 * if the status is bad it means it has not been read out.
1044 * in this case skip channel in order to not affect the mean */
1045 if (fStatus->GetHWStatus(ientry-1) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1049 if (h1->GetBinContent(ientry)==-1) continue;
1051 if (h1->GetBinContent(ientry)>0) {
1053 AliDebug(2,Form(" channel %i is ok with entry = %f; so far %i channels added ",ientry-1,h1->GetBinContent(ientry),nreadNotEmpty));
1055 mean+=h1->GetBinContent(ientry);
1061 AliDebug(2,Form(" nread = %i , nreadNotEmpty = %i, mean = %f",nread,nreadNotEmpty,mean));
1062 for (Int_t ich =0;ich<fNChannels;ich++){
1063 if (h1->GetBinContent(ich+1)==-1) continue;
1064 AliDebug(3,Form(" channel %i pulser status before pulser = %i",ich,(Int_t)fStatus->GetPulserStatus(ich)));
1066 /* check whether channel has been read out during current run.
1067 * if the status is bad it means it has not been read out.
1068 * in this case skip channel in order to leave its status
1070 if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1073 if (h1->GetBinContent(ich+1)<0.05*mean){
1074 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserBad); // bad status for pulser
1075 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)));
1078 fStatus->SetPulserStatus(ich,AliTOFChannelOnlineStatusArray::kTOFPulserOk); // good status for pulser
1079 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)));
1084 Log("No channels read!! No action taken, keeping old status");
1093 Log("The input data file from DAQ (pulser) was not found, TOF exiting from Shuttle ");
1101 return 10;//return error code for failure in retrieving Ref Data
1103 AliDebug(2,Form(" Number of channels processed during pulser run from source %i = %i",jj, nPulserSource));
1105 AliDebug(2,Form(" Number of channels processed during pulser run = %i",nPulser));
1110 Log("The input data file list from DAQ (pulser) was not found, TOF exiting from Shuttle ");
1117 return 10;//return error code for failure in retrieving Ref Data
1122 AliCDBMetaData metaData;
1123 metaData.SetBeamPeriod(0);
1124 metaData.SetResponsible("Chiara Zampolli");
1125 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Pulser run.");
1126 AliInfo("Storing Calibration Data from Pulser Run");
1127 resultPulser = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
1129 Log("Some problems occurred while storing online object resulting from Pulser data processing");
1136 return 11;//return error code for problems in storing Pulser data
1141 AliCDBMetaData metaDataHisto;
1142 metaDataHisto.SetBeamPeriod(0);
1143 metaDataHisto.SetResponsible("Chiara Zampolli");
1145 sprintf(comment,"This preprocessor stores the Ref data from a pulser run.");
1146 metaDataHisto.SetComment(comment);
1147 AliInfo("Storing Reference Data");
1148 resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
1149 if (!resultPulserRef){
1150 Log("some problems occurred::No Reference Data for pulser stored, TOF exiting from Shuttle");
1157 return 9;//return error code for failure in storing Ref Data
1173 //_____________________________________________________________________________
1175 UInt_t AliTOFPreprocessor::ProcessNoiseData()
1178 // Processing Noise Run data for TOF channel status
1180 Log("Processing Noise");
1183 AliError("No valid fStatus found, some errors must have occurred!!");
1187 Float_t noiseThr = 1; // setting default threshold for noise to 1 Hz
1188 // reading config map
1189 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
1191 Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %d",noiseThr));
1194 TMap *configMap = (TMap*)cdbEntry->GetObject();
1196 Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %d", noiseThr));
1199 TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
1201 TString tmpstr = strNoiseThr->GetString();
1202 noiseThr = tmpstr.Atoi();
1205 Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %i",noiseThr));
1213 TH1::AddDirectory(0);
1215 Bool_t resultNoiseRef=kFALSE;
1216 Bool_t resultNoise=kFALSE;
1218 static const Int_t kSize = AliTOFGeometry::NPadXSector()*AliTOFGeometry::NSectors();
1219 TH1F * htofNoise = new TH1F("hTOFnoise","histo with signals on TOF during noise", kSize,-0.5,kSize-0.5);
1220 for (Int_t ibin =1;ibin<=kSize;ibin++){
1221 htofNoise->SetBinContent(ibin,-1);
1226 TFile * daqFile=0x0;
1231 Int_t nNoisyChannels = 0;
1232 Int_t nNotNoisyChannels = 0;
1233 Int_t nChannelsFromDA = 0;
1234 Int_t nMatchingWindowNullNonZero = 0;
1235 Int_t nMatchingWindowNullEqualZero = 0;
1237 // retrieving Noise data
1238 TList* listNoise = GetFileSources(kDAQ, "NOISE");
1239 if (listNoise !=0x0 && listNoise->GetEntries()!=0)
1241 AliInfo("The following sources produced files with the id NOISE");
1243 for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
1244 Int_t nNoiseSource = 0;
1245 TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
1246 AliInfo(Form("found source %s", str->String().Data()));
1247 // file to be stored run per run
1248 TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
1249 if (fileNameNoise.Length()>0){
1250 // storing reference data
1251 AliInfo(Form("Got the file %s, now we can process noise data.", fileNameNoise.Data()));
1252 daqFile = new TFile(fileNameNoise.Data(),"READ");
1253 h1 = (TH1F*) daqFile->Get("hTOFnoise");
1254 for (Int_t ibin=0;ibin<kSize;ibin++){
1255 if ((h1->GetBinContent(ibin+1))!=-1){
1257 // checking the matching window for current channel
1258 if (fMatchingWindow[ibin] == 0){
1259 Log(Form("Matching window for channel %i null, but the channel was read by the LDC! skipping channel, BUT Please check!",ibin));
1260 if ((h1->GetBinContent(ibin+1))!=0) nMatchingWindowNullNonZero++;
1261 if ((h1->GetBinContent(ibin+1))==0) nMatchingWindowNullEqualZero++;
1264 if ((htofNoise->GetBinContent(ibin+1))==-1){
1265 htofNoise->SetBinContent(ibin+1,h1->GetBinContent(ibin+1)/(fMatchingWindow[ibin]*1.E-9));
1266 if ((h1->GetBinContent(ibin+1))!= 0) AliDebug(2,Form("Channel = %i, Matching window = %i, Content = %f", ibin, fMatchingWindow[ibin], htofNoise->GetBinContent(ibin+1)));
1269 Log(Form("Something strange occurred during Noise run, channel %i already read by another LDC, please check!",ibin));
1274 Log(Form(" Number of channels processed during noise run from source %i = %i",jj, nNoiseSource));
1283 Log("The input data file from DAQ (noise) was not found, TOF exiting from Shuttle ");
1292 if (fMatchingWindow){
1293 delete [] fMatchingWindow;
1294 fMatchingWindow = 0;
1296 return 13;//return error code for failure in retrieving Ref Data
1302 Log("The input data file list from DAQ (noise) was not found, TOF exiting from Shuttle ");
1309 if (fMatchingWindow){
1310 delete [] fMatchingWindow;
1311 fMatchingWindow = 0;
1313 return 13;//return error code for failure in retrieving Ref Data
1316 // elaborating infos to set NOISE status
1317 for (Int_t ich =0;ich<fNChannels;ich++){
1318 if (htofNoise->GetBinContent(ich+1)== -1) continue;
1322 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)));
1323 //AliDebug(2,Form( " channel %i status before noise = %i",ich,(Int_t)fStatus->GetNoiseStatus(ich)));
1325 /* check whether channel has been read out during current run.
1326 * if the status is bad it means it has not been read out.
1327 * in this case skip channel in order to leave its status
1330 if ((fStatus->GetHWStatus(ich)) == AliTOFChannelOnlineStatusArray::kTOFHWBad)
1334 if (htofNoise->GetBinContent(ich+1) >= noiseThr){
1335 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseBad); // bad status for noise
1336 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)));
1340 fStatus->SetNoiseStatus(ich,AliTOFChannelOnlineStatusArray::kTOFNoiseOk); // good status for noise
1341 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)));
1342 nNotNoisyChannels++;
1346 Log(Form(" Number of channels processed by DA during noise run, independetly from TOFFEE = %i",nChannelsFromDA));
1347 Log(Form(" Number of channels processed during noise run (that were ON according to TOFFEE) = %i",nNoise));
1348 Log(Form(" Number of noisy channels found during noise run = %i",nNoisyChannels));
1349 Log(Form(" Number of not noisy channels found during noise run = %i",nNotNoisyChannels));
1350 Log(Form(" Number of channels with matching window NULL (so skipped), but Non Zero content = %i",nMatchingWindowNullNonZero));
1351 Log(Form(" Number of channels with matching window NULL (so skipped), and Zero content = %i",nMatchingWindowNullEqualZero));
1359 AliCDBMetaData metaData;
1360 metaData.SetBeamPeriod(0);
1361 metaData.SetResponsible("Chiara Zampolli");
1362 metaData.SetComment("This preprocessor fills an AliTOFChannelOnlineStatusArray object after a Noise run.");
1363 AliInfo("Storing Calibration Data from Noise Run");
1364 resultNoise = Store("Calib","Status",fStatus, &metaData,0,kTRUE);
1366 Log("Some problems occurred while storing online object resulting from Noise data processing");
1373 if (fMatchingWindow){
1374 delete [] fMatchingWindow;
1375 fMatchingWindow = 0;
1377 return 14;//return error code for problems in storing Noise data
1382 AliCDBMetaData metaDataHisto;
1383 metaDataHisto.SetBeamPeriod(0);
1384 metaDataHisto.SetResponsible("Chiara Zampolli");
1386 sprintf(comment,"This preprocessor stores the Ref data from a noise run. ");
1387 metaDataHisto.SetComment(comment);
1388 AliInfo("Storing Reference Data");
1389 resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
1390 if (!resultNoiseRef){
1391 Log("some problems occurred::No Reference Data for noise stored");
1398 if (fMatchingWindow){
1399 delete [] fMatchingWindow;
1400 fMatchingWindow = 0;
1402 return 12;//return error code for failure in storing Ref Data
1414 if (fMatchingWindow){
1415 delete [] fMatchingWindow;
1416 fMatchingWindow = 0;
1421 //_____________________________________________________________________________
1423 UInt_t AliTOFPreprocessor::ProcessFEEData()
1425 // Processing Pulser Run data for TOF channel status
1426 // dummy for the time being
1428 Log("Processing FEE");
1430 //Bool_t updateOCDB = kFALSE;
1431 AliTOFFEEReader feeReader;
1433 TH1C hCurrentFEE("hCurrentFEE","histo with current FEE channel status", fNChannels, 0, fNChannels);
1435 /* load current TOF FEE(dump) from DCS FXS,
1436 * setup TOFFEEdump object */
1438 const char * toffeeFileName = GetFile(kDCS,"TofFeeMap","");
1439 AliInfo(Form("toffee file name = %s", toffeeFileName));
1440 if (toffeeFileName == NULL) {
1443 AliTOFFEEDump feedump;
1444 feedump.ReadFromFile(toffeeFileName);
1446 /* load current TOF FEE(light) config from DCS FXS, parse,
1447 * fill current FEE histogram and set FEE status */
1449 const char * nameFile = GetFile(kDCS,"TofFeeLightMap","");
1450 AliInfo(Form("toffeeLight file name = %s",nameFile));
1451 if (nameFile == NULL) {
1454 feeReader.LoadFEElightConfig(nameFile);
1455 Int_t parseFee = feeReader.ParseFEElightConfig();
1456 AliDebug(2,Form("%i enabled channels found in FEElight configuration",parseFee));
1457 /* load stored TOF FEE from OCDB and compare it with current FEE.
1458 * if stored FEE is different from current FEE set update flag.
1459 * if there is no stored FEE in OCDB set update flag */
1461 fMatchingWindow = new Int_t[fNChannels];
1462 fLatencyWindow = new Int_t[fNChannels];
1464 AliCDBEntry *cdbEntry = GetFromOCDB("Calib","Status");
1466 /* no CDB entry found. set update flag */
1467 Log(" ************ WARNING ************");
1468 Log("No CDB Status entry found, creating a new one!");
1469 Log(" *********************************");
1470 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1471 //updateOCDB = kTRUE;
1472 fIsStatusMapChanged = kTRUE;
1475 if (cdbEntry) cdbEntry->SetOwner(kFALSE);
1476 /* CDB entry OK. loop over channels */
1477 fStatus = (AliTOFChannelOnlineStatusArray*) cdbEntry->GetObject();
1480 /* cehck whether status object has latency window data */
1481 if (!fStatus->HasLatencyWindow()) {
1482 /* create new status object and update OCDB */
1483 Log(" ************ WARNING ************");
1484 Log("CDB Status entry found but has no latency window data, creating a new one!");
1485 Log(" *********************************");
1487 fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
1488 //updateOCDB = kTRUE;
1489 fIsStatusMapChanged = kTRUE;
1492 for (Int_t iChannel = 0; iChannel < fNChannels; iChannel++){
1493 //AliDebug(2,Form("********** channel %i",iChannel));
1494 /* compare current FEE channel status with stored one
1495 * if different set update flag and break loop */
1496 //AliDebug(2,Form( " channel %i status before FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1497 fMatchingWindow[iChannel] = feeReader.GetMatchingWindow(iChannel);
1498 fLatencyWindow[iChannel] = feeReader.GetLatencyWindow(iChannel);
1499 if (feeReader.IsChannelEnabled(iChannel)) {
1500 hCurrentFEE.SetBinContent(iChannel + 1, 1);
1501 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWOk){
1502 //updateOCDB = kTRUE;
1503 fIsStatusMapChanged = kTRUE;
1504 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWOk);
1505 AliDebug(3,Form( " changed into enabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1507 if (fStatus->GetLatencyWindow(iChannel)!=fLatencyWindow[iChannel]){
1508 //updateOCDB = kTRUE;
1509 fIsStatusMapChanged = kTRUE;
1510 fStatus->SetLatencyWindow(iChannel,fLatencyWindow[iChannel]);
1511 AliDebug(3,Form( " changed latency window: channel %i latency window after FEE = %i",iChannel,fStatus->GetLatencyWindow(iChannel)));
1515 if (fStatus->GetHWStatus(iChannel)!=AliTOFChannelOnlineStatusArray::kTOFHWBad){
1516 //updateOCDB = kTRUE;
1517 fIsStatusMapChanged = kTRUE;
1518 fStatus->SetHWStatus(iChannel,AliTOFChannelOnlineStatusArray::kTOFHWBad);
1519 AliDebug(3,Form( " changed into disabled: channel %i status after FEE = %i",iChannel,(Int_t)fStatus->GetHWStatus(iChannel)));
1525 /* check whether we don't have to store reference data.
1526 * in this case we return without errors. */
1527 if (fStoreRefData) {
1528 /* store reference data */
1529 AliCDBMetaData metaDataHisto;
1530 metaDataHisto.SetBeamPeriod(0);
1531 metaDataHisto.SetResponsible("Roberto Preghenella");
1532 metaDataHisto.SetComment("This preprocessor stores the FEE Ref data of the current run.");
1533 AliInfo("Storing FEE reference data");
1534 /* store FEE reference data */
1535 if (!StoreReferenceData("Calib", "FEEData", &hCurrentFEE, &metaDataHisto)) {
1537 Log("problems while storing FEE reference data");
1542 return 18; /* error return code for problems while storing FEE reference data */
1545 /* store TOF FEE dump reference data */
1546 AliCDBMetaData metaDatadump;
1547 metaDatadump.SetBeamPeriod(0);
1548 metaDatadump.SetResponsible("Roberto Preghenella");
1549 metaDatadump.SetComment("This preprocessor stores the TOF FEE dump Ref data of the current run.");
1550 AliInfo("Storing TOF FEE dump reference data");
1551 /* store FEE reference data */
1552 if (!StoreReferenceData("Calib", "FEEDump", &feedump, &metaDatadump)) {
1554 Log("problems while storing TOF FEE dump reference data");
1555 return 18; /* error return code for problems while storing FEE reference data */
1563 //_____________________________________________________________________________
1565 UInt_t AliTOFPreprocessor::Process(TMap *dcsAliasMap)
1568 // Main AliTOFPreprocessor method called by SHUTTLE
1571 TString runType = GetRunType();
1572 Log(Form("RunType %s",runType.Data()));
1576 /* always process FEE data */
1577 Int_t iresultFEE = ProcessFEEData();
1578 if (iresultFEE != 0)
1581 if (runType == "PULSER") {
1582 Int_t iresultPulser = ProcessPulserData();
1583 return iresultPulser;
1586 if (runType == "NOISE") { // for the time being associating noise runs with pedestal runs; proper run type to be defined
1587 Int_t iresultNoise = ProcessNoiseData();
1588 return iresultNoise;
1591 if (runType == "PHYSICS") {
1592 // Int_t iresultDAQ = ProcessOnlineDelays();
1593 Int_t iresultDAQ = ProcessT0Fill();
1594 if (iresultDAQ != 0) {
1598 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
1599 Int_t iResultHVandLVdps = ProcessHVandLVdps(dcsAliasMap);
1600 return iresultDCS+iResultHVandLVdps;
1609 //_____________________________________________________________________________
1612 AliTOFPreprocessor::FillWithCosmicCalibration(AliTOFChannelOnlineArray *cal)
1615 * fill with cosmic calibration
1618 Log(" Using cosmic-ray calibration.");
1620 AliTOFcalibHisto calibHisto;
1621 calibHisto.SetFullCorrectionFlag(AliTOFcalibHisto::kTimeSlewingCorr, kFALSE);
1622 Log(Form(" loading calibration histograms from %s", calibHisto.GetCalibHistoFileName()));
1623 Log(Form(" loading calibration parameters from %s", calibHisto.GetCalibParFileName()));
1624 calibHisto.LoadCalibPar();
1626 /* loop over channel index */
1627 for (Int_t iIndex = 0; iIndex < fNChannels; iIndex++) {
1628 cal->SetDelay(iIndex, calibHisto.GetFullCorrection(iIndex));
1633 //_____________________________________________________________________________
1636 AliTOFPreprocessor::FillWithCableLengthMap(AliTOFChannelOnlineArray *cal)
1639 * fill with cosmic calibration
1642 Log(" Using cable-length map.");
1643 AliTOFRawStream tofrs;
1644 Int_t det[5], dummy, index;
1645 Float_t cableTimeShift;
1647 /* temporarly disable warnings */
1648 AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
1649 AliLog::SetGlobalLogLevel(AliLog::kError);
1651 /* loop over EO indeces */
1652 for (Int_t iddl = 0; iddl < 72; iddl++)
1653 for (Int_t islot = 3; islot <= 12; islot++)
1654 for (Int_t ichain = 0; ichain < 2; ichain++)
1655 for (Int_t itdc = 0; itdc < 15; itdc++)
1656 for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
1659 tofrs.EquipmentId2VolumeId(iddl, islot, ichain, itdc, ichannel, det);
1661 /* swap det[3] and det[4] indeces (needed to obtain correct channel index) */
1666 /* check DO index */
1667 if (det[0] < 0 || det[0] > 17 ||
1668 det[1] < 0 || det[1] > 4 ||
1669 det[2] < 0 || det[2] > 18 ||
1670 det[3] < 0 || det[3] > 1 ||
1671 det[4] < 0 || det[4] > 47)
1674 /* get channel index */
1675 index = AliTOFGeometry::GetIndex(det);
1677 /* get cable time shift */
1678 cableTimeShift = AliTOFCableLengthMap::GetCableTimeShift(iddl, islot, ichain, itdc);
1681 if (index<fNChannels) {
1682 cal->SetDelay(index,cableTimeShift); // delay in ns
1683 AliDebug(2,Form("Setting delay %f (ns) for channel %i",cableTimeShift,index));
1686 } /* loop over EO indeces */
1688 /* re-enable warnings */
1689 AliLog::SetGlobalLogLevel(logLevel);