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