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;
85 class AliRawDataHeader;
86 class AliHLTComponent;
87 class AliHLTMemoryFile;
89 class AliHLTReadoutList;
91 /** list of component data type structures */
92 typedef vector<AliHLTComponentDataType> AliHLTComponentDataTypeList;
93 /** list of component block data structures */
94 typedef vector<AliHLTComponentBlockData> AliHLTComponentBlockDataList;
95 /** list of component statistics struct */
96 typedef vector<AliHLTComponentStatistics> AliHLTComponentStatisticsList;
97 /** list of component pointers */
98 typedef vector<AliHLTComponent*> AliHLTComponentPList;
99 /** list of memory file pointers */
100 typedef vector<AliHLTMemoryFile*> AliHLTMemoryFilePList;
103 * @class AliHLTComponent
104 * Base class of HLT data processing components.
105 * The class provides a common interface for HLT data processing components.
106 * The interface can be accessed from the online HLT framework or the AliRoot
107 * offline analysis framework.
108 * @section alihltcomponent-properties Component identification and properties
109 * Each component must provide a unique ID, input and output data type indications,
110 * and a spawn function.
111 * @subsection alihltcomponent-req-methods Required property methods
112 * - @ref GetComponentID
113 * - @ref GetInputDataTypes (see @ref alihltcomponent-type for default
115 * - @ref GetOutputDataType (see @ref alihltcomponent-type for default
117 * - @ref GetOutputDataSize (see @ref alihltcomponent-type for default
121 * @subsection alihltcomponent-opt-mehods Optional handlers
124 * - @ref GetOutputDataTypes
125 * If the component has multiple output data types @ref GetOutputDataType
126 * should return @ref kAliHLTMultipleDataType. The framework will invoke
127 * @ref GetOutputDataTypes, a list can be filled.
129 * This function is invoked by the framework on a special event which
130 * triggers the reconfiguration of the component.
132 * @subsection alihltcomponent-processing-mehods Data processing
135 * @subsection alihltcomponent-type Component type
136 * Components can be of type
137 * - @ref kSource components which only produce data
138 * - @ref kProcessor components which consume and produce data
139 * - @ref kSink components which only consume data
141 * where data production and consumption refer to the analysis data stream. In
142 * order to indicate the type, a child component can overload the
143 * @ref GetComponentType function.
144 * @subsubsection alihltcomponent-type-std Standard implementations
145 * Components in general do not need to implement this function, standard
146 * implementations of the 3 types are available:
147 * - AliHLTDataSource for components of type @ref kSource <br>
148 * All types of data sources can inherit from AliHLTDataSource and must
149 * implement the @ref AliHLTDataSource::GetEvent method. The class
150 * also implements a standard method for @ref GetInputDataTypes.
152 * - AliHLTProcessor for components of type @ref kProcessor <br>
153 * All types of data processors can inherit from AliHLTProcessor and must
154 * implement the @ref AliHLTProcessor::DoEvent method.
156 * - AliHLTDataSink for components of type @ref kSink <br>
157 * All types of data processors can inherit from AliHLTDataSink and must
158 * implement the @ref AliHLTDataSink::DumpEvent method. The class
159 * also implements a standard method for @ref GetOutputDataType and @ref
162 * @subsection alihltcomponent-environment Running environment
164 * In order to adapt to different environments (on-line/off-line), the component
165 * gets an environment structure with function pointers. The base class provides
166 * member functions for those environment dependend functions. The member
167 * functions are used by the component implementation and are re-mapped to the
168 * corresponding functions.
170 * @section alihltcomponent-interfaces Component interfaces
171 * Each of the 3 standard component base classes AliHLTProcessor, AliHLTDataSource
172 * and AliHLTDataSink provides it's own processing method (see
173 * @ref alihltcomponent-type-std), which splits into a high and a low-level
174 * method. For the @ref alihltcomponent-low-level-interface, all parameters are
175 * shipped as function arguments, the component is supposed to write data to the
176 * output buffer and handle all block descriptors.
177 * The @ref alihltcomponent-high-level-interface is the standard processing
178 * method and will be used whenever the low-level method is not overloaded.
180 * In both cases it is necessary to calculate/estimate the size of the output
181 * buffer before the processing. Output buffers can never be allocated inside
182 * the component because of the push-architecture of the HLT.
183 * For that reason the @ref GetOutputDataSize function should return a rough
184 * estimatian of the data to be produced by the component. The component is
185 * responsible for checking the memory size and must return -ENOSPC if the
186 * available buffer is too small, and update the estimator respectively. The
187 * framework will allocate a buffer of appropriate size and call the processing
190 * @subsection alihltcomponent-error-codes Return values/Error codes
191 * For return codes, the following scheme applies:
192 * - The data processing methods have to indicate error conditions by a negative
193 * error/return code. Preferably the system error codes are used like
194 * e.g. -EINVAL. This requires to include the header
196 * \#include \<cerrno\>
198 * This schema aplies to all interface functions of the component base class.
199 * For data processing it is as follows:
200 * - If no suitable input block could be found (e.g. no clusters for the TPC cluster
201 * finder) set size to 0, block list is empty, return 0
202 * - If no ususable or significant signal could be found in the input blocks
203 * return an empty output block, set size accordingly, and return 0. An empty output
204 * block here could be either a real empty one of size 0 (in which case size also
205 * would have to be set to zero) or a block filled with just the minimum necessary
206 * accounting/meta-structures. E.g. in the TPC
208 * @subsection alihltcomponent-high-level-interface High-level interface
209 * The high-level component interface provides functionality to exchange ROOT
210 * structures between components. In contrast to the
211 * @ref alihltcomponent-low-level-interface, a couple of functions can be used
212 * to access data blocks of the input stream
213 * and send data blocks or ROOT TObject's to the output stream. The functionality
214 * is hidden from the user and is implemented by using ROOT's TMessage class.
216 * @subsubsection alihltcomponent-high-level-int-methods Interface methods
217 * The interface provides a couple of methods in order to get objects from the
218 * input, data blocks (non TObject) from the input, and to push back objects and
219 * data blocks to the output. For convenience there are several functions of
220 * identical name (and similar behavior) with different parameters defined.
221 * Please refer to the function documentation.
222 * - @ref GetNumberOfInputBlocks <br>
223 * return the number of data blocks in the input stream
224 * - @ref GetFirstInputObject <br>
225 * get the first object of a specific data type
226 * - @ref GetNextInputObject <br>
227 * get the next object of same data type as last GetFirstInputObject/Block call
228 * - @ref GetFirstInputBlock <br>
229 * get the first block of a specific data type
230 * - @ref GetNextInputBlock <br>
231 * get the next block of same data type as last GetFirstInputBlock/Block call
232 * - @ref PushBack <br>
233 * insert an object or data buffer into the output
234 * - @ref CreateEventDoneData <br>
235 * add event information to the output
237 * In addition, the processing methods are simplified a bit by cutting out most of
240 * - @ref AliHLTProcessor::DoEvent
241 * - @ref AliHLTDataSource::GetEvent
242 * - @ref AliHLTDataSink::DumpEvent
244 * \em IMPORTANT: objects and block descriptors provided by the high-level interface
245 * <b>MUST NOT BE DELETED</b> by the caller.
247 * @subsubsection alihltcomponent-high-level-int-guidelines High-level interface guidelines
248 * - Structures must inherit from the ROOT object base class TObject in order be
249 * transported by the transportation framework.
250 * - all pointer members must be transient (marked <tt>//!</tt> behind the member
251 * definition), i.e. will not be stored/transported, or properly marked
252 * (<tt>//-></tt>) in order to call the streamer of the object the member is pointing
253 * to. The latter is not recomended. Structures to be transported between components
254 * should be streamlined.
255 * - no use of stl vectors/strings, use appropriate ROOT classes instead
257 * @subsection alihltcomponent-low-level-interface Low-level interface
258 * The low-level component interface consists of the specific data processing
259 * methods for @ref AliHLTProcessor, @ref AliHLTDataSource, and @ref AliHLTDataSink.
260 * - @ref AliHLTProcessor::DoEvent
261 * - @ref AliHLTDataSource::GetEvent
262 * - @ref AliHLTDataSink::DumpEvent
264 * The base class passes all relevant parameters for data access directly on to the
265 * component. Input blocks can be accessed by means of the array <tt> blocks </tt>.
266 * Output data are written directly to shared memory provided by the pointer
267 * <tt> outputPtr </tt> and output block descriptors are inserted directly to the
268 * list <tt> outputBlocks </tt>.
270 * \b NOTE: The high-level input data access methods can be used also from the low
271 * level interface. Also the PushBack functions can be used BUT ONLY if no data is
272 * written to the output buffer and no data block descriptors are inserted into the
275 * @section alihltcomponent-initialization Component initialization and configuration
276 * The component interface provides two optional methods for component initialization
277 * and configuration. The @ref DoInit function is called once before the processing.
278 * During the event processing, a special event can trigger a reconfiguration and the
279 * @ref Reconfigure method is called. There are three possible options of initialization
281 * - default values: set directly in the source code
282 * - OCDB objects: all necessary information must be loaded from OCDB objects. The
283 * Offline Conditions Data Base stores objects specifically valid for individual runs
285 * - Component arguments: can be specified for every component in the chain
286 * configuration. The arguments can be used to override specific parameters of the
289 * As a general rule, the three options should be processed in that sequence, i.e
290 * default parameters might be overridden by OCDB configuration, and the latter one
291 * by component arguments.
293 * @subsection alihltcomponent-initialization-arguments Component arguments
294 * In normal operation, components are supposed to run without any additional argument,
295 * however such arguments can be useful for testing and debugging. The idea follows
296 * the format of command line arguments. A keyword is indicated by a dash and an
297 * optional argument might follow, e.g.:
299 * -argument1 0.5 -argument2
301 * In this case argument1 requires an additional parameter whereas argument2 does not.
302 * The arguments will be provided as an array of separated arguments.
304 * Component arguments can be classified into initialization arguments and configuration
305 * arguments. The latter are applicable for both the @ref DoInit and @ref Reconfigure
306 * method whereas initialization arguments are not applicable after DoInit.
308 * @subsection alihltcomponent-initialization-ocdb OCDB objects
309 * OCDB objects are ROOT <tt>TObjects</tt> and can be of any type. This is in particular
310 * useful for complex parameter sets. However in most cases, a simple approach of human
311 * readable command line arguments is appropriate. Such a string can be simply stored
312 * in a TObjString (take note that the TString does not derive from TObject). The
313 * same arguments as for the command line can be used. Take note that in the TObjString
314 * all arguments are separated by blanks, instead of being in an array of separate
317 * The base class provides two functions regarding OCDB objects:
318 * - LoadAndExtractOCDBObject() loads the OCDB entry for the specified path and extracts
319 * the TObject from it.
320 * - ConfigureFromCDBTObjString() can load a number of OCDB objects and calls the
321 * argument parsing ConfigureFromArgumentString
324 * @subsection alihltcomponent-initialization-sequence Initialization sequence
325 * Using the approach of <tt>TObjString</tt>-type configuration objects allows to treat
326 * configuration from both @ref DoInit and @ref Reconfigure in the same way.
328 * The base class provides the function ConfigureFromArgumentString() which loops over
329 * all arguments and calls the child's method ScanConfigurationArgument(). Here the
330 * actual treatment of the argument and its parameters needs to be implemented.
331 * ConfigureFromArgumentString() can treat both arrays of arguments and arguments in
332 * one single string separated by blanks. The two options can be mixed.
334 * A second bas class function ConfigureFromCDBTObjString() allows to configure
335 * directly from a number of OCDB objects. This requires the entries to be of
336 * type TObjString and the child implementation of ScanConfigurationArgument().
338 * @section alihltcomponent-handling Component handling
339 * The handling of HLT analysis components is carried out by the AliHLTComponentHandler.
340 * Component are registered automatically at load-time of the component shared library
341 * under the following suppositions:
342 * - the component library has to be loaded from the AliHLTComponentHandler using the
343 * @ref AliHLTComponentHandler::LoadLibrary method.
344 * - the library defines an AliHLTModuleAgent which registers all components.
345 * See AliHLTModuleAgent::RegisterComponents <br>
347 * - the component implementation defines one global object (which is generated
348 * when the library is loaded) <br>
350 * @subsection alihltcomponent-design-rules General design considerations
351 * The analysis code should be implemented in one or more destict class(es). A
352 * \em component should be implemented which interface the destict analysis code to the
353 * component interface. This component generates the analysis object dynamically. <br>
355 * Assume you have an implemetation <tt> AliHLTDetMyAnalysis </tt>, another class <tt>
356 * AliHLTDetMyAnalysisComponent </tt> contains:
359 * AliHLTDetMyAnalysis* fMyAnalysis; //!
361 * The object should then be instantiated in the DoInit handler of
362 * <tt>AliHLTDetMyAnalysisComponent </tt>, and cleaned in the DoDeinit handler.
365 * - avoid big static arrays in the component, allocate the memory at runtime
366 * - allocate all kind of complex data members (like classes, ROOT TObjects of
367 * any kind) dynamically in DoInit and clean up in DoDeinit
369 * @section alihlt_component_arguments Default arguments
370 * The component base class provides some default arguments:
371 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
372 * \li -loglevel=level <br>
373 * \li -object-compression=level <br>
374 * compression level for ROOT objects, default is defined by
375 * @ref ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION
376 * \li -pushback-period=period <br>
377 * scale down for PushBack of objects, shipped only for one event
378 * every <i>period</i> seconds
380 * @ingroup alihlt_component
381 * @section alihltcomponent-members Class members
383 class AliHLTComponent : public AliHLTLogging {
385 /** standard constructor */
387 /** standard destructor */
388 virtual ~AliHLTComponent();
390 /** component type definitions */
391 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
394 * Init function to prepare data processing.
395 * Initialization of common data structures for a sequence of events.
396 * The call is redirected to the internal method DoInit which can be
397 * overridden by the child class.
398 * During Init also the environment structure is passed to the component.
399 * @param comenv environment pointer with environment dependent function
401 * @param environParam additional parameter for function calls, the pointer
403 * @param argc size of the argument array
404 * @param argv augment array for component initialization
406 virtual int Init( const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv );
409 * Clean-up function to terminate data processing.
410 * Clean-up of common data structures after data processing.
411 * The call is redirected to the internal method @ref DoDeinit which can be
412 * overridden by the child class.
414 virtual int Deinit();
417 * Processing of one event.
418 * The method is the entrance of the event processing. The parameters are
419 * cached for uses with the high-level interface and the DoProcessing
420 * implementation is called.
427 * @param outputBlockCnt out: size of the output block array, set by the component
428 * @param outputBlocks out: the output block array is allocated internally
430 * @return neg. error code if failed
432 int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
433 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
434 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
435 AliHLTComponentBlockData*& outputBlocks,
436 AliHLTComponentEventDoneData*& edd );
439 * Internal processing of one event.
440 * The method is pure virtual and implemented by the child classes
441 * - @ref AliHLTProcessor
442 * - @ref AliHLTDataSource
443 * - @ref AliHLTDataSink
450 * @param outputBlocks out: the output block array is allocated internally
452 * @return neg. error code if failed
454 virtual int DoProcessing( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
455 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
456 AliHLTUInt32_t& size,
457 AliHLTComponentBlockDataList& outputBlocks,
458 AliHLTComponentEventDoneData*& edd ) = 0;
462 * The function must not be called when running in AliRoot unless it it
463 * really wanted. The CDB path will be set to the specified path, which might
464 * override the path initialized at the beginning of the AliRoot reconstruction.
466 * The method is used from the external interface in order to set the correct
467 * path when running on-line. The function also initializes the function
468 * callback for setting the run no during operation.
470 * A separation of library and component handling is maybe appropriate in the
471 * future. Using the global component handler here is maybe not the cleanest
473 * @param cdbPath path of the CDB
474 * @param pHandler the component handler used for llibrary handling.
476 int InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler);
479 * Set the run no for the CDB.
480 * The function must not be called when running in AliRoot unless it it
481 * really wanted. The CDB path will be set to the specified path, which might
482 * override the run no initialized at the beginning of the AliRoot reconstruction.
483 * InitCDB() has to be called before in order to really change the CDB settings.
485 * The method is used from the external interface in order to set the correct
486 * path when running on-line.
488 int SetCDBRunNo(int runNo);
491 * Set the run description.
492 * The run description is set before the call of Init() -> DoInit().
493 * @note: This functionality has been added in Juli 2008. The transmission of
494 * run properties by a special SOR (SOD event in DAQ terminalogy but this was
495 * changed after the HLT interface was designed) event is not sufficient because
496 * the data might be needed already in the DoInit handler of the component.
497 * @param desc run descriptor, currently only the run no member is used
498 * @param runType originally, run type was supposed to be a number and part
499 * of the run descriptor. But it was defined as string later
501 int SetRunDescription(const AliHLTRunDesc* desc, const char* runType);
504 * Set the component description.
505 * The description string can contain tokens separated by blanks, a token
506 * consists of a key and an optional value separated by '='.
508 * \li -chainid=id string id within the chain of the instance
510 * @param desc component description
512 int SetComponentDescription(const char* desc);
515 * Set the running environment for the component.
516 * Originally, the environment was set in the Init function. However, the setup of
517 * the CDB is required before. In order to have proper logging functionality, the
518 * environment is required.
519 * @param comenv environment pointer with environment dependent function
521 * @param environParam additional parameter for function calls, the pointer
524 int SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam);
526 // Information member functions for registration.
529 * Get the type of the component.
530 * The function is pure virtual and must be implemented by the child class.
531 * @return component type id
533 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
536 * Get the id of the component.
537 * Each component is identified by a unique id.
538 * The function is pure virtual and must be implemented by the child class.
539 * @return component id (string)
541 virtual const char* GetComponentID() = 0;
544 * Get the input data types of the component.
545 * The function is pure virtual and must be implemented by the child class.
546 * @return list of data types in the vector reference
548 virtual void GetInputDataTypes( AliHLTComponentDataTypeList& ) = 0;
551 * Get the output data type of the component.
552 * The function is pure virtual and must be implemented by the child class.
553 * @return output data type
555 virtual AliHLTComponentDataType GetOutputDataType() = 0;
558 * Get the output data types of the component.
559 * The function can be implemented to indicate multiple output data types
560 * in the target array.
561 * @ref GetOutputDataType must return @ref kAliHLTMultipleDataType in order
562 * to invoke this method.
563 * @param tgtList list to receive the data types
564 * @return no of output data types, data types in the target list
566 virtual int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList);
569 * Get a ratio by how much the data volume is shrunken or enhanced.
570 * The function is pure virtual and must be implemented by the child class.
571 * @param constBase <i>return</i>: additive part, independent of the
573 * @param inputMultiplier <i>return</i>: multiplication ratio
574 * @return values in the reference variables
576 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
579 * Get a list of OCDB object description.
580 * The list of objects is provided in a TMap
581 * - key: complete OCDB path, e.g. GRP/GRP/Data
582 * - value: short description why the object is needed
583 * Key and value objects created inside this class go into ownership of
585 * @param targetMap TMap instance receiving the list
588 virtual void GetOCDBObjectDescription( TMap* const targetArray);
592 * Each component must implement a spawn function to create a new instance of
593 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
594 * @return new class instance
596 virtual AliHLTComponent* Spawn() = 0;
599 * check the availability of the OCDB entry descriptions in the TMap
600 * key : complete OCDB path of the entry
601 * value : auxiliary object - short description
602 * if the external map was not provided the function invokes
603 * interface function GetOCDBObjectDescription() to retrieve the list.
604 * @param externList map of entries to be tested
605 * @result 0 if all found, -ENOENT if objects not found
607 int CheckOCDBEntries(const TMap* const externList=NULL);
610 * Find matching data types between this component and a consumer component.
611 * Currently, a component can produce only one type of data. This restriction is most
612 * likely to be abolished in the future.
613 * @param pConsumer a component and consumer of the data produced by this component
614 * @param tgtList reference to a vector list to receive the matching data types.
615 * @return >= 0 success, neg. error code if failed
617 int FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList);
620 * Set the global component handler.
621 * The static method is needed for the automatic registration of components.
623 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
626 * Clear the global component handler.
627 * The static method is needed for the automatic registration of components.
629 static int UnsetGlobalComponentHandler();
632 * Helper function to convert the data type to a string.
633 * @param type data type structure
634 * @param mode 0 print string origin:type <br>
638 static string DataType2Text( const AliHLTComponentDataType& type, int mode=0);
641 * Calculate a CRC checksum of a data buffer.
642 * Polynomial for the calculation is 0xD8.
644 static AliHLTUInt32_t CalculateChecksum(const AliHLTUInt8_t* buffer, int size);
647 * Helper function to print content of data type.
649 static void PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format=NULL);
652 * helper function to initialize AliHLTComponentEventData structure
654 static void FillEventData(AliHLTComponentEventData& evtData);
657 * Print info on an AliHLTComponentDataType structure
658 * This is just a helper function to examine an @ref AliHLTComponentDataType
661 static void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
664 * Fill AliHLTComponentBlockData structure with default values.
665 * @param blockData reference to data structure
667 static void FillBlockData( AliHLTComponentBlockData& blockData );
670 * Fill AliHLTComponentShmData structure with default values.
671 * @param shmData reference to data structure
673 static void FillShmData( AliHLTComponentShmData& shmData );
676 * Fill AliHLTComponentDataType structure with default values.
677 * @param dataType reference to data structure
679 static void FillDataType( AliHLTComponentDataType& dataType );
682 * Copy data type structure
683 * Copies the value an AliHLTComponentDataType structure to another one
684 * @param[out] tgtdt target structure
685 * @param[in] srcdt source structure
687 static void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
690 * Set the ID and Origin of an AliHLTComponentDataType structure.
691 * The function sets the fStructureSize member and copies the strings
692 * to the ID and Origin. Only characters from the valid part of the string
693 * are copied, the rest is filled with 0's. <br>
694 * Please note that the fID and fOrigin members are not strings, just arrays of
695 * chars of size @ref kAliHLTComponentDataTypefIDsize and
696 * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
697 * a terminating zero. <br>
698 * It is possible to pass NULL pointers as id or origin argument, in that case they
700 * @param tgtdt target data type structure
701 * @param id ID string
702 * @param origin Origin string
704 static void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
707 * Set the ID and Origin of an AliHLTComponentDataType structure.
708 * Given the fact that the data type ID is 64bit wide and origin 32, this helper
709 * function sets the data type from those two parameters.
710 * @param dt target data type structure
712 * @param orig 32bit origin
714 static void SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t orig);
717 * Extract a component table entry from the payload buffer.
718 * The entry consists of the AliHLTComponentTableEntry structure, the array of
719 * parents and a description string of the format 'chain-id{component-id:component-args}'.
720 * The function fills all the variables after a consistency check.
722 static int ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
723 string& chainId, string& compId, string& compParam,
724 vector<AliHLTUInt32_t>& parents);
727 * Extracts the different data parts from the trigger data structure.
728 * [in] @param trigData The trigger data as passed to the DoProcessing method.
729 * [out] @param attributes The data block attributes given by the HLT framework.
730 * [out] @param status The HLT status bits given by the HLT framework.
731 * [out] @param cdh The common data header received from DDL links.
732 * [out] @param readoutlist The readout list to fill with readout list bits
733 * passed on by the HLT framework.
734 * [in] @param printErrors If true then error messages are generated as necessary
735 * and suppressed otherwise.
736 * @note If any of the output parameters are set to NULL then the field is not set.
737 * For example, the following line will only fill the CDH pointer.
739 * AliRawDataHeader* cdh;
740 * ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL);
742 * @return the zero on success and one of the following error codes on failure.
743 * if a non-zero error code is returned then none of the output parameters are
745 * \li -ENOENT The <i>trigData</i> structure size is wrong.
746 * \li -EBADF The <i>trigData</i> data size is wrong.
747 * \li -EBADMSG The common data header (CDH) in the trigger data has the wrong
748 * number of words indicated.
749 * \li -EPROTO The readout list structure in the trigger data has the wrong
750 * number of words indicated.
752 static int ExtractTriggerData(
753 const AliHLTComponentTriggerData& trigData,
754 const AliHLTUInt8_t (**attributes)[gkAliHLTBlockDAttributeCount],
755 AliHLTUInt64_t* status,
756 const AliRawDataHeader** cdh,
757 AliHLTReadoutList* readoutlist,
758 bool printErrors = false
762 * Extracts the readout list from a trigger data structure.
763 * [in] @param trigData The trigger data as passed to the DoProcessing method.
764 * [out] @param list The output readout list to fill.
765 * [in] @param printErrors If true then error messages are generated as necessary
766 * and suppressed otherwise.
767 * @return the zero on success or one of the error codes returned by ExtractTriggerData.
769 static int GetReadoutList(
770 const AliHLTComponentTriggerData& trigData, AliHLTReadoutList& list,
771 bool printErrors = false
774 return ExtractTriggerData(trigData, NULL, NULL, NULL, &list, printErrors);
778 * Stopwatch type for benchmarking.
780 enum AliHLTStopwatchType {
781 /** total time for event processing */
783 /** detector algorithm w/o interface callbacks */
789 /** number of types */
794 * Helper class for starting and stopping a stopwatch.
795 * The guard can be used by instantiating an object in a function. The
796 * specified stopwatch is started and the previous stopwatch put on
797 * hold. When the function is terminated, the object is deleted automatically
798 * deleted, stopping the stopwatch and starting the one on hold.<br>
799 * \em IMPORTANT: never create dynamic objects from this guard as this violates
800 * the idea of a guard.
802 class AliHLTStopwatchGuard {
804 /** standard constructor (not for use) */
805 AliHLTStopwatchGuard();
807 AliHLTStopwatchGuard(TStopwatch* pStart);
808 /** copy constructor (not for use) */
809 AliHLTStopwatchGuard(const AliHLTStopwatchGuard&);
810 /** assignment operator (not for use) */
811 AliHLTStopwatchGuard& operator=(const AliHLTStopwatchGuard&);
813 ~AliHLTStopwatchGuard();
817 * Hold the previous guard for the existence of this guard.
818 * Checks whether this guard controls a new stopwatch. In that case, the
819 * previous guard and its stopwatch are put on hold.
820 * @param pSucc instance of the stopwatch of the new guard
821 * @return 1 if pSucc is a different stopwatch which should
823 * 0 if it controls the same stopwatch
825 int Hold(const TStopwatch* pSucc);
828 * Resume the previous guard.
829 * Checks whether the peceeding guard controls a different stopwatch. In that
830 * case, the its stopwatch is resumed.
831 * @param pSucc instance of the stopwatch of the new guard
832 * @return 1 if pSucc is a different stopwatch which should
834 * 0 if it controls the same stopwatch
836 int Resume(const TStopwatch* pSucc);
838 /** the stopwatch controlled by this guard */
839 TStopwatch* fpStopwatch; //!transient
841 /** previous stopwatch guard, put on hold during existence of the guard */
842 AliHLTStopwatchGuard* fpPrec; //!transient
844 /** active stopwatch guard */
845 static AliHLTStopwatchGuard* fgpCurrent; //!transient
849 * Set a stopwatch for a given purpose.
850 * @param pSW stopwatch object
851 * @param type type of the stopwatch
853 int SetStopwatch(TObject* pSW, AliHLTStopwatchType type=kSWBase);
856 * Init a set of stopwatches.
857 * @param pStopwatches object array of stopwatches
859 int SetStopwatches(TObjArray* pStopwatches);
862 * Customized logging function.
863 * The chain id, component id and pointer is added at the beginning of each message.
865 int LoggingVarargs(AliHLTComponentLogSeverity severity,
866 const char* originClass, const char* originFunc,
867 const char* file, int line, ... ) const;
870 * Get size of last serialized object.
871 * During PushBack, TObjects are serialized in a separate buffer. The
872 * size of the last object can be retrieved by this function.
874 * This might be especially useful for PushBack failures caused by too
875 * small output buffer.
877 int GetLastObjectSize() const {return fLastObjectSize;}
882 * Default method for the internal initialization.
883 * The method is called by @ref Init
885 virtual int DoInit( int argc, const char** argv );
888 * Default method for the internal clean-up.
889 * The method is called by @ref Deinit
891 virtual int DoDeinit();
894 * Reconfigure the component.
895 * The method is called when an event of type @ref kAliHLTDataTypeComConf
896 * {COM_CONF:PRIV} is received by the component. If the event is sent as
897 * part of a normal event, the component configuration is called first.
899 * The CDB path parameter specifies the path in the CDB, i.e. without
900 * leading absolute path of the CDB location. The framework might also
901 * provide the id of the component in the analysis chain.
903 * The actual sequence of configuration depends on the component. As a
904 * general rule, the component should load the specific OCDB object if
905 * provided as parameter, and load the default objects if the parameter
906 * is NULL. However, other schemes are possible. See @ref
908 * \b Note: The CDB will be initialized by the framework, either already set
909 * from AliRoot or from the wrapper interface during initialization.
911 * @param cdbEntry path of the cdbEntry
912 * @param chainId the id/name of the component in the current analysis
913 * chain. This is not necessarily the same as what is
914 * returned by the GetComponentID() method.
915 * @note both parameters can be NULL, check before usage
917 virtual int Reconfigure(const char* cdbEntry, const char* chainId);
920 * Read the Preprocessor values.
921 * The function is invoked when the component is notified about available/
922 * updated data points from the detector Preprocessors. The 'modules'
923 * argument contains all detectors for which the Preprocessors have
924 * updated data points. The component has to implement the CDB access to
925 * get the desired data points.
926 * @param modules detectors for which the Preprocessors have updated
927 * data points: TPC, TRD, ITS, PHOS, MUON, or ALL if
928 * no argument was received.
929 * @return neg. error code if failed
931 virtual int ReadPreprocessorValues(const char* modules);
934 * Child implementation to scan a number of configuration arguments.
935 * The method is invoked by the framework in conjunction with the
936 * common framework functions ConfigureFromArgumentString and
937 * ConfigureFromCDBTObjString.
938 * Function needs to scan the argument and optional additional
939 * parameters and returns the number of elements in the array which
943 * @return number of arguments which have been scanned or neg error
944 * code if failed <br>
945 * \li -EINVAL unknown argument
946 * \li -EPROTO protocol error, e.g. missing parameter
948 virtual int ScanConfigurationArgument(int argc, const char** argv);
951 * Custom handler for the SOR event.
952 * Is invoked from the base class if an SOR event is in the block list.
953 * The handler is called before the processing function. The processing
954 * function is skipped if there are no other data blocks available.
956 * The SOR event is generated by the PubSub framework in response to
957 * the DAQ start of data (SOD - has been renamed after HLT interface
958 * was designed). The SOD event consists of 3 blocks:
959 * - ::kAliHLTDataTypeEvent block: spec ::gkAliEventTypeStartOfRun
960 * - SOD block of type ::kAliHLTDataTypeSOR, payload: AliHLTRunDesc struct
961 * - run type block ::kAliHLTDataTypeRunType, payload: run type string
963 * Run properties can be retrieved by getters like GetRunNo().
964 * @return neg. error code if failed
966 virtual int StartOfRun();
969 * Custom handler for the EOR event.
970 * Is invoked from the base class if an EOR event is in the block list.
971 * The handler is called before the processing function. The processing
972 * function is skipped if there are no other data blocks available.
974 * See StartOfRun() for more comments of the sequence of steering events.
976 * @return neg. error code if failed
978 virtual int EndOfRun();
981 * Check whether a component requires all steering blocks.
982 * Childs can overload in order to indicate that they want to
983 * receive also the steering data blocks. There is also the
984 * possibility to add the required data types to the input
985 * data type list in GetInputDataTypes().
987 virtual bool RequireSteeringBlocks() const {return false;}
990 * General memory allocation method.
991 * All memory which is going to be used 'outside' of the interface must
992 * be provided by the framework (online or offline).
993 * The method is redirected to a function provided by the current
994 * framework. Function pointers are transferred via the @ref
995 * AliHLTAnalysisEnvironment structure.
997 void* AllocMemory( unsigned long size );
1000 * Helper function to create a monolithic BlockData description block out
1001 * of a list BlockData descriptors.
1002 * For convenience, inside the interface vector lists are used, to make the
1003 * interface pure C style, monilithic blocks must be exchanged.
1004 * The method is redirected to a function provided by the current
1005 * framework. Function pointers are transferred via the @ref
1006 * AliHLTAnalysisEnvironment structure.
1008 int MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
1009 AliHLTComponentBlockData** outputBlocks );
1012 * Fill the EventDoneData structure.
1013 * The method is redirected to a function provided by the current
1014 * framework. Function pointers are transferred via the @ref
1015 * AliHLTAnalysisEnvironment structure.
1017 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) const;
1020 * Allocate an EventDoneData structure for the current event .
1021 * The method allocates the memory internally and does not interact with the current Framework.
1022 * The allocated data structure is empty initially and can be filled by calls to the
1023 * @ref PushEventDoneData method. The memory will be automatically released after the event has been processed.
1026 int ReserveEventDoneData( unsigned long size );
1029 * Push a 32 bit word of data into event done data for the current event which
1030 * has previously been allocated by the @ref ReserveEventDoneData method.
1032 int PushEventDoneData( AliHLTUInt32_t eddDataWord );
1035 * Release event done data previously reserved by @ref ReserveEventDoneData
1037 void ReleaseEventDoneData();
1040 * Get the pointer to the event done data available/built so far for the current event via
1041 * @ref ReserveEventDoneData and @ref PushEventDoneData
1043 AliHLTComponentEventDoneData* GetCurrentEventDoneData() const
1045 return fEventDoneData;
1049 * Helper function to convert the data type to a string.
1051 void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]) const;
1054 * Loop through a list of component arguments.
1055 * The list can be either an array of separated strings or one single
1056 * string containing blank separated arguments, or both mixed.
1057 * ScanConfigurationArgument() is called to allow the component to treat
1058 * the individual arguments.
1059 * @return neg. error code if failed
1061 int ConfigureFromArgumentString(int argc, const char** argv);
1064 * Read configuration objects from OCDB and configure from
1065 * the content of TObjString entries.
1066 * @param entries blank separated list of OCDB paths
1067 * @return neg. error code if failed
1069 int ConfigureFromCDBTObjString(const char* entries);
1072 * Load specified entry from the OCDB and extract the object.
1073 * The entry is explicitely unloaded from the cache before it is loaded.
1074 * @param path path of the entry under to root of the OCDB
1075 * @param version version of the entry
1076 * @param subVersion subversion of the entry
1078 TObject* LoadAndExtractOCDBObject(const char* path, int version = -1, int subVersion = -1);
1083 * @return value of the internal event counter
1085 int GetEventCount() const;
1088 * Get the number of input blocks.
1089 * @return number of input blocks
1091 int GetNumberOfInputBlocks() const;
1094 * Get id of the current event
1097 AliHLTEventID_t GetEventId() const;
1100 * Get the first object of a specific data type from the input data.
1101 * The High-level methods provide functionality to transfer ROOT data
1102 * structures which inherit from TObject.
1104 * The method looks for the first ROOT object of type dt in the input stream.
1105 * If also the class name is provided, the object is checked for the right
1106 * class type. The input data block needs a certain structure, namely the
1107 * buffer size as first word. If the cross check fails, the retrieval is
1108 * silently abandoned, unless the \em bForce parameter is set.<br>
1109 * \b Note: THE OBJECT MUST NOT BE DELETED by the caller.
1111 * If called without parameters, the function tries to create objects from
1112 * all available input blocks, also the ones of data type kAliHLTVoidDataType
1113 * which are not matched by kAliHLTAnyDataType.
1115 * @param dt data type of the object
1116 * @param classname class name of the object
1117 * @param bForce force the retrieval of an object, error messages
1118 * are suppressed if \em bForce is not set
1119 * @return pointer to @ref TObject, NULL if no objects of specified type
1122 const TObject* GetFirstInputObject(const AliHLTComponentDataType& dt=kAliHLTAllDataTypes,
1123 const char* classname=NULL,
1127 * Get the first object of a specific data type from the input data.
1128 * The High-level methods provide functionality to transfer ROOT data
1129 * structures which inherit from TObject.
1130 * The method looks for the first ROOT object of type specified by the ID and
1131 * Origin strings in the input stream.
1132 * If also the class name is provided, the object is checked for the right
1133 * class type. The input data block needs a certain structure, namely the
1134 * buffer size as first word. If the cross check fails, the retrieval is
1135 * silently abandoned, unless the \em bForce parameter is set.<br>
1136 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
1137 * @param dtID data type ID of the object
1138 * @param dtOrigin data type origin 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 char* dtID,
1146 const char* dtOrigin,
1147 const char* classname=NULL,
1151 * Get the next object of a specific data type from the input data.
1152 * The High-level methods provide functionality to transfer ROOT data
1153 * structures which inherit from TObject.
1154 * The method looks for the next ROOT object of type and class specified
1155 * to the previous @ref GetFirstInputObject call.<br>
1156 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
1157 * @param bForce force the retrieval of an object, error messages
1158 * are suppressed if \em bForce is not set
1159 * @return pointer to @ref TObject, NULL if no more objects available
1161 const TObject* GetNextInputObject(int bForce=0);
1164 * Get data type of an input block.
1165 * Get data type of the object previously fetched via
1166 * GetFirstInputObject/NextInputObject or the last one if no object
1168 * @param pObject pointer to TObject
1169 * @return data specification, kAliHLTVoidDataSpec if failed
1171 AliHLTComponentDataType GetDataType(const TObject* pObject=NULL);
1174 * Get data specification of an input block.
1175 * Get data specification of the object previously fetched via
1176 * GetFirstInputObject/NextInputObject or the last one if no object
1178 * @param pObject pointer to TObject
1179 * @return data specification, kAliHLTVoidDataSpec if failed
1181 AliHLTUInt32_t GetSpecification(const TObject* pObject=NULL);
1184 * Get the first block of a specific data type from the input data.
1185 * The method looks for the first block of type dt in the input stream.
1186 * It is intended to be used within the high-level interface.<br>
1187 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
1189 * If called without parameters, the function works on all input blocks,
1190 * also the ones of data type kAliHLTVoidDataType which are not matched by
1191 * kAliHLTAnyDataType.
1193 * @param dt data type of the block
1194 * @return pointer to @ref AliHLTComponentBlockData
1196 const AliHLTComponentBlockData* GetFirstInputBlock(const AliHLTComponentDataType& dt=kAliHLTAllDataTypes);
1199 * Get the first block of a specific data type from the input data.
1200 * The method looks for the first block of type specified by the ID and
1201 * Origin strings in the input stream. It is intended
1202 * to be used within the high-level interface.<br>
1203 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
1204 * @param dtID data type ID of the block
1205 * @param dtOrigin data type origin of the block
1206 * @return pointer to @ref AliHLTComponentBlockData
1208 const AliHLTComponentBlockData* GetFirstInputBlock(const char* dtID,
1209 const char* dtOrigin);
1212 * Get input block by index.<br>
1213 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
1214 * @return pointer to AliHLTComponentBlockData, NULL if index out of range
1216 const AliHLTComponentBlockData* GetInputBlock(int index) const;
1219 * Get the next block of a specific data type from the input data.
1220 * The method looks for the next block of type and class specified
1221 * to the previous @ref GetFirstInputBlock call.
1222 * To be used within the high-level interface.<br>
1223 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
1225 const AliHLTComponentBlockData* GetNextInputBlock();
1228 * Get data specification of an input block.
1229 * Get data specification of the input block previously fetched via
1230 * GetFirstInputObject/NextInputObject or the last one if no block
1232 * @param pBlock pointer to input block
1233 * @return data specification, kAliHLTVoidDataSpec if failed
1235 AliHLTUInt32_t GetSpecification(const AliHLTComponentBlockData* pBlock);
1238 * Forward an input object to the output.
1239 * Forward the input block of an object previously fetched via
1240 * GetFirstInputObject/NextInputObject or the last one if no object
1242 * The block descriptor of the input block is forwarded to the
1243 * output block list.
1244 * @param pObject pointer to TObject
1245 * @return neg. error code if failed
1247 int Forward(const TObject* pObject);
1250 * Forward an input block to the output.
1251 * Forward the input block fetched via GetFirstInputObject/
1252 * NextInputBlock or the last one if no block specified.
1253 * The block descriptor of the input block is forwarded to the
1254 * output block list.
1255 * @param pBlock pointer to input block
1256 * @return neg. error code if failed
1258 int Forward(const AliHLTComponentBlockData* pBlock=NULL);
1261 * Insert an object into the output.
1262 * If header is specified, it will be inserted before the root object,
1263 * default is no header.
1264 * The publishing can be downscaled by means of the -pushback-period
1265 * parameter. This is especially useful for histograms which do not
1266 * need to be sent for every event.
1267 * @param pObject pointer to root object
1268 * @param dt data type of the object
1269 * @param spec data specification
1270 * @param pHeader pointer to header
1271 * @param headerSize size of Header
1272 * @return neg. error code if failed
1274 int PushBack(TObject* pObject, const AliHLTComponentDataType& dt,
1275 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1276 void* pHeader=NULL, int headerSize=0);
1279 * Insert an object into the output.
1280 * If header is specified, it will be inserted before the root object,
1281 * default is no header.
1282 * The publishing can be downscaled by means of the -pushback-period
1283 * parameter. This is especially useful for histograms which do not
1284 * need to be sent for every event.
1285 * @param pObject pointer to root object
1286 * @param dtID data type ID of the object
1287 * @param dtOrigin data type origin of the object
1288 * @param spec data specification
1289 * @param pHeader pointer to header
1290 * @param headerSize size of Header
1291 * @return neg. error code if failed
1293 int PushBack(TObject* pObject, const char* dtID, const char* dtOrigin,
1294 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1295 void* pHeader=NULL, int headerSize=0);
1298 * Insert an object into the output.
1299 * @param pBuffer pointer to buffer
1300 * @param iSize size of the buffer
1301 * @param dt data type of the object
1302 * @param spec data specification
1303 * @param pHeader pointer to header
1304 * @param headerSize size of Header
1305 * @return neg. error code if failed
1307 int PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt,
1308 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1309 const void* pHeader=NULL, int headerSize=0);
1312 * Insert an object into the output.
1313 * @param pBuffer pointer to buffer
1314 * @param iSize size of the buffer
1315 * @param dtID data type ID of the object
1316 * @param dtOrigin data type origin of the object
1317 * @param spec data specification
1318 * @param pHeader pointer to header
1319 * @param headerSize size of Header
1320 * @return neg. error code if failed
1322 int PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin,
1323 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1324 const void* pHeader=NULL, int headerSize=0);
1327 * Estimate size of a TObject
1329 * @return buffer size in byte
1331 int EstimateObjectSize(TObject* pObject) const;
1334 * Create a memory file in the output stream.
1335 * This method creates a TFile object which stores all data in
1336 * memory instead of disk. The TFile object is published as binary data.
1337 * The instance can be used like a normal TFile object. The TFile::Close
1338 * or @ref CloseMemoryFile method has to be called in order to flush the
1341 * \b Note: The returned object is deleted by the framework.
1342 * @param capacity total size reserved for the memory file
1343 * @param dtID data type ID of the file
1344 * @param dtOrigin data type origin of the file
1345 * @param spec data specification
1346 * @return file handle, NULL if failed
1348 AliHLTMemoryFile* CreateMemoryFile(int capacity, const char* dtID, const char* dtOrigin,
1349 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
1352 * Create a memory file in the output stream.
1353 * This method creates a TFile object which stores all data in
1354 * memory instead of disk. The TFile object is published as binary data.
1355 * The instance can be used like a normal TFile object. The TFile::Close
1356 * or @ref CloseMemoryFile method has to be called in order to flush the
1359 * \b Note: The returned object is deleted by the framework.
1360 * @param capacity total size reserved for the memory file
1361 * @param dt data type of the file
1362 * @param spec data specification
1363 * @return file handle, NULL if failed
1365 AliHLTMemoryFile* CreateMemoryFile(int capacity,
1366 const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
1367 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
1370 * Create a memory file in the output stream.
1371 * This method creates a TFile object which stores all data in
1372 * memory instead of disk. The TFile object is published as binary data.
1373 * The instance can be used like a normal TFile object. The TFile::Close
1374 * or @ref CloseMemoryFile method has to be called in order to flush the
1377 * \b Note: The returned object is deleted by the framework.
1378 * @param dtID data type ID of the file
1379 * @param dtOrigin data type origin of the file
1380 * @param spec data specification
1381 * @param capacity fraction of the available output buffer size
1382 * @return file handle, NULL if failed
1384 AliHLTMemoryFile* CreateMemoryFile(const char* dtID, const char* dtOrigin,
1385 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1386 float capacity=1.0);
1389 * Create a memory file in the output stream.
1390 * This method creates a TFile object which stores all data in
1391 * memory instead of disk. The TFile object is published as binary data.
1392 * The instance can be used like a normal TFile object. The TFile::Close
1393 * or @ref CloseMemoryFile method has to be called in order to flush the
1396 * \b Note: The returned object is deleted by the framework.
1397 * @param dt data type of the file
1398 * @param spec data specification
1399 * @param capacity fraction of the available output buffer size
1400 * @return file handle, NULL if failed
1402 AliHLTMemoryFile* CreateMemoryFile(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
1403 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1404 float capacity=1.0);
1407 * Write an object to memory file in the output stream.
1408 * @param pFile file handle
1409 * @param pObject pointer to root object
1410 * @param key key in ROOT file
1411 * @param option options, see TObject::Write
1412 * @return neg. error code if failed
1413 * - -ENOSPC no space left
1415 int Write(AliHLTMemoryFile* pFile, const TObject* pObject, const char* key=NULL, int option=TObject::kOverwrite);
1418 * Close object memory file.
1419 * @param pFile file handle
1420 * @return neg. error code if failed
1421 * - -ENOSPC buffer size too small
1423 int CloseMemoryFile(AliHLTMemoryFile* pFile);
1426 * Insert event-done data information into the output.
1427 * @param edd event-done data information
1429 int CreateEventDoneData(AliHLTComponentEventDoneData edd);
1432 * Get current run number
1434 AliHLTUInt32_t GetRunNo() const;
1437 * Get the current run type.
1439 AliHLTUInt32_t GetRunType() const;
1442 * Get the chain id of the component.
1444 const char* GetChainId() const {return fChainId.c_str();}
1447 * Get a timestamp of the current event
1448 * Exact format needs to be documented.
1450 AliHLTUInt32_t GetTimeStamp() const;
1453 * Get the period number.
1454 * Upper 28 bits (36 to 63) of the 64-bit event id
1456 AliHLTUInt32_t GetPeriodNumber() const;
1459 * Get the period number.
1460 * 24 bits, 12 to 35 of the 64-bit event id
1462 AliHLTUInt32_t GetOrbitNumber() const;
1465 * Get the bunch crossing number.
1466 * 12 bits, 0 to 12 of the 64-bit event id
1468 AliHLTUInt16_t GetBunchCrossNumber() const;
1471 * Setup the CTP accounting functionality of the base class.
1472 * The method can be invoked from DoInit() for componenets which want to
1473 * use the CTP functionality of the base class.
1475 * The AliHLTCTPData is initialized with the trigger classes from the ECS
1476 * parameters. The base class automatically increments the counters according
1477 * to the trigger pattern in the CDH before the event processing.
1482 * Get the instance of the CTP data.
1484 const AliHLTCTPData* CTPData() const {return fpCTPData;}
1487 * Check whether a combination of trigger classes is fired.
1488 * The expression can contain trigger class ids and logic operators
1489 * like &&, ||, !, and ^, and may be grouped by parentheses.
1490 * @note the function requires the setup of the CTP handling for the component by
1491 * invoking SetupCTPData() from DoInit()
1492 * @param expression a logic expression of trigger class ids
1493 * @param trigData the trigger data data
1495 bool EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const;
1498 * Check state of a trigger class.
1499 * If the class name is not part of the current trigger setup (i.e. ECS parameter
1500 * does not contain a trigger definition for this class name) the function
1502 * @note the function requires the setup of the CTP handling for the component by
1503 * invoking SetupCTPData() from DoInit()
1504 * @return -1 class name not initialized,
1505 * 0 trigger not active
1508 int CheckCTPTrigger(const char* name) const;
1511 * Get the overall solenoid field.
1515 * Get the solenoid field at point r.
1517 Double_t GetBz(const Double_t *r);
1519 * Get the solenoid field components at point r.
1521 void GetBxByBz(const Double_t r[3], Double_t b[3]);
1524 * Check whether the current event is a valid data event.
1525 * @param pTgt optional pointer to get the event type
1526 * @return true if the current event is a real data event
1528 bool IsDataEvent(AliHLTUInt32_t* pTgt=NULL) const;
1531 * Copy a struct from block data.
1532 * The function checks for block size and struct size. The least common
1533 * size will be copied to the target struct, remaining fields are initialized
1535 * The target struct must have a 32bit struct size indicator as first member.
1536 * @param pStruct target struct
1537 * @param iStructSize size of the struct
1538 * @param iBlockNo index of input block
1539 * @param structname name of the struct (log messages)
1540 * @param eventname name of the event (log messages)
1541 * @return size copied, neg. error if failed
1543 int CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
1544 const char* structname="", const char* eventname="");
1547 /** copy constructor prohibited */
1548 AliHLTComponent(const AliHLTComponent&);
1549 /** assignment operator prohibited */
1550 AliHLTComponent& operator=(const AliHLTComponent&);
1553 * Increment the internal event counter.
1554 * To be used by the friend classes AliHLTProcessor, AliHLTDataSource
1555 * and AliHLTDataSink.
1556 * @return new value of the internal event counter
1559 int IncrementEventCounter();
1562 * Find the first input block of specified data type beginning at index.
1563 * Input blocks containing a TObject have the size of the object as an
1564 * unsigned 32 bit number in the first 4 bytes. This has to match the block
1567 * kAliHLTAllDataTypes is a special data type which includes both
1568 * kAliHLTVoidDataType and kAliHLTAnyDataType.
1570 * @param dt data type
1571 * @param startIdx index to start the search
1572 * @param bObject check if this is an object
1573 * @return index of the block, -ENOENT if no block found
1577 int FindInputBlock(const AliHLTComponentDataType& dt, int startIdx=-1, int bObject=0) const;
1580 * Get index in the array of input bocks.
1581 * Calculate index and check integrety of a block data structure pointer.
1582 * @param pBlock pointer to block data
1583 * @return index of the block, -ENOENT if no block found
1587 int FindInputBlock(const AliHLTComponentBlockData* pBlock) const;
1590 * Create an object from a specified input block.
1591 * @param idx index of the input block
1592 * @param bForce force the retrieval of an object, error messages
1593 * are suppressed if \em bForce is not set
1594 * @return pointer to TObject, caller must delete the object after use
1598 TObject* CreateInputObject(int idx, int bForce=0);
1602 * Get object from the input block list. The methods first checks whether the
1603 * object was already created. If not, it is created by @ref CreateInputObject
1604 * and inserted into the list of objects.
1605 * @param idx index in the input block list
1606 * @param classname name of the class, object is checked for correct class
1608 * @param bForce force the retrieval of an object, error messages
1609 * are suppressed if \em bForce is not set
1610 * @return pointer to TObject
1614 TObject* GetInputObject(int idx, const char* classname=NULL, int bForce=0);
1617 * Clean the list of input objects.
1618 * Cleanup is done at the end of each event processing.
1620 int CleanupInputObjects();
1623 * Insert a buffer into the output block stream.
1624 * This is the only method to insert blocks into the output stream, called
1625 * from all types of the Pushback method. The actual data might have been
1626 * written to the output buffer already. In that case NULL can be provided
1627 * as buffer, only the block descriptor will be build. If a header is specified,
1628 * it will be inserted before the buffer, default is no header.
1629 * @param pBuffer pointer to buffer
1630 * @param iBufferSize size of the buffer in byte
1631 * @param dt data type
1632 * @param spec data specification
1633 * @param pHeader pointer to header
1634 * @param iHeaderSize size of Header
1635 * @return neg. error code if failed
1637 int InsertOutputBlock(const void* pBuffer, int iBufferSize,
1638 const AliHLTComponentDataType& dt,
1639 AliHLTUInt32_t spec,
1640 const void* pHeader=NULL, int iHeaderSize=0);
1643 * Add a component statistics block to the output.
1644 * @return size of the added data
1646 int AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
1647 AliHLTUInt8_t* buffer,
1648 AliHLTUInt32_t bufferSize,
1649 AliHLTUInt32_t offset,
1650 AliHLTComponentStatisticsList& stats) const;
1653 * Add a component table entry (descriptor) to the output
1654 * This is done at SOR/EOR. The component table is a list of chain ids
1655 * and 32bit ids calculated by a crc algorithm from the chian id. This
1656 * allows to tag data blocks with the id number rather than the string.
1658 * The kAliHLTDataTypeComponentTable data block currently has the string
1659 * as payload and the crc id as specification.
1660 * @return size of the added data
1662 int AddComponentTableEntry(AliHLTComponentBlockDataList& blocks,
1663 AliHLTUInt8_t* buffer,
1664 AliHLTUInt32_t bufferSize,
1665 AliHLTUInt32_t offset,
1666 const vector<AliHLTUInt32_t>& parents) const;
1669 * Scan the ECS parameter string.
1670 * The framework provides both the parameters of CONFIGURE and ENGAGE
1671 * in one string in a special data block kAliHLTDataTypeECSParam
1672 * {ECSPARAM:PRIV}. The general format is
1673 * <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
1675 int ScanECSParam(const char* ecsParam);
1678 * The trigger classes are determined from the trigger and propagated by
1679 * ECS as part of the ENGAGE command parameter which is sent through the
1680 * framework during the SOR event. This function treats the value of the
1681 * parameter key CTP_TRIGGER_CLASS.
1683 int InitCTPTriggerClasses(const char* ctpString);
1686 kRequireSteeringBlocks = 0x1,
1687 kDisableComponentStat = 0x2
1690 /** The global component handler instance */
1691 static AliHLTComponentHandler* fgpComponentHandler; //! transient
1693 /** The environment where the component is running in */
1694 AliHLTAnalysisEnvironment fEnvironment; // see above
1696 /** Set by ProcessEvent before the processing starts */
1697 AliHLTEventID_t fCurrentEvent; // see above
1699 /** internal event no */
1700 int fEventCount; // see above
1702 /** the number of failed events */
1703 int fFailedEvents; // see above
1705 /** event data struct of the current event under processing */
1706 AliHLTComponentEventData fCurrentEventData; // see above
1708 /** array of input data blocks of the current event */
1709 const AliHLTComponentBlockData* fpInputBlocks; //! transient
1711 /** index of the current input block */
1712 int fCurrentInputBlock; // see above
1714 /** data type of the last block search */
1715 AliHLTComponentDataType fSearchDataType; // see above
1717 /** name of the class for the object to search for */
1718 string fClassName; // see above
1720 /** array of generated input objects */
1721 TObjArray* fpInputObjects; //! transient
1723 /** the output buffer */
1724 AliHLTUInt8_t* fpOutputBuffer; //! transient
1726 /** size of the output buffer */
1727 AliHLTUInt32_t fOutputBufferSize; // see above
1729 /** size of data written to output buffer */
1730 AliHLTUInt32_t fOutputBufferFilled; // see above
1732 /** list of ouput block data descriptors */
1733 AliHLTComponentBlockDataList fOutputBlocks; // see above
1735 /** stopwatch array */
1736 TObjArray* fpStopwatches; //! transient
1738 /** array of memory files AliHLTMemoryFile */
1739 AliHLTMemoryFilePList fMemFiles; //! transient
1741 /** descriptor of the current run */
1742 AliHLTRunDesc* fpRunDesc; //! transient
1744 /** external fct to set CDB run no, indicates external CDB initialization */
1745 void (*fCDBSetRunNoFunc)(); //! transient
1747 /** id of the component in the analysis chain */
1748 string fChainId; //! transient
1750 /** crc value of the chainid, used as a 32bit id */
1751 AliHLTUInt32_t fChainIdCrc; //! transient
1753 /** optional benchmarking for the component statistics */
1754 TStopwatch* fpBenchmark; //! transient
1756 /** component flags, cleared in Deinit */
1757 AliHLTUInt32_t fFlags; //! transient
1759 /** current event type */
1760 AliHLTUInt32_t fEventType; //! transient
1762 /** component arguments */
1763 string fComponentArgs; //! transient
1766 /** event done data */
1767 AliHLTComponentEventDoneData* fEventDoneData; //! transient
1769 /** Reserved size of the memory stored at fEventDoneData */
1770 unsigned long fEventDoneDataSize; //! transient
1772 /** Comression level for ROOT objects */
1773 int fCompressionLevel; //! transient
1775 /** size of last PushBack-serialized object */
1776 int fLastObjectSize; //! transient
1778 /** array of trigger class descriptors */
1779 AliHLTCTPData* fpCTPData; //! transient
1781 /// update period for PushBack calls
1782 int fPushbackPeriod; //! transient
1783 /// time of last executed PushBack
1784 int fLastPushBackTime; //! transient
1786 ClassDef(AliHLTComponent, 14)