]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
- implemented component registration via agents
authorrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 16 Oct 2007 09:39:41 +0000 (09:39 +0000)
committerrichterm <richterm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Tue, 16 Oct 2007 09:39:41 +0000 (09:39 +0000)
- added HLTOUT component as default data sink for simulation
- added AliHLTAgentSim for libHLTsim.so
- AliHLTComponentHandler: more robust library handling

23 files changed:
HLT/BASE/AliHLTComponentHandler.cxx
HLT/BASE/AliHLTComponentHandler.h
HLT/BASE/AliHLTModuleAgent.cxx
HLT/BASE/AliHLTModuleAgent.h
HLT/BASE/AliHLTSystem.cxx
HLT/BASE/AliHLTSystem.h
HLT/BASE/util/AliHLTAgentUtil.cxx
HLT/BASE/util/AliHLTAgentUtil.h
HLT/BASE/util/AliHLTDataGenerator.cxx
HLT/BASE/util/AliHLTFilePublisher.cxx
HLT/BASE/util/AliHLTFileWriter.cxx
HLT/BASE/util/AliHLTLoaderPublisherComponent.cxx
HLT/BASE/util/AliHLTRawReaderPublisherComponent.cxx
HLT/BASE/util/AliHLTRootFilePublisherComponent.cxx
HLT/BASE/util/AliHLTRootFileStreamerComponent.cxx
HLT/BASE/util/AliHLTRootFileWriterComponent.cxx
HLT/ChangeLog
HLT/SampleLib/AliHLTAgentSample.cxx
HLT/SampleLib/AliHLTAgentSample.h
HLT/SampleLib/AliHLTDummyComponent.cxx
HLT/TPCLib/AliHLTTPCAgent.cxx
HLT/TPCLib/AliHLTTPCAgent.h
HLT/libHLTsim.pkg

index f95574a1be12149c78d47c1657c12f0153c42b0c..b8e0da4fdb8c13f7e1f01216331993aa018e7203 100644 (file)
@@ -36,15 +36,9 @@ using namespace std;
 #include "AliHLTComponentHandler.h"
 #include "AliHLTComponent.h"
 #include "AliHLTDataTypes.h"
-//#include "AliHLTSystem.h"
+#include "AliHLTModuleAgent.h"
 #include "TString.h"
 
-// the standard components
-// #include "AliHLTFilePublisher.h"
-// #include "AliHLTFileWriter.h"
-// #include "AliHLTRootFilePublisherComponent.h"
-// #include "AliHLTRootFileWriterComponent.h"
-
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTComponentHandler)
 
@@ -54,7 +48,7 @@ AliHLTComponentHandler::AliHLTComponentHandler()
   fScheduleList(),
   fLibraryList(),
   fEnvironment(),
-  fStandardList()
+  fOwnedComponents()
 {
   // see header file for class documentation
   // or
@@ -72,7 +66,7 @@ AliHLTComponentHandler::AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv)
   fScheduleList(),
   fLibraryList(),
   fEnvironment(),
-  fStandardList()
+  fOwnedComponents()
 {
   // see header file for class documentation
   if (pEnv) {
@@ -84,8 +78,15 @@ AliHLTComponentHandler::AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv)
       // for redirection
       AliHLTLogging::Init(pEnv->fLoggingFunc);
     }
-  }  else
+  }  else {
     memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
+  }
+  //#ifndef __DEBUG
+  //SetLocalLoggingLevel(kHLTLogError);
+  //#else
+  //SetLocalLoggingLevel(kHLTLogInfo);
+  //#endif
+
   AddStandardComponents();
 }
 
@@ -114,6 +115,16 @@ int AliHLTComponentHandler::AnnounceVersion()
   return iResult;
 }
 
+Int_t AliHLTComponentHandler::AddComponent(AliHLTComponent* pSample)
+{
+  // see header file for class documentation
+  Int_t iResult=0;
+  if ((iResult=RegisterComponent(pSample))>=0) {
+    fOwnedComponents.push_back(pSample);
+  }
+  return iResult;
+}
+
 Int_t AliHLTComponentHandler::RegisterComponent(AliHLTComponent* pSample)
 {
   // see header file for class documentation
@@ -242,6 +253,21 @@ void AliHLTComponentHandler::List()
   }
 }
 
+int AliHLTComponentHandler::HasOutputData( const char* componentID)
+{
+  // see header file for class documentation
+  int iResult=0;
+  AliHLTComponent* pSample=FindComponent(componentID);
+  if (pSample) {
+    AliHLTComponent::TComponentType ct=AliHLTComponent::kUnknown;
+    ct=pSample->GetComponentType();
+    iResult=(ct==AliHLTComponent::kSource || ct==AliHLTComponent::kProcessor);
+  } else {
+    iResult=-ENOENT;
+  }
+  return iResult;
+}
+
 void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv) 
 {
   // see header file for class documentation
@@ -257,22 +283,34 @@ void AliHLTComponentHandler::SetEnvironment(AliHLTComponentEnvironment* pEnv)
   }
 }
 
