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 */
8 /** @file AliHLTComponent.h
9 @author Matthias Richter, Timm Steinbeck
11 @brief Base class declaration for HLT components.
12 @note The class is both used in Online (PubSub) and Offline (AliRoot)
16 * @defgroup alihlt_component Component handling of the HLT module
17 * This section describes the the component handling for the HLT module.
22 #include "AliHLTLogging.h"
23 #include "AliHLTDataTypes.h"
24 #include "AliHLTDefinitions.h"
28 * The names have been changed for Aliroot's coding conventions sake
29 * The old names are defined for backward compatibility with the
30 * stand alone SampleLib package
32 typedef AliHLTComponentLogSeverity AliHLTComponent_LogSeverity;
33 typedef AliHLTComponentEventData AliHLTComponent_EventData;
34 typedef AliHLTComponentShmData AliHLTComponent_ShmData;
35 typedef AliHLTComponentDataType AliHLTComponent_DataType;
36 typedef AliHLTComponentBlockData AliHLTComponent_BlockData;
37 typedef AliHLTComponentTriggerData AliHLTComponent_TriggerData;
38 typedef AliHLTComponentEventDoneData AliHLTComponent_EventDoneData;
40 class AliHLTComponentHandler;
43 * @class AliHLTComponent
44 * Base class of HLT data processing components.
45 * The class provides a common interface for HLT data processing components.
46 * The interface can be accessed from the online HLT framework or the AliRoot
47 * offline analysis framework.
48 * Components can be of type
49 * - @ref AliHLTComponent::kSource: components which only produce data
50 * - @ref AliHLTComponent::kProcessor: components which consume and produce data
51 * - @ref AliHLTComponent::kSink: components which only consume data
53 * where data production and consumption refer to the analysis data stream.<br>
55 * In order to adapt to different environments (on-line/off-line), the component
56 * gets an environment structure with function pointers. The base class provides
57 * member functions for those environment dependend functions. The member
58 * functions are used by the component implementation and are re-mapped to the
59 * corresponding functions.
60 * @ingroup alihlt_component
62 class AliHLTComponent : public AliHLTLogging {
64 /** standard constructor */
66 /** standard destructor */
67 virtual ~AliHLTComponent();
69 /** component type definitions */
70 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
73 * Init function to prepare data processing.
74 * Initialization of common data structures for a sequence of events.
75 * The call is redirected to the internal method @ref DoInit which can be
76 * overridden by the child class.<br>
77 * During Init also the environment structure is passed to the component.
78 * @param environ environment pointer with environment dependend function
80 * @param environ_param additionel parameter for function calls, the pointer
82 * @param argc size of the argument array
83 * @param argv agument array for component initialization
85 virtual int Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv );
88 * Clean-up function to terminate data processing.
89 * Clean-up of common data structures after data processing.
90 * The call is redirected to the internal method @ref DoDeinit which can be
91 * overridden by the child class.
96 * Processing of one event.
97 * The method is the entrance of the event processing. The parameters are
98 * cached for uses with the high-level interface and the DoProcessing
99 * implementation is called.
106 * @param outputBlockCnt out: size of the output block array, set by the component
107 * @param outputBlocks out: the output block array is allocated internally
109 * @return neg. error code if failed
111 int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
112 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
113 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
114 AliHLTComponentBlockData*& outputBlocks,
115 AliHLTComponentEventDoneData*& edd );
118 * Internal processing of one event.
119 * The method is pure virtual and implemented by the child classes
120 * - @ref AliHLTProcessor
121 * - @ref AliHLTDataSource
122 * - @ref AliHLTDataSink
129 * @param outputBlockCnt out: size of the output block array, set by the component
130 * @param outputBlocks out: the output block array is allocated internally
132 * @return neg. error code if failed
134 virtual int DoProcessing( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
135 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
136 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
137 AliHLTComponentBlockData*& outputBlocks,
138 AliHLTComponentEventDoneData*& edd ) = 0;
140 // Information member functions for registration.
143 * Get the type of the component.
144 * The function is pure virtual and must be implemented by the child class.
145 * @return component type id
147 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
150 * Get the id of the component.
151 * Each component is identified by a unique id.
152 * The function is pure virtual and must be implemented by the child class.
153 * @return component id (string)
155 virtual const char* GetComponentID() = 0;
158 * Get the input data types of the component.
159 * The function is pure virtual and must be implemented by the child class.
160 * @return list of data types in the vector reference
162 virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& ) = 0;
165 * Get the output data type of the component.
166 * The function is pure virtual and must be implemented by the child class.
167 * @return output data type
169 virtual AliHLTComponentDataType GetOutputDataType() = 0;
172 * Get a ratio by how much the data volume is shrinked or enhanced.
173 * The function is pure virtual and must be implemented by the child class.
174 * @param constBase <i>return</i>: additive part, independent of the
176 * @param inputMultiplier <i>return</i>: multiplication ratio
177 * @return values in the reference variables
179 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
183 * Each component must implement a spawn function to create a new instance of
184 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
185 * @return new class instance
187 virtual AliHLTComponent* Spawn() = 0;
190 * Find matching data types between this component and a consumer component.
191 * Currently, a component can produce only one type of data. This restriction is most
192 * likely to be abolished in the future.
193 * @param pConsumer a component and consumer of the data produced by this component
194 * @param tgtList reference to a vector list to receive the matching data types.
195 * @return >= 0 success, neg. error code if failed
197 int FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList);
200 * Set the global component handler.
201 * The static method is needed for the automatic registration of components.
203 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
206 * Clear the global component handler.
207 * The static method is needed for the automatic registration of components.
209 static int UnsetGlobalComponentHandler();
212 * Helper function to convert the data type to a string.
214 static string DataType2Text( const AliHLTComponentDataType& type );
217 * helper function to initialize AliHLTComponentEventData structure
219 static void FillEventData(AliHLTComponentEventData& evtData);
222 * Print info on an AliHLTComponentDataType structure
223 * This is just a helper function to examine an @ref AliHLTComponentDataType
226 void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
231 * Fill AliHLTComponentBlockData structure with default values.
232 * @param blockData reference to data structure
234 void FillBlockData( AliHLTComponentBlockData& blockData );
237 * Fill AliHLTComponentShmData structure with default values.
238 * @param shmData reference to data structure
240 void FillShmData( AliHLTComponentShmData& shmData );
243 * Fill AliHLTComponentDataType structure with default values.
244 * @param dataType reference to data structure
246 void FillDataType( AliHLTComponentDataType& dataType );
249 * Copy data type structure
250 * Copies the value an AliHLTComponentDataType structure to another one
251 * @param[out] tgtdt target structure
252 * @param[in] srcdt source structure
254 void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
257 * Set the ID and Origin of an AliHLTComponentDataType structure.
258 * The function sets the fStructureSize member and copies the strings
259 * to the ID and Origin. Only characters from the valid part of the string
260 * are copied, the rest is fille with 0's.
261 * Please note that the fID and fOrigin members are not strings, just arrays of
262 * chars of size @ref kAliHLTComponentDataTypefIDsize and
263 * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
264 * a terminating zero.
265 * @param tgtdt target data type structure
266 * @param id ID string
267 * @param origin Origin string
269 void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
272 * Default method for the internal initialization.
273 * The method is called by @ref Init
275 virtual int DoInit( int argc, const char** argv );
278 * Default method for the internal clean-up.
279 * The method is called by @ref Deinit
281 virtual int DoDeinit();
284 * General memory allocation method.
285 * All memory which is going to be used 'outside' of the interface must
286 * be provided by the framework (online or offline).
287 * The method is redirected to a function provided by the current
288 * framework. Function pointers are transferred via the @ref
289 * AliHLTComponentEnvironment structure.
291 void* AllocMemory( unsigned long size );
294 * Helper function to create a monolithic BlockData description block out
295 * of a list BlockData descriptors.
296 * For convenience, inside the interface vector lists are used, to make the
297 * interface pure C style, monilithic blocks must be exchanged.
298 * The method is redirected to a function provided by the current
299 * framework. Function pointers are transferred via the @ref
300 * AliHLTComponentEnvironment structure.
302 int MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
303 AliHLTComponentBlockData** outputBlocks );
306 * Fill the EventDoneData structure.
307 * The method is redirected to a function provided by the current
308 * framework. Function pointers are transferred via the @ref
309 * AliHLTComponentEnvironment structure.
311 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd );
314 * Helper function to convert the data type to a string.
316 void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]);
320 * @return value of the internal event counter
326 * Increment the internal event counter.
327 * To be used by the friend classes AliHLTProcessor, AliHLTDataSource
328 * and AliHLTDataSink.
329 * @return new value of the internal event counter
331 int IncrementEventCounter();
333 /** The global component handler instance */
334 static AliHLTComponentHandler* fpComponentHandler;
335 /** The environment where the component is running in */
336 AliHLTComponentEnvironment fEnvironment;
339 * Set by ProcessEvent before the processing starts (e.g. before calling
340 * @ref AliHLTProcessor::DoEvent)
342 AliHLTEventID_t fCurrentEvent;
344 /** internal event no */
347 ClassDef(AliHLTComponent, 1)