]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/STEER/AliReconstruction.cxx
Removed unused variables. Initial value for centrality fixed.
[u/mrichter/AliRoot.git] / STEER / STEER / AliReconstruction.cxx
index be0719957b96bdf6131cfffbb6a270006d27b0a4..6eaaa94ddc3fe4667463860cd2f825730ee54eef 100644 (file)
 #include <TMessage.h>
 #include <TUrl.h>
 #include <TRandom.h>
+#include <THashList.h>
 
 #include "AliAlignObj.h"
 #include "AliAnalysisManager.h"
 #include <sys/resource.h>
 ClassImp(AliReconstruction)
 
+using std::endl;
+
 //_____________________________________________________________________________
 const char* AliReconstruction::fgkStopEvFName = "_stopEvent_";
 const char* AliReconstruction::fgkDetectorName[AliReconstruction::kNDetectors] = {"ITS", "TPC", "TRD", "TOF", "PHOS", "HMPID", "EMCAL", "MUON", "FMD", "ZDC", "PMD", "T0", "VZERO", "ACORDE"
@@ -221,12 +224,12 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   TSelector(),
   fRunVertexFinder(kTRUE),
   fRunVertexFinderTracks(kTRUE),
-  fRunHLTTracking(kFALSE),
   fRunMuonTracking(kFALSE),
   fRunV0Finder(kTRUE),
   fRunCascadeFinder(kTRUE),
   fRunMultFinder(kTRUE),
   fStopOnError(kTRUE),
+  fStopOnMissingTriggerFile(kTRUE),
   fWriteAlignmentData(kFALSE),
   fWriteESDfriend(kFALSE),
   fFillTriggerESD(kTRUE),
@@ -286,8 +289,7 @@ AliReconstruction::AliReconstruction(const char* gAliceFilename) :
   fQARefUri(),
   fSpecCDBUri(), 
   fInitCDBCalled(kFALSE),
-  fFromCDBSnapshot(kFALSE),
-  fSnapshotFileName(""),
+  fCDBSnapshotMode(kFALSE),
   fSetRunNumberFromDataCalled(kFALSE),
   fQADetectors("ALL"), 
   fQATasks("ALL"), 
@@ -347,12 +349,12 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   TSelector(),
   fRunVertexFinder(rec.fRunVertexFinder),
   fRunVertexFinderTracks(rec.fRunVertexFinderTracks),
-  fRunHLTTracking(rec.fRunHLTTracking),
   fRunMuonTracking(rec.fRunMuonTracking),
   fRunV0Finder(rec.fRunV0Finder),
   fRunCascadeFinder(rec.fRunCascadeFinder),
   fRunMultFinder(rec.fRunMultFinder),
   fStopOnError(rec.fStopOnError),
+  fStopOnMissingTriggerFile(rec.fStopOnMissingTriggerFile),
   fWriteAlignmentData(rec.fWriteAlignmentData),
   fWriteESDfriend(rec.fWriteESDfriend),
   fFillTriggerESD(rec.fFillTriggerESD),
@@ -412,8 +414,7 @@ AliReconstruction::AliReconstruction(const AliReconstruction& rec) :
   fQARefUri(rec.fQARefUri),
   fSpecCDBUri(), 
   fInitCDBCalled(rec.fInitCDBCalled),
-  fFromCDBSnapshot(rec.fFromCDBSnapshot),
-  fSnapshotFileName(rec.fSnapshotFileName),
+  fCDBSnapshotMode(rec.fCDBSnapshotMode),
   fSetRunNumberFromDataCalled(rec.fSetRunNumberFromDataCalled),
   fQADetectors(rec.fQADetectors), 
   fQATasks(rec.fQATasks), 
@@ -489,12 +490,12 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
 
   fRunVertexFinder       = rec.fRunVertexFinder;
   fRunVertexFinderTracks = rec.fRunVertexFinderTracks;
-  fRunHLTTracking        = rec.fRunHLTTracking;
   fRunMuonTracking       = rec.fRunMuonTracking;
   fRunV0Finder           = rec.fRunV0Finder;
   fRunCascadeFinder      = rec.fRunCascadeFinder;
   fRunMultFinder         = rec.fRunMultFinder;
   fStopOnError           = rec.fStopOnError;
+  fStopOnMissingTriggerFile = rec.fStopOnMissingTriggerFile;
   fWriteAlignmentData    = rec.fWriteAlignmentData;
   fWriteESDfriend        = rec.fWriteESDfriend;
   fFillTriggerESD        = rec.fFillTriggerESD;
@@ -586,8 +587,7 @@ AliReconstruction& AliReconstruction::operator = (const AliReconstruction& rec)
   fQARefUri      = rec.fQARefUri;
   fSpecCDBUri.Delete();
   fInitCDBCalled               = rec.fInitCDBCalled;
-  fFromCDBSnapshot             = rec.fFromCDBSnapshot;
-  fSnapshotFileName            = rec.fSnapshotFileName;
+  fCDBSnapshotMode             = rec.fCDBSnapshotMode;
   fSetRunNumberFromDataCalled  = rec.fSetRunNumberFromDataCalled;
   fQADetectors                 = rec.fQADetectors;
   fQATasks                     = rec.fQATasks; 
@@ -661,6 +661,8 @@ void AliReconstruction::InitQA()
 
 
   AliQAManager * qam = AliQAManager::QAManager(AliQAv1::kRECMODE) ; 
+  qam->SetSaveData(kTRUE); 
+  qam->SetCycleLength(AliQAv1::kITS, 5) ; 
   if (fWriteQAExpertData)
     qam->SetWriteExpert() ; 
  
@@ -687,7 +689,9 @@ void AliReconstruction::InitQA()
   }
   
   if (fRunQA) {
-  qam->SetActiveDetectors(fQADetectors) ; 
+  qam->SetActiveDetectors(fQADetectors) ;
+  qam->SetActiveOnlineDetectors(fRunInfo->GetActiveDetectors());
+    
   for (Int_t det = 0 ; det < AliQAv1::kNDET ; det++) {
     qam->SetCycleLength(AliQAv1::DETECTORINDEX_t(det), fQACycles[det]) ;  
     qam->SetWriteExpert(AliQAv1::DETECTORINDEX_t(det)) ;
@@ -779,6 +783,12 @@ void AliReconstruction::InitCDB()
   AliSysInfo::AddStamp("InitCDB");
 }
 
+//_____________________________________________________________________________
+void AliReconstruction::SetCDBSnapshotMode(const char* snapshotFileName) {
+    fCDBSnapshotMode = kTRUE;
+    AliCDBManager::Instance()->SetSnapshotMode(snapshotFileName);
+}
+
 //_____________________________________________________________________________
 void AliReconstruction::SetDefaultStorage(const char* uri) {
 // Store the desired default CDB storage location
@@ -858,6 +868,7 @@ Bool_t AliReconstruction::SetRunNumberFromData()
        AliWarning("Run number is taken from raw-event header! Ignoring settings in AliCDBManager!");
       } 
       man->SetRun(fRawReader->GetRunNumber());
+      GetEventInfo();
       fRawReader->RewindEvents();
     }
     else {
@@ -1114,6 +1125,7 @@ Bool_t AliReconstruction::InitGRP() {
     fRunTracking = MatchDetectorList(fRunTracking,detMask);
     fFillESD = MatchDetectorList(fFillESD,detMask);
     fQADetectors = MatchDetectorList(fQADetectors,detMask);
+    AliInfo(Form("fQADetectors=%s",fQADetectors.Data()));
     fDeleteRecPoints = MatchDetectorList(fDeleteRecPoints,detMask);
     fDeleteDigits    = MatchDetectorList(fDeleteDigits,detMask);
     fLoadCDB.Form("%s %s %s %s",
@@ -1265,6 +1277,7 @@ Bool_t AliReconstruction::LoadCDB()
   // in the trigger or that are needed in order to put correct
   // information in ESD
   AliCDBManager::Instance()->GetAll("TRIGGER/*/*");
+  AliCDBManager::Instance()->GetAll("HLT/*/*");
 
   return kTRUE;
 }
@@ -1427,6 +1440,7 @@ Bool_t AliReconstruction::Run(const char* input)
       }
       iEvent++;
     }
