]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFPreprocessor.cxx
Coverity fixes
[u/mrichter/AliRoot.git] / TOF / AliTOFPreprocessor.cxx
index 75acf465451d1be4b133950b904cfc4c3bf18e18..99cb61ed2da4ef39fb8fb717e702f5e92d20debd 100644 (file)
 #include "TChain.h"
 #include "AliTOFDeltaBCOffset.h"
 #include "AliTOFCTPLatency.h"
-#include "AliTOFT0Fill.h"
+#include "AliTOFRunParams.h"
 #include "AliTOFT0FillOnlineCalib.h"
 #include "AliTOFHitField.h"
 #include "AliTOFChannelOffline.h"
 #include "TF1.h"
 #include "TGeoManager.h"
 #include "AliGeomManager.h"
+#include "AliTOFReadoutInfo.h"
 
 // TOF preprocessor class.
 // It takes data from DCS and passes them to the class AliTOFDataDCS, which
@@ -168,8 +169,6 @@ UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap *dcsAliasMap)
 
   // processing DCS
 
-  fData->SetFDRFlag(fFDRFlag);
-  
   if (!dcsAliasMap){
     Log("No DCS map found: TOF exiting from Shuttle");
     if (fData){
@@ -180,7 +179,9 @@ UInt_t AliTOFPreprocessor::ProcessDCSDataPoints(TMap *dcsAliasMap)
   }
   else {
 
-  // The processing of the DCS input data is forwarded to AliTOFDataDCS
+    fData->SetFDRFlag(fFDRFlag);
+  
+    // The processing of the DCS input data is forwarded to AliTOFDataDCS
     resultDCSMap=fData->ProcessData(*dcsAliasMap);
     if(!resultDCSMap){
       Log("Some problems occurred while processing DCS data, TOF exiting from Shuttle");
@@ -235,8 +236,6 @@ UInt_t AliTOFPreprocessor::ProcessHVandLVdps(TMap *dcsAliasMap)
 
   // processing DCS HV and LV data points
 
-  fHVLVmaps->SetFDRFlag(fFDRFlag);
-  
   if (!dcsAliasMap){
     Log("No DCS map found: TOF exiting from Shuttle");
     if (fHVLVmaps){
@@ -247,6 +246,8 @@ UInt_t AliTOFPreprocessor::ProcessHVandLVdps(TMap *dcsAliasMap)
   }
   else {
 
+    fHVLVmaps->SetFDRFlag(fFDRFlag);
+  
     // The processing of the DCS input data is forwarded to AliTOFDataDCS
     //if (0) { // AdC
     resultDCSMap = fHVLVmaps->ProcessData(*dcsAliasMap);
@@ -447,7 +448,7 @@ UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
                          integralThr = tmpstr.Atof();
                  }
                  else {
-                         Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %i",integralThr));
+                         Log(Form("No IntegralThr value found in Map from Config entry in CDB, using default value: IntegralThr = %f",integralThr));
                  }
                  TObjString *strThrPar = (TObjString*)configMap->GetValue("ThrPar");
                  if (strThrPar) {
@@ -455,7 +456,7 @@ UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
                          thrPar = tmpstr.Atof();
                  }
                  else {
-                         Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %i",thrPar));
+                         Log(Form("No ThrPar value found in Map from Config entry in CDB, using default value: ThrPar = %f",thrPar));
                  }
          }
   }
@@ -505,6 +506,10 @@ UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
                          list->Print();
                          for (Int_t jj=0;jj<list->GetEntries();jj++){
                                  TObjString * str = dynamic_cast<TObjString*> (list->At(jj));
+                                 if (!str) {
+                                   AliError("dynamic_cast returned NULL");
+                                   return 4;
+                                 }
                                  AliInfo(Form("found source %s", str->String().Data()));
                                  // file to be stored run per run
                                  TString fileNameRun = GetFile(kDAQ, "RUNLevel", str->GetName());
@@ -557,7 +562,11 @@ UInt_t AliTOFPreprocessor::ProcessOnlineDelays()
                  AliInfo("The following sources produced files with the id DELAYS");
                  listTot->Print();
                  for (Int_t jj=0;jj<listTot->GetEntries();jj++){
-                         TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
+                   TObjString * str = dynamic_cast<TObjString*> (listTot->At(jj));
+                   if (!str) {
+                     AliError("dynamic_cast returned NULL");
+                                   return 4;
+                         }
                          AliInfo(Form("found source %s", str->String().Data()));
                          
                          // file with summed histos, to extract calib params
@@ -745,33 +754,33 @@ AliTOFPreprocessor::ProcessT0Fill()
   /* get params from OCDB */
   AliCDBEntry *cdbe = NULL;
 
-  /* get T0-fill calibration params */
-  cdbe = GetFromOCDB("Calib", "T0FillOnlineCalib");
+  /*
+   * check UseLHCClockPhase flag in RunParams.
+   * if set do nothing and return successfully
+   */
+  cdbe = GetFromOCDB("Calib", "RunParams");
   if (!cdbe) {
-    Log("cannot get \"T0FillOnlineCalib\" entry from OCDB");
+    Log("cannot get \"RunParams\" entry from OCDB");
     return 21;
   }
-  AliTOFT0FillOnlineCalib *t0FillOnlineCalibObject = (AliTOFT0FillOnlineCalib *)cdbe->GetObject();
-  if (!t0FillOnlineCalibObject) {
-    Log("cannot get \"T0FillOnlineCalib\" object from CDB entry");
-    return 21;
+  AliTOFRunParams *runparams = (AliTOFRunParams *)cdbe->GetObject();
+  if (runparams->GetUseLHCClockPhase()) {
+    Log("UseLHCClockPhase flag is set in RunParams: online T0-fill not computed");
+    return 0;
   }
-  Float_t t0FillCalibOffset = t0FillOnlineCalibObject->GetOffset();
-  Float_t t0FillCalibCoefficient = t0FillOnlineCalibObject->GetCoefficient();
-  Log(Form("got \"T0FillOnlineCalib\" object: offset=%f coeff=%f", t0FillCalibOffset, t0FillCalibCoefficient));
 
-  /* get online status from OCDB */
-  cdbe = GetFromOCDB("Calib", "Status");
-  if (!cdbe) {
-    Log("cannot get \"Status\" entry from OCDB");
-    return 21;
-  }
-  AliTOFChannelOnlineStatusArray *statusArray = (AliTOFChannelOnlineStatusArray *)cdbe->GetObject();
-  if (!statusArray) {
-    Log("cannot get \"Status\" object from CDB entry");
+  /* 
+   * at this stage status object is not on OCDB yet
+   * since it will be stored later. nevertheless we
+   * should have the array in memory since it has been
+   * already setup by ProcessFEF. 
+   */
+  
+  /* check status and latency window available */
+  if (!fStatus || !fLatencyWindow){
+    AliError("No valid fStatus or fLatencyWindow found, some errors must have occurred!!");
     return 21;
   }
-  Log("got \"Status\" object");
 
   /* get offline calibration from OCDB */
   cdbe = GetFromOCDB("Calib", "ParOffline");
@@ -866,12 +875,14 @@ AliTOFPreprocessor::ProcessT0Fill()
     totbin = hit->GetTOTBin();
     deltaBC = hit->GetDeltaBC();
     l0l1latency = hit->GetL0L1Latency();
-    latencyWindow = statusArray->GetLatencyWindow(index) * 1.e3;
+    latencyWindow = fLatencyWindow[index] * 1.e3;
     
     /* convert time in ps and tot in ns */
     timeps = timebin * AliTOFGeometry::TdcBinWidth();
     totns = totbin * AliTOFGeometry::ToTBinWidth() * 1.e-3;
     /* get calibration correction in ps */
+    
+
     channelOffline = (AliTOFChannelOffline *)offlineArray->At(index);
     if (totns < AliTOFGeometry::SlewTOTMin()) totns = AliTOFGeometry::SlewTOTMin();
     if (totns > AliTOFGeometry::SlewTOTMax()) totns = AliTOFGeometry::SlewTOTMax();
@@ -879,7 +890,8 @@ AliTOFPreprocessor::ProcessT0Fill()
     for (Int_t ipar = 0; ipar < 6; ipar++) corrps += channelOffline->GetSlewPar(ipar) * TMath::Power(totns, ipar);
     corrps *= 1.e3;
     /* perform time correction */
-    timeps = timeps + (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth() + l0l1latency * AliTOFGeometry::BunchCrossingBinWidth() + ctpLatency - latencyWindow - corrps;
+    //    timeps = timeps + (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth() + l0l1latency * AliTOFGeometry::BunchCrossingBinWidth() + ctpLatency - latencyWindow - corrps; /* deltaBC correction removed for the time being */
+    timeps = timeps + l0l1latency * AliTOFGeometry::BunchCrossingBinWidth() + ctpLatency - latencyWindow - corrps;
     /* compute length and expected time */
     tofGeo.GetVolumeIndices(index, det);
     tofGeo.GetPosPar(det, pos);
@@ -906,36 +918,54 @@ AliTOFPreprocessor::ProcessT0Fill()
   }
   Float_t maxBinCenter = hT0Fill->GetBinCenter(maxBin);
 
-  /* rough landau fit of the edge */
-  TF1 *landau = (TF1 *)gROOT->GetFunction("landau");
-  landau->SetParameter(1, maxBinCenter);
-  Float_t fitMin = maxBinCenter - 1000.; /* fit from 10 ns before max */
-  Float_t fitMax = maxBinCenter + binWidth; /* fit until a bin width above max */
-  hT0Fill->Fit("landau", "q0", "", fitMin, fitMax);
-  /* get rough landau mean and sigma to set a better fit range */
-  Float_t mean = landau->GetParameter(1);
-  Float_t sigma = landau->GetParameter(2);
-  /* better landau fit of the edge */
-  fitMin = maxBinCenter - 3. * sigma;
-  fitMax = mean;
-  hT0Fill->Fit("landau", "q0", "", fitMin, fitMax);
+  /* rough fit of the edge */
+  TF1 *gaus = (TF1 *)gROOT->GetFunction("gaus");
+  gaus->SetParameter(1, maxBinCenter);
+  Float_t fitMin = maxBinCenter - 1000.; /* fit from 1 ns before max */
+  Float_t fitMax = maxBinCenter + 1000.; /* fit until 1 ns above max */
+  hT0Fill->Fit("gaus", "q0", "", fitMin, fitMax);
+  /* better fit of the edge */
+  Float_t mean, sigma;
+  for (Int_t istep = 0; istep < 10; istep++) {
+    mean = gaus->GetParameter(1);
+    sigma = gaus->GetParameter(2);
+    fitMin = mean - 3. * sigma;
+    fitMax = mean;
+    hT0Fill->Fit("gaus", "q0", "", fitMin, fitMax);
+  }
   /* print params */
-  mean = landau->GetParameter(1);
-  sigma = landau->GetParameter(2);
-  Float_t meane = landau->GetParError(1);
-  Float_t sigmae = landau->GetParError(2);
+  mean = gaus->GetParameter(1);
+  sigma = gaus->GetParameter(2);
+  Float_t meane = gaus->GetParError(1);
+  Float_t sigmae = gaus->GetParError(2);
   Log(Form("edge fit: mean  = %f +- %f ps", mean, meane));
   Log(Form("edge fit: sigma = %f +- %f ps", sigma, sigmae));
-  Float_t edge = mean - 3. * sigma;
-  Float_t edgee = TMath::Sqrt(meane * meane + 3. * sigmae * 3. * sigmae);
-  Log(Form("edge fit: edge = %f +- %f ps", edge, edgee));
-  /* apply calibration to get T0-fill from egde */
-  Float_t t0Fill = edge * t0FillCalibCoefficient + t0FillCalibOffset;
-  Log(Form("estimated T0-fill: %f ps", t0Fill));
+  /* check error */
+  if (meane > 300.) {
+    Log("error on mean is large: store default T0-fill value (0 ps)");
+    mean = 0.;
+  }
+  if (sigmae > 300.) {
+    Log("error on sigma is large: store default TOFreso value (200 ps)");
+    sigma = 200.;
+  }
 
-  /* create T0-fill object */
-  AliTOFT0Fill *t0FillObject = new AliTOFT0Fill();
-  t0FillObject->SetT0Fill(t0Fill);
+  /* scratch values from the fit and use max bin center as t0-fill */
+  mean = maxBinCenter;
+  sigma = -1.;
+  Log(Form("do not care about fitted value, just use max bin as t0-fill: %f ps", mean));
+
+  /* create RunParams object */
+  UInt_t timestamp[1] = {0};
+  Float_t t0[1] = {mean};
+  Float_t tofReso[1] = {sigma};
+  Float_t t0Spread[1] = {-1.};
+  AliTOFRunParams *runParamsObject = new AliTOFRunParams(1);
+  runParamsObject->SetTimestamp(timestamp);
+  runParamsObject->SetT0(t0);
+  runParamsObject->SetTOFResolution(tofReso);
+  runParamsObject->SetT0Spread(t0Spread);
+  runParamsObject->SetUseLHCClockPhase(kFALSE);
 
   /* store reference data */
   if(fStoreRefData){
@@ -947,7 +977,7 @@ AliTOFPreprocessor::ProcessT0Fill()
       Log("error while storing reference data");
       delete hT0Fill;
       delete hit;
-      delete t0FillObject;
+      delete runParamsObject;
       return 21;
     }
     Log("reference data successfully stored");
@@ -956,23 +986,262 @@ AliTOFPreprocessor::ProcessT0Fill()
   AliCDBMetaData metaData;
   metaData.SetBeamPeriod(0);
   metaData.SetResponsible("Roberto Preghenella");
-  metaData.SetComment("online T0-fill measurement");
-  if (!Store("Calib", "T0Fill", t0FillObject, &metaData, 0, kFALSE)) {
-    Log("error while storing T0-fill object");
+  metaData.SetComment("online RunParams measurement");
+  if (!Store("Calib", "RunParams", runParamsObject, &metaData, 0, kFALSE)) {
+    Log("error while storing RunParams object");
     delete hT0Fill;
     delete hit;
-    delete t0FillObject;
+    delete runParamsObject;
     return 21;
   }
-  Log("T0-fill object successfully stored");
+  Log("RunParams object successfully stored");
 
   delete hT0Fill;
   delete hit;
-  delete t0FillObject;
+  delete runParamsObject;
   return 0;
 
 }
  
+//_____________________________________________________________________________
+
+UInt_t 
+AliTOFPreprocessor::ProcessNoiseCalibTrg()
+{
+  // Processing data from DAQ using calibration triggers for noise measurement 
+
+  Log("Processing Noise (calibration trigger)");
+
+  /* check status and matching window available */
+  if (!fStatus || !fMatchingWindow){
+    AliError("No valid fStatus or fMatchingWindow found, some errors must have occurred!!");
+    return 22;
+  }
+
+  Float_t noiseThr = 1000.;   // setting default threshold for noise to 1000 Hz
+  // reading config map
+  AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
+  if (!cdbEntry) Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %f",noiseThr));
+  else {
+    TMap *configMap = (TMap*)cdbEntry->GetObject();
+    if (!configMap) Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %f", noiseThr));
+    else {
+      TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
+      if (strNoiseThr) {
+       TString tmpstr = strNoiseThr->GetString();
+       noiseThr = tmpstr.Atoi();
+      }
+      else Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %f",noiseThr));
+    }
+  }
+
+  /* get file sources from FXS */
+  TList *fileList = GetFileSources(kDAQ, "CALIB");
+  if (!fileList || fileList->GetEntries() == 0) {
+    Log("cannot get DAQ source file list or empty list");
+    return 22;
+  }
+  Log(Form("got DAQ source file list: %d files", fileList->GetEntries()));
+  fileList->Print();
+
+  /* open input file (only one expected) */
+  TObjString *str = (TObjString *)fileList->At(0);
+  TString filename = GetFile(kDAQ, "CALIB", str->GetName());
+  Log(Form("opening input file: source=%s, filename=%s", str->String().Data(), filename.Data()));
+  TFile *filein = TFile::Open(filename.Data());
+  if (!filein || !filein->IsOpen()) {
+    Log("cannot open input file");
+    return 22;
+  }
+
+  /* get histo from input file */
+  TH1F *hCalibHit = (TH1F *)filein->Get("hCalibHit");
+  if (!hCalibHit) {
+    Log("cannot get \"hCalibHit\" histo");
+    return 22;
+  }
+
+  /* create and set noise rate histo and check rate */
+  TH1F *hNoiseRate = new TH1F("hNoiseRate", ";index;rate (Hz)", fNChannels, 0., fNChannels);
+  Float_t rate, rate_err;
+  for (Int_t ich = 0; ich < fNChannels; ich++) {
+    /* check channel enabled */
+    if (fStatus->GetHWStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFHWBad) continue;
+    /* set noise rate histo */
+    rate = hCalibHit->GetBinContent(ich + 1);
+    rate_err = hCalibHit->GetBinError(ich + 1);
+    rate /= fMatchingWindow[ich] * 1.e-9;
+    rate_err /= fMatchingWindow[ich] * 1.e-9;
+    hNoiseRate->SetBinContent(ich + 1, rate);
+    hNoiseRate->SetBinError(ich + 1, rate_err);
+    /* check error */
+    if (rate_err == 0.) continue;
+    /* check noise rate and set noise flags */
+    if ((rate - 3. * rate_err) > noiseThr) {
+      Log(Form("channel %d detected as noisy: rate = (%f +- %f) Hz", ich, rate, rate_err));
+      if (fStatus->GetNoiseStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFNoiseOk) {
+       Log(Form("channel %d noise status changed from Ok to Bad", ich));
+       fStatus->SetNoiseStatus(ich, AliTOFChannelOnlineStatusArray::kTOFNoiseBad);
+       fIsStatusMapChanged = kTRUE;
+      }
+      else Log(Form("channel %d noise status unchanged", ich));
+    }
+    else if ((rate + 3. * rate_err) < noiseThr) {
+      if (fStatus->GetNoiseStatus(ich) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) {
+       Log(Form("channel %d noise status changed from Bad to Ok", ich));
+       fStatus->SetNoiseStatus(ich, AliTOFChannelOnlineStatusArray::kTOFNoiseOk);
+       fIsStatusMapChanged = kTRUE;
+      }
+    }
+  }
+
+  /* store reference data */
+  if(fStoreRefData){
+    AliCDBMetaData metaDataHisto;
+    metaDataHisto.SetBeamPeriod(0);
+    metaDataHisto.SetResponsible("Roberto Preghenella");
+    metaDataHisto.SetComment("calibration trigger noise rate histogram");
+    if (!StoreReferenceData("Calib","CalibNoise", hNoiseRate, &metaDataHisto)) {
+      Log("error while storing reference data");
+      delete hNoiseRate;
+      filein->Close();
+      return 22;
+    }
+    Log("reference data successfully stored");
+  }
+
+  delete hNoiseRate;
+  filein->Close();
+  return 0;
+}
+
+//_____________________________________________________________________________
+
+UInt_t 
+AliTOFPreprocessor::ProcessReadout()
+{
+  // Processing data from DAQ to compute reaodut efficiency
+
+  Log("Processing Readout");
+
+  /* get file sources from FXS */
+  TList *fileList = GetFileSources(kDAQ, "READOUT");
+  if (!fileList || fileList->GetEntries() == 0) {
+    Log("cannot get DAQ source file list or empty list");
+    return 22;
+  }
+  Log(Form("got DAQ source file list: %d files", fileList->GetEntries()));
+  fileList->Print();
+
+  /* open input file (only one expected) */
+  TObjString *str = (TObjString *)fileList->At(0);
+  TString filename = GetFile(kDAQ, "READOUT", str->GetName());
+  Log(Form("opening input file: source=%s, filename=%s", str->String().Data(), filename.Data()));
+  TFile *filein = TFile::Open(filename.Data());
+  if (!filein || !filein->IsOpen()) {
+    Log("cannot open input file");
+    return 23;
+  }
+
+  /* get histo from input file */
+  TH1F *hChainEfficiency = (TH1F *)filein->Get("hChainEfficiency");
+  if (!hChainEfficiency) {
+    Log("cannot get \"hChainEfficiency\" histo");
+    return 23;
+  }
+
+  /* fill channel efficiency histo */
+
+ /* temporarly disable warnings */
+  AliLog::EType_t logLevel = (AliLog::EType_t)AliLog::GetGlobalLogLevel();
+  AliLog::SetGlobalLogLevel(AliLog::kError);
+
+  TH1F *hChannelEfficiency = new TH1F("hChannelEfficiency", "Channel readout efficiency;index;efficiency", fNChannels, 0., fNChannels);
+  Int_t chainIndex, det[5], dummy, index;
+  Float_t effi, effi_err;
+  /* loop over DDLs */
+  for (Int_t iddl = 0; iddl < 72; iddl++) {
+    /* loop over TRMs */
+    for (Int_t itrm = 0; itrm < 10; itrm++) {
+      /* loop over chains */
+      for (Int_t ichain = 0; ichain < 2; ichain++) {
+       chainIndex = ichain + 2 * itrm + 20 * iddl;
+       effi = hChainEfficiency->GetBinContent(chainIndex + 1);
+       effi_err = hChainEfficiency->GetBinError(chainIndex + 1);
+       /* loop over TDCs */
+       for (Int_t itdc = 0; itdc < 15; itdc++) {
+         /* loop over channels */
+         for (Int_t ichannel = 0; ichannel < 8; ichannel++) {
+
+           /* get channel index */
+           AliTOFRawStream::EquipmentId2VolumeId(iddl, itrm + 3, ichain, itdc, ichannel, det);
+           dummy = det[4];
+           det[4] = det[3];
+           det[3] = dummy;
+           /* check valid index */
+           if (det[0] < 0 || det[0] > 17 ||
+               det[1] < 0 || det[1] > 5 ||
+               det[2] < 0 || det[2] > 18 ||
+               det[3] < 0 || det[3] > 1 ||
+               det[4] < 0 || det[4] > 47) continue;
+           index = AliTOFGeometry::GetIndex(det);
+
+           /* set channel efficiency */
+           hChannelEfficiency->SetBinContent(index + 1, effi);
+           hChannelEfficiency->SetBinError(index + 1, effi_err);
+
+         }
+       }
+      }
+    }
+  }
+
+  /* re-enable warnings */
+  AliLog::SetGlobalLogLevel(logLevel);
+
+  /* store reference data */
+  if(fStoreRefData){
+    /* setup TOF readout info object */
+    AliTOFReadoutInfo readoutInfo;
+    readoutInfo.SetChainEfficiency((TH1F *)filein->Get("hChainEfficiency"));
+    readoutInfo.SetTRMData((TH1F *)filein->Get("hTRMData"));
+    readoutInfo.SetTRMEmptyEvent((TH1F *)filein->Get("hTRMEmptyEvent"));
+    readoutInfo.SetTRMBadEventCounter((TH1F *)filein->Get("hTRMBadEventCounter"));
+    readoutInfo.SetTRMBadCRC((TH1F *)filein->Get("hTRMBadCRC"));
+    readoutInfo.SetChainData((TH1F *)filein->Get("hChainData"));
+    readoutInfo.SetChainBadStatus((TH1F *)filein->Get("hChainBadStatus"));
+    readoutInfo.SetChainBadEventCounter((TH1F *)filein->Get("hChainBadEventCounter"));
+    readoutInfo.SetTDCError((TH1F *)filein->Get("hTDCError"));
+    readoutInfo.SetTDCErrorFlags((TH2F *)filein->Get("hTDCErrorFlags"));
+
+    AliCDBMetaData metaDataHisto;
+    metaDataHisto.SetBeamPeriod(0);
+    metaDataHisto.SetResponsible("Roberto Preghenella");
+    metaDataHisto.SetComment("readout info data");
+    if (!StoreReferenceData("Calib","ReadoutInfo", &readoutInfo, &metaDataHisto)) {
+      Log("error while storing reference data");
+      filein->Close();
+      return 23;
+    }
+    Log("reference data successfully stored");
+  }
+
+  AliCDBMetaData metaData;
+  metaData.SetBeamPeriod(0);
+  metaData.SetResponsible("Roberto Preghenella");
+  metaData.SetComment("online ReadoutEfficiency measurement");
+  if (!Store("Calib", "ReadoutEfficiency", hChannelEfficiency, &metaData, 0, kFALSE)) {
+    Log("error while storing ReadoutEfficiency object");
+    delete hChannelEfficiency;
+    filein->Close();
+    return 23;
+  }
+  Log("ReadoutEfficiency object successfully stored");
+
+  delete hChannelEfficiency;
+  filein->Close();
+  return 0;
+}
 
 //_____________________________________________________________________________
 
@@ -1013,6 +1282,10 @@ UInt_t AliTOFPreprocessor::ProcessPulserData()
                  for (Int_t jj=0;jj<listPulser->GetEntries();jj++){
                          Int_t nPulserSource = 0;
                          TObjString * str = dynamic_cast<TObjString*> (listPulser->At(jj));
+                         if (!str) {
+                           AliError("dynamic_cast returned NULL");
+                           return 4;
+                         }
                          AliInfo(Form("found source %s", str->String().Data()));
                          // file to be stored run per run
                          TString fileNamePulser = GetFile(kDAQ, "PULSER", str->GetName());
@@ -1141,9 +1414,7 @@ UInt_t AliTOFPreprocessor::ProcessPulserData()
     AliCDBMetaData metaDataHisto;
     metaDataHisto.SetBeamPeriod(0);
     metaDataHisto.SetResponsible("Chiara Zampolli");
-    char comment[200];
-    sprintf(comment,"This preprocessor stores the Ref data from a pulser run.");
-    metaDataHisto.SetComment(comment);
+    metaDataHisto.SetComment("This preprocessor stores the Ref data from a pulser run.");
     AliInfo("Storing Reference Data");
     resultPulserRef = StoreReferenceData("Calib","PulserData",htofPulser, &metaDataHisto);
     if (!resultPulserRef){
@@ -1188,12 +1459,12 @@ UInt_t AliTOFPreprocessor::ProcessNoiseData()
   // reading config map
   AliCDBEntry *cdbEntry = GetFromOCDB("Calib","ConfigNoise");
   if (!cdbEntry) {
-         Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %d",noiseThr));
+         Log(Form("No Configuration entry found in CDB, using default values: NoiseThr = %f",noiseThr));
   }
   else {
          TMap *configMap = (TMap*)cdbEntry->GetObject();
          if (!configMap){
-                 Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %d", noiseThr));
+                 Log(Form("No map found in Config entry in CDB, using default values: NoiseThr = %f", noiseThr));
          }
          else{
                  TObjString *strNoiseThr = (TObjString*)configMap->GetValue("NoiseThr");
@@ -1202,7 +1473,7 @@ UInt_t AliTOFPreprocessor::ProcessNoiseData()
                          noiseThr = tmpstr.Atoi();
                  }
                  else {
-                         Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %i",noiseThr));
+                         Log(Form("No NoiseThr value found in Map from ConfigNoise entry in CDB, using default value: NoiseThr = %f",noiseThr));
                  }
          }
   }
@@ -1243,6 +1514,10 @@ UInt_t AliTOFPreprocessor::ProcessNoiseData()
                  for (Int_t jj=0;jj<listNoise->GetEntries();jj++){
                          Int_t nNoiseSource = 0;
                          TObjString * str = dynamic_cast<TObjString*> (listNoise->At(jj));
+                         if (!str) {
+                           AliError("dynamic_cast returned NULL");
+                           return 4;
+                         }
                          AliInfo(Form("found source %s", str->String().Data()));
                          // file to be stored run per run
                          TString fileNameNoise = GetFile(kDAQ, "NOISE", str->GetName());
@@ -1382,9 +1657,7 @@ UInt_t AliTOFPreprocessor::ProcessNoiseData()
     AliCDBMetaData metaDataHisto;
     metaDataHisto.SetBeamPeriod(0);
     metaDataHisto.SetResponsible("Chiara Zampolli");
-    char comment[200];
-    sprintf(comment,"This preprocessor stores the Ref data from a noise run. ");
-    metaDataHisto.SetComment(comment);
+    metaDataHisto.SetComment("This preprocessor stores the Ref data from a noise run. ");
     AliInfo("Storing Reference Data");
     resultNoiseRef = StoreReferenceData("Calib","NoiseData",htofNoise, &metaDataHisto);
     if (!resultNoiseRef){
@@ -1591,14 +1864,11 @@ UInt_t AliTOFPreprocessor::Process(TMap *dcsAliasMap)
   if (runType == "PHYSICS") {
     //    Int_t iresultDAQ = ProcessOnlineDelays();
     Int_t iresultDAQ = ProcessT0Fill();
-    if (iresultDAQ != 0) {
-      return iresultDAQ;
-    }
-    else {
-      Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
-      Int_t iResultHVandLVdps = ProcessHVandLVdps(dcsAliasMap);
-      return iresultDCS+iResultHVandLVdps;
-    }
+    Int_t iresultNoiseCalib = ProcessNoiseCalibTrg();
+    Int_t iresultReadout = ProcessReadout();
+    Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
+    Int_t iResultHVandLVdps = ProcessHVandLVdps(dcsAliasMap);
+    return iresultDAQ+iresultNoiseCalib+iresultDCS+iResultHVandLVdps+iresultReadout;
   }
 
   // storing
@@ -1673,6 +1943,7 @@ AliTOFPreprocessor::FillWithCableLengthMap(AliTOFChannelOnlineArray *cal)
            
            /* get channel index */
            index = AliTOFGeometry::GetIndex(det);
+           if (index < 0) continue;
            
            /* get cable time shift */
            cableTimeShift = AliTOFCableLengthMap::GetCableTimeShift(iddl, islot, ichain, itdc);