]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponent.h
Error corrected
[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 *
29 * @section alihlt_component_intro Component implementation
30 * AliHLTComponent provides the interface for all components, see there
31 * for details. Three types are provided:
32 * - AliHLTProcessor
33 * - AliHLTDataSource
34 * - AliHLTDataSink
35 *
36 * The two last represent data sinks and sources for the HLT integration
37 * into AliRoot. When running only, only the processors are relevant,
38 * sources and sinks are provided by the HLT PubSub framework. Please check
39 * AliHLTComponent for detailed description.
40 *
41 * @section alihlt_component_registration Component registration
42 * Components need to be registered with the AliHLTComponentHandler in
43 * order to be used with the system. Registration is purely done from the
44 * module library. Two methods are possible:
45 * - the module library implements an AliHLTModuleAgent and overloads the
46 * AliHLTModuleAgent::RegisterComponents() function
47 * - in the implementation file, one object is defined. The global object is
48 * automatically instantiated when the library is loaded for the first
49 * time and the object is used for registration.
50 *
51 * In both cases, the library must be loaded via the method
52 * <pre>
53 * AliHLTComponentHandler::LoadComponentLibraries()
54 * </pre>
55 * For the global object approach it is important that the library is
56 * not loaded elsewhere before (e.g. a gSystem->Load operation in your
57 * rootlogon.C).
58 *
59 *
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 *
b22e91eb 282 * @ingroup alihlt_component
a655eae3 283 * @section alihltcomponent-members Class members
bfccbf68 284 */
5ec8e281 285class AliHLTComponent : public AliHLTLogging {
f23a6e1a 286 public:
bfccbf68 287 /** standard constructor */
f23a6e1a 288 AliHLTComponent();
bfccbf68 289 /** standard destructor */
f23a6e1a 290 virtual ~AliHLTComponent();
291
bfccbf68 292 /** component type definitions */
f23a6e1a 293 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
bfccbf68 294
295 /**
296 * Init function to prepare data processing.
297 * Initialization of common data structures for a sequence of events.
298 * The call is redirected to the internal method @ref DoInit which can be
299 * overridden by the child class.<br>
300 * During Init also the environment structure is passed to the component.
301 * @param environ environment pointer with environment dependend function
302 * calls
70ed7d01 303 * @param environParam additionel parameter for function calls, the pointer
bfccbf68 304 * is passed as it is
305 * @param argc size of the argument array
306 * @param argv agument array for component initialization
307 */
a3c9b745 308 virtual int Init( const AliHLTAnalysisEnvironment* environ, void* environParam, int argc, const char** argv );
bfccbf68 309
310 /**
311 * Clean-up function to terminate data processing.
312 * Clean-up of common data structures after data processing.
313 * The call is redirected to the internal method @ref DoDeinit which can be
314 * overridden by the child class.
315 */
f23a6e1a 316 virtual int Deinit();
bfccbf68 317
318 /**
319 * Processing of one event.
3cde846d 320 * The method is the entrance of the event processing. The parameters are
321 * cached for uses with the high-level interface and the DoProcessing
322 * implementation is called.
323 *
324 * @param evtData
325 * @param blocks
326 * @param trigData
327 * @param outputPtr
328 * @param size
329 * @param outputBlockCnt out: size of the output block array, set by the component
330 * @param outputBlocks out: the output block array is allocated internally
331 * @param edd
332 * @return neg. error code if failed
333 */
334 int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
335 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
336 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
337 AliHLTComponentBlockData*& outputBlocks,
338 AliHLTComponentEventDoneData*& edd );
339
340 /**
341 * Internal processing of one event.
bfccbf68 342 * The method is pure virtual and implemented by the child classes
343 * - @ref AliHLTProcessor
344 * - @ref AliHLTDataSource
345 * - @ref AliHLTDataSink
346 *
347 * @param evtData
348 * @param blocks
349 * @param trigData
350 * @param outputPtr
351 * @param size
2d7ff710 352 * @param outputBlocks out: the output block array is allocated internally
bfccbf68 353 * @param edd
354 * @return neg. error code if failed
355 */
3cde846d 356 virtual int DoProcessing( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
8ede8717 357 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
a655eae3 358 AliHLTUInt32_t& size,
2be3f004 359 AliHLTComponentBlockDataList& outputBlocks,
8ede8717 360 AliHLTComponentEventDoneData*& edd ) = 0;
f23a6e1a 361
579d9eb7 362 /**
363 * Init the CDB.
364 * The function must not be called when running in AliRoot unless it it
365 * really wanted. The CDB path will be set to the specified path, which might
366 * override the path initialized at the beginning of the AliRoot reconstruction.
367 *
368 * The method is used from the external interface in order to set the correct
82c58a87 369 * path when running on-line. The function also initializes the function
370 * callback for setting the run no during operation.
371 *
372 * A separation of library and component handling is maybe appropriate in the
373 * future. Using the global component handler here is maybe not the cleanest
374 * solution.
375 * @param cdbPath path of the CDB
376 * @param pHandler the component handler used for llibrary handling.
579d9eb7 377 */
82c58a87 378 int InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler);
579d9eb7 379
380 /**
381 * Set the run no for the CDB.
382 * The function must not be called when running in AliRoot unless it it
383 * really wanted. The CDB path will be set to the specified path, which might
384 * override the run no initialized at the beginning of the AliRoot reconstruction.
45c0a780 385 * InitCDB() has to be called before in order to really change the CDB settings.
579d9eb7 386 *
387 * The method is used from the external interface in order to set the correct
388 * path when running on-line.
389 */
390 int SetCDBRunNo(int runNo);
391
45c0a780 392 /**
393 * Set the run description.
394 * The run description is set before the call of Init() -> DoInit().
395 * @note: This functionality has been added in Juli 2008. The transmission of
396 * run properties by a special SOR (SOD event in DAQ terminalogy but this was
397 * changed after the HLT interface was designed) event is not sufficient because
398 * the data might be needed already in the DoInit handler of the component.
399 * @param desc run descriptor, currently only the run no member is used
400 * @param runType originally, run type was supposed to be a number and part
401 * of the run descriptor. But it was defined as string later
402 */
403 int SetRunDescription(const AliHLTRunDesc* desc, const char* runType);
404
9a0ef890 405 /**
406 * Set the component description.
407 * The description string can contain tokens separated by blanks, a token
408 * consists of a key and an optional value separated by '='.
409 * Possible keys:
410 * \li -chainid=id string id within the chain of the instance
411 *
412 * @param desc component description
413 */
414 int SetComponentDescription(const char* desc);
415
f23a6e1a 416 // Information member functions for registration.
bfccbf68 417
418 /**
419 * Get the type of the component.
420 * The function is pure virtual and must be implemented by the child class.
421 * @return component type id
422 */
f23a6e1a 423 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
bfccbf68 424
425 /**
426 * Get the id of the component.
427 * Each component is identified by a unique id.
428 * The function is pure virtual and must be implemented by the child class.
429 * @return component id (string)
430 */
f23a6e1a 431 virtual const char* GetComponentID() = 0;
bfccbf68 432
433 /**
434 * Get the input data types of the component.
435 * The function is pure virtual and must be implemented by the child class.
436 * @return list of data types in the vector reference
437 */
2be3f004 438 virtual void GetInputDataTypes( AliHLTComponentDataTypeList& ) = 0;
bfccbf68 439
440 /**
441 * Get the output data type of the component.
442 * The function is pure virtual and must be implemented by the child class.
443 * @return output data type
444 */
8ede8717 445 virtual AliHLTComponentDataType GetOutputDataType() = 0;
bfccbf68 446
de6593d0 447 /**
448 * Get the output data types of the component.
449 * The function can be implemented to indicate multiple output data types
450 * in the target array.
451 * @ref GetOutputDataType must return @ref kAliHLTMultipleDataType in order
452 * to invoke this method.
453 * @param tgtList list to receive the data types
454 * @return no of output data types, data types in the target list
455 */
2be3f004 456 virtual int GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList);
de6593d0 457
bfccbf68 458 /**
459 * Get a ratio by how much the data volume is shrinked or enhanced.
460 * The function is pure virtual and must be implemented by the child class.
461 * @param constBase <i>return</i>: additive part, independent of the
462 * input data volume
463 * @param inputMultiplier <i>return</i>: multiplication ratio
464 * @return values in the reference variables
465 */
71d7c760 466 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
f23a6e1a 467
bfccbf68 468 /**
469 * Spawn function.
470 * Each component must implement a spawn function to create a new instance of
471 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
472 * @return new class instance
473 */
f23a6e1a 474 virtual AliHLTComponent* Spawn() = 0;
0c0c9d99 475
bfccbf68 476 /**
477 * Find matching data types between this component and a consumer component.
478 * Currently, a component can produce only one type of data. This restriction is most
479 * likely to be abolished in the future.
480 * @param pConsumer a component and consumer of the data produced by this component
481 * @param tgtList reference to a vector list to receive the matching data types.
482 * @return >= 0 success, neg. error code if failed
483 */
2be3f004 484 int FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList);
f23a6e1a 485
bfccbf68 486 /**
487 * Set the global component handler.
488 * The static method is needed for the automatic registration of components.
489 */
85869391 490 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
bfccbf68 491
492 /**
493 * Clear the global component handler.
494 * The static method is needed for the automatic registration of components.
495 */
85869391 496 static int UnsetGlobalComponentHandler();
bfccbf68 497
9ce4bf4a 498 /**
499 * Helper function to convert the data type to a string.
fbdb63fd 500 * @param type data type structure
501 * @param mode 0 print string origin:type <br>
502 * 1 print chars <br>
503 * 2 print numbers
9ce4bf4a 504 */
fbdb63fd 505 static string DataType2Text( const AliHLTComponentDataType& type, int mode=0);
9ce4bf4a 506
48abe484 507 /**
508 * Calculate a CRC checksum of a data buffer.
509 * Polynomial for the calculation is 0xD8.
510 */
511 static AliHLTUInt32_t CalculateChecksum(const AliHLTUInt8_t* buffer, int size);
512
5f5b708b 513 /**
514 * Helper function to print content of data type.
515 */
8b97f4f1 516 static void PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format=NULL);
5f5b708b 517
9ce4bf4a 518 /**
519 * helper function to initialize AliHLTComponentEventData structure
520 */
521 static void FillEventData(AliHLTComponentEventData& evtData);
522
523 /**
524 * Print info on an AliHLTComponentDataType structure
525 * This is just a helper function to examine an @ref AliHLTComponentDataType
526 * structur.
527 */
8b97f4f1 528 static void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
9ce4bf4a 529
fbdb63fd 530 /**
531 * Fill AliHLTComponentBlockData structure with default values.
532 * @param blockData reference to data structure
533 */
534 static void FillBlockData( AliHLTComponentBlockData& blockData );
535
536 /**
537 * Fill AliHLTComponentShmData structure with default values.
538 * @param shmData reference to data structure
539 */
540 static void FillShmData( AliHLTComponentShmData& shmData );
541
542 /**
543 * Fill AliHLTComponentDataType structure with default values.
544 * @param dataType reference to data structure
545 */
546 static void FillDataType( AliHLTComponentDataType& dataType );
547
548 /**
549 * Copy data type structure
550 * Copies the value an AliHLTComponentDataType structure to another one
551 * @param[out] tgtdt target structure
552 * @param[in] srcdt source structure
553 */
554 static void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
555
556 /**
557 * Set the ID and Origin of an AliHLTComponentDataType structure.
558 * The function sets the fStructureSize member and copies the strings
559 * to the ID and Origin. Only characters from the valid part of the string
7e3efc8f 560 * are copied, the rest is filled with 0's. <br>
fbdb63fd 561 * Please note that the fID and fOrigin members are not strings, just arrays of
562 * chars of size @ref kAliHLTComponentDataTypefIDsize and
563 * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
7e3efc8f 564 * a terminating zero. <br>
565 * It is possible to pass NULL pointers as id or origin argument, in that case they
566 * are just ignored.
fbdb63fd 567 * @param tgtdt target data type structure
568 * @param id ID string
569 * @param origin Origin string
570 */
571 static void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
572
18b56222 573 /**
574 * Set the ID and Origin of an AliHLTComponentDataType structure.
575 * Given the fact that the data type ID is 64bit wide and origin 32, this helper
576 * function sets the data type from those two parameters.
af2ed151 577 * @param dt target data type structure
18b56222 578 * @param id 64bit id
af2ed151 579 * @param orig 32bit origin
18b56222 580 */
581 static void SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t orig);
582
abb52c8f 583 /**
584 * Extract a component table entry from the payload buffer.
585 * The entry consists of the AliHLTComponentTableEntry structure, the array of
586 * parents and a description string of the format 'chain-id{component-id:component-args}'.
587 * The function fills all the variables after a consistency check.
588 */
589 static int ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
590 string& chainId, string& compId, string& compParam,
591 vector<AliHLTUInt32_t>& parents);
90ebac25 592 /**
593 * Stopwatch type for benchmarking.
594 */
595 enum AliHLTStopwatchType {
596 /** total time for event processing */
597 kSWBase,
598 /** detector algorithm w/o interface callbacks */
599 kSWDA,
600 /** data sources */
601 kSWInput,
602 /** data sinks */
603 kSWOutput,
604 /** number of types */
605 kSWTypeCount
606 };
607
608 /**
609 * Helper class for starting and stopping a stopwatch.
610 * The guard can be used by instantiating an object in a function. The
611 * specified stopwatch is started and the previous stopwatch put on
612 * hold. When the function is terminated, the object is deleted automatically
613 * deleted, stopping the stopwatch and starting the one on hold.<br>
614 * \em IMPORTANT: never create dynamic objects from this guard as this violates
615 * the idea of a guard.
616 */
617 class AliHLTStopwatchGuard {
618 public:
619 /** standard constructor (not for use) */
620 AliHLTStopwatchGuard();
621 /** constructor */
622 AliHLTStopwatchGuard(TStopwatch* pStart);
623 /** copy constructor (not for use) */
e419b223 624 AliHLTStopwatchGuard(const AliHLTStopwatchGuard&);
625 /** assignment operator (not for use) */
626 AliHLTStopwatchGuard& operator=(const AliHLTStopwatchGuard&);
90ebac25 627 /** destructor */
628 ~AliHLTStopwatchGuard();
629
630 private:
631 /**
632 * Hold the previous guard for the existence of this guard.
633 * Checks whether this guard controls a new stopwatch. In that case, the
634 * previous guard and its stopwatch are put on hold.
635 * @param pSucc instance of the stopwatch of the new guard
636 * @return 1 if pSucc is a different stopwatch which should
637 * be started<br>
638 * 0 if it controls the same stopwatch
639 */
640 int Hold(TStopwatch* pSucc);
641
642 /**
643 * Resume the previous guard.
644 * Checks whether the peceeding guard controls a different stopwatch. In that
645 * case, the its stopwatch is resumed.
646 * @param pSucc instance of the stopwatch of the new guard
647 * @return 1 if pSucc is a different stopwatch which should
648 * be stopped<br>
649 * 0 if it controls the same stopwatch
650 */
651 int Resume(TStopwatch* pSucc);
652
653 /** the stopwatch controlled by this guard */
654 TStopwatch* fpStopwatch; //!transient
655
656 /** previous stopwatch guard, put on hold during existence of the guard */
657 AliHLTStopwatchGuard* fpPrec; //!transient
658
659 /** active stopwatch guard */
660 static AliHLTStopwatchGuard* fgpCurrent; //!transient
661 };
662
663 /**
664 * Set a stopwatch for a given purpose.
665 * @param pSW stopwatch object
666 * @param type type of the stopwatch
667 */
668 int SetStopwatch(TObject* pSW, AliHLTStopwatchType type=kSWBase);
669
670 /**
671 * Init a set of stopwatches.
672 * @param pStopwatches object array of stopwatches
673 */
674 int SetStopwatches(TObjArray* pStopwatches);
a655eae3 675
f23a6e1a 676 protected:
71d7c760 677
bfccbf68 678 /**
679 * Default method for the internal initialization.
680 * The method is called by @ref Init
681 */
53feaef5 682 virtual int DoInit( int argc, const char** argv );
f23a6e1a 683
bfccbf68 684 /**
685 * Default method for the internal clean-up.
686 * The method is called by @ref Deinit
687 */
53feaef5 688 virtual int DoDeinit();
f23a6e1a 689
579d9eb7 690 /**
691 * Reconfigure the component.
692 * The method is called when an event of type @ref kAliHLTDataTypeComConf
693 * {COM_CONF:PRIV} is received by the component. If the event is sent as
694 * part of a normal event, the component configuration is called first.
695 *
696 * The CDB path parameter specifies the path in the CDB, i.e. without
697 * leading absolute path of the CDB location. The framework might alse
698 * provide the id of the component in the analysis chain.
699 *
700 * \b Note: The CDB will be initialized by the framework, either already set
701 * from AliRoot or from the wrapper interface during initialization.
702 *
703 * @param cdbEntry path of the cdbEntry
e63b561e 704 * @param chainId the id/name of the component in the current analysis
705 * chain. This is not necessarily the same as what is
706 * returned by the GetComponentID() method.
579d9eb7 707 * @note both parameters can be NULL, check before usage
708 */
709 virtual int Reconfigure(const char* cdbEntry, const char* chainId);
b543e186 710
711 /**
712 * Read the Preprocessor values.
713 * The function is invoked when the component is notified about available/
714 * updated data points from the detector Preprocessors. The 'modules'
715 * argument contains all detectors for which the Preprocessors have
716 * updated data points. The component has to implement the CDB access to
717 * get the desired data points.
718 * @param modules detectors for which the Preprocessors have updated
d6b69874 719 * data points: TPC, TRD, ITS, PHOS, MUON, or ALL if
720 * no argument was received.
b543e186 721 * @return neg. error code if failed
722 */
723 virtual int ReadPreprocessorValues(const char* modules);
579d9eb7 724
45c0a780 725 /**
726 * Custom handler for the SOR event.
727 * Is invoked from the base class if an SOR event is in the block list.
728 * The handler is called before the processing function. The processing
729 * function is skipped if there are no other data blocks available.
730 *
731 * The SOR event is generated by the PubSub framework in response to
732 * the DAQ start of data (SOD - has been renamed after HLT interface
733 * was designed). The SOD event consists of 3 blocks:
734 * - ::kAliHLTDataTypeEvent block: spec ::gkAliEventTypeStartOfRun
735 * - SOD block of type ::kAliHLTDataTypeSOR, payload: AliHLTRunDesc struct
736 * - run type block ::kAliHLTDataTypeRunType, payload: run type string
737 *
738 * Run properties can be retrieved by getters like GetRunNo().
739 * @return neg. error code if failed
740 */
741 virtual int StartOfRun();
742
743 /**
744 * Custom handler for the EOR event.
745 * Is invoked from the base class if an EOR event is in the block list.
746 * The handler is called before the processing function. The processing
747 * function is skipped if there are no other data blocks available.
748 *
749 * See StartOfRun() for mor ecomments of the sequence of steering events.
750 *
751 * @return neg. error code if failed
752 */
753 virtual int EndOfRun();
754
48abe484 755 /**
756 * Check whether a component requires all steering blocks.
757 * Childs can overload in order to indicate that they want to
758 * receive also the steering data blocks. There is also the
759 * possibility to add the required data types to the input
760 * data type list in GetInputDataTypes().
761 */
762 virtual bool RequireSteeringBlocks() const {return false;}
763
bfccbf68 764 /**
765 * General memory allocation method.
766 * All memory which is going to be used 'outside' of the interface must
767 * be provided by the framework (online or offline).
768 * The method is redirected to a function provided by the current
769 * framework. Function pointers are transferred via the @ref
a3c9b745 770 * AliHLTAnalysisEnvironment structure.
bfccbf68 771 */
85869391 772 void* AllocMemory( unsigned long size );
f23a6e1a 773
bfccbf68 774 /**
775 * Helper function to create a monolithic BlockData description block out
776 * of a list BlockData descriptors.
777 * For convenience, inside the interface vector lists are used, to make the
778 * interface pure C style, monilithic blocks must be exchanged.
779 * The method is redirected to a function provided by the current
780 * framework. Function pointers are transferred via the @ref
a3c9b745 781 * AliHLTAnalysisEnvironment structure.
bfccbf68 782 */
2be3f004 783 int MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
8ede8717 784 AliHLTComponentBlockData** outputBlocks );
f23a6e1a 785
bfccbf68 786 /**
787 * Fill the EventDoneData structure.
788 * The method is redirected to a function provided by the current
789 * framework. Function pointers are transferred via the @ref
a3c9b745 790 * AliHLTAnalysisEnvironment structure.
bfccbf68 791 */
8ede8717 792 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd );
f23a6e1a 793
eafbc306 794 /**
795 * Allocate an EventDoneData structure for the current event .
796 * The method allocates the memory internally and does not interact with the current Framework.
797 * The allocated data structure is empty initially and can be filled by calls to the
798 * @ref PushEventDoneData method. The memory will be automatically released after the event has been processed.
799 *
800 */
801 int ReserveEventDoneData( unsigned long size );
802
803 /**
804 * Push a 32 bit word of data into event done data for the current event which
805 * has previously been allocated by the @ref ReserveEventDoneData method.
806 */
807 int PushEventDoneData( AliHLTUInt32_t eddDataWord );
808
809 /**
810 * Release event done data previously reserved by @ref ReserveEventDoneData
811 */
812 void ReleaseEventDoneData();
813
814 /**
815 * Get the pointer to the event done data available/built so far for the current event via
816 * @ref ReserveEventDoneData and @ref PushEventDoneData
817 */
818 AliHLTComponentEventDoneData* GetCurrentEventDoneData()
819 {
820 return fEventDoneData;
821 }
822
bfccbf68 823 /**
824 * Helper function to convert the data type to a string.
825 */
70ed7d01 826 void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]) const;
fa2e9b7c 827
3cde846d 828 /**
829 * Get event number.
830 * @return value of the internal event counter
831 */
70ed7d01 832 int GetEventCount() const;
3cde846d 833
a655eae3 834 /**
835 * Get the number of input blocks.
836 * @return number of input blocks
837 */
66043029 838 int GetNumberOfInputBlocks() const;
a655eae3 839
840 /**
841 * Get the first object of a specific data type from the input data.
842 * The hight-level methods provide functionality to transfer ROOT data
843 * structures which inherit from TObject.
3dd8541e 844 *
a655eae3 845 * The method looks for the first ROOT object of type dt in the input stream.
846 * If also the class name is provided, the object is checked for the right
847 * class type. The input data block needs a certain structure, namely the
848 * buffer size as first word. If the cross check fails, the retrieval is
8451168b 849 * silently abondoned, unless the \em bForce parameter is set.<br>
3dd8541e 850 * \b Note: THE OBJECT MUST NOT BE DELETED by the caller.
851 *
852 * If called without parameters, the function tries to create objects from
853 * all available input blocks, also the ones of data type kAliHLTVoidDataType
854 * which are not matched by kAliHLTAnyDataType.
855 *
a655eae3 856 * @param dt data type of the object
857 * @param classname class name of the object
858 * @param bForce force the retrieval of an object, error messages
859 * are suppressed if \em bForce is not set
860 * @return pointer to @ref TObject, NULL if no objects of specified type
861 * available
862 */
3dd8541e 863 const TObject* GetFirstInputObject(const AliHLTComponentDataType& dt=kAliHLTAllDataTypes,
a655eae3 864 const char* classname=NULL,
865 int bForce=0);
866
867 /**
868 * Get the first object of a specific data type from the input data.
869 * The hight-level methods provide functionality to transfer ROOT data
870 * structures which inherit from TObject.
871 * The method looks for the first ROOT object of type specified by the ID and
872 * Origin strings in the input stream.
873 * If also the class name is provided, the object is checked for the right
874 * class type. The input data block needs a certain structure, namely the
875 * buffer size as first word. If the cross check fails, the retrieval is
8451168b 876 * silently abondoned, unless the \em bForce parameter is set.<br>
877 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
a655eae3 878 * @param dtID data type ID of the object
879 * @param dtOrigin data type origin of the object
880 * @param classname class name of the object
881 * @param bForce force the retrieval of an object, error messages
882 * are suppressed if \em bForce is not set
883 * @return pointer to @ref TObject, NULL if no objects of specified type
884 * available
885 */
886 const TObject* GetFirstInputObject(const char* dtID,
887 const char* dtOrigin,
888 const char* classname=NULL,
889 int bForce=0);
890
891 /**
892 * Get the next object of a specific data type from the input data.
893 * The hight-level methods provide functionality to transfer ROOT data
894 * structures which inherit from TObject.
895 * The method looks for the next ROOT object of type and class specified
8451168b 896 * to the previous @ref GetFirstInputObject call.<br>
897 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
a655eae3 898 * @param bForce force the retrieval of an object, error messages
899 * are suppressed if \em bForce is not set
900 * @return pointer to @ref TObject, NULL if no more objects available
901 */
902 const TObject* GetNextInputObject(int bForce=0);
903
904 /**
905 * Get data type of an input block.
906 * Get data type of the object previously fetched via
907 * GetFirstInputObject/NextInputObject or the last one if no object
908 * specified.
909 * @param pObject pointer to TObject
910 * @return data specification, kAliHLTVoidDataSpec if failed
911 */
912 AliHLTComponentDataType GetDataType(const TObject* pObject=NULL);
913
914 /**
915 * Get data specification of an input block.
916 * Get data specification of the object previously fetched via
917 * GetFirstInputObject/NextInputObject or the last one if no object
918 * specified.
919 * @param pObject pointer to TObject
920 * @return data specification, kAliHLTVoidDataSpec if failed
921 */
922 AliHLTUInt32_t GetSpecification(const TObject* pObject=NULL);
923
924 /**
925 * Get the first block of a specific data type from the input data.
3dd8541e 926 * The method looks for the first block of type dt in the input stream.
927 * It is intended to be used within the high-level interface.<br>
8451168b 928 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
3dd8541e 929 *
930 * If called without parameters, the function works on all input blocks,
931 * also the ones of data type kAliHLTVoidDataType which are not matched by
932 * kAliHLTAnyDataType.
933 *
a655eae3 934 * @param dt data type of the block
935 * @return pointer to @ref AliHLTComponentBlockData
936 */
3dd8541e 937 const AliHLTComponentBlockData* GetFirstInputBlock(const AliHLTComponentDataType& dt=kAliHLTAllDataTypes);
a655eae3 938
939 /**
940 * Get the first block of a specific data type from the input data.
941 * The method looks for the first block of type specified by the ID and
942 * Origin strings in the input stream. It is intended
8451168b 943 * to be used within the high-level interface.<br>
944 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 945 * @param dtID data type ID of the block
946 * @param dtOrigin data type origin of the block
947 * @return pointer to @ref AliHLTComponentBlockData
948 */
949 const AliHLTComponentBlockData* GetFirstInputBlock(const char* dtID,
950 const char* dtOrigin);
951
952 /**
8451168b 953 * Get input block by index.<br>
954 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 955 * @return pointer to AliHLTComponentBlockData, NULL if index out of range
956 */
10b9cbf9 957 const AliHLTComponentBlockData* GetInputBlock(int index) const;
a655eae3 958
959 /**
960 * Get the next block of a specific data type from the input data.
961 * The method looks for the next block of type and class specified
962 * to the previous @ref GetFirstInputBlock call.
8451168b 963 * To be used within the high-level interface.<br>
964 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 965 */
966 const AliHLTComponentBlockData* GetNextInputBlock();
967
968 /**
969 * Get data specification of an input block.
970 * Get data specification of the input bblock previously fetched via
971 * GetFirstInputObject/NextInputObject or the last one if no block
972 * specified.
973 * @param pBlock pointer to input block
974 * @return data specification, kAliHLTVoidDataSpec if failed
975 */
976 AliHLTUInt32_t GetSpecification(const AliHLTComponentBlockData* pBlock=NULL);
977
c7e9e2f2 978 /**
979 * Forward an input object to the output.
980 * Forward the input block of an object previously fetched via
981 * GetFirstInputObject/NextInputObject or the last one if no object
982 * specified.
983 * The block descriptor of the input block is forwarded to the
984 * output block list.
985 * @param pObject pointer to TObject
986 * @return neg. error code if failed
987 */
988 int Forward(const TObject* pObject);
989
990 /**
991 * Forward an input block to the output.
992 * Forward the input block fetched via GetFirstInputObject/
993 * NextInputBlock or the last one if no block specified.
994 * The block descriptor of the input block is forwarded to the
995 * output block list.
996 * @param pBlock pointer to input block
997 * @return neg. error code if failed
998 */
999 int Forward(const AliHLTComponentBlockData* pBlock=NULL);
1000
a655eae3 1001 /**
1002 * Insert an object into the output.
79c114b5 1003 * If header is specified, it will be inserted before the root object,
1004 * default is no header.
a655eae3 1005 * @param pObject pointer to root object
1006 * @param dt data type of the object
1007 * @param spec data specification
79c114b5 1008 * @param pHeader pointer to header
1009 * @param headerSize size of Header
a655eae3 1010 * @return neg. error code if failed
1011 */
1012 int PushBack(TObject* pObject, const AliHLTComponentDataType& dt,
79c114b5 1013 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1014 void* pHeader=NULL, int headerSize=0);
a655eae3 1015
1016 /**
1017 * Insert an object into the output.
79c114b5 1018 * If header is specified, it will be inserted before the root object,
1019 * default is no header.
a655eae3 1020 * @param pObject pointer to root object
1021 * @param dtID data type ID of the object
1022 * @param dtOrigin data type origin of the object
1023 * @param spec data specification
79c114b5 1024 * @param pHeader pointer to header
1025 * @param headerSize size of Header
a655eae3 1026 * @return neg. error code if failed
1027 */
1028 int PushBack(TObject* pObject, const char* dtID, const char* dtOrigin,
79c114b5 1029 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1030 void* pHeader=NULL, int headerSize=0);
1031
a655eae3 1032 /**
1033 * Insert an object into the output.
1034 * @param pBuffer pointer to buffer
1035 * @param iSize size of the buffer
1036 * @param dt data type of the object
1037 * @param spec data specification
9d9ffd37 1038 * @param pHeader pointer to header
7c4091c1 1039 * @param headerSize size of Header
a655eae3 1040 * @return neg. error code if failed
1041 */
438635e3 1042 int PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt,
9d9ffd37 1043 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
438635e3 1044 const void* pHeader=NULL, int headerSize=0);
a655eae3 1045
1046 /**
1047 * Insert an object into the output.
1048 * @param pBuffer pointer to buffer
1049 * @param iSize size of the buffer
1050 * @param dtID data type ID of the object
1051 * @param dtOrigin data type origin of the object
1052 * @param spec data specification
9d9ffd37 1053 * @param pHeader pointer to header
7c4091c1 1054 * @param headerSize size of Header
a655eae3 1055 * @return neg. error code if failed
1056 */
438635e3 1057 int PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin,
9d9ffd37 1058 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
438635e3 1059 const void* pHeader=NULL, int headerSize=0);
a655eae3 1060
8451168b 1061 /**
1062 * Estimate size of a TObject
1063 * @param pObject
1064 * @return buffer size in byte
1065 */
1066 int EstimateObjectSize(TObject* pObject) const;
1067
79c114b5 1068 /**
1069 * Create a memory file in the output stream.
1070 * This method creates a TFile object which stores all data in
1071 * memory instead of disk. The TFile object is published as binary data.
1072 * The instance can be used like a normal TFile object. The TFile::Close
1073 * or @ref CloseMemoryFile method has to be called in order to flush the
1074 * output stream.
1075 *
1076 * \b Note: The returned object is deleted by the framework.
1077 * @param capacity total size reserved for the memory file
1078 * @param dtID data type ID of the file
1079 * @param dtOrigin data type origin of the file
1080 * @param spec data specification
1081 * @return file handle, NULL if failed
1082 */
1083 AliHLTMemoryFile* CreateMemoryFile(int capacity, const char* dtID, const char* dtOrigin,
1084 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
1085
1086 /**
1087 * Create a memory file in the output stream.
1088 * This method creates a TFile object which stores all data in
1089 * memory instead of disk. The TFile object is published as binary data.
1090 * The instance can be used like a normal TFile object. The TFile::Close
1091 * or @ref CloseMemoryFile method has to be called in order to flush the
1092 * output stream.
1093 *
1094 * \b Note: The returned object is deleted by the framework.
1095 * @param capacity total size reserved for the memory file
1096 * @param dt data type of the file
1097 * @param spec data specification
1098 * @return file handle, NULL if failed
1099 */
1100 AliHLTMemoryFile* CreateMemoryFile(int capacity,
1101 const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
1102 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
1103
1104 /**
1105 * Create a memory file in the output stream.
1106 * This method creates a TFile object which stores all data in
1107 * memory instead of disk. The TFile object is published as binary data.
1108 * The instance can be used like a normal TFile object. The TFile::Close
1109 * or @ref CloseMemoryFile method has to be called in order to flush the
1110 * output stream.
1111 *
1112 * \b Note: The returned object is deleted by the framework.
1113 * @param dtID data type ID of the file
1114 * @param dtOrigin data type origin of the file
1115 * @param spec data specification
1116 * @param capacity fraction of the available output buffer size
1117 * @return file handle, NULL if failed
1118 */
1119 AliHLTMemoryFile* CreateMemoryFile(const char* dtID, const char* dtOrigin,
1120 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1121 float capacity=1.0);
1122
1123 /**
1124 * Create a memory file in the output stream.
1125 * This method creates a TFile object which stores all data in
1126 * memory instead of disk. The TFile object is published as binary data.
1127 * The instance can be used like a normal TFile object. The TFile::Close
1128 * or @ref CloseMemoryFile method has to be called in order to flush the
1129 * output stream.
1130 *
1131 * \b Note: The returned object is deleted by the framework.
1132 * @param dt data type of the file
1133 * @param spec data specification
1134 * @param capacity fraction of the available output buffer size
1135 * @return file handle, NULL if failed
1136 */
1137 AliHLTMemoryFile* CreateMemoryFile(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
1138 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
1139 float capacity=1.0);
1140
1141 /**
1142 * Write an object to memory file in the output stream.
1143 * @param pFile file handle
1144 * @param pObject pointer to root object
1145 * @param key key in ROOT file
1146 * @param option options, see TObject::Write
1147 * @return neg. error code if failed
1148 * - -ENOSPC no space left
1149 */
1150 int Write(AliHLTMemoryFile* pFile, const TObject* pObject, const char* key=NULL, int option=TObject::kOverwrite);
1151
1152 /**
1153 * Close object memory file.
1154 * @param pFile file handle
1155 * @return neg. error code if failed
1156 * - -ENOSPC buffer size too small
1157 */
1158 int CloseMemoryFile(AliHLTMemoryFile* pFile);
1159
a655eae3 1160 /**
1161 * Insert event-done data information into the output.
1162 * @param edd event-done data information
1163 */
1164 int CreateEventDoneData(AliHLTComponentEventDoneData edd);
1165
559631d5 1166 /**
1167 * Get current run number
1168 */
1169 AliHLTUInt32_t GetRunNo() const;
1170
1171 /**
1172 * Get the current run type.
1173 */
1174 AliHLTUInt32_t GetRunType() const;
1175
9a0ef890 1176 /**
1177 * Get the chain id of the component.
1178 */
1179 const char* GetChainId() const {return fChainId.c_str();}
1180
48abe484 1181 /**
1182 * Check whether the current event is a valid data event.
1183 * @param pTgt optional pointer to get the event type
1184 * @return true if the current event is a real data event
1185 */
1186 bool IsDataEvent(AliHLTUInt32_t* pTgt=NULL);
1187
ed504011 1188 /**
1189 * Set a bit to 1 in a readout list ( = AliHLTEventDDL )
1190 * -> enable DDL for readout
1191 * @param list readout list
1192 * @param ddlId DDL Id to be turned on ( Decimal )
1193 */
1194 void EnableDDLBit(AliHLTEventDDL &list, Int_t ddlId ) const {
1195 SetDDLBit( list, ddlId, kTRUE );
1196 }
1197
1198 /**
1199 * Set a bit to 0 in a readout list ( = AliHLTEventDDL )
1200 * -> disable DDL for readout
1201 * @param list readout list
1202 * @param ddlId DDL Id to be turned on ( Decimal )
1203 */
1204 void DisableDDLBit(AliHLTEventDDL &list, Int_t ddlId ) const {
1205 SetDDLBit( list, ddlId, kFALSE );
1206 }
1207
1208 /**
1209 * Set or unset bit a readout list ( = AliHLTEventDDL )
1210 * -> enable or disable DDL for readout
1211 * @param list readout list
1212 * @param ddlId DDL Id to be turned on ( Decimal )
1213 * @param state kTRUE sets it, kFALSE unsets it
1214 */
1215 void SetDDLBit(AliHLTEventDDL &list, Int_t ddlId, Bool_t state ) const;
1216
1217 /**
1218 * Get the first word of a detector, which has a set DDL bit.
1219 * Beware, this only works if DDLs of 1 detector are set. In the
1220 * case of the TPC and TOF, which use 8 and 3 words, the first
1221 * word is returned.
1222 * @param list readout list
1223 * @return returns the detector index, -1 if no bit is set
1224 * at all or several detectors (=error)
1225 */
1226 Int_t GetFirstUsedDDLWord(AliHLTEventDDL &list) const;
1227
559631d5 1228 /**
1229 * Copy a struct from block data.
1230 * The function checks for block size and struct size. The least common
1231 * size will be copied to the target struct, remaining fields are initialized
1232 * to zero.<br>
1233 * The target struct must have a 32bit struct size indicator as first member.
1234 * @param pStruct target struct
1235 * @param iStructSize size of the struct
559631d5 1236 * @param iBlockNo index of input block
1237 * @param structname name of the struct (log messages)
1238 * @param eventname name of the event (log messages)
1239 * @return size copied, neg. error if failed
1240 */
83fec083 1241 int CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
559631d5 1242 const char* structname="", const char* eventname="");
1243
f23a6e1a 1244 private:
b426991e 1245 /** copy constructor prohibited */
559631d5 1246 AliHLTComponent(const AliHLTComponent&);
b426991e 1247 /** assignment operator prohibited */
559631d5 1248 AliHLTComponent& operator=(const AliHLTComponent&);
1249
3cde846d 1250 /**
1251 * Increment the internal event counter.
1252 * To be used by the friend classes AliHLTProcessor, AliHLTDataSource
1253 * and AliHLTDataSink.
1254 * @return new value of the internal event counter
a655eae3 1255 * @internal
3cde846d 1256 */
1257 int IncrementEventCounter();
1258
a655eae3 1259 /**
1260 * Find the first input block of specified data type beginning at index.
1edbbe49 1261 * Input blocks containing a TObject have the size of the object as an
1262 * unsigned 32 bit number in the first 4 bytes. This has to match the block
1263 * size minus 4.
3dd8541e 1264 *
1265 * kAliHLTAllDataTypes is a special data type which includes both
1266 * kAliHLTVoidDataType and kAliHLTAnyDataType.
1267 *
a655eae3 1268 * @param dt data type
1269 * @param startIdx index to start the search
1edbbe49 1270 * @param bObject check if this is an object
a655eae3 1271 * @return index of the block, -ENOENT if no block found
1272 *
1273 * @internal
1274 */
1edbbe49 1275 int FindInputBlock(const AliHLTComponentDataType& dt, int startIdx=-1, int bObject=0) const;
a655eae3 1276
1277 /**
1278 * Get index in the array of input bocks.
1279 * Calculate index and check integrety of a block data structure pointer.
1280 * @param pBlock pointer to block data
1281 * @return index of the block, -ENOENT if no block found
1282 *
1283 * @internal
1284 */
66043029 1285 int FindInputBlock(const AliHLTComponentBlockData* pBlock) const;
a655eae3 1286
1287 /**
1288 * Create an object from a specified input block.
1289 * @param idx index of the input block
1290 * @param bForce force the retrieval of an object, error messages
1291 * are suppressed if \em bForce is not set
1292 * @return pointer to TObject, caller must delete the object after use
1293 *
1294 * @internal
1295 */
1296 TObject* CreateInputObject(int idx, int bForce=0);
1297
1298 /**
1299 * Get input object
8451168b 1300 * Get object from the input block list. The methods first checks whether the
1301 * object was already created. If not, it is created by @ref CreateInputObject
1302 * and inserted into the list of objects.
a655eae3 1303 * @param idx index in the input block list
1304 * @param classname name of the class, object is checked for correct class
1305 * name if set
1306 * @param bForce force the retrieval of an object, error messages
1307 * are suppressed if \em bForce is not set
1308 * @return pointer to TObject
1309 *
1310 * @internal
1311 */
1312 TObject* GetInputObject(int idx, const char* classname=NULL, int bForce=0);
1313
8451168b 1314 /**
1315 * Clean the list of input objects.
1316 * Cleanup is done at the end of each event processing.
1317 */
1318 int CleanupInputObjects();
1319
a655eae3 1320 /**
1321 * Insert a buffer into the output block stream.
1322 * This is the only method to insert blocks into the output stream, called
1323 * from all types of the Pushback method. The actual data might have been
1324 * written to the output buffer already. In that case NULL can be provided
79c114b5 1325 * as buffer, only the block descriptor will be build. If a header is specified,
1326 * it will be inserted before the buffer, default is no header.
a655eae3 1327 * @param pBuffer pointer to buffer
32db4144 1328 * @param iBufferSize size of the buffer in byte
a655eae3 1329 * @param dt data type
1330 * @param spec data specification
79c114b5 1331 * @param pHeader pointer to header
1332 * @param iHeaderSize size of Header
b6800be0 1333 * @return neg. error code if failed
a655eae3 1334 */
438635e3 1335 int InsertOutputBlock(const void* pBuffer, int iBufferSize,
a655eae3 1336 const AliHLTComponentDataType& dt,
79c114b5 1337 AliHLTUInt32_t spec,
438635e3 1338 const void* pHeader=NULL, int iHeaderSize=0);
a655eae3 1339
a0aeb701 1340 /**
1341 * Add a component statistics block to the output.
438635e3 1342 * @return size of the added data
a0aeb701 1343 */
1344 int AddComponentStatistics(AliHLTComponentBlockDataList& blocks,
1345 AliHLTUInt8_t* buffer,
1346 AliHLTUInt32_t bufferSize,
1347 AliHLTUInt32_t offset,
1348 AliHLTComponentStatisticsList& stats) const;
1349
438635e3 1350 /**
1351 * Add a component table entry (descriptor) to the output
1352 * This is done at SOR/EOR. The component table is a list of chain ids
1353 * and 32bit ids calculated by a crc algorithm from the chian id. This
1354 * allows to tag data blocks with the id number rather than the string.
1355 *
1356 * The kAliHLTDataTypeComponentTable data block currently has the string
1357 * as payload and the crc id as specification.
1358 * @return size of the added data
1359 */
1360 int AddComponentTableEntry(AliHLTComponentBlockDataList& blocks,
1361 AliHLTUInt8_t* buffer,
1362 AliHLTUInt32_t bufferSize,
abb52c8f 1363 AliHLTUInt32_t offset,
1364 const vector<AliHLTUInt32_t>& parents) const;
438635e3 1365
bfccbf68 1366 /** The global component handler instance */
a655eae3 1367 static AliHLTComponentHandler* fgpComponentHandler; //! transient
70ed7d01 1368
bfccbf68 1369 /** The environment where the component is running in */
a3c9b745 1370 AliHLTAnalysisEnvironment fEnvironment; // see above
f23a6e1a 1371
a655eae3 1372 /** Set by ProcessEvent before the processing starts */
1373 AliHLTEventID_t fCurrentEvent; // see above
f23a6e1a 1374
3cde846d 1375 /** internal event no */
a655eae3 1376 int fEventCount; // see above
1377
1378 /** the number of failed events */
1379 int fFailedEvents; // see above
1380
1381 /** event data struct of the current event under processing */
1382 AliHLTComponentEventData fCurrentEventData; // see above
1383
1384 /** array of input data blocks of the current event */
1385 const AliHLTComponentBlockData* fpInputBlocks; //! transient
1386
1387 /** index of the current input block */
1388 int fCurrentInputBlock; // see above
1389
1390 /** data type of the last block search */
1391 AliHLTComponentDataType fSearchDataType; // see above
1392
1393 /** name of the class for the object to search for */
1394 string fClassName; // see above
1395
1396 /** array of generated input objects */
1397 TObjArray* fpInputObjects; //! transient
1398
1399 /** the output buffer */
1400 AliHLTUInt8_t* fpOutputBuffer; //! transient
1401
1402 /** size of the output buffer */
1403 AliHLTUInt32_t fOutputBufferSize; // see above
1404
1405 /** size of data written to output buffer */
1406 AliHLTUInt32_t fOutputBufferFilled; // see above
1407
1408 /** list of ouput block data descriptors */
2be3f004 1409 AliHLTComponentBlockDataList fOutputBlocks; // see above
3cde846d 1410
90ebac25 1411 /** stopwatch array */
1412 TObjArray* fpStopwatches; //! transient
1413
79c114b5 1414 /** array of memory files AliHLTMemoryFile */
2be3f004 1415 AliHLTMemoryFilePList fMemFiles; //! transient
79c114b5 1416
559631d5 1417 /** descriptor of the current run */
1418 AliHLTRunDesc* fpRunDesc; //! transient
1419
1420 /** the current DDL list */
1421 AliHLTEventDDL* fpDDLList; //! transient
1422
82c58a87 1423 /** external fct to set CDB run no, indicates external CDB initialization */
1424 void* fCDBSetRunNoFunc; //! transient
579d9eb7 1425
1426 /** id of the component in the analysis chain */
1427 string fChainId; //! transient
1428
48abe484 1429 /** crc value of the chainid, used as a 32bit id */
1430 AliHLTUInt32_t fChainIdCrc; //! transient
1431
a0aeb701 1432 /** optional benchmarking for the component statistics */
1433 TStopwatch* fpBenchmark; //! transient
1434
1435 /** component requires steering data blocks */
1436 bool fRequireSteeringBlocks; //! transient
1437
48abe484 1438 /** current event type */
1439 AliHLTUInt32_t fEventType; //! transient
1440
abb52c8f 1441 /** component arguments */
1442 string fComponentArgs; //! transient
1443
eafbc306 1444
1445 /** event done data */
1446 AliHLTComponentEventDoneData* fEventDoneData; //! transient
1447
1448 /** Reserved size of the memory stored at fEventDoneData */
1449 unsigned long fEventDoneDataSize; //! transient
1450
48abe484 1451 ClassDef(AliHLTComponent, 8)
f23a6e1a 1452};
1453#endif