+    if (!iEvent) AliWarning("No events passed trigger selection");
     SlaveTerminate();
     if (GetAbort() != TSelector::kContinue) return kFALSE;
     Terminate();
@@ -1533,29 +1547,27 @@ void AliReconstruction::Begin(TTree *)
     AliSysInfo::AddStamp("CheckGeom");
   }
 
-  Bool_t loadedFromSnapshot=kFALSE;
   Bool_t toCDBSnapshot=kFALSE;
   TString snapshotFileOut(""); // we could use fSnapshotFileName if we are not interested
   // in reading from and writing to a snapshot file at the same time
-  if(TString(gSystem->Getenv("OCDB_SNAPSHOT_CREATE")) == TString("kTRUE")){
+  if(TString(getenv("OCDB_SNAPSHOT_CREATE")) == TString("kTRUE")){
       toCDBSnapshot=kTRUE;
       //fFromCDBSnapshot=kFALSE;
-      TString snapshotFile(gSystem->Getenv("OCDB_SNAPSHOT_FILENAME"));
+      TString snapshotFile(getenv("OCDB_SNAPSHOT_FILENAME"));
       if(!(snapshotFile.IsNull() || snapshotFile.IsWhitespace()))
          snapshotFileOut = snapshotFile;
       else
          snapshotFileOut="OCDB.root";
   }
-  if(fFromCDBSnapshot){
-      AliDebug(2,"Initializing from a CDB snapshot");
-      loadedFromSnapshot = AliCDBManager::Instance()->InitFromSnapshot(fSnapshotFileName.Data());
-  }
 
   if (!MisalignGeometry(fLoadAlignData)) {
     Abort("MisalignGeometry", TSelector::kAbortProcess);
     return;
   }
-  AliCDBManager::Instance()->UnloadFromCache("GRP/Geometry/Data");
+
+  const TMap* cdbCache = AliCDBManager::Instance()->GetEntryCache();
+  if(cdbCache->Contains("GRP/Geometry/Data"))
+         AliCDBManager::Instance()->UnloadFromCache("GRP/Geometry/Data");
   if(!toCDBSnapshot) AliCDBManager::Instance()->UnloadFromCache("*/Align/*");
   AliSysInfo::AddStamp("MisalignGeom");
 
@@ -1564,14 +1576,16 @@ void AliReconstruction::Begin(TTree *)
     return;
   }
   AliSysInfo::AddStamp("InitGRP");
