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