]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponentHandler.h
Air with increased transport cuts close to qb28.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponentHandler.h
CommitLineData
f23a6e1a 1// @(#) $Id$
2
3#ifndef ALIHLTCOMPONENTHANDLER_H
4#define ALIHLTCOMPONENTHANDLER_H
5/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * See cxx source for full Copyright notice */
7
b22e91eb 8/** @file AliHLTComponentHandler.h
9 @author Matthias Richter, Timm Steinbeck
10 @date
11 @brief Global handling of HLT processing components
12 @note The handler is part of the interface and both used in the
13 Online (PubSub) and Offline (AliRoot) context.
14 */
15
f23a6e1a 16
8ede8717 17#include <vector>
f23a6e1a 18#include "TObject.h"
19#include "AliHLTDataTypes.h"
5ec8e281 20#include "AliHLTLogging.h"
f23a6e1a 21
22class AliHLTComponent;
23struct AliHLTComponentEnvironment;
8ede8717 24struct AliHLTComponentDataType;
f23a6e1a 25
fa760045 26/**
27 * @class AliHLTComponentHandler
28 * The component handler controls all the processing components available in
29 * the system. It also controls the component shared libraries.
30 * @ingroup alihlt_component
31 */
5ec8e281 32class AliHLTComponentHandler : public AliHLTLogging {
f23a6e1a 33 public:
fa760045 34 /** standard constructor */
f23a6e1a 35 AliHLTComponentHandler();
3cde846d 36 /** constructor */
37 AliHLTComponentHandler(AliHLTComponentEnvironment* pEnv);
fa760045 38 /** destructor */
f23a6e1a 39 virtual ~AliHLTComponentHandler();
40
fa760045 41 /**
42 * Set the environment for the HLT framework.
43 * The environment mainly consists of function pointers for the integration
44 * of the HLT framework into a system like the PubSub online system or
45 * AliRoot offline system.
46 * @param pEnv pointer to @ref AliHLTComponentEnvironment structure
47 * @return none
48 */
f23a6e1a 49 void SetEnvironment(AliHLTComponentEnvironment* pEnv);
50
fa760045 51 /**
52 * Load a component shared library.
53 * The component library needs to be loaded from the ComponentHanler in order
54 * to automatically register all components in the library.
55 * Registration is done by passing a sample object of the component to the
56 * handler. The object has to be valid during the whole runtime and should
57 * thus be a global object which is ONLY used for the purpose of registration.
58 * This also ensures automatically registration at library load time.
59 * @param libraryPath const char string containing the library name/path
60 * @return 0 if succeeded, neg. error code if failed
61 */
f23a6e1a 62 int LoadLibrary( const char* libraryPath );
fa760045 63
85f0cede 64 /**
65 * Find a symbol in a dynamically loaded library.
66 * @param library library
67 * @param symbol the symbol to find
68 * @return void pointer to function
69 */
70 void* FindSymbol(const char* library, const char* symbol);
71
fa760045 72 /**
73 * Unload a component shared library.
a742f6f8 74 * All components will be de-registered when the last instance of the
75 * library was unloaded.
fa760045 76 * @param libraryPath library name as specified to @ref LoadLibrary
77 * @return 0 if succeeded, neg. error code if failed
78 */
f23a6e1a 79 int UnloadLibrary( const char* libraryPath );
80
fa760045 81 /**
82 * Schedule a component for registration.
83 * Full registration will be done after successfull loading of the shared
84 * library.
85 * @param pSample a sample object of the component
86 * @return neg. error code if failed
f23a6e1a 87 */
f23a6e1a 88 int ScheduleRegister(AliHLTComponent* pSample );
89
fa760045 90 /**
91 * Register a component.
92 * Registration is done by passing a sample object of the component to the
93 * handler. The object has to be valid during the whole runtime and should
94 * thus be a global object which is ONLY used for the purpose of registration.
95 * @param pSample a sample object of the component
96 * @return neg. error code if failed
97 */
f23a6e1a 98 int RegisterComponent(AliHLTComponent* pSample );
f23a6e1a 99
9ce4bf4a 100 /**
101 * Registers all scheduled components.
102 */
103 int RegisterScheduledComponents();
104
fa760045 105 /**
106 * Deregister a component.
107 * @param componentID ID of the component
108 * @return neg. error code if failed
109 */
110 int DeregisterComponent( const char* componentID );
f23a6e1a 111
9ce4bf4a 112 /**
113 * Add standard components
114 * The standard components are part of the libHLTbase library and
115 * need therefore a special handling.
116 */
117 int AddStandardComponents();
118
119 /**
120 */
121 int DeleteStandardComponents();
122
fa760045 123 /**
124 * Find the ID of a component with the given output data.
125 * @param dtype data type descriptor
126 * @param prevType can be used to iterate if there are multiple components
127 * with the same output data type.
128 * @return component id
129 */
8ede8717 130 //const char* FindComponentType( AliHLTComponentDataType dtype,
fa760045 131 // const char* prevType = NULL )
132 // { return NULL;}
133
134 /**
135 * Create a component of the given name (ID).
c215072c 136 * The method tries to find a registerd component of id \em componentID and
137 * calls the \em Spawn method of the template component. After successful
138 * creation of a new object, the Init method is called in order to initialize
139 * the environment and the component arguments. <br>
2d7ff710 140 * The environment is the same for all components, but each component can
141 * have an additional private parameter \em pEnvParam.<br>
c215072c 142 * The component arguments consist of an array of strings and the array size
143 * in the usual manner of the main() function.
fa760045 144 * @param componentID ID of the component to create
2d7ff710 145 * @param pEnvParam environment parameter for the component
db16520a 146 * @param argc number of arguments in argv
fa760045 147 * @param argv argument array like in main()
148 * @param component reference to receive the create component instance
db16520a 149 * @return component pointer in component, neg. error code if failed
fa760045 150 */
2d7ff710 151 int CreateComponent( const char* componentID, void* pEnvParam,
fa760045 152 int argc, const char** argv, AliHLTComponent*& component );
153
154 /**
155 * Create a component of the given name (ID).
156 * Introduced for backward compatibility.
157 * @param componentID ID of the component to create
2d7ff710 158 * @param pEnvParam environment parameter for the component
fa760045 159 * @param component reference to receive the create component instance
db16520a 160 * @return component pointer in component, neg. error code if failed
fa760045 161 */
2d7ff710 162 int CreateComponent( const char* componentID, void* pEnvParam,
fa760045 163 AliHLTComponent*& component )
164 {
2d7ff710 165 return CreateComponent( componentID, pEnvParam, 0, NULL, component );
fa760045 166 }
167
168 /**
169 * Print registered components to stdout.
170 * @return none
f23a6e1a 171 */
172 void List();
fa760045 173
174 /**
175 * Announce version and compilation info of the base library.
176 */
177 int AnnounceVersion();
178
f23a6e1a 179 protected:
f23a6e1a 180
181 private:
fa760045 182 /**
183 * Find a component.
184 * @param componentID ID of the component to find
185 * @return index, neg. error code if failed
186 */
f23a6e1a 187 int FindComponentIndex(const char* componentID);
188
fa760045 189 /**
190 * Find a component.
191 * @param componentID ID of the component to find
192 * @return descriptor
193 */
f23a6e1a 194 AliHLTComponent* FindComponent(const char* componentID);
195
fa760045 196 /**
197 * Insert component to the list
198 * @param pSample sample object of the component
199 * @return neg. error code if failed
200 */
f23a6e1a 201 int InsertComponent(AliHLTComponent* pSample);
202
fa760045 203 /**
204 * Close all libraries.
205 * @return neg. error code if failed
206 */
f23a6e1a 207 int UnloadLibraries();
208
c215072c 209 /**
210 * Compount descriptor for component libraries
211 */
212 struct AliHLTLibHandle {
213 AliHLTLibHandle() : handle(NULL), name(NULL) {}
214 /** dlopen handle */
215 void* handle; //! transient
216 /** name of the library, casted to TString* before use */
217 void* name; //! transient
218 };
219
85f0cede 220 /**
221 * Find a specific library among the loaded libraries.
222 * @param library library name/path
223 * @return pointer to AliHLTLibHandle
224 */
225 AliHLTLibHandle* FindLibrary(const char* library);
226
a742f6f8 227 /**
228 * Unload a component shared library.
229 * All components will be de-registered when the last instance of the
230 * library was unloaded.
231 * @param handle handle to the library to unload
232 * @return 0 if succeeded, neg. error code if failed
233 */
234 int UnloadLibrary(AliHLTComponentHandler::AliHLTLibHandle &handle);
235
fa760045 236 /** list of registered components */
70ed7d01 237 vector<AliHLTComponent*> fComponentList; // see above
fa760045 238 /** list of scheduled components */
70ed7d01 239 vector<AliHLTComponent*> fScheduleList; // see above
fa760045 240 /** list of libraries */
70ed7d01 241 vector<AliHLTLibHandle> fLibraryList; // see above
fa760045 242 /** running environment for the component */
70ed7d01 243 AliHLTComponentEnvironment fEnvironment; // see above
9ce4bf4a 244 /** list of standard components */
70ed7d01 245 vector<AliHLTComponent*> fStandardList; // see above
f23a6e1a 246
fa760045 247 ClassDef(AliHLTComponentHandler, 0);
fa2e9b7c 248
fa760045 249};
f23a6e1a 250#endif
251