4 #ifndef ALIHLTCOMPONENT_H
5 #define ALIHLTCOMPONENT_H
6 //* This file is property of and copyright by the ALICE HLT Project *
7 //* ALICE Experiment at CERN, All rights reserved. *
8 //* See cxx source for full Copyright notice *
10 // @file AliHLTComponent.h
11 // @author Matthias Richter, Timm Steinbeck
13 // @brief Base class declaration for HLT components.
14 // @note The class is both used in Online (PubSub) and Offline (AliRoot)
19 * @defgroup alihlt_component Component handling of the HLT module
20 * This section describes the the component base classes and handling for
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.
29 * @section alihlt_component_implementation Component implementation
30 * AliHLTComponent provides the interface for all components, see there
31 * for details. Three types are provided:
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.
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.
51 * In both cases, the library must be loaded via the method
53 * AliHLTComponentHandler::LoadComponentLibraries()
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
64 #include "AliHLTLogging.h"
65 #include "AliHLTDataTypes.h"
66 #include "AliHLTCommonCDBEntries.h"
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
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;
81 class AliHLTComponentHandler;
86 class AliRawDataHeader;
87 class AliHLTComponent;
88 class AliHLTMemoryFile;
90 class AliHLTReadoutList;
92 /** list of component data type structures */
93 typedef vector<AliHLTComponentDataType> AliHLTComponentDataTypeList;
94 /** list of component block data structures */
95 typedef vector<AliHLTComponentBlockData> AliHLTComponentBlockDataList;
96 /** list of component statistics struct */
97 typedef vector<AliHLTComponentStatistics> AliHLTComponentStatisticsList;
98 /** list of component pointers */
99 typedef vector<AliHLTComponent*> AliHLTComponentPList;
100 /** list of memory file pointers */
101 typedef vector<AliHLTMemoryFile*> AliHLTMemoryFilePList;
104 * @class AliHLTComponent
105 * Base class of HLT data processing components.
106 * The class provides a common interface for HLT data processing components.
107 * The interface can be accessed from the online HLT framework or the AliRoot
108 * offline analysis framework.
109 * @section alihltcomponent-properties Component identification and properties
110 * Each component must provide a unique ID, input and output data type indications,
111 * and a spawn function.
112 * @subsection alihltcomponent-req-methods Required property methods
113 * - @ref GetComponentID
114 * - @ref GetInputDataTypes (see @ref alihltcomponent-type for default
116 * - @ref GetOutputDataType (see @ref alihltcomponent-type for default
118 * - @ref GetOutputDataSize (see @ref alihltcomponent-type for default
122 * @subsection alihltcomponent-opt-mehods Optional handlers
125 * - @ref GetOutputDataTypes
126 * If the component has multiple output data types @ref GetOutputDataType
127 * should return @ref kAliHLTMultipleDataType. The framework will invoke
128 * @ref GetOutputDataTypes, a list can be filled.
130 * This function is invoked by the framework on a special event which
131 * triggers the reconfiguration of the component.
133 * @subsection alihltcomponent-processing-mehods Data processing
136 * @subsection alihltcomponent-type Component type
137 * Components can be of type
138 * - @ref kSource components which only produce data
139 * - @ref kProcessor components which consume and produce data
140 * - @ref kSink components which only consume data
142 * where data production and consumption refer to the analysis data stream. In
143 * order to indicate the type, a child component can overload the
144 * @ref GetComponentType function.
145 * @subsubsection alihltcomponent-type-std Standard implementations
146 * Components in general do not need to implement this function, standard
147 * implementations of the 3 types are available:
148 * - AliHLTDataSource for components of type @ref kSource <br>
149 * All types of data sources can inherit from AliHLTDataSource and must
150 * implement the @ref AliHLTDataSource::GetEvent method. The class
151 * also implements a standard method for @ref GetInputDataTypes.
153 * - AliHLTProcessor for components of type @ref kProcessor <br>
154 * All types of data processors can inherit from AliHLTProcessor and must
155 * implement the @ref AliHLTProcessor::DoEvent method.
157 * - AliHLTDataSink for components of type @ref kSink <br>
158 * All types of data processors can inherit from AliHLTDataSink and must
159 * implement the @ref AliHLTDataSink::DumpEvent method. The class
160 * also implements a standard method for @ref GetOutputDataType and @ref
163 * @subsection alihltcomponent-environment Running environment
165 * In order to adapt to different environments (on-line/off-line), the component
166 * gets an environment structure with function pointers. The base class provides
167 * member functions for those environment dependend functions. The member
168 * functions are used by the component implementation and are re-mapped to the
169 * corresponding functions.
171 * @section alihltcomponent-interfaces Component interfaces
172 * Each of the 3 standard component base classes AliHLTProcessor, AliHLTDataSource
173 * and AliHLTDataSink provides it's own processing method (see
174 * @ref alihltcomponent-type-std), which splits into a high and a low-level
175 * method. For the @ref alihltcomponent-low-level-interface, all parameters are
176 * shipped as function arguments, the component is supposed to write data to the
177 * output buffer and handle all block descriptors.
178 * The @ref alihltcomponent-high-level-interface is the standard processing
179 * method and will be used whenever the low-level method is not overloaded.
181 * In both cases it is necessary to calculate/estimate the size of the output
182 * buffer before the processing. Output buffers can never be allocated inside
183 * the component because of the push-architecture of the HLT.
184 * For that reason the @ref GetOutputDataSize function should return a rough
185 * estimatian of the data to be produced by the component. The component is
186 * responsible for checking the memory size and must return -ENOSPC if the
187 * available buffer is too small, and update the estimator respectively. The
188 * framework will allocate a buffer of appropriate size and call the processing
191 * @subsection alihltcomponent-error-codes Return values/Error codes
192 * For return codes, the following scheme applies:
193 * - The data processing methods have to indicate error conditions by a negative
194 * error/return code. Preferably the system error codes are used like
195 * e.g. -EINVAL. This requires to include the header
197 * \#include \<cerrno\>
199 * This schema aplies to all interface functions of the component base class.
200 * For data processing it is as follows:
201 * - If no suitable input block could be found (e.g. no clusters for the TPC cluster
202 * finder) set size to 0, block list is empty, return 0
203 * - If no ususable or significant signal could be found in the input blocks
204 * return an empty output block, set size accordingly, and return 0. An empty output
205 * block here could be either a real empty one of size 0 (in which case size also
206 * would have to be set to zero) or a block filled with just the minimum necessary
207 * accounting/meta-structures. E.g. in the TPC
209 * @subsection alihltcomponent-high-level-interface High-level interface
210 * The high-level component interface provides functionality to exchange ROOT
211 * structures between components. In contrast to the
212 * @ref alihltcomponent-low-level-interface, a couple of functions can be used
213 * to access data blocks of the input stream
214 * and send data blocks or ROOT TObject's to the output stream. The functionality
215 * is hidden from the user and is implemented by using ROOT's TMessage class.
217 * @subsubsection alihltcomponent-high-level-int-methods Interface methods
218 * The interface provides a couple of methods in order to get objects from the
219 * input, data blocks (non TObject) from the input, and to push back objects and
220 * data blocks to the output. For convenience there are several functions of
221 * identical name (and similar behavior) with different parameters defined.
222 * Please refer to the function documentation.
223 * - @ref GetNumberOfInputBlocks <br>
224 * return the number of data blocks in the input stream
225 * - @ref GetFirstInputObject <br>
226 * get the first object of a specific data type
227 * - @ref GetNextInputObject <br>
228 * get the next object of same data type as last GetFirstInputObject/Block call
229 * - @ref GetFirstInputBlock <br>
230 * get the first block of a specific data type
231 * - @ref GetNextInputBlock <br>
232 * get the next block of same data type as last GetFirstInputBlock/Block call
233 * - @ref PushBack <br>
234 * insert an object or data buffer into the output
235 * - @ref CreateEventDoneData <br>
236 * add event information to the output
238 * In addition, the processing methods are simplified a bit by cutting out most of
241 * - @ref AliHLTProcessor::DoEvent
242 * - @ref AliHLTDataSource::GetEvent
243 * - @ref AliHLTDataSink::DumpEvent
245 * \em IMPORTANT: objects and block descriptors provided by the high-level interface
246 * <b>MUST NOT BE DELETED</b> by the caller.
248 * @subsubsection alihltcomponent-high-level-int-guidelines High-level interface guidelines
249 * - Structures must inherit from the ROOT object base class TObject in order be
250 * transported by the transportation framework.
251 * - all pointer members must be transient (marked <tt>//!</tt> behind the member
252 * definition), i.e. will not be stored/transported, or properly marked
253 * (<tt>//-></tt>) in order to call the streamer of the object the member is pointing
254 * to. The latter is not recomended. Structures to be transported between components
255 * should be streamlined.
256 * - no use of stl vectors/strings, use appropriate ROOT classes instead
258 * @subsection alihltcomponent-low-level-interface Low-level interface
259 * The low-level component interface consists of the specific data processing
260 * methods for @ref AliHLTProcessor, @ref AliHLTDataSource, and @ref AliHLTDataSink.
261 * - @ref AliHLTProcessor::DoEvent
262 * - @ref AliHLTDataSource::GetEvent
263 * - @ref AliHLTDataSink::DumpEvent
265 * The base class passes all relevant parameters for data access directly on to the
266 * component. Input blocks can be accessed by means of the array <tt> blocks </tt>.
267 * Output data are written directly to shared memory provided by the pointer
268 * <tt> outputPtr </tt> and output block descriptors are inserted directly to the
269 * list <tt> outputBlocks </tt>.
271 * \b NOTE: The high-level input data access methods can be used also from the low
272 * level interface. Also the PushBack functions can be used BUT ONLY if no data is
273 * written to the output buffer and no data block descriptors are inserted into the
276 * @section alihltcomponent-initialization Component initialization and configuration
277 * The component interface provides two optional methods for component initialization
278 * and configuration. The @ref DoInit function is called once before the processing.
279 * During the event processing, a special event can trigger a reconfiguration and the
280 * @ref Reconfigure method is called. There are three possible options of initialization
282 * - default values: set directly in the source code
283 * - OCDB objects: all necessary information must be loaded from OCDB objects. The
284 * Offline Conditions Data Base stores objects specifically valid for individual runs
286 * - Component arguments: can be specified for every component in the chain
287 * configuration. The arguments can be used to override specific parameters of the
290 * As a general rule, the three options should be processed in that sequence, i.e
291 * default parameters might be overridden by OCDB configuration, and the latter one
292 * by component arguments.
294 * @subsection alihltcomponent-initialization-arguments Component arguments
295 * In normal operation, components are supposed to run without any additional argument,
296 * however such arguments can be useful for testing and debugging. The idea follows
297 * the format of command line arguments. A keyword is indicated by a dash and an
298 * optional argument might follow, e.g.:
300 * -argument1 0.5 -argument2
302 * In this case argument1 requires an additional parameter whereas argument2 does not.
303 * The arguments will be provided as an array of separated arguments.
305 * Component arguments can be classified into initialization arguments and configuration
306 * arguments. The latter are applicable for both the @ref DoInit and @ref Reconfigure
307 * method whereas initialization arguments are not applicable after DoInit.
309 * @subsection alihltcomponent-initialization-ocdb OCDB objects
310 * OCDB objects are ROOT <tt>TObjects</tt> and can be of any type. This is in particular
311 * useful for complex parameter sets. However in most cases, a simple approach of human
312 * readable command line arguments is appropriate. Such a string can be simply stored
313 * in a TObjString (take note that the TString does not derive from TObject). The
314 * same arguments as for the command line can be used. Take note that in the TObjString
315 * all arguments are separated by blanks, instead of being in an array of separate
318 * The base class provides two functions regarding OCDB objects:
319 * - LoadAndExtractOCDBObject() loads the OCDB entry for the specified path and extracts
320 * the TObject from it. An optional key allows to access
321 * a TObject within a TMap
322 * - ConfigureFromCDBTObjString() can load a number of OCDB objects and calls the
323 * argument parsing ConfigureFromArgumentString
326 * @subsection alihltcomponent-initialization-sequence Initialization sequence
327 * Using the approach of <tt>TObjString</tt>-type configuration objects allows to treat
328 * configuration from both @ref DoInit and @ref Reconfigure in the same way.
330 * The base class provides the function ConfigureFromArgumentString() which loops over
331 * all arguments and calls the child's method ScanConfigurationArgument(). Here the
332 * actual treatment of the argument and its parameters needs to be implemented.
333 * ConfigureFromArgumentString() can treat both arrays of arguments and arguments in
334 * one single string separated by blanks. The two options can be mixed.
336 * A second base class function ConfigureFromCDBTObjString() allows to configure
337 * directly from a number of OCDB objects. This requires the entries to be of
338 * type TObjString and the child implementation of ScanConfigurationArgument().
339 * The object can also be of type TMap with TObjStrings as key-value pairs. The
340 * key identifier can be chosen by the component implementation. Normally it will
341 * be the run type ("p","A-A", "p-A", ...) or e.g. the trigger code secified by
344 * @section alihltcomponent-handling Component handling
345 * The handling of HLT analysis components is carried out by the AliHLTComponentHandler.
346 * Component are registered automatically at load-time of the component shared library
347 * under the following suppositions:
348 * - the component library has to be loaded from the AliHLTComponentHandler using the
349 * @ref AliHLTComponentHandler::LoadLibrary method.
350 * - the library defines an AliHLTModuleAgent which registers all components.
351 * See AliHLTModuleAgent::RegisterComponents <br>
353 * - the component implementation defines one global object (which is generated
354 * when the library is loaded) <br>
356 * @subsection alihltcomponent-design-rules General design considerations
357 * The analysis code should be implemented in one or more destict class(es). A
358 * \em component should be implemented which interface the destict analysis code to the
359 * component interface. This component generates the analysis object dynamically. <br>
361 * Assume you have an implemetation <tt> AliHLTDetMyAnalysis </tt>, another class <tt>
362 * AliHLTDetMyAnalysisComponent </tt> contains:
365 * AliHLTDetMyAnalysis* fMyAnalysis; //!
367 * The object should then be instantiated in the DoInit handler of
368 * <tt>AliHLTDetMyAnalysisComponent </tt>, and cleaned in the DoDeinit handler.
371 * - avoid big static arrays in the component, allocate the memory at runtime
372 * - allocate all kind of complex data members (like classes, ROOT TObjects of
373 * any kind) dynamically in DoInit and clean up in DoDeinit
375 * @section alihlt_component_arguments Default arguments
376 * The component base class provides some default arguments:
377 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
378 * \li -loglevel=level <br>
379 * \li -object-compression=level <br>
380 * compression level for ROOT objects, default is defined by
381 * @ref ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION
382 * \li -pushback-period=period <br>
383 * scale down for PushBack of objects, shipped only for one event
384 * every <i>period</i> seconds
386 * @ingroup alihlt_component
387 * @section alihltcomponent-members Class members
389 class AliHLTComponent : public AliHLTLogging {
391 /** standard constructor */
393 /** standard destructor */
394 virtual ~AliHLTComponent();
396 /** component type definitions */
397 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
400 * Init function to prepare data processing.
401 * Initialization of common data structures for a sequence of events.
402 * The call is redirected to the internal method DoInit which can be
403 * overridden by the child class.
404 * During Init also the environment structure is passed to the component.
405 * @param comenv environment pointer with environment dependent function
407 * @param environParam additional parameter for function calls, the pointer
409 * @param argc size of the argument array
410 * @param argv augment array for component initialization
412 virtual int Init( const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv );
415 * Clean-up function to terminate data processing.
416 * Clean-up of common data structures after data processing.
417 * The call is redirected to the internal method @ref DoDeinit which can be
418 * overridden by the child class.
420 virtual int Deinit();
423 * Processing of one event.
424 * The method is the entrance of the event processing. The parameters are
425 * cached for uses with the high-level interface and the DoProcessing
426 * implementation is called.
433 * @param outputBlockCnt out: size of the output block array, set by the component
434 * @param outputBlocks out: the output block array is allocated internally
436 * @return neg. error code if failed
438 int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
439 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
440 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
441 AliHLTComponentBlockData*& outputBlocks,
442 AliHLTComponentEventDoneData*& edd );
445 * Internal processing of one event.
446 * The method is pure virtual and implemented by the child classes
447 * - @ref AliHLTProcessor
448 * - @ref AliHLTDataSource
449 * - @ref AliHLTDataSink
456 * @param outputBlocks out: the output block array is allocated internally
458 * @return neg. error code if failed
460 virtual int DoProcessing( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
461 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
462 AliHLTUInt32_t& size,
463 AliHLTComponentBlockDataList& outputBlocks,
464 AliHLTComponentEventDoneData*& edd ) = 0;
468 * The function must not be called when running in AliRoot unless it it
469 * really wanted. The CDB path will be set to the specified path, which might
470 * override the path initialized at the beginning of the AliRoot reconstruction.
472 * The method is used from the external interface in order to set the correct
473 * path when running on-line. The function also initializes the function
474 * callback for setting the run no during operation.
476 * A separation of library and component handling is maybe appropriate in the
477 * future. Using the global component handler here is maybe not the cleanest
479 * @param cdbPath path of the CDB
480 * @param pHandler the component handler used for llibrary handling.
482 int InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler);
485 * Set the run no for the CDB.
486 * The function must not be called when running in AliRoot unless it it
487 * really wanted. The CDB path will be set to the specified path, which might
488 * override the run no initialized at the beginning of the AliRoot reconstruction.
489 * InitCDB() has to be called before in order to really change the CDB settings.
491 * The method is used from the external interface in order to set the correct
492 * path when running on-line.
494 int SetCDBRunNo(int runNo);
497 * Set the run description.
498 * The run description is set before the call of Init() -> DoInit().
499 * @note: This functionality has been added in Juli 2008. The transmission of
500 * run properties by a special SOR (SOD event in DAQ terminalogy but this was
501 * changed after the HLT interface was designed) event is not sufficient because
502 * the data might be needed already in the DoInit handler of the component.
503 * @param desc run descriptor, currently only the run no member is used
504 * @param runType originally, run type was supposed to be a number and part
505 * of the run descriptor. But it was defined as string later
507 int SetRunDescription(const AliHLTRunDesc* desc, const char* runType);
510 * Set the component description.
511 * The description string can contain tokens separated by blanks, a token
512 * consists of a key and an optional value separated by '='.
514 * \li -chainid=id string id within the chain of the instance
516 * @param desc component description
518 int SetComponentDescription(const char* desc);
521 * Set the running environment for the component.
522 * Originally, the environment was set in the Init function. However, the setup of
523 * the CDB is required before. In order to have proper logging functionality, the
524 * environment is required.
525 * @param comenv environment pointer with environment dependent function
527 * @param environParam additional parameter for function calls, the pointer
530 int SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam);
532 // Information member functions for registration.
535 * Get the type of the component.
536 * The function is pure virtual and must be implemented by the child class.
537 * @return component type id
539 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
542 * Get the id of the component.
543 * Each component is identified by a unique id.
544 * The function is pure virtual and must be implemented by the child class.
545 * @return component id (string)
547 virtual const char* GetComponentID() = 0;
550 * Get the input data types of the component.
551 * The function is pure virtual and must be implemented by the child class.
552 * @return list of data types in the vector reference
554 virtual void GetInputDataTypes( AliHLTComponentDataTypeList& ) = 0;
557 * Get the output data type of the component.
558 * The function is pure virtual and must be implemented by the child class.
559 * @return output data type
561 virtual AliHLTComponentDataType GetOutputDataType() = 0;
564 * Get the output data types of the component.
565 * The function can be implemented to indicate multiple output data types
566 * in the target array.
567 * @ref GetOutputDataType must return @ref kAliHLTMultipleDataType in order
568 * to invoke this method.
569 * @param tgtList list to receive the data types
570 * @return no of output data types, data types in the target list
572 virtual int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList);
575 * Get a ratio by how much the data volume is shrunken or enhanced.
576 * The function is pure virtual and must be implemented by the child class.
577 * @param constBase <i>return</i>: additive part, independent of the
579 * @param inputMultiplier <i>return</i>: multiplication ratio
580 * @return values in the reference variables
582 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
585 * Get a list of OCDB object description.
586 * The list of objects is provided in a TMap
587 * - key: complete OCDB path, e.g. GRP/GRP/Data
588 * - value: short description why the object is needed
589 * Key and value objects created inside this class go into ownership of
591 * @param targetMap TMap instance receiving the list
594 virtual void GetOCDBObjectDescription( TMap* const targetArray);
598 * Each component must implement a spawn function to create a new instance of
599 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
600 * @return new class instance
602 virtual AliHLTComponent* Spawn() = 0;
605 * check the availability of the OCDB entry descriptions in the TMap
606 * key : complete OCDB path of the entry
607 * value : auxiliary object - short description
608 * if the external map was not provided the function invokes
609 * interface function GetOCDBObjectDescription() to retrieve the list.
610 * @param externList map of entries to be tested
611 * @result 0 if all found, -ENOENT if objects not found
613 int CheckOCDBEntries(const TMap* const externList=NULL);
616 * Find matching data types between this component and a consumer component.
617 * Currently, a component can produce only one type of data. This restriction is most
618 * likely to be abolished in the future.
619 * @param pConsumer a component and consumer of the data produced by this component
620 * @param tgtList reference to a vector list to receive the matching data types.
621 * @return >= 0 success, neg. error code if failed
623 int FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList);
626 * Set the global component handler.
627 * The static method is needed for the automatic registration of components.
629 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
632 * Clear the global component handler.
633 * The static method is needed for the automatic registration of components.
635 static int UnsetGlobalComponentHandler();
638 * Helper function to convert the data type to a string.
639 * @param type data type structure
640 * @param mode 0 print string origin:type <br>
642 * 2 print numbers <br>
643 * 3 print 'type' 'origin'
645 static string DataType2Text( const AliHLTComponentDataType& type, int mode=0);
648 * Calculate a CRC checksum of a data buffer.
649 * Polynomial for the calculation is 0xD8.
651 static AliHLTUInt32_t CalculateChecksum(const AliHLTUInt8_t* buffer, int size);
654 * Helper function to print content of data type.
656 static void PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format=NULL);
659 * helper function to initialize AliHLTComponentEventData structure
661 static void FillEventData(AliHLTComponentEventData& evtData);
664 * Print info on an AliHLTComponentDataType structure
665 * This is just a helper function to examine an @ref AliHLTComponentDataType
668 static void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
671 * Fill AliHLTComponentBlockData structure with default values.
672 * @param blockData reference to data structure
674 static void FillBlockData( AliHLTComponentBlockData& blockData );
677 * Fill AliHLTComponentShmData structure with default values.
678 * @param shmData reference to data structure
680 static void FillShmData( AliHLTComponentShmData& shmData );
683 * Fill AliHLTComponentDataType structure with default values.
684 * @param dataType reference to data structure
686 static void FillDataType( AliHLTComponentDataType& dataType );
689 * Copy data type structure
690 * Copies the value an AliHLTComponentDataType structure to another one
691 * @param[out] tgtdt target structure
692 * @param[in] srcdt source structure
694 static void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
697 * Set the ID and Origin of an AliHLTComponentDataType structure.
698 * The function sets the fStructureSize member and copies the strings
699 * to the ID and Origin. Only characters from the valid part of the string
700 * are copied, the rest is filled with 0's. <br>
701 * Please note that the fID and fOrigin members are not strings, just arrays of
702 * chars of size @ref kAliHLTComponentDataTypefIDsize and
703 * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
704 * a terminating zero. <br>
705 * It is possible to pass NULL pointers as id or origin argument, in that case they
707 * @param tgtdt target data type structure
708 * @param id ID string
709 * @param origin Origin string
711 static void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
714 * Set the ID and Origin of an AliHLTComponentDataType structure.
715 * Given the fact that the data type ID is 64bit wide and origin 32, this helper
716 * function sets the data type from those two parameters.
717 * @param dt target data type structure
719 * @param orig 32bit origin
721 static void SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t orig);
724 * Extract a component table entry from the payload buffer.
725 * The entry consists of the AliHLTComponentTableEntry structure, the array of
726 * parents and a description string of the format 'chain-id{component-id:component-args}'.
727 * The function fills all the variables after a consistency check.
729 static int ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
730 string& chainId, string& compId, string& compParam,
731 vector<AliHLTUInt32_t>& parents);
734 * Extracts the different data parts from the trigger data structure.
735 * [in] @param trigData The trigger data as passed to the DoProcessing method.
736 * [out] @param attributes The data block attributes given by the HLT framework.
737 * [out] @param status The HLT status bits given by the HLT framework.
738 * [out] @param cdh The common data header received from DDL links.
739 * [out] @param readoutlist The readout list to fill with readout list bits
740 * passed on by the HLT framework.
741 * [in] @param printErrors If true then error messages are generated as necessary
742 * and suppressed otherwise.
743 * @note If any of the output parameters are set to NULL then the field is not set.
744 * For example, the following line will only fill the CDH pointer.
746 * AliRawDataHeader* cdh;
747 * ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL);
749 * @return the zero on success and one of the following error codes on failure.
750 * if a non-zero error code is returned then none of the output parameters are
752 * \li -ENOENT The <i>trigData</i> structure size is wrong.
753 * \li -EBADF The <i>trigData</i> data size is wrong.
754 * \li -EBADMSG The common data header (CDH) in the trigger data has the wrong
755 * number of words indicated.
756 * \li -EPROTO The readout list structure in the trigger data has the wrong
757 * number of words indicated.
759 static int ExtractTriggerData(
760 const AliHLTComponentTriggerData& trigData,
761 const AliHLTUInt8_t (**attributes)[gkAliHLTBlockDAttributeCount],
762 AliHLTUInt64_t* status,
763 const AliRawDataHeader** cdh,
764 AliHLTReadoutList* readoutlist,
765 bool printErrors = false
769 * Extracts the readout list from a trigger data structure.
770 * [in] @param trigData The trigger data as passed to the DoProcessing method.
771 * [out] @param list The output readout list to fill.
772 * [in] @param printErrors If true then error messages are generated as necessary
773 * and suppressed otherwise.
774 * @return the zero on success or one of the error codes returned by ExtractTriggerData.
776 static int GetReadoutList(
777 const AliHLTComponentTriggerData& trigData, AliHLTReadoutList& list,
778 bool printErrors = false
781 return ExtractTriggerData(trigData, NULL, NULL, NULL, &list, printErrors);
785 * Stopwatch type for benchmarking.
787 enum AliHLTStopwatchType {
788 /** total time for event processing */
790 /** detector algorithm w/o interface callbacks */
796 /** number of types */
801 * Helper class for starting and stopping a stopwatch.
802 * The guard can be used by instantiating an object in a function. The
803 * specified stopwatch is started and the previous stopwatch put on
804 * hold. When the function is terminated, the object is deleted automatically
805 * deleted, stopping the stopwatch and starting the one on hold.<br>
806 * \em IMPORTANT: never create dynamic objects from this guard as this violates
807 * the idea of a guard.
809 class AliHLTStopwatchGuard {
811 /** standard constructor (not for use) */
812 AliHLTStopwatchGuard();
814 AliHLTStopwatchGuard(TStopwatch* pStart);
815 /** copy constructor (not for use) */
816 AliHLTStopwatchGuard(const AliHLTStopwatchGuard&);
817 /** assignment operator (not for use) */
818 AliHLTStopwatchGuard& operator=(const AliHLTStopwatchGuard&);
820 ~AliHLTStopwatchGuard();
824 * Hold the previous guard for the existence of this guard.
825 * Checks whether this guard controls a new stopwatch. In that case, the
826 * previous guard and its stopwatch are put on hold.
827 * @param pSucc instance of the stopwatch of the new guard
828 * @return 1 if pSucc is a different stopwatch which should
830 * 0 if it controls the same stopwatch
832 int Hold(const TStopwatch* pSucc);
835 * Resume the previous guard.
836 * Checks whether the peceeding guard controls a different stopwatch. In that
837 * case, the its stopwatch is resumed.
838 * @param pSucc instance of the stopwatch of the new guard
839 * @return 1 if pSucc is a different stopwatch which should
841 * 0 if it controls the same stopwatch
843 int Resume(const TStopwatch* pSucc);
845 /** the stopwatch controlled by this guard */
846 TStopwatch* fpStopwatch; //!transient
848 /** previous stopwatch guard, put on hold during existence of the guard */
849 AliHLTStopwatchGuard* fpPrec; //!transient
851 /** active stopwatch guard */
852 static AliHLTStopwatchGuard* fgpCurrent; //!transient
856 * Set a stopwatch for a given purpose.
857 * @param pSW stopwatch object
858 * @param type type of the stopwatch
860 int SetStopwatch(TObject* pSW, AliHLTStopwatchType type=kSWBase);
863 * Init a set of stopwatches.
864 * @param pStopwatches object array of stopwatches
866 int SetStopwatches(TObjArray* pStopwatches);
869 * Customized logging function.
870 * The chain id, component id and pointer is added at the beginning of each message.
872 int LoggingVarargs(AliHLTComponentLogSeverity severity,
873 const char* originClass, const char* originFunc,
874 const char* file, int line, ... ) const;
877 * Get size of last serialized object.
878 * During PushBack, TObjects are serialized in a separate buffer. The
879 * size of the last object can be retrieved by this function.
881 * This might be especially useful for PushBack failures caused by too
882 * small output buffer.
884 int GetLastObjectSize() const {return fLastObjectSize;}
887 * This method generates a V4 Globally Unique Identifier (GUID) using the
888 * ROOT TRandom3 pseudo-random number generator with the process' UID, GID
889 * PID and host address as seeds. For good measure MD5 sum hashing is also
891 * @return the newly generated GUID structure.
893 static TUUID GenerateGUID();
898 * Default method for the internal initialization.
899 * The method is called by @ref Init
901 virtual int DoInit( int argc, const char** argv );
904 * Default method for the internal clean-up.
905 * The method is called by @ref Deinit
907 virtual int DoDeinit();
910 * Reconfigure the component.
911 * The method is called when an event of type @ref kAliHLTDataTypeComConf
912 * {COM_CONF:PRIV} is received by the component. If the event is sent as
913 * part of a normal event, the component configuration is called first.
915 * The CDB path parameter specifies the path in the CDB, i.e. without
916 * leading absolute path of the CDB location. The framework might also
917 * provide the id of the component in the analysis chain.
919 * The actual sequence of configuration depends on the component. As a
920 * general rule, the component should load the specific OCDB object if
921 * provided as parameter, and load the default objects if the parameter
922 * is NULL. However, other schemes are possible. See @ref
924 * \b Note: The CDB will be initialized by the framework, either already set
925 * from AliRoot or from the wrapper interface during initialization.
927 * @param cdbEntry path of the cdbEntry
928 * @param chainId the id/name of the component in the current analysis
929 * chain. This is not necessarily the same as what is
930 * returned by the GetComponentID() method.
931 * @note both parameters can be NULL, check before usage
933 virtual int Reconfigure(const char* cdbEntry, const char* chainId);
936 * Read the Preprocessor values.
937 * The function is invoked when the component is notified about available/
938 * updated data points from the detector Preprocessors. The 'modules'
939 * argument contains all detectors for which the Preprocessors have
940 * updated data points. The component has to implement the CDB access to
941 * get the desired data points.
942 * @param modules detectors for which the Preprocessors have updated
943 * data points: TPC, TRD, ITS, PHOS, MUON, or ALL if
944 * no argument was received.
945 * @return neg. error code if failed
947 virtual int ReadPreprocessorValues(const char* modules);
950 * Child implementation to scan a number of configuration arguments.
951 * The method is invoked by the framework in conjunction with the
952 * common framework functions ConfigureFromArgumentString and
953 * ConfigureFromCDBTObjString.
954 * Function needs to scan the argument and optional additional
955 * parameters and returns the number of elements in the array which
959 * @return number of arguments which have been scanned or neg error
960 * code if failed <br>
961 * \li -EINVAL unknown argument
962 * \li -EPROTO protocol error, e.g. missing parameter
964 virtual int ScanConfigurationArgument(int argc, const char** argv);
967 * Custom handler for the SOR event.
968 * Is invoked from the base class if an SOR event is in the block list.
969 * The handler is called before the processing function. The processing
970 * function is skipped if there are no other data blocks available.
972 * The SOR event is generated by the PubSub framework in response to
973 * the DAQ start of data (SOD - has been renamed after HLT interface
974 * was designed). The SOD event consists of 3 blocks:
975 * - ::kAliHLTDataTypeEvent block: spec ::gkAliEventTypeStartOfRun
976 * - SOD block of type ::kAliHLTDataTypeSOR, payload: AliHLTRunDesc struct
977 * - run type block ::kAliHLTDataTypeRunType, payload: run type string
979 * Run properties can be retrieved by getters like GetRunNo().
980 * @return neg. error code if failed
982 virtual int StartOfRun();
985 * Custom handler for the EOR event.
986 * Is invoked from the base class if an EOR event is in the block list.
987 * The handler is called before the processing function. The processing
988 * function is skipped if there are no other data blocks available.
990 * See StartOfRun() for more comments of the sequence of steering events.
992 * @return neg. error code if failed
994 virtual int EndOfRun();
997 * Check whether a component requires all steering blocks.
998 * Childs can overload in order to indicate that they want to
999 * receive also the steering data blocks. There is also the
1000 * possibility to add the required data types to the input
1001 * data type list in GetInputDataTypes().
1003 virtual bool RequireSteeringBlocks() const {return false;}
1006 * General memory allocation method.
1007 * All memory which is going to be used 'outside' of the interface must
1008 * be provided by the framework (online or offline).
1009 * The method is redirected to a function provided by the current
1010 * framework. Function pointers are transferred via the @ref
1011 * AliHLTAnalysisEnvironment structure.
1013 void* AllocMemory( unsigned long size );
1016 * Helper function to create a monolithic BlockData description block out
1017 * of a list BlockData descriptors.
1018 * For convenience, inside the interface vector lists are used, to make the
1019 * interface pure C style, monilithic blocks must be exchanged.
1020 * The method is redirected to a function provided by the current
1021 * framework. Function pointers are transferred via the @ref
1022 * AliHLTAnalysisEnvironment structure.
1024 int MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
1025 AliHLTComponentBlockData** outputBlocks );
1028 * Fill the EventDoneData structure.
1029 * The method is redirected to a function provided by the current
1030 * framework. Function pointers are transferred via the @ref
1031 * AliHLTAnalysisEnvironment structure.
1033 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) const;
1036 * Allocate an EventDoneData structure for the current event .
1037 * The method allocates the memory internally and does not interact with the current Framework.
1038 * The allocated data structure is empty initially and can be filled by calls to the
1039 * @ref PushEventDoneData method. The memory will be automatically released after the event has been processed.
1042 int ReserveEventDoneData( unsigned long size );
1045 * Push a 32 bit word of data into event done data for the current event which
1046 * has previously been allocated by the @ref ReserveEventDoneData method.
1048 int PushEventDoneData( AliHLTUInt32_t eddDataWord );
1051 * Release event done data previously reserved by @ref ReserveEventDoneData
1053 void ReleaseEventDoneData();
1056 * Get the pointer to the event done data available/built so far for the current event via
1057 * @ref ReserveEventDoneData and @ref PushEventDoneData
1059 AliHLTComponentEventDoneData* GetCurrentEventDoneData() const
1061 return fEventDoneData;
1065 * Helper function to convert the data type to a string.
1067 void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]) const;
1070 * Loop through a list of component arguments.
1071 * The list can be either an array of separated strings or one single
1072 * string containing blank separated arguments, or both mixed.
1073 * ScanConfigurationArgument() is called to allow the component to treat
1074 * the individual arguments.
1075 * @return neg. error code if failed
1077 int ConfigureFromArgumentString(int argc, const char** argv);
1080 * Read configuration objects from OCDB and configure from
1081 * the content of TObjString entries.
1082 * @param entries blank separated list of OCDB paths
1083 * @param key if the entry is a TMap, search for the corresponding object
1084 * @return neg. error code if failed
1086 int ConfigureFromCDBTObjString(const char* entries, const char* key=NULL);
1089 * Load specified entry from the OCDB and extract the object.
1090 * The entry is explicitely unloaded from the cache before it is loaded.
1091 * If parameter key is specified the OCDB object is treated as TMap
1092 * and the TObject associated with 'key' is loaded.
1093 * @param path path of the entry under to root of the OCDB
1094 * @param version version of the entry
1095 * @param subVersion subversion of the entry
1096 * @param key key of the object within TMap
1098 TObject* LoadAndExtractOCDBObject(const char* path, int version = -1, int subVersion = -1, const char* key=NULL);
1100 TObject* LoadAndExtractOCDBObject(const char* path, const char* key) {
1101 return LoadAndExtractOCDBObject(path, -1, -1, key);
1106 * @return value of the internal event counter
1108 int GetEventCount() const;
1111 * Get the number of input blocks.
1112 * @return number of input blocks
1114 int GetNumberOfInputBlocks() const;
1117 * Get id of the current event
1120 AliHLTEventID_t GetEventId() const;
1123 * Get the first object of a specific data type from the input data.
1124 * The High-level methods provide functionality to transfer ROOT data
1125 * structures which inherit from TObject.
1127 * The method looks for the first ROOT object of type dt in the input stream.
1128 * If also the class name is provided, the object is checked for the right
1129 * class type. The input data block needs a certain structure, namely the
1130 * buffer size as first word. If the cross check fails, the retrieval is
1131 * silently abandoned, unless the \em bForce parameter is set.<br>
1132 * \b Note: THE OBJECT MUST NOT BE DELETED by the caller.
1134 * If called without parameters, the function tries to create objects from
1135 * all available input blocks, also the ones of data type kAliHLTVoidDataType
1136 * which are not matched by kAliHLTAnyDataType.
1138 * @param dt data type of the object
1139 * @param classname class name of the object
1140 * @param bForce force the retrieval of an object, error messages
1141 * are suppressed if \em bForce is not set
1142 * @return pointer to @ref TObject, NULL if no objects of specified type
1145 const TObject* GetFirstInputObject(const AliHLTComponentDataType& dt=kAliHLTAllDataTypes,
1146 const char* classname=NULL,
1150 * Get the first object of a specific data type from the input data.
1151 * The High-level methods provide functionality to transfer ROOT data
1152 * structures which inherit from TObject.
1153 * The method looks for the first ROOT object of type specified by the ID and
1154 * Origin strings in the input stream.
1155 * If also the class name is provided, the object is checked for the right
1156 * class type. The input data block needs a certain structure, namely the
1157 * buffer size as first word. If the cross check fails, the retrieval is
1158 * silently abandoned, unless the \em bForce parameter is set.<br>
1159 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
1160 * @param dtID data type ID of the object
1161 * @param dtOrigin data type origin of the object
1162 * @param classname class name of the object
1163 * @param bForce force the retrieval of an object, error messages
1164 * are suppressed if \em bForce is not set
1165 * @return pointer to @ref TObject, NULL if no objects of specified type
1168 const TObject* GetFirstInputObject(const char* dtID,
1169 const char* dtOrigin,
1170 const char* classname=NULL,
1174 * Get the next object of a specific data type from the input data.
1175 * The High-level methods provide functionality to transfer ROOT data
1176 * structures which inherit from TObject.
1177 * The method looks for the next ROOT object of type and class specified
1178 * to the previous @ref GetFirstInputObject call.<br>
1179 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
1180 * @param bForce force the retrieval of an object, error messages
1181 * are suppressed if \em bForce is not set
1182 * @return pointer to @ref TObject, NULL if no more objects available
1184 const TObject* GetNextInputObject(int bForce=0);
1187 * Get data type of an input block.
1188 * Get data type of the object previously fetched via
1189 * GetFirstInputObject/NextInputObject or the last one if no object
1191 * @param pObject pointer to TObject
1192 * @return data specification, kAliHLTVoidDataSpec if failed
1194 AliHLTComponentDataType GetDataType(const TObject* pObject=NULL);
1197 * Get data specification of an input block.
1198 * Get data specification of the object previously fetched via
1199 * GetFirstInputObject/NextInputObject or the last one if no object
1201 * @param pObject pointer to TObject
1202 * @return data specification, kAliHLTVoidDataSpec if failed
1204 AliHLTUInt32_t GetSpecification(const TObject* pObject=NULL);
1207 * Get the first block of a specific data type from the input data.
1208 * The method looks for the first block of type dt in the input stream.
1209 * It is intended to be used within the high-level interface.<br>
1210 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
1212 * If called without parameters, the function works on all input blocks,
1213 * also the ones of data type kAliHLTVoidDataType which are not matched by
1214 * kAliHLTAnyDataType.
1216 * @param dt data type of the block
1217 * @return pointer to @ref AliHLTComponentBlockData
1219 const AliHLTComponentBlockData* GetFirstInputBlock(const AliHLTComponentDataType& dt=kAliHLTAllDataTypes);
1222 * Get the first block of a specific data type from the input data.
1223 * The method looks for the first block of type specified by the ID and
1224 * Origin strings in the input stream. It is intended
1225 * to be used within the high-level interface.<br>
1226 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
1227 * @param dtID data type ID of the block
1228 * @param dtOrigin data type origin of the block
1229 * @return pointer to @ref AliHLTComponentBlockData
1231 const AliHLTComponentBlockData* GetFirstInputBlock(const char* dtID,
1232 const char* dtOrigin);
1235 * Get input block by index.<br>
1236 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
1237 * @return pointer to AliHLTComponentBlockData, NULL if index out of range
1239 const AliHLTComponentBlockData* GetInputBlock(int index) const;
1242 * Get the next block of a specific data type from the input data.
1243 * The method looks for the next block of type and class specified
1244 * to the previous @ref GetFirstInputBlock call.
1245 * To be used within the high-level interface.<br>
1246 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
1248 const AliHLTComponentBlockData* GetNextInputBlock();
1251 * Get data specification of an input block.
1252 * Get data specification of the input block previously fetched via
1253 * GetFirstInputObject/NextInputObject or the last one if no block
1255 * @param pBlock pointer to input block
1256 * @return data specification, kAliHLTVoidDataSpec if failed
1258 AliHLTUInt32_t GetSpecification(const AliHLTComponentBlockData* pBlock);
1261 * Forward an input object to the output.
1262 * Forward the input block of an object previously fetched via
1263 * GetFirstInputObject/NextInputObject or the last one if no object
1265 * The block descriptor of the input block is forwarded to the
1266 * output block list.
1267 * @param pObject pointer to TObject
1268 * @return neg. error code if failed
1270 int Forward(const TObject* pObject);
1273 * Forward an input block to the output.
1274 * Forward the input block fetched via GetFirstInputObject/
1275 * NextInputBlock or the last one if no block specified.
1276 * The block descriptor of the input block is forwarded to the
1277 * output block list.
1278 * @param pBlock pointer to input block
1279 * @return neg. error code if failed
1281 int Forward(const AliHLTComponentBlockData* pBlock=NULL);
1284 * Insert an object into the output.
1285 * If header is specified, it will be inserted before the root object,
1286 * default is no header.
1287 * The publishing can be downscaled by means of the -pushback-period
1288 * parameter. This is especially useful for histograms which do not
1289 * need to be sent for every event.
1290 * @param pObject pointer to root object
1291 * @param dt data type of the object
1292 * @param spec data specification
1293 * @param pHeader pointer to header
1294 * @param headerSize size of Header
1295 * @return neg. error code if failed
1297 int PushBack(TObject* pObject, const AliHLTComponentDataType& dt,
1298 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1299 void* pHeader=NULL, int headerSize=0);
1302 * Insert an object into the output.
1303 * If header is specified, it will be inserted before the root object,
1304 * default is no header.
1305 * The publishing can be downscaled by means of the -pushback-period
1306 * parameter. This is especially useful for histograms which do not
1307 * need to be sent for every event.
1308 * @param pObject pointer to root object
1309 * @param dtID data type ID of the object
1310 * @param dtOrigin data type origin of the object
1311 * @param spec data specification
1312 * @param pHeader pointer to header
1313 * @param headerSize size of Header
1314 * @return neg. error code if failed
1316 int PushBack(TObject* pObject, const char* dtID, const char* dtOrigin,
1317 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1318 void* pHeader=NULL, int headerSize=0);
1321 * Insert an object into the output.
1322 * @param pBuffer pointer to buffer
1323 * @param iSize size of the buffer
1324 * @param dt data type of the object
1325 * @param spec data specification
1326 * @param pHeader pointer to header
1327 * @param headerSize size of Header
1328 * @return neg. error code if failed
1330 int PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt,
1331 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1332 const void* pHeader=NULL, int headerSize=0);
1335 * Insert an object into the output.
1336 * @param pBuffer pointer to buffer
1337 * @param iSize size of the buffer
1338 * @param dtID data type ID of the object
1339 * @param dtOrigin data type origin of the object
1340 * @param spec data specification
1341 * @param pHeader pointer to header
1342 * @param headerSize size of Header
1343 * @return neg. error code if failed
1345 int PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin,
1346 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1347 const void* pHeader=NULL, int headerSize=0);
1350 * Estimate size of a TObject
1352 * @return buffer size in byte
1354 int EstimateObjectSize(TObject* pObject) const;
1357 * Create a memory file in the output stream.
1358 * This method creates a TFile object which stores all data in
1359 * memory instead of disk. The TFile object is published as binary data.
1360 * The instance can be used like a normal TFile object. The TFile::Close
1361 * or @ref CloseMemoryFile method has to be called in order to flush the
1364 * \b Note: The returned object is deleted by the framework.
1365 * @param capacity total size reserved for the memory file
1366 * @param dtID data type ID of the file
1367 * @param dtOrigin data type origin of the file
1368 * @param spec data specification
1369 * @return file handle, NULL if failed
1371 AliHLTMemoryFile* CreateMemoryFile(int capacity, const char* dtID, const char* dtOrigin,
1372 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
1375 * Create a memory file in the output stream.
1376 * This method creates a TFile object which stores all data in
1377 * memory instead of disk. The TFile object is published as binary data.
1378 * The instance can be used like a normal TFile object. The TFile::Close
1379 * or @ref CloseMemoryFile method has to be called in order to flush the
1382 * \b Note: The returned object is deleted by the framework.
1383 * @param capacity total size reserved for the memory file
1384 * @param dt data type of the file
1385 * @param spec data specification
1386 * @return file handle, NULL if failed
1388 AliHLTMemoryFile* CreateMemoryFile(int capacity,
1389 const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
1390 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
1393 * Create a memory file in the output stream.
1394 * This method creates a TFile object which stores all data in
1395 * memory instead of disk. The TFile object is published as binary data.
1396 * The instance can be used like a normal TFile object. The TFile::Close
1397 * or @ref CloseMemoryFile method has to be called in order to flush the
1400 * \b Note: The returned object is deleted by the framework.
1401 * @param dtID data type ID of the file
1402 * @param dtOrigin data type origin of the file
1403 * @param spec data specification
1404 * @param capacity fraction of the available output buffer size
1405 * @return file handle, NULL if failed
1407 AliHLTMemoryFile* CreateMemoryFile(const char* dtID, const char* dtOrigin,
1408 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1409 float capacity=1.0);
1412 * Create a memory file in the output stream.
1413 * This method creates a TFile object which stores all data in
1414 * memory instead of disk. The TFile object is published as binary data.
1415 * The instance can be used like a normal TFile object. The TFile::Close
1416 * or @ref CloseMemoryFile method has to be called in order to flush the
1419 * \b Note: The returned object is deleted by the framework.
1420 * @param dt data type of the file
1421 * @param spec data specification
1422 * @param capacity fraction of the available output buffer size
1423 * @return file handle, NULL if failed
1425 AliHLTMemoryFile* CreateMemoryFile(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
1426 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1427 float capacity=1.0);
1430 * Write an object to memory file in the output stream.
1431 * @param pFile file handle
1432 * @param pObject pointer to root object
1433 * @param key key in ROOT file
1434 * @param option options, see TObject::Write
1435 * @return neg. error code if failed
1436 * - -ENOSPC no space left
1438 int Write(AliHLTMemoryFile* pFile, const TObject* pObject, const char* key=NULL, int option=TObject::kOverwrite);
1441 * Close object memory file.
1442 * @param pFile file handle
1443 * @return neg. error code if failed
1444 * - -ENOSPC buffer size too small
1446 int CloseMemoryFile(AliHLTMemoryFile* pFile);
1449 * Insert event-done data information into the output.
1450 * @param edd event-done data information
1452 int CreateEventDoneData(AliHLTComponentEventDoneData edd);
1455 * Get current run number
1457 AliHLTUInt32_t GetRunNo() const;
1460 * Get the current run type.
1462 AliHLTUInt32_t GetRunType() const;
1465 * Get the chain id of the component.
1467 const char* GetChainId() const {return fChainId.c_str();}
1470 * Get a timestamp of the current event
1471 * Exact format needs to be documented.
1473 AliHLTUInt32_t GetTimeStamp() const;
1476 * Get the period number.
1477 * Upper 28 bits (36 to 63) of the 64-bit event id
1479 AliHLTUInt32_t GetPeriodNumber() const;
1482 * Get the period number.
1483 * 24 bits, 12 to 35 of the 64-bit event id
1485 AliHLTUInt32_t GetOrbitNumber() const;
1488 * Get the bunch crossing number.
1489 * 12 bits, 0 to 12 of the 64-bit event id
1491 AliHLTUInt16_t GetBunchCrossNumber() const;
1494 * Setup the CTP accounting functionality of the base class.
1495 * The method can be invoked from DoInit() for componenets which want to
1496 * use the CTP functionality of the base class.
1498 * The AliHLTCTPData is initialized with the trigger classes from the ECS
1499 * parameters. The base class automatically increments the counters according
1500 * to the trigger pattern in the CDH before the event processing.
1505 * Get the instance of the CTP data.
1507 const AliHLTCTPData* CTPData() const {return fpCTPData;}
1510 * Check whether a combination of trigger classes is fired.
1511 * The expression can contain trigger class ids and logic operators
1512 * like &&, ||, !, and ^, and may be grouped by parentheses.
1513 * @note the function requires the setup of the CTP handling for the component by
1514 * invoking SetupCTPData() from DoInit()
1515 * @param expression a logic expression of trigger class ids
1516 * @param trigData the trigger data data
1518 bool EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const;
1521 * Check state of a trigger class.
1522 * If the class name is not part of the current trigger setup (i.e. ECS parameter
1523 * does not contain a trigger definition for this class name) the function
1525 * @note the function requires the setup of the CTP handling for the component by
1526 * invoking SetupCTPData() from DoInit()
1527 * @return -1 class name not initialized,
1528 * 0 trigger not active
1531 int CheckCTPTrigger(const char* name) const;
1534 * Get the overall solenoid field.
1538 * Get the solenoid field at point r.
1540 Double_t GetBz(const Double_t *r);
1542 * Get the solenoid field components at point r.
1544 void GetBxByBz(const Double_t r[3], Double_t b[3]);
1547 * Check whether the current event is a valid data event.
1548 * @param pTgt optional pointer to get the event type
1549 * @return true if the current event is a real data event
1551 bool IsDataEvent(AliHLTUInt32_t* pTgt=NULL) const;
1554 * Copy a struct from block data.
1555 * The function checks for block size and struct size. The least common
1556 * size will be copied to the target struct, remaining fields are initialized
1558 * The target struct must have a 32bit struct size indicator as first member.
1559 * @param pStruct target struct
1560 * @param iStructSize size of the struct
1561 * @param iBlockNo index of input block
1562 * @param structname name of the struct (log messages)
1563 * @param eventname name of the event (log messages)
1564 * @return size copied, neg. error if failed
1566 int CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
1567 const char* structname="", const char* eventname="");
1570 /** copy constructor prohibited */
1571 AliHLTComponent(const AliHLTComponent&);
1572 /** assignment operator prohibited */
1573 AliHLTComponent& operator=(const AliHLTComponent&);
1576 * Increment the internal event counter.
1577 * To be used by the friend classes AliHLTProcessor, AliHLTDataSource
1578 * and AliHLTDataSink.
1579 * @return new value of the internal event counter
1582 int IncrementEventCounter();
1585 * Find the first input block of specified data type beginning at index.
1586 * Input blocks containing a TObject have the size of the object as an
1587 * unsigned 32 bit number in the first 4 bytes. This has to match the block
1590 * kAliHLTAllDataTypes is a special data type which includes both
1591 * kAliHLTVoidDataType and kAliHLTAnyDataType.
1593 * @param dt data type
1594 * @param startIdx index to start the search
1595 * @param bObject check if this is an object
1596 * @return index of the block, -ENOENT if no block found
1600 int FindInputBlock(const AliHLTComponentDataType& dt, int startIdx=-1, int bObject=0) const;
1603 * Get index in the array of input bocks.
1604 * Calculate index and check integrety of a block data structure pointer.
1605 * @param pBlock pointer to block data
1606 * @return index of the block, -ENOENT if no block found
1610 int FindInputBlock(const AliHLTComponentBlockData* pBlock) const;
1613 * Create an object from a specified input block.
1614 * @param idx index of the input block
1615 * @param bForce force the retrieval of an object, error messages
1616 * are suppressed if \em bForce is not set
1617 * @return pointer to TObject, caller must delete the object after use
1621 TObject* CreateInputObject(int idx, int bForce=0);
1625 * Get object from the input block list. The methods first checks whether the
1626 * object was already created. If not, it is created by @ref CreateInputObject
1627 * and inserted into the list of objects.
1628 * @param idx index in the input block list
1629 * @param classname name of the class, object is checked for correct class
1631 * @param bForce force the retrieval of an object, error messages
1632 * are suppressed if \em bForce is not set
1633 * @return pointer to TObject
1637 TObject* GetInputObject(int idx, const char* classname=NULL, int bForce=0);
1640 * Clean the list of input objects.
1641 * Cleanup is done at the end of each event processing.
1643 int CleanupInputObjects();
1646 * Insert a buffer into the output block stream.
1647 * This is the only method to insert blocks into the output stream, called
1648 * from all types of the Pushback method. The actual data might have been
1649 * written to the output buffer already. In that case NULL can be provided
1650 * as buffer, only the block descriptor will be build. If a header is specified,
1651 * it will be inserted before the buffer, default is no header.
1652 * @param pBuffer pointer to buffer
1653 * @param iBufferSize size of the buffer in byte
1654 * @param dt data type
1655 * @param spec data specification
1656 * @param pHeader pointer to header
1657 * @param iHeaderSize size of Header
1658 * @return neg. error code if failed
1660 int InsertOutputBlock(const void* pBuffer, int iBufferSize,
1661 const AliHLTComponentDataType& dt,
1662 AliHLTUInt32_t spec,
1663 const void* pHeader=NULL, int iHeaderSize=0);
1666 * Add a component statistics block to the output.
1667 * @return size of the added data
1669 int AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
1670 AliHLTUInt8_t* buffer,
1671 AliHLTUInt32_t bufferSize,
1672 AliHLTUInt32_t offset,
1673 AliHLTComponentStatisticsList& stats) const;
1676 * Add a component table entry (descriptor) to the output
1677 * This is done at SOR/EOR. The component table is a list of chain ids
1678 * and 32bit ids calculated by a crc algorithm from the chian id. This
1679 * allows to tag data blocks with the id number rather than the string.
1681 * The kAliHLTDataTypeComponentTable data block currently has the string
1682 * as payload and the crc id as specification.
1683 * @return size of the added data
1685 int AddComponentTableEntry(AliHLTComponentBlockDataList& blocks,
1686 AliHLTUInt8_t* buffer,
1687 AliHLTUInt32_t bufferSize,
1688 AliHLTUInt32_t offset,
1689 const vector<AliHLTUInt32_t>& parents) const;
1692 * Scan the ECS parameter string.
1693 * The framework provides both the parameters of CONFIGURE and ENGAGE
1694 * in one string in a special data block kAliHLTDataTypeECSParam
1695 * {ECSPARAM:PRIV}. The general format is
1696 * <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
1698 int ScanECSParam(const char* ecsParam);
1701 * The trigger classes are determined from the trigger and propagated by
1702 * ECS as part of the ENGAGE command parameter which is sent through the
1703 * framework during the SOR event. This function treats the value of the
1704 * parameter key CTP_TRIGGER_CLASS.
1706 int InitCTPTriggerClasses(const char* ctpString);
1709 kRequireSteeringBlocks = 0x1,
1710 kDisableComponentStat = 0x2
1713 /** The global component handler instance */
1714 static AliHLTComponentHandler* fgpComponentHandler; //! transient
1716 /** The environment where the component is running in */
1717 AliHLTAnalysisEnvironment fEnvironment; // see above
1719 /** Set by ProcessEvent before the processing starts */
1720 AliHLTEventID_t fCurrentEvent; // see above
1722 /** internal event no */
1723 int fEventCount; // see above
1725 /** the number of failed events */
1726 int fFailedEvents; // see above
1728 /** event data struct of the current event under processing */
1729 AliHLTComponentEventData fCurrentEventData; // see above
1731 /** array of input data blocks of the current event */
1732 const AliHLTComponentBlockData* fpInputBlocks; //! transient
1734 /** index of the current input block */
1735 int fCurrentInputBlock; // see above
1737 /** data type of the last block search */
1738 AliHLTComponentDataType fSearchDataType; // see above
1740 /** name of the class for the object to search for */
1741 string fClassName; // see above
1743 /** array of generated input objects */
1744 TObjArray* fpInputObjects; //! transient
1746 /** the output buffer */
1747 AliHLTUInt8_t* fpOutputBuffer; //! transient
1749 /** size of the output buffer */
1750 AliHLTUInt32_t fOutputBufferSize; // see above
1752 /** size of data written to output buffer */
1753 AliHLTUInt32_t fOutputBufferFilled; // see above
1755 /** list of ouput block data descriptors */
1756 AliHLTComponentBlockDataList fOutputBlocks; // see above
1758 /** stopwatch array */
1759 TObjArray* fpStopwatches; //! transient
1761 /** array of memory files AliHLTMemoryFile */
1762 AliHLTMemoryFilePList fMemFiles; //! transient
1764 /** descriptor of the current run */
1765 AliHLTRunDesc* fpRunDesc; //! transient
1767 /** external fct to set CDB run no, indicates external CDB initialization */
1768 void (*fCDBSetRunNoFunc)(); //! transient
1770 /** id of the component in the analysis chain */
1771 string fChainId; //! transient
1773 /** crc value of the chainid, used as a 32bit id */
1774 AliHLTUInt32_t fChainIdCrc; //! transient
1776 /** optional benchmarking for the component statistics */
1777 TStopwatch* fpBenchmark; //! transient
1779 /** component flags, cleared in Deinit */
1780 AliHLTUInt32_t fFlags; //! transient
1782 /** current event type */
1783 AliHLTUInt32_t fEventType; //! transient
1785 /** component arguments */
1786 string fComponentArgs; //! transient
1789 /** event done data */
1790 AliHLTComponentEventDoneData* fEventDoneData; //! transient
1792 /** Reserved size of the memory stored at fEventDoneData */
1793 unsigned long fEventDoneDataSize; //! transient
1795 /** Comression level for ROOT objects */
1796 int fCompressionLevel; //! transient
1798 /** size of last PushBack-serialized object */
1799 int fLastObjectSize; //! transient
1801 /** array of trigger class descriptors */
1802 AliHLTCTPData* fpCTPData; //! transient
1804 /// update period for PushBack calls
1805 int fPushbackPeriod; //! transient
1806 /// time of last executed PushBack
1807 int fLastPushBackTime; //! transient
1809 ClassDef(AliHLTComponent, 0)