]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/rec/AliHLTReconstructor.cxx
Adding OADB to CMake
[u/mrichter/AliRoot.git] / HLT / rec / AliHLTReconstructor.cxx
index b9ccde0a4ee0fca1a23aae8b31d5f21ad3b3c875..dd9f5d1de7f230f3e8b9aa02c915a21a084bda2e 100644 (file)
 //* provided "as is" without express or implied warranty.                  *
 //**************************************************************************
 
-/** @file   AliHLTReconstructor.cxx
-    @author Matthias Richter
-    @date   
-    @brief  Binding class for HLT reconstruction in AliRoot. */
+//  @file   AliHLTReconstructor.cxx
+//  @author Matthias Richter
+//  @date   
+//  @brief  Binding class for HLT reconstruction in AliRoot
+//          Implements bot the interface to run HLT chains embedded into
+//          AliReconstruction and the unpacking and treatment of HLTOUT
 
 #include <TSystem.h>
 #include <TObjString.h>
 #include "TFile.h"
 #include "TTree.h"
+#include "TObject.h"
+#include "TObjArray.h"
+#include "TClass.h"
+#include "TStreamerInfo.h"
 #include "AliHLTReconstructor.h"
 #include "AliLog.h"
 #include "AliRawReader.h"
 #include "AliHLTOUTDigitReader.h"
 #include "AliHLTEsdManager.h"
 #include "AliHLTPluginBase.h"
