]>
Commit | Line | Data |
---|---|---|
f23a6e1a | 1 | // @(#) $Id$ |
2 | ||
3 | #ifndef ALIHLTCOMPONENT_H | |
4 | #define ALIHLTCOMPONENT_H | |
5 | /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
6 | * See cxx source for full Copyright notice */ | |
7 | ||
bfccbf68 | 8 | /** @file AliHLTComponent.h |
9 | @author Matthias Richter, Timm Steinbeck | |
10 | @date | |
11 | @brief Base class declaration for HLT components. */ | |
f23a6e1a | 12 | |
a5854ddd | 13 | #include <cerrno> |
5ec8e281 | 14 | #include "AliHLTLogging.h" |
f23a6e1a | 15 | #include "AliHLTDataTypes.h" |
71d7c760 | 16 | #include "AliHLTDefinitions.h" |
f23a6e1a | 17 | #include "TObject.h" |
18 | ||
19 | class AliHLTComponentHandler; | |
20 | ||
bfccbf68 | 21 | /** |
22 | * @class AliHLTComponent | |
23 | * Base class of HLT data processing components. | |
24 | * The class provides a common interface for HLT data processing components. | |
25 | * The interface can be accessed from the online HLT framework or the AliRoot | |
26 | * offline analysis framework. | |
27 | * Components can be of type | |
28 | * - @ref kSource: components which only produce data | |
29 | * - @ref kProcessor: components which consume and produce data | |
30 | * - @ref kSink: components which only consume data | |
31 | * | |
32 | * where data production and consumption refer to the analysis data stream.<br> | |
33 | * | |
34 | * In order to adapt to different environments (on-line/off-line), the component | |
35 | * gets an environment structure with function pointers. The base class provides | |
36 | * member functions for those environment dependend functions. The member | |
37 | * functions are used by the component implementation and are re-mapped to the | |
38 | * corresponding functions. | |
39 | * @ingroup AliHLTbase | |
40 | */ | |
5ec8e281 | 41 | class AliHLTComponent : public AliHLTLogging { |
f23a6e1a | 42 | public: |
bfccbf68 | 43 | /** standard constructor */ |
f23a6e1a | 44 | AliHLTComponent(); |
bfccbf68 | 45 | /** standard destructor */ |
f23a6e1a | 46 | virtual ~AliHLTComponent(); |
47 | ||
bfccbf68 | 48 | /** component type definitions */ |
f23a6e1a | 49 | enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 }; |
bfccbf68 | 50 | |
51 | /** | |
52 | * Init function to prepare data processing. | |
53 | * Initialization of common data structures for a sequence of events. | |
54 | * The call is redirected to the internal method @ref DoInit which can be | |
55 | * overridden by the child class.<br> | |
56 | * During Init also the environment structure is passed to the component. | |
57 | * @param environ environment pointer with environment dependend function | |
58 | * calls | |
59 | * @param environ_param additionel parameter for function calls, the pointer | |
60 | * is passed as it is | |
61 | * @param argc size of the argument array | |
62 | * @param argv agument array for component initialization | |
63 | */ | |
f23a6e1a | 64 | virtual int Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv ); |
bfccbf68 | 65 | |
66 | /** | |
67 | * Clean-up function to terminate data processing. | |
68 | * Clean-up of common data structures after data processing. | |
69 | * The call is redirected to the internal method @ref DoDeinit which can be | |
70 | * overridden by the child class. | |
71 | */ | |
f23a6e1a | 72 | virtual int Deinit(); |
bfccbf68 | 73 | |
74 | /** | |
75 | * Processing of one event. | |
76 | * The method is pure virtual and implemented by the child classes | |
77 | * - @ref AliHLTProcessor | |
78 | * - @ref AliHLTDataSource | |
79 | * - @ref AliHLTDataSink | |
80 | * | |
81 | * @param evtData | |
82 | * @param blocks | |
83 | * @param trigData | |
84 | * @param outputPtr | |
85 | * @param size | |
86 | * @param outputBlockCnt | |
87 | * @param outputBlocks | |
88 | * @param edd | |
89 | * @return neg. error code if failed | |
90 | */ | |
71d7c760 | 91 | virtual int ProcessEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, |
92 | AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr, | |
93 | AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt, | |
94 | AliHLTComponent_BlockData*& outputBlocks, | |
95 | AliHLTComponent_EventDoneData*& edd ) = 0; | |
f23a6e1a | 96 | |
97 | // Information member functions for registration. | |
bfccbf68 | 98 | |
99 | /** | |
100 | * Get the type of the component. | |
101 | * The function is pure virtual and must be implemented by the child class. | |
102 | * @return component type id | |
103 | */ | |
f23a6e1a | 104 | virtual TComponentType GetComponentType() = 0; // Source, sink, or processor |
bfccbf68 | 105 | |
106 | /** | |
107 | * Get the id of the component. | |
108 | * Each component is identified by a unique id. | |
109 | * The function is pure virtual and must be implemented by the child class. | |
110 | * @return component id (string) | |
111 | */ | |
f23a6e1a | 112 | virtual const char* GetComponentID() = 0; |
bfccbf68 | 113 | |
114 | /** | |
115 | * Get the input data types of the component. | |
116 | * The function is pure virtual and must be implemented by the child class. | |
117 | * @return list of data types in the vector reference | |
118 | */ | |
f23a6e1a | 119 | virtual void GetInputDataTypes( vector<AliHLTComponent_DataType>& ) = 0; |
bfccbf68 | 120 | |
121 | /** | |
122 | * Get the output data type of the component. | |
123 | * The function is pure virtual and must be implemented by the child class. | |
124 | * @return output data type | |
125 | */ | |
f23a6e1a | 126 | virtual AliHLTComponent_DataType GetOutputDataType() = 0; |
bfccbf68 | 127 | |
128 | /** | |
129 | * Get a ratio by how much the data volume is shrinked or enhanced. | |
130 | * The function is pure virtual and must be implemented by the child class. | |
131 | * @param constBase <i>return</i>: additive part, independent of the | |
132 | * input data volume | |
133 | * @param inputMultiplier <i>return</i>: multiplication ratio | |
134 | * @return values in the reference variables | |
135 | */ | |
71d7c760 | 136 | virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0; |
f23a6e1a | 137 | |
bfccbf68 | 138 | /** |
139 | * Spawn function. | |
140 | * Each component must implement a spawn function to create a new instance of | |
141 | * the class. Basically the function must return <i>new <b>my_class_name</b></i>. | |
142 | * @return new class instance | |
143 | */ | |
f23a6e1a | 144 | virtual AliHLTComponent* Spawn() = 0; |
0c0c9d99 | 145 | |
bfccbf68 | 146 | /** |
147 | * Find matching data types between this component and a consumer component. | |
148 | * Currently, a component can produce only one type of data. This restriction is most | |
149 | * likely to be abolished in the future. | |
150 | * @param pConsumer a component and consumer of the data produced by this component | |
151 | * @param tgtList reference to a vector list to receive the matching data types. | |
152 | * @return >= 0 success, neg. error code if failed | |
153 | */ | |
0c0c9d99 | 154 | int FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponent_DataType>* tgtList); |
f23a6e1a | 155 | |
bfccbf68 | 156 | /** |
157 | * Set the global component handler. | |
158 | * The static method is needed for the automatic registration of components. | |
159 | */ | |
f23a6e1a | 160 | static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0) { |
161 | int iResult=0; | |
162 | if (fpComponentHandler==NULL || bOverwrite!=0) | |
163 | fpComponentHandler=pCH; | |
164 | else | |
165 | iResult=-EPERM; | |
166 | return iResult; | |
167 | } | |
bfccbf68 | 168 | |
169 | /** | |
170 | * Clear the global component handler. | |
171 | * The static method is needed for the automatic registration of components. | |
172 | */ | |
f23a6e1a | 173 | static int UnsetGlobalComponentHandler() { |
174 | return SetGlobalComponentHandler(NULL,1); | |
175 | } | |
bfccbf68 | 176 | |
f23a6e1a | 177 | protected: |
71d7c760 | 178 | |
bfccbf68 | 179 | /** |
180 | * Fill AliHLTComponent_BlockData structure with default values. | |
181 | * @param blockData reference to data structure | |
182 | */ | |
71d7c760 | 183 | void FillBlockData( AliHLTComponent_BlockData& blockData ) { |
184 | blockData.fStructSize = sizeof(blockData); | |
185 | FillShmData( blockData.fShmKey ); | |
186 | blockData.fOffset = ~(AliHLTUInt32_t)0; | |
187 | blockData.fPtr = NULL; | |
188 | blockData.fSize = 0; | |
189 | FillDataType( blockData.fDataType ); | |
190 | blockData.fSpecification = ~(AliHLTUInt32_t)0; | |
191 | } | |
bfccbf68 | 192 | |
193 | /** | |
194 | * Fill AliHLTComponent_ShmData structure with default values. | |
195 | * @param shmData reference to data structure | |
196 | */ | |
71d7c760 | 197 | void FillShmData( AliHLTComponent_ShmData& shmData ) { |
198 | shmData.fStructSize = sizeof(shmData); | |
199 | shmData.fShmType = gkAliHLTComponent_InvalidShmType; | |
200 | shmData.fShmID = gkAliHLTComponent_InvalidShmID; | |
201 | } | |
bfccbf68 | 202 | |
203 | /** | |
204 | * Fill AliHLTComponent_DataType structure with default values. | |
205 | * @param dataType reference to data structure | |
206 | */ | |
71d7c760 | 207 | void FillDataType( AliHLTComponent_DataType& dataType ) { |
208 | dataType.fStructSize = sizeof(dataType); | |
209 | memset( dataType.fID, '*', 8 ); | |
210 | memset( dataType.fOrigin, '*', 4 ); | |
211 | } | |
f23a6e1a | 212 | |
bfccbf68 | 213 | /** |
214 | * Default method for the internal initialization. | |
215 | * The method is called by @ref Init | |
216 | */ | |
f23a6e1a | 217 | virtual int DoInit( int argc, const char** argv ){ |
218 | return 0; | |
219 | } | |
220 | ||
bfccbf68 | 221 | /** |
222 | * Default method for the internal clean-up. | |
223 | * The method is called by @ref Deinit | |
224 | */ | |
f23a6e1a | 225 | virtual int DoDeinit(){ |
226 | return 0; | |
227 | } | |
228 | ||
bfccbf68 | 229 | /** |
230 | * General memory allocation method. | |
231 | * All memory which is going to be used 'outside' of the interface must | |
232 | * be provided by the framework (online or offline). | |
233 | * The method is redirected to a function provided by the current | |
234 | * framework. Function pointers are transferred via the @ref | |
235 | * AliHLTComponentEnvironment structure. | |
236 | */ | |
f23a6e1a | 237 | void* AllocMemory( unsigned long size ) { |
238 | if (fEnvironment.fAllocMemoryFunc) | |
239 | return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size ); | |
240 | return NULL; | |
241 | } | |
242 | ||
bfccbf68 | 243 | /** |
244 | * Helper function to create a monolithic BlockData description block out | |
245 | * of a list BlockData descriptors. | |
246 | * For convenience, inside the interface vector lists are used, to make the | |
247 | * interface pure C style, monilithic blocks must be exchanged. | |
248 | * The method is redirected to a function provided by the current | |
249 | * framework. Function pointers are transferred via the @ref | |
250 | * AliHLTComponentEnvironment structure. | |
251 | */ | |
f23a6e1a | 252 | int MakeOutputDataBlockList( const vector<AliHLTComponent_BlockData>& blocks, AliHLTUInt32_t* blockCount, |
fa2e9b7c | 253 | AliHLTComponent_BlockData** outputBlocks ); |
254 | /* { */ | |
255 | /* if (fEnvironment.fMakeOutputDataBlockListFunc) */ | |
256 | /* return (*fEnvironment.fMakeOutputDataBlockListFunc)(fEnvironment.fParam, blocks, blockCount, outputBlocks ); */ | |
257 | /* return -ENOSYS; */ | |
258 | /* } */ | |
f23a6e1a | 259 | |
bfccbf68 | 260 | /** |
261 | * Fill the EventDoneData structure. | |
262 | * The method is redirected to a function provided by the current | |
263 | * framework. Function pointers are transferred via the @ref | |
264 | * AliHLTComponentEnvironment structure. | |
265 | */ | |
f23a6e1a | 266 | int GetEventDoneData( unsigned long size, AliHLTComponent_EventDoneData** edd ) { |
267 | if (fEnvironment.fGetEventDoneDataFunc) | |
268 | return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd ); | |
269 | return -ENOSYS; | |
270 | } | |
271 | ||
f23a6e1a | 272 | |
bfccbf68 | 273 | /** |
274 | * Helper function to convert the data type to a string. | |
275 | */ | |
fa2e9b7c | 276 | void DataType2Text( const AliHLTComponent_DataType& type, char output[14] ); |
277 | ||
f23a6e1a | 278 | private: |
bfccbf68 | 279 | /** The global component handler instance */ |
f23a6e1a | 280 | static AliHLTComponentHandler* fpComponentHandler; |
bfccbf68 | 281 | /** The environment where the component is running in */ |
f23a6e1a | 282 | AliHLTComponentEnvironment fEnvironment; |
283 | ||
bfccbf68 | 284 | /** |
285 | * Set by ProcessEvent before the processing starts (e.g. before calling | |
286 | * @ref AliHLTProcessor::DoEvent) | |
287 | */ | |
288 | AliHLTEventID_t fCurrentEvent; | |
f23a6e1a | 289 | |
290 | ClassDef(AliHLTComponent, 0) | |
291 | }; | |
292 | #endif |