]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponent.h
changes according to coding conventions
[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>
5ec8e281 21#include "AliHLTLogging.h"
f23a6e1a 22#include "AliHLTDataTypes.h"
71d7c760 23#include "AliHLTDefinitions.h"
f23a6e1a 24#include "TObject.h"
25
26class AliHLTComponentHandler;
27
bfccbf68 28/**
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
38 *
39 * where data production and consumption refer to the analysis data stream.<br>
40 *
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.
b22e91eb 46 * @ingroup alihlt_component
bfccbf68 47 */
5ec8e281 48class AliHLTComponent : public AliHLTLogging {
f23a6e1a 49 public:
bfccbf68 50 /** standard constructor */
f23a6e1a 51 AliHLTComponent();
bfccbf68 52 /** standard destructor */
f23a6e1a 53 virtual ~AliHLTComponent();
54
bfccbf68 55 /** component type definitions */
f23a6e1a 56 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
bfccbf68 57
58 /**
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
65 * calls
66 * @param environ_param additionel parameter for function calls, the pointer
67 * is passed as it is
68 * @param argc size of the argument array
69 * @param argv agument array for component initialization
70 */
f23a6e1a 71 virtual int Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv );
bfccbf68 72
73 /**
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.
78 */
f23a6e1a 79 virtual int Deinit();
bfccbf68 80
81 /**
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
87 *
88 * @param evtData
89 * @param blocks
90 * @param trigData
91 * @param outputPtr
92 * @param size
93 * @param outputBlockCnt
94 * @param outputBlocks
95 * @param edd
96 * @return neg. error code if failed
97 */
8ede8717 98 virtual int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
99 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
71d7c760 100 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
8ede8717 101 AliHLTComponentBlockData*& outputBlocks,
102 AliHLTComponentEventDoneData*& edd ) = 0;
f23a6e1a 103
104 // Information member functions for registration.
bfccbf68 105
106 /**
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
110 */
f23a6e1a 111 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
bfccbf68 112
113 /**
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)
118 */
f23a6e1a 119 virtual const char* GetComponentID() = 0;
bfccbf68 120
121 /**
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
125 */
8ede8717 126 virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& ) = 0;
bfccbf68 127
128 /**
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
132 */
8ede8717 133 virtual AliHLTComponentDataType GetOutputDataType() = 0;
bfccbf68 134
135 /**
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
139 * input data volume
140 * @param inputMultiplier <i>return</i>: multiplication ratio
141 * @return values in the reference variables
142 */
71d7c760 143 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
f23a6e1a 144
bfccbf68 145 /**
146 * Spawn function.
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
150 */
f23a6e1a 151 virtual AliHLTComponent* Spawn() = 0;
0c0c9d99 152
bfccbf68 153 /**
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
160 */
8ede8717 161 int FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList);
f23a6e1a 162
bfccbf68 163 /**
164 * Set the global component handler.
165 * The static method is needed for the automatic registration of components.
166 */
85869391 167 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
bfccbf68 168
169 /**
170 * Clear the global component handler.
171 * The static method is needed for the automatic registration of components.
172 */
85869391 173 static int UnsetGlobalComponentHandler();
bfccbf68 174
f23a6e1a 175 protected:
71d7c760 176
bfccbf68 177 /**
8ede8717 178 * Fill AliHLTComponentBlockData structure with default values.
bfccbf68 179 * @param blockData reference to data structure
180 */
8ede8717 181 void FillBlockData( AliHLTComponentBlockData& blockData ) {
71d7c760 182 blockData.fStructSize = sizeof(blockData);
183 FillShmData( blockData.fShmKey );
184 blockData.fOffset = ~(AliHLTUInt32_t)0;
185 blockData.fPtr = NULL;
186 blockData.fSize = 0;
187 FillDataType( blockData.fDataType );
188 blockData.fSpecification = ~(AliHLTUInt32_t)0;
189 }
bfccbf68 190
191 /**
8ede8717 192 * Fill AliHLTComponentShmData structure with default values.
bfccbf68 193 * @param shmData reference to data structure
194 */
8ede8717 195 void FillShmData( AliHLTComponentShmData& shmData ) {
71d7c760 196 shmData.fStructSize = sizeof(shmData);
8ede8717 197 shmData.fShmType = gkAliHLTComponentInvalidShmType;
198 shmData.fShmID = gkAliHLTComponentInvalidShmID;
71d7c760 199 }
bfccbf68 200
201 /**
8ede8717 202 * Fill AliHLTComponentDataType structure with default values.
bfccbf68 203 * @param dataType reference to data structure
204 */
8ede8717 205 void FillDataType( AliHLTComponentDataType& dataType ) {
71d7c760 206 dataType.fStructSize = sizeof(dataType);
207 memset( dataType.fID, '*', 8 );
208 memset( dataType.fOrigin, '*', 4 );
209 }
f23a6e1a 210
bfccbf68 211 /**
212 * Default method for the internal initialization.
213 * The method is called by @ref Init
214 */
53feaef5 215 virtual int DoInit( int argc, const char** argv );
f23a6e1a 216
bfccbf68 217 /**
218 * Default method for the internal clean-up.
219 * The method is called by @ref Deinit
220 */
53feaef5 221 virtual int DoDeinit();
f23a6e1a 222
bfccbf68 223 /**
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.
230 */
85869391 231 void* AllocMemory( unsigned long size );
f23a6e1a 232
bfccbf68 233 /**
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.
241 */
8ede8717 242 int MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
243 AliHLTComponentBlockData** outputBlocks );
f23a6e1a 244
bfccbf68 245 /**
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.
250 */
8ede8717 251 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd );
f23a6e1a 252
bfccbf68 253 /**
254 * Helper function to convert the data type to a string.
255 */
8ede8717 256 void DataType2Text( const AliHLTComponentDataType& type, char output[14] );
fa2e9b7c 257
f23a6e1a 258 private:
bfccbf68 259 /** The global component handler instance */
f23a6e1a 260 static AliHLTComponentHandler* fpComponentHandler;
bfccbf68 261 /** The environment where the component is running in */
f23a6e1a 262 AliHLTComponentEnvironment fEnvironment;
263
bfccbf68 264 /**
265 * Set by ProcessEvent before the processing starts (e.g. before calling
266 * @ref AliHLTProcessor::DoEvent)
267 */
268 AliHLTEventID_t fCurrentEvent;
f23a6e1a 269
270 ClassDef(AliHLTComponent, 0)
271};
272#endif