]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLTTask.h
Corrected pragma: no need for newObj to access the target data members
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTTask.h
index 5fe52da19c7398e31625e068477dd93a4e56a3e3..23d19fe8645cca4ff64eb37c151a450c44c9d75c 100644 (file)
@@ -1,61 +1,94 @@
+//-*- Mode: C++ -*-
 // $Id$
 
 #ifndef ALIHLTTASK_H
 #define ALIHLTTASK_H
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
- * See cxx source for full Copyright notice                               */
+///* This file is property of and copyright by the                          * 
+///* ALICE Experiment at CERN, All rights reserved.                         *
+///* See cxx source for full Copyright notice                               *
 
-/** @file   AliHLTConfiguration.h
-    @author Matthias Richter
-    @date   
-    @brief  base class for HLT tasks
-*/
+/// @file   AliHLTTask.h
+/// @author Matthias Richter
+/// @date   
+/// @brief  base class for HLT tasks
+///
 
-#include <cerrno>
+#include <vector>
 #include <TObject.h>
 #include <TList.h>
 #include "AliHLTDataTypes.h"
 #include "AliHLTLogging.h"
 #include "AliHLTDataBuffer.h"
 
-struct AliHLTComponent_BlockData;
+using std::vector;
+
+struct AliHLTComponentBlockData;
 class AliHLTComponent;
 class AliHLTComponentHandler;
+class AliHLTConfiguration;
+class AliHLTTask;
+
+typedef vector<AliHLTTask*> AliHLTTaskPList;
 
 /******************************************************************************/
 
