]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTTask.h
coding conventions
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTTask.h
1 //-*- Mode: C++ -*-
2 // $Id$
3
4 #ifndef ALIHLTTASK_H
5 #define ALIHLTTASK_H
6 /* This file is property of and copyright by the ALICE HLT Project        * 
7  * ALICE Experiment at CERN, All rights reserved.                         *
8  * See cxx source for full Copyright notice                               */
9
10 /** @file   AliHLTTask.h
11     @author Matthias Richter
12     @date   
13     @brief  base class for HLT tasks
14 */
15
16 // see below for class documentation
17 // or
18 // refer to README to build package
19 // or
20 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
21
22 #include <TObject.h>
23 #include <TList.h>
24 #include "AliHLTDataTypes.h"
25 #include "AliHLTLogging.h"
26 #include "AliHLTDataBuffer.h"
27
28 struct AliHLTComponentBlockData;
29 class AliHLTComponent;
30 class AliHLTComponentHandler;
31
32 /******************************************************************************/
33
34 /**
35  * @class AliHLTTask
36  * A task collects all the information which is necessary to process a certain
37  * step in the HLT data processing chain.
38  * - the instance of the component
39  *   the task object creates and deletes the component object
40  * - the data buffer which receives the result of the component and provides
41  *   the data to other tasks/components
42  * - a list of all dependencies
43  * - a list of consumers
44  * - the task object holds an external pointer to the configuration object; 
45  *   \b Note: the configuration object must exist through the existence of the
46  *   task object!!!
47  *  
48  *
49  * @note This class is only used for the @ref alihlt_system.
50  *
51  * @ingroup alihlt_system
52  */
53 class AliHLTTask : public TObject, public AliHLTLogging {
54  public:
55   /** standard constructor */
56   AliHLTTask();
57   /** constructor 
58       @param pConf pointer to configuration descriptor
59    */
60   AliHLTTask(AliHLTConfiguration* pConf);
61   /** destructor */
62   virtual ~AliHLTTask();
63
64   /**
65    * Initialize the task.
66    * The task is initialized with a configuration descriptor. It needs a
67    * component handler instance to create the analysis component. The
68    * component is created and initialized.
69    * @param pConf pointer to configuration descriptor, can be NULL if it
70    *              was already provided to the constructor
71    * @param pCH   the HLT component handler
72    */
73   int Init(AliHLTConfiguration* pConf, AliHLTComponentHandler* pCH);
74
75   /**
76    * De-Initialize the task.
77    * Final cleanup after the run. The @ref AliHLTComponent::Deinit method of
78    * the component is called. The analysis component is deleted.
79    */
80   int Deinit();
81
82   /**
83    * Get the name of the object.
84    * This is an overridden TObject function in order to return the configuration
85    * name instead of the class name. Enables use of TList standard functions.
86    * @return name of the configuration
87    */
88   const char *GetName() const;
89
90   /**
91    * Return pointer to configuration.
92    * The tasks holds internally the configuration object.
93    * @return pointer to configuration
94    */
95   AliHLTConfiguration* GetConf() const;
96
97   /**
98    * Return pointer to component, which the task internally holds.
99    * <b>Never delete this object!!!</b>
100    * @return instance of the component
101    */
102   AliHLTComponent* GetComponent() const;
103
104   /**
105    * Find a dependency with a certain <i>name id</i>. 
106    * Searches in the list of dependencies for a task.
107    * @param id      the id of the <b>CONFIGURATION</b><br>
108    *                <b>NOTE:</b> the id does NOT specify a COMPONENT
109    * @return pointer to task
110    */
111   AliHLTTask* FindDependency(const char* id);
112
113   /**
114    * Add a dependency for the task.
115    * The task maintains a list of other tasks it depends on.
116    * @param   pDep  pointer to a task descriptor
117    * @return 0 if suceeded, neg error code if failed <br>
118    *    -EEXIST : the dependencie exists already
119    *
120    */
121   int SetDependency(AliHLTTask* pDep);
122
123   /**
124    * Clear a dependency.
125    * The ROOT TList touches the object which is in the list, even though
126    * it shouldn't care about. Thats why all lists have to be cleared before
127    * objects are deleted.
128    */
129   int UnsetDependency(AliHLTTask* pDep);
130
131   /**
132    * Return number of unresolved dependencies.
133    * Iterate through all the configurations the task depends on and check
134    * whether a corresponding task is available in the list.
135    * @return number of unresolved dependencies
136    */
137   int CheckDependencies();
138
139   /**
140    * Check whether the current task depends on the task pTask.
141    * @param pTask pointer to Task descriptor
142    * @return 1 the current task depends on pTask <br>
143    *         0 no dependency <br>
144    *         neg. error code if failed
145    */
146   int Depends(AliHLTTask* pTask);
147
148   /**
149    * Find a target with a certain id.
150    * Tasks which depend on the current task are referred to be <i>targets</i>. 
151    * @param id      configuration id to search for
152    * @return pointer to task instance
153    */
154   AliHLTTask* FindTarget(const char* id);
155
156   /**
157    * Insert task into target list.
158    * The target list specifies all the tasks which depend on the current task.
159    * @param pDep    pointer task object
160    * @return >=0 if succeeded, neg. error code if failed 
161    */
162   int SetTarget(AliHLTTask* pDep);
163
164   /**
165    * Clear a target.
166    * The ROOT TList touches the object which is in the list, even though
167    * it shouldn't care about. Thats why all lists have to be cleared before
168    * objects are deleted.
169    */
170   int UnsetTarget(AliHLTTask* pTarget);
171
172   /**
173    * Prepare the task for event processing.
174    * The method initializes the Data Buffer and calls the
175    * @ref AliHLTComponent::Init method of the component.<br>
176    * The @ref ProcessTask method can be called an arbitrary number of times
177    * as soon as the task is in <i>running</i> mode. 
178    */
179   int StartRun();
180
181   /**
182    * Clean-up the task after event processing.
183    * The method cleans up internal structures.
184    */
185   int EndRun();
186
187   /**
188    * Process the task.
189    * If all dependencies are resolved the tasks subscribes to the data of 
190    * all source tasks, builds the block descriptor and calls the
191    * @ref AliHLTComponent::ProcessEvent method of the component, after
192    * processing, the data blocks are released. <br>
193    * The @ref StartRun method must be called before.
194    */
195   int ProcessTask(Int_t eventNo);
196
197   /**
198    * Determine the number of matching data block between the component and the
199    * data buffer of a consumer component. It checks which data types from the
200    * list of input data types of the consumer component can be provided by data
201    * blocks of the current component.
202    * @param pConsumerTask   the task which subscribes to the data
203    * @return number of matching data blocks
204    */
205   int GetNofMatchingDataBlocks(const AliHLTTask* pConsumerTask) const;
206
207   /**
208    * Determine the number of matching data types between the component and a
209    * consumer component. It checks which data types from the list of input data
210    * types of the consumer component can be provided by the current component.
211    * @param pConsumerTask   the task which subscribes to the data
212    * @return number of matching data types
213    */
214   int GetNofMatchingDataTypes(const AliHLTTask* pConsumerTask) const;
215
216   /**
217    * Subscribe to the data of a source task.
218    * The function prepares the block descriptors for subsequent use with the
219    * @ref AliHLTComponent::ProcessEvent method, the method prepares all block
220    * descriptors which match the input data type of the consumer the function
221    * returns the number of blocks which would be prepared in case the target
222    * array is big enough.
223    * @param pConsumerTask   the task which subscribes to the data
224    * @param arrayBlockDesc  pointer to block descriptor to be filled
225    * @param iArraySize      size of the block descriptor array
226    * @return number of matching data blocks, negative error code if failed
227    */
228   int Subscribe(const AliHLTTask* pConsumerTask,
229                 AliHLTComponentBlockData* arrayBlockDesc, int iArraySize);
230
231   /**
232    * Release a block descriptor.
233    * Notification from consumer task.  
234    * @param pBlockDesc      descriptor of the data segment
235    * @param pConsumerTask   the task which subscribed to the data
236    * @return: >0 if success, negative error code if failed
237    */
238   int Release(AliHLTComponentBlockData* pBlockDesc,
239               const AliHLTTask* pConsumerTask);
240
241   /**
242    * Print the status of the task with component, dependencies and targets.
243    */
244   void PrintStatus();
245
246   /**
247    * Search task dependency list recursively to find a dependency.
248    * @param id              id of the task to search for
249    * @param pTgtList        (optional) target list to receive dependency tree
250    * @return 0 if not found, >0 found in the n-th level, 
251              dependency list in the target list  
252    */
253   int FollowDependency(const char* id, TList* pTgtList=NULL);
254
255   /**
256    * Print the tree for a certain dependency either from the task or
257    * configuration list.
258    * Each task posseses two "link lists": The configurations are the origin
259    * of the  task list. In case of an error during the built of the task list,
260    * the dependencies for the task list might be incomplete. In this case the
261    * configurations can give infomation on the error reason.  
262    * @param id              id of the dependency to search for
263    * @param bMode           0 (default) from task dependency list, <br> 
264    *                        1 from configuration list
265    */
266   void PrintDependencyTree(const char* id, int bMode=0);
267
268   /**
269    * Get number of source tasks.
270    * @return number of source tasks
271    */
272   int GetNofSources() const {return fListDependencies.GetSize();}
273
274  private:
275   /** prohibited copy constructor */
276   AliHLTTask(const AliHLTTask&);
277   /** prohibited assignment operator */
278   AliHLTTask& operator=(const AliHLTTask&);
279
280   /** the configuration descriptor (external pointer) */
281   AliHLTConfiguration* fpConfiguration;                           //! transient
282   /** the component described by this task (created and deleted internally) */
283   AliHLTComponent* fpComponent;                                   //! transient
284   /** the data buffer for the component processing */
285   AliHLTDataBuffer* fpDataBuffer;                                 //! transient
286   /** the list of targets (tasks which depend upon the current one) */
287   TList fListTargets;                                             // see above
288   /** the list of sources (tasks upon which the current one depends) */ 
289   TList fListDependencies;                                        // see above
290
291   /**
292    * block data array to be passed as argument to the 
293    * @ref AliHLTComponent::ProcessEvent method. 
294    * Filled through subscription to source tasks (@ref Subscribe).
295    */
296   vector<AliHLTComponentBlockData> fBlockDataArray;               //! transient
297
298   ClassDef(AliHLTTask, 2);
299 };
300
301 #endif