-int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
+int AliHLTComponentHandler::LoadLibrary( const char* libraryPath, int bActivateAgents)
 {
   // see header file for class documentation
   int iResult=0;
   if (libraryPath) {
+    // first activate all agents which are already loaded
+    if (bActivateAgents) ActivateAgents();
+
+    // set the global component handler for static component registration
     AliHLTComponent::SetGlobalComponentHandler(this);
+
     AliHLTLibHandle hLib;
     const char* loadtype="";
 #ifdef HAVE_DLFCN_H
     // use interface to the dynamic linking loader
-    hLib.fHandle=dlopen(libraryPath, RTLD_NOW);
-    loadtype="dlopen";
+    try {
+      hLib.fHandle=dlopen(libraryPath, RTLD_NOW);
+      loadtype="dlopen";
+    }
+    catch (...) {
+      // error message printed further down
+      loadtype="dlopen exeption";
+    }
 #else
     // use ROOT dynamic loader
     // check if the library was already loaded, as Load returns
     // 'failure' if the library was already loaded
+    try {
     AliHLTLibHandle* pLib=FindLibrary(libraryPath);
     if (pLib) {
        int* pRootHandle=reinterpret_cast<int*>(pLib->fHandle);
@@ -288,6 +326,11 @@ int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
       //HLTDebug("library %s loaded via gSystem", libraryPath);
     }
     loadtype="gSystem";
+    }
+    catch (...) {
+      // error message printed further down
+      loadtype="gSystem exeption";
+    }
 #endif //HAVE_DLFCN_H
     if (hLib.fHandle!=NULL) {
       // create TString object to store library path and use pointer as handle 
@@ -306,9 +349,12 @@ int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
       } else {
        HLTInfo("no build info available (possible AliRoot embedded build)");
       }
+
+      // static registration of components when library is loaded
       iResult=RegisterScheduledComponents();
+
     } else {
-      HLTError("can not load library %s", libraryPath);
+      HLTError("can not load library %s (%s)", libraryPath, loadtype);
 #ifdef HAVE_DLFCN_H
       HLTError("dlopen error: %s", dlerror());
 #endif //HAVE_DLFCN_H
@@ -319,6 +365,13 @@ int AliHLTComponentHandler::LoadLibrary( const char* libraryPath )
 #endif
     }
     AliHLTComponent::UnsetGlobalComponentHandler();
+    
+    if (iResult>=0) {
+      // alternative dynamic registration by library agents
+      // !!! has to be done after UnsetGlobalComponentHandler
+      if (bActivateAgents) ActivateAgents();
+    }
+
   } else {
     iResult=-EINVAL;
   }