-  if(!toCDBSnapshot) AliCDBManager::Instance()->UnloadFromCache("GRP/Calib/CosmicTriggers");
+  if(!toCDBSnapshot)
+      if(cdbCache->Contains("GRP/Calib/CosmicTriggers"))
+         AliCDBManager::Instance()->UnloadFromCache("GRP/Calib/CosmicTriggers");
 
-  if(!loadedFromSnapshot){
+  if(!fCDBSnapshotMode || toCDBSnapshot){
       if (!LoadCDB()) {
          Abort("LoadCDB", TSelector::kAbortProcess);
          return;
       }
-      AliSysInfo::AddStamp("LoadCDB");
+      AliSysInfo::AddStamp("LoadCDB"); 
   }
 
   if (!LoadTriggerScalersCDB()) {
@@ -1599,9 +1613,12 @@ void AliReconstruction::Begin(TTree *)
   AliSysInfo::AddStamp("InitRecoParams");
 
   if(toCDBSnapshot)
-      AliCDBManager::Instance()->DumpToSnapshotFile(snapshotFileOut.Data());
-  AliCDBManager::Instance()->UnloadFromCache("*/Align/*");
-  AliCDBManager::Instance()->UnloadFromCache("GRP/Calib/CosmicTriggers");
+  {
+      AliCDBManager::Instance()->DumpToSnapshotFile(snapshotFileOut.Data(),kFALSE);
+      AliCDBManager::Instance()->UnloadFromCache("*/Align/*");
+      if(cdbCache->Contains("GRP/Calib/CosmicTriggers"))
+         AliCDBManager::Instance()->UnloadFromCache("GRP/Calib/CosmicTriggers");
+  }
 
   if (fInput && gProof) {
     if (reco) *reco = *this;
@@ -1766,22 +1783,21 @@ void AliReconstruction::SlaveBegin(TTree*)
   // order to create all branches. Initialization is done from an
   // ESD layout template in CDB
   AliCDBManager* man = AliCDBManager::Instance();
-  AliCDBPath hltESDConfigPath("HLT/ConfigHLT/esdLayout");
-  AliCDBEntry* hltESDConfig=NULL;
-  if (man->GetId(hltESDConfigPath)!=NULL &&
-      (hltESDConfig=man->Get(hltESDConfigPath))!=NULL) {
-    AliESDEvent* pESDLayout=dynamic_cast<AliESDEvent*>(hltESDConfig->GetObject());
-    if (pESDLayout) {
+  AliCDBEntry* hltESDConfig = man->Get("HLT/Calib/esdLayout");
+  if(!hltESDConfig){
+      AliError(Form("Error getting \"HLT/Calib/esdLayout\""));
+      return;
+  }
+  AliESDEvent* pESDLayout=dynamic_cast<AliESDEvent*>(hltESDConfig->GetObject());
+  if (pESDLayout) {
       // init all internal variables from the list of objects
       pESDLayout->GetStdContent();
 
       // copy content and create non-std objects
       *fhltesd=*pESDLayout;
       fhltesd->Reset();
-    } else {
-      AliError(Form("error setting hltEsd layout from %s: invalid object type",
-                   hltESDConfigPath.GetPath().Data()));
-    }
+  } else {
+      AliError(Form("error setting hltEsd layout from \"HLT/Calib/esdLayout\": invalid object type"));
   }
 
   fhltesd->WriteToTree(fhlttree);
@@ -1813,7 +1829,7 @@ void AliReconstruction::SlaveBegin(TTree*)
     }
     // Set the event and other data pointers
     fRecoHandler = new AliRecoInputHandler();
-    fRecoHandler->Init(ftree, "LOCAL");
+//    fRecoHandler->Init(ftree, "LOCAL");
     fRecoHandler->SetEvent(fesd);
     fRecoHandler->SetESDfriend(fesdf);
     fRecoHandler->SetHLTEvent(fhltesd);
@@ -1822,6 +1838,7 @@ void AliReconstruction::SlaveBegin(TTree*)
     // Enter external loop mode
     fAnalysis->SetExternalLoop(kTRUE);
     // Initialize analysis
+    fAnalysis->SlaveBegin(ftree);
     fAnalysis->StartAnalysis("local", (TTree*)0);
     // Connect ESD tree with the input container
     fAnalysis->GetCommonInputContainer()->SetData(ftree);
@@ -1950,26 +1967,7 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
     AliQAManager::QAManager()->RunOneEvent(fRawReader) ;  
     AliSysInfo::AddStamp(Form("RawQA_%d",iEvent), 0,0,iEvent);
   }
-    // local single event reconstruction
-    if (!fRunLocalReconstruction.IsNull()) {
-      TString detectors=fRunLocalReconstruction;
-      // run HLT event reconstruction first
-      // ;-( IsSelected changes the string
-      if (IsSelected("HLT", detectors) &&
-         !RunLocalEventReconstruction("HLT")) {
-       if (fStopOnError) {CleanUp(); return kFALSE;}
-      }
-      detectors=fRunLocalReconstruction;
-      detectors.ReplaceAll("HLT", "");
-      if (!RunLocalEventReconstruction(detectors)) {
-        if (fStopOnError) {
-          CleanUp(); 
-          return kFALSE;
-        }
-      }
-    }
 
-  
     // fill Event header information from the RawEventHeader
     if (fRawReader){FillRawEventHeaderESD(fesd);}
     if (fRawReader){FillRawEventHeaderESD(fhltesd);}
@@ -2024,6 +2022,43 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
       fhltesd->SetUniformBMap(fld->IsUniform());
       fhltesd->SetBInfoStored();
     }
+
+    //
+    // run full HLT reconstruction first
+    //
+    {
+      TString detectors=fRunLocalReconstruction;
+      if (IsSelected("HLT", detectors) &&
+         !RunLocalEventReconstruction("HLT")) {
+       if (fStopOnError) {CleanUp(); return kFALSE;}
+      }
+      detectors=fFillESD;
+      // run HLT on hltesd
+      if (IsSelected("HLT", detectors) &&
+         !FillESD(fhltesd, "HLT")) {
+       if (fStopOnError) {CleanUp(); return kFALSE;}
+      }
+    }
+
+    // local single event reconstruction
+    if (!fRunLocalReconstruction.IsNull()) {
+      TString detectors=fRunLocalReconstruction;
+      // the logic for selection and correct sequence of reconstruction relies on the
+      // full list of detectors. Keyword 'ALL' should have been replaced at this point.
+      if (detectors.Contains("ALL")) {
+       AliFatal("Keyword 'ALL' needs to be replaced by the full list of detectors in "
+                "fRunLocalReconstruction. This should have been done by the framework");
+      }
+      detectors.ReplaceAll("HLT", "");
+      if (!RunLocalEventReconstruction(detectors)) {
+        if (fStopOnError) {
+          CleanUp(); 
+          return kFALSE;
+        }
+      }
+    }
+
+  
     //
     // Set most probable pt, for B=0 tracking
     // Get the global reco-params. They are atposition 16 inside the array of detectors in fRecoParam
@@ -2071,27 +2106,18 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
     // fill ESD
     if (!fFillESD.IsNull()) {
       TString detectors=fFillESD;
-      // run HLT first and on hltesd
-      // ;-( IsSelected changes the string
-      if (IsSelected("HLT", detectors) &&
-         !FillESD(fhltesd, "HLT")) {
-       if (fStopOnError) {CleanUp(); return kFALSE;}
-      }
-      detectors=fFillESD;
-      // Temporary fix to avoid problems with HLT that overwrites the offline ESDs
+      // the logic for selection and correct sequence of reconstruction relies on the
+      // full list of detectors. Keyword 'ALL' should have been replaced at this point.
       if (detectors.Contains("ALL")) {
-       detectors="";
-       for (Int_t idet=0; idet<kNDetectors; ++idet){
-         detectors += fgkDetectorName[idet];
-         detectors += " ";
-       }
+       AliFatal("Keyword 'ALL' needs to be replaced by the full list of detectors in "
+                "fFillESD. This should have been done by the framework");
       }
+      // remove HLT as this has been executed at the beginning of the event reconstruction
       detectors.ReplaceAll("HLT", "");
       if (!FillESD(fesd, detectors)) {
        if (fStopOnError) {CleanUp(); return kFALSE;}
       }
     }
-    
 
     ffile->cd();
 
@@ -2271,7 +2297,9 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
     AliSysInfo::AddStamp(Form("FillVaria_%d",iEvent), 0,0,iEvent); 
 
     // write ESD
-    if (fCleanESD) {
+    UInt_t specie = fesd->GetEventSpecie();
+    Bool_t keepAll = (specie==AliRecoParam::kCosmic || specie==AliRecoParam::kCalib);
+    if (fCleanESD && (!keepAll) ) {
       CleanESD(fesd);
       AliSysInfo::AddStamp(Form("CleanESD_%d",iEvent), 0,0,iEvent); 
     }
@@ -2351,6 +2379,10 @@ Bool_t AliReconstruction::ProcessEvent(Int_t iEvent)
       fesdf->~AliESDfriend();
       new (fesdf) AliESDfriend(); // Reset...
     }
+
+    for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
+      if (fReconstructor[iDet]) fReconstructor[iDet]->FinishEvent();
+    }
  
     gSystem->GetProcInfo(&procInfo);
     Long_t dMres=(procInfo.fMemResident-oldMres)/1024;
