]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTComponentHandler.h
Cluster indices are published via AliKalmanTrack::GetClusterIndex()
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponentHandler.h
index 3ee115d89ca3be29427999b9e9894ef53a03e950..7cc7722ef9a2823a9b7b4aaa1941b9ac72a28da3 100644 (file)
@@ -26,7 +26,8 @@
 #include "AliHLTLogging.h"
 
 class AliHLTComponent;
-struct AliHLTComponentEnvironment;
+class AliHLTModuleAgent;
+struct AliHLTAnalysisEnvironment;
 struct AliHLTComponentDataType;
 
 /**
@@ -40,23 +41,52 @@ class AliHLTComponentHandler : public AliHLTLogging {
   /** standard constructor */
   AliHLTComponentHandler();
   /** constructor */
-  AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv);
-  /** not a valid copy constructor, defined according to effective C++ style */
-  AliHLTComponentHandler(const AliHLTComponentHandler&);
-  /** not a valid assignment op, but defined according to effective C++ style */
-  AliHLTComponentHandler& operator=(const AliHLTComponentHandler&);
+  AliHLTComponentHandler(AliHLTAnalysisEnvironment* pEnv);
   /** destructor */
   virtual ~AliHLTComponentHandler();
 
+  /**
+   * Create an instance from the global sigleton.
+   * Instance has to be destroyed by the Destroy function
+   */
+  static AliHLTComponentHandler* CreateHandler();
+
+  /**
+   * Destroy an instance of the global singleton retrieved by
+   * AliHLTComponentHandler::CreateHandler()
+   */
+  int Destroy();
+
+  /**
+   * Library mode.
+   * - kDynamic: library can be unloaded (unload forced at termination of the
+   *             handler
+   * - kStatic:  library persistent, once loaded it stays
+   */
+  enum TLibraryMode {kDynamic, kStatic};
+
   /**
    * Set the environment for the HLT framework.
    * The environment mainly consists of function pointers for the integration
    * of the HLT framework into a system like the PubSub online system or
    * AliRoot offline system.
-   * @param pEnv    pointer to @ref AliHLTComponentEnvironment structure
+   * @param pEnv    pointer to @ref AliHLTAnalysisEnvironment structure
    * @return none
    */
-  void SetEnvironment(AliHLTComponentEnvironment* pEnv);
+  void SetEnvironment(AliHLTAnalysisEnvironment* pEnv);
+
+  /**
+   * Get the current environment.
+   */
+  const AliHLTAnalysisEnvironment* GetEnvironment() const {return &fEnvironment;}
+
+  /**
+   * Set library mode.
+   * The mode effects all loaded libraries until another mode is set.
+   * @param mode             persistent library or not
+   * @return previous mode
+   */
+  TLibraryMode SetLibraryMode(TLibraryMode mode);
 
   /**
    * Load a component shared library.
@@ -66,10 +96,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.
@@ -77,7 +108,7 @@ class AliHLTComponentHandler : public AliHLTLogging {
    * @param symbol       the symbol to find
    * @return void pointer to function
    */
-  void* FindSymbol(const char* library, const char* symbol);
+  void (*FindSymbol(const char* library, const char* symbol))();
 
   /**
    * Unload a component shared library.
@@ -102,10 +133,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.
@@ -128,7 +168,7 @@ class AliHLTComponentHandler : public AliHLTLogging {
 
   /**
    */
