]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/rec/AliHLTReconstructor.cxx
CMake: removing qpythia from the depedencies
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTReconstructor.cxx
index dd9f5d1de7f230f3e8b9aa02c915a21a084bda2e..7fdab9b0316b38dcbc244db92d128dd30ced95d0 100644 (file)
@@ -1,11 +1,10 @@
 // $Id$
 
 //**************************************************************************
-//* This file is property of and copyright by the ALICE HLT Project        * 
+//* This file is property of and copyright by the                          * 
 //* ALICE Experiment at CERN, All rights reserved.                         *
 //*                                                                        *
 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
-//*                  for The ALICE HLT Project.                            *
 //*                                                                        *
 //* Permission to use, copy, modify and distribute this software and its   *
 //* documentation strictly for non-commercial purposes is hereby granted   *
@@ -49,6 +48,8 @@
 #include "AliTriggerClass.h"
 #include "AliTriggerCluster.h"
 #include "AliDAQ.h"
+#include "AliRunLoader.h"
+#include "AliRunInfo.h"
 
 class AliCDBEntry;
 
@@ -60,6 +61,7 @@ AliHLTReconstructor::AliHLTReconstructor()
   , fpEsdManager(NULL)
   , fpPluginBase(new AliHLTPluginBase)
   , fFlags(0)
+  , fProcessingStep(kProcessingStepUndefined)
 { 
   //constructor
 }
@@ -69,6 +71,7 @@ AliHLTReconstructor::AliHLTReconstructor(const char* options)
   , fpEsdManager(NULL)
   , fpPluginBase(new AliHLTPluginBase)
   , fFlags(0)
+  , fProcessingStep(kProcessingStepUndefined)
 { 
   //constructor
   if (options) Init(options);
@@ -78,6 +81,9 @@ AliHLTReconstructor::~AliHLTReconstructor()
 { 
   //destructor
 
+  if (fpEsdManager) AliHLTEsdManager::Delete(fpEsdManager);
+  fpEsdManager=NULL;
+
   if (fpPluginBase) {
   AliHLTSystem* pSystem=fpPluginBase->GetInstance();
   if (pSystem) {
@@ -91,8 +97,6 @@ AliHLTReconstructor::~AliHLTReconstructor()
   }
   fpPluginBase=NULL;
 
-  if (fpEsdManager) AliHLTEsdManager::Delete(fpEsdManager);
-  fpEsdManager=NULL;
 }
 
 void AliHLTReconstructor::Init(const char* options)
@@ -148,6 +152,10 @@ void AliHLTReconstructor::Init()
        pSystem->SwitchAliLog(0);
       } else if (token.CompareTo("ignore-hltout")==0) {
        fFlags|=kAliHLTReconstructorIgnoreHLTOUT;
+      } else if (token.CompareTo("run-online-config")==0) {
+        fFlags|=kAliHLTReconstructorIgnoreHLTOUT;
+       if (option.Length()>0) option+=" ";
+       option+=token;
       } else if (token.CompareTo("ignore-ctp")==0) {
        fFlags|=kAliHLTReconstructorIgnoreCTP;
       } else if (token.Contains("esdmanager=")) {
@@ -178,6 +186,7 @@ void AliHLTReconstructor::Init()
   }
 
   if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
+    pSystem->SetDetectorMask(GetRunInfo()->GetDetectorMask());
     if (pSystem->ScanOptions(option.Data())<0) {
       AliError("error setting options for HLT system");
       return;
@@ -189,11 +198,69 @@ void AliHLTReconstructor::Init()
   }
 
   fpEsdManager=AliHLTEsdManager::New();
-  fpEsdManager->SetOption(esdManagerOptions.Data());
+  if (fpEsdManager) {
+    fpEsdManager->SetOption(esdManagerOptions.Data());
+  }
 
   AliHLTMisc::Instance().InitStreamerInfos(fgkCalibStreamerInfoEntry);
 }
 
