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