]>
Commit | Line | Data |
---|---|---|
30338a30 | 1 | //-*- Mode: C++ -*- |
28cd9358 | 2 | // $Id$ |
f23a6e1a | 3 | |
4 | #ifndef ALIHLTCOMPONENTHANDLER_H | |
5 | #define ALIHLTCOMPONENTHANDLER_H | |
c515df4c | 6 | //* This file is property of and copyright by the * |
28cd9358 | 7 | //* ALICE Experiment at CERN, All rights reserved. * |
8 | //* See cxx source for full Copyright notice * | |
f23a6e1a | 9 | |
28cd9358 | 10 | /// @file AliHLTComponentHandler.h |
11 | /// @author Matthias Richter, Timm Steinbeck | |
12 | /// @date | |
13 | /// @brief Global handling of HLT processing components | |
14 | /// @note The handler is part of the interface and both used in the | |
15 | /// Online (PubSub) and Offline (AliRoot) context. | |
30338a30 | 16 | |
8ede8717 | 17 | #include <vector> |
f23a6e1a | 18 | #include "AliHLTDataTypes.h" |
5ec8e281 | 19 | #include "AliHLTLogging.h" |
f23a6e1a | 20 | |
c515df4c | 21 | using std::vector; |
22 | ||
f23a6e1a | 23 | class AliHLTComponent; |
f3506ea2 | 24 | class AliHLTModuleAgent; |
a3c9b745 | 25 | struct AliHLTAnalysisEnvironment; |
8ede8717 | 26 | struct AliHLTComponentDataType; |
f23a6e1a | 27 | |
fa760045 | 28 | /** |
29 | * @class AliHLTComponentHandler | |
30 | * The component handler controls all the processing components available in | |
31 | * the system. It also controls the component shared libraries. | |
32 | * @ingroup alihlt_component | |
33 | */ | |
5ec8e281 | 34 | class AliHLTComponentHandler : public AliHLTLogging { |
f23a6e1a | 35 | public: |
fa760045 | 36 | /** standard constructor */ |
f23a6e1a | 37 | AliHLTComponentHandler(); |
3cde846d | 38 | /** constructor */ |
a3c9b745 | 39 | AliHLTComponentHandler(AliHLTAnalysisEnvironment* pEnv); |
fa760045 | 40 | /** destructor */ |
f23a6e1a | 41 | virtual ~AliHLTComponentHandler(); |
42 | ||
b005ef92 | 43 | /** |
44 | * Create an instance from the global sigleton. | |
45 | * Instance has to be destroyed by the Destroy function | |
46 | */ | |
47 | static AliHLTComponentHandler* CreateHandler(); | |
48 | ||
49 | /** | |
50 | * Destroy an instance of the global singleton retrieved by | |
51 | * AliHLTComponentHandler::CreateHandler() | |
52 | */ | |
53 | int Destroy(); | |
54 | ||
dba03d72 | 55 | /** |
56 | * Library mode. | |
57 | * - kDynamic: library can be unloaded (unload forced at termination of the | |
58 | * handler | |
59 | * - kStatic: library persistent, once loaded it stays | |
60 | */ | |
61 | enum TLibraryMode {kDynamic, kStatic}; | |
62 | ||
fa760045 | 63 | /** |
64 | * Set the environment for the HLT framework. | |
65 | * The environment mainly consists of function pointers for the integration | |
66 | * of the HLT framework into a system like the PubSub online system or | |
67 | * AliRoot offline system. | |
a3c9b745 | 68 | * @param pEnv pointer to @ref AliHLTAnalysisEnvironment structure |
fa760045 | 69 | * @return none |
70 | */ | |
a3c9b745 | 71 | void SetEnvironment(AliHLTAnalysisEnvironment* pEnv); |
f23a6e1a | 72 | |
9a0ef890 | 73 | /** |
74 | * Get the current environment. | |
75 | */ | |
a3c9b745 | 76 | const AliHLTAnalysisEnvironment* GetEnvironment() const {return &fEnvironment;} |
9a0ef890 | 77 | |
dba03d72 | 78 | /** |
79 | * Set library mode. | |
80 | * The mode effects all loaded libraries until another mode is set. | |
81 | * @param mode persistent library or not | |
7bcd6cad | 82 | * @return previous mode |
dba03d72 | 83 | */ |
84 | TLibraryMode SetLibraryMode(TLibraryMode mode); | |
85 | ||
fa760045 | 86 | /** |
87 | * Load a component shared library. | |
88 | * The component library needs to be loaded from the ComponentHanler in order | |
89 | * to automatically register all components in the library. | |
90 | * Registration is done by passing a sample object of the component to the | |
91 | * handler. The object has to be valid during the whole runtime and should | |
92 | * thus be a global object which is ONLY used for the purpose of registration. | |
93 | * This also ensures automatically registration at library load time. | |
f3506ea2 | 94 | * @param libraryPath const char string containing the library name/path |
95 | * @param bActivateAgents activate agents after loading (@ref ActivateAgents) | |
fa760045 | 96 | * @return 0 if succeeded, neg. error code if failed |
97 | */ | |
dba03d72 | 98 | int LoadLibrary( const char* libraryPath, int bActivateAgents=1); |
fa760045 | 99 | |
85f0cede | 100 | /** |
101 | * Find a symbol in a dynamically loaded library. | |
102 | * @param library library | |
103 | * @param symbol the symbol to find | |
104 | * @return void pointer to function | |
105 | */ | |
f331e6c5 | 106 | AliHLTfctVoid FindSymbol(const char* library, const char* symbol); |
85f0cede | 107 | |
fa760045 | 108 | /** |
109 | * Unload a component shared library. | |
a742f6f8 | 110 | * All components will be de-registered when the last instance of the |
111 | * library was unloaded. | |
fa760045 | 112 | * @param libraryPath library name as specified to @ref LoadLibrary |
113 | * @return 0 if succeeded, neg. error code if failed | |
114 | */ | |
f23a6e1a | 115 | int UnloadLibrary( const char* libraryPath ); |
116 | ||
fa760045 | 117 | /** |
118 | * Schedule a component for registration. | |
119 | * Full registration will be done after successfull loading of the shared | |
120 | * library. | |
121 | * @param pSample a sample object of the component | |
122 | * @return neg. error code if failed | |
f23a6e1a | 123 | */ |
f23a6e1a | 124 | int ScheduleRegister(AliHLTComponent* pSample ); |
125 | ||
fa760045 | 126 | /** |
127 | * Register a component. | |
128 | * Registration is done by passing a sample object of the component to the | |
129 | * handler. The object has to be valid during the whole runtime and should | |
130 | * thus be a global object which is ONLY used for the purpose of registration. | |
f3506ea2 | 131 | * @param pSample a sample object of the component |
fa760045 | 132 | * @return neg. error code if failed |
133 | */ | |
f3506ea2 | 134 | int RegisterComponent(AliHLTComponent* pSample); |
135 | ||
136 | /** | |
137 | * Add a component and leave control of the sample object to the handler. | |
138 | * Exactly the same functionality as @ref RegisterComponent but deletes | |
139 | * the sample object at clean-up of the handler. | |
140 | * @param pSample a sample object of the component | |
141 | * @return neg. error code if failed | |
142 | */ | |
143 | int AddComponent(AliHLTComponent* pSample); | |
f23a6e1a | 144 | |
9ce4bf4a | 145 | /** |
146 | * Registers all scheduled components. | |
147 | */ | |
148 | int RegisterScheduledComponents(); | |
149 | ||
fa760045 | 150 | /** |
151 | * Deregister a component. | |
152 | * @param componentID ID of the component | |
153 | * @return neg. error code if failed | |
154 | */ | |
155 | int DeregisterComponent( const char* componentID ); | |
f23a6e1a | 156 | |
9ce4bf4a | 157 | /** |
158 | * Add standard components | |
159 | * The standard components are part of the libHLTbase library and | |
160 | * need therefore a special handling. | |
161 | */ | |
162 | int AddStandardComponents(); | |
163 | ||
164 | /** | |
165 | */ | |
cbd84228 | 166 | int DeleteOwnedComponents(); |
9ce4bf4a | 167 | |
fa760045 | 168 | /** |
169 | * Find the ID of a component with the given output data. | |
170 | * @param dtype data type descriptor | |
171 | * @param prevType can be used to iterate if there are multiple components | |
172 | * with the same output data type. | |
173 | * @return component id | |
174 | */ | |
8ede8717 | 175 | //const char* FindComponentType( AliHLTComponentDataType dtype, |
fa760045 | 176 | // const char* prevType = NULL ) |
177 | // { return NULL;} | |
178 | ||
179 | /** | |
180 | * Create a component of the given name (ID). | |
c215072c | 181 | * The method tries to find a registerd component of id \em componentID and |
182 | * calls the \em Spawn method of the template component. After successful | |
183 | * creation of a new object, the Init method is called in order to initialize | |
184 | * the environment and the component arguments. <br> | |
2d7ff710 | 185 | * The environment is the same for all components, but each component can |
186 | * have an additional private parameter \em pEnvParam.<br> | |
c215072c | 187 | * The component arguments consist of an array of strings and the array size |
188 | * in the usual manner of the main() function. | |
fa760045 | 189 | * @param componentID ID of the component to create |
2d7ff710 | 190 | * @param pEnvParam environment parameter for the component |
db16520a | 191 | * @param argc number of arguments in argv |
fa760045 | 192 | * @param argv argument array like in main() |
193 | * @param component reference to receive the create component instance | |
db16520a | 194 | * @return component pointer in component, neg. error code if failed |
fa760045 | 195 | */ |
2d7ff710 | 196 | int CreateComponent( const char* componentID, void* pEnvParam, |
9a0ef890 | 197 | int argc, const char** argv, AliHLTComponent*& component); |
198 | ||
199 | /** | |
200 | * Create component without initializing it. | |
201 | * @param componentID ID of the component to create | |
202 | * @param component reference to receive the create component instance | |
203 | */ | |
204 | int CreateComponent(const char* componentID, AliHLTComponent*& component ); | |
fa760045 | 205 | |
206 | /** | |
207 | * Create a component of the given name (ID). | |
208 | * Introduced for backward compatibility. | |
209 | * @param componentID ID of the component to create | |
2d7ff710 | 210 | * @param pEnvParam environment parameter for the component |
fa760045 | 211 | * @param component reference to receive the create component instance |
db16520a | 212 | * @return component pointer in component, neg. error code if failed |
fa760045 | 213 | */ |
2d7ff710 | 214 | int CreateComponent( const char* componentID, void* pEnvParam, |
fa760045 | 215 | AliHLTComponent*& component ) |
216 | { | |
2d7ff710 | 217 | return CreateComponent( componentID, pEnvParam, 0, NULL, component ); |
fa760045 | 218 | } |
219 | ||
45c0a780 | 220 | /** |
221 | * Set the run description. | |
222 | * The run description is set globally for all components. Each component | |
223 | * is initialized from the global run description after creation and before | |
224 | * call of AliHLTComponent::Init(). | |
225 | * | |
226 | * @param desc run descriptor, currently only the run no member is used | |
227 | * @param runType originally, run type was supposed to be a number and part | |
228 | * of the run descriptor. But it was defined as string later | |
229 | */ | |
230 | int SetRunDescription(const AliHLTRunDesc* desc, const char* runType); | |
231 | ||
f3506ea2 | 232 | /** |
233 | * Check if a registered component has output data, e.g. is of type | |
234 | * kSource or kProcessor (see @ref AliHLTComponent::TComponentType). | |
235 | * @param componentID ID of the component to create | |
236 | * @return 1 if component has output data, 0 if not <br> | |
237 | * -ENOENT if component does not exist | |
238 | */ | |
239 | int HasOutputData( const char* componentID); | |
240 | ||
fa760045 | 241 | /** |
242 | * Print registered components to stdout. | |
243 | * @return none | |
f23a6e1a | 244 | */ |
245 | void List(); | |
fa760045 | 246 | |
247 | /** | |
248 | * Announce version and compilation info of the base library. | |
249 | */ | |
250 | int AnnounceVersion(); | |
251 | ||
f3506ea2 | 252 | /** |
253 | * Find a component. | |
254 | * @param componentID ID of the component to find | |
255 | * @return index, neg. error code if failed | |
256 | */ | |
257 | int FindComponentIndex(const char* componentID); | |
258 | ||
f23a6e1a | 259 | protected: |
f23a6e1a | 260 | |
261 | private: | |
298ef463 | 262 | /** copy constructor prohibited */ |
263 | AliHLTComponentHandler(const AliHLTComponentHandler&); | |
264 | /** assignment operator prohibited */ | |
265 | AliHLTComponentHandler& operator=(const AliHLTComponentHandler&); | |
266 | ||
fa760045 | 267 | /** |
268 | * Find a component. | |
269 | * @param componentID ID of the component to find | |
270 | * @return descriptor | |
271 | */ | |
f23a6e1a | 272 | AliHLTComponent* FindComponent(const char* componentID); |
273 | ||
fa760045 | 274 | /** |
275 | * Insert component to the list | |
276 | * @param pSample sample object of the component | |
277 | * @return neg. error code if failed | |
278 | */ | |
f23a6e1a | 279 | int InsertComponent(AliHLTComponent* pSample); |
280 | ||
fa760045 | 281 | /** |
282 | * Close all libraries. | |
283 | * @return neg. error code if failed | |
284 | */ | |
f23a6e1a | 285 | int UnloadLibraries(); |
286 | ||
c215072c | 287 | /** |
f3506ea2 | 288 | * Activate all module agents with this component handler. |
289 | * The function loops over all available module agents and activates | |
290 | * each agent with this component handler. During activation, the | |
291 | * dynamic component registration is carried out by the agents version | |
292 | * of @ref AliHLTModuleAgent::RegisterComponents | |
7dbfa7c9 | 293 | * |
294 | * Agents are identified by an id which is a string containing the | |
295 | * module name. Libraries follow the naming scheme libAliHLT<MOD>.so | |
296 | * If the library name is provided and the specific agent found in the | |
297 | * list, only that one is activated. All pending agents otherwize. | |
298 | * @param library library to activate the agent for | |
299 | * @param blackList blank separated list of module ids | |
f3506ea2 | 300 | */ |
7dbfa7c9 | 301 | int ActivateAgents(const char* library=NULL, const char* blackList=NULL); |
f3506ea2 | 302 | |
55baa954 | 303 | /** |
304 | * Loop through all the agents and deregister this instance if neccessary. | |
305 | */ | |
306 | ||
307 | int DeactivateAgents() const; | |
308 | ||
faf00b0d | 309 | public: |
f3506ea2 | 310 | /** |
faf00b0d | 311 | * Compound descriptor for component libraries - must be public |
c215072c | 312 | */ |
313 | struct AliHLTLibHandle { | |
620fcee6 | 314 | AliHLTLibHandle() : fHandle(NULL), fName(NULL), fMode(kDynamic) {} |
c215072c | 315 | /** dlopen handle */ |
5df0cbb9 | 316 | void* fHandle; //! transient |
c215072c | 317 | /** name of the library, casted to TString* before use */ |
5df0cbb9 | 318 | void* fName; //! transient |
dba03d72 | 319 | /** library mode: kStatic means never unloaded */ |
320 | TLibraryMode fMode; //! transient | |
c215072c | 321 | }; |
faf00b0d | 322 | private: |
85f0cede | 323 | /** |
324 | * Find a specific library among the loaded libraries. | |
325 | * @param library library name/path | |
326 | * @return pointer to AliHLTLibHandle | |
327 | */ | |
328 | AliHLTLibHandle* FindLibrary(const char* library); | |
329 | ||
a742f6f8 | 330 | /** |
331 | * Unload a component shared library. | |
332 | * All components will be de-registered when the last instance of the | |
333 | * library was unloaded. | |
334 | * @param handle handle to the library to unload | |
335 | * @return 0 if succeeded, neg. error code if failed | |
336 | */ | |
337 | int UnloadLibrary(AliHLTComponentHandler::AliHLTLibHandle &handle); | |
338 | ||
fa760045 | 339 | /** list of registered components */ |
70ed7d01 | 340 | vector<AliHLTComponent*> fComponentList; // see above |
fa760045 | 341 | /** list of scheduled components */ |
70ed7d01 | 342 | vector<AliHLTComponent*> fScheduleList; // see above |
fa760045 | 343 | /** list of libraries */ |
70ed7d01 | 344 | vector<AliHLTLibHandle> fLibraryList; // see above |
fa760045 | 345 | /** running environment for the component */ |
a3c9b745 | 346 | AliHLTAnalysisEnvironment fEnvironment; // see above |
f3506ea2 | 347 | /** list of owned components, deleted at termination of the handler */ |
348 | vector<AliHLTComponent*> fOwnedComponents; // see above | |
dba03d72 | 349 | /** library mode effects all loaded libraries until a new mode is set */ |
350 | TLibraryMode fLibraryMode; // see above | |
f23a6e1a | 351 | |
45c0a780 | 352 | /** run descriptor */ |
353 | AliHLTRunDesc fRunDesc; //!transient | |
354 | /** run type string */ | |
355 | char* fRunType; //!transient | |
356 | ||
b005ef92 | 357 | /** the global singleton */ |
358 | static AliHLTComponentHandler* fgpInstance; //!transient | |
359 | /** number of used instances of the global singleton */ | |
107e2b1c | 360 | static int fgNofInstances; //!transient |
b005ef92 | 361 | |
45c0a780 | 362 | ClassDef(AliHLTComponentHandler, 2); |
fa2e9b7c | 363 | |
fa760045 | 364 | }; |
f23a6e1a | 365 | #endif |
366 |