]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTComponent.h
components return -ENOSPC if output buffer too small, second trial by the AliRoot...
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.h
1 //-*- Mode: C++ -*-
2 // @(#) $Id$
3
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                               */
9
10 /** @file   AliHLTComponent.h
11     @author Matthias Richter, Timm Steinbeck
12     @date   
13     @brief  Base class declaration for HLT components. 
14     @note   The class is both used in Online (PubSub) and Offline (AliRoot)
15             context
16
17 // see below for class documentation
18 // or
19 // refer to README to build package
20 // or
21 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
22                                                                           */
23 /**
24  * @defgroup alihlt_component Component handling of the HLT module
25  * This section describes the the component handling for the HLT module.
26  */
27
28 #include <vector>
29 #include <string>
30 #include "AliHLTLogging.h"
31 #include "AliHLTDataTypes.h"
32 //#include "AliHLTDefinitions.h"
33
34 /* Matthias Dec 2006
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
38  */
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;
46
47 class AliHLTComponentHandler;
48 class TObjArray;
49 class TStopwatch;
50 class AliHLTMemoryFile;
51
52 /**
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
64  *   implementations.)
65  * - @ref GetOutputDataType (see @ref alihltcomponent-type for default
66  *   implementations.)
67  * - @ref GetOutputDataSize (see @ref alihltcomponent-type for default
68  *   implementations.)
69  * - @ref Spawn
70  *
71  * @subsection alihltcomponent-opt-mehods Optional handlers
72  * - @ref DoInit
73  * - @ref DoDeinit
74  *
75  * @subsection alihltcomponent-processing-mehods Data processing
76  * 
77  * 
78  * @subsection alihltcomponent-type Component type
79  * Components can be of type
80  * - @ref kSource     components which only produce data 
81  * - @ref kProcessor  components which consume and produce data
82  * - @ref kSink       components which only consume data
83  *
84  * where data production and consumption refer to the analysis data stream. In
85  * order to indicate the type, a child component can overload the
86  * @ref GetComponentType function.
87  * @subsubsection alihltcomponent-type-std Standard implementations
88  * Components in general do not need to implement this function, standard
89  * implementations of the 3 types are available:
90  * - AliHLTDataSource for components of type @ref kSource <br>
91  *   All types of data sources can inherit from AliHLTDataSource and must
92  *   implement the @ref AliHLTDataSource::GetEvent method. The class
93  *   also implements a standard method for @ref GetInputDataTypes.
94  *   
95  * - AliHLTProcessor for components of type @ref kProcessor <br>
96  *   All types of data processors can inherit from AliHLTDataSource and must
97  *   implement the @ref AliHLTProcessor::DoEvent method.
98  *
99  * - AliHLTDataSink for components of type @ref kSink <br>
100  *   All types of data processors can inherit from AliHLTDataSource and must
101  *   implement the @ref AliHLTDataSink::DumpEvent method. The class
102  *   also implements a standard method for @ref GetOutputDataType and @ref
103  *   GetOutputDataSize.
104  *
105  * @subsection alihltcomponent-environment Running environment
106  *
107  * In order to adapt to different environments (on-line/off-line), the component
108  * gets an environment structure with function pointers. The base class provides
109  * member functions for those environment dependend functions. The member 
110  * functions are used by the component implementation and are re-mapped to the
111  * corresponding functions.
112  *
113  * @section alihltcomponent-interfaces Component interfaces
114  * Each of the 3 standard component base classes AliHLTProcessor, AliHLTDataSource
115  * and AliHLTDataSink provides it's own processing method (see
116  * @ref alihltcomponent-type-std), which splits into a high and a low-level
117  * method. For the @ref alihltcomponent-low-level-interface, all parameters are
118  * shipped as function arguments, the component is supposed to dump data to the
119  * output buffer and handle all block descriptors. 
120  * The @ref alihltcomponent-high-level-interface is the standard processing
121  * method and will be used whenever the low-level method is not overloaded.
122  *
123  * In both cases it is necessary to calculate/estimate the size of the output
124  * buffer before the processing. Output buffers can never be allocated inside
125  * the component because of the push-architecture of the HLT.
126  * For that reason the @ref GetOutputDataSize function should return a rough
127  * estimatian of the data to be produced by the component. The component is
128  * responsible for checking the memory size and must return -ENOSPC if the
129  * available buffer is to small, and update the estimator respectively. The
130  * framework will allocate a buffer of appropriate size and call the processing
131  * again.
132  *
133  * @subsection alihltcomponent-high-level-interface High-level interface
134  * The high-level component interface provides functionality to exchange ROOT
135  * structures between components. In contrast to the 
136  * @ref alihltcomponent-low-level-interface, a couple of functions can be used
137  * to access data blocks of the input stream
138  * and send data blocks or ROOT TObject's to the output stream. The functionality
139  * is hidden from the user and is implemented by using ROOT's TMessage class.
140  *
141  * @subsubsection alihltcomponent-high-level-int-methods Interface methods
142  * The interface provides a couple of methods in order to get objects from the
143  * input, data blocks (non TObject) from the input, and to push back objects and
144  * data blocks to the output. For convenience there are several functions of 
145  * identical name (and similar behavior) with different parameters defined.
146  * Please refer to the function documentation.
147  * - @ref GetNumberOfInputBlocks <br>
148  *        return the number of data blocks in the input stream
149  * - @ref GetFirstInputObject <br>
150  *        get the first object of a specific data type
151  * - @ref GetNextInputObject <br>
152  *        get the next object of same data type as last GetFirstInputObject/Block call
153  * - @ref GetFirstInputBlock <br>
154  *        get the first block of a specific data type
155  * - @ref GetNextInputBlock <br>
156  *        get the next block of same data type as last GetFirstInputBlock/Block call
157  * - @ref PushBack <br>
158  *        insert an object or data buffer into the output
159  * - @ref CreateEventDoneData <br>
160  *        add event information to the output
161  * 
162  * In addition, the processing methods are simplified a bit by cutting out most of
163  * the parameters.
164  * @see 
165  * - @ref AliHLTProcessor::DoEvent
166  * - @ref AliHLTDataSource::GetEvent
167  * - @ref AliHLTDataSink::DumpEvent
168  *
169  * \em IMPORTANT: objects and block descriptors provided by the high-level interface
170  *  <b>MUST NOT BE DELETED</b> by the caller.
171  *
172  * @subsubsection alihltcomponent-high-level-int-guidelines High-level interface guidelines
173  * - Structures must inherit from the ROOT object base class TObject in order be 
174  * transported by the transportation framework.
175  * - all pointer members must be transient (marked <tt>//!</tt> behind the member
176  * definition), i.e. will not be stored/transported, or properly marked
177  * (<tt>//-></tt>) in order to call the streamer of the object the member is pointing
178  * to. The latter is not recomended. Structures to be transported between components
179  * should be streamlined.
180  * - no use of stl vectors/strings, use appropriate ROOT classes instead 
181  * 
182  * @subsection alihltcomponent-low-level-interface Low-level interface
183  * The low-level component interface consists of the specific data processing
184  * methods for @ref AliHLTProcessor, @ref AliHLTDataSource, and @ref AliHLTDataSink.
185  * - @ref AliHLTProcessor::DoEvent
186  * - @ref AliHLTDataSource::GetEvent
187  * - @ref AliHLTDataSink::DumpEvent
188  * 
189  * 
190  * @section alihltcomponent-handling Component handling 
191  * The handling of HLT analysis components is carried out by the AliHLTComponentHandler.
192  * Component are registered automatically at load-time of the component shared library
193  * under the following suppositions:
194  * - the component library has to be loaded from the AliHLTComponentHandler using the
195  *   @ref AliHLTComponentHandler::LoadLibrary method.
196  * - the component implementation defines one global object (which is generated
197  *   when the library is loaded)
198  *
199  * @subsection alihltcomponent-design-rules General design considerations
200  * The analysis code should be implemented in one or more destict class(es). A 
201  * \em component should be implemented which interface the destict analysis code to the
202  * component interface. This component generates the analysis object dynamically. <br>
203  *
204  * Assume you have an implemetation <tt> AliHLTDetMyAnalysis </tt>, another class <tt>
205  * AliHLTDetMyAnalysisComponent </tt> contains:
206  * <pre>
207  * private:
208  *   AliHLTDetMyAnalysis* fMyAnalysis;  //!
209  * </pre>
210  * The object should then be instantiated in the DoInit handler of 
211  * <tt>AliHLTDetMyAnalysisComponent </tt>, and cleaned in the DoDeinit handler.
212  *
213  * Further rules:
214  * - avoid big static arrays in the component, allocate the memory at runtime
215  *
216  * @ingroup alihlt_component
217  * @section alihltcomponent-members Class members
218  */
219 class AliHLTComponent : public AliHLTLogging {
220  public:
221   /** standard constructor */
222   AliHLTComponent();
223   /** standard destructor */
224   virtual ~AliHLTComponent();
225
226   /** component type definitions */
227   enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
228
229   /**
230    * Init function to prepare data processing.
231    * Initialization of common data structures for a sequence of events.
232    * The call is redirected to the internal method @ref DoInit which can be
233    * overridden by the child class.<br>
234    * During Init also the environment structure is passed to the component.
235    * @param environ        environment pointer with environment dependend function
236    *                       calls
237    * @param environParam   additionel parameter for function calls, the pointer
238    *                       is passed as it is
239    * @param argc           size of the argument array
240    * @param argv           agument array for component initialization
241    */
242   virtual int Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv );
243
244   /**
245    * Clean-up function to terminate data processing.
246    * Clean-up of common data structures after data processing.
247    * The call is redirected to the internal method @ref DoDeinit which can be
248    * overridden by the child class.
249    */
250   virtual int Deinit();
251
252   /**
253    * Processing of one event.
254    * The method is the entrance of the event processing. The parameters are
255    * cached for uses with the high-level interface and the DoProcessing
256    * implementation is called.
257    *
258    * @param evtData
259    * @param blocks
260    * @param trigData
261    * @param outputPtr
262    * @param size
263    * @param outputBlockCnt  out: size of the output block array, set by the component
264    * @param outputBlocks    out: the output block array is allocated internally
265    * @param edd
266    * @return neg. error code if failed
267    */
268   int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
269                             AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
270                             AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt, 
271                             AliHLTComponentBlockData*& outputBlocks,
272                             AliHLTComponentEventDoneData*& edd );
273
274   /**
275    * Internal processing of one event.
276    * The method is pure virtual and implemented by the child classes 
277    * - @ref AliHLTProcessor
278    * - @ref AliHLTDataSource
279    * - @ref AliHLTDataSink
280    *
281    * @param evtData
282    * @param blocks
283    * @param trigData
284    * @param outputPtr
285    * @param size
286    * @param outputBlocks    out: the output block array is allocated internally
287    * @param edd
288    * @return neg. error code if failed
289    */
290   virtual int DoProcessing( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
291                             AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
292                             AliHLTUInt32_t& size,
293                             vector<AliHLTComponentBlockData>& outputBlocks,
294                             AliHLTComponentEventDoneData*& edd ) = 0;
295
296   // Information member functions for registration.
297
298   /**
299    * Get the type of the component.
300    * The function is pure virtual and must be implemented by the child class.
301    * @return component type id
302    */
303   virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
304
305   /**
306    * Get the id of the component.
307    * Each component is identified by a unique id.
308    * The function is pure virtual and must be implemented by the child class.
309    * @return component id (string)
310    */
311   virtual const char* GetComponentID() = 0;
312
313   /**
314    * Get the input data types of the component.
315    * The function is pure virtual and must be implemented by the child class.
316    * @return list of data types in the vector reference
317    */
318   virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& ) = 0;
319
320   /**
321    * Get the output data type of the component.
322    * The function is pure virtual and must be implemented by the child class.
323    * @return output data type
324    */
325   virtual AliHLTComponentDataType GetOutputDataType() = 0;
326
327   /**
328    * Get a ratio by how much the data volume is shrinked or enhanced.
329    * The function is pure virtual and must be implemented by the child class.
330    * @param constBase        <i>return</i>: additive part, independent of the
331    *                                   input data volume  
332    * @param inputMultiplier  <i>return</i>: multiplication ratio
333    * @return values in the reference variables
334    */
335   virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
336
337   /**
338    * Spawn function.
339    * Each component must implement a spawn function to create a new instance of 
340    * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
341    * @return new class instance
342    */
343   virtual AliHLTComponent* Spawn() = 0;
344
345   /**
346    * Find matching data types between this component and a consumer component.
347    * Currently, a component can produce only one type of data. This restriction is most
348    * likely to be abolished in the future.
349    * @param pConsumer a component and consumer of the data produced by this component
350    * @param tgtList   reference to a vector list to receive the matching data types.
351    * @return >= 0 success, neg. error code if failed
352    */ 
353   int FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList);
354  
355   /**
356    * Set the global component handler.
357    * The static method is needed for the automatic registration of components. 
358    */
359   static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
360
361   /**
362    * Clear the global component handler.
363    * The static method is needed for the automatic registration of components. 
364    */
365   static int UnsetGlobalComponentHandler();
366
367   /**
368    * Helper function to convert the data type to a string.
369    */
370   static string DataType2Text( const AliHLTComponentDataType& type );
371
372   /**
373    * Helper function to print content of data type.
374    */
375   void PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format=NULL) const;
376
377   /**
378    * helper function to initialize AliHLTComponentEventData structure
379    */
380   static void FillEventData(AliHLTComponentEventData& evtData);
381
382   /**
383    * Print info on an AliHLTComponentDataType structure
384    * This is just a helper function to examine an @ref AliHLTComponentDataType
385    * structur.
386    */
387   void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
388
389   /**
390    * Stopwatch type for benchmarking.
391    */
392   enum AliHLTStopwatchType {
393     /** total time for event processing */
394     kSWBase,
395     /** detector algorithm w/o interface callbacks */
396     kSWDA,
397     /** data sources */
398     kSWInput,
399     /** data sinks */
400     kSWOutput,
401     /** number of types */
402     kSWTypeCount
403   };
404
405   /**
406    * Helper class for starting and stopping a stopwatch.
407    * The guard can be used by instantiating an object in a function. The
408    * specified stopwatch is started and the previous stopwatch put on
409    * hold. When the function is terminated, the object is deleted automatically
410    * deleted, stopping the stopwatch and starting the one on hold.<br>
411    * \em IMPORTANT: never create dynamic objects from this guard as this violates
412    * the idea of a guard.
413    */
414   class AliHLTStopwatchGuard {
415   public:
416     /** standard constructor (not for use) */
417     AliHLTStopwatchGuard();
418     /** constructor */
419     AliHLTStopwatchGuard(TStopwatch* pStart);
420     /** copy constructor (not for use) */
421     AliHLTStopwatchGuard(const AliHLTStopwatchGuard&);
422     /** assignment operator (not for use) */
423     AliHLTStopwatchGuard& operator=(const AliHLTStopwatchGuard&);
424     /** destructor */
425     ~AliHLTStopwatchGuard();
426
427   private:
428     /**
429      * Hold the previous guard for the existence of this guard.
430      * Checks whether this guard controls a new stopwatch. In that case, the
431      * previous guard and its stopwatch are put on hold.
432      * @param pSucc        instance of the stopwatch of the new guard
433      * @return    1 if pSucc is a different stopwatch which should
434      *            be started<br>
435      *            0 if it controls the same stopwatch
436      */
437     int Hold(TStopwatch* pSucc);
438
439     /**
440      * Resume the previous guard.
441      * Checks whether the peceeding guard controls a different stopwatch. In that
442      * case, the its stopwatch is resumed.
443      * @param pSucc        instance of the stopwatch of the new guard
444      * @return    1 if pSucc is a different stopwatch which should
445      *            be stopped<br>
446      *            0 if it controls the same stopwatch
447      */
448     int Resume(TStopwatch* pSucc);
449
450     /** the stopwatch controlled by this guard */
451     TStopwatch* fpStopwatch;                                                //!transient
452
453     /** previous stopwatch guard, put on hold during existence of the guard */
454     AliHLTStopwatchGuard* fpPrec;                                           //!transient
455
456     /** active stopwatch guard */
457     static AliHLTStopwatchGuard* fgpCurrent;                                //!transient
458   };
459
460   /**
461    * Set a stopwatch for a given purpose.
462    * @param pSW         stopwatch object
463    * @param type        type of the stopwatch
464    */
465   int SetStopwatch(TObject* pSW, AliHLTStopwatchType type=kSWBase);
466
467   /**
468    * Init a set of stopwatches.
469    * @param pStopwatches object array of stopwatches
470    */
471   int SetStopwatches(TObjArray* pStopwatches);
472
473  protected:
474
475   /**
476    * Fill AliHLTComponentBlockData structure with default values.
477    * @param blockData   reference to data structure
478    */
479   void FillBlockData( AliHLTComponentBlockData& blockData ) const;
480
481   /**
482    * Fill AliHLTComponentShmData structure with default values.
483    * @param shmData   reference to data structure
484    */
485   void FillShmData( AliHLTComponentShmData& shmData ) const;
486
487   /**
488    * Fill AliHLTComponentDataType structure with default values.
489    * @param dataType   reference to data structure
490    */
491   void FillDataType( AliHLTComponentDataType& dataType ) const;
492   
493   /**
494    * Copy data type structure
495    * Copies the value an AliHLTComponentDataType structure to another one
496    * @param[out] tgtdt   target structure
497    * @param[in] srcdt   source structure
498    */
499   void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
500
501   /**
502    * Set the ID and Origin of an AliHLTComponentDataType structure.
503    * The function sets the fStructureSize member and copies the strings
504    * to the ID and Origin. Only characters from the valid part of the string
505    * are copied, the rest is fille with 0's.
506    * Please note that the fID and fOrigin members are not strings, just arrays of
507    * chars of size @ref kAliHLTComponentDataTypefIDsize and
508    * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
509    * a terminating zero.
510    * @param tgtdt   target data type structure
511    * @param id      ID string
512    * @param origin  Origin string
513    */
514   void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
515
516   /**
517    * Default method for the internal initialization.
518    * The method is called by @ref Init
519    */
520   virtual int DoInit( int argc, const char** argv );
521
522   /**
523    * Default method for the internal clean-up.
524    * The method is called by @ref Deinit
525    */
526   virtual int DoDeinit();
527
528   /**
529    * General memory allocation method.
530    * All memory which is going to be used 'outside' of the interface must
531    * be provided by the framework (online or offline).
532    * The method is redirected to a function provided by the current
533    * framework. Function pointers are transferred via the @ref
534    * AliHLTComponentEnvironment structure.
535    */
536   void* AllocMemory( unsigned long size );
537
538   /**
539    * Helper function to create a monolithic BlockData description block out
540    * of a list BlockData descriptors.
541    * For convenience, inside the interface vector lists are used, to make the
542    * interface pure C style, monilithic blocks must be exchanged. 
543    * The method is redirected to a function provided by the current
544    * framework. Function pointers are transferred via the @ref
545    * AliHLTComponentEnvironment structure.
546    */
547   int MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
548                                AliHLTComponentBlockData** outputBlocks );
549
550   /**
551    * Fill the EventDoneData structure.
552    * The method is redirected to a function provided by the current
553    * framework. Function pointers are transferred via the @ref
554    * AliHLTComponentEnvironment structure.
555    */
556   int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd );
557
558   /**
559    * Helper function to convert the data type to a string.
560    */
561   void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]) const;
562
563   /**
564    * Get event number.
565    * @return value of the internal event counter
566    */
567   int GetEventCount() const;
568
569   /**
570    * Get the number of input blocks.
571    * @return number of input blocks
572    */
573   int GetNumberOfInputBlocks() const;
574
575   /**
576    * Get the first object of a specific data type from the input data.
577    * The hight-level methods provide functionality to transfer ROOT data
578    * structures which inherit from TObject.
579    * The method looks for the first ROOT object of type dt in the input stream.
580    * If also the class name is provided, the object is checked for the right
581    * class type. The input data block needs a certain structure, namely the 
582    * buffer size as first word. If the cross check fails, the retrieval is
583    * silently abondoned, unless the \em bForce parameter is set.<br>
584    * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
585    * @param dt          data type of the object
586    * @param classname   class name of the object
587    * @param bForce      force the retrieval of an object, error messages
588    *                    are suppressed if \em bForce is not set
589    * @return pointer to @ref TObject, NULL if no objects of specified type
590    *         available
591    */
592   const TObject* GetFirstInputObject(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
593                                      const char* classname=NULL,
594                                      int bForce=0);
595
596   /**
597    * Get the first object of a specific data type from the input data.
598    * The hight-level methods provide functionality to transfer ROOT data
599    * structures which inherit from TObject.
600    * The method looks for the first ROOT object of type specified by the ID and 
601    * Origin strings in the input stream.
602    * If also the class name is provided, the object is checked for the right
603    * class type. The input data block needs a certain structure, namely the 
604    * buffer size as first word. If the cross check fails, the retrieval is
605    * silently abondoned, unless the \em bForce parameter is set.<br>
606    * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
607    * @param dtID        data type ID of the object
608    * @param dtOrigin    data type origin of the object
609    * @param classname   class name of the object
610    * @param bForce      force the retrieval of an object, error messages
611    *                    are suppressed if \em bForce is not set
612    * @return pointer to @ref TObject, NULL if no objects of specified type
613    *         available
614    */
615   const TObject* GetFirstInputObject(const char* dtID, 
616                                      const char* dtOrigin,
617                                      const char* classname=NULL,
618                                      int bForce=0);
619
620   /**
621    * Get the next object of a specific data type from the input data.
622    * The hight-level methods provide functionality to transfer ROOT data
623    * structures which inherit from TObject.
624    * The method looks for the next ROOT object of type and class specified
625    * to the previous @ref GetFirstInputObject call.<br>
626    * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
627    * @param bForce      force the retrieval of an object, error messages
628    *                    are suppressed if \em bForce is not set
629    * @return pointer to @ref TObject, NULL if no more objects available
630    */
631   const TObject* GetNextInputObject(int bForce=0);
632
633   /**
634    * Get data type of an input block.
635    * Get data type of the object previously fetched via
636    * GetFirstInputObject/NextInputObject or the last one if no object
637    * specified.
638    * @param pObject     pointer to TObject
639    * @return data specification, kAliHLTVoidDataSpec if failed
640    */
641   AliHLTComponentDataType GetDataType(const TObject* pObject=NULL);
642
643   /**
644    * Get data specification of an input block.
645    * Get data specification of the object previously fetched via
646    * GetFirstInputObject/NextInputObject or the last one if no object
647    * specified.
648    * @param pObject     pointer to TObject
649    * @return data specification, kAliHLTVoidDataSpec if failed
650    */
651   AliHLTUInt32_t GetSpecification(const TObject* pObject=NULL);
652
653   /**
654    * Get the first block of a specific data type from the input data.
655    * The method looks for the first block of type dt in the input stream. It is intended
656    * to be used within the high-level interface.<br>
657    * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
658    * @param dt          data type of the block
659    * @return pointer to @ref AliHLTComponentBlockData
660    */
661   const AliHLTComponentBlockData* GetFirstInputBlock(const AliHLTComponentDataType& dt=kAliHLTAnyDataType);
662
663   /**
664    * Get the first block of a specific data type from the input data.
665    * The method looks for the first block of type specified by the ID and 
666    * Origin strings in the input stream.  It is intended
667    * to be used within the high-level interface.<br>
668    * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
669    * @param dtID        data type ID of the block
670    * @param dtOrigin    data type origin of the block
671    * @return pointer to @ref AliHLTComponentBlockData
672    */
673   const AliHLTComponentBlockData* GetFirstInputBlock(const char* dtID, 
674                                                       const char* dtOrigin);
675
676   /**
677    * Get input block by index.<br>
678    * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
679    * @return pointer to AliHLTComponentBlockData, NULL if index out of range
680    */
681   const AliHLTComponentBlockData* GetInputBlock(int index);
682
683   /**
684    * Get the next block of a specific data type from the input data.
685    * The method looks for the next block  of type and class specified
686    * to the previous @ref GetFirstInputBlock call.
687    * To be used within the high-level interface.<br>
688    * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
689    */
690   const AliHLTComponentBlockData* GetNextInputBlock();
691
692   /**
693    * Get data specification of an input block.
694    * Get data specification of the input bblock previously fetched via
695    * GetFirstInputObject/NextInputObject or the last one if no block
696    * specified.
697    * @param pBlock     pointer to input block
698    * @return data specification, kAliHLTVoidDataSpec if failed
699    */
700   AliHLTUInt32_t GetSpecification(const AliHLTComponentBlockData* pBlock=NULL);
701
702   /**
703    * Insert an object into the output.
704    * If header is specified, it will be inserted before the root object,
705    * default is no header.
706    * @param pObject     pointer to root object
707    * @param dt          data type of the object
708    * @param spec        data specification
709    * @param pHeader     pointer to header
710    * @param headerSize  size of Header
711    * @return neg. error code if failed 
712    */
713   int PushBack(TObject* pObject, const AliHLTComponentDataType& dt, 
714                AliHLTUInt32_t spec=kAliHLTVoidDataSpec, 
715                void* pHeader=NULL, int headerSize=0);
716
717   /**
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 dtID        data type ID of the object
723    * @param dtOrigin    data type origin of the object
724    * @param spec        data specification
725    * @param pHeader     pointer to header
726    * @param headerSize  size of Header
727    * @return neg. error code if failed 
728    */
729   int PushBack(TObject* pObject, const char* dtID, const char* dtOrigin,
730                AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
731                void* pHeader=NULL, int headerSize=0);
732  
733   /**
734    * Insert an object into the output.
735    * @param pBuffer     pointer to buffer
736    * @param iSize       size of the buffer
737    * @param dt          data type of the object
738    * @param spec        data specification
739    * @return neg. error code if failed 
740    */
741   int PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt,
742                AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
743
744   /**
745    * Insert an object into the output.
746    * @param pBuffer     pointer to buffer
747    * @param iSize       size of the buffer
748    * @param dtID        data type ID of the object
749    * @param dtOrigin    data type origin of the object
750    * @param spec        data specification
751    * @return neg. error code if failed 
752    */
753   int PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin,
754                AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
755
756   /**
757    * Estimate size of a TObject
758    * @param pObject
759    * @return buffer size in byte
760    */
761   int EstimateObjectSize(TObject* pObject) const;
762
763   /**
764    * Create a memory file in the output stream.
765    * This method creates a TFile object which stores all data in
766    * memory instead of disk. The TFile object is published as binary data.
767    * The instance can be used like a normal TFile object. The TFile::Close
768    * or @ref CloseMemoryFile method has to be called in order to flush the
769    * output stream.
770    *
771    * \b Note: The returned object is deleted by the framework.
772    * @param capacity    total size reserved for the memory file
773    * @param dtID        data type ID of the file
774    * @param dtOrigin    data type origin of the file
775    * @param spec        data specification
776    * @return file handle, NULL if failed 
777    */
778   AliHLTMemoryFile* CreateMemoryFile(int capacity, const char* dtID, const char* dtOrigin,
779                                      AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
780
781   /**
782    * Create a memory file in the output stream.
783    * This method creates a TFile object which stores all data in
784    * memory instead of disk. The TFile object is published as binary data.
785    * The instance can be used like a normal TFile object. The TFile::Close
786    * or @ref CloseMemoryFile method has to be called in order to flush the
787    * output stream.
788    *
789    * \b Note: The returned object is deleted by the framework.
790    * @param capacity    total size reserved for the memory file
791    * @param dt          data type of the file
792    * @param spec        data specification
793    * @return file handle, NULL if failed 
794    */
795   AliHLTMemoryFile* CreateMemoryFile(int capacity, 
796                                      const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
797                                      AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
798
799   /**
800    * Create a memory file in the output stream.
801    * This method creates a TFile object which stores all data in
802    * memory instead of disk. The TFile object is published as binary data.
803    * The instance can be used like a normal TFile object. The TFile::Close
804    * or @ref CloseMemoryFile method has to be called in order to flush the
805    * output stream.
806    *
807    * \b Note: The returned object is deleted by the framework.
808    * @param dtID        data type ID of the file
809    * @param dtOrigin    data type origin of the file
810    * @param spec        data specification
811    * @param capacity    fraction of the available output buffer size
812    * @return file handle, NULL if failed 
813    */
814   AliHLTMemoryFile* CreateMemoryFile(const char* dtID, const char* dtOrigin,
815                                      AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
816                                      float capacity=1.0);
817
818   /**
819    * Create a memory file in the output stream.
820    * This method creates a TFile object which stores all data in
821    * memory instead of disk. The TFile object is published as binary data.
822    * The instance can be used like a normal TFile object. The TFile::Close
823    * or @ref CloseMemoryFile method has to be called in order to flush the
824    * output stream.
825    *
826    * \b Note: The returned object is deleted by the framework.
827    * @param dt          data type of the file
828    * @param spec        data specification
829    * @param capacity    fraction of the available output buffer size
830    * @return file handle, NULL if failed 
831    */
832   AliHLTMemoryFile* CreateMemoryFile(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
833                                      AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
834                                      float capacity=1.0);
835
836   /**
837    * Write an object to memory file in the output stream.
838    * @param pFile       file handle
839    * @param pObject     pointer to root object
840    * @param key         key in ROOT file
841    * @param option      options, see TObject::Write
842    * @return neg. error code if failed
843    *         - -ENOSPC    no space left
844    */
845   int Write(AliHLTMemoryFile* pFile, const TObject* pObject, const char* key=NULL, int option=TObject::kOverwrite);
846
847   /**
848    * Close object memory file.
849    * @param pFile       file handle
850    * @return neg. error code if failed
851    *         - -ENOSPC    buffer size too small
852    */
853   int CloseMemoryFile(AliHLTMemoryFile* pFile);
854
855   /**
856    * Insert event-done data information into the output.
857    * @param edd          event-done data information
858    */
859   int CreateEventDoneData(AliHLTComponentEventDoneData edd);
860
861   /**
862    * Get current run number
863    */
864   AliHLTUInt32_t GetRunNo() const;
865
866   /**
867    * Get the current run type.
868    */
869   AliHLTUInt32_t GetRunType() const;
870
871   /**
872    * Copy a struct from block data.
873    * The function checks for block size and struct size. The least common
874    * size will be copied to the target struct, remaining fields are initialized
875    * to zero.<br>
876    * The target struct must have a 32bit struct size indicator as first member.
877    * @param pStruct     target struct
878    * @param iStructSize size of the struct
879    * @param iBlockNo    index of input block
880    * @param structname  name of the struct (log messages)
881    * @param eventname   name of the event (log messages)
882    * @return size copied, neg. error if failed
883    */
884   int CopyStruct(void* pStruct, int iStructSize, int iBlockNo,
885                  const char* structname="", const char* eventname="");
886
887  private:
888   /** not a valid copy constructor, defined according to effective C++ style */
889   AliHLTComponent(const AliHLTComponent&);
890   /** not a valid assignment op, but defined according to effective C++ style */
891   AliHLTComponent& operator=(const AliHLTComponent&);
892
893   /**
894    * Increment the internal event counter.
895    * To be used by the friend classes AliHLTProcessor, AliHLTDataSource
896    * and AliHLTDataSink.
897    * @return new value of the internal event counter
898    * @internal
899    */
900   int IncrementEventCounter();
901
902   /**
903    * Find the first input block of specified data type beginning at index.
904    * Input blocks containing a TObject have the size of the object as an
905    * unsigned 32 bit number in the first 4 bytes. This has to match the block
906    * size minus 4.
907    * @param dt          data type
908    * @param startIdx    index to start the search
909    * @param bObject     check if this is an object
910    * @return index of the block, -ENOENT if no block found
911    *
912    * @internal
913    */
914   int FindInputBlock(const AliHLTComponentDataType& dt, int startIdx=-1, int bObject=0) const;
915
916   /**
917    * Get index in the array of input bocks.
918    * Calculate index and check integrety of a block data structure pointer.
919    * @param pBlock      pointer to block data
920    * @return index of the block, -ENOENT if no block found
921    *
922    * @internal
923    */
924   int FindInputBlock(const AliHLTComponentBlockData* pBlock) const;
925
926   /**
927    * Create an object from a specified input block.
928    * @param idx         index of the input block
929    * @param bForce      force the retrieval of an object, error messages
930    *                    are suppressed if \em bForce is not set
931    * @return pointer to TObject, caller must delete the object after use
932    *
933    * @internal
934    */
935   TObject* CreateInputObject(int idx, int bForce=0);
936
937   /**
938    * Get input object
939    * Get object from the input block list. The methods first checks whether the
940    * object was already created. If not, it is created by @ref CreateInputObject
941    * and inserted into the list of objects.
942    * @param idx         index in the input block list
943    * @param classname   name of the class, object is checked for correct class
944    *                    name if set
945    * @param bForce      force the retrieval of an object, error messages
946    *                    are suppressed if \em bForce is not set
947    * @return pointer to TObject
948    *
949    * @internal
950    */
951   TObject* GetInputObject(int idx, const char* classname=NULL, int bForce=0);
952
953   /**
954    * Clean the list of input objects.
955    * Cleanup is done at the end of each event processing.
956    */
957   int CleanupInputObjects();
958
959   /**
960    * Insert a buffer into the output block stream.
961    * This is the only method to insert blocks into the output stream, called
962    * from all types of the Pushback method. The actual data might have been
963    * written to the output buffer already. In that case NULL can be provided
964    * as buffer, only the block descriptor will be build. If a header is specified, 
965    * it will be inserted before the buffer, default is no header.
966    * @param pBuffer     pointer to buffer
967    * @param iBufferSize size of the buffer in byte
968    * @param dt          data type
969    * @param spec        data specification
970    * @param pHeader     pointer to header
971    * @param iHeaderSize size of Header
972    * @return neg. error code if failed
973    */
974   int InsertOutputBlock(void* pBuffer, int iBufferSize,
975                         const AliHLTComponentDataType& dt,
976                         AliHLTUInt32_t spec,
977                         void* pHeader=NULL, int iHeaderSize=0);
978
979   /** The global component handler instance */
980   static AliHLTComponentHandler* fgpComponentHandler;              //! transient
981
982   /** The environment where the component is running in */
983   AliHLTComponentEnvironment fEnvironment;                         // see above
984
985   /** Set by ProcessEvent before the processing starts */
986   AliHLTEventID_t fCurrentEvent;                                   // see above
987
988   /** internal event no */
989   int fEventCount;                                                 // see above
990
991   /** the number of failed events */
992   int fFailedEvents;                                               // see above
993
994   /** event data struct of the current event under processing */
995   AliHLTComponentEventData fCurrentEventData;                      // see above
996
997   /** array of input data blocks of the current event */
998   const AliHLTComponentBlockData* fpInputBlocks;                   //! transient
999
1000   /** index of the current input block */
1001   int fCurrentInputBlock;                                          // see above
1002
1003   /** data type of the last block search */
1004   AliHLTComponentDataType fSearchDataType;                         // see above
1005
1006   /** name of the class for the object to search for */
1007   string fClassName;                                               // see above
1008
1009   /** array of generated input objects */
1010   TObjArray* fpInputObjects;                                       //! transient
1011  
1012   /** the output buffer */
1013   AliHLTUInt8_t* fpOutputBuffer;                                   //! transient
1014
1015   /** size of the output buffer */
1016   AliHLTUInt32_t fOutputBufferSize;                                // see above
1017
1018   /** size of data written to output buffer */
1019   AliHLTUInt32_t fOutputBufferFilled;                              // see above
1020
1021   /** list of ouput block data descriptors */
1022   vector<AliHLTComponentBlockData> fOutputBlocks;                  // see above
1023
1024   /** stopwatch array */
1025   TObjArray* fpStopwatches;                                        //! transient
1026
1027   /** array of memory files AliHLTMemoryFile */
1028   vector<AliHLTMemoryFile*> fMemFiles;                             //! transient
1029
1030   /** descriptor of the current run */
1031   AliHLTRunDesc* fpRunDesc;                                        //! transient
1032
1033   /** the current DDL list */
1034   AliHLTEventDDL* fpDDLList;                                       //! transient
1035
1036   ClassDef(AliHLTComponent, 3)
1037 };
1038 #endif