-
+#include "AliHLTMisc.h"
+#include "AliCDBManager.h"
+#include "AliCDBEntry.h"
+#include "AliHLTMessage.h"
+#include "AliCentralTrigger.h"
+#include "AliTriggerConfiguration.h"
+#include "AliTriggerClass.h"
+#include "AliTriggerCluster.h"
+#include "AliDAQ.h"
+
+class AliCDBEntry;
+
+/** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTReconstructor)
 
 AliHLTReconstructor::AliHLTReconstructor()
-  : 
-  AliReconstructor(),
-  fFctProcessHLTOUT(NULL),
-  fpEsdManager(NULL),
-  fpPluginBase(new AliHLTPluginBase)
+  : AliReconstructor()
+  , fpEsdManager(NULL)
+  , fpPluginBase(new AliHLTPluginBase)
+  , fFlags(0)
 { 
   //constructor
 }
 
 AliHLTReconstructor::AliHLTReconstructor(const char* options)
-  : 
-  AliReconstructor(),
-  fFctProcessHLTOUT(NULL),
-  fpEsdManager(NULL),
-  fpPluginBase(new AliHLTPluginBase)
+  : AliReconstructor()
+  , fpEsdManager(NULL)
+  , fpPluginBase(new AliHLTPluginBase)
+  , fFlags(0)
 { 
   //constructor
   if (options) Init(options);
@@ -109,7 +125,6 @@ void AliHLTReconstructor::Init()
   // the options scan has been moved to AliHLTSystem, the old code
   // here is kept to be able to run an older version of the HLT code
   // with newer AliRoot versions.
-  TString libs("");
   TString option = GetOption();
   TObjArray* pTokens=option.Tokenize(" ");
   option="";
@@ -131,14 +146,15 @@ void AliHLTReconstructor::Init()
        }
       } else if (token.Contains("alilog=off")) {
        pSystem->SwitchAliLog(0);
+      } else if (token.CompareTo("ignore-hltout")==0) {
+       fFlags|=kAliHLTReconstructorIgnoreHLTOUT;
+      } else if (token.CompareTo("ignore-ctp")==0) {
+       fFlags|=kAliHLTReconstructorIgnoreCTP;
       } else if (token.Contains("esdmanager=")) {
        token.ReplaceAll("esdmanager=", "");
        token.ReplaceAll(","," ");
        token.ReplaceAll("'","");
        esdManagerOptions=token;
-      } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
-       libs+=token;
-       libs+=" ";
       } else {
        if (option.Length()>0) option+=" ";
        option+=token;
@@ -147,24 +163,23 @@ void AliHLTReconstructor::Init()
     delete pTokens;
   }
 
-  if (!libs.IsNull() &&
-      (!pSystem->CheckStatus(AliHLTSystem::kLibrariesLoaded)) &&
-      (pSystem->LoadComponentLibraries(libs.Data())<0)) {
-    AliError("error while loading HLT libraries");
-    return;
+  TString ecsParam;
+  TString ctpParam;
+  if ((fFlags&kAliHLTReconstructorIgnoreCTP)==0 &&
+      BuildCTPTriggerClassString(ctpParam)>=0) {
+    if (!ecsParam.IsNull()) ecsParam+=";";
+    ecsParam+="CTP_TRIGGER_CLASS=";
+    ecsParam+=ctpParam;
+  }
+
+  if (!ecsParam.IsNull()) {
+    option+=" ECS=";
+    option+=ecsParam;
   }
 
   if (!pSystem->CheckStatus(AliHLTSystem::kReady)) {
-    typedef int (*AliHLTSystemSetOptions)(AliHLTSystem* pInstance, const char* options);
-    gSystem->Load("libHLTinterface.so");
-    AliHLTSystemSetOptions pFunc=(AliHLTSystemSetOptions)(gSystem->DynFindSymbol("libHLTinterface.so", "AliHLTSystemSetOptions"));
-    if (pFunc) {
-      if ((pFunc)(pSystem, option.Data())<0) {
+    if (pSystem->ScanOptions(option.Data())<0) {
       AliError("error setting options for HLT system");
-      return;  
-      }
-    } else if (option.Length()>0) {
-      AliError(Form("version of HLT system does not support the options \'%s\'", option.Data()));
       return;
     }
     if ((pSystem->Configure())<0) {
@@ -173,13 +188,14 @@ void AliHLTReconstructor::Init()
     }
   }
 
-  gSystem->Load("libHLTinterface.so");
-  fFctProcessHLTOUT=(void (*)())gSystem->DynFindSymbol("libHLTinterface.so", "AliHLTSystemProcessHLTOUT");
-
   fpEsdManager=AliHLTEsdManager::New();
   fpEsdManager->SetOption(esdManagerOptions.Data());
+
+  AliHLTMisc::Instance().InitStreamerInfos(fgkCalibStreamerInfoEntry);
 }
 
+const char* AliHLTReconstructor::fgkCalibStreamerInfoEntry="HLT/Calib/StreamerInfo";
+
 void AliHLTReconstructor::Reconstruct(AliRawReader* rawReader, TTree* /*clustersTree*/) const 
 {
   // reconstruction of real data without writing of ESD
@@ -235,9 +251,13 @@ void AliHLTReconstructor::FillESD(AliRawReader* rawReader, TTree* /*clustersTree
     }
     pSystem->FillESD(-1, NULL, esd);
 
-    AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(rawReader, esd->GetEventNumberInFile(), fpEsdManager);
+    AliRawReader* input=NULL;
+    if ((fFlags&kAliHLTReconstructorIgnoreHLTOUT) == 0 ) {
+      input=rawReader;
+    }
+    AliHLTOUTRawReader* pHLTOUT=new AliHLTOUTRawReader(input, esd->GetEventNumberInFile(), fpEsdManager);
     if (pHLTOUT) {
-      ProcessHLTOUT(pHLTOUT, esd);
+      ProcessHLTOUT(pHLTOUT, esd, (pSystem->GetGlobalLoggingLevel()&kHLTLogDebug)!=0);
       delete pHLTOUT;
     } else {
       AliError("error creating HLTOUT handler");
@@ -296,7 +316,7 @@ void AliHLTReconstructor::FillESD(TTree* /*digitsTree*/, TTree* /*clustersTree*/
 
     AliHLTOUTDigitReader* pHLTOUT=new AliHLTOUTDigitReader(esd->GetEventNumberInFile(), fpEsdManager);
     if (pHLTOUT) {
-      ProcessHLTOUT(pHLTOUT, esd);
+      ProcessHLTOUT(pHLTOUT, esd, (pSystem->GetGlobalLoggingLevel()&kHLTLogDebug)!=0);
       delete pHLTOUT;
     } else {
       AliError("error creating HLTOUT handler");
@@ -327,13 +347,35 @@ void AliHLTReconstructor::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd, bo
   if (bVerbose)
     PrintHLTOUTContent(pHLTOUT);
 
-  if (fFctProcessHLTOUT) {
-    typedef int (*AliHLTSystemProcessHLTOUT)(AliHLTSystem* pInstance, AliHLTOUT* pHLTOUT, AliESDEvent* esd);
-    AliHLTSystemProcessHLTOUT pFunc=(AliHLTSystemProcessHLTOUT)fFctProcessHLTOUT;
-    if ((pFunc)(pSystem, pHLTOUT, esd)<0) {
-      AliError("error processing HLTOUT");
+  int blockindex=pHLTOUT->SelectFirstDataBlock(kAliHLTDataTypeStreamerInfo);
+  if (blockindex>=0) {
+    const AliHLTUInt8_t* pBuffer=NULL;
+    AliHLTUInt32_t size=0;
+    if (pHLTOUT->GetDataBuffer(pBuffer, size)>=0) {
+      TObject* pObject=AliHLTMessage::Extract(pBuffer, size);
+      if (pObject) {
+       TObjArray* pArray=dynamic_cast<TObjArray*>(pObject);
+       if (pArray) {
+         AliHLTMisc::Instance().InitStreamerInfos(pArray);
+       } else {
+         AliError(Form("wrong class type of streamer info list: expected TObjArray, but object is of type %s", pObject->Class()->GetName()));
+       }
+      } else {
+       AliError(Form("failed to extract object from data block of type %s", AliHLTComponent::DataType2Text(kAliHLTDataTypeStreamerInfo).c_str()));
+      }
+    } else {
+      AliError(Form("failed to get data buffer for block of type %s", AliHLTComponent::DataType2Text(kAliHLTDataTypeStreamerInfo).c_str()));
     }
   }
+
+  if (pSystem->ProcessHLTOUT(pHLTOUT, esd)<0) {
+    AliError("error processing HLTOUT");
+  }
+
+  if (bVerbose) {
+    AliInfo("HLT ESD content:");
+    esd->Print();
+  }
   pHLTOUT->Reset();
 }
 
@@ -382,7 +424,7 @@ void AliHLTReconstructor::ProcessHLTOUT(AliRawReader* pRawReader, AliESDEvent* p
       //        id[0]               id[1]
       // |32                0|32                0|
       //
-      // |28              |20                | 12|
+      // |      28 bit    |       24 bit     | 12|
       //        period          orbit         bcc
       AliHLTUInt64_t eventId=0;
       const UInt_t* rawreaderEventId=pRawReader->GetEventId();
@@ -422,3 +464,55 @@ void AliHLTReconstructor::PrintHLTOUTContent(AliHLTOUT* pHLTOUT) const
     AliInfo(Form("   %s  0x%x: size %d", AliHLTComponent::DataType2Text(dt).c_str(), spec, size));
   }
 }
+
+int AliHLTReconstructor::BuildCTPTriggerClassString(TString& triggerclasses) const
+{
+  // build the CTP trigger class string from the OCDB entry of the CTP trigger
+  int iResult=0;
+  
+  triggerclasses.Clear();
+  AliCentralTrigger* pCTP = new AliCentralTrigger();
+  AliTriggerConfiguration *config=NULL;
+  TString configstr("");
+  if (pCTP->LoadConfiguration(configstr) && 
+      (config = pCTP->GetConfiguration())!=NULL) {
+    const TObjArray& classesArray = config->GetClasses();
+    int nclasses = classesArray.GetEntriesFast();
+    for( int iclass=0; iclass < nclasses; iclass++ ) {
+      AliTriggerClass* trclass = NULL;
+      if (classesArray.At(iclass) && (trclass=dynamic_cast<AliTriggerClass*>(classesArray.At(iclass)))!=NULL) {
+       TString entry;
+       int trindex = TMath::Nint(TMath::Log2(trclass->GetMask()));
+       entry.Form("%02d:%s:", trindex, trclass->GetName());
+       AliTriggerCluster* cluster=NULL;
+       TObject* clusterobj=config->GetClusters().FindObject(trclass->GetCluster());
+       if (clusterobj && (cluster=dynamic_cast<AliTriggerCluster*>(clusterobj))!=NULL) {
+         TString detectors=cluster->GetDetectorsInCluster();
+         TObjArray* pTokens=detectors.Tokenize(" ");
+         if (pTokens) {
+           for (int dix=0; dix<pTokens->GetEntriesFast(); dix++) {
+             int id=AliDAQ::DetectorID(((TObjString*)pTokens->At(dix))->GetString());
+             if (id>=0) {
+               TString detstr; detstr.Form("%s%02d", dix>0?"-":"", id);
+               entry+=detstr;
+             } else {
+               AliError(Form("invalid detector name extracted from trigger cluster: %s (%s)", ((TObjString*)pTokens->At(dix))->GetString().Data(), detectors.Data()));
+               iResult=-EPROTO;
+               break;
+             }
+           }
+           delete pTokens;
+         }
+       } else {
+         AliError(Form("can not find trigger cluster %s in config", trclass->GetCluster()?trclass->GetCluster()->GetName():"NULL"));
+         iResult=-EPROTO;
+         break;
+       }
+       if (!triggerclasses.IsNull()) triggerclasses+=",";
+       triggerclasses+=entry;
+      }
+    }
+  }
+
+  return iResult;
+}