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 struct AliRawDataHeader;
87 class AliHLTComponent;
88 class AliHLTMemoryFile;
90 class AliHLTReadoutList;
94 /** list of component data type structures */
95 typedef vector<AliHLTComponentDataType> AliHLTComponentDataTypeList;
96 /** list of component block data structures */
97 typedef vector<AliHLTComponentBlockData> AliHLTComponentBlockDataList;
98 /** list of component statistics struct */
99 typedef vector<AliHLTComponentStatistics> AliHLTComponentStatisticsList;
100 /** list of component pointers */
101 typedef vector<AliHLTComponent*> AliHLTComponentPList;
102 /** list of memory file pointers */
103 typedef vector<AliHLTMemoryFile*> AliHLTMemoryFilePList;
106 * @class AliHLTComponent
107 * Base class of HLT data processing components.
108 * The class provides a common interface for HLT data processing components.
109 * The interface can be accessed from the online HLT framework or the AliRoot
110 * offline analysis framework.
111 * @section alihltcomponent-properties Component identification and properties
112 * Each component must provide a unique ID, input and output data type indications,
113 * and a spawn function.
114 * @subsection alihltcomponent-req-methods Required property methods
115 * - @ref GetComponentID
116 * - @ref GetInputDataTypes (see @ref alihltcomponent-type for default
118 * - @ref GetOutputDataType (see @ref alihltcomponent-type for default
120 * - @ref GetOutputDataSize (see @ref alihltcomponent-type for default
124 * @subsection alihltcomponent-opt-mehods Optional handlers
127 * - @ref GetOutputDataTypes
128 * If the component has multiple output data types @ref GetOutputDataType
129 * should return @ref kAliHLTMultipleDataType. The framework will invoke
130 * @ref GetOutputDataTypes, a list can be filled.
132 * This function is invoked by the framework on a special event which
133 * triggers the reconfiguration of the component.
135 * @subsection alihltcomponent-processing-mehods Data processing
138 * @subsection alihltcomponent-type Component type
139 * Components can be of type
140 * - @ref kSource components which only produce data
141 * - @ref kProcessor components which consume and produce data
142 * - @ref kSink components which only consume data
144 * where data production and consumption refer to the analysis data stream. In
145 * order to indicate the type, a child component can overload the
146 * @ref GetComponentType function.
147 * @subsubsection alihltcomponent-type-std Standard implementations
148 * Components in general do not need to implement this function, standard
149 * implementations of the 3 types are available:
150 * - AliHLTDataSource for components of type @ref kSource <br>
151 * All types of data sources can inherit from AliHLTDataSource and must
152 * implement the @ref AliHLTDataSource::GetEvent method. The class
153 * also implements a standard method for @ref GetInputDataTypes.
155 * - AliHLTProcessor for components of type @ref kProcessor <br>
156 * All types of data processors can inherit from AliHLTProcessor and must
157 * implement the @ref AliHLTProcessor::DoEvent method.
159 * - AliHLTDataSink for components of type @ref kSink <br>
160 * All types of data processors can inherit from AliHLTDataSink and must
161 * implement the @ref AliHLTDataSink::DumpEvent method. The class
162 * also implements a standard method for @ref GetOutputDataType and @ref
165 * @subsection alihltcomponent-environment Running environment
167 * In order to adapt to different environments (on-line/off-line), the component
168 * gets an environment structure with function pointers. The base class provides
169 * member functions for those environment dependend functions. The member
170 * functions are used by the component implementation and are re-mapped to the
171 * corresponding functions.
173 * @section alihltcomponent-interfaces Component interfaces
174 * Each of the 3 standard component base classes AliHLTProcessor, AliHLTDataSource
175 * and AliHLTDataSink provides it's own processing method (see
176 * @ref alihltcomponent-type-std), which splits into a high and a low-level
177 * method. For the @ref alihltcomponent-low-level-interface, all parameters are
178 * shipped as function arguments, the component is supposed to write data to the
179 * output buffer and handle all block descriptors.
180 * The @ref alihltcomponent-high-level-interface is the standard processing
181 * method and will be used whenever the low-level method is not overloaded.
183 * In both cases it is necessary to calculate/estimate the size of the output
184 * buffer before the processing. Output buffers can never be allocated inside
185 * the component because of the push-architecture of the HLT.
186 * For that reason the @ref GetOutputDataSize function should return a rough
187 * estimatian of the data to be produced by the component. The component is
188 * responsible for checking the memory size and must return -ENOSPC if the
189 * available buffer is too small, and update the estimator respectively. The
190 * framework will allocate a buffer of appropriate size and call the processing
193 * @subsection alihltcomponent-error-codes Return values/Error codes
194 * For return codes, the following scheme applies:
195 * - The data processing methods have to indicate error conditions by a negative
196 * error/return code. Preferably the system error codes are used like
197 * e.g. -EINVAL. This requires to include the header
199 * \#include \<cerrno\>
201 * This schema aplies to all interface functions of the component base class.
202 * For data processing it is as follows:
203 * - If no suitable input block could be found (e.g. no clusters for the TPC cluster
204 * finder) set size to 0, block list is empty, return 0
205 * - If no ususable or significant signal could be found in the input blocks
206 * return an empty output block, set size accordingly, and return 0. An empty output
207 * block here could be either a real empty one of size 0 (in which case size also
208 * would have to be set to zero) or a block filled with just the minimum necessary
209 * accounting/meta-structures. E.g. in the TPC
211 * @subsection alihltcomponent-high-level-interface High-level interface
212 * The high-level component interface provides functionality to exchange ROOT
213 * structures between components. In contrast to the
214 * @ref alihltcomponent-low-level-interface, a couple of functions can be used
215 * to access data blocks of the input stream
216 * and send data blocks or ROOT TObject's to the output stream. The functionality
217 * is hidden from the user and is implemented by using ROOT's TMessage class.
219 * @subsubsection alihltcomponent-high-level-int-methods Interface methods
220 * The interface provides a couple of methods in order to get objects from the
221 * input, data blocks (non TObject) from the input, and to push back objects and
222 * data blocks to the output. For convenience there are several functions of
223 * identical name (and similar behavior) with different parameters defined.
224 * Please refer to the function documentation.
225 * - @ref GetNumberOfInputBlocks <br>
226 * return the number of data blocks in the input stream
227 * - @ref GetFirstInputObject <br>
228 * get the first object of a specific data type
229 * - @ref GetNextInputObject <br>
230 * get the next object of same data type as last GetFirstInputObject/Block call
231 * - @ref GetFirstInputBlock <br>
232 * get the first block of a specific data type
233 * - @ref GetNextInputBlock <br>
234 * get the next block of same data type as last GetFirstInputBlock/Block call
235 * - @ref PushBack <br>
236 * insert an object or data buffer into the output
237 * - @ref CreateEventDoneData <br>
238 * add event information to the output
240 * In addition, the processing methods are simplified a bit by cutting out most of
243 * - @ref AliHLTProcessor::DoEvent
244 * - @ref AliHLTDataSource::GetEvent
245 * - @ref AliHLTDataSink::DumpEvent
247 * \em IMPORTANT: objects and block descriptors provided by the high-level interface
248 * <b>MUST NOT BE DELETED</b> by the caller.
250 * @subsubsection alihltcomponent-high-level-int-guidelines High-level interface guidelines
251 * - Structures must inherit from the ROOT object base class TObject in order be
252 * transported by the transportation framework.
253 * - all pointer members must be transient (marked <tt>//!</tt> behind the member
254 * definition), i.e. will not be stored/transported, or properly marked
255 * (<tt>//-></tt>) in order to call the streamer of the object the member is pointing
256 * to. The latter is not recomended. Structures to be transported between components
257 * should be streamlined.
258 * - no use of stl vectors/strings, use appropriate ROOT classes instead
260 * @subsection alihltcomponent-low-level-interface Low-level interface
261 * The low-level component interface consists of the specific data processing
262 * methods for @ref AliHLTProcessor, @ref AliHLTDataSource, and @ref AliHLTDataSink.
263 * - @ref AliHLTProcessor::DoEvent
264 * - @ref AliHLTDataSource::GetEvent
265 * - @ref AliHLTDataSink::DumpEvent
267 * The base class passes all relevant parameters for data access directly on to the
268 * component. Input blocks can be accessed by means of the array <tt> blocks </tt>.
269 * Output data are written directly to shared memory provided by the pointer
270 * <tt> outputPtr </tt> and output block descriptors are inserted directly to the
271 * list <tt> outputBlocks </tt>.
273 * \b NOTE: The high-level input data access methods can be used also from the low
274 * level interface. Also the PushBack functions can be used BUT ONLY if no data is
275 * written to the output buffer and no data block descriptors are inserted into the
278 * @section alihltcomponent-initialization Component initialization and configuration
279 * The component interface provides two optional methods for component initialization
280 * and configuration. The @ref DoInit function is called once before the processing.
281 * During the event processing, a special event can trigger a reconfiguration and the
282 * @ref Reconfigure method is called. There are three possible options of initialization
284 * - default values: set directly in the source code
285 * - OCDB objects: all necessary information must be loaded from OCDB objects. The
286 * Offline Conditions Data Base stores objects specifically valid for individual runs
288 * - Component arguments: can be specified for every component in the chain
289 * configuration. The arguments can be used to override specific parameters of the
292 * As a general rule, the three options should be processed in that sequence, i.e
293 * default parameters might be overridden by OCDB configuration, and the latter one
294 * by component arguments.
296 * @subsection alihltcomponent-initialization-arguments Component arguments
297 * In normal operation, components are supposed to run without any additional argument,
298 * however such arguments can be useful for testing and debugging. The idea follows
299 * the format of command line arguments. A keyword is indicated by a dash and an
300 * optional argument might follow, e.g.:
302 * -argument1 0.5 -argument2
304 * In this case argument1 requires an additional parameter whereas argument2 does not.
305 * The arguments will be provided as an array of separated arguments.
307 * Component arguments can be classified into initialization arguments and configuration
308 * arguments. The latter are applicable for both the @ref DoInit and @ref Reconfigure
309 * method whereas initialization arguments are not applicable after DoInit.
311 * @subsection alihltcomponent-initialization-ocdb OCDB objects
312 * OCDB objects are ROOT <tt>TObjects</tt> and can be of any type. This is in particular
313 * useful for complex parameter sets. However in most cases, a simple approach of human
314 * readable command line arguments is appropriate. Such a string can be simply stored
315 * in a TObjString (take note that the TString does not derive from TObject). The
316 * same arguments as for the command line can be used. Take note that in the TObjString
317 * all arguments are separated by blanks, instead of being in an array of separate
320 * The base class provides two functions regarding OCDB objects:
321 * - LoadAndExtractOCDBObject() loads the OCDB entry for the specified path and extracts
322 * the TObject from it. An optional key allows to access
323 * a TObject within a TMap
324 * - ConfigureFromCDBTObjString() can load a number of OCDB objects and calls the
325 * argument parsing ConfigureFromArgumentString
328 * @subsection alihltcomponent-initialization-sequence Initialization sequence
329 * Using the approach of <tt>TObjString</tt>-type configuration objects allows to treat
330 * configuration from both @ref DoInit and @ref Reconfigure in the same way.
332 * The base class provides the function ConfigureFromArgumentString() which loops over
333 * all arguments and calls the child's method ScanConfigurationArgument(). Here the
334 * actual treatment of the argument and its parameters needs to be implemented.
335 * ConfigureFromArgumentString() can treat both arrays of arguments and arguments in
336 * one single string separated by blanks. The two options can be mixed.
338 * A second base class function ConfigureFromCDBTObjString() allows to configure
339 * directly from a number of OCDB objects. This requires the entries to be of
340 * type TObjString and the child implementation of ScanConfigurationArgument().
341 * The object can also be of type TMap with TObjStrings as key-value pairs. The
342 * key identifier can be chosen by the component implementation. Normally it will
343 * be the run type ("p","A-A", "p-A", ...) or e.g. the trigger code secified by
346 * @section alihltcomponent-handling Component handling
347 * The handling of HLT analysis components is carried out by the AliHLTComponentHandler.
348 * Component are registered automatically at load-time of the component shared library
349 * under the following suppositions:
350 * - the component library has to be loaded from the AliHLTComponentHandler using the
351 * @ref AliHLTComponentHandler::LoadLibrary method.
352 * - the library defines an AliHLTModuleAgent which registers all components.
353 * See AliHLTModuleAgent::RegisterComponents <br>
355 * - the component implementation defines one global object (which is generated
356 * when the library is loaded) <br>
358 * @subsection alihltcomponent-design-rules General design considerations
359 * The analysis code should be implemented in one or more destict class(es). A
360 * \em component should be implemented which interface the destict analysis code to the
361 * component interface. This component generates the analysis object dynamically. <br>
363 * Assume you have an implemetation <tt> AliHLTDetMyAnalysis </tt>, another class <tt>
364 * AliHLTDetMyAnalysisComponent </tt> contains:
367 * AliHLTDetMyAnalysis* fMyAnalysis; //!
369 * The object should then be instantiated in the DoInit handler of
370 * <tt>AliHLTDetMyAnalysisComponent </tt>, and cleaned in the DoDeinit handler.
373 * - avoid big static arrays in the component, allocate the memory at runtime
374 * - allocate all kind of complex data members (like classes, ROOT TObjects of
375 * any kind) dynamically in DoInit and clean up in DoDeinit
377 * @section alihlt_component_arguments Default arguments
378 * The component base class provides some default arguments:
379 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
380 * \li -loglevel=level <br>
381 * \li -object-compression=level <br>
382 * compression level for ROOT objects, default is defined by
383 * @ref ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION
384 * \li -pushback-period=period <br>
385 * scale down for PushBack of objects, shipped only for one event
386 * every <i>period</i> seconds
387 * \li -event-module=number <br>
388 * This option reduces the event processing rate by processing only n'th event
389 * based on the modulo number <i>number</i>. The scale down should be about
390 * 1/<i>number</i>, where <i>number</i> is a positive integer.
392 * @ingroup alihlt_component
393 * @section alihltcomponent-members Class members
395 class AliHLTComponent : public AliHLTLogging {
397 /** standard constructor */
399 /** standard destructor */
400 virtual ~AliHLTComponent();
402 /** component type definitions */
403 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
406 * Init function to prepare data processing.
407 * Initialization of common data structures for a sequence of events.
408 * The call is redirected to the internal method DoInit which can be
409 * overridden by the child class.
410 * During Init also the environment structure is passed to the component.
411 * @param comenv environment pointer with environment dependent function
413 * @param environParam additional parameter for function calls, the pointer
415 * @param argc size of the argument array
416 * @param argv augment array for component initialization
418 virtual int Init( const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv );
421 * Clean-up function to terminate data processing.
422 * Clean-up of common data structures after data processing.
423 * The call is redirected to the internal method @ref DoDeinit which can be
424 * overridden by the child class.
426 virtual int Deinit();
429 * Processing of one event.
430 * The method is the entrance of the event processing. The parameters are
431 * cached for uses with the high-level interface and the DoProcessing
432 * implementation is called.
439 * @param outputBlockCnt out: size of the output block array, set by the component
440 * @param outputBlocks out: the output block array is allocated internally
442 * @return neg. error code if failed
444 int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
445 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
446 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
447 AliHLTComponentBlockData*& outputBlocks,
448 AliHLTComponentEventDoneData*& edd );
451 * Internal processing of one event.
452 * The method is pure virtual and implemented by the child classes
453 * - @ref AliHLTProcessor
454 * - @ref AliHLTDataSource
455 * - @ref AliHLTDataSink
462 * @param outputBlocks out: the output block array is allocated internally
464 * @return neg. error code if failed
466 virtual int DoProcessing( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
467 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
468 AliHLTUInt32_t& size,
469 AliHLTComponentBlockDataList& outputBlocks,
470 AliHLTComponentEventDoneData*& edd ) = 0;
474 * The function must not be called when running in AliRoot unless it it
475 * really wanted. The CDB path will be set to the specified path, which might
476 * override the path initialized at the beginning of the AliRoot reconstruction.
478 * The method is used from the external interface in order to set the correct
479 * path when running on-line. The function also initializes the function
480 * callback for setting the run no during operation.
482 * A separation of library and component handling is maybe appropriate in the
483 * future. Using the global component handler here is maybe not the cleanest
485 * @param cdbPath path of the CDB
486 * @param pHandler the component handler used for llibrary handling.
488 int InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler);
491 * Set the run no for the CDB.
492 * The function must not be called when running in AliRoot unless it it
493 * really wanted. The CDB path will be set to the specified path, which might
494 * override the run no initialized at the beginning of the AliRoot reconstruction.
495 * InitCDB() has to be called before in order to really change the CDB settings.
497 * The method is used from the external interface in order to set the correct
498 * path when running on-line.
500 int SetCDBRunNo(int runNo);
503 * Set the run description.
504 * The run description is set before the call of Init() -> DoInit().
505 * @note: This functionality has been added in Juli 2008. The transmission of
506 * run properties by a special SOR (SOD event in DAQ terminalogy but this was
507 * changed after the HLT interface was designed) event is not sufficient because
508 * the data might be needed already in the DoInit handler of the component.
509 * @param desc run descriptor, currently only the run no member is used
510 * @param runType originally, run type was supposed to be a number and part
511 * of the run descriptor. But it was defined as string later
513 int SetRunDescription(const AliHLTRunDesc* desc, const char* runType);
516 * Set the component description.
517 * The description string can contain tokens separated by blanks, a token
518 * consists of a key and an optional value separated by '='.
520 * \li -chainid=id string id within the chain of the instance
522 * @param desc component description
524 int SetComponentDescription(const char* desc);
527 * Set the running environment for the component.
528 * Originally, the environment was set in the Init function. However, the setup of
529 * the CDB is required before. In order to have proper logging functionality, the
530 * environment is required.
531 * @param comenv environment pointer with environment dependent function
533 * @param environParam additional parameter for function calls, the pointer
536 int SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam);
538 // Information member functions for registration.
541 * Get the type of the component.
542 * The function is pure virtual and must be implemented by the child class.
543 * @return component type id
545 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
548 * Get the id of the component.
549 * Each component is identified by a unique id.
550 * The function is pure virtual and must be implemented by the child class.
551 * @return component id (string)
553 virtual const char* GetComponentID() = 0;
556 * Get the input data types of the component.
557 * The function is pure virtual and must be implemented by the child class.
558 * @return list of data types in the vector reference
560 virtual void GetInputDataTypes( AliHLTComponentDataTypeList& ) = 0;
563 * Get the output data type of the component.
564 * The function is pure virtual and must be implemented by the child class.
565 * @return output data type
567 virtual AliHLTComponentDataType GetOutputDataType() = 0;
570 * Get the output data types of the component.
571 * The function can be implemented to indicate multiple output data types
572 * in the target array.
573 * @ref GetOutputDataType must return @ref kAliHLTMultipleDataType in order
574 * to invoke this method.
575 * @param tgtList list to receive the data types
576 * @return no of output data types, data types in the target list
578 virtual int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList);
581 * Get a ratio by how much the data volume is shrunken or enhanced.
582 * The function is pure virtual and must be implemented by the child class.
583 * @param constBase <i>return</i>: additive part, independent of the
585 * @param inputMultiplier <i>return</i>: multiplication ratio
586 * @return values in the reference variables
588 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
591 * Get a list of OCDB object description.
592 * The list of objects is provided in a TMap
593 * - key: complete OCDB path, e.g. GRP/GRP/Data
594 * - value: short description why the object is needed
595 * Key and value objects created inside this class go into ownership of
597 * @param targetMap TMap instance receiving the list
600 virtual void GetOCDBObjectDescription( TMap* const targetArray);
604 * Each component must implement a spawn function to create a new instance of
605 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
606 * @return new class instance
608 virtual AliHLTComponent* Spawn() = 0;
611 * check the availability of the OCDB entry descriptions in the TMap
612 * key : complete OCDB path of the entry
613 * value : auxiliary object - short description
614 * if the external map was not provided the function invokes
615 * interface function GetOCDBObjectDescription() to retrieve the list.
616 * @param externList map of entries to be tested
617 * @result 0 if all found, -ENOENT if objects not found
619 int CheckOCDBEntries(const TMap* const externList=NULL);
622 * Find matching data types between this component and a consumer component.
623 * Currently, a component can produce only one type of data. This restriction is most
624 * likely to be abolished in the future.
625 * @param pConsumer a component and consumer of the data produced by this component
626 * @param tgtList reference to a vector list to receive the matching data types.
627 * @return >= 0 success, neg. error code if failed
629 int FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList);
632 * Set the global component handler.
633 * The static method is needed for the automatic registration of components.
635 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
638 * Clear the global component handler.
639 * The static method is needed for the automatic registration of components.
641 static int UnsetGlobalComponentHandler();
644 * Helper function to convert the data type to a string.
645 * @param type data type structure
646 * @param mode 0 print string origin:type <br>
648 * 2 print numbers <br>
649 * 3 print 'type' 'origin'
651 static string DataType2Text( const AliHLTComponentDataType& type, int mode=0);
654 * Calculate a CRC checksum of a data buffer.
655 * Polynomial for the calculation is 0xD8.
657 static AliHLTUInt32_t CalculateChecksum(const AliHLTUInt8_t* buffer, int size);
660 * Helper function to print content of data type.
662 static void PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format=NULL);
665 * helper function to initialize AliHLTComponentEventData structure
667 static void FillEventData(AliHLTComponentEventData& evtData);
670 * Print info on an AliHLTComponentDataType structure
671 * This is just a helper function to examine an @ref AliHLTComponentDataType
674 static void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
677 * Fill AliHLTComponentBlockData structure with default values.
678 * @param blockData reference to data structure
680 static void FillBlockData( AliHLTComponentBlockData& blockData );
683 * Fill AliHLTComponentShmData structure with default values.
684 * @param shmData reference to data structure
686 static void FillShmData( AliHLTComponentShmData& shmData );
689 * Fill AliHLTComponentDataType structure with default values.
690 * @param dataType reference to data structure
692 static void FillDataType( AliHLTComponentDataType& dataType );
695 * Copy data type structure
696 * Copies the value an AliHLTComponentDataType structure to another one
697 * @param [out] tgtdt target structure
698 * @param [in] srcdt source structure
700 static void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
703 * Set the ID and Origin of an AliHLTComponentDataType structure.
704 * The function sets the fStructureSize member and copies the strings
705 * to the ID and Origin. Only characters from the valid part of the string
706 * are copied, the rest is filled with 0's. <br>
707 * Please note that the fID and fOrigin members are not strings, just arrays of
708 * chars of size @ref kAliHLTComponentDataTypefIDsize and
709 * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
710 * a terminating zero. <br>
711 * It is possible to pass NULL pointers as id or origin argument, in that case they
713 * @param tgtdt target data type structure
714 * @param id ID string
715 * @param origin Origin string
717 static void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
720 * Set the ID and Origin of an AliHLTComponentDataType structure.
721 * Given the fact that the data type ID is 64bit wide and origin 32, this helper
722 * function sets the data type from those two parameters.
723 * @param dt target data type structure
725 * @param orig 32bit origin
727 static void SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t orig);
730 * Extract a component table entry from the payload buffer.
731 * The entry consists of the AliHLTComponentTableEntry structure, the array of
732 * parents and a description string of the format 'chain-id{component-id:component-args}'.
733 * The function fills all the variables after a consistency check.
735 static int ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
736 string& chainId, string& compId, string& compParam,
737 vector<AliHLTUInt32_t>& parents) {
739 return ExtractComponentTableEntry(pBuffer, size, chainId, compId, compParam, parents, dummy);
742 static int ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
743 string& chainId, string& compId, string& compParam,
744 vector<AliHLTUInt32_t>& parents, int& level);
747 * Extracts the different data parts from the trigger data structure.
748 * @param [in] trigData The trigger data as passed to the DoProcessing method.
749 * @param [out] attributes The data block attributes given by the HLT framework.
750 * @param [out] status The HLT status bits given by the HLT framework.
751 * @param [out] cdh The common data header received from DDL links.
752 * @param [out] readoutlist The readout list to fill with readout list bits
753 * passed on by the HLT framework.
754 * @param [in] printErrors If true then error messages are generated as necessary
755 * and suppressed otherwise.
756 * @note If any of the output parameters are set to NULL then the field is not set.
757 * For example, the following line will only fill the CDH pointer.
759 * AliRawDataHeader* cdh;
760 * ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL);
762 * @return zero on success or one of the following error codes on failure.
763 * if a non-zero error code is returned then none of the output parameters are
765 * \li -ENOENT The <i>trigData</i> structure size is wrong.
766 * \li -EBADF The <i>trigData</i> data size is wrong.
767 * \li -EBADMSG The common data header (CDH) in the trigger data has the wrong
768 * number of words indicated.
769 * \li -EPROTO The readout list structure in the trigger data has the wrong
770 * number of words indicated.
772 static int ExtractTriggerData(
773 const AliHLTComponentTriggerData& trigData,
774 const AliHLTUInt8_t (**attributes)[gkAliHLTBlockDAttributeCount],
775 AliHLTUInt64_t* status,
776 const AliRawDataHeader** cdh,
777 AliHLTReadoutList* readoutlist,
778 bool printErrors = false
782 * Extracts the readout list from a trigger data structure.
783 * @param [in] trigData The trigger data as passed to the DoProcessing method.
784 * @param [out] list The output readout list to fill.
785 * @param [in] printErrors If true then error messages are generated as necessary
786 * and suppressed otherwise.
787 * @return zero on success or one of the error codes returned by ExtractTriggerData.
789 static int GetReadoutList(
790 const AliHLTComponentTriggerData& trigData, AliHLTReadoutList& list,
791 bool printErrors = false
794 return ExtractTriggerData(trigData, NULL, NULL, NULL, &list, printErrors);
798 * Extracts the event type from the given Common Data Header.
799 * @param [in] cdh The Common Data Header to extract the event type from.
800 * @return the event type code from the CDH.
802 static AliHLTUInt32_t ExtractEventTypeFromCDH(const AliRawDataHeader* cdh);
805 * Stopwatch type for benchmarking.
807 enum AliHLTStopwatchType {
808 /** total time for event processing */
810 /** detector algorithm w/o interface callbacks */
816 /** number of types */
821 * Helper class for starting and stopping a stopwatch.
822 * The guard can be used by instantiating an object in a function. The
823 * specified stopwatch is started and the previous stopwatch put on
824 * hold. When the function is terminated, the object is deleted automatically
825 * deleted, stopping the stopwatch and starting the one on hold.<br>
826 * \em IMPORTANT: never create dynamic objects from this guard as this violates
827 * the idea of a guard.
829 class AliHLTStopwatchGuard {
831 /** standard constructor (not for use) */
832 AliHLTStopwatchGuard();
834 AliHLTStopwatchGuard(TStopwatch* pStart);
835 /** copy constructor (not for use) */
836 AliHLTStopwatchGuard(const AliHLTStopwatchGuard&);
837 /** assignment operator (not for use) */
838 AliHLTStopwatchGuard& operator=(const AliHLTStopwatchGuard&);
840 ~AliHLTStopwatchGuard();
844 * Hold the previous guard for the existence of this guard.
845 * Checks whether this guard controls a new stopwatch. In that case, the
846 * previous guard and its stopwatch are put on hold.
847 * @param pSucc instance of the stopwatch of the new guard
848 * @return 1 if pSucc is a different stopwatch which should
850 * 0 if it controls the same stopwatch
852 int Hold(const TStopwatch* pSucc);
855 * Resume the previous guard.
856 * Checks whether the peceeding guard controls a different stopwatch. In that
857 * case, the its stopwatch is resumed.
858 * @param pSucc instance of the stopwatch of the new guard
859 * @return 1 if pSucc is a different stopwatch which should
861 * 0 if it controls the same stopwatch
863 int Resume(const TStopwatch* pSucc);
865 /** the stopwatch controlled by this guard */
866 TStopwatch* fpStopwatch; //!transient
868 /** previous stopwatch guard, put on hold during existence of the guard */
869 AliHLTStopwatchGuard* fpPrec; //!transient
871 /** active stopwatch guard */
872 static AliHLTStopwatchGuard* fgpCurrent; //!transient
876 * Set a stopwatch for a given purpose.
877 * @param pSW stopwatch object
878 * @param type type of the stopwatch
880 int SetStopwatch(TObject* pSW, AliHLTStopwatchType type=kSWBase);
883 * Init a set of stopwatches.
884 * @param pStopwatches object array of stopwatches
886 int SetStopwatches(TObjArray* pStopwatches);
889 * Customized logging function.
890 * The chain id, component id and pointer is added at the beginning of each message.
892 int LoggingVarargs(AliHLTComponentLogSeverity severity,
893 const char* originClass, const char* originFunc,
894 const char* file, int line, ... ) const;
897 * Get size of last serialized object.
898 * During PushBack, TObjects are serialized in a separate buffer. The
899 * size of the last object can be retrieved by this function.
901 * This might be especially useful for PushBack failures caused by too
902 * small output buffer.
904 int GetLastObjectSize() const {return fLastObjectSize;}
907 * This method generates a V4 Globally Unique Identifier (GUID) using the
908 * ROOT TRandom3 pseudo-random number generator with the process' UID, GID
909 * PID and host address as seeds. For good measure MD5 sum hashing is also
911 * @return the newly generated GUID structure.
913 static TUUID GenerateGUID();
915 /// get the compression level for TObjects
916 int GetCompressionLevel() const {return fCompressionLevel;}
921 * Default method for the internal initialization.
922 * The method is called by @ref Init
924 virtual int DoInit( int argc, const char** argv );
927 * Default method for the internal clean-up.
928 * The method is called by @ref Deinit
930 virtual int DoDeinit();
933 * Reconfigure the component.
934 * The method is called when an event of type @ref kAliHLTDataTypeComConf
935 * {COM_CONF:PRIV} is received by the component. If the event is sent as
936 * part of a normal event, the component configuration is called first.
938 * The CDB path parameter specifies the path in the CDB, i.e. without
939 * leading absolute path of the CDB location. The framework might also
940 * provide the id of the component in the analysis chain.
942 * The actual sequence of configuration depends on the component. As a
943 * general rule, the component should load the specific OCDB object if
944 * provided as parameter, and load the default objects if the parameter
945 * is NULL. However, other schemes are possible. See @ref
947 * \b Note: The CDB will be initialized by the framework, either already set
948 * from AliRoot or from the wrapper interface during initialization.
950 * @param cdbEntry path of the cdbEntry
951 * @param chainId the id/name of the component in the current analysis
952 * chain. This is not necessarily the same as what is
953 * returned by the GetComponentID() method.
954 * @note both parameters can be NULL, check before usage
956 virtual int Reconfigure(const char* cdbEntry, const char* chainId);
959 * Read the Preprocessor values.
960 * The function is invoked when the component is notified about available/
961 * updated data points from the detector Preprocessors. The 'modules'
962 * argument contains all detectors for which the Preprocessors have
963 * updated data points. The component has to implement the CDB access to
964 * get the desired data points.
965 * @param modules detectors for which the Preprocessors have updated
966 * data points: TPC, TRD, ITS, PHOS, MUON, or ALL if
967 * no argument was received.
968 * @return neg. error code if failed
970 virtual int ReadPreprocessorValues(const char* modules);
973 * Child implementation to scan a number of configuration arguments.
974 * The method is invoked by the framework in conjunction with the
975 * common framework functions ConfigureFromArgumentString and
976 * ConfigureFromCDBTObjString.
977 * Function needs to scan the argument and optional additional
978 * parameters and returns the number of elements in the array which
982 * @return number of arguments which have been scanned or neg error
983 * code if failed <br>
984 * \li -EINVAL unknown argument
985 * \li -EPROTO protocol error, e.g. missing parameter
987 virtual int ScanConfigurationArgument(int argc, const char** argv);
990 * Custom handler for the SOR event.
991 * Is invoked from the base class if an SOR event is in the block list.
992 * The handler is called before the processing function. The processing
993 * function is skipped if there are no other data blocks available.
995 * The SOR event is generated by the PubSub framework in response to
996 * the DAQ start of data (SOD - has been renamed after HLT interface
997 * was designed). The SOD event consists of 3 blocks:
998 * - ::kAliHLTDataTypeEvent block: spec ::gkAliEventTypeStartOfRun
999 * - SOD block of type ::kAliHLTDataTypeSOR, payload: AliHLTRunDesc struct
1000 * - run type block ::kAliHLTDataTypeRunType, payload: run type string
1002 * Run properties can be retrieved by getters like GetRunNo().
1003 * @return neg. error code if failed
1005 virtual int StartOfRun();
1008 * Custom handler for the EOR event.
1009 * Is invoked from the base class if an EOR event is in the block list.
1010 * The handler is called before the processing function. The processing
1011 * function is skipped if there are no other data blocks available.
1013 * See StartOfRun() for more comments of the sequence of steering events.
1015 * @return neg. error code if failed
1017 virtual int EndOfRun();
1020 * Check whether a component requires all steering blocks.
1021 * Childs can overload in order to indicate that they want to
1022 * receive also the steering data blocks. There is also the
1023 * possibility to add the required data types to the input
1024 * data type list in GetInputDataTypes().
1026 virtual bool RequireSteeringBlocks() const {return false;}
1029 * General memory allocation method.
1030 * All memory which is going to be used 'outside' of the interface must
1031 * be provided by the framework (online or offline).
1032 * The method is redirected to a function provided by the current
1033 * framework. Function pointers are transferred via the @ref
1034 * AliHLTAnalysisEnvironment structure.
1036 void* AllocMemory( unsigned long size );
1039 * Helper function to create a monolithic BlockData description block out
1040 * of a list BlockData descriptors.
1041 * For convenience, inside the interface vector lists are used, to make the
1042 * interface pure C style, monilithic blocks must be exchanged.
1043 * The method is redirected to a function provided by the current
1044 * framework. Function pointers are transferred via the @ref
1045 * AliHLTAnalysisEnvironment structure.
1047 int MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
1048 AliHLTComponentBlockData** outputBlocks );
1051 * Fill the EventDoneData structure.
1052 * The method is redirected to a function provided by the current
1053 * framework. Function pointers are transferred via the @ref
1054 * AliHLTAnalysisEnvironment structure.
1056 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) const;
1059 * Allocate an EventDoneData structure for the current event .
1060 * The method allocates the memory internally and does not interact with the current Framework.
1061 * The allocated data structure is empty initially and can be filled by calls to the
1062 * @ref PushEventDoneData method. The memory will be automatically released after the event has been processed.
1065 int ReserveEventDoneData( unsigned long size );
1068 * Push a 32 bit word of data into event done data for the current event which
1069 * has previously been allocated by the @ref ReserveEventDoneData method.
1071 int PushEventDoneData( AliHLTUInt32_t eddDataWord );
1074 * Release event done data previously reserved by @ref ReserveEventDoneData
1076 void ReleaseEventDoneData();
1079 * Get the pointer to the event done data available/built so far for the current event via
1080 * @ref ReserveEventDoneData and @ref PushEventDoneData
1082 AliHLTComponentEventDoneData* GetCurrentEventDoneData() const
1084 return fEventDoneData;
1088 * Helper function to convert the data type to a string.
1090 void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]) const;
1093 * Loop through a list of component arguments.
1094 * The list can be either an array of separated strings or one single
1095 * string containing blank separated arguments, or both mixed.
1096 * ScanConfigurationArgument() is called to allow the component to treat
1097 * the individual arguments.
1098 * @return neg. error code if failed
1100 int ConfigureFromArgumentString(int argc, const char** argv);
1103 * Read configuration objects from OCDB and configure from
1104 * the content of TObjString entries.
1105 * @param entries blank separated list of OCDB paths
1106 * @param key if the entry is a TMap, search for the corresponding object
1107 * @return neg. error code if failed
1109 int ConfigureFromCDBTObjString(const char* entries, const char* key=NULL);
1112 * Load specified entry from the OCDB and extract the object.
1113 * The entry is explicitely unloaded from the cache before it is loaded.
1114 * If parameter key is specified the OCDB object is treated as TMap
1115 * and the TObject associated with 'key' is loaded.
1116 * @param path path of the entry under to root of the OCDB
1117 * @param version version of the entry
1118 * @param subVersion subversion of the entry
1119 * @param key key of the object within TMap
1121 TObject* LoadAndExtractOCDBObject(const char* path, const char* key=NULL) const;
1125 * @return value of the internal event counter
1127 int GetEventCount() const;
1130 * Get the number of input blocks.
1131 * @return number of input blocks
1133 int GetNumberOfInputBlocks() const;
1136 * Get id of the current event
1139 AliHLTEventID_t GetEventId() const;
1142 * Get the first object of a specific data type from the input data.
1143 * The High-level methods provide functionality to transfer ROOT data
1144 * structures which inherit from TObject.
1146 * The method looks for the first ROOT object of type dt in the input stream.
1147 * If also the class name is provided, the object is checked for the right
1148 * class type. The input data block needs a certain structure, namely the
1149 * buffer size as first word. If the cross check fails, the retrieval is
1150 * silently abandoned, unless the \em bForce parameter is set.<br>
1151 * \b Note: THE OBJECT MUST NOT BE DELETED by the caller.
1153 * If called without parameters, the function tries to create objects from
1154 * all available input blocks, also the ones of data type kAliHLTVoidDataType
1155 * which are not matched by kAliHLTAnyDataType.
1157 * @param dt data type of the object
1158 * @param classname class name of the object
1159 * @param bForce force the retrieval of an object, error messages
1160 * are suppressed if \em bForce is not set
1161 * @return pointer to @ref TObject, NULL if no objects of specified type
1164 const TObject* GetFirstInputObject(const AliHLTComponentDataType& dt=kAliHLTAllDataTypes,
1165 const char* classname=NULL,
1169 * Get the first object of a specific data type from the input data.
1170 * The High-level methods provide functionality to transfer ROOT data
1171 * structures which inherit from TObject.
1172 * The method looks for the first ROOT object of type specified by the ID and
1173 * Origin strings in the input stream.
1174 * If also the class name is provided, the object is checked for the right
1175 * class type. The input data block needs a certain structure, namely the
1176 * buffer size as first word. If the cross check fails, the retrieval is
1177 * silently abandoned, unless the \em bForce parameter is set.<br>
1178 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
1179 * @param dtID data type ID of the object
1180 * @param dtOrigin data type origin of the object
1181 * @param classname class name of the object
1182 * @param bForce force the retrieval of an object, error messages
1183 * are suppressed if \em bForce is not set
1184 * @return pointer to @ref TObject, NULL if no objects of specified type
1187 const TObject* GetFirstInputObject(const char* dtID,
1188 const char* dtOrigin,
1189 const char* classname=NULL,
1193 * Get the next object of a specific data type from the input data.
1194 * The High-level methods provide functionality to transfer ROOT data
1195 * structures which inherit from TObject.
1196 * The method looks for the next ROOT object of type and class specified
1197 * to the previous @ref GetFirstInputObject call.<br>
1198 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
1199 * @param bForce force the retrieval of an object, error messages
1200 * are suppressed if \em bForce is not set
1201 * @return pointer to @ref TObject, NULL if no more objects available
1203 const TObject* GetNextInputObject(int bForce=0);
1206 * Get data type of an input block.
1207 * Get data type of the object previously fetched via
1208 * GetFirstInputObject/NextInputObject or the last one if no object
1210 * @param pObject pointer to TObject
1211 * @return data specification, kAliHLTVoidDataSpec if failed
1213 AliHLTComponentDataType GetDataType(const TObject* pObject=NULL);
1216 * Get data specification of an input block.
1217 * Get data specification of the object previously fetched via
1218 * GetFirstInputObject/NextInputObject or the last one if no object
1220 * @param pObject pointer to TObject
1221 * @return data specification, kAliHLTVoidDataSpec if failed
1223 AliHLTUInt32_t GetSpecification(const TObject* pObject=NULL);
1226 * Get the first block of a specific data type from the input data.
1227 * The method looks for the first block of type dt in the input stream.
1228 * It is intended to be used within the high-level interface.<br>
1229 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
1231 * If called without parameters, the function works on all input blocks,
1232 * also the ones of data type kAliHLTVoidDataType which are not matched by
1233 * kAliHLTAnyDataType.
1235 * @param dt data type of the block
1236 * @return pointer to @ref AliHLTComponentBlockData
1238 const AliHLTComponentBlockData* GetFirstInputBlock(const AliHLTComponentDataType& dt=kAliHLTAllDataTypes);
1241 * Get the first block of a specific data type from the input data.
1242 * The method looks for the first block of type specified by the ID and
1243 * Origin strings in the input stream. It is intended
1244 * to be used within the high-level interface.<br>
1245 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
1246 * @param dtID data type ID of the block
1247 * @param dtOrigin data type origin of the block
1248 * @return pointer to @ref AliHLTComponentBlockData
1250 const AliHLTComponentBlockData* GetFirstInputBlock(const char* dtID,
1251 const char* dtOrigin);
1254 * Get input block by index.<br>
1255 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
1256 * @return pointer to AliHLTComponentBlockData, NULL if index out of range
1258 const AliHLTComponentBlockData* GetInputBlock(int index) const;
1261 * Get the next block of a specific data type from the input data.
1262 * The method looks for the next block of type and class specified
1263 * to the previous @ref GetFirstInputBlock call.
1264 * To be used within the high-level interface.<br>
1265 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
1267 const AliHLTComponentBlockData* GetNextInputBlock();
1270 * Get data specification of an input block.
1271 * Get data specification of the input block previously fetched via
1272 * GetFirstInputObject/NextInputObject or the last one if no block
1274 * @param pBlock pointer to input block
1275 * @return data specification, kAliHLTVoidDataSpec if failed
1277 AliHLTUInt32_t GetSpecification(const AliHLTComponentBlockData* pBlock);
1280 * Forward an input object to the output.
1281 * Forward the input block of an object previously fetched via
1282 * GetFirstInputObject/NextInputObject or the last one if no object
1284 * The block descriptor of the input block is forwarded to the
1285 * output block list.
1286 * @param pObject pointer to TObject
1287 * @return neg. error code if failed
1289 int Forward(const TObject* pObject);
1292 * Forward an input block to the output.
1293 * Forward the input block fetched via GetFirstInputObject/
1294 * NextInputBlock or the last one if no block specified.
1295 * The block descriptor of the input block is forwarded to the
1296 * output block list.
1297 * @param pBlock pointer to input block
1298 * @return neg. error code if failed
1300 int Forward(const AliHLTComponentBlockData* pBlock=NULL);
1303 * Insert an object into the output.
1304 * If header is specified, it will be inserted before the root object,
1305 * default is no header.
1306 * The publishing can be downscaled by means of the -pushback-period
1307 * parameter. This is especially useful for histograms which do not
1308 * need to be sent for every event.
1309 * @param pObject pointer to root object
1310 * @param dt data type 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(const TObject* pObject, const AliHLTComponentDataType& dt,
1317 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1318 void* pHeader=NULL, int headerSize=0);
1321 * Insert an object into the output.
1322 * If header is specified, it will be inserted before the root object,
1323 * default is no header.
1324 * The publishing can be downscaled by means of the -pushback-period
1325 * parameter. This is especially useful for histograms which do not
1326 * need to be sent for every event.
1327 * @param pObject pointer to root object
1328 * @param dtID data type ID of the object
1329 * @param dtOrigin data type origin of the object
1330 * @param spec data specification
1331 * @param pHeader pointer to header
1332 * @param headerSize size of Header
1333 * @return neg. error code if failed
1335 int PushBack(const TObject* pObject, const char* dtID, const char* dtOrigin,
1336 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1337 void* pHeader=NULL, int headerSize=0);
1340 * Insert an object into the output.
1341 * @param pBuffer pointer to buffer
1342 * @param iSize size of the buffer
1343 * @param dt data type of the object
1344 * @param spec data specification
1345 * @param pHeader pointer to header
1346 * @param headerSize size of Header
1347 * @return neg. error code if failed
1349 int PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt,
1350 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1351 const void* pHeader=NULL, int headerSize=0);
1354 * Insert an object into the output.
1355 * @param pBuffer pointer to buffer
1356 * @param iSize size of the buffer
1357 * @param dtID data type ID of the object
1358 * @param dtOrigin data type origin of the object
1359 * @param spec data specification
1360 * @param pHeader pointer to header
1361 * @param headerSize size of Header
1362 * @return neg. error code if failed
1364 int PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin,
1365 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1366 const void* pHeader=NULL, int headerSize=0);
1369 * Estimate size of a TObject
1371 * @return buffer size in byte
1373 int EstimateObjectSize(const TObject* pObject) const;
1376 * Create a memory file in the output stream.
1377 * This method creates a TFile object which stores all data in
1378 * memory instead of disk. The TFile object is published as binary data.
1379 * The instance can be used like a normal TFile object. The TFile::Close
1380 * or @ref CloseMemoryFile method has to be called in order to flush the
1383 * \b Note: The returned object is deleted by the framework.
1384 * @param capacity total size reserved for the memory file
1385 * @param dtID data type ID of the file
1386 * @param dtOrigin data type origin of the file
1387 * @param spec data specification
1388 * @return file handle, NULL if failed
1390 AliHLTMemoryFile* CreateMemoryFile(int capacity, const char* dtID, const char* dtOrigin,
1391 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
1394 * Create a memory file in the output stream.
1395 * This method creates a TFile object which stores all data in
1396 * memory instead of disk. The TFile object is published as binary data.
1397 * The instance can be used like a normal TFile object. The TFile::Close
1398 * or @ref CloseMemoryFile method has to be called in order to flush the
1401 * \b Note: The returned object is deleted by the framework.
1402 * @param capacity total size reserved for the memory file
1403 * @param dt data type of the file
1404 * @param spec data specification
1405 * @return file handle, NULL if failed
1407 AliHLTMemoryFile* CreateMemoryFile(int capacity,
1408 const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
1409 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
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 dtID data type ID of the file
1421 * @param dtOrigin data type origin of the file
1422 * @param spec data specification
1423 * @param capacity fraction of the available output buffer size
1424 * @return file handle, NULL if failed
1426 AliHLTMemoryFile* CreateMemoryFile(const char* dtID, const char* dtOrigin,
1427 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1428 float capacity=1.0);
1431 * Create a memory file in the output stream.
1432 * This method creates a TFile object which stores all data in
1433 * memory instead of disk. The TFile object is published as binary data.
1434 * The instance can be used like a normal TFile object. The TFile::Close
1435 * or @ref CloseMemoryFile method has to be called in order to flush the
1438 * \b Note: The returned object is deleted by the framework.
1439 * @param dt data type of the file
1440 * @param spec data specification
1441 * @param capacity fraction of the available output buffer size
1442 * @return file handle, NULL if failed
1444 AliHLTMemoryFile* CreateMemoryFile(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
1445 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1446 float capacity=1.0);
1449 * Write an object to memory file in the output stream.
1450 * @param pFile file handle
1451 * @param pObject pointer to root object
1452 * @param key key in ROOT file
1453 * @param option options, see TObject::Write
1454 * @return neg. error code if failed
1455 * - -ENOSPC no space left
1457 int Write(AliHLTMemoryFile* pFile, const TObject* pObject, const char* key=NULL, int option=TObject::kOverwrite);
1460 * Close object memory file.
1461 * @param pFile file handle
1462 * @return neg. error code if failed
1463 * - -ENOSPC buffer size too small
1465 int CloseMemoryFile(AliHLTMemoryFile* pFile);
1468 * Insert event-done data information into the output.
1469 * @param edd event-done data information
1471 int CreateEventDoneData(AliHLTComponentEventDoneData edd);
1474 * Get current run number
1476 AliHLTUInt32_t GetRunNo() const;
1479 * Get the current run type.
1481 AliHLTUInt32_t GetRunType() const;
1484 * Get the chain id of the component.
1486 const char* GetChainId() const {return fChainId.c_str();}
1489 * Get a timestamp of the current event
1490 * Exact format needs to be documented.
1492 AliHLTUInt32_t GetTimeStamp() const;
1495 * Get the period number.
1496 * Upper 28 bits (36 to 63) of the 64-bit event id
1498 AliHLTUInt32_t GetPeriodNumber() const;
1501 * Get the period number.
1502 * 24 bits, 12 to 35 of the 64-bit event id
1504 AliHLTUInt32_t GetOrbitNumber() const;
1507 * Get the bunch crossing number.
1508 * 12 bits, 0 to 12 of the 64-bit event id
1510 AliHLTUInt16_t GetBunchCrossNumber() const;
1513 * Setup the CTP accounting functionality of the base class.
1514 * The method can be invoked from DoInit() for componenets which want to
1515 * use the CTP functionality of the base class.
1517 * The AliHLTCTPData is initialized with the trigger classes from the ECS
1518 * parameters. The base class automatically increments the counters according
1519 * to the trigger pattern in the CDH before the event processing.
1524 * Get the instance of the CTP data.
1526 const AliHLTCTPData* CTPData() const {return fpCTPData;}
1529 * Check whether a combination of trigger classes is fired.
1530 * The expression can contain trigger class ids and logic operators
1531 * like &&, ||, !, and ^, and may be grouped by parentheses.
1532 * @note the function requires the setup of the CTP handling for the component by
1533 * invoking SetupCTPData() from DoInit()
1534 * @param expression a logic expression of trigger class ids
1535 * @param trigData the trigger data data
1537 bool EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const;
1540 * Check state of a trigger class.
1541 * If the class name is not part of the current trigger setup (i.e. ECS parameter
1542 * does not contain a trigger definition for this class name) the function
1544 * @note the function requires the setup of the CTP handling for the component by
1545 * invoking SetupCTPData() from DoInit()
1546 * @return -1 class name not initialized,
1547 * 0 trigger not active
1550 int CheckCTPTrigger(const char* name) const;
1553 * Get the overall solenoid field.
1557 * Get the solenoid field at point r.
1559 Double_t GetBz(const Double_t *r);
1561 * Get the solenoid field components at point r.
1563 void GetBxByBz(const Double_t r[3], Double_t b[3]);
1566 * Check whether the current event is a valid data event.
1567 * @param pTgt optional pointer to get the event type
1568 * @return true if the current event is a real data event
1570 bool IsDataEvent(AliHLTUInt32_t* pTgt=NULL) const;
1573 * Copy a struct from block data.
1574 * The function checks for block size and struct size. The least common
1575 * size will be copied to the target struct, remaining fields are initialized
1577 * The target struct must have a 32bit struct size indicator as first member.
1578 * @param pStruct target struct
1579 * @param iStructSize size of the struct
1580 * @param iBlockNo index of input block
1581 * @param structname name of the struct (log messages)
1582 * @param eventname name of the event (log messages)
1583 * @return size copied, neg. error if failed
1585 int CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
1586 const char* structname="", const char* eventname="");
1589 /** copy constructor prohibited */
1590 AliHLTComponent(const AliHLTComponent&);
1591 /** assignment operator prohibited */
1592 AliHLTComponent& operator=(const AliHLTComponent&);
1595 * Increment the internal event counter.
1596 * To be used by the friend classes AliHLTProcessor, AliHLTDataSource
1597 * and AliHLTDataSink.
1598 * @return new value of the internal event counter
1601 int IncrementEventCounter();
1604 * Find the first input block of specified data type beginning at index.
1605 * Input blocks containing a TObject have the size of the object as an
1606 * unsigned 32 bit number in the first 4 bytes. This has to match the block
1609 * kAliHLTAllDataTypes is a special data type which includes both
1610 * kAliHLTVoidDataType and kAliHLTAnyDataType.
1612 * @param dt data type
1613 * @param startIdx index to start the search
1614 * @param bObject check if this is an object
1615 * @return index of the block, -ENOENT if no block found
1619 int FindInputBlock(const AliHLTComponentDataType& dt, int startIdx=-1, int bObject=0) const;
1622 * Get index in the array of input bocks.
1623 * Calculate index and check integrety of a block data structure pointer.
1624 * @param pBlock pointer to block data
1625 * @return index of the block, -ENOENT if no block found
1629 int FindInputBlock(const AliHLTComponentBlockData* pBlock) const;
1632 * Create an object from a specified input block.
1633 * @param idx index of the input block
1634 * @param bForce force the retrieval of an object, error messages
1635 * are suppressed if \em bForce is not set
1636 * @return pointer to TObject, caller must delete the object after use
1640 TObject* CreateInputObject(int idx, int bForce=0);
1644 * Get object from the input block list. The methods first checks whether the
1645 * object was already created. If not, it is created by @ref CreateInputObject
1646 * and inserted into the list of objects.
1647 * @param idx index in the input block list
1648 * @param classname name of the class, object is checked for correct class
1650 * @param bForce force the retrieval of an object, error messages
1651 * are suppressed if \em bForce is not set
1652 * @return pointer to TObject
1656 TObject* GetInputObject(int idx, const char* classname=NULL, int bForce=0);
1659 * Clean the list of input objects.
1660 * Cleanup is done at the end of each event processing.
1662 int CleanupInputObjects();
1665 * Insert a buffer into the output block stream.
1666 * This is the only method to insert blocks into the output stream, called
1667 * from all types of the Pushback method. The actual data might have been
1668 * written to the output buffer already. In that case NULL can be provided
1669 * as buffer, only the block descriptor will be build. If a header is specified,
1670 * it will be inserted before the buffer, default is no header.
1671 * @param pBuffer pointer to buffer
1672 * @param iBufferSize size of the buffer in byte
1673 * @param dt data type
1674 * @param spec data specification
1675 * @param pHeader pointer to header
1676 * @param iHeaderSize size of Header
1677 * @return neg. error code if failed
1679 int InsertOutputBlock(const void* pBuffer, int iBufferSize,
1680 const AliHLTComponentDataType& dt,
1681 AliHLTUInt32_t spec,
1682 const void* pHeader=NULL, int iHeaderSize=0);
1685 * Add a component statistics block to the output.
1686 * @return size of the added data
1688 int AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
1689 AliHLTUInt8_t* buffer,
1690 AliHLTUInt32_t bufferSize,
1691 AliHLTUInt32_t offset,
1692 AliHLTComponentStatisticsList& stats) const;
1695 * Add a component table entry (descriptor) to the output
1696 * This is done at SOR/EOR. The component table is a list of chain ids
1697 * and 32bit ids calculated by a crc algorithm from the chian id. This
1698 * allows to tag data blocks with the id number rather than the string.
1700 * The kAliHLTDataTypeComponentTable data block currently has the string
1701 * as payload and the crc id as specification.
1702 * @return size of the added data
1704 int AddComponentTableEntry(AliHLTComponentBlockDataList& blocks,
1705 AliHLTUInt8_t* buffer,
1706 AliHLTUInt32_t bufferSize,
1707 AliHLTUInt32_t offset,
1708 const vector<AliHLTUInt32_t>& parents,
1709 int processingLevel) const;
1712 * Scan the ECS parameter string.
1713 * The framework provides both the parameters of CONFIGURE and ENGAGE
1714 * in one string in a special data block kAliHLTDataTypeECSParam
1715 * {ECSPARAM:PRIV}. The general format is
1716 * <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
1718 int ScanECSParam(const char* ecsParam);
1721 * The trigger classes are determined from the trigger and propagated by
1722 * ECS as part of the ENGAGE command parameter which is sent through the
1723 * framework during the SOR event. This function treats the value of the
1724 * parameter key CTP_TRIGGER_CLASS.
1726 int InitCTPTriggerClasses(const char* ctpString);
1729 kRequireSteeringBlocks = 0x1,
1730 kDisableComponentStat = 0x2
1733 /** The global component handler instance */
1734 static AliHLTComponentHandler* fgpComponentHandler; //! transient
1736 /** The environment where the component is running in */
1737 AliHLTAnalysisEnvironment fEnvironment; // see above
1739 /** Set by ProcessEvent before the processing starts */
1740 AliHLTEventID_t fCurrentEvent; // see above
1742 /** internal event no */
1743 int fEventCount; // see above
1745 /** the number of failed events */
1746 int fFailedEvents; // see above
1748 /** event data struct of the current event under processing */
1749 AliHLTComponentEventData fCurrentEventData; // see above
1751 /** array of input data blocks of the current event */
1752 const AliHLTComponentBlockData* fpInputBlocks; //! transient
1754 /** index of the current input block */
1755 int fCurrentInputBlock; // see above
1757 /** data type of the last block search */
1758 AliHLTComponentDataType fSearchDataType; // see above
1760 /** name of the class for the object to search for */
1761 string fClassName; // see above
1763 /** array of generated input objects */
1764 TObjArray* fpInputObjects; //! transient
1766 /** the output buffer */
1767 AliHLTUInt8_t* fpOutputBuffer; //! transient
1769 /** size of the output buffer */
1770 AliHLTUInt32_t fOutputBufferSize; // see above
1772 /** size of data written to output buffer */
1773 AliHLTUInt32_t fOutputBufferFilled; // see above
1775 /** list of ouput block data descriptors */
1776 AliHLTComponentBlockDataList fOutputBlocks; // see above
1778 /** stopwatch array */
1779 TObjArray* fpStopwatches; //! transient
1781 /** array of memory files AliHLTMemoryFile */
1782 AliHLTMemoryFilePList fMemFiles; //! transient
1784 /** descriptor of the current run */
1785 AliHLTRunDesc* fpRunDesc; //! transient
1787 /** external fct to set CDB run no, indicates external CDB initialization */
1788 void (*fCDBSetRunNoFunc)(); //! transient
1790 /** id of the component in the analysis chain */
1791 string fChainId; //! transient
1793 /** crc value of the chainid, used as a 32bit id */
1794 AliHLTUInt32_t fChainIdCrc; //! transient
1796 /** optional benchmarking for the component statistics */
1797 TStopwatch* fpBenchmark; //! transient
1799 /** component flags, cleared in Deinit */
1800 AliHLTUInt32_t fFlags; //! transient
1802 /** current event type */
1803 AliHLTUInt32_t fEventType; //! transient
1805 /** component arguments */
1806 string fComponentArgs; //! transient
1809 /** event done data */
1810 AliHLTComponentEventDoneData* fEventDoneData; //! transient
1812 /** Reserved size of the memory stored at fEventDoneData */
1813 unsigned long fEventDoneDataSize; //! transient
1815 /** Comression level for ROOT objects */
1816 int fCompressionLevel; //! transient
1818 /** size of last PushBack-serialized object */
1819 int fLastObjectSize; //! transient
1821 /** array of trigger class descriptors */
1822 AliHLTCTPData* fpCTPData; //! transient
1824 /// update period for PushBack calls
1825 int fPushbackPeriod; //! transient
1826 /// time of last executed PushBack
1827 int fLastPushBackTime; //! transient
1829 /// Event modulo for down scaling the processing rate.
1830 int fEventModulo; //! transient
1832 ClassDef(AliHLTComponent, 0)