@@ -353,7 +406,12 @@ int AliHLTComponentHandler::UnloadLibrary(AliHLTComponentHandler::AliHLTLibHandl
   fgAliLoggingFunc=NULL;
   TString* pName=reinterpret_cast<TString*>(handle.fName);
 #ifdef HAVE_DLFCN_H
-  dlclose(handle.fHandle);
+  try {
+    dlclose(handle.fHandle);
+  }
+  catch (...) {
+    HLTError("exeption caught during dlclose of library %s", pName!=NULL?pName->Data():"");
+  }
 #else
   int* pCount=reinterpret_cast<int*>(handle.fHandle);
   if (--(*pCount)==0) {
@@ -444,10 +502,6 @@ int AliHLTComponentHandler::AddStandardComponents()
   // see header file for class documentation
   int iResult=0;
   AliHLTComponent::SetGlobalComponentHandler(this);
-//   fStandardList.push_back(new AliHLTFilePublisher);
-//   fStandardList.push_back(new AliHLTFileWriter);
-//   fStandardList.push_back(new AliHLTRootFilePublisherComponent);
-//   fStandardList.push_back(new AliHLTRootFileWriterComponent);
   AliHLTComponent::UnsetGlobalComponentHandler();
   iResult=RegisterScheduledComponents();
   return iResult;
@@ -468,16 +522,40 @@ int AliHLTComponentHandler::RegisterScheduledComponents()
   return iResult;
 }
 
+int AliHLTComponentHandler::ActivateAgents(const AliHLTModuleAgent** blackList, int size)
+{
+  // see header file for class documentation
+  int iResult=0;
+  AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
+  while (pAgent && iResult>=0) {
+    if (blackList) {
+      int i=0;
+      for (; i<size; i++) {
+       if (blackList[i]==pAgent) break;
+      }
+      if (i<size) {
+       // this agent was in the list
+       pAgent=AliHLTModuleAgent::GetNextAgent();
+       continue;
+      }
+    }
+
+    pAgent->ActivateComponentHandler(this);
+    pAgent=AliHLTModuleAgent::GetNextAgent();
+  }
+  return iResult;
+}
+
 int AliHLTComponentHandler::DeleteStandardComponents()
 {
   // see header file for class documentation
   int iResult=0;
-  vector<AliHLTComponent*>::iterator element=fStandardList.begin();
-  while (element!=fStandardList.end()) {
+  vector<AliHLTComponent*>::iterator element=fOwnedComponents.begin();
+  while (element!=fOwnedComponents.end()) {
     //DeregisterComponent((*element)->GetComponentID());
     delete(*element);
-    fStandardList.erase(element);
-    element=fStandardList.begin();
+    fOwnedComponents.erase(element);
+    element=fOwnedComponents.begin();
   }
   return iResult;
 }
index d75a7e974401762d9e5a93b13c159df689b4284b..01d54ee50587a9b98ceaf8ddebbceab19c613557 100644 (file)
@@ -26,6 +26,7 @@
 #include "AliHLTLogging.h"
 
 class AliHLTComponent;
+class AliHLTModuleAgent;
 struct AliHLTComponentEnvironment;
 struct AliHLTComponentDataType;
 
@@ -62,10 +63,11 @@ class AliHLTComponentHandler : public AliHLTLogging {
    * handler. The object has to be valid during the whole runtime and should
    * thus be a global object which is ONLY used for the purpose of registration.
    * This also ensures automatically registration at library load time.
-   * @param libraryPath  const char string containing the library name/path
+   * @param libraryPath      const char string containing the library name/path
+   * @param bActivateAgents  activate agents after loading (@ref ActivateAgents)
    * @return 0 if succeeded, neg. error code if failed
    */
-  int LoadLibrary( const char* libraryPath );
+  int LoadLibrary( const char* libraryPath, int bActivateAgents=1 );
 
   /**
    * Find a symbol in a dynamically loaded library.
@@ -98,10 +100,19 @@ class AliHLTComponentHandler : public AliHLTLogging {
    * Registration is done by passing a sample object of the component to the
    * handler. The object has to be valid during the whole runtime and should
    * thus be a global object which is ONLY used for the purpose of registration.
-   * @param pSample  a sample object of the component
+   * @param pSample   a sample object of the component
    * @return neg. error code if failed
    */
-  int RegisterComponent(AliHLTComponent* pSample );
+  int RegisterComponent(AliHLTComponent* pSample);
+
+  /**
+   * Add a component and leave control of the sample object to the handler.
+   * Exactly the same functionality as @ref RegisterComponent but deletes
+   * the sample object at clean-up of the handler.
+   * @param pSample   a sample object of the component
+   * @return neg. error code if failed
+   */
+  int AddComponent(AliHLTComponent* pSample);
 
   /**
    * Registers all scheduled components.
@@ -171,6 +182,15 @@ class AliHLTComponentHandler : public AliHLTLogging {
     return CreateComponent( componentID, pEnvParam, 0, NULL, component );
     }
 
+  /**
+   * Check if a registered component has output data, e.g. is of type
+   * kSource or kProcessor (see @ref AliHLTComponent::TComponentType).
+   * @param componentID  ID of the component to create
+   * @return 1 if component has output data, 0 if not                 <br>
+   *         -ENOENT     if component does not exist
+   */
+  int HasOutputData( const char* componentID);
+
   /**
    * Print registered components to stdout.
    * @return none
@@ -182,6 +202,13 @@ class AliHLTComponentHandler : public AliHLTLogging {
    */
   int AnnounceVersion();
 
+  /**
+   * Find a component.
+   * @param componentID  ID of the component to find
+   * @return index, neg. error code if failed
+   */
+  int FindComponentIndex(const char* componentID);
+
  protected:
 
  private:
@@ -190,13 +217,6 @@ class AliHLTComponentHandler : public AliHLTLogging {
   /** assignment operator prohibited */
   AliHLTComponentHandler& operator=(const AliHLTComponentHandler&);
 
-  /**
-   * Find a component.
-   * @param componentID  ID of the component to find
-   * @return index, neg. error code if failed
-   */
-  int FindComponentIndex(const char* componentID);
-
   /**
    * Find a component.
    * @param componentID  ID of the component to find
@@ -218,7 +238,18 @@ class AliHLTComponentHandler : public AliHLTLogging {
   int UnloadLibraries();
 
   /**
-   * Compount descriptor for component libraries
+   * Activate all module agents with this component handler.
+   * The function loops over all available module agents and activates
+   * each agent with this component handler. During activation, the
+   * dynamic component registration is carried out by the agents version
+   * of @ref AliHLTModuleAgent::RegisterComponents
+   * @param blackList     array of agents which should be excluded
+   * @param size          array size
+   */
+  int ActivateAgents(const AliHLTModuleAgent** blackList=NULL, int size=0);
+
+  /**
+   * Compound descriptor for component libraries
    */
   struct AliHLTLibHandle {
     AliHLTLibHandle() : fHandle(NULL), fName(NULL) {}
@@ -252,8 +283,8 @@ class AliHLTComponentHandler : public AliHLTLogging {
   vector<AliHLTLibHandle> fLibraryList;                            // see above 
   /** running environment for the component */
   AliHLTComponentEnvironment fEnvironment;                         // see above 
-  /** list of standard components */
-  vector<AliHLTComponent*> fStandardList;                          // see above 
+  /** list of owned components, deleted at termination of the handler */
+  vector<AliHLTComponent*> fOwnedComponents;                       // see above 
 
   ClassDef(AliHLTComponentHandler, 0);
 
index f8d284e9efe8ce1abbb1947ae19397bf08565f44..086de37c2ded7bc151a68f807ea4ea640324c341 100644 (file)
@@ -30,7 +30,8 @@ ClassImp(AliHLTModuleAgent)
 
 AliHLTModuleAgent::AliHLTModuleAgent()
   :
-  fpNext(NULL)
+  fpNext(NULL),
+  fpComponentHandler(NULL)
 {
   // see header file for class documentation
   // or
@@ -97,8 +98,31 @@ const char* AliHLTModuleAgent::GetRequiredComponentLibraries() const
   return NULL;
 }
 
-int AliHLTModuleAgent::RegisterComponents(AliRawReader* /*rawReader*/,
-                                         AliRunLoader* /*runloader*/) const
+int AliHLTModuleAgent::ActivateComponentHandler(AliHLTComponentHandler* pHandler)
+{
+  int iResult=0;
+  if (pHandler==NULL) {
+    if (fpComponentHandler!=NULL) {
+      // reset and think about deregistration
+      fpComponentHandler=NULL;
+      HLTWarning("deregistration of components not yet implemented");
+    }
+    return 0;
+  }
+  if (fpComponentHandler!=NULL) {
+    if (pHandler!=fpComponentHandler) {
+      HLTError("only one component handler can be activated per agent");
+      return -EINVAL;
+    }
+    return 0;
+  }
+  if ((iResult=RegisterComponents(pHandler))>=0) {
+    fpComponentHandler=pHandler;
+  }
+  return iResult;
+}
+
+int AliHLTModuleAgent::RegisterComponents(AliHLTComponentHandler* /*pHandler*/) const
 {
   // default method, nothing to be done, child classes can overload
   return 0;
index d9dda5b6771d14205a9c7cea2a5a497cb7c42306..25bfa088d2b6914eb993d9fbb6b610862387746f 100644 (file)
@@ -25,6 +25,7 @@
 #include "AliHLTLogging.h"
 #include "AliHLTConfiguration.h"
 #include "AliHLTConfigurationHandler.h"
+#include "AliHLTComponentHandler.h"
 
 class AliRunLoader;
 class AliRawReader;
@@ -117,6 +118,18 @@ class AliHLTModuleAgent : public TObject, public AliHLTLogging {
    */
   static AliHLTModuleAgent* GetNextAgent();
 
+  /**
+   * Activate a component handler for this agent.
+   * The @ref RegisterComponents method will be called in order to allow
+   * the agent to register components. Once activated, the function can
+   * be called repeatedly with the same handler and gently ignores the
+   * invocation. In the current stage of development, only one handler
+   * can be activated per agent. This is sufficient for the current
+   * operation, but can be extended.
+   * @param pHandler  [in] the component handler instance
+   */
+  int ActivateComponentHandler(AliHLTComponentHandler* pHandler);
+
   /**
    * Register all configurations belonging to this module with the
    * AliHLTConfigurationHandler. The agent can adapt the configurations
@@ -158,15 +171,18 @@ class AliHLTModuleAgent : public TObject, public AliHLTLogging {
   virtual const char* GetRequiredComponentLibraries() const;
 
   /**
-   * Register componets.
+   * Register components.
    * This method can be used to register components for the module instead
-   * of the 'static object approach'. Registration is don by passing a
-   * sample object to @ref AliHLTComponentHandler::RegisterComponent<br>
-   * \em Note: The sample object is owned by the agent, make sure to delete
-   * it.
+   * of the 'static object approach'. Registration is done by passing a
+   * sample object to the AliHLTComponentHandler via
+   * - @ref AliHLTComponentHandler::RegisterComponent                      <br>
+   *        The sample object is owned by the agent, make sure to delete it.
+   * - @ref AliHLTComponentHandler::AddComponent                           <br>
+   *        Same functionality but handler deletes the object at the end.
+   *
+   * @param pHandler  [in] instance of the component handler          
    */
-  virtual int RegisterComponents(AliRawReader* rawReader=NULL,
-                                AliRunLoader* runloader=NULL) const;
+  virtual int RegisterComponents(AliHLTComponentHandler* pHandler) const;
 
   /**
    * Old method kept for backward compatibility, redirected to @ref
@@ -208,7 +224,10 @@ class AliHLTModuleAgent : public TObject, public AliHLTLogging {
   /** number of agents */
   static int fCount;                                               //! transient
 
-  ClassDef(AliHLTModuleAgent, 1);
+  /* instance of the active component handler */
+  AliHLTComponentHandler* fpComponentHandler;                      //! transient
+
+  ClassDef(AliHLTModuleAgent, 2);
 };
 
 #endif
index aa7aed257fd0784eea3616b63549fce3f68ac184..823e502a02f65a07c7b8a372207a44ba70e3928a 100644 (file)
@@ -26,6 +26,7 @@
 using namespace std;
 #endif
 
+#include <cassert>
 #include "AliHLTStdIncludes.h"
 #include "AliHLTSystem.h"
 #include "AliHLTComponentHandler.h"
@@ -84,7 +85,7 @@ AliHLTSystem::AliHLTSystem()
     AliHLTComponentLogSeverity loglevel=fpComponentHandler->GetLocalLoggingLevel();
     fpComponentHandler->SetLocalLoggingLevel(kHLTLogError);
     fpComponentHandler->SetEnvironment(&env);
-    fpComponentHandler->LoadLibrary("libAliHLTUtil.so");
+    fpComponentHandler->LoadLibrary("libAliHLTUtil.so", 0/* do not activate agents */);
     fgAliLoggingFunc=(AliHLTLogging::AliHLTDynamicMessage)fpComponentHandler->FindSymbol("libAliHLTUtil.so", "AliDynamicMessage");
     fpComponentHandler->SetLocalLoggingLevel(loglevel);
     if (fgAliLoggingFunc==NULL) {
@@ -303,7 +304,7 @@ AliHLTTask* AliHLTSystem::FindTask(const char* id)
   // see header file for class documentation
   AliHLTTask* pTask=NULL;
   if (id) {
-    pTask=(AliHLTTask*)fTaskList.FindObject(id); 
+    pTask=dynamic_cast<AliHLTTask*>(fTaskList.FindObject(id)); 
   }
   return pTask;
 }
@@ -359,7 +360,7 @@ int AliHLTSystem::Run(Int_t iNofEvents, int bStop)
   }
   if (iResult>=0) {
     iResult=iCount;
-  } else  if (iResult==-ENOENT) {
+  } else  if (iResult==-ENOKEY) {
     iResult=0; // do not propagate the error
   }
   ClearStatusFlags(kRunning);
@@ -374,7 +375,7 @@ int AliHLTSystem::InitTasks()
 
   if (lnk==NULL) {
     HLTWarning("Task list is empty, aborting ...");
-    return -ENOENT;
+    return -ENOKEY;
   }
   while (lnk && iResult>=0) {
     TObject* obj=lnk->GetObject();
@@ -604,13 +605,15 @@ int AliHLTSystem::Reconstruct(int nofEvents, AliRunLoader* runLoader,
     if (CheckStatus(kReady)) {
       if (nofEvents==0) {
        // special case to close the reconstruction
+       if (!CheckStatus(kError)) {
        StopTasks();
        DeinitTasks();
+       }
       } else {
       if ((iResult=AliHLTOfflineInterface::SetParamsToComponents(runLoader, rawReader))>=0) {
        // the system always remains started after event processing, a specific
-       // call with nofEvents==0 is neede to execute the stop sequence
-       iResult=Run(nofEvents, 0);
+       // call with nofEvents==0 is needed to execute the stop sequence
+       if ((iResult=Run(nofEvents, 0))<0) SetStatusFlags(kError);
       }
       }
     } else {
@@ -672,7 +675,7 @@ int AliHLTSystem::LoadComponentLibraries(const char* libraries)
 int AliHLTSystem::Configure(AliRunLoader* runloader)
 {
   // see header file for class documentation
-  Configure(NULL, runloader);
+  return Configure(NULL, runloader);
 }
 
 int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
@@ -698,7 +701,7 @@ int AliHLTSystem::Configure(AliRawReader* rawReader, AliRunLoader* runloader)
     SetStatusFlags(kConfigurationLoaded);
     if (CheckFilter(kHLTLogDebug))
       fpConfigurationHandler->PrintConfigurations();
-    iResult=BuildTaskListsFromTopConfigurations(rawReader, runloader);
+    iResult=BuildTaskListsFromReconstructionChains(rawReader, runloader);
     if (iResult>=0) {
       SetStatusFlags(kTaskListCreated);
     }
@@ -812,7 +815,7 @@ int AliHLTSystem::LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runl
   return iResult;
 }
 
-int AliHLTSystem::BuildTaskListsFromTopConfigurations(AliRawReader* rawReader, AliRunLoader* runloader)
+int AliHLTSystem::BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, AliRunLoader* runloader)
 {
   // see header file for class documentation
   if (CheckStatus(kRunning)) {
@@ -825,36 +828,72 @@ int AliHLTSystem::BuildTaskListsFromTopConfigurations(AliRawReader* rawReader, A
   }
 
   int iResult=0;
-  AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
-  while ((pAgent || fChains.Length()>0) && iResult>=0) {
-    TString tops;
-    if (fChains.Length()>0) {
-      tops=fChains;
-      HLTInfo("custom local reconstruction configurations: %s", tops.Data());
-    } else {
-      tops=pAgent->GetReconstructionChains(rawReader, runloader);
-      HLTInfo("local reconstruction configurations for agent %s (%p): %s", pAgent->GetName(), pAgent, tops.Data());
+  int bHaveOutput=0;
+
+  // query chains
+  TString chains;
+  if (fChains.Length()>0) {
+    chains=fChains;
+    HLTInfo("custom reconstruction chain: %s", chains.Data());
+  } else {
+    AliHLTModuleAgent* pAgent=AliHLTModuleAgent::GetFirstAgent();
+    while ((pAgent || fChains.Length()>0) && iResult>=0) {
+      const char* agentchains=pAgent->GetReconstructionChains(rawReader, runloader);
+      if (agentchains) {
+       if (!chains.IsNull()) chains+="";
+       chains+=agentchains;
+       HLTInfo("reconstruction chains for agent %s (%p): %s", pAgent->GetName(), pAgent, agentchains);
+      }
+      pAgent=AliHLTModuleAgent::GetNextAgent();
     }
-    TObjArray* pTokens=tops.Tokenize(" ");
-    if (pTokens) {
-      int iEntries=pTokens->GetEntries();
-      for (int i=0; i<iEntries && iResult>=0; i++) {
-       const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
-       AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
-       if (pConf) {
-         iResult=BuildTaskList(pConf);
-       } else {
-         HLTWarning("can not find top configuration %s", pCID);
+  }
+
+  // build task list for chains
+  TObjArray* pTokens=chains.Tokenize(" ");
+  if (pTokens) {
+    int iEntries=pTokens->GetEntries();
+    for (int i=0; i<iEntries && iResult>=0; i++) {
+      const char* pCID=((TObjString*)pTokens->At(i))->GetString().Data();
+      AliHLTConfiguration* pConf=fpConfigurationHandler->FindConfiguration(pCID);
+      if (pConf) {
+       iResult=BuildTaskList(pConf);
+       if (runloader) {
+         assert(fpComponentHandler!=NULL);
+         TString cid=pConf->GetComponentID();
+         if (cid.CompareTo("HLTOUT")==0) {
+           // remove from the input of a global HLTOUT configuration
+           chains.ReplaceAll(pCID, "");
+         } else if (bHaveOutput==0) {
+           // check whether this configuration produces data output
+           if ((bHaveOutput=fpComponentHandler->HasOutputData(cid.Data()))<0) {
+             bHaveOutput=0;
+             chains.ReplaceAll(pCID, "");
+           }
+         }
        }
+      } else {
+       HLTWarning("can not find configuration %s", pCID);
       }
-      delete pTokens;
     }
-    
-    if (fChains.Length()>0) {
-      break; // ignore the agents
+    delete pTokens;
+  }
+
+  // build HLTOUT for simulation
+  if (iResult>=0 && runloader) {
+    if (bHaveOutput) {
+      // there are components in the chain which produce data which need to be
+      // piped to an HLTOUT
+      if (fpComponentHandler->FindComponentIndex("HLTOUT")>=0 ||
+         LoadComponentLibraries("libHLTsim.so")>=0) {
+       AliHLTConfiguration globalout("_globalout_", "HLTOUT", chains.Data(), NULL);
+       iResult=BuildTaskList("_globalout_");
+      } else {
+       HLTError("can not load libHLTsim.so and HLTOUT component");
+       iResult=-EFAULT;
+      }
     }
-    pAgent=AliHLTModuleAgent::GetNextAgent();
   }
+
   if (iResult>=0) SetStatusFlags(kTaskListCreated);
 
   return iResult;
index ab6a686bdde9fdd3ad114ff79da50110af584892..57319f2d7ccfcb5cf7b8343b2e164becb1630d3d 100644 (file)
@@ -332,8 +332,8 @@ class AliHLTSystem : public AliHLTLogging {
    * @param runloader    optional instance of the run loader
    * @return neg. error code if failed 
    */
-  int BuildTaskListsFromTopConfigurations(AliRawReader* rawReader, 
-                                         AliRunLoader* runloader=NULL);
+  int BuildTaskListsFromReconstructionChains(AliRawReader* rawReader, 
+                                            AliRunLoader* runloader=NULL);
 
   enum AliHLTSystemState_t {
     kUninitialized       = 0x0,
index 1949ccd7d9a872e74e5fac4776a9d8003180d32d..85ef9099fc1a0d5f9dfde7a714abb1b7af26673f 100644 (file)
     @brief  Agent of the libAliHLTUtil library
 */
 
+#include <cassert>
 #include "AliHLTAgentUtil.h"
 #include "AliHLTConfiguration.h"
 
+// header files of library components
+#include "AliHLTDataGenerator.h"
+#include "AliHLTRawReaderPublisherComponent.h"
+#include "AliHLTLoaderPublisherComponent.h"
+#include "AliHLTRootFileStreamerComponent.h"
+#include "AliHLTRootFileWriterComponent.h"
+#include "AliHLTRootFilePublisherComponent.h"
+#include "AliHLTFileWriter.h"
+#include "AliHLTFilePublisher.h"
+
 /** global instance for agent registration */
 AliHLTAgentUtil gAliHLTAgentUtil;
 
@@ -65,3 +76,19 @@ const char* AliHLTAgentUtil::GetRequiredComponentLibraries() const
   // see header file for class documentation
   return NULL;
 }
+
+int AliHLTAgentUtil::RegisterComponents(AliHLTComponentHandler* pHandler) const
+{
+  // see header file for class documentation
+  assert(pHandler);
+  if (!pHandler) return -EINVAL;
+  pHandler->AddComponent(new AliHLTDataGenerator);
+  pHandler->AddComponent(new AliHLTRawReaderPublisherComponent);
+  pHandler->AddComponent(new AliHLTLoaderPublisherComponent);
+  pHandler->AddComponent(new AliHLTRootFileStreamerComponent);
+  pHandler->AddComponent(new AliHLTRootFileWriterComponent);
+  pHandler->AddComponent(new AliHLTRootFilePublisherComponent);
+  pHandler->AddComponent(new AliHLTFileWriter);
+  pHandler->AddComponent(new AliHLTFilePublisher);
+  return 0;
+}
index b83a769da05dd0170603a6daa8d2b866f47d67e0..f75f9045eb19c8be0e81287b51c76bdb367d9e00 100644 (file)
@@ -61,6 +61,11 @@ class AliHLTAgentUtil : public AliHLTModuleAgent {
    */
   const char* GetRequiredComponentLibraries() const;
 
+  /**
+   * Register components for the AliHLTUtil library.
+   * @param pHandler  [in] instance of the component handler          
+   */
+  int RegisterComponents(AliHLTComponentHandler* pHandler) const;
  protected:
 
  private:
index 063ad5ffffe77df45f191a91b15c305ba87a97b8..cfcced7acecc1197c18af1afb0edca73a77eedf7 100644 (file)
@@ -34,9 +34,6 @@ using namespace std;
 #include "AliHLTDataGenerator.h"
 #include "TString.h"
 
-/** the global object for component registration */
-AliHLTDataGenerator gAliHLTDataGenerator;
-
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTDataGenerator)
 
index b2bfa4d3b282583825fbb294511da1c4dabbb8d2..38ae8e4e449fbaa901d8df00fe6dc5c59fd4f821 100644 (file)
@@ -31,8 +31,6 @@ using namespace std;
 #include <TMath.h>
 #include <TFile.h>
 
-/** the global object for component registration */
-AliHLTFilePublisher gAliHLTFilePublisher;
 
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTFilePublisher)
@@ -211,6 +209,7 @@ int AliHLTFilePublisher::DoInit( int argc, const char** argv )
 
 int AliHLTFilePublisher::InsertFile(EventFiles* &pCurrEvent, FileDesc* pDesc)
 {
+  // see header file for class documentation
   int iResult=0;
   if (pDesc) {
     if (pCurrEvent==NULL) {
@@ -232,6 +231,7 @@ int AliHLTFilePublisher::InsertFile(EventFiles* &pCurrEvent, FileDesc* pDesc)
 
 int AliHLTFilePublisher::InsertEvent(EventFiles* &pEvent)
 {
+  // see header file for class documentation
   int iResult=0;
   if (pEvent) {
     HLTDebug("Inserted event %p", pEvent);
@@ -303,6 +303,7 @@ int AliHLTFilePublisher::GetEvent( const AliHLTComponentEventData& /*evtData*/,
                                   AliHLTUInt32_t& size,
                                   vector<AliHLTComponentBlockData>& outputBlocks )
 {
+  // see header file for class documentation
   int iResult=0;
   TObjLink *lnk=fpCurrent;
   if (lnk==NULL) lnk=fEvents.FirstLink();
@@ -379,15 +380,22 @@ AliHLTFilePublisher::FileDesc::FileDesc(const char* name, AliHLTComponentDataTyp
   fDataType(dt),
   fSpecification(spec)
 {
+  // see header file for class documentation
+  // or
+  // refer to README to build package
+  // or
+  // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
 }
 
 AliHLTFilePublisher::FileDesc::~FileDesc()
 {
+  // see header file for class documentation
   CloseFile();
 }
 
 void AliHLTFilePublisher::FileDesc::CloseFile()
 {
+  // see header file for class documentation
   if (fpInstance)
   {
     // Unfortunately had to use AliLog mechanisms rather that AliHLTLogging because
@@ -405,6 +413,7 @@ void AliHLTFilePublisher::FileDesc::CloseFile()
 
 int AliHLTFilePublisher::FileDesc::OpenFile()
 {
+  // see header file for class documentation
   int iResult=0;
   TString fullFN= fName + "?filetype=raw";
   fpInstance = new TFile(fullFN);
index 5871f55790a88f568a1fb014edcb10a2341a39df..ca75880f72f5def45697ff691cd4e3607751699f 100644 (file)
@@ -32,9 +32,6 @@ using namespace std;
 //#include <TMath.h>
 //#include <TFile.h>
 
-/** the global object for component registration */
-AliHLTFileWriter gAliHLTFileWriter;
-
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTFileWriter)
 
index 8b1da04b8218596b714dc0298662cabf28f2d929..a61a66fd4c2c250305bc36ed3d2269c987db88c9 100644 (file)
@@ -34,9 +34,6 @@
 #include "AliLog.h"
 #include "TTree.h"
 
-/** global instance for agent registration */
-AliHLTLoaderPublisherComponent gAliHLTLoaderPublisherComponent;
-
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTLoaderPublisherComponent)
 
@@ -70,11 +67,13 @@ const char* AliHLTLoaderPublisherComponent::GetComponentID()
 
 AliHLTComponentDataType AliHLTLoaderPublisherComponent::GetOutputDataType()
 {
+  // see header file for class documentation
   return fDataType;
 }
 
 void AliHLTLoaderPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
 {
+  // see header file for class documentation
   constBase=fMaxSize;
   inputMultiplier=1;
 }
@@ -221,6 +220,7 @@ int AliHLTLoaderPublisherComponent::GetEvent(const AliHLTComponentEventData& /*e
 
 TTree* AliHLTLoaderPublisherComponent::GetTree()
 {
+  // see header file for class documentation
   TTree* pTree=NULL;
   if (fpLoader) {
     if (fTreeType.CompareTo("digits")==0)
index 01e26e67c1af8cc2fa1e8e36d3fd1c8491f5115f..53d9860050e55e89fc377414669b1ae5f69d419f 100644 (file)
@@ -34,9 +34,6 @@
 #include <cerrno>
 #include <cassert>
 
-/** global instance for agent registration */
-AliHLTRawReaderPublisherComponent gAliHLTRawReaderPublisherComponent;
-
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTRawReaderPublisherComponent)
 
@@ -70,11 +67,13 @@ const char* AliHLTRawReaderPublisherComponent::GetComponentID()
 
 AliHLTComponentDataType AliHLTRawReaderPublisherComponent::GetOutputDataType()
 {
+  // see header file for class documentation
   return fDataType;
 }
 
 void AliHLTRawReaderPublisherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
 {
+  // see header file for class documentation
   constBase=fMaxSize;
   inputMultiplier=1;
 }
@@ -266,5 +265,6 @@ int AliHLTRawReaderPublisherComponent::GetEvent(const AliHLTComponentEventData&
 }
 
 int AliHLTRawReaderPublisherComponent::GetSpecificationFromEquipmentId(int id, AliHLTUInt32_t& specification) const {
+  // see header file for class documentation
   return specification=id;
 }
index 7d15fc44d9e6e2772d47c3f75350d412a46053d9..9cf757c05ebd39c0a91346f692e14cf82ac0e360 100644 (file)
@@ -29,9 +29,6 @@
 // temporary
 #include "TH1F.h"
 
-/** the global object for component registration */
-AliHLTRootFilePublisherComponent gAliHLTRootFilePublisherComponent;
-
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTRootFilePublisherComponent)
 
@@ -109,6 +106,7 @@ int AliHLTRootFilePublisherComponent::GetEvent( const AliHLTComponentEventData&
                                                AliHLTUInt32_t& /*size*/,
                                                vector<AliHLTComponentBlockData>& /*outputBlocks*/ )
 {
+  // see header file for class documentation
   int iResult=0;
   if (GetEventCount()%2==0) {
     TH1F *hpx = new TH1F("hpx","px distribution",100,-4,4);
index 09b1551cdc9331604e69794928d784bd9b9a30d6..165e6862fdbb8ec34bb5db2314d9a06a6aada70b 100644 (file)
@@ -26,9 +26,6 @@
 #include "AliHLTRootFileStreamerComponent.h"
 #include "TString.h"
 
-/** the global object for component registration */
-AliHLTRootFileStreamerComponent gAliHLTRootFileStreamerComponent;
-
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTRootFileStreamerComponent)
 
index 38d6dfd0f205f325bb384f5e9b76e70e1e970a4c..f0076ec526ecf308515d64dfe7a2583c28275914 100644 (file)
@@ -27,9 +27,6 @@
 #include "TFile.h"
 #include "TString.h"
 
-/** the global object for component registration */
-AliHLTRootFileWriterComponent gAliHLTRootFileWriterComponent;
-
 /** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTRootFileWriterComponent)
 
index 5888f3ba2317a52813f3c6aec1541bfc88e712ee..7f54e5e9f27b106e2b5bfec930fb4b10f6cdbf8c 100644 (file)
@@ -1,3 +1,9 @@
+2007-10-16
+       - implemented component registration via agents
+       - added HLTOUT component as default data sink for simulation
+       - added AliHLTAgentSim for libHLTsim.so
+       - AliHLTComponentHandler: more robust library handling
+       
 2007-08-17 version HLT-v0-7 tagged
        - corresponds to AliRoot v4-06-Rev-00
        - calibration framework
index 3f9b041d7cdcf94d494919e2f399624ff84ea3f3..c0a10578c8ad6eeed3aaf69f74ae838e5ddea86d 100644 (file)
     @brief  Agent of the libAliHLTSample library
 */
 
+#include <cassert>
 #include "AliHLTAgentSample.h"
 #include "AliHLTConfiguration.h"
 #include "TSystem.h"
 
+// header files of library components
+#include "AliHLTDummyComponent.h"
+
 /** global instance for agent registration */
 AliHLTAgentSample gAliHLTAgentSample;
 
@@ -104,3 +108,12 @@ const char* AliHLTAgentSample::GetRequiredComponentLibraries() const
   // see header file for class documentation
   return "libAliHLTUtil.so libAliHLTSample.so";
 }
+
+int AliHLTAgentSample::RegisterComponents(AliHLTComponentHandler* pHandler) const
+{
+  // see header file for class documentation
+  assert(pHandler);
+  if (!pHandler) return -EINVAL;
+  pHandler->AddComponent(new AliHLTDummyComponent);
+  return 0;
+}
index 382620cbdd6163d5f763dcdaaaaa0fb603155887..eafd2adc653a222df1ce9d54ee6e96434cdd48fb 100644 (file)
@@ -94,6 +94,11 @@ class AliHLTAgentSample : public AliHLTModuleAgent {
    */
   const char* GetRequiredComponentLibraries() const;
 
+  /**
+   * Register components for the AliHLTSample library.
+   * @param pHandler  [in] instance of the component handler          
+   */
+  int RegisterComponents(AliHLTComponentHandler* pHandler) const;
  protected:
 
  private:
index 41dbf709e9acaf096c6750caf9ad5b5f50aa5b01..f663dded0fe9bdc060253112b44ccec32b0de6d5 100644 (file)
@@ -29,12 +29,10 @@ using namespace std;
 #include "AliHLTSystem.h"
 #include "AliHLTDummyComponent.h"
 #include "AliHLTDefinitions.h"
-#include <stdlib.h>
-#include <errno.h>
-
-// this is a global object used for automatic component registration, do not use this
-AliHLTDummyComponent gAliHLTDummyComponent;
+#include <cstdlib>
+#include <cerrno>
 
+/** ROOT macro for the implementation of ROOT specific class methods */
 ClassImp(AliHLTDummyComponent)
     
 AliHLTDummyComponent::AliHLTDummyComponent()
index ce2c7cdb628dac69321e3beebf9e397dc13017bc..d0d2e4dc96975a4d6d1b14ba0770b4ea5f55594a 100644 (file)
@@ -109,3 +109,8 @@ const char* AliHLTTPCAgent::GetRequiredComponentLibraries() const
   // see header file for class documentation
   return NULL;
 }
+
+int AliHLTTPCAgent::RegisterComponents(AliHLTComponentHandler* pHandler) const
+{
+  return 0;
+}
index 02b370d7684f68fef2ade6181e68b19e8f3b6607..98e134cd35f94e1fcd7b15e1870423dfba1ce50c 100644 (file)
@@ -62,6 +62,11 @@ class AliHLTTPCAgent : public AliHLTModuleAgent {
    */
   const char* GetRequiredComponentLibraries() const;
 
+  /**
+   * Register components for the AliHLTTPC library.
+   * @param pHandler  [in] instance of the component handler          
+   */
+  int RegisterComponents(AliHLTComponentHandler* pHandler) const;
  protected:
 
  private:
index 7f0c6a3a3f922b9c0aad2ab3351cbfb54a767bac..85c78ffbf6c567d35dc6032257252493349e3e76 100644 (file)
@@ -5,7 +5,9 @@ include $(MODDIR)/hlt.conf
 
 LIBHLTSIM_VERSION := 0
 
-MODULE_SRCS=   AliHLTSimulation.cxx
+MODULE_SRCS=   AliHLTSimulation.cxx \
+               AliHLTAgentSim.cxx \
+               AliHLTOUTComponent.cxx
 
 CLASS_HDRS:=   $(MODULE_SRCS:.cxx=.h)