@@ -2444,7 +2476,7 @@ void AliReconstruction::SlaveTerminate()
    sVersion += ":";
    sVersion += ROOT_SVN_REVISION;
    sVersion += "; metadata ";
-   sVersion += gSystem->Getenv("PRODUCTION_METADATA");
+   sVersion += getenv("PRODUCTION_METADATA");
                    
 
    TNamed * alirootVersion = new TNamed("alirootVersion",sVersion.Data());
@@ -2549,7 +2581,7 @@ Bool_t AliReconstruction::RunLocalEventReconstruction(const TString& detectors)
   // execute HLT reconstruction first since other detector reconstruction
   // might depend on HLT data
   // key 'HLT' is removed from detStr by IsSelected
-  if (!IsSelected("HLT", detStr)) {
+  if (IsSelected("HLT", detStr)) {
     AliReconstructor* reconstructor = GetReconstructor(kNDetectors-1);
     if (reconstructor) {
       // there is no AliLoader for HLT, see
@@ -2794,62 +2826,6 @@ Bool_t AliReconstruction::RunMultFinder(AliESDEvent*& esd)
   return kTRUE;
 }
 
-//_____________________________________________________________________________
-Bool_t AliReconstruction::RunHLTTracking(AliESDEvent*& esd)
-{
-// run the HLT barrel tracking
-
-  AliCodeTimerAuto("",0)
-
-  if (!fRunLoader) {
-    AliError("Missing runLoader!");
-    return kFALSE;
-  }
-
-  AliInfo("running HLT tracking");
-
-  // Get a pointer to the HLT reconstructor
-  AliReconstructor *reconstructor = GetReconstructor(kNDetectors-1);
-  if (!reconstructor) return kFALSE;
-
-  // TPC + ITS
-  for (Int_t iDet = 1; iDet >= 0; iDet--) {
-    TString detName = fgkDetectorName[iDet];
-    AliDebug(1, Form("%s HLT tracking", detName.Data()));
-    reconstructor->SetOption(detName.Data());
-    AliTracker *tracker = reconstructor->CreateTracker();
-    if (!tracker) {
-      AliWarning(Form("couldn't create a HLT tracker for %s", detName.Data()));
-      if (fStopOnError) return kFALSE;
-      continue;
-    }
-    Double_t vtxPos[3];
-    Double_t vtxErr[3]={0.005,0.005,0.010};
-    const AliESDVertex *vertex = esd->GetVertex();
-    vertex->GetXYZ(vtxPos);
-    tracker->SetVertex(vtxPos,vtxErr);
-    if(iDet != 1) {
-      fLoader[iDet]->LoadRecPoints("read");
-      TTree* tree = fLoader[iDet]->TreeR();
-      if (!tree) {
-       AliError(Form("Can't get the %s cluster tree", detName.Data()));
-       return kFALSE;
-      }
-      tracker->LoadClusters(tree);
-    }
-    if (tracker->Clusters2Tracks(esd) != 0) {
-      AliError(Form("HLT %s Clusters2Tracks failed", fgkDetectorName[iDet]));
-      return kFALSE;
-    }
-    if(iDet != 1) {
-      tracker->UnloadClusters();
-    }
-    delete tracker;
-  }
-
-  return kTRUE;
-}
-
 //_____________________________________________________________________________
 Bool_t AliReconstruction::RunMuonTracking(AliESDEvent*& esd)
 {
@@ -2941,7 +2917,7 @@ Bool_t AliReconstruction::RunTracking(AliESDEvent*& esd,AliESDpid &PID)
     fTracker[iDet]->LoadClusters(tree);
     AliSysInfo::AddStamp(Form("TLoadCluster%s_%d",fgkDetectorName[iDet],eventNr), iDet,2, eventNr);
     // run tracking
-    if (fTracker[iDet]->Clusters2Tracks(esd) != 0) {
+    if (fTracker[iDet]->Clusters2TracksHLT(esd, fhltesd) != 0) {
       AliError(Form("%s Clusters2Tracks failed", fgkDetectorName[iDet]));
       return kFALSE;
     }
@@ -3182,9 +3158,11 @@ Bool_t AliReconstruction::FillTriggerESD(AliESDEvent*& esd)
        esdheader->AddTriggerIR(input.GetIR(i));
       }
        AliCentralTrigger* rlCTP = fRunLoader->GetTrigger();
-       rlCTP->SetL0TriggerInputs(input.GetL0Inputs());
-       rlCTP->SetL1TriggerInputs(input.GetL1Inputs());
-       rlCTP->SetL2TriggerInputs(input.GetL2Inputs());
+       if (rlCTP) {
+        rlCTP->SetL0TriggerInputs(input.GetL0Inputs());
+        rlCTP->SetL1TriggerInputs(input.GetL1Inputs());
+        rlCTP->SetL2TriggerInputs(input.GetL2Inputs());
+       }
     }
     if (fIsNewRunLoader) fRunLoader->TreeCT()->Fill();
   }
@@ -3285,7 +3263,6 @@ Bool_t AliReconstruction::InitRunLoader()
     TString libs = gSystem->GetLibraries();
     for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
       TString detName = fgkDetectorName[iDet];
-      if (detName == "HLT") continue;
       if (libs.Contains("lib" + detName + "base.so")) continue;
       gSystem->Load("lib" + detName + "base.so");
     }
