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 pure virtual and implemented by the child classes
98 * - @ref AliHLTProcessor
99 * - @ref AliHLTDataSource
100 * - @ref AliHLTDataSink
107 * @param outputBlockCnt out: size of the output block array, set by the component
108 * @param outputBlocks out: the output block array is allocated internally
110 * @return neg. error code if failed
112 virtual int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
113 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
114 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
115 AliHLTComponentBlockData*& outputBlocks,
116 AliHLTComponentEventDoneData*& edd ) = 0;
118 // Information member functions for registration.
121 * Get the type of the component.
122 * The function is pure virtual and must be implemented by the child class.
123 * @return component type id
125 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
128 * Get the id of the component.
129 * Each component is identified by a unique id.
130 * The function is pure virtual and must be implemented by the child class.
131 * @return component id (string)
133 virtual const char* GetComponentID() = 0;
136 * Get the input data types of the component.
137 * The function is pure virtual and must be implemented by the child class.
138 * @return list of data types in the vector reference
140 virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& ) = 0;
143 * Get the output data type of the component.
144 * The function is pure virtual and must be implemented by the child class.
145 * @return output data type
147 virtual AliHLTComponentDataType GetOutputDataType() = 0;
150 * Get a ratio by how much the data volume is shrinked or enhanced.
151 * The function is pure virtual and must be implemented by the child class.
152 * @param constBase <i>return</i>: additive part, independent of the
154 * @param inputMultiplier <i>return</i>: multiplication ratio
155 * @return values in the reference variables
157 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
161 * Each component must implement a spawn function to create a new instance of
162 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
163 * @return new class instance
165 virtual AliHLTComponent* Spawn() = 0;
168 * Find matching data types between this component and a consumer component.
169 * Currently, a component can produce only one type of data. This restriction is most
170 * likely to be abolished in the future.
171 * @param pConsumer a component and consumer of the data produced by this component
172 * @param tgtList reference to a vector list to receive the matching data types.
173 * @return >= 0 success, neg. error code if failed
175 int FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList);
178 * Set the global component handler.
179 * The static method is needed for the automatic registration of components.
181 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
184 * Clear the global component handler.
185 * The static method is needed for the automatic registration of components.
187 static int UnsetGlobalComponentHandler();
190 * Helper function to convert the data type to a string.
192 static string DataType2Text( const AliHLTComponentDataType& type );
195 * helper function to initialize AliHLTComponentEventData structure
197 static void FillEventData(AliHLTComponentEventData& evtData);
200 * Print info on an AliHLTComponentDataType structure
201 * This is just a helper function to examine an @ref AliHLTComponentDataType
204 void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
209 * Fill AliHLTComponentBlockData structure with default values.
210 * @param blockData reference to data structure
212 void FillBlockData( AliHLTComponentBlockData& blockData );
215 * Fill AliHLTComponentShmData structure with default values.
216 * @param shmData reference to data structure
218 void FillShmData( AliHLTComponentShmData& shmData );
221 * Fill AliHLTComponentDataType structure with default values.
222 * @param dataType reference to data structure
224 void FillDataType( AliHLTComponentDataType& dataType );
227 * Copy data type structure
228 * Copies the value an AliHLTComponentDataType structure to another one
229 * @param[out] tgtdt target structure
230 * @param[in] srcdt source structure
232 void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
235 * Set the ID and Origin of an AliHLTComponentDataType structure.
236 * The function sets the fStructureSize member and copies the strings
237 * to the ID and Origin. Only characters from the valid part of the string
238 * are copied, the rest is fille with 0's.
239 * Please note that the fID and fOrigin members are not strings, just arrays of
240 * chars of size @ref kAliHLTComponentDataTypefIDsize and
241 * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
242 * a terminating zero.
243 * @param tgtdt target data type structure
244 * @param id ID string
245 * @param origin Origin string
247 void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
250 * Default method for the internal initialization.
251 * The method is called by @ref Init
253 virtual int DoInit( int argc, const char** argv );
256 * Default method for the internal clean-up.
257 * The method is called by @ref Deinit
259 virtual int DoDeinit();
262 * General memory allocation method.
263 * All memory which is going to be used 'outside' of the interface must
264 * be provided by the framework (online or offline).
265 * The method is redirected to a function provided by the current
266 * framework. Function pointers are transferred via the @ref
267 * AliHLTComponentEnvironment structure.
269 void* AllocMemory( unsigned long size );
272 * Helper function to create a monolithic BlockData description block out
273 * of a list BlockData descriptors.
274 * For convenience, inside the interface vector lists are used, to make the
275 * interface pure C style, monilithic blocks must be exchanged.
276 * The method is redirected to a function provided by the current
277 * framework. Function pointers are transferred via the @ref
278 * AliHLTComponentEnvironment structure.
280 int MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
281 AliHLTComponentBlockData** outputBlocks );
284 * Fill the EventDoneData structure.
285 * The method is redirected to a function provided by the current
286 * framework. Function pointers are transferred via the @ref
287 * AliHLTComponentEnvironment structure.
289 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd );
292 * Helper function to convert the data type to a string.
294 void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]);
297 /** The global component handler instance */
298 static AliHLTComponentHandler* fpComponentHandler;
299 /** The environment where the component is running in */
300 AliHLTComponentEnvironment fEnvironment;
303 * Set by ProcessEvent before the processing starts (e.g. before calling
304 * @ref AliHLTProcessor::DoEvent)
306 AliHLTEventID_t fCurrentEvent;
308 ClassDef(AliHLTComponent, 0)