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