several corrections, still needs testing
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.h
CommitLineData
30338a30 1//-*- Mode: C++ -*-
f23a6e1a 2// @(#) $Id$
3
4#ifndef ALIHLTSYSTEM_H
5#define ALIHLTSYSTEM_H
6/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
7 * See cxx source for full Copyright notice */
8
b22e91eb 9/** @file AliHLTSystem.h
10 @author Matthias Richter
11 @date
12 @brief Global HLT module management and AliRoot integration.
13 @note The class is used in Offline (AliRoot) context
14*/
f23a6e1a 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
b22e91eb 22/**
23 * @defgroup alihlt_system HLT integration into AliRoot
24 * This section describes the HLT integration into AliRoot.
25 */
f23a6e1a 26
5ec8e281 27#include "AliHLTLogging.h"
28#include <TList.h>
c043fa2c 29#include <TString.h>
f23a6e1a 30
5ec8e281 31class AliHLTComponentHandler;
32class AliHLTConfiguration;
85465857 33class AliHLTConfigurationHandler;
5ec8e281 34class AliHLTTask;
242bb794 35class AliRunLoader;
36class AliRawReader;
af885e0f 37class AliESDEvent;
90ebac25 38class TObjArray;
39class TStopwatch;
f23a6e1a 40
bfccbf68 41/**
42 * @class AliHLTSystem
43 * Main class for the HLT integration into AliRoot.
44 * The class handles a list of configurations. Configurations are translated
45 * into task lists which can be executed.
46 *
b22e91eb 47 * @note This class is only used for the @ref alihlt_system.
48 *
49 * @ingroup alihlt_system
bfccbf68 50 */
5ec8e281 51class AliHLTSystem : public AliHLTLogging {
52 public:
bfccbf68 53 /** default constructor */
f23a6e1a 54 AliHLTSystem();
bfccbf68 55 /** destructor */
f23a6e1a 56 virtual ~AliHLTSystem();
57
bfccbf68 58 /**
59 * Pointer to an instance of @ref AliHLTComponentHandler.
3b35e87c 60 */
70ed7d01 61 AliHLTComponentHandler* fpComponentHandler; //! transient
bfccbf68 62
63 /**
64 * Pointer to an instance of @ref AliHLTConfigurationHandler.
65 */
70ed7d01 66 AliHLTConfigurationHandler* fpConfigurationHandler; //! transient
f23a6e1a 67
bfccbf68 68 /**
69 * Add a configuration to the end of the list.
70 * @param pConf pointer to configuration to add
5ec8e281 71 */
72 int AddConfiguration(AliHLTConfiguration* pConf);
73
bfccbf68 74 /**
70ed7d01 75 * Insert a configuration to the end of the list after the specified
76 * configuration.
bfccbf68 77 * @param pConf pointer to configuration to insert
78 * @param pPrec pointer to configuration to insert the new one after
5ec8e281 79 */
80 int InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec);
81
bfccbf68 82 /**
83 * Remove a configuration from the list.
84 * @param pConf pointer to configuration to delete
5ec8e281 85 */
86 int DeleteConfiguration(AliHLTConfiguration* pConf);
87
bfccbf68 88 /**
a742f6f8 89 * Build a task list
3b35e87c 90 * This method is used to build the tasks from the 'master' configuration
91 * objects which are added to the HLT system handler. This is an iterative
92 * process since the task might depend upon other configurations. For each
93 * configuration object which has not yet been converted into a task, the
94 * method will be called iteratively. Finally, after building all tasks which
95 * the current one depends on have been created, the task is inserted to the
96 * list of tasks with the InsertTask method.
a742f6f8 97 * @param pConf configuration name/id
98 */
99 int BuildTaskList(const char* pConf);
100
101 /**
102 * Build task list from a configuration object.
103 * This method is kept for backward compatibility. Use the version
104 * with the configuration name.
bfccbf68 105 * @param pConf pointer to configuration to build the task list from
5ec8e281 106 */
107 int BuildTaskList(AliHLTConfiguration* pConf);
108
bfccbf68 109 /**
110 * Clean the list of tasks and delete all the task objects.
3b35e87c 111 */
5ec8e281 112 int CleanTaskList();
113
bfccbf68 114 /**
115 * Insert a task to the task list.
116 * The method first checks whether all dependencies are resolved (i.e. exist
70ed7d01 117 * already in the task list). During this iteration the cross links between
118 * the tasks are set as well. If all dependencies are resolved, the task is
119 * added at the end of the list.
bfccbf68 120 * @param pTask pointer to task to add
3b35e87c 121 */
5ec8e281 122 int InsertTask(AliHLTTask* pTask);
123
bfccbf68 124 /**
125 * Find a task with an id.
126 * @param id CONFIGURATION id (not a COMPONENT id!)
3b35e87c 127 */
5ec8e281 128 AliHLTTask* FindTask(const char* id);
129
bfccbf68 130 /**
131 * Print the task list.
3b35e87c 132 */
5ec8e281 133 void PrintTaskList();
134
53feaef5 135 /**
136 * Run the task list.
9ce4bf4a 137 * The method checks whether the task list has already been build. If not,
138 * or the configuration list has been changed, the @ref BuildTaskList
139 * method is scalled
53feaef5 140 * All tasks of the list will be subsequently processed for each event.
141 * @param iNofEvents number of events
242bb794 142 * @return number of reconstructed events, neg error code if failed
53feaef5 143 */
144 int Run(Int_t iNofEvents=1);
145
146 /**
9ce4bf4a 147 * Init all tasks from the list.
148 * The @ref AliHLTTask::Init method is called for each task, the components
149 * will be created.
150 * @return neg error code if failed
151 */
152 int InitTasks();
153
154 /**
90ebac25 155 * Init the stopwatches for all tasks.
156 * @param pStopwatches object array of stopwatches, for types
157 * @see AliHLTComponent::AliHLTStopwatchType
158 * @return neg error code if failed
159 */
160 int InitBenchmarking(TObjArray* pStopwatches);
161
162 /**
53feaef5 163 * Start task list.
70ed7d01 164 * The @ref AliHLTTask::StartRun method is called for each task, the
165 * components will be prepared for event processing.
53feaef5 166 * @return neg error code if failed
167 */
168 int StartTasks();
169
170 /**
171 * Process task list.
172 * The @ref AliHLTTask::ProcessTask method is called for each task.
173 * @return neg error code if failed
174 */
175 int ProcessTasks(Int_t eventNo);
176
177 /**
178 * Stop task list.
179 * The @ref AliHLTTask::EndRun method is called for each task, the components
180 * will be cleaned after event processing.
181 * @return neg error code if failed
5ec8e281 182 */
53feaef5 183 int StopTasks();
5ec8e281 184
9ce4bf4a 185 /**
186 * De-init all tasks from the list.
187 * The @ref AliHLTTask::Deinit method is called for each task, the components
188 * will be deleted.
189 * @return neg error code if failed
190 */
191 int DeinitTasks();
192
193 /**
194 * The memory allocation function for components.
195 * This function is part of the running environment of the components.
196 */
197 static void* AllocMemory( void* param, unsigned long size );
198
242bb794 199 /**
200 * Reconstruction inside AliRoot.
201 * To be called by the AliHLTReconstructor plugin during the
202 * LocalReconstruction step of the AliRoot reconstruction. The latter means
203 * that all events are reconstructed at once, the event loop is internally
204 * implemented. In contrast to that, the FillESD method is called event by
205 * event. This requires an 'ESD' recorder at the end of the HLT chain, in
206 * order to have the reconstructed events available for the FillESD loop.
207 * The 'runLoader' and 'rawReader' parameters are set to all active
208 * AliHLTOfflineDataSource's and the HLT chain is processed for the given
209 * number of events. If the rawReader is NULL, reconstruction is done on
210 * simulated data, from real data if a RawReader is specified.
211 * @param nofEvents number of events
212 * @param runLoader the AliRoot runloader
213 * @param rawReader the AliRoot RawReader
214 * @return number of reconstructed events, neg. error code if failed
215 */
216 int Reconstruct(int nofEvents, AliRunLoader* runLoader,
217 AliRawReader* rawReader=NULL);
218
219 /**
220 * Fill ESD for one event.
221 * To be called by the AliHLTReconstructor plugin during the event loop
222 * and FillESD method of the AliRoot reconstruction.
223 * This method is called on event basis, and thus must copy the previously
224 * reconstructed data of the event from the 'ESD' recorder. The FillESD
225 * method of all active AliHLTOfflineDataSink's is called.
226 * @param eventNo current event no (Note: this event number is just a
227 * processing counter and is not related to the nature/
228 * origin of the event
229 * @param runLoader the AliRoot runloader
af885e0f 230 * @param esd an AliESDEvent instance
242bb794 231 * @return neg. error code if failed
232 */
af885e0f 233 int FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd);
242bb794 234
235 /**
236 * Load component libraries.
237 * @param libs string of blank separated library names
238 * @return neg. error code if failed
239 */
240 int LoadComponentLibraries(const char* libs);
241
242 /**
85f0cede 243 * Find a symbol in a dynamically loaded library.
244 * @param library library
245 * @param symbol the symbol to find
246 * @return void pointer to function
247 */
248 void* FindDynamicSymbol(const char* library, const char* symbol);
249
250 /**
242bb794 251 * Prepare the HLT system for running.
252 * - module agents are requested to register configurations
253 * - task lists are built from the top configurations of the modules
c043fa2c 254 *
255 * @param runloader optional instance of the run loader
242bb794 256 * @return neg. error code if failed <br>
257 * -EBUSY system is in kRunning state <br>
258 */
259 int Configure(AliRunLoader* runloader=NULL);
260
c043fa2c 261
262 /**
263 * Scan options.
264 * Known options
265 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formating -->
266 * \li loglevel=<i>level</i> <br>
267 * logging level for this processing
268 * \li alilog=off
269 * disable redirection of log messages to AliLog class
270 * \li config=<i>macro</i>
271 * configuration macro
272 * \li localrec=<i>configuration</i>
273 * comma separated list of configurations to be run during local
274 * reconstruction
275 */
276 int ScanOptions(const char* options);
277
242bb794 278 /**
279 * Reset the HLT system.
280 * Reset is not possible while the system is in running state.
281 * @param bForce force the reset
282 * @return neg. error code if failed <br>
283 * -EBUSY system is in kRunning state <br>
284 */
285 int Reset(int bForce=0);
286
287 /**
288 * Load the configurations specified by the module agents.
289 * The runLoader is passed to the agent and allows configuration
290 * selection.
291 * @return neg. error code if failed
292 */
293 int LoadConfigurations(AliRunLoader* runloader=NULL);
294
295 /**
296 * Get the top configurations of all agents and build the task lists.
297 * @return neg. error code if failed
298 */
299 int BuildTaskListsFromTopConfigurations(AliRunLoader* runloader=NULL);
300
9253e11b 301 enum AliHLTSystemState_t {
242bb794 302 kUninitialized = 0x0,
303 kLibrariesLoaded = 0x1,
304 kConfigurationLoaded = 0x2,
305 kTaskListCreated = 0x4,
306 kReady = 0x7,
307 kRunning = 0x8,
308 kError = 0x1000
9253e11b 309 };
242bb794 310
311 /**
312 * Check status of the system.
313 * @param flag AliHLTSystemState_t value to check for
314 * @return 1 if set, 0 if not
315 */
316 int CheckStatus(int flag);
317
318 /**
319 * Get the current status.
320 * @return status flags of @ref AliHLTSystemState_t
321 */
322 int GetStatusFlags();
323
5ec8e281 324 protected:
5ec8e281 325
326 private:
c043fa2c 327 /** copy constructor prohibited */
328 AliHLTSystem(const AliHLTSystem&);
329 /** assignment operator prohibited */
330 AliHLTSystem& operator=(const AliHLTSystem&);
331
242bb794 332 /**
333 * Set status flags.
334 */
335 int SetStatusFlags(int flags);
336
337 /**
338 * clear status flags.
339 */
340 int ClearStatusFlags(int flags);
341
c043fa2c 342
85869391 343/* TList fConfList; */
344/* int fbListChanged; */
5ec8e281 345
242bb794 346 /** list of tasks */
70ed7d01 347 TList fTaskList; // see above
f23a6e1a 348
fc455fba 349 /** the number of instances of AliHLTSystem */
350 static int fgNofInstances; // see above
351
242bb794 352 /** state of the object */
353 int fState; // see above
354
c043fa2c 355 /** configurations to be run during local reconstruction */
356 TString fLocalRec; //!transient
357
5ec8e281 358 private:
c043fa2c 359 ClassDef(AliHLTSystem, 3);
f23a6e1a 360};
f23a6e1a 361
c043fa2c 362#endif