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