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