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