CCUSB reader from Rachid Guernane for SuperModule calibration - added to EMCAL base...
[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
c5123824 6//* This file is property of and copyright by the ALICE HLT Project *
7//* ALICE Experiment at CERN, All rights reserved. *
8//* See cxx source for full Copyright notice *
f23a6e1a 9
b22e91eb 10/** @file AliHLTSystem.h
11 @author Matthias Richter
12 @date
13 @brief Global HLT module management and AliRoot integration.
14 @note The class is used in Offline (AliRoot) context
15*/
f23a6e1a 16
b22e91eb 17/**
18 * @defgroup alihlt_system HLT integration into AliRoot
19 * This section describes the HLT integration into AliRoot.
20 */
f23a6e1a 21
5ec8e281 22#include "AliHLTLogging.h"
23#include <TList.h>
c043fa2c 24#include <TString.h>
f23a6e1a 25
5ec8e281 26class AliHLTComponentHandler;
27class AliHLTConfiguration;
85465857 28class AliHLTConfigurationHandler;
5ec8e281 29class AliHLTTask;
c5123824 30class AliHLTOUT;
f3c1d403 31class AliHLTOUTTask;
19b5c321 32class AliHLTControlTask;
242bb794 33class AliRunLoader;
34class AliRawReader;
af885e0f 35class AliESDEvent;
90ebac25 36class TObjArray;
37class TStopwatch;
f23a6e1a 38
bfccbf68 39/**
40 * @class AliHLTSystem
41 * Main class for the HLT integration into AliRoot.
42 * The class handles a list of configurations. Configurations are translated
43 * into task lists which can be executed.
44 *
b22e91eb 45 * @note This class is only used for the @ref alihlt_system.
46 *
47 * @ingroup alihlt_system
bfccbf68 48 */
5ec8e281 49class AliHLTSystem : public AliHLTLogging {
50 public:
bfccbf68 51 /** default constructor */
19b5c321 52 AliHLTSystem(AliHLTComponentLogSeverity loglevel=kHLTLogDefault, const char* name="");
bfccbf68 53 /** destructor */
f23a6e1a 54 virtual ~AliHLTSystem();
55
bfccbf68 56 /**
57 * Pointer to an instance of @ref AliHLTComponentHandler.
3b35e87c 58 */
70ed7d01 59 AliHLTComponentHandler* fpComponentHandler; //! transient
bfccbf68 60
61 /**
62 * Pointer to an instance of @ref AliHLTConfigurationHandler.
63 */
70ed7d01 64 AliHLTConfigurationHandler* fpConfigurationHandler; //! transient
f23a6e1a 65
bfccbf68 66 /**
67 * Add a configuration to the end of the list.
68 * @param pConf pointer to configuration to add
5ec8e281 69 */
70 int AddConfiguration(AliHLTConfiguration* pConf);
71
bfccbf68 72 /**
70ed7d01 73 * Insert a configuration to the end of the list after the specified
74 * configuration.
bfccbf68 75 * @param pConf pointer to configuration to insert
76 * @param pPrec pointer to configuration to insert the new one after
5ec8e281 77 */
78 int InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec);
79
bfccbf68 80 /**
81 * Remove a configuration from the list.
82 * @param pConf pointer to configuration to delete
5ec8e281 83 */
84 int DeleteConfiguration(AliHLTConfiguration* pConf);
85
bfccbf68 86 /**
a742f6f8 87 * Build a task list
3b35e87c 88 * This method is used to build the tasks from the 'master' configuration
89 * objects which are added to the HLT system handler. This is an iterative
90 * process since the task might depend upon other configurations. For each
91 * configuration object which has not yet been converted into a task, the
92 * method will be called iteratively. Finally, after building all tasks which
93 * the current one depends on have been created, the task is inserted to the
94 * list of tasks with the InsertTask method.
a742f6f8 95 * @param pConf configuration name/id
96 */
97 int BuildTaskList(const char* pConf);
98
99 /**
100 * Build task list from a configuration object.
101 * This method is kept for backward compatibility. Use the version
102 * with the configuration name.
bfccbf68 103 * @param pConf pointer to configuration to build the task list from
5ec8e281 104 */
105 int BuildTaskList(AliHLTConfiguration* pConf);
106
bfccbf68 107 /**
108 * Clean the list of tasks and delete all the task objects.
3b35e87c 109 */
5ec8e281 110 int CleanTaskList();
111
bfccbf68 112 /**
113 * Insert a task to the task list.
114 * The method first checks whether all dependencies are resolved (i.e. exist
70ed7d01 115 * already in the task list). During this iteration the cross links between
116 * the tasks are set as well. If all dependencies are resolved, the task is
117 * added at the end of the list.
bfccbf68 118 * @param pTask pointer to task to add
3b35e87c 119 */
5ec8e281 120 int InsertTask(AliHLTTask* pTask);
121
bfccbf68 122 /**
19b5c321 123 * Add HLTOUT task to the end of the task list.
124 * If one of the specified chains has output, an AliHLTOUTTask is
125 * added which controls the output. All other chains are removed from the
126 * AliHLTOUTTask input.
127 * @return 0 if no task has been added, 1 if task has been added
128 */
129 int AddHLTOUTTask(const char* chains);
130
131 AliHLTOUTTask* GetHLTOUTTask() const {return fpHLTOUTTask;}
132
133 /**
bfccbf68 134 * Find a task with an id.
135 * @param id CONFIGURATION id (not a COMPONENT id!)
3b35e87c 136 */
5ec8e281 137 AliHLTTask* FindTask(const char* id);
138
bfccbf68 139 /**
140 * Print the task list.
3b35e87c 141 */
5ec8e281 142 void PrintTaskList();
143
53feaef5 144 /**
145 * Run the task list.
9ce4bf4a 146 * The method checks whether the task list has already been build. If not,
147 * or the configuration list has been changed, the @ref BuildTaskList
dee38f1b 148 * method is called. <br>
53feaef5 149 * All tasks of the list will be subsequently processed for each event.
dee38f1b 150 * The system can remain started if the \em bStop parameter is 0. In that
151 * case the system just waits for the next event. A specific call with
152 * nofEvents==0 is needed to execute the stop sequence.
53feaef5 153 * @param iNofEvents number of events
dee38f1b 154 * @param bStop stop the chain after processing
242bb794 155 * @return number of reconstructed events, neg error code if failed
53feaef5 156 */
dee38f1b 157 int Run(Int_t iNofEvents=1, int bStop=1);
53feaef5 158
159 /**
9ce4bf4a 160 * Init all tasks from the list.
161 * The @ref AliHLTTask::Init method is called for each task, the components
162 * will be created.
163 * @return neg error code if failed
164 */
165 int InitTasks();
166
167 /**
90ebac25 168 * Init the stopwatches for all tasks.
169 * @param pStopwatches object array of stopwatches, for types
170 * @see AliHLTComponent::AliHLTStopwatchType
171 * @return neg error code if failed
172 */
173 int InitBenchmarking(TObjArray* pStopwatches);
174
175 /**
032c5e5e 176 * Stop the stopwatches for all tasks.
177 * @param pStopwatches object array of stopwatches, for types
178 * @see AliHLTComponent::AliHLTStopwatchType
179 * @return neg error code if failed
180 */
181 int PauseBenchmarking(TObjArray* pStopwatches) const;
182
183 /**
184 * Continue the stopwatches for all tasks.
185 * @param pStopwatches object array of stopwatches, for types
186 * @see AliHLTComponent::AliHLTStopwatchType
187 * @return neg error code if failed
188 */
189 int ResumeBenchmarking(TObjArray* pStopwatches) const;
190
191 /**
dee38f1b 192 * Print benchmarking summary.
193 * Optionak: clean up stop watches.
194 * @param pStopwatches object array of stopwatches
195 * @param bClean delete stop watches if 1
196 * @return neg error code if failed
197 */
032c5e5e 198 int PrintBenchmarking(TObjArray* pStopwatches, int bClean=0) const;
dee38f1b 199
200 /**
53feaef5 201 * Start task list.
70ed7d01 202 * The @ref AliHLTTask::StartRun method is called for each task, the
203 * components will be prepared for event processing.
53feaef5 204 * @return neg error code if failed
205 */
206 int StartTasks();
207
208 /**
209 * Process task list.
210 * The @ref AliHLTTask::ProcessTask method is called for each task.
211 * @return neg error code if failed
212 */
213 int ProcessTasks(Int_t eventNo);
214
215 /**
216 * Stop task list.
217 * The @ref AliHLTTask::EndRun method is called for each task, the components
218 * will be cleaned after event processing.
219 * @return neg error code if failed
5ec8e281 220 */
53feaef5 221 int StopTasks();
5ec8e281 222
9ce4bf4a 223 /**
457ec821 224 * Send a control event trough the chain.
225 * All data sources in the chain are switched to publish a control event like
226 * SOR or EOR. The event is propagated in the same way as a normal event.
227 * @param dt type of the event
228 */
229 int SendControlEvent(AliHLTComponentDataType dt);
230
231 /**
9ce4bf4a 232 * De-init all tasks from the list.
233 * The @ref AliHLTTask::Deinit method is called for each task, the components
234 * will be deleted.
235 * @return neg error code if failed
236 */
237 int DeinitTasks();
238
239 /**
a472be38 240 * Cleanup all internal objects from HLTOUT processing.
241 */
242 int CleanHLTOUT();
243
244 /**
9ce4bf4a 245 * The memory allocation function for components.
246 * This function is part of the running environment of the components.
247 */
248 static void* AllocMemory( void* param, unsigned long size );
249
242bb794 250 /**
dee38f1b 251 * AliRoot embedded reconstruction.
252 * Main entry point to execute the HLT reconstruction from AliRoot. Called
253 * either by the AliHLTReconstructor plugin during AliRoot reconstruction
254 * of raw data, or AliHLTSimulation during simulation of data.
255 *
256 * The two cases are distinguished by the availablility of the run loader
257 * and raw reader.
258 * - AliRoot simulation: run loader is available and is propagated to the
259 * module agents (AliHLTModuleAgent) to generate the corresponding
260 * configurations and chains, and to the AliHLTOfflineSource components.
261 * - AliRoot reconstruction: raw reader is available and is propagated to
262 * the agents and AliHLTOfflineSource components.
263 *
264 * The system remains started after the processing and just waits for the
265 * next event. A specific call with nofEvents==0 is needed to execute the
266 * stop sequence.
267 *
242bb794 268 * The 'runLoader' and 'rawReader' parameters are set to all active
269 * AliHLTOfflineDataSource's and the HLT chain is processed for the given
270 * number of events. If the rawReader is NULL, reconstruction is done on
271 * simulated data, from real data if a RawReader is specified.
272 * @param nofEvents number of events
273 * @param runLoader the AliRoot runloader
274 * @param rawReader the AliRoot RawReader
275 * @return number of reconstructed events, neg. error code if failed
276 */
277 int Reconstruct(int nofEvents, AliRunLoader* runLoader,
278 AliRawReader* rawReader=NULL);
279
280 /**
281 * Fill ESD for one event.
282 * To be called by the AliHLTReconstructor plugin during the event loop
283 * and FillESD method of the AliRoot reconstruction.
c5123824 284 *
285 * The method is most likely deprecated as the scheme has been slightly
286 * changed. The ESD is filled by the HLTOUT handlers u=implemented by the
287 * HLT modules rather than by components within the reconstruction chain.
288 * Still, HLT reconstruction chains can be run during the AliRoot
289 * reconstruction, data produced by such chains is automatically added
290 * to the HLTOUT stream in order to be equivalent to the online HLT.
291 * The HLTOUT is processed during AliReconstruction at the end of the
292 * HLT event processing, literally during the FillESD method of the AliRoot
293 * reconstruction interface. The HLT module must implement HLTOUT handlers
294 * and provide those through the module agent.
295 *
242bb794 296 * This method is called on event basis, and thus must copy the previously
297 * reconstructed data of the event from the 'ESD' recorder. The FillESD
298 * method of all active AliHLTOfflineDataSink's is called.
299 * @param eventNo current event no (Note: this event number is just a
300 * processing counter and is not related to the nature/
301 * origin of the event
302 * @param runLoader the AliRoot runloader
af885e0f 303 * @param esd an AliESDEvent instance
242bb794 304 * @return neg. error code if failed
305 */
af885e0f 306 int FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd);
242bb794 307
308 /**
c5123824 309 * Process the HLTOUT data.
310 */
311 int ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd);
312
313 /**
0f1882a7 314 * Process all kChain-type data blocks of the HLTOUT data.
315 * The function is involed from ProcessHLTOUT as the first step in
316 * the processing.
317 */
318 int ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT);
319
320 /**
242bb794 321 * Load component libraries.
322 * @param libs string of blank separated library names
323 * @return neg. error code if failed
324 */
325 int LoadComponentLibraries(const char* libs);
326
327 /**
85f0cede 328 * Find a symbol in a dynamically loaded library.
329 * @param library library
330 * @param symbol the symbol to find
331 * @return void pointer to function
332 */
333 void* FindDynamicSymbol(const char* library, const char* symbol);
334
335 /**
242bb794 336 * Prepare the HLT system for running.
337 * - module agents are requested to register configurations
338 * - task lists are built from the top configurations of the modules
c043fa2c 339 *
dee38f1b 340 * @param rawReader instance of the raw reader or NULL
c043fa2c 341 * @param runloader optional instance of the run loader
242bb794 342 * @return neg. error code if failed <br>
343 * -EBUSY system is in kRunning state <br>
344 */
dee38f1b 345 int Configure(AliRawReader* rawReader, AliRunLoader* runloader=NULL);
242bb794 346
dee38f1b 347 /**
348 * Old method kept for backward compatibilty.
349 *
350 * @param runloader optional instance of the run loader
351 * @return neg. error code if failed <br>
352 * -EBUSY system is in kRunning state <br>
353 */
354 int Configure(AliRunLoader* runloader=NULL);
c043fa2c 355
356 /**
b005ef92 357 * Scan options and load component libraries.
358 * The options consist of blank separated tokens. Libraries can be just
359 * specified by their name. Further options
1ac82ce6 360 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
c043fa2c 361 * \li loglevel=<i>level</i> <br>
362 * logging level for this processing
dba03d72 363 * \li frameworklog=<i>level</i> <br>
364 * logging level for framework classes
c043fa2c 365 * \li alilog=off
366 * disable redirection of log messages to AliLog class
367 * \li config=<i>macro</i>
368 * configuration macro
dee38f1b 369 * \li chains=<i>configuration</i>
c043fa2c 370 * comma separated list of configurations to be run during local
371 * reconstruction
dba03d72 372 * \li libmode=<i>static,dynamic(default)</i>
373 * libraries are persistent if loaded in mode <i>static</i>, i.e. they
374 * can't be unloaded
c043fa2c 375 */
376 int ScanOptions(const char* options);
377
242bb794 378 /**
379 * Reset the HLT system.
380 * Reset is not possible while the system is in running state.
381 * @param bForce force the reset
382 * @return neg. error code if failed <br>
383 * -EBUSY system is in kRunning state <br>
384 */
385 int Reset(int bForce=0);
386
387 /**
388 * Load the configurations specified by the module agents.
389 * The runLoader is passed to the agent and allows configuration
390 * selection.
dee38f1b 391 * @param rawReader instance of the raw reader or NULL
392 * @param runloader optional instance of the run loader
242bb794 393 * @return neg. error code if failed
394 */
dee38f1b 395 int LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader=NULL);
242bb794 396
397 /**
398 * Get the top configurations of all agents and build the task lists.
dee38f1b 399 * @param rawReader instance of the raw reader or NULL
400 * @param runloader optional instance of the run loader
242bb794 401 * @return neg. error code if failed
402 */
f3506ea2 403 int BuildTaskListsFromReconstructionChains(AliRawReader* rawReader,
404 AliRunLoader* runloader=NULL);
242bb794 405
6a8e0bb4 406 enum AliHLTSystemState {
242bb794 407 kUninitialized = 0x0,
408 kLibrariesLoaded = 0x1,
409 kConfigurationLoaded = 0x2,
410 kTaskListCreated = 0x4,
411 kReady = 0x7,
dee38f1b 412 kStarted = 0x8,
413 kRunning = 0x10,
242bb794 414 kError = 0x1000
9253e11b 415 };
242bb794 416
417 /**
418 * Check status of the system.
6a8e0bb4 419 * @param flag AliHLTSystemState value to check for
242bb794 420 * @return 1 if set, 0 if not
421 */
422 int CheckStatus(int flag);
423
424 /**
425 * Get the current status.
6a8e0bb4 426 * @return status flags of @ref AliHLTSystemState
242bb794 427 */
428 int GetStatusFlags();
429
e642a402 430 /**
431 * Set logging level for framework classes.
432 * This sets the local logging level of this instance and all subsequent
433 * framework classes to \em level.
434 * @param level local logging level for the framework classes
435 */
436 void SetFrameworkLog(AliHLTComponentLogSeverity level);
437
5ec8e281 438 protected:
5ec8e281 439
440 private:
c043fa2c 441 /** copy constructor prohibited */
442 AliHLTSystem(const AliHLTSystem&);
443 /** assignment operator prohibited */
444 AliHLTSystem& operator=(const AliHLTSystem&);
445
242bb794 446 /**
447 * Set status flags.
448 */
449 int SetStatusFlags(int flags);
450
451 /**
452 * clear status flags.
453 */
454 int ClearStatusFlags(int flags);
455
85869391 456/* TList fConfList; */
457/* int fbListChanged; */
5ec8e281 458
242bb794 459 /** list of tasks */
70ed7d01 460 TList fTaskList; // see above
f23a6e1a 461
fc455fba 462 /** the number of instances of AliHLTSystem */
463 static int fgNofInstances; // see above
464
242bb794 465 /** state of the object */
466 int fState; // see above
467
dee38f1b 468 /** chains to be run during reconstruction */
469 TString fChains; //!transient
470
6a8e0bb4 471 /** array of stopwatches */
dee38f1b 472 TObjArray* fStopwatches; //!transient
473
6a8e0bb4 474 /** number of events processed in total */
dee38f1b 475 int fEventCount; //!transient
476
6a8e0bb4 477 /** number of events processed successfully */
dee38f1b 478 int fGoodEvents; //!transient
c043fa2c 479
6a8e0bb4 480 /** array of default libraries */
481 static const char* fgkHLTDefaultLibs[]; //!transient
482
b005ef92 483 /** active kChain handlers (AliHLTOUT::AliHLTOUTHandlerListEntryVector*) */
484 void* fpChainHandlers; //!transient
485
486 /** active kEsd handlers (AliHLTOUT::AliHLTOUTHandlerListEntryVector*) */
487 void* fpEsdHandlers; //!transient
488
489 /** active kProprietary handlers (AliHLTOUT::AliHLTOUTHandlerListEntryVector*) */
490 void* fpProprietaryHandlers; //!transient
491
f3c1d403 492 /** active HLTOUT task for the reconstruction */
493 AliHLTOUTTask* fpHLTOUTTask; //!transient
494
19b5c321 495 /** special task to publish the control events */
496 AliHLTControlTask* fpControlTask; //!transient
497
498 /** name of this system instance */
499 TString fName; //!transient
500
501 ClassDef(AliHLTSystem, 12);
f23a6e1a 502};
f23a6e1a 503
c043fa2c 504#endif