+void AliHLTReconstructor::Terminate()
+{
+  /// overloaded from AliReconstructor: terminate event processing
+
+  // indicate step 'Terminate'
+  SetProcessingStep(kProcessingStepTerminate);
+
+  if (fpPluginBase) {
+    AliHLTSystem* pSystem=fpPluginBase->GetInstance();
+    if (pSystem) {
+      // 2012-04-02
+      // clean up the HLTOUT instance if still existing, currently FinishEvent
+      // is not called at the end of the event processing and the cleanup
+      // needs to be done here to avoid a warning message. Later it can be
+      // declared a malfunction if the HLTOUT instance is still existing at
+      // this point.
+      AliHLTOUT* pHLTOUT=NULL;
+      pSystem->InvalidateHLTOUT(&pHLTOUT);
+      if (pHLTOUT) {
+       pHLTOUT->Reset();
+       delete pHLTOUT;
+       pHLTOUT=NULL;
+      }
+
+      AliDebug(0, Form("terminate HLT system: status %#x", pSystem->GetStatusFlags()));
+      if (pSystem->CheckStatus(AliHLTSystem::kStarted)) {
+       // send specific 'event' to execute the stop sequence
+       pSystem->Reconstruct(0, NULL, NULL);
+      }
+    }
+  }
+}
+
+void AliHLTReconstructor::FinishEvent()
+{
+  /// overloaded from AliReconstructor: finish current event
+  if (!fpPluginBase) return;
+
+  // indicate step 'FinishEvent'
+  SetProcessingStep(kProcessingStepFinishEvent);
+
+  AliInfo("finishing event");
+  AliHLTSystem* pSystem=fpPluginBase->GetInstance();
+  if (pSystem) {
+    // this is the end of the lifetime of the HLTOUT instance
+    // called after all other modules have been reconstructed
+    AliHLTOUT* pHLTOUT=NULL;
+    pSystem->InvalidateHLTOUT(&pHLTOUT);
+    if (pHLTOUT) {
+      pHLTOUT->Reset();
+      delete pHLTOUT;
+      pHLTOUT=NULL;
+    }
+  }
+}
+
 const char* AliHLTReconstructor::fgkCalibStreamerInfoEntry="HLT/Calib/StreamerInfo";
 
 void AliHLTReconstructor::Reconstruct(AliRawReader* rawReader, TTree* /*clustersTree*/) const 
