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.
21 #include "AliHLTLogging.h"
22 #include "AliHLTDataTypes.h"
23 #include "AliHLTDefinitions.h"
26 class AliHLTComponentHandler;
29 * @class AliHLTComponent
30 * Base class of HLT data processing components.
31 * The class provides a common interface for HLT data processing components.
32 * The interface can be accessed from the online HLT framework or the AliRoot
33 * offline analysis framework.
34 * Components can be of type
35 * - @ref kSource: components which only produce data
36 * - @ref kProcessor: components which consume and produce data
37 * - @ref kSink: components which only consume data
39 * where data production and consumption refer to the analysis data stream.<br>
41 * In order to adapt to different environments (on-line/off-line), the component
42 * gets an environment structure with function pointers. The base class provides
43 * member functions for those environment dependend functions. The member
44 * functions are used by the component implementation and are re-mapped to the
45 * corresponding functions.
46 * @ingroup alihlt_component
48 class AliHLTComponent : public AliHLTLogging {
50 /** standard constructor */
52 /** standard destructor */
53 virtual ~AliHLTComponent();
55 /** component type definitions */
56 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
59 * Init function to prepare data processing.
60 * Initialization of common data structures for a sequence of events.
61 * The call is redirected to the internal method @ref DoInit which can be
62 * overridden by the child class.<br>
63 * During Init also the environment structure is passed to the component.
64 * @param environ environment pointer with environment dependend function
66 * @param environ_param additionel parameter for function calls, the pointer
68 * @param argc size of the argument array
69 * @param argv agument array for component initialization
71 virtual int Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv );
74 * Clean-up function to terminate data processing.
75 * Clean-up of common data structures after data processing.
76 * The call is redirected to the internal method @ref DoDeinit which can be
77 * overridden by the child class.
82 * Processing of one event.
83 * The method is pure virtual and implemented by the child classes
84 * - @ref AliHLTProcessor
85 * - @ref AliHLTDataSource
86 * - @ref AliHLTDataSink
93 * @param outputBlockCnt
96 * @return neg. error code if failed
98 virtual int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
99 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
100 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
101 AliHLTComponentBlockData*& outputBlocks,
102 AliHLTComponentEventDoneData*& edd ) = 0;
104 // Information member functions for registration.
107 * Get the type of the component.
108 * The function is pure virtual and must be implemented by the child class.
109 * @return component type id
111 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
114 * Get the id of the component.
115 * Each component is identified by a unique id.
116 * The function is pure virtual and must be implemented by the child class.
117 * @return component id (string)
119 virtual const char* GetComponentID() = 0;
122 * Get the input data types of the component.
123 * The function is pure virtual and must be implemented by the child class.
124 * @return list of data types in the vector reference
126 virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& ) = 0;
129 * Get the output data type of the component.
130 * The function is pure virtual and must be implemented by the child class.
131 * @return output data type
133 virtual AliHLTComponentDataType GetOutputDataType() = 0;
136 * Get a ratio by how much the data volume is shrinked or enhanced.
137 * The function is pure virtual and must be implemented by the child class.
138 * @param constBase <i>return</i>: additive part, independent of the
140 * @param inputMultiplier <i>return</i>: multiplication ratio
141 * @return values in the reference variables
143 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
147 * Each component must implement a spawn function to create a new instance of
148 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
149 * @return new class instance
151 virtual AliHLTComponent* Spawn() = 0;
154 * Find matching data types between this component and a consumer component.
155 * Currently, a component can produce only one type of data. This restriction is most
156 * likely to be abolished in the future.
157 * @param pConsumer a component and consumer of the data produced by this component
158 * @param tgtList reference to a vector list to receive the matching data types.
159 * @return >= 0 success, neg. error code if failed
161 int FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList);
164 * Set the global component handler.
165 * The static method is needed for the automatic registration of components.
167 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
170 * Clear the global component handler.
171 * The static method is needed for the automatic registration of components.
173 static int UnsetGlobalComponentHandler();
178 * Fill AliHLTComponentBlockData structure with default values.
179 * @param blockData reference to data structure
181 void FillBlockData( AliHLTComponentBlockData& blockData ) {
182 blockData.fStructSize = sizeof(blockData);
183 FillShmData( blockData.fShmKey );
184 blockData.fOffset = ~(AliHLTUInt32_t)0;
185 blockData.fPtr = NULL;
187 FillDataType( blockData.fDataType );
188 blockData.fSpecification = ~(AliHLTUInt32_t)0;
192 * Fill AliHLTComponentShmData structure with default values.
193 * @param shmData reference to data structure
195 void FillShmData( AliHLTComponentShmData& shmData ) {
196 shmData.fStructSize = sizeof(shmData);
197 shmData.fShmType = gkAliHLTComponentInvalidShmType;
198 shmData.fShmID = gkAliHLTComponentInvalidShmID;
202 * Fill AliHLTComponentDataType structure with default values.
203 * @param dataType reference to data structure
205 void FillDataType( AliHLTComponentDataType& dataType ) {
206 dataType.fStructSize = sizeof(dataType);
207 memset( dataType.fID, '*', 8 );
208 memset( dataType.fOrigin, '*', 4 );
212 * Default method for the internal initialization.
213 * The method is called by @ref Init
215 virtual int DoInit( int argc, const char** argv );
218 * Default method for the internal clean-up.
219 * The method is called by @ref Deinit
221 virtual int DoDeinit();
224 * General memory allocation method.
225 * All memory which is going to be used 'outside' of the interface must
226 * be provided by the framework (online or offline).
227 * The method is redirected to a function provided by the current
228 * framework. Function pointers are transferred via the @ref
229 * AliHLTComponentEnvironment structure.
231 void* AllocMemory( unsigned long size );
234 * Helper function to create a monolithic BlockData description block out
235 * of a list BlockData descriptors.
236 * For convenience, inside the interface vector lists are used, to make the
237 * interface pure C style, monilithic blocks must be exchanged.
238 * The method is redirected to a function provided by the current
239 * framework. Function pointers are transferred via the @ref
240 * AliHLTComponentEnvironment structure.
242 int MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
243 AliHLTComponentBlockData** outputBlocks );
246 * Fill the EventDoneData structure.
247 * The method is redirected to a function provided by the current
248 * framework. Function pointers are transferred via the @ref
249 * AliHLTComponentEnvironment structure.
251 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd );
254 * Helper function to convert the data type to a string.
256 void DataType2Text( const AliHLTComponentDataType& type, char output[14] );
259 /** The global component handler instance */
260 static AliHLTComponentHandler* fpComponentHandler;
261 /** The environment where the component is running in */
262 AliHLTComponentEnvironment fEnvironment;
265 * Set by ProcessEvent before the processing starts (e.g. before calling
266 * @ref AliHLTProcessor::DoEvent)
268 AliHLTEventID_t fCurrentEvent;
270 ClassDef(AliHLTComponent, 0)