]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTSystem.h
added support for symbol lookup in dynamically loaded libraries; minor warning removed
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTSystem.h
1 // @(#) $Id$
2
3 #ifndef ALIHLTSYSTEM_H
4 #define ALIHLTSYSTEM_H
5 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6  * See cxx source for full Copyright notice                               */
7
8 /** @file   AliHLTSystem.h
9     @author Matthias Richter
10     @date   
11     @brief  Global HLT module management and AliRoot integration.
12     @note   The class is used in Offline (AliRoot) context
13 */
14
15 /**
16  * @defgroup alihlt_system HLT integration into AliRoot
17  * This section describes the HLT integration into AliRoot.
18  */
19
20 #include "AliHLTLogging.h"
21 #include <TList.h>
22
23 class AliHLTComponentHandler;
24 class AliHLTConfiguration;
25 class AliHLTConfigurationHandler;
26 class AliHLTTask;
27 class AliRunLoader;
28 class AliRawReader;
29 class AliESD;
30 class TObjArray;
31 class TStopwatch;
32
33 /**
34  * @class AliHLTSystem
35  * Main class for the HLT integration into AliRoot.
36  * The class handles a list of configurations. Configurations are translated
37  * into task lists which can be executed. 
38  *
39  * @note This class is only used for the @ref alihlt_system.
40  *
41  * @ingroup alihlt_system
42  */
43 class AliHLTSystem : public AliHLTLogging {
44  public:
45   /** default constructor */
46   AliHLTSystem();
47   /** not a valid copy constructor, defined according to effective C++ style */
48   AliHLTSystem(const AliHLTSystem&);
49   /** not a valid assignment op, but defined according to effective C++ style */
50   AliHLTSystem& operator=(const AliHLTSystem&);
51   /** destructor */
52   virtual ~AliHLTSystem();
53
54   /**
55    * Pointer to an instance of @ref AliHLTComponentHandler.
56    */
57   AliHLTComponentHandler* fpComponentHandler;                      //! transient
58
59   /**
60    * Pointer to an instance of @ref AliHLTConfigurationHandler.
61    */
62   AliHLTConfigurationHandler* fpConfigurationHandler;              //! transient
63
64   /**
65    * Add a configuration to the end of the list.
66    * @param pConf    pointer to configuration to add
67    */
68   int AddConfiguration(AliHLTConfiguration* pConf);
69
70   /**
71    * Insert a configuration to the end of the list after the specified
72    * configuration.
73    * @param pConf    pointer to configuration to insert
74    * @param pPrec    pointer to configuration to insert the new one after
75    */
76   int InsertConfiguration(AliHLTConfiguration* pConf, AliHLTConfiguration* pPrec);
77
78   /**
79    * Remove a configuration from the list.
80    * @param pConf    pointer to configuration to delete
81    */
82   int DeleteConfiguration(AliHLTConfiguration* pConf);
83
84   /**
85    * Build a task list from a configuration object.
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.
93    * @param pConf    pointer to configuration to build the task list from
94    */
95   int BuildTaskList(AliHLTConfiguration* pConf);
96
97   /**
98    * Clean the list of tasks and delete all the task objects.
99    */
100   int CleanTaskList();
101
102   /**
103    * Insert a task to the task list.
104    * The method first checks whether all dependencies are resolved (i.e. exist 
105    * already in the task list). During this iteration the cross links between
106    * the tasks are set as well. If all dependencies are resolved, the task is
107    * added at the end of the list.
108    * @param pTask    pointer to task to add
109    */
110   int InsertTask(AliHLTTask* pTask);
111
112   /**
113    * Find a task with an id.
114    * @param id       CONFIGURATION id (not a COMPONENT id!)
115    */
116   AliHLTTask* FindTask(const char* id);
117
118   /**
119    * Print the task list.
120    */
121   void PrintTaskList();
122
123   /**
124    * Run the task list.
125    * The method checks whether the task list has already been build. If not,
126    * or the configuration list has been changed, the @ref BuildTaskList
127    * method is scalled
128    * All tasks of the list will be subsequently processed for each event.
129    * @param iNofEvents number of events
130    * @return number of reconstructed events, neg error code if failed
131    */
132   int Run(Int_t iNofEvents=1);
133
134   /**
135    * Init all tasks from the list.
136    * The @ref AliHLTTask::Init method is called for each task, the components
137    * will be created.
138    * @return neg error code if failed
139    */
140   int InitTasks();
141
142   /**
143    * Init the stopwatches for all tasks.
144    * @param pStopwatches    object array of stopwatches, for types
145    *                        @see AliHLTComponent::AliHLTStopwatchType
146    * @return neg error code if failed
147    */
148   int InitBenchmarking(TObjArray* pStopwatches);
149
150   /**
151    * Start task list.
152    * The @ref AliHLTTask::StartRun method is called for each task, the
153    * components will be prepared for event processing.
154    * @return neg error code if failed
155    */
156   int StartTasks();
157
158   /**
159    * Process task list.
160    * The @ref AliHLTTask::ProcessTask method is called for each task.
161    * @return neg error code if failed
162    */
163   int ProcessTasks(Int_t eventNo);
164
165   /**
166    * Stop task list.
167    * The @ref AliHLTTask::EndRun method is called for each task, the components
168    * will be cleaned after event processing.
169    * @return neg error code if failed
170    */
171   int StopTasks();
172
173   /**
174    * De-init all tasks from the list.
175    * The @ref AliHLTTask::Deinit method is called for each task, the components
176    * will be deleted.
177    * @return neg error code if failed
178    */
179   int DeinitTasks();
180
181   /**
182    * The memory allocation function for components.
183    * This function is part of the running environment of the components.
184    */
185   static void* AllocMemory( void* param, unsigned long size );
186
187   /**
188    * Reconstruction inside AliRoot.
189    * To be called by the AliHLTReconstructor plugin during the
190    * LocalReconstruction step of the AliRoot reconstruction. The latter means
191    * that all events are reconstructed at once, the event loop is internally
192    * implemented. In contrast to that, the FillESD method is called event by
193    * event. This requires an 'ESD' recorder at the end of the HLT chain, in
194    * order to have the reconstructed events available for the FillESD loop.
195    * The 'runLoader' and 'rawReader' parameters are set to all active
196    * AliHLTOfflineDataSource's and the HLT chain is processed for the given
197    * number of events. If the rawReader is NULL, reconstruction is done on
198    * simulated data, from real data if a RawReader is specified.
199    * @param nofEvents     number of events
200    * @param runLoader     the AliRoot runloader
201    * @param rawReader     the AliRoot RawReader
202    * @return number of reconstructed events, neg. error code if failed 
203    */
204   int Reconstruct(int nofEvents, AliRunLoader* runLoader, 
205                   AliRawReader* rawReader=NULL);
206
207   /**
208    * Fill ESD for one event.
209    * To be called by the AliHLTReconstructor plugin during the event loop
210    * and FillESD method of the AliRoot reconstruction.
211    * This method is called on event basis, and thus must copy the previously
212    * reconstructed data of the event from the 'ESD' recorder. The FillESD
213    * method of all active AliHLTOfflineDataSink's is called.
214    * @param eventNo       current event no (Note: this event number is just a
215    *                      processing counter and is not related to the nature/
216    *                      origin of the event
217    * @param runLoader     the AliRoot runloader
218    * @param esd           an AliESD instance
219    * @return neg. error code if failed 
220    */
221   int FillESD(int eventNo, AliRunLoader* runLoader, AliESD* esd);
222
223   /**
224    * Load component libraries.
225    * @param libs          string of blank separated library names
226    * @return neg. error code if failed 
227    */
228   int LoadComponentLibraries(const char* libs);
229
230   /**
231    * Find a symbol in a dynamically loaded library.
232    * @param library      library
233    * @param symbol       the symbol to find
234    * @return void pointer to function
235    */
236   void* FindDynamicSymbol(const char* library, const char* symbol);
237
238   /**
239    * Prepare the HLT system for running.
240    * - module agents are requested to register configurations
241    * - task lists are built from the top configurations of the modules
242    * @return neg. error code if failed <br>
243    *         -EBUSY      system is in kRunning state <br>
244    */
245   int Configure(AliRunLoader* runloader=NULL);
246
247   /**
248    * Reset the HLT system.
249    * Reset is not possible while the system is in running state.
250    * @param bForce       force the reset
251    * @return neg. error code if failed <br>
252    *         -EBUSY      system is in kRunning state <br>
253    */
254   int Reset(int bForce=0);
255
256   /**
257    * Load the configurations specified by the module agents.
258    * The runLoader is passed to the agent and allows configuration
259    * selection.
260    * @return neg. error code if failed 
261    */
262   int LoadConfigurations(AliRunLoader* runloader=NULL);
263
264   /**
265    * Get the top configurations of all agents and build the task lists.
266    * @return neg. error code if failed 
267    */
268   int BuildTaskListsFromTopConfigurations(AliRunLoader* runloader=NULL);
269
270   enum AliHLTSystemState_t {
271     kUninitialized       = 0x0,
272     kLibrariesLoaded     = 0x1,
273     kConfigurationLoaded = 0x2,
274     kTaskListCreated     = 0x4,
275     kReady               = 0x7,
276     kRunning             = 0x8,
277     kError               = 0x1000
278   };
279
280   /**
281    * Check status of the system.
282    * @param flag          AliHLTSystemState_t value to check for
283    * @return 1 if set, 0 if not
284    */
285   int CheckStatus(int flag);
286
287   /**
288    * Get the current status.
289    * @return status flags of @ref AliHLTSystemState_t
290    */
291   int GetStatusFlags();
292
293  protected:
294  
295  private:
296   /**
297    * Set status flags.
298    */
299   int SetStatusFlags(int flags);
300
301   /**
302    * clear status flags.
303    */
304   int ClearStatusFlags(int flags);
305
306 /*   TList fConfList; */
307 /*   int fbListChanged; */
308
309   /** list of tasks */
310   TList fTaskList;                                                 // see above
311
312   /** the number of instances of AliHLTSystem */
313   static int fgNofInstances;                                       // see above
314
315   /** state of the object */
316   int fState;                                                      // see above
317
318  private:
319   ClassDef(AliHLTSystem, 2);
320 };
321 #endif
322