]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - HLT/BASE/AliHLTSystem.h
Added protections in case std branches are missing
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.h
... / ...
CommitLineData
1//-*- Mode: C++ -*-
2// $Id$
3
4#ifndef ALIHLTSYSTEM_H
5#define ALIHLTSYSTEM_H
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 *
9
10// @file AliHLTSystem.h
11// @author Matthias Richter
12// @date 2007
13// @brief Global HLT module management and AliRoot integration.
14// @note The class is used in Offline (AliRoot) context
15//
16
17/**
18 * @defgroup alihlt_system HLT integration into AliRoot
19 * This section describes the HLT integration into AliRoot.
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 * In either case an HLT chain described by means of AliHLTConfiguration
29 * builds the core of any HLT application. Special components exist, which
30 * emulate the behavior 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 *
74 */
75
76#include "AliHLTLogging.h"
77#include <TList.h>
78#include <TString.h>
79
80class AliHLTComponentHandler;
81class AliHLTConfiguration;
82class AliHLTConfigurationHandler;
83class AliHLTTask;
84class AliHLTOUT;
85class AliHLTOUTTask;
86class AliHLTControlTask;
87class AliRunLoader;
88class AliRawReader;
89class AliESDEvent;
90class TObjArray;
91class TStopwatch;
92
93/**
94 * @class AliHLTSystem
95 * Main class for the HLT integration into AliRoot.
96 * @note This class is only used for the @ref alihlt_system.
97 *
98 * @section alihltsystem_overview Main functionality
99 * The class implements the main binding functionality to run HLT
100 * embedded in AliRoot:
101 * - creates handlers for HLT components (AliHLTComponentHandler)
102 * and configurations (AliHLTConfigurationHandler).
103 * - implements the creation of a task list from configurations
104 * - runs the tasks of the task list
105 * - implements the interface to AliHLTReconstructor and AliHLTSimulation
106 * - manages the registered module agents (AliHLTModuleAgent)
107 *
108 * @section alihltsystem_functions Main functions
109 * The following list gives the most important functions, see documentation
110 * of functions for details.
111 * - ScanOptions(const char*) initialize the system from arguments
112 * - BuildTaskList(const char*) build task list for a reconstruction chain
113 * - Run() processing loop for task list
114 * - Reconstruct() interface to AliHLTReconstructor
115 * - ProcessHLTOUT() process an HLTOUT colection
116 *
117 * @section alihltsystem_initialization Initialization
118 * AliHLTSystem is initialized with a list of component libraries which determine
119 * the actual functionality. See ScanOptions() for description of options.
120 *
121 * @section alihltsystem_usage Usage
122 * The class AliHLTPluginBase handles the global instance of AliHLTSystem,
123 * the instance is created and fetched like
124 * <pre>
125 * // setup the HLT system
126 * AliHLTSystem* pHLT=AliHLTPluginBase::GetInstance();
127 * </pre>
128 *
129 * @ingroup alihlt_system
130 */
131class AliHLTSystem : public AliHLTLogging {
132 public:
133 /** default constructor */
134 AliHLTSystem(AliHLTComponentLogSeverity loglevel=kHLTLogDefault, const char* name="");
135 /** destructor */
136 virtual ~AliHLTSystem();
137
138 /**
139 * Build a task list
140 * This method is used to build the list of tasks from the configuration
141 * id of a single 'master' configuration.
142 *
143 * Configuration entries might depend upon other configurations. For each
144 * configuration which has not yet been converted into an AliHLTTask, the
145 * method will be called iteratively. Finally, after building all tasks
146 * providing the input for the current one, the task is inserted to the
147 * list of tasks with the InsertTask() method.
148 *
149 * The function can be called multiple times in order to add more than one
150 * chain to the system.
151 *
152 * @param pConf configuration name/id
153 */
154 int BuildTaskList(const char* pConf);
155
156 /**
157 * Clean the list of tasks and delete all the task objects.
158 */
159 int CleanTaskList();
160
161 /**
162 * Insert a task to the task list.
163 * The method first checks whether all dependencies are resolved (i.e. exist
164 * already in the task list). During this iteration the cross links between
165 * the tasks are set as well. If all dependencies are resolved, the task is
166 * added at the end of the list.
167 * @param pTask pointer to task to add
168 */
169 int InsertTask(AliHLTTask* pTask);
170
171 /**
172 * Add HLTOUT task to the end of the task list.
173 * If one of the specified chains has output, an AliHLTOUTTask is
174 * added which controls the output. All other chains are removed from the
175 * AliHLTOUTTask input.
176 * @return 0 if no task has been added, 1 if task has been added
177 */
178 int AddHLTOUTTask(const char* chains);
179
180 AliHLTOUTTask* GetHLTOUTTask() const {return fpHLTOUTTask;}
181 AliHLTComponentHandler* GetComponentHandler() const {return fpComponentHandler;}
182 AliHLTConfigurationHandler* GetConfigurationHandler() const {return fpConfigurationHandler;}
183
184 /**
185 * Find a task with an id.
186 * @param id CONFIGURATION id (not a COMPONENT id!)
187 */
188 AliHLTTask* FindTask(const char* id);
189
190 /**
191 * Print the task list.
192 */
193 void PrintTaskList();
194
195 /**
196 * Run one or more events.
197 * Core of the processing loop. The method expects the task list to be
198 * already created by a previous call to BuildTaskList(const char*)
199 *
200 * All tasks of the list will be subsequently processed for each event.
201 * The system can remain started if the \em bStop parameter is 0. In that
202 * case the system just waits for the next event. A specific call with
203 * nofEvents==0 is needed to execute the stop sequence.
204 * @param iNofEvents number of events
205 * @param bStop stop the chain after processing
206 * @param trgMask ctp trigger mask from the rawreader
207 * @param timestamp timestamp of the event, read from the rawreader
208 * @param eventtype event type, read from the rawreader
209 * @param participatingDetectors the bit flags of the participating detectors
210 * as will we inserted into the Common Data Header. This should only
211 * be used for software event types.
212 * @return number of reconstructed events, neg error code if failed
213 */
214 int Run(Int_t iNofEvents, int bStop, AliHLTUInt64_t trgMask,
215 AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
216 AliHLTUInt32_t participatingDetectors = 0);
217
218 /**
219 * Run the tasklist
220 * Somehow the 64bit variable/default value did not work out on mac.
221 * Re-introducing the original function, and forwarding it.
222 */
223 int Run(Int_t iNofEvents=1, int bStop=1)
224 {return Run(iNofEvents, bStop, 0, 0, 0);}
225
226 /**
227 * Init all tasks from the list.
228 * The @ref AliHLTTask::Init method is called for each task, the components
229 * will be created.
230 * @return neg error code if failed
231 */
232 int InitTasks();
233
234 /**
235 * Init the stopwatches for all tasks.
236 * @param pStopwatches object array of stopwatches, for types
237 * @see AliHLTComponent::AliHLTStopwatchType
238 * @return neg error code if failed
239 */
240 int InitBenchmarking(TObjArray* pStopwatches);
241
242 /**
243 * Stop the stopwatches for all tasks.
244 * @param pStopwatches object array of stopwatches, for types
245 * @see AliHLTComponent::AliHLTStopwatchType
246 * @return neg error code if failed
247 */
248 int PauseBenchmarking(TObjArray* pStopwatches) const;
249
250 /**
251 * Continue the stopwatches for all tasks.
252 * @param pStopwatches object array of stopwatches, for types
253 * @see AliHLTComponent::AliHLTStopwatchType
254 * @return neg error code if failed
255 */
256 int ResumeBenchmarking(TObjArray* pStopwatches) const;
257
258 /**
259 * Print benchmarking summary.
260 * Optionak: clean up stop watches.
261 * @param pStopwatches object array of stopwatches
262 * @param bClean delete stop watches if 1
263 * @return neg error code if failed
264 */
265 int PrintBenchmarking(TObjArray* pStopwatches, int bClean=0) const;
266
267 /**
268 * Start task list.
269 * The @ref AliHLTTask::StartRun method is called for each task, the
270 * components will be prepared for event processing.
271 * @return neg error code if failed
272 */
273 int StartTasks();
274
275 /**
276 * Process task list.
277 * The @ref AliHLTTask::ProcessTask method is called for each task.
278 * @return neg error code if failed
279 */
280 int ProcessTasks(Int_t eventNo, AliHLTUInt64_t trgMask,
281 AliHLTUInt32_t timestamp, AliHLTUInt32_t eventtype,
282 AliHLTUInt32_t participatingDetectors = 0);
283
284 /**
285 * Stop task list.
286 * The @ref AliHLTTask::EndRun method is called for each task, the components
287 * will be cleaned after event processing.
288 * @return neg error code if failed
289 */
290 int StopTasks();
291
292 /**
293 * Send a control event trough the chain.
294 * All data sources in the chain are switched to publish a control event like
295 * SOR or EOR. The event is propagated in the same way as a normal event.
296 * @param dt type of the event
297 */
298 int SendControlEvent(AliHLTComponentDataType dt);
299
300 /**
301 * De-init all tasks from the list.
302 * The @ref AliHLTTask::Deinit method is called for each task, the components
303 * will be deleted.
304 * @return neg error code if failed
305 */
306 int DeinitTasks();
307
308 /**
309 * Cleanup all internal objects from HLTOUT processing.
310 */
311 int CleanHLTOUT();
312
313 /**
314 * The memory allocation function for components.
315 * This function is part of the running environment of the components,
316 * see AliHLTAnalysisEnvironment
317 */
318 static void* AllocMemory( void* param, unsigned long size );
319
320 /**
321 * The allocation function for component EventDoneData.
322 * This function is part of the running environment of the components,
323 * see AliHLTAnalysisEnvironment
324 */
325 static int AllocEventDoneData( void* param, AliHLTEventID_t eventID, unsigned long size, AliHLTComponentEventDoneData** edd );
326
327 /**
328 * AliRoot embedded reconstruction.
329 * Main entry point to execute the HLT reconstruction from AliRoot. Called
330 * either by the AliHLTReconstructor plugin during AliRoot reconstruction
331 * of raw data, or AliHLTSimulation during simulation of data.
332 *
333 * The two cases are distinguished by the availablility of the AliRunLoader
334 * and raw reader.
335 * - AliRoot simulation: AliRunLoader is available and is propagated to the
336 * module agents (AliHLTModuleAgent) to generate the corresponding
337 * configurations and chains, and to the AliHLTOfflineSource components.
338 * raw reader might be available depending on whether raw data was
339 * simulated or not.
340 * - AliRoot reconstruction: raw reader is available and is propagated to
341 * the agents and AliHLTOfflineSource components. AliRunLoader is always
342 * NULL.
343 *
344 * The system remains started after the processing and just waits for the
345 * next event. A specific call with nofEvents==0 is needed to execute the
346 * stop sequence.
347 *
348 * The 'runLoader' and 'rawReader' parameters are propagated to all active
349 * AliHLTOfflineDataSource's and the HLT chain is processed for the given
350 * number of events. If the rawReader is NULL, reconstruction is done on
351 * simulated data, from real data if a RawReader is specified.
352 *
353 * After setting up the system with the reconstruction parameters the
354 * Run() method is called and carries out the processing of the chain.
355 *
356 * @param nofEvents number of events
357 * @param runLoader the AliRoot RunLoader
358 * @param rawReader the AliRoot RawReader
359 * @return number of reconstructed events, neg. error code if failed
360 */
361 int Reconstruct(int nofEvents, AliRunLoader* runLoader,
362 AliRawReader* rawReader=NULL);
363
364 /**
365 * Fill ESD for one event.
366 * To be called by the AliHLTReconstructor plugin during the event loop
367 * and FillESD method of the AliRoot reconstruction.
368 *
369 * The method is most likely deprecated as the scheme has been slightly
370 * changed. The ESD is filled by the HLTOUT handlers implemented by the
371 * HLT modules rather than by components within the reconstruction chain.
372 * Still, HLT reconstruction chains can be run during the AliRoot
373 * reconstruction, data produced by such chains is automatically added
374 * to the HLTOUT stream in order to be equivalent to the online HLT.
375 * The HLTOUT is processed during AliReconstruction at the end of the
376 * HLT event processing, literally during the FillESD method of the AliRoot
377 * reconstruction interface. The HLT module must implement HLTOUT handlers
378 * and provide those through the module agent.
379 *
380 * @param eventNo current event no (Note: this event number is just a
381 * processing counter and is not related to the nature/
382 * origin of the event
383 * @param runLoader the AliRoot runloader
384 * @param esd an AliESDEvent instance
385 * @return neg. error code if failed
386 */
387 int FillESD(int eventNo, AliRunLoader* runLoader, AliESDEvent* esd);
388
389 /**
390 * Process the HLTOUT data.
391 * The provided instance of AliHLTOUT provides the access to the data.
392 * AliHLTSystem queries all registered module agents (AliHLTModuleAgent)
393 * for the ability to treat a specific data block. As the last step the
394 * ESD object is filled. Please note that the provided ESD is the hltEsd
395 * in case of AliReconstructor (switched in AliReconstruction).
396 */
397 int ProcessHLTOUT(AliHLTOUT* pHLTOUT, AliESDEvent* esd);
398
399 /**
400 * Process all kChain-type data blocks of the HLTOUT data.
401 * Handlers of type AliHLTModuleAgent::kChain are executed as the first
402 * step of the processing. The function is invoked from ProcessHLTOUT(),
403 * eventual output of the chain is added to the HLTOUT collection.
404 */
405 int ProcessHLTOUTkChain(AliHLTOUT* pHLTOUT);
406
407 /**
408 * Load component libraries.
409 * @param libs string of blank separated library names
410 * @return neg. error code if failed
411 */
412 int LoadComponentLibraries(const char* libs);
413
414 /**
415 * Find a symbol in a dynamically loaded library.
416 * @param library library
417 * @param symbol the symbol to find
418 * @return void pointer to function
419 */
420 AliHLTfctVoid FindDynamicSymbol(const char* library, const char* symbol);
421
422 /**
423 * Prepare the HLT system for running.
424 * - module agents are requested to register configurations
425 * - task lists are built from the reconstruction chains of the modules
426 *
427 * @param rawReader instance of the raw reader or NULL
428 * @param runloader optional instance of the AliRunLoader
429 * @return neg. error code if failed <br>
430 * -EBUSY system is in kRunning state <br>
431 */
432 int Configure(AliRawReader* rawReader, AliRunLoader* runloader=NULL);
433
434 /**
435 * Old method kept for backward compatibilty.
436 *
437 * @param runloader optional instance of the AliRunLoader
438 * @return neg. error code if failed <br>
439 * -EBUSY system is in kRunning state <br>
440 */
441 int Configure(AliRunLoader* runloader=NULL);
442
443 /**
444 * Scan options and load component libraries.
445 * The options consist of blank separated tokens. Libraries can be just
446 * specified by their name, and can be excluded by adding a '!'-mark in
447 * front. <br>
448 * Further options
449 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
450 * \li loglevel=<i>level</i> <br>
451 * logging level for this processing
452 * \li frameworklog=<i>level</i> <br>
453 * logging level for framework classes
454 * \li alilog=off
455 * disable redirection of log messages to AliLog class
456 * \li config=<i>macro</i>
457 * configuration macro
458 * \li chains=<i>configuration</i>
459 * comma separated list of configurations to be run during local
460 * reconstruction
461 * \li libmode=<i>static,dynamic(default)</i>
462 * libraries are persistent if loaded in mode <i>static</i>, i.e. they
463 * can't be unloaded
464 */
465 int ScanOptions(const char* options);
466
467 /**
468 * Reset the HLT system.
469 * Reset is not possible while the system is in running state.
470 * @param bForce force the reset
471 * @return neg. error code if failed <br>
472 * -EBUSY system is in kRunning state <br>
473 */
474 int Reset(int bForce=0);
475
476 /**
477 * Load the configurations specified by the module agents.
478 * The runLoader is passed to the agent and allows configuration
479 * selection.
480 * - AliSimulation: runloader valid, raw reader might be valid
481 * - AliReconstruction: runloader always NULL, raw reader valid
482 *
483 * @param rawReader instance of the raw reader or NULL
484 * @param runloader optional instance of the AliRunLoader
485 * @return neg. error code if failed
486 */
487 int LoadConfigurations(AliRawReader* rawReader, AliRunLoader* runloader=NULL);
488
489 /**
490 * Get the reconstruction chains from all agents and build the task lists.
491 * AliHLTModuleAgent implementations can define reconstruction chains
492 * depending on the availibility of AliRunLoader and AliRawReader parameters.
493 *
494 * @param rawReader instance of the raw reader or NULL
495 * @param runloader optional instance of the AliRunLoader
496 * @return neg. error code if failed
497 */
498 int BuildTaskListsFromReconstructionChains(AliRawReader* rawReader,
499 AliRunLoader* runloader=NULL);
500
501 enum AliHLTSystemState {
502 kUninitialized = 0x0,
503 kLibrariesLoaded = 0x1,
504 kConfigurationLoaded = 0x2,
505 kTaskListCreated = 0x4,
506 kReady = 0x7,
507 kStarted = 0x8,
508 kRunning = 0x10,
509 kError = 0x1000
510 };
511
512 /**
513 * Check status of the system.
514 * @param flag AliHLTSystemState value to check for
515 * @return 1 if set, 0 if not
516 */
517 int CheckStatus(int flag);
518
519 /**
520 * Get the current status.
521 * @return status flags of @ref AliHLTSystemState
522 */
523 int GetStatusFlags();
524
525 /**
526 * Set logging level for framework classes.
527 * This sets the local logging level of this instance and all subsequent
528 * framework classes to \em level.
529 * @param level local logging level for the framework classes
530 */
531 void SetFrameworkLog(AliHLTComponentLogSeverity level);
532
533 /**
534 * Customized logging function.
535 * The name of the system and pointer is added at the beginning of each
536 * message if name was set.
537 */
538 int LoggingVarargs(AliHLTComponentLogSeverity severity,
539 const char* originClass, const char* originFunc,
540 const char* file, int line, ... ) const;
541
542 protected:
543
544 private:
545 /** copy constructor prohibited */
546 AliHLTSystem(const AliHLTSystem&);
547 /** assignment operator prohibited */
548 AliHLTSystem& operator=(const AliHLTSystem&);
549
550 /**
551 * Build task list from a configuration object.
552 * This method implements the configuration parsing and transformation into
553 * a list of AliHLTTask objects. It has been made private in April 2007.
554 * Use BuildTaskList(const char*) instead.
555 *
556 * @param pConf pointer to configuration to build the task list from
557 */
558 int BuildTaskList(AliHLTConfiguration* pConf);
559
560 /**
561 * Set status flags.
562 */
563 int SetStatusFlags(int flags);
564
565 /**
566 * clear status flags.
567 */
568 int ClearStatusFlags(int flags);
569
570 /// Pointer to an instance of @ref AliHLTComponentHandler.
571 AliHLTComponentHandler* fpComponentHandler; //! transient
572
573 /// Pointer to an instance of @ref AliHLTConfigurationHandler.
574 AliHLTConfigurationHandler* fpConfigurationHandler; //! transient
575
576 /** list of tasks */
577 TList fTaskList; // see above
578
579 /** the number of instances of AliHLTSystem */
580 static int fgNofInstances; // see above
581
582 /** state of the object */
583 int fState; // see above
584
585 /** chains to be run during reconstruction */
586 TString fChains; //!transient
587
588 /** array of stopwatches */
589 TObjArray* fStopwatches; //!transient
590
591 /** number of events processed in total */
592 int fEventCount; //!transient
593
594 /** number of events processed successfully */
595 int fGoodEvents; //!transient
596
597 /** array of default libraries */
598 static const char* fgkHLTDefaultLibs[]; //!transient
599
600 /** active kChain handlers (AliHLTOUT::AliHLTOUTHandlerListEntryVector*) */
601 void* fpChainHandlers; //!transient
602
603 /** active kEsd handlers (AliHLTOUT::AliHLTOUTHandlerListEntryVector*) */
604 void* fpEsdHandlers; //!transient
605
606 /** active kProprietary handlers (AliHLTOUT::AliHLTOUTHandlerListEntryVector*) */
607 void* fpProprietaryHandlers; //!transient
608
609 /** active HLTOUT task for the reconstruction */
610 AliHLTOUTTask* fpHLTOUTTask; //!transient
611
612 /** special task to publish the control events */
613 AliHLTControlTask* fpControlTask; //!transient
614
615 /** name of this system instance */
616 TString fName; //!transient
617
618 /// ECS parameter string
619 TString fECSParams; //!transient
620
621 ClassDef(AliHLTSystem, 13);
622};
623
624#endif