logging class extended and macros for easy log messages introduced, code changed...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTConfiguration.h
CommitLineData
3495cce2 1// @(#) $Id$
2
3#ifndef ALIHLTCONFIGURATION_H
4#define ALIHLTCONFIGURATION_H
5/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * See cxx source for full Copyright notice */
7
8/* AliHLTConfiguration
9 base class for HLT configurations
10 */
11
12#include <errno.h>
13#include <TObject.h>
14#include <TList.h>
15#include "AliHLTDataTypes.h"
16#include "AliHLTLogging.h"
17
85465857 18class AliHLTConfigurationHandler;
3495cce2 19/*****************************************************************************************************
20 *
21 * AliHLTConfiguration
22 *
23 * this class describes a certain configuration af an HLT processing step by the following parameters:
24 * - a unique id string/name
25 * - the id of the component
26 * - the ids of the configurations it requires input from
27 * - the arguments, which are passed to the component when it is initialized
28 *
29 * The setup of a configuration requires simply the creation of a global object of class AliHLTConfiguration.
30 * The Configuration is automatically registered in the list of available configurations. The list is used
31 * by the handler to resolve the dependencies upon other configurations. Hierarchies can be built up in
32 * an easy way.
33 *
34 * A configuration is interpreted by the Configuration Handler and transformed into a Task List.
35 */
36class AliHLTConfiguration : public TObject, public AliHLTLogging {
37 public:
38 AliHLTConfiguration();
39 AliHLTConfiguration(const char* id, const char* component, const char* sources, const char* arguments);
40 virtual ~AliHLTConfiguration();
41
85465857 42 /****************************************************************************************************
43 * global initialization
44 */
45 static int GlobalInit(AliHLTConfigurationHandler* pHandler);
46
47 static int GlobalDeinit();
48
3495cce2 49 /****************************************************************************************************
50 * properties
51 */
52
53 // configuration id, a unique name
54 // overridden TObject function in order to return the configuration name instead of the class name
55 // enables use of TList standard functions
56 const char *GetName() const;
57
58 // id of the component
59 const char* GetComponentID();
60
61 // print status info
62 void PrintStatus();
63
64 // get a certain source
65 AliHLTConfiguration* GetSource(const char* id);
66
67 // try to find a dependency recursively in the list of sources
68 // parameter:
69 // id - the source to search for
70 // pTgtList - (optional) target list to receive the dependency tree
71 // result:
72 // 0 if not found
73 // n found in the n-th level
74 // dependency list in the target list
75 int FollowDependency(const char* id, TList* pTgtList=NULL);
76
77 // get the number of resolved sources
78 int GetNofSources() {return fListSources.size();}
79
80 // 1 if all sources are resolved
81 // try to resolve if bAuto==1
82 int SourcesResolved(int bAuto=0);
83
84 // start iteration and get the first source
85 AliHLTConfiguration* GetFirstSource();
86
87 // continue iteration and get the next source
88 AliHLTConfiguration* GetNextSource();
89
90 // invalidate a dependency and mark the configuration to be re-evaluted
91 int InvalidateSource(AliHLTConfiguration* pConf);
92
93 // mark the configuration to be re-evaluted
94 int InvalidateSources() {fNofSources=-1; return 0;}
95
96 // return the arguments array
97 int GetArguments(int* pArgc, const char*** pArgv);
98
99 protected:
100
3495cce2 101
102 private:
103 /* extract the source configurations from the sources string
104 */
105 int ExtractSources();
106
107 /* extract arguments from the argument string
108 */
109 int ExtractArguments();
110
111 /* helper function to build a vector from an argument string
112 */
113 int InterpreteString(const char* arg, vector<char*>& argList);
114
115 const char* fID; // id of this configuration
116 const char* fComponent; // component id of this configuration
117
118 const char* fStringSources; // the 'sources' string as passed to the constructor
119 int fNofSources;
120 vector<AliHLTConfiguration*> fListSources; // list of sources
121 vector<AliHLTConfiguration*>::iterator fListSrcElement; // iterator for the above list
122
123 const char* fArguments; // the arguments string as passed to the constructor
124 int fArgc; // number of arguments
125 char** fArgv; // argument array
126
85465857 127 static AliHLTConfigurationHandler* fConfigurationHandler;
128
3495cce2 129 ClassDef(AliHLTConfiguration, 0);
130};
131
132struct AliHLTComponent_BlockData;
133class AliHLTComponent;
134class AliHLTComponentHandler;
135
136/*****************************************************************************************************
137 *
138 * AliHLTTask
139 *
140 *
141 */
142class AliHLTTask : public TObject, public AliHLTLogging {
143 public:
144 AliHLTTask();
145 AliHLTTask(AliHLTConfiguration* fConf, AliHLTComponentHandler* pCH);
146 virtual ~AliHLTTask();
147
148 /* initialize the task
149 */
150 int Init(AliHLTConfiguration* fConf, AliHLTComponentHandler* pCH);
151
152 // overridden TObject function in order to return the configuration name instead of the class name
153 // enables use of TList standard functions
154 const char *GetName() const;
155
156 /* return pointer to configuration
157 */
158 AliHLTConfiguration* GetConf();
159
160 /* return pointer to configuration
161 */
162 AliHLTComponent* GetComponent();
163
164 /* find a dependency with name/id
165 */
166 AliHLTTask* FindDependency(const char* id);
167
168 /* insert block data to the list
169 * the data has to come from a task the current one depend on
170 * result:
171 * -EEXIST : the block data from this task has already been inserted
172 * -ENOENT : no dependencies to the task the data is coming from
173 */
174 int InsertBlockData(AliHLTComponent_BlockData* pBlock, AliHLTTask* pSource);
175
176 /* add a dependency for the task
177 */
178 int SetDependency(AliHLTTask* pDep);
179
180 /* return number of unresolved dependencies
181 */
182 int CheckDependencies();
183
184 /* 1 if the current task depends upon pTask
185 * 0 if no dependency
186 */
187 int Depends(AliHLTTask* pTask);
188
189 /* find a target
190 */
191 AliHLTTask* FindTarget(const char* id);
192
193 /* insert task into target list
194 */
195 int SetTarget(AliHLTTask* pDep);
196
197 // build a monolithic array of block data
198 // result: array size, pointer to array in the target pTgt
199 //
200 int BuildBlockDataArray(AliHLTComponent_BlockData*& pTgt);
201
202 /* process the task if all dependencies are resolved
203 * reset the source block data list
204 */
205 //int ProcessTask(...);
206
207 // clear the list of source data blocks
208 // the list of source data blocks has to be cleared at the beginning of
209 // a new event
210 int ClearSourceBlocks();
211
212 // print the status of the task with component, dependencies and targets
213 void PrintStatus();
214
215 // search task dependency list recursively to find a dependency
216 // parameter:
217 // id - the task to search for
218 // pTgtList - (optional) target list to receive the dependency tree
219 // result:
220 // 0 if not found
221 // n found in the n-th level
222 // dependency list in the target list
223 int FollowDependency(const char* id, TList* pTgtList=NULL);
224
225 // print the tree for a certain dependency either from the task or configuration list
226 // each task posseses two "link lists": The configurations are the the origin of the
227 // task list. In case of an error during the built of the task list, the dependencies
228 // for the task list might be incomplete. In this case the configurations can give
229 // infomation on the error reason
230 // parameter:
231 // id - the dependency to search for
232 // bFromConfiguration (default=0) - if 0 the task dependency list is used, if one the configuration list is used
233 void PrintDependencyTree(const char* id, int bFromConfiguration=0);
234
235 private:
236 AliHLTConfiguration* fpConfiguration;
237 AliHLTComponent* fpComponent;
238 vector<AliHLTComponent_BlockData*> fSources;
239 TList fListTargets;
240 TList fListDependencies;
241
242 AliHLTComponent_BlockData* fpBlockDataArray;
243
244 ClassDef(AliHLTTask, 0);
245};
246
247class AliHLTConfigurationHandler : public AliHLTLogging {
248 public:
249 AliHLTConfigurationHandler();
250 AliHLTConfigurationHandler(AliHLTConfiguration* pConf);
251 virtual ~AliHLTConfigurationHandler();
252
253 /****************************************************************************************************
254 * registration
255 */
256
257 // register a configuration to the global list of configurations
85465857 258 int RegisterConfiguration(AliHLTConfiguration* pConf);
3495cce2 259
260 // create a configuration and register it
85465857 261 int CreateConfiguration(const char* id, const char* component, const char* sources, const char* arguments);
3495cce2 262
263 // remove a configuration from the global list
85465857 264 int RemoveConfiguration(AliHLTConfiguration* pConf);
265 int RemoveConfiguration(const char* id);
3495cce2 266
267 // find a configuration from the global list
85465857 268 AliHLTConfiguration* FindConfiguration(const char* id);
3495cce2 269
270 // print the registered configurations to the logging function
85465857 271 void PrintConfigurations();
3495cce2 272
273
274 private:
275 static TList fListConfigurations; // the list of registered configurations
276 static TList fListDynamicConfigurations; // the list of dynamic configurations (for proper cleanup)
277
278 ClassDef(AliHLTConfigurationHandler, 0);
279};
280
281#endif