]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTSystem.cxx
CMake: removing qpythia from the depedencies
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.cxx
index 2dee381a0dadbe6d2e9b86fcf635d31a14b0a872..e6eca330f6122854d8821307e7ce331e94a991f6 100644 (file)
@@ -1,6 +1,6 @@
 // $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>        *
 //* provided "as is" without express or implied warranty.                  *
 //**************************************************************************
 
-/** @file   AliHLTSystem.cxx
-    @author Matthias Richter
-    @date   
-    @brief  Implementation of HLT module management.
-*/
-
-#if __GNUC__>= 3
-using namespace std;
-#endif
+/// @file   AliHLTSystem.cxx
+/// @author Matthias Richter
+/// @date   
+/// @brief  Implementation of HLT module management.
+///
 
 #include <cassert>
 #include "AliHLTStdIncludes.h"
@@ -89,10 +85,13 @@ AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel, const char* name
   fpEsdHandlers(NULL),
   fpProprietaryHandlers(NULL),
   fpHLTOUTTask(NULL),
+  fpHLTOUT(NULL),
+  fHLTOUTUse(0),
   fpControlTask(NULL),
   fName(name)
   , fECSParams()
   , fUseHLTOUTComponentTypeGlobal(true)
+  , fDetMask(0)
 {
   // see header file for class documentation
   // or
@@ -105,7 +104,6 @@ AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel, const char* name
     // AliHLTSystem is used in multiple instances for the kChain HLTOUT handler
     //HLTWarning("multiple instances of AliHLTSystem, you should not use more than one at a time");
   }
