* provided "as is" without express or implied warranty. *
**************************************************************************/
-/*
-$Log$
-Revision 1.1 2006/10/26 09:09:29 arcelli
-prototype for the TOF Shuttle preprocessor (C.Zampolli)
+/* $Id$ */
-*/
+#include <Riostream.h>
+#include <stdio.h>
+#include <stdlib.h>
-#include "AliTOFPreprocessor.h"
+#include <TFile.h>
+#include <TH1.h>
+#include <TH1F.h>
+#include <TH1S.h>
+#include <TH2S.h>
+#include <TMath.h>
+#include <TObjArray.h>
+#include <TObjString.h>
+#include <TTimeStamp.h>
#include "AliCDBMetaData.h"
#include "AliLog.h"
-#include "AliTOFDataDCS.h"
-#include "TFile.h"
-#include "TObjArray.h"
-#include "TObjString.h"
#include "AliTOFCalOnline.h"
#include "AliTOFChannelOnline.h"
+#include "AliTOFDataDCS.h"
#include "AliTOFGeometryV5.h"
-#include "TTimeStamp.h"
-#include "TH1F.h"
+#include "AliTOFPreprocessor.h"
class TF1;
class AliDCSValue;
ClassImp(AliTOFPreprocessor)
const Int_t AliTOFPreprocessor::fgkBinRangeAve = 13; // number of bins where to calculate the mean
+const Double_t AliTOFPreprocessor::fgkThrPar = 0.013; // parameter used to trigger the calculation of the delay
//_____________________________________________________________________________
-AliTOFPreprocessor::AliTOFPreprocessor(const char* detector, AliShuttleInterface* shuttle) :
- AliPreprocessor(detector, shuttle),
+AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
+ AliPreprocessor("TOF", shuttle),
fData(0),
- fArray(0),
+ fh2(0),
fCal(0),
- fTOFGeometry(0)
+ fTOFGeometry(0),
+ fStoreRefData(kTRUE)
{
// constructor
}
AliTOFPreprocessor::~AliTOFPreprocessor()
{
// destructor
+ delete fData;
+ fData = 0;
+ delete fh2;
+ fh2 = 0;
+ delete fCal;
+ fCal = 0;
+ delete fTOFGeometry;
+ fTOFGeometry = 0;
}
//______________________________________________________________________________
TTimeStamp(endTime).AsString()));
fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime);
- fArray = 0x0;
+ fh2 = 0x0;
fTOFGeometry = new AliTOFGeometryV5();
fCal = new AliTOFCalOnline(fTOFGeometry);
fCal->CreateArray();
UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
{
// Fills data into a AliTOFDataDCS object
+ // return codes:
+ // return=0 : all ok
+ // return=1 : no DCS input data Map
+ // return=2 : no DCS input data processing
+ // return=3 : no DCS processed data was stored
+ // return=4 : no DAQ input for Ref Data
+ // return=5 : failed to store Ref data
+ // return=6 : failed to retrieve DAQ data for calibration
+ // return=7 : problems in histos in the input DAQ file
+ // return=8 : failed to store Online Delays
- UInt_t resultDCS=0;
- UInt_t resultDAQ=0;
- UInt_t resultDAQRef=0;
- UInt_t result=0;
+ TH1::AddDirectory(0);
+
+ Bool_t resultDCSMap=kFALSE;
+ Bool_t resultDCSStore=kFALSE;
+ Bool_t resultDAQ=kFALSE;
+ Bool_t resultDAQRef=kFALSE;
// processing DCS
if (!dcsAliasMap){
- AliInfo(Form("No DCS map found "));
+ Log("No DCS map found: TOF exiting from Shuttle");
+ return 1;// return error Code for DCS input data not found
}
else {
// The processing of the DCS input data is forwarded to AliTOFDataDCS
- fData->ProcessData(*dcsAliasMap);
- AliCDBMetaData metaDataDCS;
- metaDataDCS.SetBeamPeriod(0);
- metaDataDCS.SetResponsible("Chiara Zampolli");
- metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object."); resultDCS = Store("Calib","DCSData",fData, &metaDataDCS);
- result+=resultDCS;
- if (!resultDCS){
- AliInfo(Form("some problems occurred while storing DCS data processing results"));
+ resultDCSMap=fData->ProcessData(*dcsAliasMap);
+ if(!resultDCSMap){
+ Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
+ return 2;// return error Code for processed DCS data not stored
+ }
+ else{
+ AliCDBMetaData metaDataDCS;
+ metaDataDCS.SetBeamPeriod(0);
+ metaDataDCS.SetResponsible("Chiara Zampolli");
+ metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
+ AliInfo("Storing DCS Data");
+ resultDCSStore = Store("Calib","DCSData",fData, &metaDataDCS);
+ if (!resultDCSStore){
+ Log("Some problems occurred while storing DCS data results in OCDB, TOF exiting from Shuttle");
+ return 3;// return error Code for processed DCS data not stored
+
+ }
}
}
-
+
// processing DAQ
-
+
TFile * daqFile=0x0;
- TList* list = GetFileSources(kDAQ, "DELAYS");
+
+ if(fStoreRefData){
+ //retrieving data at Run level
+ TList* list = GetFileSources(kDAQ, "RUNLevel");
+ if (list)
+ {
+ AliInfo("The following sources produced files with the id RUNLevel");
+ list->Print();
+ for (Int_t jj=0;jj<list->GetEntries();jj++){
+ TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
+ AliInfo(Form("found source %s", str->String().Data()));
+ // file to be stored run per run
+ TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
+ if (fileNameRun.Length()>0){
+ AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun.Data()));
+ daqFile = new TFile(fileNameRun.Data(),"READ");
+ fh2 = (TH2S*) daqFile->Get("htof");
+ AliCDBMetaData metaDataHisto;
+ metaDataHisto.SetBeamPeriod(0);
+ metaDataHisto.SetResponsible("Chiara Zampolli");
+ metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
+ AliInfo("Storing Reference Data");
+ resultDAQRef = StoreReferenceData("Calib","DAQData",fh2, &metaDataHisto);
+ if (!resultDAQRef){
+ Log("some problems occurred::No Reference Data stored, TOF exiting from Shuttle");
+ return 5;//return error code for failure in storing Ref Data
+ }
+ daqFile->Close();
+ delete daqFile;
+ }
+
+ else{
+ Log("The input data file from DAQ (run-level) was not found, TOF exiting from Shuttle ");
+ return 4;//return error code for failure in retrieving Ref Data
+ }
+ }
+ }
+ else{
+ Log("The input data file list from DAQ (run-level) was not found, TOF exiting from Shuttle ");
+ return 4;//return error code for failure in retrieving Ref Data
+ }
+ }
+
- if (list)
+//Total files, with cumulative histos
+
+ TList* listTot = GetFileSources(kDAQ, "DELAYS");
+ if (listTot)
{
AliInfo("The following sources produced files with the id DELAYS");
- list->Print();
- for (Int_t jj=0;jj<list->GetEntries();jj++){
- TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
+ listTot->Print();
+ for (Int_t jj=0;jj<listTot->GetEntries();jj++){
+ TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
AliInfo(Form("found source %s", str->String().Data()));
- // file to be stored run per run
- const char* fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
- if (fileNameRun){
- AliInfo(Form("Got the file %s, now we can store the Reference Data for the current Run.", fileNameRun));
- daqFile = new TFile(fileNameRun,"READ");
- fArray = (TObjArray*) daqFile->Get("ciccio");
- AliCDBMetaData metaDataHisto;
- metaDataHisto.SetBeamPeriod(0);
- metaDataHisto.SetResponsible("Chiara Zampolli");
- metaDataHisto.SetComment("This preprocessor stores the array of histos object as Reference Data.");
- resultDAQRef = StoreReferenceData("Calib","DAQData",fArray, &metaDataHisto);
- result+=resultDAQRef*2;
- if (!resultDAQRef){
- AliInfo(Form("some problems occurred::No Reference Data stored"));
- }
- daqFile->Close();
- delete daqFile;
- }
- else{
- AliError(Form("The file %s does not exist",fileNameRun));
- }
-
// file with summed histos, to extract calib params
- const char *fileName = GetFile(kDAQ, "DELAYS", str->GetName());
- if (fileName){
- AliInfo(Form("Got the file %s, now we can extract some values.", fileName));
-
- daqFile = new TFile(fileName,"READ");
- fArray = (TObjArray*) daqFile->Get("ciccio");
- if (!fArray){
- AliInfo(Form("some problems occurred:: No histo array retrieved"));
+ TString fileName = GetFile(kDAQ, "DELAYS", str->GetName());
+ if (fileName.Length()>0){
+ AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
+
+ daqFile = new TFile(fileName.Data(),"READ");
+ fh2 = (TH2S*) daqFile->Get("htoftot");
+ if (!fh2){
+ Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
+ delete daqFile;
+ return 7; //return error code for histograms not existing/junky
}
-
else {
- Int_t nentries=(Int_t)fArray->GetEntries();
- AliInfo(Form(" il numero di entries e' = %i ", nentries));
+ static const Int_t kSize=fh2->GetNbinsX();
+ static const Int_t kNBins=fh2->GetNbinsY();
+ static const Double_t kXBinmin=fh2->GetYaxis()->GetBinLowEdge(1);
Int_t npads = fCal->NPads();
- for (Int_t i=0 ; i<nentries; i++){
+ if (kSize != npads){
+ Log(" number of bins along x different from number of pads, found only a subset of the histograms, TOF exiting from Shuttle");
+ delete daqFile;
+ return 7; //return error code for histograms not existing/junky
+ }
+ for (Int_t ich=0;ich<kSize;ich++){
+ TH1S *h1 = new TH1S("h1","h1",kNBins,kXBinmin-0.5,kNBins*1.+kXBinmin-0.5);
+ for (Int_t ibin=0;ibin<kNBins;ibin++){
+ h1->SetBinContent(ibin+1,fh2->GetBinContent(ich+1,ibin+1));
+ }
Bool_t found=kFALSE;
- TH1F * h1 = (TH1F*)fArray->At(i);
- Float_t minContent=h1->Integral()*0.01; //for the time being
- //we use integral() since we simulate landau distribution
- //Float_t minContent=h1->GetEntries()*0.01;
+ Float_t minContent=h1->Integral()*fgkThrPar;
Int_t nbinsX = h1->GetNbinsX();
Int_t startBin=1;
for (Int_t j=1; j<=nbinsX; j++){
break;
}
}
- if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",i));
+ if(!found) AliInfo(Form("WARNING!!! no start of fit found for histo # %i",ich));
// Now calculate the mean over the interval.
Double_t mean = 0;
Double_t sumw2 = 0;
nent=nent+h1->GetBinContent(startBin+k);
sumw2=sumw2+(h1->GetBinCenter(startBin+k))*(h1->GetBinCenter(startBin+k))*(h1->GetBinContent(startBin+k));
}
-
mean= mean/nent; //<x>
sumw2=sumw2/nent; //<x^2>
Double_t rmsmean= 0;
rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
- if (i<npads) {
- AliTOFChannelOnline * ch = fCal->GetChannel(i);
+ if (ich<npads) {
+ AliTOFChannelOnline * ch = fCal->GetChannel(ich);
ch->SetDelay(mean);
}
+ delete h1;
+ h1=0x0;
}
}
daqFile->Close();
metaData.SetBeamPeriod(0);
metaData.SetResponsible("Chiara Zampolli");
metaData.SetComment("This preprocessor fills an AliTOFCal object.");
+ AliInfo("Storing Calibration Data");
resultDAQ = Store("Calib","OnlineDelay",fCal, &metaData);
- result+=resultDAQ*2*2;
+ if(!resultDAQ){
+ Log("Some problems occurred while storing DAQ data processing results");
+ return 8;//return error code for problems in storing DAQ data
+ }
}
else{
- AliError(Form("The file %s does not exist",fileName));
+ Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle");
+ return 6;//return error code for problems in retrieving DAQ data
}
}
}
else{
- AliInfo(Form("Problem: no list found"));
+ Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
+ return 6; //return error code for problems in retrieving DAQ data
}
- delete list;
- list = 0;
daqFile=0;
- delete fData;
- fData = 0;
- delete fCal;
- fCal = 0;
- delete fArray;
- fArray = 0;
- return result;
+
+ return 0;
}