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