4 #ifndef ALIHLTCOMPONENTHANDLER_H
5 #define ALIHLTCOMPONENTHANDLER_H
6 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
7 * See cxx source for full Copyright notice */
9 /** @file AliHLTComponentHandler.h
10 @author Matthias Richter, Timm Steinbeck
12 @brief Global handling of HLT processing components
13 @note The handler is part of the interface and both used in the
14 Online (PubSub) and Offline (AliRoot) context.
17 // see below for class documentation
19 // refer to README to build package
21 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
24 //#include "TObject.h"
25 #include "AliHLTDataTypes.h"
26 #include "AliHLTLogging.h"
28 class AliHLTComponent;
29 struct AliHLTComponentEnvironment;
30 struct AliHLTComponentDataType;
33 * @class AliHLTComponentHandler
34 * The component handler controls all the processing components available in
35 * the system. It also controls the component shared libraries.
36 * @ingroup alihlt_component
38 class AliHLTComponentHandler : public AliHLTLogging {
40 /** standard constructor */
41 AliHLTComponentHandler();
43 AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv);
45 virtual ~AliHLTComponentHandler();
48 * Set the environment for the HLT framework.
49 * The environment mainly consists of function pointers for the integration
50 * of the HLT framework into a system like the PubSub online system or
51 * AliRoot offline system.
52 * @param pEnv pointer to @ref AliHLTComponentEnvironment structure
55 void SetEnvironment(AliHLTComponentEnvironment* pEnv);
58 * Load a component shared library.
59 * The component library needs to be loaded from the ComponentHanler in order
60 * to automatically register all components in the library.
61 * Registration is done by passing a sample object of the component to the
62 * handler. The object has to be valid during the whole runtime and should
63 * thus be a global object which is ONLY used for the purpose of registration.
64 * This also ensures automatically registration at library load time.
65 * @param libraryPath const char string containing the library name/path
66 * @return 0 if succeeded, neg. error code if failed
68 int LoadLibrary( const char* libraryPath );
71 * Find a symbol in a dynamically loaded library.
72 * @param library library
73 * @param symbol the symbol to find
74 * @return void pointer to function
76 void* FindSymbol(const char* library, const char* symbol);
79 * Unload a component shared library.
80 * All components will be de-registered when the last instance of the
81 * library was unloaded.
82 * @param libraryPath library name as specified to @ref LoadLibrary
83 * @return 0 if succeeded, neg. error code if failed
85 int UnloadLibrary( const char* libraryPath );
88 * Schedule a component for registration.
89 * Full registration will be done after successfull loading of the shared
91 * @param pSample a sample object of the component
92 * @return neg. error code if failed
94 int ScheduleRegister(AliHLTComponent* pSample );
97 * Register a component.
98 * Registration is done by passing a sample object of the component to the
99 * handler. The object has to be valid during the whole runtime and should
100 * thus be a global object which is ONLY used for the purpose of registration.
101 * @param pSample a sample object of the component
102 * @return neg. error code if failed
104 int RegisterComponent(AliHLTComponent* pSample );
107 * Registers all scheduled components.
109 int RegisterScheduledComponents();
112 * Deregister a component.
113 * @param componentID ID of the component
114 * @return neg. error code if failed
116 int DeregisterComponent( const char* componentID );
119 * Add standard components
120 * The standard components are part of the libHLTbase library and
121 * need therefore a special handling.
123 int AddStandardComponents();
127 int DeleteStandardComponents();
130 * Find the ID of a component with the given output data.
131 * @param dtype data type descriptor
132 * @param prevType can be used to iterate if there are multiple components
133 * with the same output data type.
134 * @return component id
136 //const char* FindComponentType( AliHLTComponentDataType dtype,
137 // const char* prevType = NULL )
141 * Create a component of the given name (ID).
142 * The method tries to find a registerd component of id \em componentID and
143 * calls the \em Spawn method of the template component. After successful
144 * creation of a new object, the Init method is called in order to initialize
145 * the environment and the component arguments. <br>
146 * The environment is the same for all components, but each component can
147 * have an additional private parameter \em pEnvParam.<br>
148 * The component arguments consist of an array of strings and the array size
149 * in the usual manner of the main() function.
150 * @param componentID ID of the component to create
151 * @param pEnvParam environment parameter for the component
152 * @param argc number of arguments in argv
153 * @param argv argument array like in main()
154 * @param component reference to receive the create component instance
155 * @return component pointer in component, neg. error code if failed
157 int CreateComponent( const char* componentID, void* pEnvParam,
158 int argc, const char** argv, AliHLTComponent*& component );
161 * Create a component of the given name (ID).
162 * Introduced for backward compatibility.
163 * @param componentID ID of the component to create
164 * @param pEnvParam environment parameter for the component
165 * @param component reference to receive the create component instance
166 * @return component pointer in component, neg. error code if failed
168 int CreateComponent( const char* componentID, void* pEnvParam,
169 AliHLTComponent*& component )
171 return CreateComponent( componentID, pEnvParam, 0, NULL, component );
175 * Print registered components to stdout.
181 * Announce version and compilation info of the base library.
183 int AnnounceVersion();
188 /** copy constructor prohibited */
189 AliHLTComponentHandler(const AliHLTComponentHandler&);
190 /** assignment operator prohibited */
191 AliHLTComponentHandler& operator=(const AliHLTComponentHandler&);
195 * @param componentID ID of the component to find
196 * @return index, neg. error code if failed
198 int FindComponentIndex(const char* componentID);
202 * @param componentID ID of the component to find
205 AliHLTComponent* FindComponent(const char* componentID);
208 * Insert component to the list
209 * @param pSample sample object of the component
210 * @return neg. error code if failed
212 int InsertComponent(AliHLTComponent* pSample);
215 * Close all libraries.
216 * @return neg. error code if failed
218 int UnloadLibraries();
221 * Compount descriptor for component libraries
223 struct AliHLTLibHandle {
224 AliHLTLibHandle() : fHandle(NULL), fName(NULL) {}
226 void* fHandle; //! transient
227 /** name of the library, casted to TString* before use */
228 void* fName; //! transient
232 * Find a specific library among the loaded libraries.
233 * @param library library name/path
234 * @return pointer to AliHLTLibHandle
236 AliHLTLibHandle* FindLibrary(const char* library);
239 * Unload a component shared library.
240 * All components will be de-registered when the last instance of the
241 * library was unloaded.
242 * @param handle handle to the library to unload
243 * @return 0 if succeeded, neg. error code if failed
245 int UnloadLibrary(AliHLTComponentHandler::AliHLTLibHandle &handle);
247 /** list of registered components */
248 vector<AliHLTComponent*> fComponentList; // see above
249 /** list of scheduled components */
250 vector<AliHLTComponent*> fScheduleList; // see above
251 /** list of libraries */
252 vector<AliHLTLibHandle> fLibraryList; // see above
253 /** running environment for the component */
254 AliHLTComponentEnvironment fEnvironment; // see above
255 /** list of standard components */
256 vector<AliHLTComponent*> fStandardList; // see above
258 ClassDef(AliHLTComponentHandler, 0);