]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFPreprocessor.cxx
Better method to find area and length of a ring (needed to normalize n. of photons)
[u/mrichter/AliRoot.git] / TOF / AliTOFPreprocessor.cxx
index 8c1279d567c22b3ca95ca2b8eedfc7b26c26ae4e..bc3b44746b44bd86c3018f3e194019641c633350 100644 (file)
 
 #include "AliCDBMetaData.h"
 #include "AliLog.h"
-#include "AliTOFCalOnline.h"
 #include "AliTOFChannelOnline.h"
 #include "AliTOFDataDCS.h"
-#include "AliTOFGeometryV5.h"
+#include "AliTOFGeometry.h"
 #include "AliTOFPreprocessor.h"
 
 class TF1;
@@ -61,9 +60,11 @@ AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
   fData(0),
   fh2(0),
   fCal(0),
-  fTOFGeometry(0)
+  fNChannels(0),
+  fStoreRefData(kTRUE)
 {
   // constructor
+
 }
 
 //_____________________________________________________________________________
@@ -71,14 +72,19 @@ AliTOFPreprocessor::AliTOFPreprocessor(AliShuttleInterface* shuttle) :
 AliTOFPreprocessor::~AliTOFPreprocessor()
 {
   // destructor
-  delete fData;
-  fData = 0;
-  delete fh2;
-  fh2 = 0;
-  delete fCal;
-  fCal = 0;
-  delete fTOFGeometry;
-  fTOFGeometry = 0;
+  if (fData){
+    delete fData;
+    fData = 0;
+  }
+  if (fh2){
+    delete fh2;
+    fh2 = 0;
+  }
+  if (fCal){
+    //    fCal->Clear();
+    delete fCal;
+    fCal = 0;
+  }
 }
 
 //______________________________________________________________________________
@@ -95,9 +101,13 @@ void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
 
        fData = new AliTOFDataDCS(fRun, fStartTime, fEndTime);
        fh2 = 0x0;
-       fTOFGeometry = new AliTOFGeometryV5();
-       fCal = new AliTOFCalOnline(fTOFGeometry);
-       fCal->CreateArray();
+       fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
+       fCal = new TObjArray(fNChannels);
+       fCal->SetOwner();
+       for (Int_t ich = 0; ich<fNChannels; ich ++){
+         AliTOFChannelOnline * calChOnline = new AliTOFChannelOnline();
+         fCal->AddAt(calChOnline,ich);
+       }
 }
 
 //_____________________________________________________________________________
@@ -105,75 +115,102 @@ void AliTOFPreprocessor::Initialize(Int_t run, UInt_t startTime,
 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 in Ref Data
+  // 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
 
   TH1::AddDirectory(0);
-  UInt_t resultDCS=0;
-  UInt_t resultDAQ=0;
-  UInt_t resultDAQRef=0;
-  UInt_t result=0;
+
+  Bool_t resultDCSMap=kFALSE;
+  Bool_t resultDCSStore=kFALSE;
+  Bool_t resultDAQ=kFALSE;
+  Bool_t resultDAQRef=kFALSE;
 
   // processing DCS
 
   if (!dcsAliasMap){
-    Log("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){
-      Log("Some problems occurred while storing DCS data processing results");
-      return 0;
+    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 = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
+      if (!resultDCSStore){
+       Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
+       return 3;// return error Code for processed DCS data not stored 
+                // in reference data
+       
+      }
     }
   }
-
+  
   // processing DAQ
-
+  
   TFile * daqFile=0x0;
-
-  //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.");
-         resultDAQRef = StoreReferenceData("Calib","DAQData",fh2, &metaDataHisto);
-         //      result+=resultDAQRef*2;
-         if (!resultDAQRef){
-           Log("some problems occurred::No Reference Data stored, still going on (please check!)");
+  
+  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 
          }
-         daqFile->Close();
-         delete daqFile;
        }
-
-       else{
-          Log("The input data file from DAQ (run-level) was not found, still going on with Cumulative data file (please check!) "); 
-        }
       }
-    }
-  else{
-    Log("The input data file list from DAQ (run-level) was not found, still going on with Cumulative data file (please check!) "); 
+    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 
+    }  
   }
 
-  //Total files, with summed histos
 
+//Total files, with cumulative histos
+  
   TList* listTot = GetFileSources(kDAQ, "DELAYS");
   if (listTot)
     {
@@ -189,21 +226,21 @@ UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
          AliInfo(Form("Got the file %s, now we can extract some values.", fileName.Data()));
 
          daqFile = new TFile(fileName.Data(),"READ");
+         if (fh2) delete fh2;
          fh2 = (TH2S*) daqFile->Get("htoftot");
          if (!fh2){
            Log("some problems occurred:: No histo retrieved, TOF exiting from Shuttle");
            delete daqFile;
-           return 0;
+           return 7; //return error code for histograms not existing/junky
          }
          else {
            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();
-           if (kSize != npads){
+           if (kSize != fNChannels){
              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 0;
+              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);
@@ -239,9 +276,9 @@ UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
              sumw2=sumw2/nent; //<x^2>
              Double_t rmsmean= 0;
              rmsmean = TMath::Sqrt((sumw2-mean*mean)/nent);
-             if (ich<npads) {
-               AliTOFChannelOnline * ch = fCal->GetChannel(ich);
-               ch->SetDelay(mean);
+             if (ich<fNChannels) {
+               AliTOFChannelOnline * ch = (AliTOFChannelOnline *)fCal->At(ich);
+               ch->SetDelay((Double_t)mean*AliTOFGeometry::TdcBinWidth()*1.E-3);  // delay in ns
              }
            delete h1;
            h1=0x0;
@@ -253,37 +290,27 @@ UInt_t AliTOFPreprocessor::Process(TMap* dcsAliasMap)
          metaData.SetBeamPeriod(0);
          metaData.SetResponsible("Chiara Zampolli");
          metaData.SetComment("This preprocessor fills an AliTOFCal object.");
-         resultDAQ = Store("Calib","OnlineDelay",fCal, &metaData);
+         AliInfo("Storing Calibration Data");
+         resultDAQ = Store("Calib","ParOnline",fCal, &metaData);
           if(!resultDAQ){
            Log("Some problems occurred while storing DAQ data processing results");
-           return 0;
+           return 8;//return error code for problems in storing DAQ data 
          }
        }
        else{
          Log("The Cumulative data file from DAQ does not exist, TOF exiting from Shuttle"); 
-          return 0;
+          return 6;//return error code for problems in retrieving DAQ data 
        }
       }
     }
   else{
     Log("Problem: no list for Cumulative data file from DAQ was found, TOF exiting from Shuttle");
-    return 0;
+    return 6; //return error code for problems in retrieving DAQ data 
   }
 
-  //  delete list;
-  // list = 0;
-  // delete listTot;
-  // listTot = 0;
   daqFile=0;
 
-  if(resultDCS ==2|| resultDAQ ==2) {
-    result=2;
-  }
-  else{ 
-    result=1;
-  }
-
-  return result;
+  return 0;
 }