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