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