@@ -202,6 +269,7 @@ void AliHLTReconstructor::Reconstruct(AliRawReader* rawReader, TTree* /*clusters
   // For each event, HLT reconstruction chains can be executed and
   // added to the existing HLTOUT data
   // The HLTOUT data is finally processed in FillESD
+
   if (!fpPluginBase) {
     AliError("internal memory error: can not get AliHLTSystem instance from plugin");
     return;
@@ -211,14 +279,55 @@ void AliHLTReconstructor::Reconstruct(AliRawReader* rawReader, TTree* /*clusters
   AliHLTSystem* pSystem=fpPluginBase->GetInstance();
 
   if (pSystem) {
+    AliHLTOUT* pHLTOUT=NULL;
+    pSystem->InvalidateHLTOUT(&pHLTOUT);
+    if (pHLTOUT) {
+      // at this stage we always have a new event, regardless state of
+      // fProcessingStep; build the HLTOUT instance from scratch
+      pHLTOUT->Reset();
+      delete pHLTOUT;
+      pHLTOUT=NULL;
+    }
     if (pSystem->CheckStatus(AliHLTSystem::kError)) {
-      AliError("HLT system in error state");
+      // this is the highest level where an error can be detected, no error
+      // codes can be returned
+      AliFatal("HLT system in error state");
       return;
     }
     if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
       AliError("HLT system in wrong state");
       return;
     }
+
+    // indicate the local reconstruction step
+    SetProcessingStep(kProcessingStepLocal);
+
+    // init the HLTOUT instance for the current event
+    // not nice. Have to query the global run loader to get the current event no.
+    Int_t eventNo=-1;
+    AliRunLoader* runloader = AliRunLoader::Instance();
+    if (runloader) {
+      eventNo=runloader->GetEventNumber();
+    }
+    if (eventNo>=0) {
+      AliRawReader* input=NULL;
+      if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
+       input=rawReader;
+      }
+      pHLTOUT=new AliHLTOUTRawReader(input, eventNo, fpEsdManager);
+      if (pHLTOUT) {
+       if (pHLTOUT->Init()>=0) {
+         pSystem->InitHLTOUT(pHLTOUT);
+       } else {
+         AliError("error : initialization of HLTOUT handler failed");
+       }
+      } else {
+       AliError("memory allocation failed: can not create AliHLTOUT object");
+      }
+    } else {
+      AliError("can not get event number");
+    }
+
     if ((iResult=pSystem->Reconstruct(1, NULL, rawReader))>=0) {
     }
   }
@@ -242,7 +351,9 @@ void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree
 
   if (pSystem) {
     if (pSystem->CheckStatus(AliHLTSystem::kError)) {
-      AliError("HLT system in error state");
+      // this is the highest level where an error can be detected, no error
+      // codes can be returned
+      AliFatal("HLT system in error state");
       return;
     }
     if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
@@ -251,14 +362,38 @@ void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree
     }
     pSystem->FillESD(-1, NULL, esd);
 
-    AliRawReader* input=NULL;
-    if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
-      input=rawReader;
+    // the HLTOUT handler has either been created in the AliHLTReconstructor::Reconstruct
+    // step of this event or is created now. In either case the instance is deleted after
+    // the processing
+    AliHLTOUT* pHLTOUT=NULL;
+    pSystem->InvalidateHLTOUT(&pHLTOUT);
+    if (pHLTOUT && fProcessingStep!=kProcessingStepLocal) {
+      // this is a new event, if local reconstruction would have been executed
+      // the HLTOUT instance would have been created for the current event already,
+      // in all other cases one has to create the HLTOUT instance here
+      pHLTOUT->Reset();
+      delete pHLTOUT;
+      pHLTOUT=NULL;
+    }
+    if (!pHLTOUT) {
+      AliRawReader* input=NULL;
+      if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
+       input=rawReader;
+      }
+      pHLTOUT=new AliHLTOUTRawReader(input, esd->GetEventNumberInFile(), fpEsdManager);
     }
-    AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(input, esd->GetEventNumberInFile(), fpEsdManager);
+
+    // indicate step 'ESD filling'
+    SetProcessingStep(kProcessingStepESD);
+
     if (pHLTOUT) {
       ProcessHLTOUT(pHLTOUT, esd, (pSystem->GetGlobalLoggingLevel()&kHLTLogDebug)!=0);
-      delete pHLTOUT;
+      // 2012-03-30: a change in the module sequence of AliReconstruction is soon
+      // going to be applied: HLT reconstruction is executed fully (i.e. both local
+      // reconstruction and FillESD) before all the other modules. In order to make the
+      // HLTOUT data available for other modules it is kept here and released in the method
+      // FinishEvent
+      pSystem->InitHLTOUT(pHLTOUT);
     } else {
       AliError("error creating HLTOUT handler");
     }
@@ -269,9 +404,55 @@ void AliHLTReconstructor::Reconstruct(TTree* /*digitsTree*/, TTree* /*clustersTr
 {
   // reconstruct simulated data
 
-  // all reconstruction has been moved to FillESD
-  //AliReconstructor::Reconstruct(digitsTree,clustersTree);
-  AliInfo("running digit data reconstruction");
+  AliHLTSystem* pSystem=fpPluginBase->GetInstance();
+
+  if (pSystem) {
+    // create the HLTOUT instance in order to be available for other detector reconstruction
+    // first cleanup any existing instance
+    AliHLTOUT* pHLTOUT=NULL;
+    pSystem->InvalidateHLTOUT(&pHLTOUT);
+    if (pHLTOUT) {
+      // at this stage we always have a new event, regardless state of
+      // fProcessingStep; build the HLTOUT instance from scratch
+      pHLTOUT->Reset();
+      delete pHLTOUT;
+      pHLTOUT=NULL;
+    }
+
+    // indicate the local reconstruction step
+    SetProcessingStep(kProcessingStepLocal);
+
+    // not nice. Have to query the global run loader to get the current event no.
+    // This is related to the missing AliLoader for HLT.
+    // Since AliReconstruction can not provide a digits tree, the file needs to be accessed
+    // explicitely, and the corresponding event needs to be selected.
+    Int_t eventNo=-1;
+    AliRunLoader* runloader = AliRunLoader::Instance();
+    if (runloader) {
+      eventNo=runloader->GetEventNumber();
+    }
+    if (eventNo>=0) {
+      const char* digitfile=NULL;
+      if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
+       digitfile="HLT.Digits.root";
+      }
+
+      pHLTOUT=new AliHLTOUTDigitReader(eventNo, fpEsdManager, digitfile);
+      if (pHLTOUT) {
+       if (pHLTOUT->Init()>=0) {
+         pSystem->InitHLTOUT(pHLTOUT);
+       } else {
+         AliError("error : initialization of HLTOUT handler failed");
+       }
+      } else {
+       AliError("memory allocation failed: can not create AliHLTOUT object");
+      }
+    } else {
+      AliError("can not get event number");
+    }
+
+    // all data processing happens in FillESD
+  }
 }
 
 void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/, AliESDEvent* esd) const
@@ -284,10 +465,12 @@ void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/
   TString option = GetOption();
   if (!option.IsNull() && 
       (option.Contains("config=") || option.Contains("chains="))) {
-    AliWarning(Form("HLT reconstruction can be run embedded into Alireconstruction from\n"
-                   "raw data (real or simulated)). Reconstruction of of digit data takes\n"
-                   "place in AliSimulation, appropriate input conversion is needed.\n"
-                   "Consider running embedded into AliSimulation."
+    AliWarning(Form("You are trying to run a custom HLT chain on digits data.\n\n"
+                   "HLT reconstruction can be run embedded into AliReconstruction from\n"
+                   "raw data (real or simulated)). Reconstruction of digit data takes\n"
+                   "place in AliSimulation, appropriate input conversion is needed to\n"
+                   "feed data from the detector digits into the HLT chain.\n"
+                   "Consider running embedded into AliSimulation.\n"
                    "        /***  run macro *****************************************/\n"
                    "        AliSimulation sim;\n"
                    "        sim.SetRunHLT(\"%s\");\n"
@@ -296,7 +479,8 @@ void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/
                    "        sim.SetMakeSDigits(\"\");\n"
                    "        sim.SetMakeDigitsFromHits(\"\");\n"
                    "        sim.Run();\n"
-                   "        /*********************************************************/", option.Data()));
+                   "        /*********************************************************/\n\n",
+                   option.Data()));
   }
   if (!fpPluginBase) {
     AliError("internal memory error: can not get AliHLTSystem instance from plugin");
@@ -306,7 +490,9 @@ void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/
   AliHLTSystem* pSystem=fpPluginBase->GetInstance();
   if (pSystem) {
     if (pSystem->CheckStatus(AliHLTSystem::kError)) {
-      AliError("HLT system in error state");
+      // this is the highest level where an error can be detected, no error
+      // codes can be returned
+      AliFatal("HLT system in error state");
       return;
     }
     if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
@@ -314,10 +500,38 @@ void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/
       return;
     }
 
-    AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(esd->GetEventNumberInFile(), fpEsdManager);
+    // the HLTOUT handler has either been created in the AliHLTReconstructor::Reconstruct
+    // step of this event or is created now. In either case the instance is deleted after
+    // the processing
+    AliHLTOUT* pHLTOUT=NULL;
+    pSystem->InvalidateHLTOUT(&pHLTOUT);
+    if (pHLTOUT && fProcessingStep!=kProcessingStepLocal) {
+      // this is a new event, if local reconstruction would have been executed
+      // the HLTOUT instance would have been created for the current event already,
+      // in all other cases one has to create the HLTOUT instance here
+      pHLTOUT->Reset();
+      delete pHLTOUT;
+      pHLTOUT=NULL;
+    }
+    if (!pHLTOUT) {
+      const char* digitfile=NULL;
+      if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
+       digitfile="HLT.Digits.root";
+      }
+      pHLTOUT=new AliHLTOUTDigitReader(esd->GetEventNumberInFile(), fpEsdManager, digitfile);
+    }
+
+    // indicate step 'ESD filling'
+    SetProcessingStep(kProcessingStepESD);
+
     if (pHLTOUT) {
       ProcessHLTOUT(pHLTOUT, esd, (pSystem->GetGlobalLoggingLevel()&kHLTLogDebug)!=0);
-      delete pHLTOUT;
+      // 2012-03-30: a change in the module sequence of AliReconstruction is soon
+      // going to be applied: HLT reconstruction is executed fully (i.e. both local
+      // reconstruction and FillESD) before all the other modules. In order to make the
+      // HLTOUT data available for other modules it is kept here and released in the method
+      // FinishEvent
+      pSystem->InitHLTOUT(pHLTOUT);
     } else {
       AliError("error creating HLTOUT handler");
     }
@@ -372,11 +586,10 @@ void AliHLTReconstructor::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd, bo
     AliError("error processing HLTOUT");
   }
 
-  if (bVerbose) {
+  if (bVerbose && esd) {
     AliInfo("HLT ESD content:");
     esd->Print();
   }
-  pHLTOUT->Reset();
 }
 
 void AliHLTReconstructor::ProcessHLTOUT(const char* digitFile, AliESDEvent* pEsd) const