-
   SetGlobalLoggingLevel(loglevel);
   SetFrameworkLog(loglevel);
   if (fpComponentHandler) {
@@ -123,9 +121,7 @@ AliHLTSystem::AliHLTSystem(AliHLTComponentLogSeverity loglevel, const char* name
   } else {
     HLTFatal("can not create Component Handler");
   }
-  if (fpConfigurationHandler) {
-    AliHLTConfiguration::GlobalInit(fpConfigurationHandler);
-  } else {
+  if (fpConfigurationHandler==NULL) {
     HLTFatal("can not create Configuration Handler");
   }
 }
@@ -134,9 +130,8 @@ AliHLTSystem::~AliHLTSystem()
 {
   // see header file for class documentation
   fgNofInstances--;
-  CleanHLTOUT();
+  CleanupHLTOUTHandlers();
   CleanTaskList();
-  AliHLTConfiguration::GlobalDeinit(fpConfigurationHandler);
   if (fpConfigurationHandler) {
     fpConfigurationHandler->Destroy();
   }
@@ -190,7 +185,7 @@ int AliHLTSystem::BuildTaskList(AliHLTConfiguration* pConf)
       // task for this configuration exists, terminate
       pTask=NULL;
     // check first if the configuration has all sources resolved, try to extract otherwise
-    } else if (pConf->SourcesResolved()!=1 && pConf->ExtractSources()!=1) {
+    } else if (pConf->SourcesResolved()!=1 && pConf->ExtractSources(fpConfigurationHandler)!=1) {
        HLTError("configuration \"%s\" has unresolved sources, aborting ...", pConf->GetName());
        iResult=-ENOLINK;
     } else {
@@ -351,6 +346,14 @@ void AliHLTSystem::PrintTaskList()
 int AliHLTSystem::Run(Int_t iNofEvents, int bStop, AliHLTUInt64_t trgMask,
                      AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
                      AliHLTUInt32_t participatingDetectors)
+{
+  return Run(iNofEvents, bStop, AliHLTTriggerMask_t(trgMask), 
+            timestamp, eventtype, participatingDetectors);
+}
+
+int AliHLTSystem::Run(Int_t iNofEvents, int bStop, AliHLTTriggerMask_t trgMask,
+                     AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
+                     AliHLTUInt32_t participatingDetectors)
 {
   // see header file for class documentation
   int iResult=0;
@@ -590,7 +593,7 @@ int AliHLTSystem::StartTasks()
   return iResult;
 }
 
-int AliHLTSystem::ProcessTasks(Int_t eventNo, AliHLTUInt64_t trgMask,
+int AliHLTSystem::ProcessTasks(Int_t eventNo, AliHLTTriggerMask_t trgMask,
          AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
          AliHLTUInt32_t participatingDetectors)
 {
@@ -654,6 +657,9 @@ int AliHLTSystem::StopTasks()
     lnk = lnk->Next();
   }
   PrintBenchmarking(fStopwatches, 1 /*clean*/);
+  if (fEventCount!=fGoodEvents) {
+    HLTError("%d out of %d event(s) failed", fEventCount-fGoodEvents, fEventCount);
+  }
   ClearStatusFlags(kStarted);
   return iResult;
 }
@@ -737,7 +743,7 @@ int AliHLTSystem::DeinitTasks()
   return iResult;
 }
 
-int AliHLTSystem::CleanHLTOUT()
+int AliHLTSystem::CleanupHLTOUTHandlers()
 {
   // see header file for class documentation
   if (fpChainHandlers) {
@@ -817,12 +823,12 @@ int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
        if (!CheckStatus(kError)) {
        StopTasks();
        DeinitTasks();
-       CleanHLTOUT();
+       CleanupHLTOUTHandlers();
        }
       } else {
       if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
-       AliHLTUInt64_t trgMask=0x1;
-       AliHLTUInt32_t timestamp=0;
+       AliHLTTriggerMask_t trgMask=0x1;
+       AliHLTUInt32_t timestamp=kMaxUInt;
        AliHLTUInt32_t eventtype=0;
        if (runLoader==NULL) {
          // this is a quick workaround for the case of simulation
@@ -842,6 +848,25 @@ int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
        if ((iResult=Run(nofEvents, 0, trgMask, timestamp, eventtype))<0) SetStatusFlags(kError);
       }
       }
+
+      // add the current HLTOUT task to the collection
+      if (fpHLTOUTTask) {
+       AliHLTOUT* pTask=dynamic_cast<AliHLTOUT*>(fpHLTOUTTask);
+       if (pTask && (iResult=pTask->Init())>=0) {
+         if (pTask->GetNofDataBlocks()>0) {
+           AliHLTOUT* pHLTOUT=RequestHLTOUT();
+           if (pHLTOUT) {
+             pHLTOUT->AddSubCollection(pTask);
+             ReleaseHLTOUT(pHLTOUT);
+           } else {
+             HLTWarning("no HLTOUT instance available, output blocks of the chain are ignored");
+           }
+         }
+       } else {
+         HLTWarning("can not initialize HLTOUT sub collection %s for reconstruction chain (%d), data blocks are lost", pTask?fpHLTOUTTask->GetName():"nil", iResult);
+         iResult=0;
+       }
+      }
     } else {
       HLTError("wrong state %#x, required flags %#x", GetStatusFlags(), kReady);
     }
@@ -873,20 +898,6 @@ int AliHLTSystem::ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd)
   if (!pHLTOUT) return -EINVAL;
   HLTDebug("processing %d HLT data blocks", pHLTOUT->GetNofDataBlocks());
 
-  // add the current HLTOUT task to the collection
-  if (fpHLTOUTTask) {
-    AliHLTOUT* pTask=dynamic_cast<AliHLTOUT*>(fpHLTOUTTask);
-    if (pTask && (iResult=pTask->Init())>=0) {
-      if (pTask->GetNofDataBlocks()>0) {
-       pHLTOUT->AddSubCollection(pTask);
-      }
-    } else {
-      HLTWarning("can not initialize HLTOUT sub collection %s for reconstruction chain (%d), data blocks are lost", pTask?fpHLTOUTTask->GetName():"nil", iResult);
-      iResult=0;
-    }
-  }
-
-  
   //
   // process all kChain handlers first
   //
