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