+//-*- Mode: C++ -*-
// $Id$
#ifndef ALIHLTTASK_H
#define ALIHLTTASK_H
-/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+/* This file is property of and copyright by the ALICE HLT Project *
+ * ALICE Experiment at CERN, All rights reserved. *
* See cxx source for full Copyright notice */
/** @file AliHLTTask.h
@brief base class for HLT tasks
*/
-#include <cerrno>
+// see below for class documentation
+// or
+// refer to README to build package
+// or
+// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+
+#include <vector>
#include <TObject.h>
#include <TList.h>
#include "AliHLTDataTypes.h"
#include "AliHLTLogging.h"
#include "AliHLTDataBuffer.h"
-struct AliHLTComponent_BlockData;
+struct AliHLTComponentBlockData;
class AliHLTComponent;
class AliHLTComponentHandler;
+class AliHLTConfiguration;
+class AliHLTTask;
+
+typedef vector<AliHLTTask*> AliHLTTaskPList;
/******************************************************************************/
* 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 the configuration object
+ * - 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.
*
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
*/
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.
*/
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
*/
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();
* 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,
+ AliHLTUInt64_t trgMask, AliHLTUInt32_t timestamp,
+ AliHLTUInt32_t participatingDetectors = 0);
/**
* Determine the number of matching data block between the component and the
* @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
* @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.
* 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.
* @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
* 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);
};