@@ -3384,6 +3361,7 @@ AliReconstructor* AliReconstruction::GetReconstructor(Int_t iDet)
     TObject* obj = fOptions.FindObject(detName.Data());
     if (obj) reconstructor->SetOption(obj->GetTitle());
     reconstructor->SetRunInfo(fRunInfo);
+    reconstructor->SetHLTESD(fhltesd);
     reconstructor->Init();
     fReconstructor[iDet] = reconstructor;
   }
@@ -3490,10 +3468,6 @@ Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
     AliReconstructor* reconstructor = GetReconstructor(iDet);
     if (!reconstructor) continue;
     TString detName = fgkDetectorName[iDet];
-    if (detName == "HLT") {
-      fRunHLTTracking = kTRUE;
-      continue;
-    }
     if (detName == "MUON") {
       fRunMuonTracking = kTRUE;
       continue;
@@ -3514,7 +3488,6 @@ Bool_t AliReconstruction::CreateTrackers(const TString& detectors)
 void AliReconstruction::CleanUp()
 {
 // delete trackers and the run loader and close and delete the file
-/*
   for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
     delete fReconstructor[iDet];
     fReconstructor[iDet] = NULL;
@@ -3522,7 +3495,6 @@ void AliReconstruction::CleanUp()
     delete fTracker[iDet];
     fTracker[iDet] = NULL;
   }
-*/
 
   delete fRunInfo;
   fRunInfo = NULL;
@@ -3771,7 +3743,7 @@ Bool_t AliReconstruction::InitAliEVE()
   // The return flag shows whenever the
   // AliEVE initialization was successful or not.
 
-  TString macroStr(gSystem->Getenv("ALIEVE_ONLINE_MACRO"));
+  TString macroStr(getenv("ALIEVE_ONLINE_MACRO"));
 
   if (macroStr.IsNull())
     macroStr.Form("%s/EVE/macros/alieve_online.C",gSystem->ExpandPathName("$ALICE_ROOT"));
@@ -3962,9 +3934,13 @@ Bool_t AliReconstruction::GetEventInfo()
     aCTP->SetClassMask(mask);
     aCTP->SetClusterMask(clmask);
 
-    AliCentralTrigger* rlCTP = fRunLoader->GetTrigger();
-    rlCTP->SetClassMask(mask);
-    rlCTP->SetClusterMask(clmask);
+    if (fRunLoader) {
+      AliCentralTrigger* rlCTP = fRunLoader->GetTrigger();
+      if (rlCTP) {
+       rlCTP->SetClassMask(mask);
+       rlCTP->SetClusterMask(clmask);
+      }
+    }
   }
   else {
     fEventInfo.SetEventType(AliRawEventHeaderBase::kPhysicsEvent);
@@ -3980,6 +3956,7 @@ Bool_t AliReconstruction::GetEventInfo()
       fEventInfo.SetTriggerCluster(AliDAQ::ListOfTriggeredDetectors(aCTP->GetClusterMask()));
     }
     else {
+      if (fStopOnMissingTriggerFile) AliFatal("No trigger can be loaded! Stopping reconstruction!");
       AliWarning("No trigger can be loaded! The trigger information will not be used!");
       return kFALSE;
     }
@@ -3992,6 +3969,32 @@ Bool_t AliReconstruction::GetEventInfo()
     return kFALSE;
   }
 