- /**
-  * @class AliHLTTask
-  * A task collects all the information which is necessary to process a certain
-  * step in the HLT data processing chain:
-  * - the instance of the component
-  * - the data buffer which receives the result of the component and provides
-  *   the data to other tasks/components
-  * - a list of all dependencies
-  * - a list of consumers
-  * - the task object holds the configuration object 
-  */
+/**
+ * @class AliHLTTask
+ * A task collects all the information which is necessary to process a certain
+ * step in the HLT data processing chain.
+ * - the instance of the component
+ *   the task object creates and deletes the component object
+ * - the data buffer which receives the result of the component and provides
+ *   the data to other tasks/components
+ * - a list of all dependencies
+ * - a list of consumers
+ * - the task object holds an external pointer to the configuration object; 
+ *   \b Note: the configuration object must exist through the existence of the
+ *   task object!!!
+ *  
+ *
+ * @note This class is only used for the @ref alihlt_system.
+ *
+ * @ingroup alihlt_system
+ */
 class AliHLTTask : public TObject, public AliHLTLogging {
  public:
   /** standard constructor */
   AliHLTTask();
   /** constructor 
       @param pConf pointer to configuration descriptor
-      @param pCH   the HLT component handler
    */
-  AliHLTTask(AliHLTConfiguration* pConf, AliHLTComponentHandler* pCH);
+  AliHLTTask(AliHLTConfiguration* pConf);
   /** destructor */
   virtual ~AliHLTTask();
 
   /**
    * Initialize the task.
    * The task is initialized with a configuration descriptor. It needs a
-   * component handler instance to create the analysis component.
-   * @param pConf pointer to configuration descriptor
+   * component handler instance to create the analysis component. The
+   * component is created and initialized.
+   * @param pConf pointer to configuration descriptor, can be NULL if it
+   *              was already provided to the constructor
    * @param pCH   the HLT component handler
    */
   int Init(AliHLTConfiguration* pConf, AliHLTComponentHandler* pCH);
 
+  /**
+   * Create the component.
+   * @param pConf    configuration descritption
+   * @param pCH      component handler
+   * @param pComponent [OUT] target to get the component instance
+   * @return component instance
+   */
+  virtual int CreateComponent(AliHLTConfiguration* pConf, AliHLTComponentHandler* pCH, AliHLTComponent*& pComponent) const;
+
+  /**
+   * De-Initialize the task.
+   * Final cleanup after the run. The @ref AliHLTComponent::Deinit method of
+   * the component is called. The analysis component is deleted.
+   */
+  int Deinit();
+
   /**
    * Get the name of the object.
    * This is an overridden TObject function in order to return the configuration
@@ -87,18 +120,6 @@ class AliHLTTask : public TObject, public AliHLTLogging {
    */
   AliHLTTask* FindDependency(const char* id);
 
-  /*
-   * insert block data to the list
-   * the data has to come from a task the current one depends on
-   * result:
-   *    -EEXIST : the block data from this task has already been inserted
-   *    -ENOENT : no dependencies to the task the data is coming from
-   */
-  /*
-   * this function is most likely depricated
-  int InsertBlockData(AliHLTComponent_BlockData* pBlock, AliHLTTask* pSource);
-  */
-
   /**
    * Add a dependency for the task.
    * The task maintains a list of other tasks it depends on.
@@ -109,6 +130,14 @@ class AliHLTTask : public TObject, public AliHLTLogging {
    */
   int SetDependency(AliHLTTask* pDep);
 
+  /**
+   * Clear a dependency.
+   * The ROOT TList touches the object which is in the list, even though
+   * it shouldn't care about. Thats why all lists have to be cleared before
+   * objects are deleted.
+   */
+  int UnsetDependency(AliHLTTask* pDep);
+
   /**
    * Return number of unresolved dependencies.
    * Iterate through all the configurations the task depends on and check
@@ -142,27 +171,26 @@ class AliHLTTask : public TObject, public AliHLTLogging {
    */
   int SetTarget(AliHLTTask* pDep);
 
-  // build a monolithic array of block data
-  // @param pBlockData reference to the block data target
-  // @return: array size, pointer to array in the target pTgt
-  //
-  /* this function is most likely depricated
-  int BuildBlockDataArray(AliHLTComponent_BlockData*& pBlockData);
-  */
+  /**
+   * Clear a target.
+   * The ROOT TList touches the object which is in the list, even though
+   * it shouldn't care about. Thats why all lists have to be cleared before
+   * objects are deleted.
+   */
+  int UnsetTarget(AliHLTTask* pTarget);
 
   /**
    * Prepare the task for event processing.
    * The method initializes the Data Buffer and calls the
    * @ref AliHLTComponent::Init method of the component.<br>
-   * The @ref ProcessTask methode can be called an arbitrary number of times
+   * The @ref ProcessTask method can be called an arbitrary number of times
    * as soon as the task is in <i>running</i> mode. 
    */
   int StartRun();
 
   /**
    * Clean-up the task after event processing.
-   * The method cleans up internal structures and calls the
-   * @ref AliHLTComponent::Deinit method of the component.
+   * The method cleans up internal structures.
    */
   int EndRun();
 
@@ -174,14 +202,9 @@ class AliHLTTask : public TObject, public AliHLTLogging {
    * processing, the data blocks are released. <br>
    * The @ref StartRun method must be called before.
    */
-  int ProcessTask();
-
-  // clear the list of source data blocks
-  // the list of source data blocks has to be cleared at the beginning of 
-  // a new event
-  /* this function is most likely depricated
-  int ClearSourceBlocks();
-  */
+  int ProcessTask(Int_t eventNo, AliHLTUInt32_t eventType,
+                 AliHLTTriggerMask_t trgMask, AliHLTUInt32_t timestamp,
+                 AliHLTUInt32_t participatingDetectors = 0);
 
   /**
    * Determine the number of matching data block between the component and the
@@ -191,7 +214,7 @@ class AliHLTTask : public TObject, public AliHLTLogging {
    * @param pConsumerTask   the task which subscribes to the data
    * @return number of matching data blocks
    */
-  int GetNofMatchingDataBlocks(const AliHLTTask* pConsumerTask);
+  int GetNofMatchingDataBlocks(const AliHLTTask* pConsumerTask) const;
 
   /**
    * Determine the number of matching data types between the component and a
@@ -200,7 +223,7 @@ class AliHLTTask : public TObject, public AliHLTLogging {
    * @param pConsumerTask   the task which subscribes to the data
    * @return number of matching data types
    */
-  int GetNofMatchingDataTypes(const AliHLTTask* pConsumerTask);
+  int GetNofMatchingDataTypes(const AliHLTTask* pConsumerTask) const;
 
   /**
    * Subscribe to the data of a source task.
@@ -210,12 +233,10 @@ class AliHLTTask : public TObject, public AliHLTLogging {
    * returns the number of blocks which would be prepared in case the target
    * array is big enough.
    * @param pConsumerTask   the task which subscribes to the data
-   * @param arrayBlockDesc  pointer to block descriptor to be filled
-   * @param iArraySize      size of the block descriptor array
+   * @param blockDescList   block descriptor list to be filled
    * @return number of matching data blocks, negative error code if failed
    */
-  int Subscribe(const AliHLTTask* pConsumerTask,
-               AliHLTComponent_BlockData* arrayBlockDesc, int iArraySize);
+  int Subscribe(const AliHLTTask* pConsumerTask, AliHLTComponentBlockDataList& blockDescList);
 
   /**
    * Release a block descriptor.
@@ -224,14 +245,30 @@ class AliHLTTask : public TObject, public AliHLTLogging {
    * @param pConsumerTask   the task which subscribed to the data
    * @return: >0 if success, negative error code if failed
    */
-  int Release(AliHLTComponent_BlockData* pBlockDesc,
+  int Release(AliHLTComponentBlockData* pBlockDesc,
              const AliHLTTask* pConsumerTask);
 
+  /**
+   * Cleanup function if the event processing is in error state.
+   * In order to handle in particular forwarded segments in the source
+   * tasks correctly the tasks of the chain have to subscribe to the
+   * parents even if the event is already in error state. This function
+   * is used instead of ProcessTask.
+   * Subscribes to all source tasks and releases them with out any event
+   * processing
+   */
+  int SubscribeSourcesAndSkip();
+
   /**
    * Print the status of the task with component, dependencies and targets.
    */
   void PrintStatus();
 
+  /**
+   * Overloaded from TObject
+   */
+  void Print(const char* options) const;
+
   /**
    * Search task dependency list recursively to find a dependency.
    * @param id              id of the task to search for
@@ -258,28 +295,52 @@ class AliHLTTask : public TObject, public AliHLTLogging {
    * Get number of source tasks.
    * @return number of source tasks
    */
-  int GetNofSources() {return fListDependencies.GetSize();}
+  int GetNofSources() const {return fListDependencies.GetSize();}
+
+  /**
+   * Customized logging function.
+   * The task id and pointer is added at the beginning of each message.
+   */
+  int LoggingVarargs(AliHLTComponentLogSeverity severity, 
+                    const char* originClass, const char* originFunc,
+                    const char* file, int line, ... ) const;
 
  private:
-  /** the configuration descriptor */
-  AliHLTConfiguration* fpConfiguration;
-  /** the component described by this task */
-  AliHLTComponent* fpComponent;
+  /** prohibited copy constructor */
+  AliHLTTask(const AliHLTTask&);
+  /** prohibited assignment operator */
+  AliHLTTask& operator=(const AliHLTTask&);
+
+  /**
+   * Custom initialization for child tasks.
+   */
+  virtual int CustomInit(AliHLTComponentHandler* pCH);
+
+  /**
+   * Custom clean up for child tasks.
+   */
+  virtual int CustomCleanup();
+
+ protected:
+  /** the configuration descriptor (external pointer) */
+  AliHLTConfiguration* fpConfiguration;                           //! transient
+  /** the component described by this task (created and deleted internally) */
+  AliHLTComponent* fpComponent;                                   //! transient
   /** the data buffer for the component processing */
-  AliHLTDataBuffer* fpDataBuffer;
+  AliHLTDataBuffer* fpDataBuffer;                                 //! transient
+
+ private:
   /** the list of targets (tasks which depend upon the current one) */
-  TList fListTargets;
+  TList fListTargets;                                             // see above
   /** the list of sources (tasks upon which the current one depends) */ 
-  TList fListDependencies;
+  TList fListDependencies;                                        // see above
 
   /**
    * block data array to be passed as argument to the 
    * @ref AliHLTComponent::ProcessEvent method. 
    * Filled through subscription to source tasks (@ref Subscribe).
    */
-  AliHLTComponent_BlockData* fpBlockDataArray;
-  /** size of the block data array */
-  int fBlockDataArraySize;
+  vector<AliHLTComponentBlockData> fBlockDataArray;               //! transient
 
   ClassDef(AliHLTTask, 0);
 };