]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTTask.h
- AliHLTFileWriter added
[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
2d7ff710 64 * component handler instance to create the analysis component. The
65 * component is created and initialized.
53feaef5 66 * @param pConf pointer to configuration descriptor, can be NULL if it
67 * was already provided to the constructor
c38ba6f9 68 * @param pCH the HLT component handler
69 */
70 int Init(AliHLTConfiguration* pConf, AliHLTComponentHandler* pCH);
71
53feaef5 72 /**
73 * De-Initialize the task.
2d7ff710 74 * Final cleanup after the run. The @ref AliHLTComponent::Deinit method of
75 * the component is called. The analysis component is deleted.
53feaef5 76 */
77 int Deinit();
78
c38ba6f9 79 /**
80 * Get the name of the object.
81 * This is an overridden TObject function in order to return the configuration
82 * name instead of the class name. Enables use of TList standard functions.
83 * @return name of the configuration
84 */
85 const char *GetName() const;
86
87 /**
88 * Return pointer to configuration.
89 * The tasks holds internally the configuration object.
90 * @return pointer to configuration
91 */
92 AliHLTConfiguration* GetConf() const;
93
94 /**
95 * Return pointer to component, which the task internally holds.
96 * <b>Never delete this object!!!</b>
97 * @return instance of the component
98 */
99 AliHLTComponent* GetComponent() const;
100
101 /**
102 * Find a dependency with a certain <i>name id</i>.
103 * Searches in the list of dependencies for a task.
104 * @param id the id of the <b>CONFIGURATION</b><br>
105 * <b>NOTE:</b> the id does NOT specify a COMPONENT
106 * @return pointer to task
107 */
108 AliHLTTask* FindDependency(const char* id);
109
c38ba6f9 110 /**
111 * Add a dependency for the task.
112 * The task maintains a list of other tasks it depends on.
113 * @param pDep pointer to a task descriptor
114 * @return 0 if suceeded, neg error code if failed <br>
115 * -EEXIST : the dependencie exists already
116 *
117 */
118 int SetDependency(AliHLTTask* pDep);
119
120 /**
121 * Return number of unresolved dependencies.
122 * Iterate through all the configurations the task depends on and check
123 * whether a corresponding task is available in the list.
124 * @return number of unresolved dependencies
125 */
126 int CheckDependencies();
127
128 /**
129 * Check whether the current task depends on the task pTask.
130 * @param pTask pointer to Task descriptor
131 * @return 1 the current task depends on pTask <br>
132 * 0 no dependency <br>
133 * neg. error code if failed
134 */
135 int Depends(AliHLTTask* pTask);
136
137 /**
138 * Find a target with a certain id.
139 * Tasks which depend on the current task are referred to be <i>targets</i>.
140 * @param id configuration id to search for
141 * @return pointer to task instance
142 */
143 AliHLTTask* FindTarget(const char* id);
144
145 /**
146 * Insert task into target list.
147 * The target list specifies all the tasks which depend on the current task.
148 * @param pDep pointer task object
149 * @return >=0 if succeeded, neg. error code if failed
150 */
151 int SetTarget(AliHLTTask* pDep);
152
c38ba6f9 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>
2d7ff710 157 * The @ref ProcessTask method can be called an arbitrary number of times
c38ba6f9 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.
2d7ff710 164 * The method cleans up internal structures.
c38ba6f9 165 */
166 int EndRun();
167
168 /**
169 * Process the task.
170 * If all dependencies are resolved the tasks subscribes to the data of
171 * all source tasks, builds the block descriptor and calls the
172 * @ref AliHLTComponent::ProcessEvent method of the component, after
173 * processing, the data blocks are released. <br>
174 * The @ref StartRun method must be called before.
175 */
9ce4bf4a 176 int ProcessTask(Int_t eventNo);
c38ba6f9 177
178 /**
179 * Determine the number of matching data block between the component and the
180 * data buffer of a consumer component. It checks which data types from the
181 * list of input data types of the consumer component can be provided by data
182 * blocks of the current component.
183 * @param pConsumerTask the task which subscribes to the data
184 * @return number of matching data blocks
185 */
2d7ff710 186 int GetNofMatchingDataBlocks(const AliHLTTask* pConsumerTask) const;
c38ba6f9 187
188 /**
189 * Determine the number of matching data types between the component and a
190 * consumer component. It checks which data types from the list of input data
191 * types of the consumer component can be provided by the current component.
192 * @param pConsumerTask the task which subscribes to the data
193 * @return number of matching data types
194 */
2d7ff710 195 int GetNofMatchingDataTypes(const AliHLTTask* pConsumerTask) const;
c38ba6f9 196
197 /**
198 * Subscribe to the data of a source task.
199 * The function prepares the block descriptors for subsequent use with the
200 * @ref AliHLTComponent::ProcessEvent method, the method prepares all block
201 * descriptors which match the input data type of the consumer the function
202 * returns the number of blocks which would be prepared in case the target
203 * array is big enough.
204 * @param pConsumerTask the task which subscribes to the data
205 * @param arrayBlockDesc pointer to block descriptor to be filled
206 * @param iArraySize size of the block descriptor array
207 * @return number of matching data blocks, negative error code if failed
208 */
209 int Subscribe(const AliHLTTask* pConsumerTask,
8ede8717 210 AliHLTComponentBlockData* arrayBlockDesc, int iArraySize);
c38ba6f9 211
212 /**
213 * Release a block descriptor.
214 * Notification from consumer task.
215 * @param pBlockDesc descriptor of the data segment
216 * @param pConsumerTask the task which subscribed to the data
217 * @return: >0 if success, negative error code if failed
218 */
8ede8717 219 int Release(AliHLTComponentBlockData* pBlockDesc,
c38ba6f9 220 const AliHLTTask* pConsumerTask);
221
222 /**
223 * Print the status of the task with component, dependencies and targets.
224 */
225 void PrintStatus();
226
227 /**
228 * Search task dependency list recursively to find a dependency.
229 * @param id id of the task to search for
230 * @param pTgtList (optional) target list to receive dependency tree
231 * @return 0 if not found, >0 found in the n-th level,
232 dependency list in the target list
233 */
234 int FollowDependency(const char* id, TList* pTgtList=NULL);
235
236 /**
237 * Print the tree for a certain dependency either from the task or
238 * configuration list.
239 * Each task posseses two "link lists": The configurations are the origin
240 * of the task list. In case of an error during the built of the task list,
241 * the dependencies for the task list might be incomplete. In this case the
242 * configurations can give infomation on the error reason.
243 * @param id id of the dependency to search for
244 * @param bMode 0 (default) from task dependency list, <br>
245 * 1 from configuration list
246 */
247 void PrintDependencyTree(const char* id, int bMode=0);
248
249 /**
250 * Get number of source tasks.
251 * @return number of source tasks
252 */
2d7ff710 253 int GetNofSources() const {return fListDependencies.GetSize();}
c38ba6f9 254
255 private:
53feaef5 256 /** the configuration descriptor (external pointer) */
c38ba6f9 257 AliHLTConfiguration* fpConfiguration;
53feaef5 258 /** the component described by this task (created and deleted by the task object) */
c38ba6f9 259 AliHLTComponent* fpComponent;
260 /** the data buffer for the component processing */
261 AliHLTDataBuffer* fpDataBuffer;
262 /** the list of targets (tasks which depend upon the current one) */
263 TList fListTargets;
264 /** the list of sources (tasks upon which the current one depends) */
265 TList fListDependencies;
266
267 /**
268 * block data array to be passed as argument to the
269 * @ref AliHLTComponent::ProcessEvent method.
270 * Filled through subscription to source tasks (@ref Subscribe).
271 */
8ede8717 272 AliHLTComponentBlockData* fpBlockDataArray;
c38ba6f9 273 /** size of the block data array */
274 int fBlockDataArraySize;
275
53feaef5 276 ClassDef(AliHLTTask, 1);
c38ba6f9 277};
278
279#endif