Esempio n. 1
0
Bool_t
RecoParamWithTPCDistortions(AliCDBManager *man) {

  // check methods exist
  if (!AliRecoParam::Class()->GetMethodAny("SuggestRunEventSpecie"))
    return kFALSE;
  if (!AliTPCRecoParam::Class()->GetMethodAny("GetUseCorrectionMap"))
    return kFALSE;
  
  // get event specie from GRP
  AliCDBEntry *grpe = man->Get("GRP/GRP/Data");
  if (!grpe) return kFALSE;
  AliGRPObject *grp = (AliGRPObject *)grpe->GetObject();
  AliRecoParam::EventSpecie_t evs = AliRecoParam::SuggestRunEventSpecie(grp->GetRunType(),
									grp->GetBeamType(),
									grp->GetLHCState());

  // get TPC RecoParam for event specie
  AliCDBEntry *pare = man->Get("TPC/Calib/RecoParam");
  if (!pare) return kFALSE;
  TObjArray *parl = (TObjArray *)pare->GetObject();
  AliTPCRecoParam *par = NULL;
  for (Int_t i = parl->GetEntriesFast(); i--;) {
    AliTPCRecoParam *p = (AliTPCRecoParam *)parl->UncheckedAt(i);
    if (!p || !(p->GetEventSpecie() & evs)) continue;
    par = p;
    break;
  }
  // check if use correction map
  if (!par->GetUseCorrectionMap())
    return kFALSE;

  return kTRUE;
  
}
Esempio n. 2
0
//_________________________________________________________________________________________________
void GetTimeRange(Int_t runNumber, time_t& start, time_t& end)
{
  AliCDBManager::Instance()->SetRun(runNumber);

  AliCDBEntry* e = AliCDBManager::Instance()->Get("GRP/GRP/Data");

  AliGRPObject* grp = static_cast<AliGRPObject*>(e->GetObject());

  start = grp->GetTimeStart();
  end = grp->GetTimeEnd();

  TDatime dstart(start);
  TDatime dend(end);

  dstart.Set(dstart.GetYear(),dstart.GetMonth(),dstart.GetDay(),dstart.GetHour(),0,0);
  dend.Set(dend.GetYear(),dend.GetMonth(),dend.GetDay(),dend.GetHour()+1,0,0);
  
  std::cout << TDatime(start).AsString() << std::endl;
  std::cout << TDatime(end).AsString() << std::endl;

  std::cout << dstart.AsString() << std::endl;
  std::cout << dend.AsString() << std::endl;

  start = dstart.Convert(kFALSE);
  end = dend.Convert(kFALSE);
}
Esempio n. 3
0
Float_t
SetEnergyFromGRP()
{
  AliCDBEntry *cdbe = AliCDBManager::Instance()->Get("GRP/GRP/Data");
  AliGRPObject *grpd = dynamic_cast<AliGRPObject*>(cdbe->GetObject()); 
  return (grpd->GetBeamEnergy() * 2.);
}
Esempio n. 4
0
void DefaultSpecificStorage(AliCDBManager *man, Int_t mode)
{

  AliCDBEntry *cdbe = man->Get("GRP/GRP/Data");
  if (!cdbe) return NULL;
  AliGRPObject *grp = (AliGRPObject *)cdbe->GetObject();
  TDatime date = grp->GetTimeStart();
  Int_t year = date.GetYear();

  const Char_t *Raw      = Form("alien://Folder=/alice/data/%d/OCDB", year);
  const Char_t *Ideal    = "alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/";
  const Char_t *Residual = "alien://Folder=/alice/simulation/2008/v4-15-Release/Residual/";
  const Char_t *Full     = "alien://Folder=/alice/simulation/2008/v4-15-Release/Full/";
  // for AD hack 
  const Char_t *Raw2015  = "alien://Folder=/alice/data/2015/OCDB";
  
  // DEFAULT SPECIFIC OBJECTS 
  const Char_t *SpecificStorageList[][3] = {
    // path                    sim       rec
    //
    // ITS
    "ITS/Align/Data",          Ideal,    Residual, // ok
    "ITS/Calib/SPDSparseDead", Full,     Residual, // ok ?
    // TPC
    "TPC/Calib/ClusterParam",  Ideal,    Residual, // ok!
    "TPC/Calib/RecoParam",     Residual, Residual, // ok!
    "TPC/Calib/TimeGain",      Ideal,    Residual, // ok!
    "TPC/Calib/Correction",    Ideal,    Residual, // ok!
    // MUON
    "MUON/Align/Data",         Full,     NULL,     // ok!
    // ZDC
    "ZDC/Align/Data",          Ideal,    Ideal,    // ok
    "ZDC/Calib/Pedestals",     Ideal,    Ideal     // added (11.12.2017)
  };
  const Int_t nSpecificStorages = sizeof(SpecificStorageList) / (3 * sizeof(Char_t *));

  // set specific storages
  for (Int_t isto = 0; isto < nSpecificStorages; isto++) {
    if (SpecificStorageList[isto][mode+1]) {
      printf("Setting specific storage: %s -> %s\n", SpecificStorageList[isto][0], SpecificStorageList[isto][mode+1]);
      man->SetSpecificStorage(SpecificStorageList[isto][0], SpecificStorageList[isto][mode+1]);
    }
  }

  // EXTRA SPECIFIC OBJECTS IF NO DISTORTIONS
  if (!RecoParamWithTPCDistortions(man)) {
    printf("Not using TPC distortions, need extra specific storages\n");
    NoDistortionSpecificStorage(man, mode);
  }
  
  // Run-1 settings
  if (year < 2015) {
    man->SetSpecificStorage("AD/Calib/QAParam", Raw2015);
    const Char_t *muonHack[2] = {Ideal, Residual};
    man->SetSpecificStorage("MUON/Align/Data", muonHack[mode]);
  }

}
Esempio n. 5
0
//_____________________________________________________________________________
void    readCDB (TObject *task1,  Int_t runNumber) {

  Float_t zero_timecdb[24]={0};
  Float_t *timecdb = zero_timecdb;
  Float_t cfdvalue[24][5];
  for(Int_t i=0; i<24; i++)
    for (Int_t i0=0; i0<5; i0++)
      cfdvalue[i][i0] = 0;

  Float_t zero_shiftcdb[4]={0};
  Float_t *shiftcdb = zero_shiftcdb;
  AliT0CalibOffsetChannelsTask *mytask = (AliT0CalibOffsetChannelsTask*)task1;

  AliCDBManager* man = AliCDBManager::Instance();
  AliCDBEntry *entry = AliCDBManager::Instance()->Get("GRP/CTP/CTPtiming");
  if (!entry) ::Fatal("AddTaskT0Calib", "CTP timing parameters are not found in OCDB !");
  AliCTPTimeParams *ctpParams = (AliCTPTimeParams*)entry->GetObject();
  Float_t l1Delay = (Float_t)ctpParams->GetDelayL1L0()*25.0;

  AliCDBEntry *entry1 = AliCDBManager::Instance()->Get("GRP/CTP/TimeAlign");
  if (!entry1) ::Fatal("AddTaskT0Calib", "CTP time-alignment is not found in OCDB !");
  AliCTPTimeParams *ctpTimeAlign = (AliCTPTimeParams*)entry1->GetObject();
  l1Delay += ((Float_t)ctpTimeAlign->GetDelayL1L0()*25.0);

  AliCDBEntry *entry4 = AliCDBManager::Instance()->Get("GRP/Calib/LHCClockPhase");
  if (!entry4) ::Fatal("AddTaskT0Calib", "LHC clock-phase shift is not found in OCDB !");
  AliLHCClockPhase *phase = (AliLHCClockPhase*)entry4->GetObject();
  Float_t fGRPdelays = l1Delay - phase->GetMeanPhase();

  AliCDBEntry* entryGRP = AliCDBManager::Instance()->Get("GRP/GRP/Data");
  AliGRPObject* grpData = dynamic_cast<AliGRPObject*>(entryGRP->GetObject());
  if (!grpData) {
    ::Error("AddTaskT0Calib","Failed to get GRP data for run %d",runNumber);
    return;
  }

  TString LHCperiod = grpData->GetLHCPeriod();
  Bool_t isLHC10b =  LHCperiod.Contains("LHC10b");
  Bool_t isLHC10c =  LHCperiod.Contains("LHC10c");
  //  AliCDBEntry* entryGRP = AliCDBManager::Instance()->Get("GRP/GRP/Data");
  // AliGRPObject* grpData = dynamic_cast<AliGRPObject*>(entryGRP->GetObject());
  UInt_t timeStart = grpData->GetTimeStart();
  UInt_t timeEnd = grpData->GetTimeEnd();
  mytask->SetStartEndTime(timeStart,timeEnd);
  cout<<"T0 start time  "<<timeStart<<" end time "<<timeEnd<<endl;

  ::Info("AddTaskT0Calib","LHCperiod:%s  --->  isLHC10b:%d isLHC10c:%d",
	 LHCperiod.Data(),(Int_t)isLHC10b, (Int_t)isLHC10c);

  if(isLHC10b || isLHC10c) mytask-> SetRefPMT(12,2);

  AliCDBEntry *entryCalib0 = man->Get("T0/Calib/Latency");
  if(!entryCalib0) {
    ::Error("AddTastT0Calib","Cannot find any AliCDBEntry for [Calib, Latency]!");
    return;
  }
  AliT0CalibLatency *calibda=(AliT0CalibLatency*)entryCalib0->GetObject();
  Float_t fLatencyL1 = calibda->GetLatencyL1();
  Float_t fLatencyHPTDC = calibda->GetLatencyHPTDC();

  AliCDBEntry *entryCalib1 = man->Get("T0/Calib/TimeDelay");
  if(!entryCalib1) {
    ::Error("AddTaskT0Calib","Cannot find any AliCDBEntry for [Calib, TimeDelay]!");
    return;
  }
  else
    {
      AliT0CalibTimeEq *clb = (AliT0CalibTimeEq*)entryCalib1->GetObject();
      timecdb = clb->GetTimeEq();
      for(Int_t i=0; i<24; i++)
        for (Int_t i0=0; i0<5; i0++){
          cfdvalue[i][i0] = clb->GetCFDvalue(i, i0);
        }
    }

  for (Int_t i=0; i<24; i++) {
    Float_t cfdmean = cfdvalue[i][0];
    if( cfdvalue[i][0] < 500 || cfdvalue[i][0] > 50000) cfdmean = ( 1000.*fLatencyHPTDC - 1000.*fLatencyL1 + 1000.*fGRPdelays)/24.4;
     mytask->SetCFDvalue(i, cfdmean);
    mytask->SetTimeEq(i, timecdb[i]);
  }

  AliCDBEntry *entryCalib2 = man->Get("T0/Calib/TimeAdjust");
  if(!entryCalib2) {
    ::Error("AddTaskT0Calib","Cannot find any AliCDBEntry for [Calib, TimeAdjust]!");
  }
 else
    {
      AliT0CalibSeasonTimeShift *clb1 = (AliT0CalibSeasonTimeShift*)entryCalib2->GetObject();
      shiftcdb = clb1->GetT0Means();
    }

  for (Int_t i=0; i<4; i++)  mytask->SetT0Means(i,shiftcdb[i]);
}
Esempio n. 6
0
void makeOCDB(Int_t runNumber, TString  targetOCDBstorage="", TString sourceOCDBstorage="raw://", Int_t detectorBitsQualityFlag = -1)
{
  //
  // extract OCDB entries for detectors participating in the calibration for the current run
  //

  gROOT->Macro("$ALICE_PHYSICS/PWGPP/CalibMacros/CPass1/LoadLibraries.C");
  gROOT->LoadMacro("$ALICE_PHYSICS/PWGPP/CalibMacros/CPass1/ConfigCalibTrain.C");

  // switch off log info
  AliLog::SetClassDebugLevel("AliESDEvent",0);

  // config GRP
  printf("runNumber from runCalibTrain = %d\n",runNumber);
  ConfigCalibTrain(runNumber, sourceOCDBstorage.Data());

  // check the presence of the detectors
  AliCDBEntry* entry = AliCDBManager::Instance()->Get("GRP/GRP/Data");
  AliGRPObject* grpData = dynamic_cast<AliGRPObject*>(entry->GetObject());
  if (!grpData) {printf("Failed to get GRP data for run",runNumber); return;}
  Int_t activeDetectors = grpData->GetDetectorMask();
  TString detStr = AliDAQ::ListOfTriggeredDetectors(activeDetectors);
  printf("Detectors in the data:\n%s\n",detStr.Data());
  TString LHCperiod = grpData->GetLHCPeriod();
  Bool_t isLHC10 =  LHCperiod.Contains("LHC10");
  Bool_t isLHC11 =  LHCperiod.Contains("LHC11");
  Bool_t isLHC12 =  LHCperiod.Contains("LHC12");
  Bool_t isLHC13 =  LHCperiod.Contains("LHC13");
  Bool_t isLHC13b =  LHCperiod.Contains("LHC13b");
  Bool_t isLHC13c =  LHCperiod.Contains("LHC13c");
  printf("LHCperiod:%s\n isLHC10:%d isLHC11:%d isLHC12:%d isLHC13:%d isLHC13b:%d isLHC13c:%d\n",LHCperiod.Data(),(Int_t)isLHC10,(Int_t)isLHC11,(Int_t)isLHC12,(Int_t)isLHC13,(Int_t)isLHC13b,(Int_t)isLHC13c);

  // Steering Tasks - set output storage
  // DefaultStorage set already before - in ConfigCalibTrain.C

  // Setting the mirror SEs for the default storage
  TString mirrorsStr("ALICE::CERN::OCDB,ALICE::FZK::SE,ALICE::LLNL::SE");
  AliCDBManager::Instance()->SetMirrorSEs(mirrorsStr.Data());
  printf("List of mirror SEs set to: \"%s\"\n",mirrorsStr.Data());

  // activate target OCDB storage
  AliCDBStorage* targetStorage = 0x0;
  if (targetOCDBstorage.Length()==0) {
    targetOCDBstorage+="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
    targetStorage = AliCDBManager::Instance()->GetStorage(targetOCDBstorage.Data());
  }
  else if (targetOCDBstorage.CompareTo("same",TString::kIgnoreCase) == 0 ){
    targetStorage = AliCDBManager::Instance()->GetDefaultStorage();
  }
  else {
    targetStorage = AliCDBManager::Instance()->GetStorage(targetOCDBstorage.Data());
  }
  printf("** targetOCDBstorage: \"%s\"\n",targetOCDBstorage.Data());

  // specific storage for TPC/Calib/Correction entry
  if (gSystem->AccessPathName("TPC", kFileExists)==0) {  
    AliCDBManager::Instance()->SetSpecificStorage("TPC/Calib/Correction","local://");
  }

  // Magnetic field
  AliMagF* fld = TGeoGlobalMagField::Instance()->GetField();
  Double_t bz = fld->SolenoidField();
  Bool_t isMagFieldON = kTRUE;
  if (TMath::Abs(bz)>0) {
    printf("Mag field is %f --> ON\n", bz);
  }
  else {
    isMagFieldON = kFALSE;
    printf("Mag field is %f --> OFF\n", bz);
  }

  // Quality flags
  Bool_t TPC_qf = kTRUE;
  Bool_t TOF_qf = kTRUE;
  Bool_t TRD_qf = kTRUE;
  Bool_t T0_qf  = kTRUE;
  Bool_t SDD_qf = kTRUE;
  Bool_t SPD_qf = kTRUE;
  Bool_t AD_qf  = kTRUE;

  /*
    // RS: commenting to sync with working version from alidaq
  if (detectorBitsQualityFlag != -1){
    TPC_qf = ((detectorBitsQualityFlag & AliDAQ::kTPC_QF) == AliDAQ::kTPC_QF)? kTRUE : kFALSE;
    TOF_qf = ((detectorBitsQualityFlag & AliDAQ::kTOF_QF) == AliDAQ::kTOF_QF)? kTRUE : kFALSE;
    TRD_qf = ((detectorBitsQualityFlag & AliDAQ::kTRD_QF) == AliDAQ::kTRD_QF)? kTRUE : kFALSE;
    T0_qf  = ((detectorBitsQualityFlag & AliDAQ::kT0_QF)  == AliDAQ::kT0_QF)?  kTRUE : kFALSE;
    SDD_qf = ((detectorBitsQualityFlag & AliDAQ::kSDD_QF) == AliDAQ::kSDD_QF)? kTRUE : kFALSE;
    SPD_qf = ((detectorBitsQualityFlag & AliDAQ::kSPD_QF) == AliDAQ::kSPD_QF)? kTRUE : kFALSE;
    AD_qf = ((detectorBitsQualityFlag & AliDAQ::kAD_QF) == AliDAQ::kAD_QF)? kTRUE : kFALSE;
  }    
  */

  Printf("Quality flags: detectorBitsQualityFlag = %d, TPC = %d, TOF = %d, TRD = %d, T0 = %d, SDD = %d, SPD = %d, AD = %d", detectorBitsQualityFlag, (Int_t)TPC_qf, (Int_t)TOF_qf, (Int_t)TRD_qf, (Int_t)T0_qf, (Int_t)SDD_qf, (Int_t)SPD_qf, (Int_t)AD_qf);

  // ===========================================================================
  // ===| TPC part |============================================================
  //
  AliTPCPreprocessorOffline *procesTPC = 0;
  if (detStr.Contains("TPC") && TPC_qf){
    Printf("\n******* Calibrating TPC *******");

    // ===| set up residual storage |===========================================
    TString targetStorageResidual="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";

    // --- check for overwrites
    const TString targetStorageResidualEnv(gSystem->Getenv("targetStorageResidual"));
    if (!targetStorageResidualEnv.IsNull())  targetStorageResidual=targetStorageResidualEnv;
    AliCDBStorage *residualStorage = AliCDBManager::Instance()->GetStorage(targetStorageResidual.Data());

    // ===| set up TPC calibration object |=====================================
    procesTPC = new AliTPCPreprocessorOffline;

    // ---| set up gain calibratin type |---------------------------------------
    //
    // default is Combined Calibration + Residual QA in CPass1
    // will be overwritte by mergeMakeOCDB.byComponent.perStage.sh
    // NOTE: This must be consistent to the settings in runCPass*.sh (runCalibTrain.C)
    //
    procesTPC->SetGainCalibrationType(AliTPCPreprocessorOffline::kResidualGainQA);

    // --- check for overwrites from environment variable
    //
    const TString sGainTypeFromEnv(gSystem->Getenv("TPC_CPass1_GainCalibType"));
    if (!sGainTypeFromEnv.IsNull()) {
      if (!procesTPC->SetGainCalibrationType(sGainTypeFromEnv)) {
        ::Fatal("makeOCDB","Could not set up gain calibration type from environment variable TPC_CPass1_GainCalibType: %s",sGainTypeFromEnv.Data());
      }

      ::Info("makeOCDB","Setting gain calibration type from environment variable TPC_CPass1_GainCalibType: %d", Int_t(procesTPC->GetGainCalibrationType()));
    }

    // ---| switch on parameter validation |------------------------------------
    procesTPC->SetTimeGainRange(0.5,5.0);
    procesTPC->SetMaxVDriftCorr(0.2); 
    procesTPC->SetMinTracksVdrift(10000);
    procesTPC->SwitchOnValidation();

    // ===| Run calibration |===================================================
    //
    // ---| Make time gain calibration |----------------------------------------
    if (isMagFieldON) procesTPC->CalibTimeGain("CalibObjects.root", runNumber, runNumber, targetStorage, residualStorage);

    // ---| Make vdrift calibration |-------------------------------------------
    procesTPC->CalibTimeVdrift("CalibObjects.root",runNumber, runNumber, residualStorage);
  }
  else {
    Printf("\n******* NOT Calibrating TPC: detStr = %s, TPC_qf = %d *******", detStr.Data(), (Int_t)TPC_qf);
  }

  // ===========================================================================
  // ===| TOF part |============================================================
  //
  AliTOFAnalysisTaskCalibPass0 *procesTOF=0;
  if (detStr.Contains("TOF") && detStr.Contains("TPC") && TOF_qf){
    procesTOF = new AliTOFAnalysisTaskCalibPass0;
    Printf("\n******* Calibrating TOF *******");
    if (isMagFieldON) procesTOF->ProcessOutput("CalibObjects.root", targetStorage);
    else {
      printf("Not calibrating TOF in case of mag field OFF\n");
    }
  }
  else {
    Printf("\n******* NOT Calibrating TOF: detStr = %s, TOF_qf = %d *******", detStr.Data(), (Int_t)TOF_qf);
  }

  // T0 part
  AliT0PreprocessorOffline *procesT0= 0;
  if (detStr.Contains("T0") && T0_qf) {
    Printf("\n******* Calibrating T0 *******");
    procesT0 = new AliT0PreprocessorOffline;
    // Make  calibration of channels offset
    procesT0->setDArun(100000);
    procesT0->Process("CalibObjects.root",runNumber, runNumber, targetStorage);
  }
  else {
    Printf("\n******* NOT Calibrating T0: detStr = %s, T0_qf = %d *******", detStr.Data(), (Int_t)T0_qf);
  }

  //TRD part
  AliTRDPreprocessorOffline *procesTRD = 0;
  if (detStr.Contains("TRD") && detStr.Contains("TPC") && TRD_qf){
    Printf("\n******* Calibrating TRD *******");
    procesTRD = new  AliTRDPreprocessorOffline;
    if(isLHC10 || isLHC13b || isLHC13c) procesTRD->SetSwitchOnChamberStatus(kFALSE);
    procesTRD->SetLinearFitForVdrift(kTRUE);
    procesTRD->SetMinStatsVdriftT0PH(600*10);
    procesTRD->SetMinStatsVdriftLinear(50);
    procesTRD->SetMinStatsGain(600);
    procesTRD->SetLimitValidateNoData(100);
    procesTRD->SetLimitValidateBadCalib(90);
    procesTRD->SetMinTimeOffsetValidate(-2.1);
    procesTRD->SetAlternativeDriftVelocityFit(kTRUE);
    if((!isLHC10) && (!isLHC11) && (!isLHC12) && (!isLHC13)) {
      printf("Run II\n");
      procesTRD->SetT0Shift1(0.2524132);// release the condition on the first bin and last bins
    }
    procesTRD->Init("CalibObjects.root");
    Int_t versionVdriftUsed = procesTRD->GetVersionVdriftUsed();
    Int_t subversionVdriftUsed = procesTRD->GetSubVersionVdriftUsed();
    Int_t versionGainUsed = procesTRD->GetVersionGainUsed();
    Int_t subversionGainUsed = procesTRD->GetSubVersionGainUsed();
    Int_t versionExBUsed = procesTRD->GetVersionExBUsed();
    Int_t subversionExBUsed = procesTRD->GetSubVersionExBUsed();
    printf("version and subversion vdrift %d and %d\n",versionVdriftUsed,subversionVdriftUsed);
    printf("version and subversion gain %d and %d\n",versionGainUsed,subversionGainUsed);
    printf("version and subversion exb %d and %d\n",versionExBUsed,subversionExBUsed);
    procesTRD->Process("CalibObjects.root",runNumber,runNumber,targetStorage);
  }
  else {
    Printf("\n******* NOT Calibrating TRD: detStr = %s, TRD_qf = %d *******", detStr.Data(), (Int_t)TRD_qf);
  }
  
  // switched OFF at CPass1 in any case
  /*
  //Mean Vertex
  AliMeanVertexPreprocessorOffline * procesMeanVtx=0;
  if (detStr.Contains("ITSSPD") && SPD_qf) {
    Printf("\n******* Calibrating MeanVertex *******");
    procesMeanVtx = new AliMeanVertexPreprocessorOffline;
    procesMeanVtx->ProcessOutput("CalibObjects.root", targetStorage, runNumber);
  }
  else {
    Printf("\n******* NOT Calibrating MeanVertex: detStr = %s, SPD_qf = %d *******", detStr.Data(), (Int_t)SPD_qf);
  }
  */

  AliAnalysisTaskADCalib *procesAD = NULL;
  if (detStr.Contains("AD") && AD_qf) {
    Printf("\n******* Calibrating AD *******");
    procesAD = new AliAnalysisTaskADCalib;
    procesAD->ProcessOutput("CalibObjects.root", targetStorage, runNumber);
  }
  else {
    Printf("\n******* NOT Calibrating AD: detStr = %s, AD_qf = %d*******", detStr.Data(), (Int_t)AD_qf);
  }

  //
  // Print calibration status into the stdout
  //
  Int_t trdStatus = (procesTRD) ?  procesTRD->GetStatus():0;
  Int_t tofStatus = (procesTOF) ?  procesTOF->GetStatus():0;
  Int_t t0Status  = (procesT0)  ?  procesT0->GetStatus():0;
  Int_t tpcStatus = (procesTPC) ?  procesTPC->GetStatus():0;
  Int_t adStatus  = (procesAD)  ?  procesAD->GetStatus():0;
  //
  printf("\n");
  printf("******* CPass1 calibration status *******\n");
  printf("TRD calibration status=%d\n",trdStatus);
  printf("TOF calibration status=%d\n",tofStatus);
  printf("TPC calibration status=%d\n",tpcStatus);
  printf("T0  calibration status=%d\n",t0Status);
  printf("AD  calibration status=%d\n",adStatus);
  
  TTreeSRedirector *pcstream = new TTreeSRedirector("cpassStat.root","recreate");
  printCalibStat(runNumber, "CalibObjects.root",pcstream);
  delete pcstream;
  return;
}
Esempio n. 7
0
void MakeLHCDataEntry(char* storageUri="local://$ALICE_ROOT/../AliRoot/OCDB", Int_t firstRun=0, Int_t lastRun=999999999)
{
  AliCDBManager *cdb = AliCDBManager::Instance();
  cdb->SetDefaultStorage(storageUri);

  // Get time start from the simulated LHCData file
  Double_t timeStart = 0.0;
  Double_t timeEnd = 1.0e+10;

  TString fileName(gSystem->ExpandPathName("$ALICE_ROOT/../AliRoot/GRP/ShuttleInput/testShuttle_GRP_run_number_testShuttle_data.txt"));
  Printf("Getting the file %s", fileName.Data());

  const Int_t fgknLHCDP = 9;   // number of dcs dps from LHC data
  const char* fgkLHCDataPoints[fgknLHCDP] = {
    "LHC_Beam_Energy",
    "LHC_MachineMode",
    "LHC_BeamMode",
    "LHC_Beams_Particle_Type",
    "BPTX_Phase_Shift_B1",
    "BPTX_Phase_Shift_B2",
    "LHC_Particle_Type_B1",
    "LHC_Particle_Type_B2",
    "LHC_Data_Quality_Flag"
  };

  AliGRPObject *grpobj = new AliGRPObject();
	// grpobj->SetBeamEnergyIsSqrtSHalfGeV(); // new format
  //
  //Getting the LHC Data from DCS FXS
  //
  AliLHCReader lhcReader;

  // Processing data to be put in AliGRPObject

		// Energy
		Printf("*************Energy ");
		TObjArray* energyArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[0]);
		if (energyArray){			
			Float_t energy = ProcessEnergy(energyArray,timeStart);
			if (energy != -1.) {
				grpobj->SetBeamEnergy(energy);
				grpobj->SetBeamEnergyIsSqrtSHalfGeV(kTRUE);
			}
			delete energyArray;
		}
		else {
			AliError("Energy not found in LHC Data file!!!");
		}	

  Double_t timeBeamModeEnd = timeEnd;        // max validity for Beam Mode 
  Double_t timeMachineModeEnd = timeEnd;     // max validity for Machine Mode
  Double_t timeBeamEnd = timeEnd;            // max validity for Beam Type
  Double_t timeBeamTypeEnd[2] = {timeEnd, timeEnd}; // max validity for Beam Type1,2
  Double_t timeBeamModeStart = -1;    // min validity for Beam Mode
  Double_t timeMachineModeStart = -1; // min validity for Machine Mode
  Double_t timeBeamStart = -1;        // min validity for Beam Type
  Double_t timeBeamTypeStart[2] = {-1,-1};        // min validity for Beam Type1,2
  Int_t indexBeamMode = -1;                  // index of measurement used to set Beam Mode
  Int_t indexMachineMode = -1;               // index of measurement used to set Machine Mode
  Int_t indexBeam = -1;                      // index of measurement used to set Beam Type
  Int_t indexBeamType[2] = {-1, -1};                      // index of measurement used to set Beam Type1,2
  Bool_t foundBeamModeStart = kFALSE;        // flag to be set in case an entry for the Beam Mode is found before (or at) SOR
  Bool_t foundMachineModeStart = kFALSE;     // flag to be set in case an entry for the Machine Mode is found before (or at) SOR
  Bool_t foundBeamStart = kFALSE;            // flag to be set in case an entry for the Beam Type is found before (or at) SOR
  Bool_t foundBeamTypeStart[2] = {kFALSE, kFALSE};            // flag to be set in case an entry for the Beam Type1,2 is found before (or at) SOR
  Bool_t flagBeamMode = kFALSE;  //flag set true if a changed occurred in BeamMode
  Bool_t flagMachineMode = kFALSE;  //flag set true if a changed occurred in MachineMode
  Bool_t flagBeam = kFALSE;  //flag set true if a changed occurred in BeamType
  Bool_t flagBeamType[2] = {kFALSE, kFALSE};  //flag set true if a changed occurred in BeamType1,2

  Double_t arrayTimes[5]={2.E9, 2.E9, 2.E9, 2.E9, 2.E9}; // array to keep track of the times of the possible changes of the LHC DPs; each entry set to Wed May 18 2033, 03:33:20 GMT (ALICE should not be running anymore...)
  // arrayTimes elements order correspond to the one used in the array of the strings fgkLHCDataPoints, i.e.:
  // arrayTimes[0] --> MachineMode
  // arrayTimes[1] --> BeamMode
  // arrayTimes[2] --> BeamType (when written together)
  // arrayTimes[3] --> BeamType1 (when written separate)
  // arrayTimes[4] --> BeamType2 (when written separate)

  // BeamMode
  Printf("*************BeamMode (LHCState) ");
  TObjArray* beamModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[2]);
  Int_t nBeamMode = -1;
  if (beamModeArray){	
    nBeamMode = beamModeArray->GetEntries();	
    if (nBeamMode==0){
      Printf("Found zero entries for the Beam Mode, leaving it empty");
    }
    else{
      for (Int_t iBeamMode = 0; iBeamMode<nBeamMode; iBeamMode++){
        AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(iBeamMode);
        if (beamMode){
          if (beamMode->GetTimeStamp()<=timeStart && beamMode->GetTimeStamp()>=timeBeamModeStart){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
            timeBeamModeStart = beamMode->GetTimeStamp();
            indexBeamMode = iBeamMode;
            foundBeamModeStart = kTRUE;
          }
          else {
            break;

          }
        }
      }
      if (!foundBeamModeStart){
        Printf("No value for the Beam Mode found before start of run, the Beam Mode will remain empty");
      }
      else {
        AliDCSArray* beamMode = (AliDCSArray*)beamModeArray->At(indexBeamMode);
        TObjString* beamModeString = beamMode->GetStringArray(0);
        Printf(Form("LHC State (corresponding to BeamMode) = %s (set at %f)",(beamModeString->String()).Data(),beamMode->GetTimeStamp()));
        grpobj->SetLHCState(beamModeString->String());
        if (indexBeamMode < nBeamMode-1){
          AliDCSArray* beamMode1 = (AliDCSArray*)beamModeArray->At(indexBeamMode+1);
          if (beamMode1){
            if (beamMode1->GetTimeStamp()<=timeStart){
              Printf("ERROR: you did not choose the correct value! there is still something before (or at) SOR, but later than this!");
            }
            else if (beamMode1->GetTimeStamp()>timeStart && beamMode1->GetTimeStamp()<=timeEnd){
              timeBeamModeEnd = beamMode1->GetTimeStamp();
              TObjString* beamModeString1 = beamMode1->GetStringArray(0);
              TString bmString0 = beamModeString->String();
              TString bmString1 = beamModeString1->String();
              if (bmString0.CompareTo(bmString1.Data(),TString::kIgnoreCase) == -1){
                Printf("WARNING: The beam mode changed from %s to %s during the run at timestamp %f! Setting it to %s and keeping track of the time of the change to set MaxTimeLHCValidity afterward",bmString0.Data(), bmString1.Data(), timeBeamModeEnd, bmString0.Data());
                flagBeamMode = kTRUE;
                arrayTimes[1]=timeBeamModeEnd;

              }
            }
          }
          else {
            Printf("Invalid pointer for the first entry for Beam Mode after the first valid one, not considering anything after what has already been found");
          }
        }
      }
    }
    delete beamModeArray;
  }
  else{
    Printf("ERROR: Beam mode array not found in LHC Data file!!!");
  }
		
  // MachineMode
  Printf("*************MachineMode ");
  TObjArray* machineModeArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[1]);
  Int_t nMachineMode = -1;
  if (machineModeArray){
    nMachineMode = machineModeArray->GetEntries();
    if (nMachineMode==0){
      Printf("No Machine Mode found, leaving it empty");
    }
    else{
      for (Int_t iMachineMode = 0; iMachineMode<nMachineMode; iMachineMode++){
        AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(iMachineMode);
        if (machineMode){
          if (machineMode->GetTimeStamp()<=timeStart && machineMode->GetTimeStamp()>=timeMachineModeStart){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
            timeMachineModeStart = machineMode->GetTimeStamp();
            indexMachineMode = iMachineMode;
            foundMachineModeStart = kTRUE;
          }
          else{
            break;
          }
        }
      }
      if (!foundMachineModeStart){
        Printf("No value for the Machine Mode found before start of run, the Machine Mode will remain empty");
      }
      else {
        AliDCSArray* machineMode = (AliDCSArray*)machineModeArray->At(indexMachineMode);
        TObjString* machineModeString = machineMode->GetStringArray(0);
        Printf(Form("MachineMode = %s (set at %f)",(machineModeString->String()).Data(),machineMode->GetTimeStamp()));
        grpobj->SetMachineMode(machineModeString->String());
        if (indexMachineMode < nMachineMode-1){
          AliDCSArray* machineMode1 = (AliDCSArray*)machineModeArray->At(indexMachineMode+1);
          if (machineMode1){
            if (machineMode1->GetTimeStamp()>timeStart && machineMode1->GetTimeStamp()<=timeEnd){
              timeMachineModeEnd = machineMode1->GetTimeStamp();
              TObjString* machineModeString1 = machineMode1->GetStringArray(0);
              TString mmString0 = machineModeString->String();
              TString mmString1 = machineModeString1->String();
              if (mmString0.CompareTo(mmString1.Data(),TString::kIgnoreCase) == -1){
                Printf("WARNING: The machine mode changed from %s to %s during the run at timestamp %f! Setting it to %s and keeping track of the time of the change to set MaxTimeLHCValidity afterward",mmString0.Data(),mmString1.Data(),timeMachineModeEnd,mmString0.Data());
                flagMachineMode = kTRUE;
                arrayTimes[0]=timeMachineModeEnd;
              }
            }
          }
          else {
            Printf("Invalid pointer for the first entry for Machine Mode after the first valid one, not considering anything after what has already been found");
          }
        }
      }
    }
    delete machineModeArray;
  }
  else{
    Printf("ERROR: Machine mode array not found in LHC Data file!!!");
  }

  // BeamType1 and BeamType2 - both put in the same string
  Printf("*************BeamType ");
  TObjArray* beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[3]);
  if (beamArray){			
    Int_t nBeam = beamArray->GetEntries();
    if (nBeam==0){
      Printf("No Beam Type found, leaving it empty");
    }
    else{
      for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
        AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
        if (beam){
          if (beam->GetTimeStamp()<=timeStart && beam->GetTimeStamp()>=timeBeamStart){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
            timeBeamStart = beam->GetTimeStamp();
            indexBeam = iBeam;
            foundBeamStart = kTRUE;
          }
          else{
            break;
          }
        }
      }
      if (!foundBeamStart){
        Printf("No value for the Beam Type found before start of run, the (common) Beam Type will remain empty");
      }
      else {
        AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
        TObjString* beamString = beam->GetStringArray(0);
        TString beamType = beamString->String();
        Printf(Form("Beam Type = %s",beamType.Data()));	
        if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
          Printf("Setting beam type to p-p");
          grpobj->SetBeamType("p-p");
        }
        else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
          Printf("Setting beam type to A-A");
          grpobj->SetBeamType("A-A");
        }
        /*
           else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
           Printf("Setting beam type to Pb-Pb");
           grpobj->SetBeamType("Pb-Pb");
           }
           else{
           Printf("ERROR: Beam Type not known, leaving it empty");
           }
           */
        if (indexBeam < nBeam-1){
          AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
          if (beam1){
            if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
              timeBeamEnd = beam1->GetTimeStamp();
              TObjString* beamString1 = beam1->GetStringArray(0);
              TString beamType1 = beamString1->String();
              if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
                Printf("WARNING: The Beam Type changed from %s to %s during the run at timestamp %f! Setting it to %s and keeping track of the time of the change to set MaxTimeLHCValidity afterward",beamType.Data(),(beamString1->String()).Data(),timeBeamEnd,beamType.Data());
                flagBeam = kTRUE;
                arrayTimes[2] = timeBeamEnd;
              }
            }
          }
          else {
            Printf("Invalid pointer for the first entry for Beam Type after the first valid one, not considering anything after what has already been found");
          }
        }
      }
    }
    delete beamArray;
  }
  else{
    Printf("ERROR: Beam Type array not found in LHC Data file!!!");
  }		

  // BeamType1 and BeamType2 - in separete string
  Printf("*************BeamType, 1 and 2 ");
  Int_t indexBeamTypeString = 6;  // index of the string with the alias of BeanType1 in the array fgkLHCDataPoints
  TString combinedBeamType = "-";  // combined beam type, built from beam type 1 and beam type 2
  TString combinedBeamTypeFromLHC = "-";  // combined beam type, built from beam type 1 and beam type 2 AS SENT FROM LHC
  for (Int_t ibeamType = 0; ibeamType<2; ibeamType++){
    beamArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[indexBeamTypeString+ibeamType]);
    if (beamArray){			
      Int_t nBeam = beamArray->GetEntries();
      if (nBeam==0){
        Printf(Form("No Beam Type %s found, leaving it empty",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
      }
      else{
        for (Int_t iBeam = 0; iBeam<nBeam; iBeam++){
          AliDCSArray* beam = (AliDCSArray*)beamArray->At(iBeam);
          if (beam){
            if (beam->GetTimeStamp()<=timeStart && beam->GetTimeStamp()>=timeBeamTypeStart[ibeamType]){// taking always the very last entry: of two measurements have the same timestamp, the last one is taken
              timeBeamTypeStart[ibeamType] = beam->GetTimeStamp();
              indexBeamType[ibeamType] = iBeam;
              foundBeamTypeStart[ibeamType] = kTRUE;
            }
            else{
              break;
            }
          }
        }
        if (!foundBeamTypeStart[ibeamType]){
          Printf(Form("No value for the Beam Type %s found before start of run, the Beam Type %d will remain empty", fgkLHCDataPoints[indexBeamTypeString+ibeamType], ibeamType));
        }
        else {
          AliDCSArray* beam = (AliDCSArray*)beamArray->At(indexBeam);
          TObjString* beamString = beam->GetStringArray(0);
          TString beamType = beamString->String();
          Printf(Form("Beam Type (for %s) = %s", fgkLHCDataPoints[indexBeamTypeString+ibeamType], beamType.Data()));
          TString singleBeam = ParseBeamTypeString(beamType,ibeamType);
          Printf(Form("Single Beam Type for beam %d set to %s", ibeamType, singleBeam.Data()));
          grpobj->SetSingleBeamType(ibeamType, singleBeam);
          if (beamType.CompareTo("PROTON",TString::kIgnoreCase) == 0){
            Printf(Form("Setting beam %d for combined beam type to p", ibeamType));
            if (ibeamType == 0) combinedBeamType.Prepend("p"); 
            else combinedBeamType.Append("p");
          }
          else { // if there is no PROTON beam, we suppose it is Pb, and we put A-A
            Printf(Form("Setting beam %d for combined beam type to A",ibeamType));
            if (ibeamType == 0) combinedBeamType.Prepend("A");
            else combinedBeamType.Append("A");
          }
          if (ibeamType == 0) combinedBeamTypeFromLHC.Prepend(beamType); 
          else combinedBeamTypeFromLHC.Append(beamType);
          /*
             else if (beamType.CompareTo("LEAD82",TString::kIgnoreCase) == 0){
             Printf("Setting beam type to Pb-Pb");
             grpobj->SetSingleBeamType(ibeamType, "Pb-Pb");
             }
             else{
             Printf("ERROR: Beam Type not known, leaving it empty");
             }
             */
          if (indexBeamType[ibeamType] < nBeam-1){
            AliDCSArray* beam1 = (AliDCSArray*)beamArray->At(indexBeam+1);
            if (beam1){
              if (beam1->GetTimeStamp()>timeStart && beam1->GetTimeStamp()<=timeEnd){
                timeBeamTypeEnd[ibeamType] = beam1->GetTimeStamp();
                TObjString* beamString1 = beam1->GetStringArray(0);
                TString beamType1 = beamString1->String();
                if (beamType.CompareTo(beamType1.Data(),TString::kIgnoreCase) == -1){
                  Printf("WARNING: The Beam Type for %s changed from %s to %s during the run at timestamp %f! Setting it to %s and keeping track of the time of the change to set MaxTimeLHCValidity afterward",fgkLHCDataPoints[indexBeamTypeString+ibeamType],beamType.Data(),(beamString1->String()).Data(),timeBeamEnd,beamType.Data());
                  flagBeamType[ibeamType] = kTRUE;
                  arrayTimes[3+ibeamType] = timeBeamTypeEnd[ibeamType];
                }
              }
            }
            else {
              Printf(Form("Invalid pointer for the first entry for Beam Type %s after the first valid one, not considering anything after what has already been found",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
            }
          }
        }
      }
      delete beamArray;
    }
    else{
      AliError(Form("Beam Type %s array not found in LHC Data file!!!",fgkLHCDataPoints[indexBeamTypeString+ibeamType]));
    }		
  }
  Printf(Form("Setting combined beam type to %s",combinedBeamType.Data()));
  grpobj->SetBeamType(combinedBeamType);
  Printf(Form("Setting combined beam type form LHC to %s",combinedBeamTypeFromLHC.Data()));
  grpobj->SetBeamTypeFromLHC(combinedBeamTypeFromLHC);

  // Setting minTimeLHCValidity
  if (flagBeamMode == kTRUE || flagMachineMode == kTRUE || flagBeam == kTRUE || flagBeamType[0] == kTRUE || flagBeamType[1] == kTRUE){ 
    Double_t minTimeLHCValidity= TMath::MinElement(5,arrayTimes);
    Printf("WARNING: Setting MaxTimeLHCValidity to %f",minTimeLHCValidity);
    grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
  }
  /* 
  // Old way to determine the Maximum Time during which the LHC info is valid
  if (timeBeamModeEnd!=0 || timeMachineModeEnd!=0 || timeBeamEnd !=0){
  Double_t minTimeLHCValidity;
  if (flagBeamMode == kFALSE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam only true --> it is the only one that changed
  minTimeLHCValidity = timeBeamEnd;
  }
  else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode only true
  minTimeLHCValidity = timeMachineModeEnd;
  }
  else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kFALSE){ // flagBeamMode only true
  minTimeLHCValidity = timeBeamModeEnd;
  }
  else if (flagBeamMode == kFALSE && flagMachineMode == kTRUE && flagBeam == kTRUE){ // flagBeam and flagMachineMode only true
  minTimeLHCValidity= TMath::Min(timeBeamEnd,timeMachineModeEnd);
  }
  else if (flagBeamMode == kTRUE && flagMachineMode == kFALSE && flagBeam == kTRUE){ // flagBeam and flagBeamMode only true
  minTimeLHCValidity= TMath::Min(timeBeamEnd,timeBeamModeEnd);
  }
  else if (flagBeamMode == kTRUE && flagMachineMode == kTRUE && flagBeam == kFALSE){ // flagMachineMode and flagBeamMode only true
  minTimeLHCValidity= TMath::Min(timeMachineModeEnd,timeBeamModeEnd);
  }
  else {
  Double_t arrayTimes[3] = {timeBeamModeEnd,timeMachineModeEnd,timeBeamEnd};// flagMachineMode and flagBeamMode and flagBeam 
  minTimeLHCValidity= TMath::MinElement(3,arrayTimes);
  }
  Printf("WARNING: Setting MaxTimeLHCValidity to %f",minTimeLHCValidity));
  grpobj->SetMaxTimeLHCValidity(minTimeLHCValidity);
  }
  */

  // Data Quality Flag --> storing start and end values of periods within the run during which the value was found to be FALSE
  Printf("*************Data Quality Flag ");
  TObjArray* dataQualityArray = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[8]);
  Int_t nDataQuality = -1;
  Double_t timeDataQualityStart = -1; // min validity for Data Quality Flag
  Int_t indexDataQuality = -1;               // index of first measurement used to set Data Quality Flag
  Bool_t foundDataQualityStart = kFALSE;     // flag to be set in case an entry for the Data Quality Flag is found before (or at) SOR

  if (dataQualityArray){
    nDataQuality = dataQualityArray->GetEntries();
    if (nDataQuality==0){
      Printf("No Data Quality Flag found, leaving it empty");
    }
    else{
      for (Int_t iDataQuality = 0; iDataQuality<nDataQuality; iDataQuality++){
        AliDCSArray* dataQuality = (AliDCSArray*)dataQualityArray->At(iDataQuality);
        if (dataQuality){
          if (dataQuality->GetTimeStamp()<=timeStart && dataQuality->GetTimeStamp()>=timeDataQualityStart){// taking always the very last entry: if two measurements have the same timestamp, the last one is taken
            timeDataQualityStart = dataQuality->GetTimeStamp();
            indexDataQuality = iDataQuality;
            foundDataQualityStart = kTRUE;
          }
          else{
            // we suppose here that if the first measurement is not before SOR, then none will be (they MUST be in chronological order!!!) 
            break;
          }
        }
      }
      if (!foundDataQualityStart){
        // The Data Quality Flag should be found and TRUE at the start of the run. For the time being, if it is not found, don't do anything, but it means there is a problem..
        Printf("No value for the Data Quality Flag found before start of run, the Data Quality Flag will remain empty");
      }
      else {
        // counting how many FALSE values there are
        Bool_t foundEndOfFalse = kFALSE;
        Int_t nFalse = 0;
        for (Int_t iDataQuality = indexDataQuality; iDataQuality < nDataQuality; iDataQuality ++){
          AliDCSArray* dataQuality = (AliDCSArray*)dataQualityArray->At(iDataQuality);
          Printf("dataQuality->GetTimeStamp() = %f, timeDataQualityStart = %f, timeEnd = %f", dataQuality->GetTimeStamp(), timeDataQualityStart, timeEnd );
          if (dataQuality->GetTimeStamp()>=timeDataQualityStart && dataQuality->GetTimeStamp()<=timeEnd){ // considering only values between the first valid and the end of the run
            Bool_t dataQualityFlag = dataQuality->GetBool(0);
            Printf("DataQuality = %d (set at %f)",(Int_t)dataQualityFlag,dataQuality->GetTimeStamp());
            if (dataQualityFlag != kTRUE){
              if (iDataQuality == indexDataQuality) {  // the first Data Quality value should be TRUE, but ignoring the problem now...
                Printf("ERROR: The first value for the Data Quality MUST be TRUE! Ignoring for now...");
              }
              nFalse++;
            }
          }
        }

        Printf(Form("Found %d FALSE values for the Data Quality Flag",nFalse));
        Double_t falses[nFalse*2];  // dimensioning this to the maximum possible, as if each false value was followed by a true one --> the false periods correspond to the number of falses

        Int_t iDataQuality = indexDataQuality;
        if (nFalse > 0){
          Int_t iFalse = 0;
          // filling the info about the periods when the flag was set to FALSE
          // starting, like for the other DPS, from the measurement closest to SOR (the index of which is iDataQuality)
          while (iDataQuality < nDataQuality){
            Printf("iDataQuality = %d",iDataQuality);
            AliDCSArray* dataQuality = (AliDCSArray*)dataQualityArray->At(iDataQuality);
            if (dataQuality->GetTimeStamp()>=timeDataQualityStart && dataQuality->GetTimeStamp()<=timeEnd){ // considering only values between the first valid and the end of the run
              Bool_t dataQualityFlag = dataQuality->GetBool(0);
              Printf("DataQuality = %d (set at %f)",(Int_t)dataQualityFlag,dataQuality->GetTimeStamp());
              if (dataQualityFlag == kTRUE){
                // found TRUE value, continuing
                iDataQuality++;
                continue;
              }
              else{
                /*
                // the check was already done before
                if (iDataQuality == indexDataQuality) {  // the first Data Quality value should be TRUE, but ignoring the problem now...
                Printf("ERROR: The first value for the Data Quality MUST be TRUE! Ignoring for now...");
                }
                */
                falses[iFalse*2] = dataQuality->GetTimeStamp();
                foundEndOfFalse = kFALSE;
                Int_t iDataQualityNext = iDataQuality+1;
                while (iDataQualityNext < nDataQuality){
                  AliDCSArray* dataQualityNext = (AliDCSArray*)dataQualityArray->At(iDataQualityNext);
                  if (dataQualityNext->GetTimeStamp()>timeDataQualityStart && dataQualityNext->GetTimeStamp()<=timeEnd && dataQualityNext->GetTimeStamp() > dataQuality->GetTimeStamp()){ // considering only values between the first valid and the end of the run, and subsequent to the current value
                    Bool_t dataQualityFlagNext = dataQualityNext->GetBool(0);
                    Printf("DataQualityNext = %d (set at %f)",(Int_t)dataQualityFlagNext,dataQualityNext->GetTimeStamp());
                    if (dataQualityFlagNext == kTRUE){
                      // found TRUE value, first FALSE period completed
                      foundEndOfFalse = kTRUE;
                      falses[iFalse*2+1] = dataQualityNext->GetTimeStamp();
                      iFalse++;
                      break;
                    }
                    iDataQualityNext++;
                  }
                }
                if (!foundEndOfFalse) {
                  Printf("Please, note that the last FALSE value lasted until the end of the run");
                  falses[iFalse*2+1] = timeEnd;
                  iFalse++;
                  break;
                }
                iDataQuality = iDataQualityNext+1;
              }
            }
          }
          grpobj->SetNFalseDataQualityFlag(iFalse);
          grpobj->SetFalseDataQualityFlagPeriods(falses);
        }
      }
    }
    delete dataQualityArray;
  }
  else{
    Printf("ERROR: Data Quality Flag array not found in LHC Data file!!!");
  }

  // Processing data to go to AliLHCData object
  AliLHCData* dt = new AliLHCData(fileName.Data(),timeStart,timeEnd);
  // storing AliLHCData in OCDB
  if (dt){
    Printf(Form("Filled %d records to AliLHCData object",dt->GetData().GetEntriesFast()));
    AliCDBMetaData md;
    md.SetResponsible("Ruben Shahoyan");
    md.SetComment("LHC data from the GRP preprocessor.");
    Bool_t result = kTRUE;
    AliCDBId id("GRP/GRP/LHCData", 0, AliCDBRunRange::Infinity());
    result = cdb->Put(dt, id, &md); 
    delete dt;
    if (!result){
      Printf("Problems in storing LHC Data - but not going into Error");
    }
  }

  // processing LHC Phase

  TObjArray *beam1phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[4]);
  TObjArray *beam2phase = lhcReader.ReadSingleLHCDP(fileName.Data(),fgkLHCDataPoints[5]);
  if (beam1phase == 0x0 || beam2phase == 0x0){
    Printf(Form("Problems in retrieving LHC Clock data from LHC file"));
    return 4;
  }			
  AliLHCClockPhase *phaseObj = ProcessLHCClockPhase(beam1phase,beam2phase,timeEnd);
  delete beam1phase;
  delete beam2phase;
  if (phaseObj){
    Printf(Form("LHC Phase found"));
    AliCDBMetaData mdPhase;
    mdPhase.SetResponsible("Cvetan Cheshkov");
    mdPhase.SetComment("LHC Clock Phase");
    Bool_t result = kTRUE;
    AliCDBId id("GRP/Calib/LHCClockPhase", 0, AliCDBRunRange::Infinity());
    result = cdb->Put(phaseObj, id, &mdPhase); 
    delete phaseObj;
    if (!result) return 3;
  }
  else return 4;

  return 0;
}