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.
19 #include "AliHLTLogging.h"
20 #include "AliHLTDataTypes.h"
21 #include "AliHLTDefinitions.h"
24 class AliHLTComponentHandler;
27 * @class AliHLTComponent
28 * Base class of HLT data processing components.
29 * The class provides a common interface for HLT data processing components.
30 * The interface can be accessed from the online HLT framework or the AliRoot
31 * offline analysis framework.
32 * Components can be of type
33 * - @ref kSource: components which only produce data
34 * - @ref kProcessor: components which consume and produce data
35 * - @ref kSink: components which only consume data
37 * where data production and consumption refer to the analysis data stream.<br>
39 * In order to adapt to different environments (on-line/off-line), the component
40 * gets an environment structure with function pointers. The base class provides
41 * member functions for those environment dependend functions. The member
42 * functions are used by the component implementation and are re-mapped to the
43 * corresponding functions.
44 * @ingroup alihlt_component
46 class AliHLTComponent : public AliHLTLogging {
48 /** standard constructor */
50 /** standard destructor */
51 virtual ~AliHLTComponent();
53 /** component type definitions */
54 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
57 * Init function to prepare data processing.
58 * Initialization of common data structures for a sequence of events.
59 * The call is redirected to the internal method @ref DoInit which can be
60 * overridden by the child class.<br>
61 * During Init also the environment structure is passed to the component.
62 * @param environ environment pointer with environment dependend function
64 * @param environ_param additionel parameter for function calls, the pointer
66 * @param argc size of the argument array
67 * @param argv agument array for component initialization
69 virtual int Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv );
72 * Clean-up function to terminate data processing.
73 * Clean-up of common data structures after data processing.
74 * The call is redirected to the internal method @ref DoDeinit which can be
75 * overridden by the child class.
80 * Processing of one event.
81 * The method is pure virtual and implemented by the child classes
82 * - @ref AliHLTProcessor
83 * - @ref AliHLTDataSource
84 * - @ref AliHLTDataSink
91 * @param outputBlockCnt
94 * @return neg. error code if failed
96 virtual int ProcessEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks,
97 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
98 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
99 AliHLTComponent_BlockData*& outputBlocks,
100 AliHLTComponent_EventDoneData*& edd ) = 0;
102 // Information member functions for registration.
105 * Get the type of the component.
106 * The function is pure virtual and must be implemented by the child class.
107 * @return component type id
109 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
112 * Get the id of the component.
113 * Each component is identified by a unique id.
114 * The function is pure virtual and must be implemented by the child class.
115 * @return component id (string)
117 virtual const char* GetComponentID() = 0;
120 * Get the input data types of the component.
121 * The function is pure virtual and must be implemented by the child class.
122 * @return list of data types in the vector reference
124 virtual void GetInputDataTypes( vector<AliHLTComponent_DataType>& ) = 0;
127 * Get the output data type of the component.
128 * The function is pure virtual and must be implemented by the child class.
129 * @return output data type
131 virtual AliHLTComponent_DataType GetOutputDataType() = 0;
134 * Get a ratio by how much the data volume is shrinked or enhanced.
135 * The function is pure virtual and must be implemented by the child class.
136 * @param constBase <i>return</i>: additive part, independent of the
138 * @param inputMultiplier <i>return</i>: multiplication ratio
139 * @return values in the reference variables
141 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
145 * Each component must implement a spawn function to create a new instance of
146 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
147 * @return new class instance
149 virtual AliHLTComponent* Spawn() = 0;
152 * Find matching data types between this component and a consumer component.
153 * Currently, a component can produce only one type of data. This restriction is most
154 * likely to be abolished in the future.
155 * @param pConsumer a component and consumer of the data produced by this component
156 * @param tgtList reference to a vector list to receive the matching data types.
157 * @return >= 0 success, neg. error code if failed
159 int FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponent_DataType>* tgtList);
162 * Set the global component handler.
163 * The static method is needed for the automatic registration of components.
165 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
168 * Clear the global component handler.
169 * The static method is needed for the automatic registration of components.
171 static int UnsetGlobalComponentHandler();
176 * Fill AliHLTComponent_BlockData structure with default values.
177 * @param blockData reference to data structure
179 void FillBlockData( AliHLTComponent_BlockData& blockData ) {
180 blockData.fStructSize = sizeof(blockData);
181 FillShmData( blockData.fShmKey );
182 blockData.fOffset = ~(AliHLTUInt32_t)0;
183 blockData.fPtr = NULL;
185 FillDataType( blockData.fDataType );
186 blockData.fSpecification = ~(AliHLTUInt32_t)0;
190 * Fill AliHLTComponent_ShmData structure with default values.
191 * @param shmData reference to data structure
193 void FillShmData( AliHLTComponent_ShmData& shmData ) {
194 shmData.fStructSize = sizeof(shmData);
195 shmData.fShmType = gkAliHLTComponent_InvalidShmType;
196 shmData.fShmID = gkAliHLTComponent_InvalidShmID;
200 * Fill AliHLTComponent_DataType structure with default values.
201 * @param dataType reference to data structure
203 void FillDataType( AliHLTComponent_DataType& dataType ) {
204 dataType.fStructSize = sizeof(dataType);
205 memset( dataType.fID, '*', 8 );
206 memset( dataType.fOrigin, '*', 4 );
210 * Default method for the internal initialization.
211 * The method is called by @ref Init
213 virtual int DoInit( int argc, const char** argv );
216 * Default method for the internal clean-up.
217 * The method is called by @ref Deinit
219 virtual int DoDeinit();
222 * General memory allocation method.
223 * All memory which is going to be used 'outside' of the interface must
224 * be provided by the framework (online or offline).
225 * The method is redirected to a function provided by the current
226 * framework. Function pointers are transferred via the @ref
227 * AliHLTComponentEnvironment structure.
229 void* AllocMemory( unsigned long size );
232 * Helper function to create a monolithic BlockData description block out
233 * of a list BlockData descriptors.
234 * For convenience, inside the interface vector lists are used, to make the
235 * interface pure C style, monilithic blocks must be exchanged.
236 * The method is redirected to a function provided by the current
237 * framework. Function pointers are transferred via the @ref
238 * AliHLTComponentEnvironment structure.
240 int MakeOutputDataBlockList( const vector<AliHLTComponent_BlockData>& blocks, AliHLTUInt32_t* blockCount,
241 AliHLTComponent_BlockData** outputBlocks );
244 * Fill the EventDoneData structure.
245 * The method is redirected to a function provided by the current
246 * framework. Function pointers are transferred via the @ref
247 * AliHLTComponentEnvironment structure.
249 int GetEventDoneData( unsigned long size, AliHLTComponent_EventDoneData** edd );
252 * Helper function to convert the data type to a string.
254 void DataType2Text( const AliHLTComponent_DataType& type, char output[14] );
257 /** The global component handler instance */
258 static AliHLTComponentHandler* fpComponentHandler;
259 /** The environment where the component is running in */
260 AliHLTComponentEnvironment fEnvironment;
263 * Set by ProcessEvent before the processing starts (e.g. before calling
264 * @ref AliHLTProcessor::DoEvent)
266 AliHLTEventID_t fCurrentEvent;
268 ClassDef(AliHLTComponent, 0)