4 #ifndef ALIHLTCOMPONENT_H
5 #define ALIHLTCOMPONENT_H
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 */
10 /** @file AliHLTComponent.h
11 @author Matthias Richter, Timm Steinbeck
13 @brief Base class declaration for HLT components.
14 @note The class is both used in Online (PubSub) and Offline (AliRoot)
17 // see below for class documentation
19 // refer to README to build package
21 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
24 * @defgroup alihlt_component Component handling of the HLT module
25 * This section describes the the component handling for the HLT module.
30 #include "AliHLTLogging.h"
31 #include "AliHLTDataTypes.h"
32 //#include "AliHLTDefinitions.h"
35 * The names have been changed for Aliroot's coding conventions sake
36 * The old names are defined for backward compatibility with the
37 * stand alone SampleLib package
39 typedef AliHLTComponentLogSeverity AliHLTComponent_LogSeverity;
40 typedef AliHLTComponentEventData AliHLTComponent_EventData;
41 typedef AliHLTComponentShmData AliHLTComponent_ShmData;
42 typedef AliHLTComponentDataType AliHLTComponent_DataType;
43 typedef AliHLTComponentBlockData AliHLTComponent_BlockData;
44 typedef AliHLTComponentTriggerData AliHLTComponent_TriggerData;
45 typedef AliHLTComponentEventDoneData AliHLTComponent_EventDoneData;
47 class AliHLTComponentHandler;
50 class AliHLTMemoryFile;
53 * @class AliHLTComponent
54 * Base class of HLT data processing components.
55 * The class provides a common interface for HLT data processing components.
56 * The interface can be accessed from the online HLT framework or the AliRoot
57 * offline analysis framework.
58 * @section alihltcomponent-properties Component identification and properties
59 * Each component must provide a unique ID, input and output data type indications,
60 * and a spawn function.
61 * @subsection alihltcomponent-req-methods Required property methods
62 * - @ref GetComponentID
63 * - @ref GetInputDataTypes (see @ref alihltcomponent-type for default
65 * - @ref GetOutputDataType (see @ref alihltcomponent-type for default
67 * - @ref GetOutputDataSize (see @ref alihltcomponent-type for default
71 * @subsection alihltcomponent-opt-mehods Optional handlers
74 * - @ref GetOutputDataTypes
75 * If the component has multiple output data types @ref GetOutputDataType
76 * should return @ref kAliHLTMultipleDataType. The framework will invoke
77 * @ref GetOutputDataTypes, a list can be filled.
79 * @subsection alihltcomponent-processing-mehods Data processing
82 * @subsection alihltcomponent-type Component type
83 * Components can be of type
84 * - @ref kSource components which only produce data
85 * - @ref kProcessor components which consume and produce data
86 * - @ref kSink components which only consume data
88 * where data production and consumption refer to the analysis data stream. In
89 * order to indicate the type, a child component can overload the
90 * @ref GetComponentType function.
91 * @subsubsection alihltcomponent-type-std Standard implementations
92 * Components in general do not need to implement this function, standard
93 * implementations of the 3 types are available:
94 * - AliHLTDataSource for components of type @ref kSource <br>
95 * All types of data sources can inherit from AliHLTDataSource and must
96 * implement the @ref AliHLTDataSource::GetEvent method. The class
97 * also implements a standard method for @ref GetInputDataTypes.
99 * - AliHLTProcessor for components of type @ref kProcessor <br>
100 * All types of data processors can inherit from AliHLTDataSource and must
101 * implement the @ref AliHLTProcessor::DoEvent method.
103 * - AliHLTDataSink for components of type @ref kSink <br>
104 * All types of data processors can inherit from AliHLTDataSource and must
105 * implement the @ref AliHLTDataSink::DumpEvent method. The class
106 * also implements a standard method for @ref GetOutputDataType and @ref
109 * @subsection alihltcomponent-environment Running environment
111 * In order to adapt to different environments (on-line/off-line), the component
112 * gets an environment structure with function pointers. The base class provides
113 * member functions for those environment dependend functions. The member
114 * functions are used by the component implementation and are re-mapped to the
115 * corresponding functions.
117 * @section alihltcomponent-interfaces Component interfaces
118 * Each of the 3 standard component base classes AliHLTProcessor, AliHLTDataSource
119 * and AliHLTDataSink provides it's own processing method (see
120 * @ref alihltcomponent-type-std), which splits into a high and a low-level
121 * method. For the @ref alihltcomponent-low-level-interface, all parameters are
122 * shipped as function arguments, the component is supposed to dump data to the
123 * output buffer and handle all block descriptors.
124 * The @ref alihltcomponent-high-level-interface is the standard processing
125 * method and will be used whenever the low-level method is not overloaded.
127 * In both cases it is necessary to calculate/estimate the size of the output
128 * buffer before the processing. Output buffers can never be allocated inside
129 * the component because of the push-architecture of the HLT.
130 * For that reason the @ref GetOutputDataSize function should return a rough
131 * estimatian of the data to be produced by the component. The component is
132 * responsible for checking the memory size and must return -ENOSPC if the
133 * available buffer is to small, and update the estimator respectively. The
134 * framework will allocate a buffer of appropriate size and call the processing
137 * @subsection alihltcomponent-high-level-interface High-level interface
138 * The high-level component interface provides functionality to exchange ROOT
139 * structures between components. In contrast to the
140 * @ref alihltcomponent-low-level-interface, a couple of functions can be used
141 * to access data blocks of the input stream
142 * and send data blocks or ROOT TObject's to the output stream. The functionality
143 * is hidden from the user and is implemented by using ROOT's TMessage class.
145 * @subsubsection alihltcomponent-high-level-int-methods Interface methods
146 * The interface provides a couple of methods in order to get objects from the
147 * input, data blocks (non TObject) from the input, and to push back objects and
148 * data blocks to the output. For convenience there are several functions of
149 * identical name (and similar behavior) with different parameters defined.
150 * Please refer to the function documentation.
151 * - @ref GetNumberOfInputBlocks <br>
152 * return the number of data blocks in the input stream
153 * - @ref GetFirstInputObject <br>
154 * get the first object of a specific data type
155 * - @ref GetNextInputObject <br>
156 * get the next object of same data type as last GetFirstInputObject/Block call
157 * - @ref GetFirstInputBlock <br>
158 * get the first block of a specific data type
159 * - @ref GetNextInputBlock <br>
160 * get the next block of same data type as last GetFirstInputBlock/Block call
161 * - @ref PushBack <br>
162 * insert an object or data buffer into the output
163 * - @ref CreateEventDoneData <br>
164 * add event information to the output
166 * In addition, the processing methods are simplified a bit by cutting out most of
169 * - @ref AliHLTProcessor::DoEvent
170 * - @ref AliHLTDataSource::GetEvent
171 * - @ref AliHLTDataSink::DumpEvent
173 * \em IMPORTANT: objects and block descriptors provided by the high-level interface
174 * <b>MUST NOT BE DELETED</b> by the caller.
176 * @subsubsection alihltcomponent-high-level-int-guidelines High-level interface guidelines
177 * - Structures must inherit from the ROOT object base class TObject in order be
178 * transported by the transportation framework.
179 * - all pointer members must be transient (marked <tt>//!</tt> behind the member
180 * definition), i.e. will not be stored/transported, or properly marked
181 * (<tt>//-></tt>) in order to call the streamer of the object the member is pointing
182 * to. The latter is not recomended. Structures to be transported between components
183 * should be streamlined.
184 * - no use of stl vectors/strings, use appropriate ROOT classes instead
186 * @subsection alihltcomponent-low-level-interface Low-level interface
187 * The low-level component interface consists of the specific data processing
188 * methods for @ref AliHLTProcessor, @ref AliHLTDataSource, and @ref AliHLTDataSink.
189 * - @ref AliHLTProcessor::DoEvent
190 * - @ref AliHLTDataSource::GetEvent
191 * - @ref AliHLTDataSink::DumpEvent
194 * @section alihltcomponent-handling Component handling
195 * The handling of HLT analysis components is carried out by the AliHLTComponentHandler.
196 * Component are registered automatically at load-time of the component shared library
197 * under the following suppositions:
198 * - the component library has to be loaded from the AliHLTComponentHandler using the
199 * @ref AliHLTComponentHandler::LoadLibrary method.
200 * - the component implementation defines one global object (which is generated
201 * when the library is loaded)
203 * @subsection alihltcomponent-design-rules General design considerations
204 * The analysis code should be implemented in one or more destict class(es). A
205 * \em component should be implemented which interface the destict analysis code to the
206 * component interface. This component generates the analysis object dynamically. <br>
208 * Assume you have an implemetation <tt> AliHLTDetMyAnalysis </tt>, another class <tt>
209 * AliHLTDetMyAnalysisComponent </tt> contains:
212 * AliHLTDetMyAnalysis* fMyAnalysis; //!
214 * The object should then be instantiated in the DoInit handler of
215 * <tt>AliHLTDetMyAnalysisComponent </tt>, and cleaned in the DoDeinit handler.
218 * - avoid big static arrays in the component, allocate the memory at runtime
220 * @ingroup alihlt_component
221 * @section alihltcomponent-members Class members
223 class AliHLTComponent : public AliHLTLogging {
225 /** standard constructor */
227 /** standard destructor */
228 virtual ~AliHLTComponent();
230 /** component type definitions */
231 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
234 * Init function to prepare data processing.
235 * Initialization of common data structures for a sequence of events.
236 * The call is redirected to the internal method @ref DoInit which can be
237 * overridden by the child class.<br>
238 * During Init also the environment structure is passed to the component.
239 * @param environ environment pointer with environment dependend function
241 * @param environParam additionel parameter for function calls, the pointer
243 * @param argc size of the argument array
244 * @param argv agument array for component initialization
246 virtual int Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv );
249 * Clean-up function to terminate data processing.
250 * Clean-up of common data structures after data processing.
251 * The call is redirected to the internal method @ref DoDeinit which can be
252 * overridden by the child class.
254 virtual int Deinit();
257 * Processing of one event.
258 * The method is the entrance of the event processing. The parameters are
259 * cached for uses with the high-level interface and the DoProcessing
260 * implementation is called.
267 * @param outputBlockCnt out: size of the output block array, set by the component
268 * @param outputBlocks out: the output block array is allocated internally
270 * @return neg. error code if failed
272 int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
273 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
274 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
275 AliHLTComponentBlockData*& outputBlocks,
276 AliHLTComponentEventDoneData*& edd );
279 * Internal processing of one event.
280 * The method is pure virtual and implemented by the child classes
281 * - @ref AliHLTProcessor
282 * - @ref AliHLTDataSource
283 * - @ref AliHLTDataSink
290 * @param outputBlocks out: the output block array is allocated internally
292 * @return neg. error code if failed
294 virtual int DoProcessing( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
295 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
296 AliHLTUInt32_t& size,
297 vector<AliHLTComponentBlockData>& outputBlocks,
298 AliHLTComponentEventDoneData*& edd ) = 0;
300 // Information member functions for registration.
303 * Get the type of the component.
304 * The function is pure virtual and must be implemented by the child class.
305 * @return component type id
307 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
310 * Get the id of the component.
311 * Each component is identified by a unique id.
312 * The function is pure virtual and must be implemented by the child class.
313 * @return component id (string)
315 virtual const char* GetComponentID() = 0;
318 * Get the input data types of the component.
319 * The function is pure virtual and must be implemented by the child class.
320 * @return list of data types in the vector reference
322 virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& ) = 0;
325 * Get the output data type of the component.
326 * The function is pure virtual and must be implemented by the child class.
327 * @return output data type
329 virtual AliHLTComponentDataType GetOutputDataType() = 0;
332 * Get the output data types of the component.
333 * The function can be implemented to indicate multiple output data types
334 * in the target array.
335 * @ref GetOutputDataType must return @ref kAliHLTMultipleDataType in order
336 * to invoke this method.
337 * @param tgtList list to receive the data types
338 * @return no of output data types, data types in the target list
340 virtual int GetOutputDataTypes(vector<AliHLTComponentDataType>& tgtList);
343 * Get a ratio by how much the data volume is shrinked or enhanced.
344 * The function is pure virtual and must be implemented by the child class.
345 * @param constBase <i>return</i>: additive part, independent of the
347 * @param inputMultiplier <i>return</i>: multiplication ratio
348 * @return values in the reference variables
350 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
354 * Each component must implement a spawn function to create a new instance of
355 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
356 * @return new class instance
358 virtual AliHLTComponent* Spawn() = 0;
361 * Find matching data types between this component and a consumer component.
362 * Currently, a component can produce only one type of data. This restriction is most
363 * likely to be abolished in the future.
364 * @param pConsumer a component and consumer of the data produced by this component
365 * @param tgtList reference to a vector list to receive the matching data types.
366 * @return >= 0 success, neg. error code if failed
368 int FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList);
371 * Set the global component handler.
372 * The static method is needed for the automatic registration of components.
374 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
377 * Clear the global component handler.
378 * The static method is needed for the automatic registration of components.
380 static int UnsetGlobalComponentHandler();
383 * Helper function to convert the data type to a string.
385 static string DataType2Text( const AliHLTComponentDataType& type );
388 * Helper function to print content of data type.
390 void PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format=NULL) const;
393 * helper function to initialize AliHLTComponentEventData structure
395 static void FillEventData(AliHLTComponentEventData& evtData);
398 * Print info on an AliHLTComponentDataType structure
399 * This is just a helper function to examine an @ref AliHLTComponentDataType
402 void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
405 * Stopwatch type for benchmarking.
407 enum AliHLTStopwatchType {
408 /** total time for event processing */
410 /** detector algorithm w/o interface callbacks */
416 /** number of types */
421 * Helper class for starting and stopping a stopwatch.
422 * The guard can be used by instantiating an object in a function. The
423 * specified stopwatch is started and the previous stopwatch put on
424 * hold. When the function is terminated, the object is deleted automatically
425 * deleted, stopping the stopwatch and starting the one on hold.<br>
426 * \em IMPORTANT: never create dynamic objects from this guard as this violates
427 * the idea of a guard.
429 class AliHLTStopwatchGuard {
431 /** standard constructor (not for use) */
432 AliHLTStopwatchGuard();
434 AliHLTStopwatchGuard(TStopwatch* pStart);
435 /** copy constructor (not for use) */
436 AliHLTStopwatchGuard(const AliHLTStopwatchGuard&);
437 /** assignment operator (not for use) */
438 AliHLTStopwatchGuard& operator=(const AliHLTStopwatchGuard&);
440 ~AliHLTStopwatchGuard();
444 * Hold the previous guard for the existence of this guard.
445 * Checks whether this guard controls a new stopwatch. In that case, the
446 * previous guard and its stopwatch are put on hold.
447 * @param pSucc instance of the stopwatch of the new guard
448 * @return 1 if pSucc is a different stopwatch which should
450 * 0 if it controls the same stopwatch
452 int Hold(TStopwatch* pSucc);
455 * Resume the previous guard.
456 * Checks whether the peceeding guard controls a different stopwatch. In that
457 * case, the its stopwatch is resumed.
458 * @param pSucc instance of the stopwatch of the new guard
459 * @return 1 if pSucc is a different stopwatch which should
461 * 0 if it controls the same stopwatch
463 int Resume(TStopwatch* pSucc);
465 /** the stopwatch controlled by this guard */
466 TStopwatch* fpStopwatch; //!transient
468 /** previous stopwatch guard, put on hold during existence of the guard */
469 AliHLTStopwatchGuard* fpPrec; //!transient
471 /** active stopwatch guard */
472 static AliHLTStopwatchGuard* fgpCurrent; //!transient
476 * Set a stopwatch for a given purpose.
477 * @param pSW stopwatch object
478 * @param type type of the stopwatch
480 int SetStopwatch(TObject* pSW, AliHLTStopwatchType type=kSWBase);
483 * Init a set of stopwatches.
484 * @param pStopwatches object array of stopwatches
486 int SetStopwatches(TObjArray* pStopwatches);
491 * Fill AliHLTComponentBlockData structure with default values.
492 * @param blockData reference to data structure
494 void FillBlockData( AliHLTComponentBlockData& blockData ) const;
497 * Fill AliHLTComponentShmData structure with default values.
498 * @param shmData reference to data structure
500 void FillShmData( AliHLTComponentShmData& shmData ) const;
503 * Fill AliHLTComponentDataType structure with default values.
504 * @param dataType reference to data structure
506 void FillDataType( AliHLTComponentDataType& dataType ) const;
509 * Copy data type structure
510 * Copies the value an AliHLTComponentDataType structure to another one
511 * @param[out] tgtdt target structure
512 * @param[in] srcdt source structure
514 void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
517 * Set the ID and Origin of an AliHLTComponentDataType structure.
518 * The function sets the fStructureSize member and copies the strings
519 * to the ID and Origin. Only characters from the valid part of the string
520 * are copied, the rest is fille with 0's.
521 * Please note that the fID and fOrigin members are not strings, just arrays of
522 * chars of size @ref kAliHLTComponentDataTypefIDsize and
523 * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
524 * a terminating zero.
525 * @param tgtdt target data type structure
526 * @param id ID string
527 * @param origin Origin string
529 void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
532 * Default method for the internal initialization.
533 * The method is called by @ref Init
535 virtual int DoInit( int argc, const char** argv );
538 * Default method for the internal clean-up.
539 * The method is called by @ref Deinit
541 virtual int DoDeinit();
544 * General memory allocation method.
545 * All memory which is going to be used 'outside' of the interface must
546 * be provided by the framework (online or offline).
547 * The method is redirected to a function provided by the current
548 * framework. Function pointers are transferred via the @ref
549 * AliHLTComponentEnvironment structure.
551 void* AllocMemory( unsigned long size );
554 * Helper function to create a monolithic BlockData description block out
555 * of a list BlockData descriptors.
556 * For convenience, inside the interface vector lists are used, to make the
557 * interface pure C style, monilithic blocks must be exchanged.
558 * The method is redirected to a function provided by the current
559 * framework. Function pointers are transferred via the @ref
560 * AliHLTComponentEnvironment structure.
562 int MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
563 AliHLTComponentBlockData** outputBlocks );
566 * Fill the EventDoneData structure.
567 * The method is redirected to a function provided by the current
568 * framework. Function pointers are transferred via the @ref
569 * AliHLTComponentEnvironment structure.
571 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd );
574 * Helper function to convert the data type to a string.
576 void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]) const;
580 * @return value of the internal event counter
582 int GetEventCount() const;
585 * Get the number of input blocks.
586 * @return number of input blocks
588 int GetNumberOfInputBlocks() const;
591 * Get the first object of a specific data type from the input data.
592 * The hight-level methods provide functionality to transfer ROOT data
593 * structures which inherit from TObject.
594 * The method looks for the first ROOT object of type dt in the input stream.
595 * If also the class name is provided, the object is checked for the right
596 * class type. The input data block needs a certain structure, namely the
597 * buffer size as first word. If the cross check fails, the retrieval is
598 * silently abondoned, unless the \em bForce parameter is set.<br>
599 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
600 * @param dt data type of the object
601 * @param classname class name of the object
602 * @param bForce force the retrieval of an object, error messages
603 * are suppressed if \em bForce is not set
604 * @return pointer to @ref TObject, NULL if no objects of specified type
607 const TObject* GetFirstInputObject(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
608 const char* classname=NULL,
612 * Get the first object of a specific data type from the input data.
613 * The hight-level methods provide functionality to transfer ROOT data
614 * structures which inherit from TObject.
615 * The method looks for the first ROOT object of type specified by the ID and
616 * Origin strings in the input stream.
617 * If also the class name is provided, the object is checked for the right
618 * class type. The input data block needs a certain structure, namely the
619 * buffer size as first word. If the cross check fails, the retrieval is
620 * silently abondoned, unless the \em bForce parameter is set.<br>
621 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
622 * @param dtID data type ID of the object
623 * @param dtOrigin data type origin of the object
624 * @param classname class name of the object
625 * @param bForce force the retrieval of an object, error messages
626 * are suppressed if \em bForce is not set
627 * @return pointer to @ref TObject, NULL if no objects of specified type
630 const TObject* GetFirstInputObject(const char* dtID,
631 const char* dtOrigin,
632 const char* classname=NULL,
636 * Get the next object of a specific data type from the input data.
637 * The hight-level methods provide functionality to transfer ROOT data
638 * structures which inherit from TObject.
639 * The method looks for the next ROOT object of type and class specified
640 * to the previous @ref GetFirstInputObject call.<br>
641 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
642 * @param bForce force the retrieval of an object, error messages
643 * are suppressed if \em bForce is not set
644 * @return pointer to @ref TObject, NULL if no more objects available
646 const TObject* GetNextInputObject(int bForce=0);
649 * Get data type of an input block.
650 * Get data type of the object previously fetched via
651 * GetFirstInputObject/NextInputObject or the last one if no object
653 * @param pObject pointer to TObject
654 * @return data specification, kAliHLTVoidDataSpec if failed
656 AliHLTComponentDataType GetDataType(const TObject* pObject=NULL);
659 * Get data specification of an input block.
660 * Get data specification of the object previously fetched via
661 * GetFirstInputObject/NextInputObject or the last one if no object
663 * @param pObject pointer to TObject
664 * @return data specification, kAliHLTVoidDataSpec if failed
666 AliHLTUInt32_t GetSpecification(const TObject* pObject=NULL);
669 * Get the first block of a specific data type from the input data.
670 * The method looks for the first block of type dt in the input stream. It is intended
671 * to be used within the high-level interface.<br>
672 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
673 * @param dt data type of the block
674 * @return pointer to @ref AliHLTComponentBlockData
676 const AliHLTComponentBlockData* GetFirstInputBlock(const AliHLTComponentDataType& dt=kAliHLTAnyDataType);
679 * Get the first block of a specific data type from the input data.
680 * The method looks for the first block of type specified by the ID and
681 * Origin strings in the input stream. It is intended
682 * to be used within the high-level interface.<br>
683 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
684 * @param dtID data type ID of the block
685 * @param dtOrigin data type origin of the block
686 * @return pointer to @ref AliHLTComponentBlockData
688 const AliHLTComponentBlockData* GetFirstInputBlock(const char* dtID,
689 const char* dtOrigin);
692 * Get input block by index.<br>
693 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
694 * @return pointer to AliHLTComponentBlockData, NULL if index out of range
696 const AliHLTComponentBlockData* GetInputBlock(int index);
699 * Get the next block of a specific data type from the input data.
700 * The method looks for the next block of type and class specified
701 * to the previous @ref GetFirstInputBlock call.
702 * To be used within the high-level interface.<br>
703 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
705 const AliHLTComponentBlockData* GetNextInputBlock();
708 * Get data specification of an input block.
709 * Get data specification of the input bblock previously fetched via
710 * GetFirstInputObject/NextInputObject or the last one if no block
712 * @param pBlock pointer to input block
713 * @return data specification, kAliHLTVoidDataSpec if failed
715 AliHLTUInt32_t GetSpecification(const AliHLTComponentBlockData* pBlock=NULL);
718 * Insert an object into the output.
719 * If header is specified, it will be inserted before the root object,
720 * default is no header.
721 * @param pObject pointer to root object
722 * @param dt data type of the object
723 * @param spec data specification
724 * @param pHeader pointer to header
725 * @param headerSize size of Header
726 * @return neg. error code if failed
728 int PushBack(TObject* pObject, const AliHLTComponentDataType& dt,
729 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
730 void* pHeader=NULL, int headerSize=0);
733 * Insert an object into the output.
734 * If header is specified, it will be inserted before the root object,
735 * default is no header.
736 * @param pObject pointer to root object
737 * @param dtID data type ID of the object
738 * @param dtOrigin data type origin of the object
739 * @param spec data specification
740 * @param pHeader pointer to header
741 * @param headerSize size of Header
742 * @return neg. error code if failed
744 int PushBack(TObject* pObject, const char* dtID, const char* dtOrigin,
745 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
746 void* pHeader=NULL, int headerSize=0);
749 * Insert an object into the output.
750 * @param pBuffer pointer to buffer
751 * @param iSize size of the buffer
752 * @param dt data type of the object
753 * @param spec data specification
754 * @param pHeader pointer to header
755 * @param headerSize size of Header
756 * @return neg. error code if failed
758 int PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt,
759 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
760 void* pHeader=NULL, int headerSize=0);
763 * Insert an object into the output.
764 * @param pBuffer pointer to buffer
765 * @param iSize size of the buffer
766 * @param dtID data type ID of the object
767 * @param dtOrigin data type origin of the object
768 * @param spec data specification
769 * @param pHeader pointer to header
770 * @param headerSize size of Header
771 * @return neg. error code if failed
773 int PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin,
774 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
775 void* pHeader=NULL, int headerSize=0);
778 * Estimate size of a TObject
780 * @return buffer size in byte
782 int EstimateObjectSize(TObject* pObject) const;
785 * Create a memory file in the output stream.
786 * This method creates a TFile object which stores all data in
787 * memory instead of disk. The TFile object is published as binary data.
788 * The instance can be used like a normal TFile object. The TFile::Close
789 * or @ref CloseMemoryFile method has to be called in order to flush the
792 * \b Note: The returned object is deleted by the framework.
793 * @param capacity total size reserved for the memory file
794 * @param dtID data type ID of the file
795 * @param dtOrigin data type origin of the file
796 * @param spec data specification
797 * @return file handle, NULL if failed
799 AliHLTMemoryFile* CreateMemoryFile(int capacity, const char* dtID, const char* dtOrigin,
800 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
803 * Create a memory file in the output stream.
804 * This method creates a TFile object which stores all data in
805 * memory instead of disk. The TFile object is published as binary data.
806 * The instance can be used like a normal TFile object. The TFile::Close
807 * or @ref CloseMemoryFile method has to be called in order to flush the
810 * \b Note: The returned object is deleted by the framework.
811 * @param capacity total size reserved for the memory file
812 * @param dt data type of the file
813 * @param spec data specification
814 * @return file handle, NULL if failed
816 AliHLTMemoryFile* CreateMemoryFile(int capacity,
817 const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
818 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
821 * Create a memory file in the output stream.
822 * This method creates a TFile object which stores all data in
823 * memory instead of disk. The TFile object is published as binary data.
824 * The instance can be used like a normal TFile object. The TFile::Close
825 * or @ref CloseMemoryFile method has to be called in order to flush the
828 * \b Note: The returned object is deleted by the framework.
829 * @param dtID data type ID of the file
830 * @param dtOrigin data type origin of the file
831 * @param spec data specification
832 * @param capacity fraction of the available output buffer size
833 * @return file handle, NULL if failed
835 AliHLTMemoryFile* CreateMemoryFile(const char* dtID, const char* dtOrigin,
836 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
840 * Create a memory file in the output stream.
841 * This method creates a TFile object which stores all data in
842 * memory instead of disk. The TFile object is published as binary data.
843 * The instance can be used like a normal TFile object. The TFile::Close
844 * or @ref CloseMemoryFile method has to be called in order to flush the
847 * \b Note: The returned object is deleted by the framework.
848 * @param dt data type of the file
849 * @param spec data specification
850 * @param capacity fraction of the available output buffer size
851 * @return file handle, NULL if failed
853 AliHLTMemoryFile* CreateMemoryFile(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
854 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
858 * Write an object to memory file in the output stream.
859 * @param pFile file handle
860 * @param pObject pointer to root object
861 * @param key key in ROOT file
862 * @param option options, see TObject::Write
863 * @return neg. error code if failed
864 * - -ENOSPC no space left
866 int Write(AliHLTMemoryFile* pFile, const TObject* pObject, const char* key=NULL, int option=TObject::kOverwrite);
869 * Close object memory file.
870 * @param pFile file handle
871 * @return neg. error code if failed
872 * - -ENOSPC buffer size too small
874 int CloseMemoryFile(AliHLTMemoryFile* pFile);
877 * Insert event-done data information into the output.
878 * @param edd event-done data information
880 int CreateEventDoneData(AliHLTComponentEventDoneData edd);
883 * Get current run number
885 AliHLTUInt32_t GetRunNo() const;
888 * Get the current run type.
890 AliHLTUInt32_t GetRunType() const;
893 * Copy a struct from block data.
894 * The function checks for block size and struct size. The least common
895 * size will be copied to the target struct, remaining fields are initialized
897 * The target struct must have a 32bit struct size indicator as first member.
898 * @param pStruct target struct
899 * @param iStructSize size of the struct
900 * @param iBlockNo index of input block
901 * @param structname name of the struct (log messages)
902 * @param eventname name of the event (log messages)
903 * @return size copied, neg. error if failed
905 int CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
906 const char* structname="", const char* eventname="");
909 /** not a valid copy constructor, defined according to effective C++ style */
910 AliHLTComponent(const AliHLTComponent&);
911 /** not a valid assignment op, but defined according to effective C++ style */
912 AliHLTComponent& operator=(const AliHLTComponent&);
915 * Increment the internal event counter.
916 * To be used by the friend classes AliHLTProcessor, AliHLTDataSource
917 * and AliHLTDataSink.
918 * @return new value of the internal event counter
921 int IncrementEventCounter();
924 * Find the first input block of specified data type beginning at index.
925 * Input blocks containing a TObject have the size of the object as an
926 * unsigned 32 bit number in the first 4 bytes. This has to match the block
928 * @param dt data type
929 * @param startIdx index to start the search
930 * @param bObject check if this is an object
931 * @return index of the block, -ENOENT if no block found
935 int FindInputBlock(const AliHLTComponentDataType& dt, int startIdx=-1, int bObject=0) const;
938 * Get index in the array of input bocks.
939 * Calculate index and check integrety of a block data structure pointer.
940 * @param pBlock pointer to block data
941 * @return index of the block, -ENOENT if no block found
945 int FindInputBlock(const AliHLTComponentBlockData* pBlock) const;
948 * Create an object from a specified input block.
949 * @param idx index of the input block
950 * @param bForce force the retrieval of an object, error messages
951 * are suppressed if \em bForce is not set
952 * @return pointer to TObject, caller must delete the object after use
956 TObject* CreateInputObject(int idx, int bForce=0);
960 * Get object from the input block list. The methods first checks whether the
961 * object was already created. If not, it is created by @ref CreateInputObject
962 * and inserted into the list of objects.
963 * @param idx index in the input block list
964 * @param classname name of the class, object is checked for correct class
966 * @param bForce force the retrieval of an object, error messages
967 * are suppressed if \em bForce is not set
968 * @return pointer to TObject
972 TObject* GetInputObject(int idx, const char* classname=NULL, int bForce=0);
975 * Clean the list of input objects.
976 * Cleanup is done at the end of each event processing.
978 int CleanupInputObjects();
981 * Insert a buffer into the output block stream.
982 * This is the only method to insert blocks into the output stream, called
983 * from all types of the Pushback method. The actual data might have been
984 * written to the output buffer already. In that case NULL can be provided
985 * as buffer, only the block descriptor will be build. If a header is specified,
986 * it will be inserted before the buffer, default is no header.
987 * @param pBuffer pointer to buffer
988 * @param iBufferSize size of the buffer in byte
989 * @param dt data type
990 * @param spec data specification
991 * @param pHeader pointer to header
992 * @param iHeaderSize size of Header
993 * @return neg. error code if failed
995 int InsertOutputBlock(void* pBuffer, int iBufferSize,
996 const AliHLTComponentDataType& dt,
998 void* pHeader=NULL, int iHeaderSize=0);
1000 /** The global component handler instance */
1001 static AliHLTComponentHandler* fgpComponentHandler; //! transient
1003 /** The environment where the component is running in */
1004 AliHLTComponentEnvironment fEnvironment; // see above
1006 /** Set by ProcessEvent before the processing starts */
1007 AliHLTEventID_t fCurrentEvent; // see above
1009 /** internal event no */
1010 int fEventCount; // see above
1012 /** the number of failed events */
1013 int fFailedEvents; // see above
1015 /** event data struct of the current event under processing */
1016 AliHLTComponentEventData fCurrentEventData; // see above
1018 /** array of input data blocks of the current event */
1019 const AliHLTComponentBlockData* fpInputBlocks; //! transient
1021 /** index of the current input block */
1022 int fCurrentInputBlock; // see above
1024 /** data type of the last block search */
1025 AliHLTComponentDataType fSearchDataType; // see above
1027 /** name of the class for the object to search for */
1028 string fClassName; // see above
1030 /** array of generated input objects */
1031 TObjArray* fpInputObjects; //! transient
1033 /** the output buffer */
1034 AliHLTUInt8_t* fpOutputBuffer; //! transient
1036 /** size of the output buffer */
1037 AliHLTUInt32_t fOutputBufferSize; // see above
1039 /** size of data written to output buffer */
1040 AliHLTUInt32_t fOutputBufferFilled; // see above
1042 /** list of ouput block data descriptors */
1043 vector<AliHLTComponentBlockData> fOutputBlocks; // see above
1045 /** stopwatch array */
1046 TObjArray* fpStopwatches; //! transient
1048 /** array of memory files AliHLTMemoryFile */
1049 vector<AliHLTMemoryFile*> fMemFiles; //! transient
1051 /** descriptor of the current run */
1052 AliHLTRunDesc* fpRunDesc; //! transient
1054 /** the current DDL list */
1055 AliHLTEventDDL* fpDDLList; //! transient
1057 ClassDef(AliHLTComponent, 3)