]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponent.h
component documentation
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.h
CommitLineData
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
b22e91eb 11 @brief Base class declaration for HLT components.
12 @note The class is both used in Online (PubSub) and Offline (AliRoot)
13 context
14 */
15/**
16 * @defgroup alihlt_component Component handling of the HLT module
17 * This section describes the the component handling for the HLT module.
18 */
8ede8717 19
20#include <vector>
9ce4bf4a 21#include <string>
5ec8e281 22#include "AliHLTLogging.h"
f23a6e1a 23#include "AliHLTDataTypes.h"
71d7c760 24#include "AliHLTDefinitions.h"
f23a6e1a 25
2d7ff710 26/* Matthias Dec 2006
27 * The names have been changed for Aliroot's coding conventions sake
28 * The old names are defined for backward compatibility with the
29 * stand alone SampleLib package
30 */
31typedef AliHLTComponentLogSeverity AliHLTComponent_LogSeverity;
32typedef AliHLTComponentEventData AliHLTComponent_EventData;
33typedef AliHLTComponentShmData AliHLTComponent_ShmData;
34typedef AliHLTComponentDataType AliHLTComponent_DataType;
35typedef AliHLTComponentBlockData AliHLTComponent_BlockData;
36typedef AliHLTComponentTriggerData AliHLTComponent_TriggerData;
37typedef AliHLTComponentEventDoneData AliHLTComponent_EventDoneData;
38
f23a6e1a 39class AliHLTComponentHandler;
40
bfccbf68 41/**
42 * @class AliHLTComponent
43 * Base class of HLT data processing components.
44 * The class provides a common interface for HLT data processing components.
45 * The interface can be accessed from the online HLT framework or the AliRoot
46 * offline analysis framework.
47 * Components can be of type
9ce4bf4a 48 * - @ref AliHLTComponent::kSource: components which only produce data
49 * - @ref AliHLTComponent::kProcessor: components which consume and produce data
50 * - @ref AliHLTComponent::kSink: components which only consume data
bfccbf68 51 *
52 * where data production and consumption refer to the analysis data stream.<br>
53 *
54 * In order to adapt to different environments (on-line/off-line), the component
55 * gets an environment structure with function pointers. The base class provides
56 * member functions for those environment dependend functions. The member
57 * functions are used by the component implementation and are re-mapped to the
58 * corresponding functions.
b22e91eb 59 * @ingroup alihlt_component
bfccbf68 60 */
5ec8e281 61class AliHLTComponent : public AliHLTLogging {
f23a6e1a 62 public:
bfccbf68 63 /** standard constructor */
f23a6e1a 64 AliHLTComponent();
70ed7d01 65 /** not a valid copy constructor, defined according to effective C++ style */
66 AliHLTComponent(const AliHLTComponent&);
67 /** not a valid assignment op, but defined according to effective C++ style */
68 AliHLTComponent& operator=(const AliHLTComponent&);
bfccbf68 69 /** standard destructor */
f23a6e1a 70 virtual ~AliHLTComponent();
71
bfccbf68 72 /** component type definitions */
f23a6e1a 73 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
bfccbf68 74
75 /**
76 * Init function to prepare data processing.
77 * Initialization of common data structures for a sequence of events.
78 * The call is redirected to the internal method @ref DoInit which can be
79 * overridden by the child class.<br>
80 * During Init also the environment structure is passed to the component.
81 * @param environ environment pointer with environment dependend function
82 * calls
70ed7d01 83 * @param environParam additionel parameter for function calls, the pointer
bfccbf68 84 * is passed as it is
85 * @param argc size of the argument array
86 * @param argv agument array for component initialization
87 */
70ed7d01 88 virtual int Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv );
bfccbf68 89
90 /**
91 * Clean-up function to terminate data processing.
92 * Clean-up of common data structures after data processing.
93 * The call is redirected to the internal method @ref DoDeinit which can be
94 * overridden by the child class.
95 */
f23a6e1a 96 virtual int Deinit();
bfccbf68 97
98 /**
99 * Processing of one event.
3cde846d 100 * The method is the entrance of the event processing. The parameters are
101 * cached for uses with the high-level interface and the DoProcessing
102 * implementation is called.
103 *
104 * @param evtData
105 * @param blocks
106 * @param trigData
107 * @param outputPtr
108 * @param size
109 * @param outputBlockCnt out: size of the output block array, set by the component
110 * @param outputBlocks out: the output block array is allocated internally
111 * @param edd
112 * @return neg. error code if failed
113 */
114 int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
115 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
116 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
117 AliHLTComponentBlockData*& outputBlocks,
118 AliHLTComponentEventDoneData*& edd );
119
120 /**
121 * Internal processing of one event.
bfccbf68 122 * The method is pure virtual and implemented by the child classes
123 * - @ref AliHLTProcessor
124 * - @ref AliHLTDataSource
125 * - @ref AliHLTDataSink
126 *
127 * @param evtData
128 * @param blocks
129 * @param trigData
130 * @param outputPtr
131 * @param size
2d7ff710 132 * @param outputBlockCnt out: size of the output block array, set by the component
133 * @param outputBlocks out: the output block array is allocated internally
bfccbf68 134 * @param edd
135 * @return neg. error code if failed
136 */
3cde846d 137 virtual int DoProcessing( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
8ede8717 138 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
71d7c760 139 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
8ede8717 140 AliHLTComponentBlockData*& outputBlocks,
141 AliHLTComponentEventDoneData*& edd ) = 0;
f23a6e1a 142
143 // Information member functions for registration.
bfccbf68 144
145 /**
146 * Get the type of the component.
147 * The function is pure virtual and must be implemented by the child class.
148 * @return component type id
149 */
f23a6e1a 150 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
bfccbf68 151
152 /**
153 * Get the id of the component.
154 * Each component is identified by a unique id.
155 * The function is pure virtual and must be implemented by the child class.
156 * @return component id (string)
157 */
f23a6e1a 158 virtual const char* GetComponentID() = 0;
bfccbf68 159
160 /**
161 * Get the input data types of the component.
162 * The function is pure virtual and must be implemented by the child class.
163 * @return list of data types in the vector reference
164 */
8ede8717 165 virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& ) = 0;
bfccbf68 166
167 /**
168 * Get the output data type of the component.
169 * The function is pure virtual and must be implemented by the child class.
170 * @return output data type
171 */
8ede8717 172 virtual AliHLTComponentDataType GetOutputDataType() = 0;
bfccbf68 173
174 /**
175 * Get a ratio by how much the data volume is shrinked or enhanced.
176 * The function is pure virtual and must be implemented by the child class.
177 * @param constBase <i>return</i>: additive part, independent of the
178 * input data volume
179 * @param inputMultiplier <i>return</i>: multiplication ratio
180 * @return values in the reference variables
181 */
71d7c760 182 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
f23a6e1a 183
bfccbf68 184 /**
185 * Spawn function.
186 * Each component must implement a spawn function to create a new instance of
187 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
188 * @return new class instance
189 */
f23a6e1a 190 virtual AliHLTComponent* Spawn() = 0;
0c0c9d99 191
bfccbf68 192 /**
193 * Find matching data types between this component and a consumer component.
194 * Currently, a component can produce only one type of data. This restriction is most
195 * likely to be abolished in the future.
196 * @param pConsumer a component and consumer of the data produced by this component
197 * @param tgtList reference to a vector list to receive the matching data types.
198 * @return >= 0 success, neg. error code if failed
199 */
8ede8717 200 int FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList);
f23a6e1a 201
bfccbf68 202 /**
203 * Set the global component handler.
204 * The static method is needed for the automatic registration of components.
205 */
85869391 206 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
bfccbf68 207
208 /**
209 * Clear the global component handler.
210 * The static method is needed for the automatic registration of components.
211 */
85869391 212 static int UnsetGlobalComponentHandler();
bfccbf68 213
9ce4bf4a 214 /**
215 * Helper function to convert the data type to a string.
216 */
217 static string DataType2Text( const AliHLTComponentDataType& type );
218
219 /**
220 * helper function to initialize AliHLTComponentEventData structure
221 */
222 static void FillEventData(AliHLTComponentEventData& evtData);
223
224 /**
225 * Print info on an AliHLTComponentDataType structure
226 * This is just a helper function to examine an @ref AliHLTComponentDataType
227 * structur.
228 */
229 void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
230
f23a6e1a 231 protected:
71d7c760 232
bfccbf68 233 /**
8ede8717 234 * Fill AliHLTComponentBlockData structure with default values.
bfccbf68 235 * @param blockData reference to data structure
236 */
70ed7d01 237 void FillBlockData( AliHLTComponentBlockData& blockData ) const;
bfccbf68 238
239 /**
8ede8717 240 * Fill AliHLTComponentShmData structure with default values.
bfccbf68 241 * @param shmData reference to data structure
242 */
70ed7d01 243 void FillShmData( AliHLTComponentShmData& shmData ) const;
bfccbf68 244
245 /**
8ede8717 246 * Fill AliHLTComponentDataType structure with default values.
bfccbf68 247 * @param dataType reference to data structure
248 */
70ed7d01 249 void FillDataType( AliHLTComponentDataType& dataType ) const;
f23a6e1a 250
2d7ff710 251 /**
252 * Copy data type structure
253 * Copies the value an AliHLTComponentDataType structure to another one
254 * @param[out] tgtdt target structure
255 * @param[in] srcdt source structure
256 */
257 void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
258
259 /**
260 * Set the ID and Origin of an AliHLTComponentDataType structure.
261 * The function sets the fStructureSize member and copies the strings
262 * to the ID and Origin. Only characters from the valid part of the string
263 * are copied, the rest is fille with 0's.
264 * Please note that the fID and fOrigin members are not strings, just arrays of
265 * chars of size @ref kAliHLTComponentDataTypefIDsize and
21745ddc 266 * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
2d7ff710 267 * a terminating zero.
9ce4bf4a 268 * @param tgtdt target data type structure
2d7ff710 269 * @param id ID string
270 * @param origin Origin string
271 */
272 void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
273
bfccbf68 274 /**
275 * Default method for the internal initialization.
276 * The method is called by @ref Init
277 */
53feaef5 278 virtual int DoInit( int argc, const char** argv );
f23a6e1a 279
bfccbf68 280 /**
281 * Default method for the internal clean-up.
282 * The method is called by @ref Deinit
283 */
53feaef5 284 virtual int DoDeinit();
f23a6e1a 285
bfccbf68 286 /**
287 * General memory allocation method.
288 * All memory which is going to be used 'outside' of the interface must
289 * be provided by the framework (online or offline).
290 * The method is redirected to a function provided by the current
291 * framework. Function pointers are transferred via the @ref
292 * AliHLTComponentEnvironment structure.
293 */
85869391 294 void* AllocMemory( unsigned long size );
f23a6e1a 295
bfccbf68 296 /**
297 * Helper function to create a monolithic BlockData description block out
298 * of a list BlockData descriptors.
299 * For convenience, inside the interface vector lists are used, to make the
300 * interface pure C style, monilithic blocks must be exchanged.
301 * The method is redirected to a function provided by the current
302 * framework. Function pointers are transferred via the @ref
303 * AliHLTComponentEnvironment structure.
304 */
8ede8717 305 int MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
306 AliHLTComponentBlockData** outputBlocks );
f23a6e1a 307
bfccbf68 308 /**
309 * Fill the EventDoneData structure.
310 * The method is redirected to a function provided by the current
311 * framework. Function pointers are transferred via the @ref
312 * AliHLTComponentEnvironment structure.
313 */
8ede8717 314 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd );
f23a6e1a 315
bfccbf68 316 /**
317 * Helper function to convert the data type to a string.
318 */
70ed7d01 319 void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]) const;
fa2e9b7c 320
3cde846d 321 /**
322 * Get event number.
323 * @return value of the internal event counter
324 */
70ed7d01 325 int GetEventCount() const;
3cde846d 326
f23a6e1a 327 private:
3cde846d 328 /**
329 * Increment the internal event counter.
330 * To be used by the friend classes AliHLTProcessor, AliHLTDataSource
331 * and AliHLTDataSink.
332 * @return new value of the internal event counter
333 */
334 int IncrementEventCounter();
335
bfccbf68 336 /** The global component handler instance */
70ed7d01 337 static AliHLTComponentHandler* fgpComponentHandler; //! transient
338
bfccbf68 339 /** The environment where the component is running in */
70ed7d01 340 AliHLTComponentEnvironment fEnvironment; // see above
f23a6e1a 341
bfccbf68 342 /**
343 * Set by ProcessEvent before the processing starts (e.g. before calling
344 * @ref AliHLTProcessor::DoEvent)
345 */
70ed7d01 346 AliHLTEventID_t fCurrentEvent; // see above
f23a6e1a 347
3cde846d 348 /** internal event no */
70ed7d01 349 int fEventCount; // see above
3cde846d 350
351 ClassDef(AliHLTComponent, 1)
f23a6e1a 352};
353#endif