]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponent.h
Detector updates.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.h
CommitLineData
a655eae3 1//-*- Mode: C++ -*-
45c0a780 2// $Id$
f23a6e1a 3
4#ifndef ALIHLTCOMPONENT_H
5#define ALIHLTCOMPONENT_H
45c0a780 6//* This file is property of and copyright by the ALICE HLT Project *
7//* ALICE Experiment at CERN, All rights reserved. *
8//* See cxx source for full Copyright notice *
f23a6e1a 9
bfccbf68 10/** @file AliHLTComponent.h
11 @author Matthias Richter, Timm Steinbeck
12 @date
b22e91eb 13 @brief Base class declaration for HLT components.
14 @note The class is both used in Online (PubSub) and Offline (AliRoot)
15 context
45c0a780 16*/
30338a30 17
b22e91eb 18/**
19 * @defgroup alihlt_component Component handling of the HLT module
45c0a780 20 * This section describes the the component base classes and handling for
21 * the HLT module.
22 *
23 * @section alihlt_component_intro General remarks
24 * HLT analysis is organized in so called components. Each component can
25 * subscribe to the data produced by other components and can from the
26 * analysis publish new data for the subsequent components. Only the
27 * input data blocks and entries from CDB are available for the analysis.
28 *
29 * @section alihlt_component_intro Component implementation
30 * AliHLTComponent provides the interface for all components, see there
31 * for details. Three types are provided:
32 * - AliHLTProcessor
33 * - AliHLTDataSource
34 * - AliHLTDataSink
35 *
36 * The two last represent data sinks and sources for the HLT integration
37 * into AliRoot. When running only, only the processors are relevant,
38 * sources and sinks are provided by the HLT PubSub framework. Please check
39 * AliHLTComponent for detailed description.
40 *
41 * @section alihlt_component_registration Component registration
42 * Components need to be registered with the AliHLTComponentHandler in
43 * order to be used with the system. Registration is purely done from the
44 * module library. Two methods are possible:
45 * - the module library implements an AliHLTModuleAgent and overloads the
46 * AliHLTModuleAgent::RegisterComponents() function
47 * - in the implementation file, one object is defined. The global object is
48 * automatically instantiated when the library is loaded for the first
49 * time and the object is used for registration.
50 *
51 * In both cases, the library must be loaded via the method
52 * <pre>
53 * AliHLTComponentHandler::LoadComponentLibraries()
54 * </pre>
55 * For the global object approach it is important that the library is
56 * not loaded elsewhere before (e.g. a gSystem->Load operation in your
57 * rootlogon.C).
58 *
59 *
b22e91eb 60 */
8ede8717 61
62#include <vector>
9ce4bf4a 63#include <string>
5ec8e281 64#include "AliHLTLogging.h"
f23a6e1a 65#include "AliHLTDataTypes.h"
1ac82ce6 66#include "AliHLTCommonCDBEntries.h"
f23a6e1a 67
2d7ff710 68/* Matthias Dec 2006
69 * The names have been changed for Aliroot's coding conventions sake
70 * The old names are defined for backward compatibility with the
71 * stand alone SampleLib package
72 */
73typedef AliHLTComponentLogSeverity AliHLTComponent_LogSeverity;
74typedef AliHLTComponentEventData AliHLTComponent_EventData;
75typedef AliHLTComponentShmData AliHLTComponent_ShmData;
76typedef AliHLTComponentDataType AliHLTComponent_DataType;
77typedef AliHLTComponentBlockData AliHLTComponent_BlockData;
78typedef AliHLTComponentTriggerData AliHLTComponent_TriggerData;
79typedef AliHLTComponentEventDoneData AliHLTComponent_EventDoneData;
80
f23a6e1a 81class AliHLTComponentHandler;
a655eae3 82class TObjArray;
90ebac25 83class TStopwatch;
2be3f004 84class AliHLTComponent;
79c114b5 85class AliHLTMemoryFile;
f23a6e1a 86
2be3f004 87/** list of component data type structures */
88typedef vector<AliHLTComponentDataType> AliHLTComponentDataTypeList;
89/** list of component block data structures */
90typedef vector<AliHLTComponentBlockData> AliHLTComponentBlockDataList;
91/** list of component pointers */
92typedef vector<AliHLTComponent*> AliHLTComponentPList;
93/** list of memory file pointers */
94typedef vector<AliHLTMemoryFile*> AliHLTMemoryFilePList;
95
bfccbf68 96/**
97 * @class AliHLTComponent
98 * Base class of HLT data processing components.
99 * The class provides a common interface for HLT data processing components.
100 * The interface can be accessed from the online HLT framework or the AliRoot
101 * offline analysis framework.
a655eae3 102 * @section alihltcomponent-properties Component identification and properties
103 * Each component must provide a unique ID, input and output data type indications,
104 * and a spawn function.
105 * @subsection alihltcomponent-req-methods Required property methods
106 * - @ref GetComponentID
107 * - @ref GetInputDataTypes (see @ref alihltcomponent-type for default
108 * implementations.)
109 * - @ref GetOutputDataType (see @ref alihltcomponent-type for default
110 * implementations.)
111 * - @ref GetOutputDataSize (see @ref alihltcomponent-type for default
112 * implementations.)
113 * - @ref Spawn
bfccbf68 114 *
a655eae3 115 * @subsection alihltcomponent-opt-mehods Optional handlers
116 * - @ref DoInit
117 * - @ref DoDeinit
de6593d0 118 * - @ref GetOutputDataTypes
119 * If the component has multiple output data types @ref GetOutputDataType
120 * should return @ref kAliHLTMultipleDataType. The framework will invoke
121 * @ref GetOutputDataTypes, a list can be filled.
a655eae3 122 *
123 * @subsection alihltcomponent-processing-mehods Data processing
124 *
125 *
126 * @subsection alihltcomponent-type Component type
127 * Components can be of type
90ebac25 128 * - @ref kSource components which only produce data
129 * - @ref kProcessor components which consume and produce data
130 * - @ref kSink components which only consume data
a655eae3 131 *
132 * where data production and consumption refer to the analysis data stream. In
133 * order to indicate the type, a child component can overload the
134 * @ref GetComponentType function.
135 * @subsubsection alihltcomponent-type-std Standard implementations
136 * Components in general do not need to implement this function, standard
137 * implementations of the 3 types are available:
138 * - AliHLTDataSource for components of type @ref kSource <br>
139 * All types of data sources can inherit from AliHLTDataSource and must
140 * implement the @ref AliHLTDataSource::GetEvent method. The class
141 * also implements a standard method for @ref GetInputDataTypes.
142 *
143 * - AliHLTProcessor for components of type @ref kProcessor <br>
144 * All types of data processors can inherit from AliHLTDataSource and must
145 * implement the @ref AliHLTProcessor::DoEvent method.
146 *
147 * - AliHLTDataSink for components of type @ref kSink <br>
148 * All types of data processors can inherit from AliHLTDataSource and must
149 * implement the @ref AliHLTDataSink::DumpEvent method. The class
150 * also implements a standard method for @ref GetOutputDataType and @ref
151 * GetOutputDataSize.
152 *
153 * @subsection alihltcomponent-environment Running environment
bfccbf68 154 *
155 * In order to adapt to different environments (on-line/off-line), the component
156 * gets an environment structure with function pointers. The base class provides
157 * member functions for those environment dependend functions. The member
158 * functions are used by the component implementation and are re-mapped to the
159 * corresponding functions.
b6800be0 160 *
a655eae3 161 * @section alihltcomponent-interfaces Component interfaces
162 * Each of the 3 standard component base classes AliHLTProcessor, AliHLTDataSource
163 * and AliHLTDataSink provides it's own processing method (see
164 * @ref alihltcomponent-type-std), which splits into a high and a low-level
165 * method. For the @ref alihltcomponent-low-level-interface, all parameters are
166 * shipped as function arguments, the component is supposed to dump data to the
167 * output buffer and handle all block descriptors.
168 * The @ref alihltcomponent-high-level-interface is the standard processing
169 * method and will be used whenever the low-level method is not overloaded.
170 *
b6800be0 171 * In both cases it is necessary to calculate/estimate the size of the output
172 * buffer before the processing. Output buffers can never be allocated inside
173 * the component because of the push-architecture of the HLT.
174 * For that reason the @ref GetOutputDataSize function should return a rough
175 * estimatian of the data to be produced by the component. The component is
176 * responsible for checking the memory size and must return -ENOSPC if the
177 * available buffer is to small, and update the estimator respectively. The
178 * framework will allocate a buffer of appropriate size and call the processing
179 * again.
180 *
b426991e 181 * @subsection alihltcomponent-error-codes Data processing
182 * For return codes, the following scheme applies:
183 * - The data processing methods have to indicate error conditions by a negative
184 * error/return code. Preferably the system error codes are used like
185 * e.g. -EINVAL. This requires to include the header
186 * <pre>
616eb170 187 * \#include \<cerrno\>
b426991e 188 * </pre>
189 * - If no suitable input block could be found (e.g. no clusters for the TPC cluster
190 * finder) set size to 0, block list is empty, return 0
191 * - If no ususable or significant signal could be found in the input blocks
192 * return an empty output block, set size accordingly, and return 0. An empty output
193 * block here could be either a real empty one of size 0 (in which case size also
194 * would have to be set to zero) or a block filled with just the minimum necessary
195 * accounting/meta-structures. E.g. in the TPC
196 *
a655eae3 197 * @subsection alihltcomponent-high-level-interface High-level interface
198 * The high-level component interface provides functionality to exchange ROOT
199 * structures between components. In contrast to the
200 * @ref alihltcomponent-low-level-interface, a couple of functions can be used
201 * to access data blocks of the input stream
202 * and send data blocks or ROOT TObject's to the output stream. The functionality
203 * is hidden from the user and is implemented by using ROOT's TMessage class.
204 *
205 * @subsubsection alihltcomponent-high-level-int-methods Interface methods
206 * The interface provides a couple of methods in order to get objects from the
207 * input, data blocks (non TObject) from the input, and to push back objects and
208 * data blocks to the output. For convenience there are several functions of
209 * identical name (and similar behavior) with different parameters defined.
210 * Please refer to the function documentation.
211 * - @ref GetNumberOfInputBlocks <br>
212 * return the number of data blocks in the input stream
213 * - @ref GetFirstInputObject <br>
214 * get the first object of a specific data type
215 * - @ref GetNextInputObject <br>
216 * get the next object of same data type as last GetFirstInputObject/Block call
217 * - @ref GetFirstInputBlock <br>
218 * get the first block of a specific data type
219 * - @ref GetNextInputBlock <br>
220 * get the next block of same data type as last GetFirstInputBlock/Block call
221 * - @ref PushBack <br>
222 * insert an object or data buffer into the output
223 * - @ref CreateEventDoneData <br>
224 * add event information to the output
225 *
226 * In addition, the processing methods are simplified a bit by cutting out most of
79c114b5 227 * the parameters.
228 * @see
229 * - @ref AliHLTProcessor::DoEvent
230 * - @ref AliHLTDataSource::GetEvent
231 * - @ref AliHLTDataSink::DumpEvent
a655eae3 232 *
8451168b 233 * \em IMPORTANT: objects and block descriptors provided by the high-level interface
234 * <b>MUST NOT BE DELETED</b> by the caller.
235 *
a655eae3 236 * @subsubsection alihltcomponent-high-level-int-guidelines High-level interface guidelines
237 * - Structures must inherit from the ROOT object base class TObject in order be
238 * transported by the transportation framework.
239 * - all pointer members must be transient (marked <tt>//!</tt> behind the member
240 * definition), i.e. will not be stored/transported, or properly marked
241 * (<tt>//-></tt>) in order to call the streamer of the object the member is pointing
242 * to. The latter is not recomended. Structures to be transported between components
243 * should be streamlined.
244 * - no use of stl vectors/strings, use appropriate ROOT classes instead
245 *
246 * @subsection alihltcomponent-low-level-interface Low-level interface
247 * The low-level component interface consists of the specific data processing
248 * methods for @ref AliHLTProcessor, @ref AliHLTDataSource, and @ref AliHLTDataSink.
249 * - @ref AliHLTProcessor::DoEvent
250 * - @ref AliHLTDataSource::GetEvent
251 * - @ref AliHLTDataSink::DumpEvent
252 *
253 *
254 * @section alihltcomponent-handling Component handling
255 * The handling of HLT analysis components is carried out by the AliHLTComponentHandler.
256 * Component are registered automatically at load-time of the component shared library
257 * under the following suppositions:
258 * - the component library has to be loaded from the AliHLTComponentHandler using the
259 * @ref AliHLTComponentHandler::LoadLibrary method.
260 * - the component implementation defines one global object (which is generated
261 * when the library is loaded)
262 *
263 * @subsection alihltcomponent-design-rules General design considerations
264 * The analysis code should be implemented in one or more destict class(es). A
265 * \em component should be implemented which interface the destict analysis code to the
266 * component interface. This component generates the analysis object dynamically. <br>
267 *
268 * Assume you have an implemetation <tt> AliHLTDetMyAnalysis </tt>, another class <tt>
269 * AliHLTDetMyAnalysisComponent </tt> contains:
270 * <pre>
271 * private:
272 * AliHLTDetMyAnalysis* fMyAnalysis; //!
273 * </pre>
274 * The object should then be instantiated in the DoInit handler of
275 * <tt>AliHLTDetMyAnalysisComponent </tt>, and cleaned in the DoDeinit handler.
276 *
277 * Further rules:
278 * - avoid big static arrays in the component, allocate the memory at runtime
279 *
b22e91eb 280 * @ingroup alihlt_component
a655eae3 281 * @section alihltcomponent-members Class members
bfccbf68 282 */
5ec8e281 283class AliHLTComponent : public AliHLTLogging {
f23a6e1a 284 public:
bfccbf68 285 /** standard constructor */
f23a6e1a 286 AliHLTComponent();
bfccbf68 287 /** standard destructor */
f23a6e1a 288 virtual ~AliHLTComponent();
289
bfccbf68 290 /** component type definitions */
f23a6e1a 291 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
bfccbf68 292
293 /**
294 * Init function to prepare data processing.
295 * Initialization of common data structures for a sequence of events.
296 * The call is redirected to the internal method @ref DoInit which can be
297 * overridden by the child class.<br>
298 * During Init also the environment structure is passed to the component.
299 * @param environ environment pointer with environment dependend function
300 * calls
70ed7d01 301 * @param environParam additionel parameter for function calls, the pointer
bfccbf68 302 * is passed as it is
303 * @param argc size of the argument array
304 * @param argv agument array for component initialization
305 */
70ed7d01 306 virtual int Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv );
bfccbf68 307
308 /**
309 * Clean-up function to terminate data processing.
310 * Clean-up of common data structures after data processing.
311 * The call is redirected to the internal method @ref DoDeinit which can be
312 * overridden by the child class.
313 */
f23a6e1a 314 virtual int Deinit();
bfccbf68 315
316 /**
317 * Processing of one event.
3cde846d 318 * The method is the entrance of the event processing. The parameters are
319 * cached for uses with the high-level interface and the DoProcessing
320 * implementation is called.
321 *
322 * @param evtData
323 * @param blocks
324 * @param trigData
325 * @param outputPtr
326 * @param size
327 * @param outputBlockCnt out: size of the output block array, set by the component
328 * @param outputBlocks out: the output block array is allocated internally
329 * @param edd
330 * @return neg. error code if failed
331 */
332 int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
333 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
334 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
335 AliHLTComponentBlockData*& outputBlocks,
336 AliHLTComponentEventDoneData*& edd );
337
338 /**
339 * Internal processing of one event.
bfccbf68 340 * The method is pure virtual and implemented by the child classes
341 * - @ref AliHLTProcessor
342 * - @ref AliHLTDataSource
343 * - @ref AliHLTDataSink
344 *
345 * @param evtData
346 * @param blocks
347 * @param trigData
348 * @param outputPtr
349 * @param size
2d7ff710 350 * @param outputBlocks out: the output block array is allocated internally
bfccbf68 351 * @param edd
352 * @return neg. error code if failed
353 */
3cde846d 354 virtual int DoProcessing( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
8ede8717 355 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
a655eae3 356 AliHLTUInt32_t& size,
2be3f004 357 AliHLTComponentBlockDataList& outputBlocks,
8ede8717 358 AliHLTComponentEventDoneData*& edd ) = 0;
f23a6e1a 359
579d9eb7 360 /**
361 * Init the CDB.
362 * The function must not be called when running in AliRoot unless it it
363 * really wanted. The CDB path will be set to the specified path, which might
364 * override the path initialized at the beginning of the AliRoot reconstruction.
365 *
366 * The method is used from the external interface in order to set the correct
82c58a87 367 * path when running on-line. The function also initializes the function
368 * callback for setting the run no during operation.
369 *
370 * A separation of library and component handling is maybe appropriate in the
371 * future. Using the global component handler here is maybe not the cleanest
372 * solution.
373 * @param cdbPath path of the CDB
374 * @param pHandler the component handler used for llibrary handling.
579d9eb7 375 */
82c58a87 376 int InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler);
579d9eb7 377
378 /**
379 * Set the run no for the CDB.
380 * The function must not be called when running in AliRoot unless it it
381 * really wanted. The CDB path will be set to the specified path, which might
382 * override the run no initialized at the beginning of the AliRoot reconstruction.
45c0a780 383 * InitCDB() has to be called before in order to really change the CDB settings.
579d9eb7 384 *
385 * The method is used from the external interface in order to set the correct
386 * path when running on-line.
387 */
388 int SetCDBRunNo(int runNo);
389
45c0a780 390 /**
391 * Set the run description.
392 * The run description is set before the call of Init() -> DoInit().
393 * @note: This functionality has been added in Juli 2008. The transmission of
394 * run properties by a special SOR (SOD event in DAQ terminalogy but this was
395 * changed after the HLT interface was designed) event is not sufficient because
396 * the data might be needed already in the DoInit handler of the component.
397 * @param desc run descriptor, currently only the run no member is used
398 * @param runType originally, run type was supposed to be a number and part
399 * of the run descriptor. But it was defined as string later
400 */
401 int SetRunDescription(const AliHLTRunDesc* desc, const char* runType);
402
f23a6e1a 403 // Information member functions for registration.
bfccbf68 404
405 /**
406 * Get the type of the component.
407 * The function is pure virtual and must be implemented by the child class.
408 * @return component type id
409 */
f23a6e1a 410 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
bfccbf68 411
412 /**
413 * Get the id of the component.
414 * Each component is identified by a unique id.
415 * The function is pure virtual and must be implemented by the child class.
416 * @return component id (string)
417 */
f23a6e1a 418 virtual const char* GetComponentID() = 0;
bfccbf68 419
420 /**
421 * Get the input data types of the component.
422 * The function is pure virtual and must be implemented by the child class.
423 * @return list of data types in the vector reference
424 */
2be3f004 425 virtual void GetInputDataTypes( AliHLTComponentDataTypeList& ) = 0;
bfccbf68 426
427 /**
428 * Get the output data type of the component.
429 * The function is pure virtual and must be implemented by the child class.
430 * @return output data type
431 */
8ede8717 432 virtual AliHLTComponentDataType GetOutputDataType() = 0;
bfccbf68 433
de6593d0 434 /**
435 * Get the output data types of the component.
436 * The function can be implemented to indicate multiple output data types
437 * in the target array.
438 * @ref GetOutputDataType must return @ref kAliHLTMultipleDataType in order
439 * to invoke this method.
440 * @param tgtList list to receive the data types
441 * @return no of output data types, data types in the target list
442 */
2be3f004 443 virtual int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList);
de6593d0 444
bfccbf68 445 /**
446 * Get a ratio by how much the data volume is shrinked or enhanced.
447 * The function is pure virtual and must be implemented by the child class.
448 * @param constBase <i>return</i>: additive part, independent of the
449 * input data volume
450 * @param inputMultiplier <i>return</i>: multiplication ratio
451 * @return values in the reference variables
452 */
71d7c760 453 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
f23a6e1a 454
bfccbf68 455 /**
456 * Spawn function.
457 * Each component must implement a spawn function to create a new instance of
458 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
459 * @return new class instance
460 */
f23a6e1a 461 virtual AliHLTComponent* Spawn() = 0;
0c0c9d99 462
bfccbf68 463 /**
464 * Find matching data types between this component and a consumer component.
465 * Currently, a component can produce only one type of data. This restriction is most
466 * likely to be abolished in the future.
467 * @param pConsumer a component and consumer of the data produced by this component
468 * @param tgtList reference to a vector list to receive the matching data types.
469 * @return >= 0 success, neg. error code if failed
470 */
2be3f004 471 int FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList);
f23a6e1a 472
bfccbf68 473 /**
474 * Set the global component handler.
475 * The static method is needed for the automatic registration of components.
476 */
85869391 477 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
bfccbf68 478
479 /**
480 * Clear the global component handler.
481 * The static method is needed for the automatic registration of components.
482 */
85869391 483 static int UnsetGlobalComponentHandler();
bfccbf68 484
9ce4bf4a 485 /**
486 * Helper function to convert the data type to a string.
fbdb63fd 487 * @param type data type structure
488 * @param mode 0 print string origin:type <br>
489 * 1 print chars <br>
490 * 2 print numbers
9ce4bf4a 491 */
fbdb63fd 492 static string DataType2Text( const AliHLTComponentDataType& type, int mode=0);
9ce4bf4a 493
5f5b708b 494 /**
495 * Helper function to print content of data type.
496 */
8b97f4f1 497 static void PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format=NULL);
5f5b708b 498
9ce4bf4a 499 /**
500 * helper function to initialize AliHLTComponentEventData structure
501 */
502 static void FillEventData(AliHLTComponentEventData& evtData);
503
504 /**
505 * Print info on an AliHLTComponentDataType structure
506 * This is just a helper function to examine an @ref AliHLTComponentDataType
507 * structur.
508 */
8b97f4f1 509 static void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
9ce4bf4a 510
fbdb63fd 511 /**
512 * Fill AliHLTComponentBlockData structure with default values.
513 * @param blockData reference to data structure
514 */
515 static void FillBlockData( AliHLTComponentBlockData& blockData );
516
517 /**
518 * Fill AliHLTComponentShmData structure with default values.
519 * @param shmData reference to data structure
520 */
521 static void FillShmData( AliHLTComponentShmData& shmData );
522
523 /**
524 * Fill AliHLTComponentDataType structure with default values.
525 * @param dataType reference to data structure
526 */
527 static void FillDataType( AliHLTComponentDataType& dataType );
528
529 /**
530 * Copy data type structure
531 * Copies the value an AliHLTComponentDataType structure to another one
532 * @param[out] tgtdt target structure
533 * @param[in] srcdt source structure
534 */
535 static void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
536
537 /**
538 * Set the ID and Origin of an AliHLTComponentDataType structure.
539 * The function sets the fStructureSize member and copies the strings
540 * to the ID and Origin. Only characters from the valid part of the string
7e3efc8f 541 * are copied, the rest is filled with 0's. <br>
fbdb63fd 542 * Please note that the fID and fOrigin members are not strings, just arrays of
543 * chars of size @ref kAliHLTComponentDataTypefIDsize and
544 * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
7e3efc8f 545 * a terminating zero. <br>
546 * It is possible to pass NULL pointers as id or origin argument, in that case they
547 * are just ignored.
fbdb63fd 548 * @param tgtdt target data type structure
549 * @param id ID string
550 * @param origin Origin string
551 */
552 static void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
553
18b56222 554 /**
555 * Set the ID and Origin of an AliHLTComponentDataType structure.
556 * Given the fact that the data type ID is 64bit wide and origin 32, this helper
557 * function sets the data type from those two parameters.
af2ed151 558 * @param dt target data type structure
18b56222 559 * @param id 64bit id
af2ed151 560 * @param orig 32bit origin
18b56222 561 */
562 static void SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t orig);
563
90ebac25 564 /**
565 * Stopwatch type for benchmarking.
566 */
567 enum AliHLTStopwatchType {
568 /** total time for event processing */
569 kSWBase,
570 /** detector algorithm w/o interface callbacks */
571 kSWDA,
572 /** data sources */
573 kSWInput,
574 /** data sinks */
575 kSWOutput,
576 /** number of types */
577 kSWTypeCount
578 };
579
580 /**
581 * Helper class for starting and stopping a stopwatch.
582 * The guard can be used by instantiating an object in a function. The
583 * specified stopwatch is started and the previous stopwatch put on
584 * hold. When the function is terminated, the object is deleted automatically
585 * deleted, stopping the stopwatch and starting the one on hold.<br>
586 * \em IMPORTANT: never create dynamic objects from this guard as this violates
587 * the idea of a guard.
588 */
589 class AliHLTStopwatchGuard {
590 public:
591 /** standard constructor (not for use) */
592 AliHLTStopwatchGuard();
593 /** constructor */
594 AliHLTStopwatchGuard(TStopwatch* pStart);
595 /** copy constructor (not for use) */
e419b223 596 AliHLTStopwatchGuard(const AliHLTStopwatchGuard&);
597 /** assignment operator (not for use) */
598 AliHLTStopwatchGuard& operator=(const AliHLTStopwatchGuard&);
90ebac25 599 /** destructor */
600 ~AliHLTStopwatchGuard();
601
602 private:
603 /**
604 * Hold the previous guard for the existence of this guard.
605 * Checks whether this guard controls a new stopwatch. In that case, the
606 * previous guard and its stopwatch are put on hold.
607 * @param pSucc instance of the stopwatch of the new guard
608 * @return 1 if pSucc is a different stopwatch which should
609 * be started<br>
610 * 0 if it controls the same stopwatch
611 */
612 int Hold(TStopwatch* pSucc);
613
614 /**
615 * Resume the previous guard.
616 * Checks whether the peceeding guard controls a different stopwatch. In that
617 * case, the its stopwatch is resumed.
618 * @param pSucc instance of the stopwatch of the new guard
619 * @return 1 if pSucc is a different stopwatch which should
620 * be stopped<br>
621 * 0 if it controls the same stopwatch
622 */
623 int Resume(TStopwatch* pSucc);
624
625 /** the stopwatch controlled by this guard */
626 TStopwatch* fpStopwatch; //!transient
627
628 /** previous stopwatch guard, put on hold during existence of the guard */
629 AliHLTStopwatchGuard* fpPrec; //!transient
630
631 /** active stopwatch guard */
632 static AliHLTStopwatchGuard* fgpCurrent; //!transient
633 };
634
635 /**
636 * Set a stopwatch for a given purpose.
637 * @param pSW stopwatch object
638 * @param type type of the stopwatch
639 */
640 int SetStopwatch(TObject* pSW, AliHLTStopwatchType type=kSWBase);
641
642 /**
643 * Init a set of stopwatches.
644 * @param pStopwatches object array of stopwatches
645 */
646 int SetStopwatches(TObjArray* pStopwatches);
a655eae3 647
f23a6e1a 648 protected:
71d7c760 649
bfccbf68 650 /**
651 * Default method for the internal initialization.
652 * The method is called by @ref Init
653 */
53feaef5 654 virtual int DoInit( int argc, const char** argv );
f23a6e1a 655
bfccbf68 656 /**
657 * Default method for the internal clean-up.
658 * The method is called by @ref Deinit
659 */
53feaef5 660 virtual int DoDeinit();
f23a6e1a 661
579d9eb7 662 /**
663 * Reconfigure the component.
664 * The method is called when an event of type @ref kAliHLTDataTypeComConf
665 * {COM_CONF:PRIV} is received by the component. If the event is sent as
666 * part of a normal event, the component configuration is called first.
667 *
668 * The CDB path parameter specifies the path in the CDB, i.e. without
669 * leading absolute path of the CDB location. The framework might alse
670 * provide the id of the component in the analysis chain.
671 *
672 * \b Note: The CDB will be initialized by the framework, either already set
673 * from AliRoot or from the wrapper interface during initialization.
674 *
675 * @param cdbEntry path of the cdbEntry
676 * @param chainId the id of the component in the analysis chain
677 * @note both parameters can be NULL, check before usage
678 */
679 virtual int Reconfigure(const char* cdbEntry, const char* chainId);
b543e186 680
681 /**
682 * Read the Preprocessor values.
683 * The function is invoked when the component is notified about available/
684 * updated data points from the detector Preprocessors. The 'modules'
685 * argument contains all detectors for which the Preprocessors have
686 * updated data points. The component has to implement the CDB access to
687 * get the desired data points.
688 * @param modules detectors for which the Preprocessors have updated
d6b69874 689 * data points: TPC, TRD, ITS, PHOS, MUON, or ALL if
690 * no argument was received.
b543e186 691 * @return neg. error code if failed
692 */
693 virtual int ReadPreprocessorValues(const char* modules);
579d9eb7 694
45c0a780 695 /**
696 * Custom handler for the SOR event.
697 * Is invoked from the base class if an SOR event is in the block list.
698 * The handler is called before the processing function. The processing
699 * function is skipped if there are no other data blocks available.
700 *
701 * The SOR event is generated by the PubSub framework in response to
702 * the DAQ start of data (SOD - has been renamed after HLT interface
703 * was designed). The SOD event consists of 3 blocks:
704 * - ::kAliHLTDataTypeEvent block: spec ::gkAliEventTypeStartOfRun
705 * - SOD block of type ::kAliHLTDataTypeSOR, payload: AliHLTRunDesc struct
706 * - run type block ::kAliHLTDataTypeRunType, payload: run type string
707 *
708 * Run properties can be retrieved by getters like GetRunNo().
709 * @return neg. error code if failed
710 */
711 virtual int StartOfRun();
712
713 /**
714 * Custom handler for the EOR event.
715 * Is invoked from the base class if an EOR event is in the block list.
716 * The handler is called before the processing function. The processing
717 * function is skipped if there are no other data blocks available.
718 *
719 * See StartOfRun() for mor ecomments of the sequence of steering events.
720 *
721 * @return neg. error code if failed
722 */
723 virtual int EndOfRun();
724
bfccbf68 725 /**
726 * General memory allocation method.
727 * All memory which is going to be used 'outside' of the interface must
728 * be provided by the framework (online or offline).
729 * The method is redirected to a function provided by the current
730 * framework. Function pointers are transferred via the @ref
731 * AliHLTComponentEnvironment structure.
732 */
85869391 733 void* AllocMemory( unsigned long size );
f23a6e1a 734
bfccbf68 735 /**
736 * Helper function to create a monolithic BlockData description block out
737 * of a list BlockData descriptors.
738 * For convenience, inside the interface vector lists are used, to make the
739 * interface pure C style, monilithic blocks must be exchanged.
740 * The method is redirected to a function provided by the current
741 * framework. Function pointers are transferred via the @ref
742 * AliHLTComponentEnvironment structure.
743 */
2be3f004 744 int MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
8ede8717 745 AliHLTComponentBlockData** outputBlocks );
f23a6e1a 746
bfccbf68 747 /**
748 * Fill the EventDoneData structure.
749 * The method is redirected to a function provided by the current
750 * framework. Function pointers are transferred via the @ref
751 * AliHLTComponentEnvironment structure.
752 */
8ede8717 753 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd );
f23a6e1a 754
bfccbf68 755 /**
756 * Helper function to convert the data type to a string.
757 */
70ed7d01 758 void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]) const;
fa2e9b7c 759
3cde846d 760 /**
761 * Get event number.
762 * @return value of the internal event counter
763 */
70ed7d01 764 int GetEventCount() const;
3cde846d 765
a655eae3 766 /**
767 * Get the number of input blocks.
768 * @return number of input blocks
769 */
66043029 770 int GetNumberOfInputBlocks() const;
a655eae3 771
772 /**
773 * Get the first object of a specific data type from the input data.
774 * The hight-level methods provide functionality to transfer ROOT data
775 * structures which inherit from TObject.
3dd8541e 776 *
a655eae3 777 * The method looks for the first ROOT object of type dt in the input stream.
778 * If also the class name is provided, the object is checked for the right
779 * class type. The input data block needs a certain structure, namely the
780 * buffer size as first word. If the cross check fails, the retrieval is
8451168b 781 * silently abondoned, unless the \em bForce parameter is set.<br>
3dd8541e 782 * \b Note: THE OBJECT MUST NOT BE DELETED by the caller.
783 *
784 * If called without parameters, the function tries to create objects from
785 * all available input blocks, also the ones of data type kAliHLTVoidDataType
786 * which are not matched by kAliHLTAnyDataType.
787 *
a655eae3 788 * @param dt data type of the object
789 * @param classname class name of the object
790 * @param bForce force the retrieval of an object, error messages
791 * are suppressed if \em bForce is not set
792 * @return pointer to @ref TObject, NULL if no objects of specified type
793 * available
794 */
3dd8541e 795 const TObject* GetFirstInputObject(const AliHLTComponentDataType& dt=kAliHLTAllDataTypes,
a655eae3 796 const char* classname=NULL,
797 int bForce=0);
798
799 /**
800 * Get the first object of a specific data type from the input data.
801 * The hight-level methods provide functionality to transfer ROOT data
802 * structures which inherit from TObject.
803 * The method looks for the first ROOT object of type specified by the ID and
804 * Origin strings in the input stream.
805 * If also the class name is provided, the object is checked for the right
806 * class type. The input data block needs a certain structure, namely the
807 * buffer size as first word. If the cross check fails, the retrieval is
8451168b 808 * silently abondoned, unless the \em bForce parameter is set.<br>
809 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
a655eae3 810 * @param dtID data type ID of the object
811 * @param dtOrigin data type origin of the object
812 * @param classname class name of the object
813 * @param bForce force the retrieval of an object, error messages
814 * are suppressed if \em bForce is not set
815 * @return pointer to @ref TObject, NULL if no objects of specified type
816 * available
817 */
818 const TObject* GetFirstInputObject(const char* dtID,
819 const char* dtOrigin,
820 const char* classname=NULL,
821 int bForce=0);
822
823 /**
824 * Get the next object of a specific data type from the input data.
825 * The hight-level methods provide functionality to transfer ROOT data
826 * structures which inherit from TObject.
827 * The method looks for the next ROOT object of type and class specified
8451168b 828 * to the previous @ref GetFirstInputObject call.<br>
829 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
a655eae3 830 * @param bForce force the retrieval of an object, error messages
831 * are suppressed if \em bForce is not set
832 * @return pointer to @ref TObject, NULL if no more objects available
833 */
834 const TObject* GetNextInputObject(int bForce=0);
835
836 /**
837 * Get data type of an input block.
838 * Get data type of the object previously fetched via
839 * GetFirstInputObject/NextInputObject or the last one if no object
840 * specified.
841 * @param pObject pointer to TObject
842 * @return data specification, kAliHLTVoidDataSpec if failed
843 */
844 AliHLTComponentDataType GetDataType(const TObject* pObject=NULL);
845
846 /**
847 * Get data specification of an input block.
848 * Get data specification of the object previously fetched via
849 * GetFirstInputObject/NextInputObject or the last one if no object
850 * specified.
851 * @param pObject pointer to TObject
852 * @return data specification, kAliHLTVoidDataSpec if failed
853 */
854 AliHLTUInt32_t GetSpecification(const TObject* pObject=NULL);
855
856 /**
857 * Get the first block of a specific data type from the input data.
3dd8541e 858 * The method looks for the first block of type dt in the input stream.
859 * It is intended to be used within the high-level interface.<br>
8451168b 860 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
3dd8541e 861 *
862 * If called without parameters, the function works on all input blocks,
863 * also the ones of data type kAliHLTVoidDataType which are not matched by
864 * kAliHLTAnyDataType.
865 *
a655eae3 866 * @param dt data type of the block
867 * @return pointer to @ref AliHLTComponentBlockData
868 */
3dd8541e 869 const AliHLTComponentBlockData* GetFirstInputBlock(const AliHLTComponentDataType& dt=kAliHLTAllDataTypes);
a655eae3 870
871 /**
872 * Get the first block of a specific data type from the input data.
873 * The method looks for the first block of type specified by the ID and
874 * Origin strings in the input stream. It is intended
8451168b 875 * to be used within the high-level interface.<br>
876 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 877 * @param dtID data type ID of the block
878 * @param dtOrigin data type origin of the block
879 * @return pointer to @ref AliHLTComponentBlockData
880 */
881 const AliHLTComponentBlockData* GetFirstInputBlock(const char* dtID,
882 const char* dtOrigin);
883
884 /**
8451168b 885 * Get input block by index.<br>
886 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 887 * @return pointer to AliHLTComponentBlockData, NULL if index out of range
888 */
889 const AliHLTComponentBlockData* GetInputBlock(int index);
890
891 /**
892 * Get the next block of a specific data type from the input data.
893 * The method looks for the next block of type and class specified
894 * to the previous @ref GetFirstInputBlock call.
8451168b 895 * To be used within the high-level interface.<br>
896 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 897 */
898 const AliHLTComponentBlockData* GetNextInputBlock();
899
900 /**
901 * Get data specification of an input block.
902 * Get data specification of the input bblock previously fetched via
903 * GetFirstInputObject/NextInputObject or the last one if no block
904 * specified.
905 * @param pBlock pointer to input block
906 * @return data specification, kAliHLTVoidDataSpec if failed
907 */
908 AliHLTUInt32_t GetSpecification(const AliHLTComponentBlockData* pBlock=NULL);
909
c7e9e2f2 910 /**
911 * Forward an input object to the output.
912 * Forward the input block of an object previously fetched via
913 * GetFirstInputObject/NextInputObject or the last one if no object
914 * specified.
915 * The block descriptor of the input block is forwarded to the
916 * output block list.
917 * @param pObject pointer to TObject
918 * @return neg. error code if failed
919 */
920 int Forward(const TObject* pObject);
921
922 /**
923 * Forward an input block to the output.
924 * Forward the input block fetched via GetFirstInputObject/
925 * NextInputBlock or the last one if no block specified.
926 * The block descriptor of the input block is forwarded to the
927 * output block list.
928 * @param pBlock pointer to input block
929 * @return neg. error code if failed
930 */
931 int Forward(const AliHLTComponentBlockData* pBlock=NULL);
932
a655eae3 933 /**
934 * Insert an object into the output.
79c114b5 935 * If header is specified, it will be inserted before the root object,
936 * default is no header.
a655eae3 937 * @param pObject pointer to root object
938 * @param dt data type of the object
939 * @param spec data specification
79c114b5 940 * @param pHeader pointer to header
941 * @param headerSize size of Header
a655eae3 942 * @return neg. error code if failed
943 */
944 int PushBack(TObject* pObject, const AliHLTComponentDataType& dt,
79c114b5 945 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
946 void* pHeader=NULL, int headerSize=0);
a655eae3 947
948 /**
949 * Insert an object into the output.
79c114b5 950 * If header is specified, it will be inserted before the root object,
951 * default is no header.
a655eae3 952 * @param pObject pointer to root object
953 * @param dtID data type ID of the object
954 * @param dtOrigin data type origin of the object
955 * @param spec data specification
79c114b5 956 * @param pHeader pointer to header
957 * @param headerSize size of Header
a655eae3 958 * @return neg. error code if failed
959 */
960 int PushBack(TObject* pObject, const char* dtID, const char* dtOrigin,
79c114b5 961 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
962 void* pHeader=NULL, int headerSize=0);
963
a655eae3 964 /**
965 * Insert an object into the output.
966 * @param pBuffer pointer to buffer
967 * @param iSize size of the buffer
968 * @param dt data type of the object
969 * @param spec data specification
9d9ffd37 970 * @param pHeader pointer to header
7c4091c1 971 * @param headerSize size of Header
a655eae3 972 * @return neg. error code if failed
973 */
974 int PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt,
9d9ffd37 975 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
976 void* pHeader=NULL, int headerSize=0);
a655eae3 977
978 /**
979 * Insert an object into the output.
980 * @param pBuffer pointer to buffer
981 * @param iSize size of the buffer
982 * @param dtID data type ID of the object
983 * @param dtOrigin data type origin of the object
984 * @param spec data specification
9d9ffd37 985 * @param pHeader pointer to header
7c4091c1 986 * @param headerSize size of Header
a655eae3 987 * @return neg. error code if failed
988 */
989 int PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin,
9d9ffd37 990 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
991 void* pHeader=NULL, int headerSize=0);
a655eae3 992
8451168b 993 /**
994 * Estimate size of a TObject
995 * @param pObject
996 * @return buffer size in byte
997 */
998 int EstimateObjectSize(TObject* pObject) const;
999
79c114b5 1000 /**
1001 * Create a memory file in the output stream.
1002 * This method creates a TFile object which stores all data in
1003 * memory instead of disk. The TFile object is published as binary data.
1004 * The instance can be used like a normal TFile object. The TFile::Close
1005 * or @ref CloseMemoryFile method has to be called in order to flush the
1006 * output stream.
1007 *
1008 * \b Note: The returned object is deleted by the framework.
1009 * @param capacity total size reserved for the memory file
1010 * @param dtID data type ID of the file
1011 * @param dtOrigin data type origin of the file
1012 * @param spec data specification
1013 * @return file handle, NULL if failed
1014 */
1015 AliHLTMemoryFile* CreateMemoryFile(int capacity, const char* dtID, const char* dtOrigin,
1016 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
1017
1018 /**
1019 * Create a memory file in the output stream.
1020 * This method creates a TFile object which stores all data in
1021 * memory instead of disk. The TFile object is published as binary data.
1022 * The instance can be used like a normal TFile object. The TFile::Close
1023 * or @ref CloseMemoryFile method has to be called in order to flush the
1024 * output stream.
1025 *
1026 * \b Note: The returned object is deleted by the framework.
1027 * @param capacity total size reserved for the memory file
1028 * @param dt data type of the file
1029 * @param spec data specification
1030 * @return file handle, NULL if failed
1031 */
1032 AliHLTMemoryFile* CreateMemoryFile(int capacity,
1033 const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
1034 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
1035
1036 /**
1037 * Create a memory file in the output stream.
1038 * This method creates a TFile object which stores all data in
1039 * memory instead of disk. The TFile object is published as binary data.
1040 * The instance can be used like a normal TFile object. The TFile::Close
1041 * or @ref CloseMemoryFile method has to be called in order to flush the
1042 * output stream.
1043 *
1044 * \b Note: The returned object is deleted by the framework.
1045 * @param dtID data type ID of the file
1046 * @param dtOrigin data type origin of the file
1047 * @param spec data specification
1048 * @param capacity fraction of the available output buffer size
1049 * @return file handle, NULL if failed
1050 */
1051 AliHLTMemoryFile* CreateMemoryFile(const char* dtID, const char* dtOrigin,
1052 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1053 float capacity=1.0);
1054
1055 /**
1056 * Create a memory file in the output stream.
1057 * This method creates a TFile object which stores all data in
1058 * memory instead of disk. The TFile object is published as binary data.
1059 * The instance can be used like a normal TFile object. The TFile::Close
1060 * or @ref CloseMemoryFile method has to be called in order to flush the
1061 * output stream.
1062 *
1063 * \b Note: The returned object is deleted by the framework.
1064 * @param dt data type of the file
1065 * @param spec data specification
1066 * @param capacity fraction of the available output buffer size
1067 * @return file handle, NULL if failed
1068 */
1069 AliHLTMemoryFile* CreateMemoryFile(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
1070 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1071 float capacity=1.0);
1072
1073 /**
1074 * Write an object to memory file in the output stream.
1075 * @param pFile file handle
1076 * @param pObject pointer to root object
1077 * @param key key in ROOT file
1078 * @param option options, see TObject::Write
1079 * @return neg. error code if failed
1080 * - -ENOSPC no space left
1081 */
1082 int Write(AliHLTMemoryFile* pFile, const TObject* pObject, const char* key=NULL, int option=TObject::kOverwrite);
1083
1084 /**
1085 * Close object memory file.
1086 * @param pFile file handle
1087 * @return neg. error code if failed
1088 * - -ENOSPC buffer size too small
1089 */
1090 int CloseMemoryFile(AliHLTMemoryFile* pFile);
1091
a655eae3 1092 /**
1093 * Insert event-done data information into the output.
1094 * @param edd event-done data information
1095 */
1096 int CreateEventDoneData(AliHLTComponentEventDoneData edd);
1097
559631d5 1098 /**
1099 * Get current run number
1100 */
1101 AliHLTUInt32_t GetRunNo() const;
1102
1103 /**
1104 * Get the current run type.
1105 */
1106 AliHLTUInt32_t GetRunType() const;
1107
ed504011 1108 /**
1109 * Set a bit to 1 in a readout list ( = AliHLTEventDDL )
1110 * -> enable DDL for readout
1111 * @param list readout list
1112 * @param ddlId DDL Id to be turned on ( Decimal )
1113 */
1114 void EnableDDLBit(AliHLTEventDDL &list, Int_t ddlId ) const {
1115 SetDDLBit( list, ddlId, kTRUE );
1116 }
1117
1118 /**
1119 * Set a bit to 0 in a readout list ( = AliHLTEventDDL )
1120 * -> disable DDL for readout
1121 * @param list readout list
1122 * @param ddlId DDL Id to be turned on ( Decimal )
1123 */
1124 void DisableDDLBit(AliHLTEventDDL &list, Int_t ddlId ) const {
1125 SetDDLBit( list, ddlId, kFALSE );
1126 }
1127
1128 /**
1129 * Set or unset bit a readout list ( = AliHLTEventDDL )
1130 * -> enable or disable DDL for readout
1131 * @param list readout list
1132 * @param ddlId DDL Id to be turned on ( Decimal )
1133 * @param state kTRUE sets it, kFALSE unsets it
1134 */
1135 void SetDDLBit(AliHLTEventDDL &list, Int_t ddlId, Bool_t state ) const;
1136
1137 /**
1138 * Get the first word of a detector, which has a set DDL bit.
1139 * Beware, this only works if DDLs of 1 detector are set. In the
1140 * case of the TPC and TOF, which use 8 and 3 words, the first
1141 * word is returned.
1142 * @param list readout list
1143 * @return returns the detector index, -1 if no bit is set
1144 * at all or several detectors (=error)
1145 */
1146 Int_t GetFirstUsedDDLWord(AliHLTEventDDL &list) const;
1147
559631d5 1148 /**
1149 * Copy a struct from block data.
1150 * The function checks for block size and struct size. The least common
1151 * size will be copied to the target struct, remaining fields are initialized
1152 * to zero.<br>
1153 * The target struct must have a 32bit struct size indicator as first member.
1154 * @param pStruct target struct
1155 * @param iStructSize size of the struct
559631d5 1156 * @param iBlockNo index of input block
1157 * @param structname name of the struct (log messages)
1158 * @param eventname name of the event (log messages)
1159 * @return size copied, neg. error if failed
1160 */
83fec083 1161 int CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
559631d5 1162 const char* structname="", const char* eventname="");
1163
f23a6e1a 1164 private:
b426991e 1165 /** copy constructor prohibited */
559631d5 1166 AliHLTComponent(const AliHLTComponent&);
b426991e 1167 /** assignment operator prohibited */
559631d5 1168 AliHLTComponent& operator=(const AliHLTComponent&);
1169
3cde846d 1170 /**
1171 * Increment the internal event counter.
1172 * To be used by the friend classes AliHLTProcessor, AliHLTDataSource
1173 * and AliHLTDataSink.
1174 * @return new value of the internal event counter
a655eae3 1175 * @internal
3cde846d 1176 */
1177 int IncrementEventCounter();
1178
a655eae3 1179 /**
1180 * Find the first input block of specified data type beginning at index.
1edbbe49 1181 * Input blocks containing a TObject have the size of the object as an
1182 * unsigned 32 bit number in the first 4 bytes. This has to match the block
1183 * size minus 4.
3dd8541e 1184 *
1185 * kAliHLTAllDataTypes is a special data type which includes both
1186 * kAliHLTVoidDataType and kAliHLTAnyDataType.
1187 *
a655eae3 1188 * @param dt data type
1189 * @param startIdx index to start the search
1edbbe49 1190 * @param bObject check if this is an object
a655eae3 1191 * @return index of the block, -ENOENT if no block found
1192 *
1193 * @internal
1194 */
1edbbe49 1195 int FindInputBlock(const AliHLTComponentDataType& dt, int startIdx=-1, int bObject=0) const;
a655eae3 1196
1197 /**
1198 * Get index in the array of input bocks.
1199 * Calculate index and check integrety of a block data structure pointer.
1200 * @param pBlock pointer to block data
1201 * @return index of the block, -ENOENT if no block found
1202 *
1203 * @internal
1204 */
66043029 1205 int FindInputBlock(const AliHLTComponentBlockData* pBlock) const;
a655eae3 1206
1207 /**
1208 * Create an object from a specified input block.
1209 * @param idx index of the input block
1210 * @param bForce force the retrieval of an object, error messages
1211 * are suppressed if \em bForce is not set
1212 * @return pointer to TObject, caller must delete the object after use
1213 *
1214 * @internal
1215 */
1216 TObject* CreateInputObject(int idx, int bForce=0);
1217
1218 /**
1219 * Get input object
8451168b 1220 * Get object from the input block list. The methods first checks whether the
1221 * object was already created. If not, it is created by @ref CreateInputObject
1222 * and inserted into the list of objects.
a655eae3 1223 * @param idx index in the input block list
1224 * @param classname name of the class, object is checked for correct class
1225 * name if set
1226 * @param bForce force the retrieval of an object, error messages
1227 * are suppressed if \em bForce is not set
1228 * @return pointer to TObject
1229 *
1230 * @internal
1231 */
1232 TObject* GetInputObject(int idx, const char* classname=NULL, int bForce=0);
1233
8451168b 1234 /**
1235 * Clean the list of input objects.
1236 * Cleanup is done at the end of each event processing.
1237 */
1238 int CleanupInputObjects();
1239
a655eae3 1240 /**
1241 * Insert a buffer into the output block stream.
1242 * This is the only method to insert blocks into the output stream, called
1243 * from all types of the Pushback method. The actual data might have been
1244 * written to the output buffer already. In that case NULL can be provided
79c114b5 1245 * as buffer, only the block descriptor will be build. If a header is specified,
1246 * it will be inserted before the buffer, default is no header.
a655eae3 1247 * @param pBuffer pointer to buffer
32db4144 1248 * @param iBufferSize size of the buffer in byte
a655eae3 1249 * @param dt data type
1250 * @param spec data specification
79c114b5 1251 * @param pHeader pointer to header
1252 * @param iHeaderSize size of Header
b6800be0 1253 * @return neg. error code if failed
a655eae3 1254 */
79c114b5 1255 int InsertOutputBlock(void* pBuffer, int iBufferSize,
a655eae3 1256 const AliHLTComponentDataType& dt,
79c114b5 1257 AliHLTUInt32_t spec,
1258 void* pHeader=NULL, int iHeaderSize=0);
a655eae3 1259
bfccbf68 1260 /** The global component handler instance */
a655eae3 1261 static AliHLTComponentHandler* fgpComponentHandler; //! transient
70ed7d01 1262
bfccbf68 1263 /** The environment where the component is running in */
a655eae3 1264 AliHLTComponentEnvironment fEnvironment; // see above
f23a6e1a 1265
a655eae3 1266 /** Set by ProcessEvent before the processing starts */
1267 AliHLTEventID_t fCurrentEvent; // see above
f23a6e1a 1268
3cde846d 1269 /** internal event no */
a655eae3 1270 int fEventCount; // see above
1271
1272 /** the number of failed events */
1273 int fFailedEvents; // see above
1274
1275 /** event data struct of the current event under processing */
1276 AliHLTComponentEventData fCurrentEventData; // see above
1277
1278 /** array of input data blocks of the current event */
1279 const AliHLTComponentBlockData* fpInputBlocks; //! transient
1280
1281 /** index of the current input block */
1282 int fCurrentInputBlock; // see above
1283
1284 /** data type of the last block search */
1285 AliHLTComponentDataType fSearchDataType; // see above
1286
1287 /** name of the class for the object to search for */
1288 string fClassName; // see above
1289
1290 /** array of generated input objects */
1291 TObjArray* fpInputObjects; //! transient
1292
1293 /** the output buffer */
1294 AliHLTUInt8_t* fpOutputBuffer; //! transient
1295
1296 /** size of the output buffer */
1297 AliHLTUInt32_t fOutputBufferSize; // see above
1298
1299 /** size of data written to output buffer */
1300 AliHLTUInt32_t fOutputBufferFilled; // see above
1301
1302 /** list of ouput block data descriptors */
2be3f004 1303 AliHLTComponentBlockDataList fOutputBlocks; // see above
3cde846d 1304
90ebac25 1305 /** stopwatch array */
1306 TObjArray* fpStopwatches; //! transient
1307
79c114b5 1308 /** array of memory files AliHLTMemoryFile */
2be3f004 1309 AliHLTMemoryFilePList fMemFiles; //! transient
79c114b5 1310
559631d5 1311 /** descriptor of the current run */
1312 AliHLTRunDesc* fpRunDesc; //! transient
1313
1314 /** the current DDL list */
1315 AliHLTEventDDL* fpDDLList; //! transient
1316
82c58a87 1317 /** external fct to set CDB run no, indicates external CDB initialization */
1318 void* fCDBSetRunNoFunc; //! transient
579d9eb7 1319
1320 /** id of the component in the analysis chain */
1321 string fChainId; //! transient
1322
3dd8541e 1323 ClassDef(AliHLTComponent, 6)
f23a6e1a 1324};
1325#endif