]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTTask.h
changes according to coding conventions
[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
b22e91eb 8/** @file AliHLTTask.h
c38ba6f9 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
8ede8717 21struct AliHLTComponentBlockData;
c38ba6f9 22class AliHLTComponent;
23class AliHLTComponentHandler;
24
25/******************************************************************************/
26
b22e91eb 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
53feaef5 32 * the task object creates and deletes the component object
b22e91eb 33 * - the data buffer which receives the result of the component and provides
34 * the data to other tasks/components
35 * - a list of all dependencies
36 * - a list of consumers
53feaef5 37 * - the task object holds an external pointer to the configuration object;
38 * \b Note: the configuration object must exist through the existence of the
39 * task object!!!
40 *
b22e91eb 41 *
42 * @note This class is only used for the @ref alihlt_system.
43 *
44 * @ingroup alihlt_system
45 */
c38ba6f9 46class AliHLTTask : public TObject, public AliHLTLogging {
47 public:
48 /** standard constructor */
49 AliHLTTask();
50 /** constructor
51 @param pConf pointer to configuration descriptor
c38ba6f9 52 */
53feaef5 53 AliHLTTask(AliHLTConfiguration* pConf);
85869391 54 /** not a valid copy constructor, defined according to effective C++ style */
55 AliHLTTask(const AliHLTTask&);
56 /** not a valid assignment op, but defined according to effective C++ style */
57 AliHLTTask& operator=(const AliHLTTask&);
c38ba6f9 58 /** destructor */
59 virtual ~AliHLTTask();
60
61 /**
62 * Initialize the task.
63 * The task is initialized with a configuration descriptor. It needs a
64 * component handler instance to create the analysis component.
53feaef5 65 * @param pConf pointer to configuration descriptor, can be NULL if it
66 * was already provided to the constructor
c38ba6f9 67 * @param pCH the HLT component handler
68 */
69 int Init(AliHLTConfiguration* pConf, AliHLTComponentHandler* pCH);
70
53feaef5 71 /**
72 * De-Initialize the task.
73 * Final cleanup after the run. The analysis component is deleted.
74 */
75 int Deinit();
76
c38ba6f9 77 /**
78 * Get the name of the object.
79 * This is an overridden TObject function in order to return the configuration
80 * name instead of the class name. Enables use of TList standard functions.
81 * @return name of the configuration
82 */
83 const char *GetName() const;
84
85 /**
86 * Return pointer to configuration.
87 * The tasks holds internally the configuration object.
88 * @return pointer to configuration
89 */
90 AliHLTConfiguration* GetConf() const;
91
92 /**
93 * Return pointer to component, which the task internally holds.
94 * <b>Never delete this object!!!</b>
95 * @return instance of the component
96 */
97 AliHLTComponent* GetComponent() const;
98
99 /**
100 * Find a dependency with a certain <i>name id</i>.
101 * Searches in the list of dependencies for a task.
102 * @param id the id of the <b>CONFIGURATION</b><br>
103 * <b>NOTE:</b> the id does NOT specify a COMPONENT
104 * @return pointer to task
105 */
106 AliHLTTask* FindDependency(const char* id);
107
108 /*
109 * insert block data to the list
110 * the data has to come from a task the current one depends on
111 * result:
112 * -EEXIST : the block data from this task has already been inserted
113 * -ENOENT : no dependencies to the task the data is coming from
114 */
115 /*
116 * this function is most likely depricated
8ede8717 117 int InsertBlockData(AliHLTComponentBlockData* pBlock, AliHLTTask* pSource);
c38ba6f9 118 */
119
120 /**
121 * Add a dependency for the task.
122 * The task maintains a list of other tasks it depends on.
123 * @param pDep pointer to a task descriptor
124 * @return 0 if suceeded, neg error code if failed <br>
125 * -EEXIST : the dependencie exists already
126 *
127 */
128 int SetDependency(AliHLTTask* pDep);
129
130 /**
131 * Return number of unresolved dependencies.
132 * Iterate through all the configurations the task depends on and check
133 * whether a corresponding task is available in the list.
134 * @return number of unresolved dependencies
135 */
136 int CheckDependencies();
137
138 /**
139 * Check whether the current task depends on the task pTask.
140 * @param pTask pointer to Task descriptor
141 * @return 1 the current task depends on pTask <br>
142 * 0 no dependency <br>
143 * neg. error code if failed
144 */
145 int Depends(AliHLTTask* pTask);
146
147 /**
148 * Find a target with a certain id.
149 * Tasks which depend on the current task are referred to be <i>targets</i>.
150 * @param id configuration id to search for
151 * @return pointer to task instance
152 */
153 AliHLTTask* FindTarget(const char* id);
154
155 /**
156 * Insert task into target list.
157 * The target list specifies all the tasks which depend on the current task.
158 * @param pDep pointer task object
159 * @return >=0 if succeeded, neg. error code if failed
160 */
161 int SetTarget(AliHLTTask* pDep);
162
163 // build a monolithic array of block data
164 // @param pBlockData reference to the block data target
165 // @return: array size, pointer to array in the target pTgt
166 //
167 /* this function is most likely depricated
8ede8717 168 int BuildBlockDataArray(AliHLTComponentBlockData*& pBlockData);
c38ba6f9 169 */
170
171 /**
172 * Prepare the task for event processing.
173 * The method initializes the Data Buffer and calls the
174 * @ref AliHLTComponent::Init method of the component.<br>
175 * The @ref ProcessTask methode can be called an arbitrary number of times
176 * as soon as the task is in <i>running</i> mode.
177 */
178 int StartRun();
179
180 /**
181 * Clean-up the task after event processing.
182 * The method cleans up internal structures and calls the
183 * @ref AliHLTComponent::Deinit method of the component.
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();
196
197 // clear the list of source data blocks
198 // the list of source data blocks has to be cleared at the beginning of
199 // a new event
200 /* this function is most likely depricated
201 int ClearSourceBlocks();
202 */
203
204 /**
205 * Determine the number of matching data block between the component and the
206 * data buffer of a consumer component. It checks which data types from the
207 * list of input data types of the consumer component can be provided by data
208 * blocks of the current component.
209 * @param pConsumerTask the task which subscribes to the data
210 * @return number of matching data blocks
211 */
212 int GetNofMatchingDataBlocks(const AliHLTTask* pConsumerTask);
213
214 /**
215 * Determine the number of matching data types between the component and a
216 * consumer component. It checks which data types from the list of input data
217 * types of the consumer component can be provided by the current component.
218 * @param pConsumerTask the task which subscribes to the data
219 * @return number of matching data types
220 */
221 int GetNofMatchingDataTypes(const AliHLTTask* pConsumerTask);
222
223 /**
224 * Subscribe to the data of a source task.
225 * The function prepares the block descriptors for subsequent use with the
226 * @ref AliHLTComponent::ProcessEvent method, the method prepares all block
227 * descriptors which match the input data type of the consumer the function
228 * returns the number of blocks which would be prepared in case the target
229 * array is big enough.
230 * @param pConsumerTask the task which subscribes to the data
231 * @param arrayBlockDesc pointer to block descriptor to be filled
232 * @param iArraySize size of the block descriptor array
233 * @return number of matching data blocks, negative error code if failed
234 */
235 int Subscribe(const AliHLTTask* pConsumerTask,
8ede8717 236 AliHLTComponentBlockData* arrayBlockDesc, int iArraySize);
c38ba6f9 237
238 /**
239 * Release a block descriptor.
240 * Notification from consumer task.
241 * @param pBlockDesc descriptor of the data segment
242 * @param pConsumerTask the task which subscribed to the data
243 * @return: >0 if success, negative error code if failed
244 */
8ede8717 245 int Release(AliHLTComponentBlockData* pBlockDesc,
c38ba6f9 246 const AliHLTTask* pConsumerTask);
247
248 /**
249 * Print the status of the task with component, dependencies and targets.
250 */
251 void PrintStatus();
252
253 /**
254 * Search task dependency list recursively to find a dependency.
255 * @param id id of the task to search for
256 * @param pTgtList (optional) target list to receive dependency tree
257 * @return 0 if not found, >0 found in the n-th level,
258 dependency list in the target list
259 */
260 int FollowDependency(const char* id, TList* pTgtList=NULL);
261
262 /**
263 * Print the tree for a certain dependency either from the task or
264 * configuration list.
265 * Each task posseses two "link lists": The configurations are the origin
266 * of the task list. In case of an error during the built of the task list,
267 * the dependencies for the task list might be incomplete. In this case the
268 * configurations can give infomation on the error reason.
269 * @param id id of the dependency to search for
270 * @param bMode 0 (default) from task dependency list, <br>
271 * 1 from configuration list
272 */
273 void PrintDependencyTree(const char* id, int bMode=0);
274
275 /**
276 * Get number of source tasks.
277 * @return number of source tasks
278 */
279 int GetNofSources() {return fListDependencies.GetSize();}
280
281 private:
53feaef5 282 /** the configuration descriptor (external pointer) */
c38ba6f9 283 AliHLTConfiguration* fpConfiguration;
53feaef5 284 /** the component described by this task (created and deleted by the task object) */
c38ba6f9 285 AliHLTComponent* fpComponent;
286 /** the data buffer for the component processing */
287 AliHLTDataBuffer* fpDataBuffer;
288 /** the list of targets (tasks which depend upon the current one) */
289 TList fListTargets;
290 /** the list of sources (tasks upon which the current one depends) */
291 TList fListDependencies;
292
293 /**
294 * block data array to be passed as argument to the
295 * @ref AliHLTComponent::ProcessEvent method.
296 * Filled through subscription to source tasks (@ref Subscribe).
297 */
8ede8717 298 AliHLTComponentBlockData* fpBlockDataArray;
c38ba6f9 299 /** size of the block data array */
300 int fBlockDataArraySize;
301
53feaef5 302 ClassDef(AliHLTTask, 1);
c38ba6f9 303};
304
305#endif