+  // Load trigger aliases and declare the trigger classes included in aliases
+  //PH Why do we do it in each event and not only once in the beginning of the chunk??
+  //PH Temporary fix for #99725: AliReconstruction::GetEventInfo bug
+  fDeclTriggerClasses.Clear();
+  AliCDBEntry * entry = AliCDBManager::Instance()->Get("GRP/CTP/Aliases");
+  if (entry) {
+    THashList * lst = dynamic_cast<THashList*>(entry->GetObject());
+    if (lst) {
+      lst->Sort(kSortDescending); // to avoid problems with substrungs
+      if (fRawReader) fRawReader->LoadTriggerAlias(lst);
+      // Now declare all the triggers present in the aliases
+      TIter iter(lst);
+      TNamed *nmd = 0;
+      while((nmd = dynamic_cast<TNamed*>(iter.Next()))){
+       fDeclTriggerClasses += " ";
+       fDeclTriggerClasses += nmd->GetName();
+      }
+    }
+    else {
+      AliError("Cannot cast the object with trigger aliases to THashList!");
+    }
+  }
+  else {
+    AliError("No OCDB ebtry for the trigger aliases!");
+  }
+  // Load trigger classes for this run
   UChar_t clustmask = 0;
   TString trclasses;
   ULong64_t trmask = fEventInfo.GetTriggerMask();