-  int DeleteStandardComponents();
+  int DeleteOwnedComponents();
 
   /**
    * Find the ID of a component with the given output data.
@@ -159,7 +199,14 @@ class AliHLTComponentHandler : public AliHLTLogging {
    * @return component pointer in component, neg. error code if failed
    */
   int CreateComponent( const char* componentID, void* pEnvParam, 
-                      int argc, const char** argv, AliHLTComponent*& component );
+                      int argc, const char** argv, AliHLTComponent*& component);
+
+  /**
+   * Create component without initializing it.
+   * @param componentID  ID of the component to create
+   * @param component    reference to receive the create component instance
+   */
+  int CreateComponent(const char* componentID, AliHLTComponent*& component );
 
   /**
    * Create a component of the given name (ID).
@@ -175,6 +222,27 @@ class AliHLTComponentHandler : public AliHLTLogging {
     return CreateComponent( componentID, pEnvParam, 0, NULL, component );
     }
 
+  /**
+   * Set the run description.
+   * The run description is set globally for all components. Each component
+   * is initialized from the global run description after creation and before
+   * call of AliHLTComponent::Init().
+   *
+   * @param desc    run descriptor, currently only the run no member is used
+   * @param runType originally, run type was supposed to be a number and part
+   *                of the run descriptor. But it was defined as string later
+   */
+  int SetRunDescription(const AliHLTRunDesc* desc, const char* runType);
+
+  /**
+   * 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
@@ -186,9 +254,6 @@ class AliHLTComponentHandler : public AliHLTLogging {
    */
   int AnnounceVersion();
 
- protected:
-
- private:
   /**
    * Find a component.
    * @param componentID  ID of the component to find
@@ -196,6 +261,14 @@ class AliHLTComponentHandler : public AliHLTLogging {
    */
   int FindComponentIndex(const char* componentID);
 
+ protected:
+
+ private:
+  /** copy constructor prohibited */
+  AliHLTComponentHandler(const AliHLTComponentHandler&);
+  /** assignment operator prohibited */
+  AliHLTComponentHandler& operator=(const AliHLTComponentHandler&);
+
   /**
    * Find a component.
    * @param componentID  ID of the component to find
@@ -217,14 +290,32 @@ 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
+   *
+   * Agents are identified by an id which is a string containing the
+   * module name. Libraries follow the naming scheme libAliHLT<MOD>.so
+   * If the library name is provided and the specific agent found in the
+   * list, only that one is activated. All pending agents otherwize.
+   * @param library       library to activate the agent for
+   * @param blackList     blank separated list of module ids
+   */
+  int ActivateAgents(const char* library=NULL, const char* blackList=NULL);
+
+  /**
+   * Compound descriptor for component libraries
    */
   struct AliHLTLibHandle {
-    AliHLTLibHandle() : fHandle(NULL), fName(NULL) {}
+    AliHLTLibHandle() : fHandle(NULL), fName(NULL), fMode(kDynamic) {}
     /** dlopen handle */
     void* fHandle;                                                 //! transient
     /** name of the library, casted to TString* before use */
     void* fName;                                                   //! transient
+    /** library mode: kStatic means never unloaded */
+    TLibraryMode fMode;                                            //! transient
   };
 
   /**
@@ -250,11 +341,23 @@ class AliHLTComponentHandler : public AliHLTLogging {
   /** list of libraries */
   vector<AliHLTLibHandle> fLibraryList;                            // see above 
   /** running environment for the component */
-  AliHLTComponentEnvironment fEnvironment;                         // see above 
-  /** list of standard components */
-  vector<AliHLTComponent*> fStandardList;                          // see above 
-
-  ClassDef(AliHLTComponentHandler, 0);
+  AliHLTAnalysisEnvironment fEnvironment;                         // see above 
+  /** list of owned components, deleted at termination of the handler */
+  vector<AliHLTComponent*> fOwnedComponents;                       // see above 
+  /** library mode effects all loaded libraries until a new mode is set */
+  TLibraryMode fLibraryMode;                                       // see above 
+
+  /** run descriptor */
+  AliHLTRunDesc fRunDesc;                                          //!transient 
+  /** run type string */
+  char* fRunType;                                                  //!transient 
+
+  /** the global singleton */
+  static AliHLTComponentHandler* fgpInstance;                      //!transient
+  /** number of used instances of the global singleton */
+  static int fgNofInstances;                                       //!transient 
+
+  ClassDef(AliHLTComponentHandler, 2);
 
 };
 #endif