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 AliHLTComponent;
51 class AliHLTMemoryFile;
53 /** list of component data type structures */
54 typedef vector<AliHLTComponentDataType> AliHLTComponentDataTypeList;
55 /** list of component block data structures */
56 typedef vector<AliHLTComponentBlockData> AliHLTComponentBlockDataList;
57 /** list of component pointers */
58 typedef vector<AliHLTComponent*> AliHLTComponentPList;
59 /** list of memory file pointers */
60 typedef vector<AliHLTMemoryFile*> AliHLTMemoryFilePList;
63 * @class AliHLTComponent
64 * Base class of HLT data processing components.
65 * The class provides a common interface for HLT data processing components.
66 * The interface can be accessed from the online HLT framework or the AliRoot
67 * offline analysis framework.
68 * @section alihltcomponent-properties Component identification and properties
69 * Each component must provide a unique ID, input and output data type indications,
70 * and a spawn function.
71 * @subsection alihltcomponent-req-methods Required property methods
72 * - @ref GetComponentID
73 * - @ref GetInputDataTypes (see @ref alihltcomponent-type for default
75 * - @ref GetOutputDataType (see @ref alihltcomponent-type for default
77 * - @ref GetOutputDataSize (see @ref alihltcomponent-type for default
81 * @subsection alihltcomponent-opt-mehods Optional handlers
84 * - @ref GetOutputDataTypes
85 * If the component has multiple output data types @ref GetOutputDataType
86 * should return @ref kAliHLTMultipleDataType. The framework will invoke
87 * @ref GetOutputDataTypes, a list can be filled.
89 * @subsection alihltcomponent-processing-mehods Data processing
92 * @subsection alihltcomponent-type Component type
93 * Components can be of type
94 * - @ref kSource components which only produce data
95 * - @ref kProcessor components which consume and produce data
96 * - @ref kSink components which only consume data
98 * where data production and consumption refer to the analysis data stream. In
99 * order to indicate the type, a child component can overload the
100 * @ref GetComponentType function.
101 * @subsubsection alihltcomponent-type-std Standard implementations
102 * Components in general do not need to implement this function, standard
103 * implementations of the 3 types are available:
104 * - AliHLTDataSource for components of type @ref kSource <br>
105 * All types of data sources can inherit from AliHLTDataSource and must
106 * implement the @ref AliHLTDataSource::GetEvent method. The class
107 * also implements a standard method for @ref GetInputDataTypes.
109 * - AliHLTProcessor for components of type @ref kProcessor <br>
110 * All types of data processors can inherit from AliHLTDataSource and must
111 * implement the @ref AliHLTProcessor::DoEvent method.
113 * - AliHLTDataSink for components of type @ref kSink <br>
114 * All types of data processors can inherit from AliHLTDataSource and must
115 * implement the @ref AliHLTDataSink::DumpEvent method. The class
116 * also implements a standard method for @ref GetOutputDataType and @ref
119 * @subsection alihltcomponent-environment Running environment
121 * In order to adapt to different environments (on-line/off-line), the component
122 * gets an environment structure with function pointers. The base class provides
123 * member functions for those environment dependend functions. The member
124 * functions are used by the component implementation and are re-mapped to the
125 * corresponding functions.
127 * @section alihltcomponent-interfaces Component interfaces
128 * Each of the 3 standard component base classes AliHLTProcessor, AliHLTDataSource
129 * and AliHLTDataSink provides it's own processing method (see
130 * @ref alihltcomponent-type-std), which splits into a high and a low-level
131 * method. For the @ref alihltcomponent-low-level-interface, all parameters are
132 * shipped as function arguments, the component is supposed to dump data to the
133 * output buffer and handle all block descriptors.
134 * The @ref alihltcomponent-high-level-interface is the standard processing
135 * method and will be used whenever the low-level method is not overloaded.
137 * In both cases it is necessary to calculate/estimate the size of the output
138 * buffer before the processing. Output buffers can never be allocated inside
139 * the component because of the push-architecture of the HLT.
140 * For that reason the @ref GetOutputDataSize function should return a rough
141 * estimatian of the data to be produced by the component. The component is
142 * responsible for checking the memory size and must return -ENOSPC if the
143 * available buffer is to small, and update the estimator respectively. The
144 * framework will allocate a buffer of appropriate size and call the processing
147 * @subsection alihltcomponent-error-codes Data processing
148 * For return codes, the following scheme applies:
149 * - The data processing methods have to indicate error conditions by a negative
150 * error/return code. Preferably the system error codes are used like
151 * e.g. -EINVAL. This requires to include the header
153 * \#include \<cerrno\>
155 * - If no suitable input block could be found (e.g. no clusters for the TPC cluster
156 * finder) set size to 0, block list is empty, return 0
157 * - If no ususable or significant signal could be found in the input blocks
158 * return an empty output block, set size accordingly, and return 0. An empty output
159 * block here could be either a real empty one of size 0 (in which case size also
160 * would have to be set to zero) or a block filled with just the minimum necessary
161 * accounting/meta-structures. E.g. in the TPC
163 * @subsection alihltcomponent-high-level-interface High-level interface
164 * The high-level component interface provides functionality to exchange ROOT
165 * structures between components. In contrast to the
166 * @ref alihltcomponent-low-level-interface, a couple of functions can be used
167 * to access data blocks of the input stream
168 * and send data blocks or ROOT TObject's to the output stream. The functionality
169 * is hidden from the user and is implemented by using ROOT's TMessage class.
171 * @subsubsection alihltcomponent-high-level-int-methods Interface methods
172 * The interface provides a couple of methods in order to get objects from the
173 * input, data blocks (non TObject) from the input, and to push back objects and
174 * data blocks to the output. For convenience there are several functions of
175 * identical name (and similar behavior) with different parameters defined.
176 * Please refer to the function documentation.
177 * - @ref GetNumberOfInputBlocks <br>
178 * return the number of data blocks in the input stream
179 * - @ref GetFirstInputObject <br>
180 * get the first object of a specific data type
181 * - @ref GetNextInputObject <br>
182 * get the next object of same data type as last GetFirstInputObject/Block call
183 * - @ref GetFirstInputBlock <br>
184 * get the first block of a specific data type
185 * - @ref GetNextInputBlock <br>
186 * get the next block of same data type as last GetFirstInputBlock/Block call
187 * - @ref PushBack <br>
188 * insert an object or data buffer into the output
189 * - @ref CreateEventDoneData <br>
190 * add event information to the output
192 * In addition, the processing methods are simplified a bit by cutting out most of
195 * - @ref AliHLTProcessor::DoEvent
196 * - @ref AliHLTDataSource::GetEvent
197 * - @ref AliHLTDataSink::DumpEvent
199 * \em IMPORTANT: objects and block descriptors provided by the high-level interface
200 * <b>MUST NOT BE DELETED</b> by the caller.
202 * @subsubsection alihltcomponent-high-level-int-guidelines High-level interface guidelines
203 * - Structures must inherit from the ROOT object base class TObject in order be
204 * transported by the transportation framework.
205 * - all pointer members must be transient (marked <tt>//!</tt> behind the member
206 * definition), i.e. will not be stored/transported, or properly marked
207 * (<tt>//-></tt>) in order to call the streamer of the object the member is pointing
208 * to. The latter is not recomended. Structures to be transported between components
209 * should be streamlined.
210 * - no use of stl vectors/strings, use appropriate ROOT classes instead
212 * @subsection alihltcomponent-low-level-interface Low-level interface
213 * The low-level component interface consists of the specific data processing
214 * methods for @ref AliHLTProcessor, @ref AliHLTDataSource, and @ref AliHLTDataSink.
215 * - @ref AliHLTProcessor::DoEvent
216 * - @ref AliHLTDataSource::GetEvent
217 * - @ref AliHLTDataSink::DumpEvent
220 * @section alihltcomponent-handling Component handling
221 * The handling of HLT analysis components is carried out by the AliHLTComponentHandler.
222 * Component are registered automatically at load-time of the component shared library
223 * under the following suppositions:
224 * - the component library has to be loaded from the AliHLTComponentHandler using the
225 * @ref AliHLTComponentHandler::LoadLibrary method.
226 * - the component implementation defines one global object (which is generated
227 * when the library is loaded)
229 * @subsection alihltcomponent-design-rules General design considerations
230 * The analysis code should be implemented in one or more destict class(es). A
231 * \em component should be implemented which interface the destict analysis code to the
232 * component interface. This component generates the analysis object dynamically. <br>
234 * Assume you have an implemetation <tt> AliHLTDetMyAnalysis </tt>, another class <tt>
235 * AliHLTDetMyAnalysisComponent </tt> contains:
238 * AliHLTDetMyAnalysis* fMyAnalysis; //!
240 * The object should then be instantiated in the DoInit handler of
241 * <tt>AliHLTDetMyAnalysisComponent </tt>, and cleaned in the DoDeinit handler.
244 * - avoid big static arrays in the component, allocate the memory at runtime
246 * @ingroup alihlt_component
247 * @section alihltcomponent-members Class members
249 class AliHLTComponent : public AliHLTLogging {
251 /** standard constructor */
253 /** standard destructor */
254 virtual ~AliHLTComponent();
256 /** component type definitions */
257 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
260 * Init function to prepare data processing.
261 * Initialization of common data structures for a sequence of events.
262 * The call is redirected to the internal method @ref DoInit which can be
263 * overridden by the child class.<br>
264 * During Init also the environment structure is passed to the component.
265 * @param environ environment pointer with environment dependend function
267 * @param environParam additionel parameter for function calls, the pointer
269 * @param argc size of the argument array
270 * @param argv agument array for component initialization
272 virtual int Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv );
275 * Clean-up function to terminate data processing.
276 * Clean-up of common data structures after data processing.
277 * The call is redirected to the internal method @ref DoDeinit which can be
278 * overridden by the child class.
280 virtual int Deinit();
283 * Processing of one event.
284 * The method is the entrance of the event processing. The parameters are
285 * cached for uses with the high-level interface and the DoProcessing
286 * implementation is called.
293 * @param outputBlockCnt out: size of the output block array, set by the component
294 * @param outputBlocks out: the output block array is allocated internally
296 * @return neg. error code if failed
298 int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
299 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
300 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
301 AliHLTComponentBlockData*& outputBlocks,
302 AliHLTComponentEventDoneData*& edd );
305 * Internal processing of one event.
306 * The method is pure virtual and implemented by the child classes
307 * - @ref AliHLTProcessor
308 * - @ref AliHLTDataSource
309 * - @ref AliHLTDataSink
316 * @param outputBlocks out: the output block array is allocated internally
318 * @return neg. error code if failed
320 virtual int DoProcessing( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
321 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
322 AliHLTUInt32_t& size,
323 AliHLTComponentBlockDataList& outputBlocks,
324 AliHLTComponentEventDoneData*& edd ) = 0;
326 // Information member functions for registration.
329 * Get the type of the component.
330 * The function is pure virtual and must be implemented by the child class.
331 * @return component type id
333 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
336 * Get the id of the component.
337 * Each component is identified by a unique id.
338 * The function is pure virtual and must be implemented by the child class.
339 * @return component id (string)
341 virtual const char* GetComponentID() = 0;
344 * Get the input data types of the component.
345 * The function is pure virtual and must be implemented by the child class.
346 * @return list of data types in the vector reference
348 virtual void GetInputDataTypes( AliHLTComponentDataTypeList& ) = 0;
351 * Get the output data type of the component.
352 * The function is pure virtual and must be implemented by the child class.
353 * @return output data type
355 virtual AliHLTComponentDataType GetOutputDataType() = 0;
358 * Get the output data types of the component.
359 * The function can be implemented to indicate multiple output data types
360 * in the target array.
361 * @ref GetOutputDataType must return @ref kAliHLTMultipleDataType in order
362 * to invoke this method.
363 * @param tgtList list to receive the data types
364 * @return no of output data types, data types in the target list
366 virtual int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList);
369 * Get a ratio by how much the data volume is shrinked or enhanced.
370 * The function is pure virtual and must be implemented by the child class.
371 * @param constBase <i>return</i>: additive part, independent of the
373 * @param inputMultiplier <i>return</i>: multiplication ratio
374 * @return values in the reference variables
376 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
380 * Each component must implement a spawn function to create a new instance of
381 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
382 * @return new class instance
384 virtual AliHLTComponent* Spawn() = 0;
387 * Find matching data types between this component and a consumer component.
388 * Currently, a component can produce only one type of data. This restriction is most
389 * likely to be abolished in the future.
390 * @param pConsumer a component and consumer of the data produced by this component
391 * @param tgtList reference to a vector list to receive the matching data types.
392 * @return >= 0 success, neg. error code if failed
394 int FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList);
397 * Set the global component handler.
398 * The static method is needed for the automatic registration of components.
400 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
403 * Clear the global component handler.
404 * The static method is needed for the automatic registration of components.
406 static int UnsetGlobalComponentHandler();
409 * Helper function to convert the data type to a string.
411 static string DataType2Text( const AliHLTComponentDataType& type );
414 * Helper function to print content of data type.
416 void PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format=NULL) const;
419 * helper function to initialize AliHLTComponentEventData structure
421 static void FillEventData(AliHLTComponentEventData& evtData);
424 * Print info on an AliHLTComponentDataType structure
425 * This is just a helper function to examine an @ref AliHLTComponentDataType
428 void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
431 * Stopwatch type for benchmarking.
433 enum AliHLTStopwatchType {
434 /** total time for event processing */
436 /** detector algorithm w/o interface callbacks */
442 /** number of types */
447 * Helper class for starting and stopping a stopwatch.
448 * The guard can be used by instantiating an object in a function. The
449 * specified stopwatch is started and the previous stopwatch put on
450 * hold. When the function is terminated, the object is deleted automatically
451 * deleted, stopping the stopwatch and starting the one on hold.<br>
452 * \em IMPORTANT: never create dynamic objects from this guard as this violates
453 * the idea of a guard.
455 class AliHLTStopwatchGuard {
457 /** standard constructor (not for use) */
458 AliHLTStopwatchGuard();
460 AliHLTStopwatchGuard(TStopwatch* pStart);
461 /** copy constructor (not for use) */
462 AliHLTStopwatchGuard(const AliHLTStopwatchGuard&);
463 /** assignment operator (not for use) */
464 AliHLTStopwatchGuard& operator=(const AliHLTStopwatchGuard&);
466 ~AliHLTStopwatchGuard();
470 * Hold the previous guard for the existence of this guard.
471 * Checks whether this guard controls a new stopwatch. In that case, the
472 * previous guard and its stopwatch are put on hold.
473 * @param pSucc instance of the stopwatch of the new guard
474 * @return 1 if pSucc is a different stopwatch which should
476 * 0 if it controls the same stopwatch
478 int Hold(TStopwatch* pSucc);
481 * Resume the previous guard.
482 * Checks whether the peceeding guard controls a different stopwatch. In that
483 * case, the its stopwatch is resumed.
484 * @param pSucc instance of the stopwatch of the new guard
485 * @return 1 if pSucc is a different stopwatch which should
487 * 0 if it controls the same stopwatch
489 int Resume(TStopwatch* pSucc);
491 /** the stopwatch controlled by this guard */
492 TStopwatch* fpStopwatch; //!transient
494 /** previous stopwatch guard, put on hold during existence of the guard */
495 AliHLTStopwatchGuard* fpPrec; //!transient
497 /** active stopwatch guard */
498 static AliHLTStopwatchGuard* fgpCurrent; //!transient
502 * Set a stopwatch for a given purpose.
503 * @param pSW stopwatch object
504 * @param type type of the stopwatch
506 int SetStopwatch(TObject* pSW, AliHLTStopwatchType type=kSWBase);
509 * Init a set of stopwatches.
510 * @param pStopwatches object array of stopwatches
512 int SetStopwatches(TObjArray* pStopwatches);
517 * Fill AliHLTComponentBlockData structure with default values.
518 * @param blockData reference to data structure
520 void FillBlockData( AliHLTComponentBlockData& blockData ) const;
523 * Fill AliHLTComponentShmData structure with default values.
524 * @param shmData reference to data structure
526 void FillShmData( AliHLTComponentShmData& shmData ) const;
529 * Fill AliHLTComponentDataType structure with default values.
530 * @param dataType reference to data structure
532 void FillDataType( AliHLTComponentDataType& dataType ) const;
535 * Copy data type structure
536 * Copies the value an AliHLTComponentDataType structure to another one
537 * @param[out] tgtdt target structure
538 * @param[in] srcdt source structure
540 void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
543 * Set the ID and Origin of an AliHLTComponentDataType structure.
544 * The function sets the fStructureSize member and copies the strings
545 * to the ID and Origin. Only characters from the valid part of the string
546 * are copied, the rest is fille with 0's.
547 * Please note that the fID and fOrigin members are not strings, just arrays of
548 * chars of size @ref kAliHLTComponentDataTypefIDsize and
549 * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
550 * a terminating zero.
551 * @param tgtdt target data type structure
552 * @param id ID string
553 * @param origin Origin string
555 void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
558 * Default method for the internal initialization.
559 * The method is called by @ref Init
561 virtual int DoInit( int argc, const char** argv );
564 * Default method for the internal clean-up.
565 * The method is called by @ref Deinit
567 virtual int DoDeinit();
570 * General memory allocation method.
571 * All memory which is going to be used 'outside' of the interface must
572 * be provided by the framework (online or offline).
573 * The method is redirected to a function provided by the current
574 * framework. Function pointers are transferred via the @ref
575 * AliHLTComponentEnvironment structure.
577 void* AllocMemory( unsigned long size );
580 * Helper function to create a monolithic BlockData description block out
581 * of a list BlockData descriptors.
582 * For convenience, inside the interface vector lists are used, to make the
583 * interface pure C style, monilithic blocks must be exchanged.
584 * The method is redirected to a function provided by the current
585 * framework. Function pointers are transferred via the @ref
586 * AliHLTComponentEnvironment structure.
588 int MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
589 AliHLTComponentBlockData** outputBlocks );
592 * Fill the EventDoneData structure.
593 * The method is redirected to a function provided by the current
594 * framework. Function pointers are transferred via the @ref
595 * AliHLTComponentEnvironment structure.
597 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd );
600 * Helper function to convert the data type to a string.
602 void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]) const;
606 * @return value of the internal event counter
608 int GetEventCount() const;
611 * Get the number of input blocks.
612 * @return number of input blocks
614 int GetNumberOfInputBlocks() const;
617 * Get the first object of a specific data type from the input data.
618 * The hight-level methods provide functionality to transfer ROOT data
619 * structures which inherit from TObject.
620 * The method looks for the first ROOT object of type dt in the input stream.
621 * If also the class name is provided, the object is checked for the right
622 * class type. The input data block needs a certain structure, namely the
623 * buffer size as first word. If the cross check fails, the retrieval is
624 * silently abondoned, unless the \em bForce parameter is set.<br>
625 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
626 * @param dt data type of the object
627 * @param classname class name of the object
628 * @param bForce force the retrieval of an object, error messages
629 * are suppressed if \em bForce is not set
630 * @return pointer to @ref TObject, NULL if no objects of specified type
633 const TObject* GetFirstInputObject(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
634 const char* classname=NULL,
638 * Get the first object of a specific data type from the input data.
639 * The hight-level methods provide functionality to transfer ROOT data
640 * structures which inherit from TObject.
641 * The method looks for the first ROOT object of type specified by the ID and
642 * Origin strings in the input stream.
643 * If also the class name is provided, the object is checked for the right
644 * class type. The input data block needs a certain structure, namely the
645 * buffer size as first word. If the cross check fails, the retrieval is
646 * silently abondoned, unless the \em bForce parameter is set.<br>
647 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
648 * @param dtID data type ID of the object
649 * @param dtOrigin data type origin of the object
650 * @param classname class name of the object
651 * @param bForce force the retrieval of an object, error messages
652 * are suppressed if \em bForce is not set
653 * @return pointer to @ref TObject, NULL if no objects of specified type
656 const TObject* GetFirstInputObject(const char* dtID,
657 const char* dtOrigin,
658 const char* classname=NULL,
662 * Get the next object of a specific data type from the input data.
663 * The hight-level methods provide functionality to transfer ROOT data
664 * structures which inherit from TObject.
665 * The method looks for the next ROOT object of type and class specified
666 * to the previous @ref GetFirstInputObject call.<br>
667 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
668 * @param bForce force the retrieval of an object, error messages
669 * are suppressed if \em bForce is not set
670 * @return pointer to @ref TObject, NULL if no more objects available
672 const TObject* GetNextInputObject(int bForce=0);
675 * Get data type of an input block.
676 * Get data type of the object previously fetched via
677 * GetFirstInputObject/NextInputObject or the last one if no object
679 * @param pObject pointer to TObject
680 * @return data specification, kAliHLTVoidDataSpec if failed
682 AliHLTComponentDataType GetDataType(const TObject* pObject=NULL);
685 * Get data specification of an input block.
686 * Get data specification of the object previously fetched via
687 * GetFirstInputObject/NextInputObject or the last one if no object
689 * @param pObject pointer to TObject
690 * @return data specification, kAliHLTVoidDataSpec if failed
692 AliHLTUInt32_t GetSpecification(const TObject* pObject=NULL);
695 * Get the first block of a specific data type from the input data.
696 * The method looks for the first block of type dt in the input stream. It is intended
697 * to be used within the high-level interface.<br>
698 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
699 * @param dt data type of the block
700 * @return pointer to @ref AliHLTComponentBlockData
702 const AliHLTComponentBlockData* GetFirstInputBlock(const AliHLTComponentDataType& dt=kAliHLTAnyDataType);
705 * Get the first block of a specific data type from the input data.
706 * The method looks for the first block of type specified by the ID and
707 * Origin strings in the input stream. It is intended
708 * to be used within the high-level interface.<br>
709 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
710 * @param dtID data type ID of the block
711 * @param dtOrigin data type origin of the block
712 * @return pointer to @ref AliHLTComponentBlockData
714 const AliHLTComponentBlockData* GetFirstInputBlock(const char* dtID,
715 const char* dtOrigin);
718 * Get input block by index.<br>
719 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
720 * @return pointer to AliHLTComponentBlockData, NULL if index out of range
722 const AliHLTComponentBlockData* GetInputBlock(int index);
725 * Get the next block of a specific data type from the input data.
726 * The method looks for the next block of type and class specified
727 * to the previous @ref GetFirstInputBlock call.
728 * To be used within the high-level interface.<br>
729 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
731 const AliHLTComponentBlockData* GetNextInputBlock();
734 * Get data specification of an input block.
735 * Get data specification of the input bblock previously fetched via
736 * GetFirstInputObject/NextInputObject or the last one if no block
738 * @param pBlock pointer to input block
739 * @return data specification, kAliHLTVoidDataSpec if failed
741 AliHLTUInt32_t GetSpecification(const AliHLTComponentBlockData* pBlock=NULL);
744 * Insert an object into the output.
745 * If header is specified, it will be inserted before the root object,
746 * default is no header.
747 * @param pObject pointer to root object
748 * @param dt data type of the object
749 * @param spec data specification
750 * @param pHeader pointer to header
751 * @param headerSize size of Header
752 * @return neg. error code if failed
754 int PushBack(TObject* pObject, const AliHLTComponentDataType& dt,
755 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
756 void* pHeader=NULL, int headerSize=0);
759 * Insert an object into the output.
760 * If header is specified, it will be inserted before the root object,
761 * default is no header.
762 * @param pObject pointer to root object
763 * @param dtID data type ID of the object
764 * @param dtOrigin data type origin of the object
765 * @param spec data specification
766 * @param pHeader pointer to header
767 * @param headerSize size of Header
768 * @return neg. error code if failed
770 int PushBack(TObject* pObject, const char* dtID, const char* dtOrigin,
771 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
772 void* pHeader=NULL, int headerSize=0);
775 * Insert an object into the output.
776 * @param pBuffer pointer to buffer
777 * @param iSize size of the buffer
778 * @param dt data type of the object
779 * @param spec data specification
780 * @param pHeader pointer to header
781 * @param headerSize size of Header
782 * @return neg. error code if failed
784 int PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt,
785 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
786 void* pHeader=NULL, int headerSize=0);
789 * Insert an object into the output.
790 * @param pBuffer pointer to buffer
791 * @param iSize size of the buffer
792 * @param dtID data type ID of the object
793 * @param dtOrigin data type origin of the object
794 * @param spec data specification
795 * @param pHeader pointer to header
796 * @param headerSize size of Header
797 * @return neg. error code if failed
799 int PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin,
800 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
801 void* pHeader=NULL, int headerSize=0);
804 * Estimate size of a TObject
806 * @return buffer size in byte
808 int EstimateObjectSize(TObject* pObject) const;
811 * Create a memory file in the output stream.
812 * This method creates a TFile object which stores all data in
813 * memory instead of disk. The TFile object is published as binary data.
814 * The instance can be used like a normal TFile object. The TFile::Close
815 * or @ref CloseMemoryFile method has to be called in order to flush the
818 * \b Note: The returned object is deleted by the framework.
819 * @param capacity total size reserved for the memory file
820 * @param dtID data type ID of the file
821 * @param dtOrigin data type origin of the file
822 * @param spec data specification
823 * @return file handle, NULL if failed
825 AliHLTMemoryFile* CreateMemoryFile(int capacity, const char* dtID, const char* dtOrigin,
826 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
829 * Create a memory file in the output stream.
830 * This method creates a TFile object which stores all data in
831 * memory instead of disk. The TFile object is published as binary data.
832 * The instance can be used like a normal TFile object. The TFile::Close
833 * or @ref CloseMemoryFile method has to be called in order to flush the
836 * \b Note: The returned object is deleted by the framework.
837 * @param capacity total size reserved for the memory file
838 * @param dt data type of the file
839 * @param spec data specification
840 * @return file handle, NULL if failed
842 AliHLTMemoryFile* CreateMemoryFile(int capacity,
843 const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
844 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
847 * Create a memory file in the output stream.
848 * This method creates a TFile object which stores all data in
849 * memory instead of disk. The TFile object is published as binary data.
850 * The instance can be used like a normal TFile object. The TFile::Close
851 * or @ref CloseMemoryFile method has to be called in order to flush the
854 * \b Note: The returned object is deleted by the framework.
855 * @param dtID data type ID of the file
856 * @param dtOrigin data type origin of the file
857 * @param spec data specification
858 * @param capacity fraction of the available output buffer size
859 * @return file handle, NULL if failed
861 AliHLTMemoryFile* CreateMemoryFile(const char* dtID, const char* dtOrigin,
862 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
866 * Create a memory file in the output stream.
867 * This method creates a TFile object which stores all data in
868 * memory instead of disk. The TFile object is published as binary data.
869 * The instance can be used like a normal TFile object. The TFile::Close
870 * or @ref CloseMemoryFile method has to be called in order to flush the
873 * \b Note: The returned object is deleted by the framework.
874 * @param dt data type of the file
875 * @param spec data specification
876 * @param capacity fraction of the available output buffer size
877 * @return file handle, NULL if failed
879 AliHLTMemoryFile* CreateMemoryFile(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
880 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
884 * Write an object to memory file in the output stream.
885 * @param pFile file handle
886 * @param pObject pointer to root object
887 * @param key key in ROOT file
888 * @param option options, see TObject::Write
889 * @return neg. error code if failed
890 * - -ENOSPC no space left
892 int Write(AliHLTMemoryFile* pFile, const TObject* pObject, const char* key=NULL, int option=TObject::kOverwrite);
895 * Close object memory file.
896 * @param pFile file handle
897 * @return neg. error code if failed
898 * - -ENOSPC buffer size too small
900 int CloseMemoryFile(AliHLTMemoryFile* pFile);
903 * Insert event-done data information into the output.
904 * @param edd event-done data information
906 int CreateEventDoneData(AliHLTComponentEventDoneData edd);
909 * Get current run number
911 AliHLTUInt32_t GetRunNo() const;
914 * Get the current run type.
916 AliHLTUInt32_t GetRunType() const;
919 * Copy a struct from block data.
920 * The function checks for block size and struct size. The least common
921 * size will be copied to the target struct, remaining fields are initialized
923 * The target struct must have a 32bit struct size indicator as first member.
924 * @param pStruct target struct
925 * @param iStructSize size of the struct
926 * @param iBlockNo index of input block
927 * @param structname name of the struct (log messages)
928 * @param eventname name of the event (log messages)
929 * @return size copied, neg. error if failed
931 int CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
932 const char* structname="", const char* eventname="");
935 /** copy constructor prohibited */
936 AliHLTComponent(const AliHLTComponent&);
937 /** assignment operator prohibited */
938 AliHLTComponent& operator=(const AliHLTComponent&);
941 * Increment the internal event counter.
942 * To be used by the friend classes AliHLTProcessor, AliHLTDataSource
943 * and AliHLTDataSink.
944 * @return new value of the internal event counter
947 int IncrementEventCounter();
950 * Find the first input block of specified data type beginning at index.
951 * Input blocks containing a TObject have the size of the object as an
952 * unsigned 32 bit number in the first 4 bytes. This has to match the block
954 * @param dt data type
955 * @param startIdx index to start the search
956 * @param bObject check if this is an object
957 * @return index of the block, -ENOENT if no block found
961 int FindInputBlock(const AliHLTComponentDataType& dt, int startIdx=-1, int bObject=0) const;
964 * Get index in the array of input bocks.
965 * Calculate index and check integrety of a block data structure pointer.
966 * @param pBlock pointer to block data
967 * @return index of the block, -ENOENT if no block found
971 int FindInputBlock(const AliHLTComponentBlockData* pBlock) const;
974 * Create an object from a specified input block.
975 * @param idx index of the input block
976 * @param bForce force the retrieval of an object, error messages
977 * are suppressed if \em bForce is not set
978 * @return pointer to TObject, caller must delete the object after use
982 TObject* CreateInputObject(int idx, int bForce=0);
986 * Get object from the input block list. The methods first checks whether the
987 * object was already created. If not, it is created by @ref CreateInputObject
988 * and inserted into the list of objects.
989 * @param idx index in the input block list
990 * @param classname name of the class, object is checked for correct class
992 * @param bForce force the retrieval of an object, error messages
993 * are suppressed if \em bForce is not set
994 * @return pointer to TObject
998 TObject* GetInputObject(int idx, const char* classname=NULL, int bForce=0);
1001 * Clean the list of input objects.
1002 * Cleanup is done at the end of each event processing.
1004 int CleanupInputObjects();
1007 * Insert a buffer into the output block stream.
1008 * This is the only method to insert blocks into the output stream, called
1009 * from all types of the Pushback method. The actual data might have been
1010 * written to the output buffer already. In that case NULL can be provided
1011 * as buffer, only the block descriptor will be build. If a header is specified,
1012 * it will be inserted before the buffer, default is no header.
1013 * @param pBuffer pointer to buffer
1014 * @param iBufferSize size of the buffer in byte
1015 * @param dt data type
1016 * @param spec data specification
1017 * @param pHeader pointer to header
1018 * @param iHeaderSize size of Header
1019 * @return neg. error code if failed
1021 int InsertOutputBlock(void* pBuffer, int iBufferSize,
1022 const AliHLTComponentDataType& dt,
1023 AliHLTUInt32_t spec,
1024 void* pHeader=NULL, int iHeaderSize=0);
1026 /** The global component handler instance */
1027 static AliHLTComponentHandler* fgpComponentHandler; //! transient
1029 /** The environment where the component is running in */
1030 AliHLTComponentEnvironment fEnvironment; // see above
1032 /** Set by ProcessEvent before the processing starts */
1033 AliHLTEventID_t fCurrentEvent; // see above
1035 /** internal event no */
1036 int fEventCount; // see above
1038 /** the number of failed events */
1039 int fFailedEvents; // see above
1041 /** event data struct of the current event under processing */
1042 AliHLTComponentEventData fCurrentEventData; // see above
1044 /** array of input data blocks of the current event */
1045 const AliHLTComponentBlockData* fpInputBlocks; //! transient
1047 /** index of the current input block */
1048 int fCurrentInputBlock; // see above
1050 /** data type of the last block search */
1051 AliHLTComponentDataType fSearchDataType; // see above
1053 /** name of the class for the object to search for */
1054 string fClassName; // see above
1056 /** array of generated input objects */
1057 TObjArray* fpInputObjects; //! transient
1059 /** the output buffer */
1060 AliHLTUInt8_t* fpOutputBuffer; //! transient
1062 /** size of the output buffer */
1063 AliHLTUInt32_t fOutputBufferSize; // see above
1065 /** size of data written to output buffer */
1066 AliHLTUInt32_t fOutputBufferFilled; // see above
1068 /** list of ouput block data descriptors */
1069 AliHLTComponentBlockDataList fOutputBlocks; // see above
1071 /** stopwatch array */
1072 TObjArray* fpStopwatches; //! transient
1074 /** array of memory files AliHLTMemoryFile */
1075 AliHLTMemoryFilePList fMemFiles; //! transient
1077 /** descriptor of the current run */
1078 AliHLTRunDesc* fpRunDesc; //! transient
1080 /** the current DDL list */
1081 AliHLTEventDDL* fpDDLList; //! transient
1083 ClassDef(AliHLTComponent, 3)