@@ -1084,7 +1095,8 @@ int AliHLTSystem::LoadComponentLibraries(const char* libraries)
       if (pTokens) {
        int iEntries=pTokens->GetEntriesFast();
        for (int i=0; i<iEntries && iResult>=0; i++) {
-         iResult=fpComponentHandler->LoadLibrary((((TObjString*)pTokens->At(i))->GetString()).Data());
+         if (!pTokens->At(i)) continue;
+         iResult=fpComponentHandler->LoadLibrary(pTokens->At(i)->GetName());
        }
        delete pTokens;
       }
@@ -1157,7 +1169,8 @@ int AliHLTSystem::ScanOptions(const char* options)
     if (pTokens) {
       int iEntries=pTokens->GetEntriesFast();
       for (int i=0; i<iEntries; i++) {
-       TString token=(((TObjString*)pTokens->At(i))->GetString());
+       if (!pTokens->At(i)) continue;
+       TString token=pTokens->At(i)->GetName();
        if (token.Contains("loglevel=")) {
          TString param=token.ReplaceAll("loglevel=", "");
          if (param.IsDigit()) {
@@ -1184,37 +1197,54 @@ int AliHLTSystem::ScanOptions(const char* options)
          }
        } else if (token.Contains("alilog=off")) {
          SwitchAliLog(0);
-       } else if (token.Contains("config=")) {
-         TString param=token.ReplaceAll("config=", "");
-         Int_t error=0;
-         if (token.EndsWith(".xml", TString::kIgnoreCase)) {
-           Int_t filesize = 0;
-           AliHLTOnlineConfiguration conf;
-           filesize = conf.LoadConfiguration(param.Data());
-           if (filesize <= 0) {
-             HLTError("can not load config \'%s\'", param.Data());
-             iResult=-EBADF;
-           } else {
-             error = conf.Parse();
-             if (error==0) {
-               fChains = conf.GetDefaultChains();
-               libs = conf.GetComponentLibraries();
-               libs += " ";
-               SetStatusFlags(kConfigurationLoaded);
+       } else if (token.Contains("config=") || token.Contains("run-online-config")) {
+         if (!CheckStatus(kConfigurationLoaded)) {
+           Int_t error=0;
+           AliHLTOnlineConfiguration* pConf = NULL;
+           if (token.Contains("run-online-config")) {
+             AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry("HLT/Calib/OnlineConfig");
+             if (pEntry) {
+               TObject* pObject=AliHLTMisc::Instance().ExtractObject(pEntry);
+               if (pObject && pObject->IsA() == AliHLTOnlineConfiguration::Class())
+                 pConf = (AliHLTOnlineConfiguration*)pObject;
+             }
+           }
+           if (token.Contains("config=")) {
+             TString param=token.ReplaceAll("config=", "");
+             if (token.EndsWith(".xml", TString::kIgnoreCase)) {
+               Int_t filesize = 0;
+               pConf = new AliHLTOnlineConfiguration;
+               filesize = pConf->LoadConfiguration(param.Data());
+               if (filesize <= 0) {
+                 HLTError("cannot load config \'%s\'", param.Data());
+                 iResult=-EBADF;
+               }
              } else {
-               HLTError("can not parse config \'%s\'", param.Data());
-               iResult=-EBADF;
+               gROOT->Macro(param.Data(), &error);
+               if (error==0) {
+                 SetStatusFlags(kConfigurationLoaded);
+               } else {
+                 HLTError("cannot execute macro \'%s\'", param.Data());
+                 iResult=-EBADF;
+               }
              }
            }
-         } else {
-           gROOT->Macro(param.Data(), &error);
-           if (error==0) {
-             SetStatusFlags(kConfigurationLoaded);
-           } else {
-             HLTError("can not execute macro \'%s\'", param.Data());
-             iResult=-EBADF;
+           if (pConf) {
+               error = pConf->Parse();
+               if (error==0) {
+                 fChains = pConf->GetDefaultChains();
+                 libs = pConf->GetComponentLibraries();
+                 libs += " ";
+                 SetStatusFlags(kConfigurationLoaded);
+               } else {
+                 HLTError("cannot parse online configuration");
+                 iResult=-EBADF;
+               }
            }
-         }     
+           delete pConf; pConf=NULL;
+         } else {
+           HLTWarning("HLT options has both a config file and run-online-config set");
+         }
        } else if (token.Contains("chains=")) {
          TString param=token.ReplaceAll("chains=", "");
          fChains=param.ReplaceAll(",", " ");
@@ -1239,7 +1269,7 @@ int AliHLTSystem::ScanOptions(const char* options)
          // separated HLTOUTComponents for digit and raw data. All others indicate
          // HLTOUTComponent type 'global' where the data generation is steered from global
          // flags
-         fUseHLTOUTComponentTypeGlobal=token.CompareTo("hltout-mode=split")==1;
+         fUseHLTOUTComponentTypeGlobal=token.CompareTo("hltout-mode=split")!=0;
        } else if (token.BeginsWith("lib") && token.EndsWith(".so")) {
          libs+=token;
          libs+=" ";
@@ -1324,7 +1354,8 @@ int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runl
     TObjArray* pTokens=dependencies.Tokenize(" ");
     if (pTokens) {
       for (int n=0; n<pTokens->GetEntriesFast(); n++) {
-       TString module=((TObjString*)pTokens->At(n))->GetString();
+       if (!pTokens->At(n)) continue;
+       TString module=pTokens->At(n)->GetName();
        HLTDebug("  checking %s", module.Data());
        module.ReplaceAll("libAliHLT", "");
        module.ReplaceAll(".so", "");
@@ -1357,8 +1388,12 @@ int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runl
   if (agents.GetEntries()) {
     TIter next(&agents);
     while ((pAgent = dynamic_cast<AliHLTModuleAgent*>(next()))) {
-      HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
-      pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
+      if(fDetMask && !(fDetMask & pAgent->GetDetectorMask())) {
+       HLTInfo("Skipping %s due to active detector mask.", pAgent->GetName());
+      } else {
+       HLTDebug("load configurations for agent %s (%p)", pAgent->GetName(), pAgent);
+       pAgent->CreateConfigurations(fpConfigurationHandler, rawReader, runloader);
+      }
     }
   }
 
@@ -1377,6 +1412,8 @@ int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader
     return 0;
   }
 
+  if (!fpConfigurationHandler || !fpComponentHandler) return -EFAULT;
+
   int iResult=0;
   int bHaveOutput=0;
 
@@ -1403,14 +1440,14 @@ int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader
   if (pTokens) {
     int iEntries=pTokens->GetEntriesFast();
     for (int i=0; i<iEntries && iResult>=0; i++) {
-      const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
+      if (!pTokens->At(i)) continue;
+      const char* pCID=pTokens->At(i)->GetName();
       AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
       if (pConf) {
        iResult=BuildTaskList(pConf);
        if (true) { // condition was deprecated but kept for sake of svn diff
          // bHaveOutput variable has to be set for both running modes
          // AliHLTSimulation and AliHLTReconstruction
-         assert(fpComponentHandler!=NULL);
          TString cid=pConf->GetComponentID();
          if (runloader!=NULL && cid.CompareTo("HLTOUT")==0) {
            // remove from the input of a global HLTOUT configuration
@@ -1440,8 +1477,8 @@ int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader
       // the output stream
       if (fpComponentHandler->FindComponentIndex("ROOTSchemaEvolutionComponent")>=0 ||
          fpComponentHandler->LoadLibrary("libAliHLTUtil.so")>=0) {
-       AliHLTConfiguration schemaevo("_schemaevolution_", "ROOTSchemaEvolutionComponent", 
-                                     chains.Data(), "-file=HLT.StreamerInfo.root");
+       fpConfigurationHandler->CreateConfiguration("_schemaevolution_", "ROOTSchemaEvolutionComponent", 
+                                                    chains.Data(), "-file=HLT.StreamerInfo.root");
        iResult=BuildTaskList("_schemaevolution_");
       } else {
        HLTWarning("can not load libAliHLTUtil.so and ROOTSchemaEvolutionComponent");
@@ -1462,7 +1499,7 @@ int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader
          if (rawReader) HLTOUTComponentId="HLTOUTraw";
          else HLTOUTComponentId="HLTOUTdigits";
        }
-       AliHLTConfiguration globalout("_globalout_", HLTOUTComponentId, chains.Data(), NULL);
+       fpConfigurationHandler->CreateConfiguration("_globalout_", HLTOUTComponentId, chains.Data(), NULL);
        iResult=BuildTaskList("_globalout_");
       } else {
        HLTError("can not load libHLTsim.so and HLTOUT component");
@@ -1507,7 +1544,8 @@ int AliHLTSystem::AddHLTOUTTask(const char* hltoutchains)
   if (pTokens) {
     int iEntries=pTokens->GetEntriesFast();
     for (int i=0; i<iEntries && iResult>=0; i++) {
-      const char* token=((TObjString*)pTokens->At(i))->GetString().Data();
+      if (!pTokens->At(i)) continue;
+      const char* token=pTokens->At(i)->GetName();
       AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(token);
       if (pConf) {
        TString cid=pConf->GetComponentID();
@@ -1541,7 +1579,9 @@ int AliHLTSystem::AddHLTOUTTask(const char* hltoutchains)
 
   fpHLTOUTTask=new AliHLTOUTTask(chains);
   if (fpHLTOUTTask) {
-    if (fpHLTOUTTask->GetConf() && fpHLTOUTTask->GetConf()->SourcesResolved()>=0) {
+    if (fpHLTOUTTask->GetConf() && 
+       (fpHLTOUTTask->GetConf()->SourcesResolved()>0 ||
+        fpHLTOUTTask->GetConf()->ExtractSources(fpConfigurationHandler)>0)) {
       iResult=InsertTask(fpHLTOUTTask);
     } else {
       HLTError("HLTOUT task (%s) sources not resolved", fpHLTOUTTask->GetName());
@@ -1618,3 +1658,46 @@ int AliHLTSystem::LoggingVarargs(AliHLTComponentLogSeverity severity,
 
   return iResult;
 }
+
+int AliHLTSystem::InitHLTOUT(AliHLTOUT* instance)
+{
+  // Init the HLTOUT instance for the current event.
+  // The instance can be used by other classes to get hold on the data
+  // from HLTOUT.
+  if (!instance) return -EINVAL;
+  if (fpHLTOUT && fpHLTOUT!=instance) return -EBUSY;
+  fpHLTOUT=instance;
+  return 0;
+}
+
+int AliHLTSystem::InvalidateHLTOUT(AliHLTOUT** target)
+{
+  // Clear the HLTOUT instance.
+  int iResult=0;
+  if (fHLTOUTUse>0) {
+    HLTWarning("HLTOUT instance still in use, potential problem due to invalid pointer ahead");
+    fHLTOUTUse=0;
+    iResult=-EBUSY;
+  }
+  if (target) *target=fpHLTOUT;
+  fpHLTOUT=NULL;
+  return iResult;
+}
+
+AliHLTOUT* AliHLTSystem::RequestHLTOUT()
+{
+  // Get the HLTOUT instance.
+  // User method for processing classes. To be released after use.
+  if (!fpHLTOUT) return NULL;
+  fHLTOUTUse++;
+  return fpHLTOUT;
+}
+
+int AliHLTSystem::ReleaseHLTOUT(const AliHLTOUT* instance)
+{
+  // Release the HLTOUT instance after use.
+  if (!instance) return -EINVAL;
+  if (instance!=fpHLTOUT) return -ENOENT;
+  fHLTOUTUse--;
+  return 0;
+}