@@ -4001,7 +4004,7 @@ Bool_t AliReconstruction::GetEventInfo()
     AliTriggerClass* trclass = (AliTriggerClass*)classesArray.At(iclass);
     if (trclass && trclass->GetMask()>0) {
       Int_t trindex = TMath::Nint(TMath::Log2(trclass->GetMask()));
-      fesd->SetTriggerClass(trclass->GetName(),trindex);
+      if (fesd) fesd->SetTriggerClass(trclass->GetName(),trindex);
       if (fRawReader) fRawReader->LoadTriggerClass(trclass->GetName(),trindex);
       if (trmask & (1ull << trindex)) {
        trclasses += " ";
@@ -4030,17 +4033,22 @@ Bool_t AliReconstruction::GetEventInfo()
     AliTriggerInput* trginput = (AliTriggerInput*)inputsArray.At(iinput);
     if (trginput && trginput->GetMask()>0) {
       Int_t inputIndex = (Int_t)TMath::Nint(TMath::Log2(trginput->GetMask()));
-      AliESDHeader* headeresd = fesd->GetHeader();
-      Int_t trglevel = (Int_t)trginput->GetLevel();
-      if (trglevel == 0) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex);
-      if (trglevel == 1) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+24);
-      if (trglevel == 2) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+48);
+      AliESDHeader* headeresd = 0x0;
+      if (fesd) headeresd = fesd->GetHeader();
+      if (headeresd) {
+       Int_t trglevel = (Int_t)trginput->GetLevel();
+       if (trglevel == 0) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex);
+       if (trglevel == 1) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+24);
+       if (trglevel == 2) headeresd->SetActiveTriggerInputs(trginput->GetInputName(), inputIndex+48);
+      }
     }
   }
 
   // Set the information in ESD
-  fesd->SetTriggerMask(trmask);
-  fesd->SetTriggerCluster(clustmask);
+  if (fesd) {
+    fesd->SetTriggerMask(trmask);
+    fesd->SetTriggerCluster(clustmask);
+  }
 
   if (!aCTP->CheckTriggeredDetectors()) {
     if (fRawReader) delete aCTP;
@@ -4355,8 +4363,8 @@ void AliReconstruction::DeleteDigits(const TString& detectors)
   AliInfo(Form("Deleting Digits: %s",detectors.Data()));
 
   for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
-    gSystem->Exec(Form("if [ -e %s.Digits.root ]; then\nrm %s.Digits.root\nfi",
-                      fgkDetectorName[iDet],fgkDetectorName[iDet]));
+    if(!IsSelected(fgkDetectorName[iDet], detStr)) continue;
+    unlink(Form("%s.Digits.root",fgkDetectorName[iDet]));
   }
   AliSysInfo::AddStamp(Form("DelDigits_%d",iEvent), 0,0,iEvent);
   iEvent++;
@@ -4372,8 +4380,8 @@ void AliReconstruction::DeleteRecPoints(const TString& detectors)
   AliInfo(Form("Deleting Recpoints: %s",detectors.Data()));
   //
   for (Int_t iDet = 0; iDet < kNDetectors; iDet++) {
-    gSystem->Exec(Form("if [ -e %s.RecPoints.root ]; then\nrm %s.RecPoints.root\nfi",
-                      fgkDetectorName[iDet],fgkDetectorName[iDet]));
+    if(!IsSelected(fgkDetectorName[iDet], detStr)) continue;
+    unlink(Form("%s.RecPoints.root",fgkDetectorName[iDet]));
   }
   AliSysInfo::AddStamp(Form("DelRecPoints_%d",iEvent), 0,0,iEvent);
   iEvent++;
@@ -4435,7 +4443,10 @@ Bool_t AliReconstruction::HasEnoughResources(int ev)
                 int(procInfo.fMemResident/kKB2MB),fMaxRSS,
                 int(procInfo.fMemVirtual/kKB2MB) ,fMaxVMEM));
     //
-    gSystem->Exec(Form("if [ -e %s ]; then\nrm %s\nfi\necho %d > %s",fgkStopEvFName,fgkStopEvFName,ev,fgkStopEvFName));
+    unlink(Form("%s",fgkStopEvFName));
+    ofstream outfile(fgkStopEvFName);
+    outfile << ev << std::endl;
+    outfile.close();
     fStopped = kTRUE;
   }
   return res;