]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponent.h
som minor changes, committed to be in synch with build system
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.h
CommitLineData
a655eae3 1//-*- Mode: C++ -*-
f23a6e1a 2// @(#) $Id$
3
4#ifndef ALIHLTCOMPONENT_H
5#define ALIHLTCOMPONENT_H
79c114b5 6/* This file is property of and copyright by the ALICE HLT Project *
7 * ALICE Experiment at CERN, All rights reserved. *
f23a6e1a 8 * See cxx source for full Copyright notice */
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
30338a30 16
17// see below for class documentation
18// or
19// refer to README to build package
20// or
21// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
b22e91eb 22 */
23/**
24 * @defgroup alihlt_component Component handling of the HLT module
25 * This section describes the the component handling for the HLT module.
26 */
8ede8717 27
28#include <vector>
9ce4bf4a 29#include <string>
5ec8e281 30#include "AliHLTLogging.h"
f23a6e1a 31#include "AliHLTDataTypes.h"
66043029 32//#include "AliHLTDefinitions.h"
f23a6e1a 33
2d7ff710 34/* Matthias Dec 2006
35 * The names have been changed for Aliroot's coding conventions sake
36 * The old names are defined for backward compatibility with the
37 * stand alone SampleLib package
38 */
39typedef AliHLTComponentLogSeverity AliHLTComponent_LogSeverity;
40typedef AliHLTComponentEventData AliHLTComponent_EventData;
41typedef AliHLTComponentShmData AliHLTComponent_ShmData;
42typedef AliHLTComponentDataType AliHLTComponent_DataType;
43typedef AliHLTComponentBlockData AliHLTComponent_BlockData;
44typedef AliHLTComponentTriggerData AliHLTComponent_TriggerData;
45typedef AliHLTComponentEventDoneData AliHLTComponent_EventDoneData;
46
f23a6e1a 47class AliHLTComponentHandler;
a655eae3 48class TObjArray;
90ebac25 49class TStopwatch;
79c114b5 50class AliHLTMemoryFile;
f23a6e1a 51
bfccbf68 52/**
53 * @class AliHLTComponent
54 * Base class of HLT data processing components.
55 * The class provides a common interface for HLT data processing components.
56 * The interface can be accessed from the online HLT framework or the AliRoot
57 * offline analysis framework.
a655eae3 58 * @section alihltcomponent-properties Component identification and properties
59 * Each component must provide a unique ID, input and output data type indications,
60 * and a spawn function.
61 * @subsection alihltcomponent-req-methods Required property methods
62 * - @ref GetComponentID
63 * - @ref GetInputDataTypes (see @ref alihltcomponent-type for default
64 * implementations.)
65 * - @ref GetOutputDataType (see @ref alihltcomponent-type for default
66 * implementations.)
67 * - @ref GetOutputDataSize (see @ref alihltcomponent-type for default
68 * implementations.)
69 * - @ref Spawn
bfccbf68 70 *
a655eae3 71 * @subsection alihltcomponent-opt-mehods Optional handlers
72 * - @ref DoInit
73 * - @ref DoDeinit
74 *
75 * @subsection alihltcomponent-processing-mehods Data processing
76 *
77 *
78 * @subsection alihltcomponent-type Component type
79 * Components can be of type
90ebac25 80 * - @ref kSource components which only produce data
81 * - @ref kProcessor components which consume and produce data
82 * - @ref kSink components which only consume data
a655eae3 83 *
84 * where data production and consumption refer to the analysis data stream. In
85 * order to indicate the type, a child component can overload the
86 * @ref GetComponentType function.
87 * @subsubsection alihltcomponent-type-std Standard implementations
88 * Components in general do not need to implement this function, standard
89 * implementations of the 3 types are available:
90 * - AliHLTDataSource for components of type @ref kSource <br>
91 * All types of data sources can inherit from AliHLTDataSource and must
92 * implement the @ref AliHLTDataSource::GetEvent method. The class
93 * also implements a standard method for @ref GetInputDataTypes.
94 *
95 * - AliHLTProcessor for components of type @ref kProcessor <br>
96 * All types of data processors can inherit from AliHLTDataSource and must
97 * implement the @ref AliHLTProcessor::DoEvent method.
98 *
99 * - AliHLTDataSink for components of type @ref kSink <br>
100 * All types of data processors can inherit from AliHLTDataSource and must
101 * implement the @ref AliHLTDataSink::DumpEvent method. The class
102 * also implements a standard method for @ref GetOutputDataType and @ref
103 * GetOutputDataSize.
104 *
105 * @subsection alihltcomponent-environment Running environment
bfccbf68 106 *
107 * In order to adapt to different environments (on-line/off-line), the component
108 * gets an environment structure with function pointers. The base class provides
109 * member functions for those environment dependend functions. The member
110 * functions are used by the component implementation and are re-mapped to the
111 * corresponding functions.
a655eae3 112 * @section alihltcomponent-interfaces Component interfaces
113 * Each of the 3 standard component base classes AliHLTProcessor, AliHLTDataSource
114 * and AliHLTDataSink provides it's own processing method (see
115 * @ref alihltcomponent-type-std), which splits into a high and a low-level
116 * method. For the @ref alihltcomponent-low-level-interface, all parameters are
117 * shipped as function arguments, the component is supposed to dump data to the
118 * output buffer and handle all block descriptors.
119 * The @ref alihltcomponent-high-level-interface is the standard processing
120 * method and will be used whenever the low-level method is not overloaded.
121 *
122 * @subsection alihltcomponent-high-level-interface High-level interface
123 * The high-level component interface provides functionality to exchange ROOT
124 * structures between components. In contrast to the
125 * @ref alihltcomponent-low-level-interface, a couple of functions can be used
126 * to access data blocks of the input stream
127 * and send data blocks or ROOT TObject's to the output stream. The functionality
128 * is hidden from the user and is implemented by using ROOT's TMessage class.
129 *
130 * @subsubsection alihltcomponent-high-level-int-methods Interface methods
131 * The interface provides a couple of methods in order to get objects from the
132 * input, data blocks (non TObject) from the input, and to push back objects and
133 * data blocks to the output. For convenience there are several functions of
134 * identical name (and similar behavior) with different parameters defined.
135 * Please refer to the function documentation.
136 * - @ref GetNumberOfInputBlocks <br>
137 * return the number of data blocks in the input stream
138 * - @ref GetFirstInputObject <br>
139 * get the first object of a specific data type
140 * - @ref GetNextInputObject <br>
141 * get the next object of same data type as last GetFirstInputObject/Block call
142 * - @ref GetFirstInputBlock <br>
143 * get the first block of a specific data type
144 * - @ref GetNextInputBlock <br>
145 * get the next block of same data type as last GetFirstInputBlock/Block call
146 * - @ref PushBack <br>
147 * insert an object or data buffer into the output
148 * - @ref CreateEventDoneData <br>
149 * add event information to the output
150 *
151 * In addition, the processing methods are simplified a bit by cutting out most of
79c114b5 152 * the parameters.
153 * @see
154 * - @ref AliHLTProcessor::DoEvent
155 * - @ref AliHLTDataSource::GetEvent
156 * - @ref AliHLTDataSink::DumpEvent
a655eae3 157 *
8451168b 158 * \em IMPORTANT: objects and block descriptors provided by the high-level interface
159 * <b>MUST NOT BE DELETED</b> by the caller.
160 *
a655eae3 161 * @subsubsection alihltcomponent-high-level-int-guidelines High-level interface guidelines
162 * - Structures must inherit from the ROOT object base class TObject in order be
163 * transported by the transportation framework.
164 * - all pointer members must be transient (marked <tt>//!</tt> behind the member
165 * definition), i.e. will not be stored/transported, or properly marked
166 * (<tt>//-></tt>) in order to call the streamer of the object the member is pointing
167 * to. The latter is not recomended. Structures to be transported between components
168 * should be streamlined.
169 * - no use of stl vectors/strings, use appropriate ROOT classes instead
170 *
171 * @subsection alihltcomponent-low-level-interface Low-level interface
172 * The low-level component interface consists of the specific data processing
173 * methods for @ref AliHLTProcessor, @ref AliHLTDataSource, and @ref AliHLTDataSink.
174 * - @ref AliHLTProcessor::DoEvent
175 * - @ref AliHLTDataSource::GetEvent
176 * - @ref AliHLTDataSink::DumpEvent
177 *
178 *
179 * @section alihltcomponent-handling Component handling
180 * The handling of HLT analysis components is carried out by the AliHLTComponentHandler.
181 * Component are registered automatically at load-time of the component shared library
182 * under the following suppositions:
183 * - the component library has to be loaded from the AliHLTComponentHandler using the
184 * @ref AliHLTComponentHandler::LoadLibrary method.
185 * - the component implementation defines one global object (which is generated
186 * when the library is loaded)
187 *
188 * @subsection alihltcomponent-design-rules General design considerations
189 * The analysis code should be implemented in one or more destict class(es). A
190 * \em component should be implemented which interface the destict analysis code to the
191 * component interface. This component generates the analysis object dynamically. <br>
192 *
193 * Assume you have an implemetation <tt> AliHLTDetMyAnalysis </tt>, another class <tt>
194 * AliHLTDetMyAnalysisComponent </tt> contains:
195 * <pre>
196 * private:
197 * AliHLTDetMyAnalysis* fMyAnalysis; //!
198 * </pre>
199 * The object should then be instantiated in the DoInit handler of
200 * <tt>AliHLTDetMyAnalysisComponent </tt>, and cleaned in the DoDeinit handler.
201 *
202 * Further rules:
203 * - avoid big static arrays in the component, allocate the memory at runtime
204 *
b22e91eb 205 * @ingroup alihlt_component
a655eae3 206 * @section alihltcomponent-members Class members
bfccbf68 207 */
5ec8e281 208class AliHLTComponent : public AliHLTLogging {
f23a6e1a 209 public:
bfccbf68 210 /** standard constructor */
f23a6e1a 211 AliHLTComponent();
70ed7d01 212 /** not a valid copy constructor, defined according to effective C++ style */
213 AliHLTComponent(const AliHLTComponent&);
214 /** not a valid assignment op, but defined according to effective C++ style */
215 AliHLTComponent& operator=(const AliHLTComponent&);
bfccbf68 216 /** standard destructor */
f23a6e1a 217 virtual ~AliHLTComponent();
218
bfccbf68 219 /** component type definitions */
f23a6e1a 220 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
bfccbf68 221
222 /**
223 * Init function to prepare data processing.
224 * Initialization of common data structures for a sequence of events.
225 * The call is redirected to the internal method @ref DoInit which can be
226 * overridden by the child class.<br>
227 * During Init also the environment structure is passed to the component.
228 * @param environ environment pointer with environment dependend function
229 * calls
70ed7d01 230 * @param environParam additionel parameter for function calls, the pointer
bfccbf68 231 * is passed as it is
232 * @param argc size of the argument array
233 * @param argv agument array for component initialization
234 */
70ed7d01 235 virtual int Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv );
bfccbf68 236
237 /**
238 * Clean-up function to terminate data processing.
239 * Clean-up of common data structures after data processing.
240 * The call is redirected to the internal method @ref DoDeinit which can be
241 * overridden by the child class.
242 */
f23a6e1a 243 virtual int Deinit();
bfccbf68 244
245 /**
246 * Processing of one event.
3cde846d 247 * The method is the entrance of the event processing. The parameters are
248 * cached for uses with the high-level interface and the DoProcessing
249 * implementation is called.
250 *
251 * @param evtData
252 * @param blocks
253 * @param trigData
254 * @param outputPtr
255 * @param size
256 * @param outputBlockCnt out: size of the output block array, set by the component
257 * @param outputBlocks out: the output block array is allocated internally
258 * @param edd
259 * @return neg. error code if failed
260 */
261 int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
262 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
263 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
264 AliHLTComponentBlockData*& outputBlocks,
265 AliHLTComponentEventDoneData*& edd );
266
267 /**
268 * Internal processing of one event.
bfccbf68 269 * The method is pure virtual and implemented by the child classes
270 * - @ref AliHLTProcessor
271 * - @ref AliHLTDataSource
272 * - @ref AliHLTDataSink
273 *
274 * @param evtData
275 * @param blocks
276 * @param trigData
277 * @param outputPtr
278 * @param size
2d7ff710 279 * @param outputBlocks out: the output block array is allocated internally
bfccbf68 280 * @param edd
281 * @return neg. error code if failed
282 */
3cde846d 283 virtual int DoProcessing( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
8ede8717 284 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
a655eae3 285 AliHLTUInt32_t& size,
286 vector<AliHLTComponentBlockData>& outputBlocks,
8ede8717 287 AliHLTComponentEventDoneData*& edd ) = 0;
f23a6e1a 288
289 // Information member functions for registration.
bfccbf68 290
291 /**
292 * Get the type of the component.
293 * The function is pure virtual and must be implemented by the child class.
294 * @return component type id
295 */
f23a6e1a 296 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
bfccbf68 297
298 /**
299 * Get the id of the component.
300 * Each component is identified by a unique id.
301 * The function is pure virtual and must be implemented by the child class.
302 * @return component id (string)
303 */
f23a6e1a 304 virtual const char* GetComponentID() = 0;
bfccbf68 305
306 /**
307 * Get the input data types of the component.
308 * The function is pure virtual and must be implemented by the child class.
309 * @return list of data types in the vector reference
310 */
8ede8717 311 virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& ) = 0;
bfccbf68 312
313 /**
314 * Get the output data type of the component.
315 * The function is pure virtual and must be implemented by the child class.
316 * @return output data type
317 */
8ede8717 318 virtual AliHLTComponentDataType GetOutputDataType() = 0;
bfccbf68 319
320 /**
321 * Get a ratio by how much the data volume is shrinked or enhanced.
322 * The function is pure virtual and must be implemented by the child class.
323 * @param constBase <i>return</i>: additive part, independent of the
324 * input data volume
325 * @param inputMultiplier <i>return</i>: multiplication ratio
326 * @return values in the reference variables
327 */
71d7c760 328 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
f23a6e1a 329
bfccbf68 330 /**
331 * Spawn function.
332 * Each component must implement a spawn function to create a new instance of
333 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
334 * @return new class instance
335 */
f23a6e1a 336 virtual AliHLTComponent* Spawn() = 0;
0c0c9d99 337
bfccbf68 338 /**
339 * Find matching data types between this component and a consumer component.
340 * Currently, a component can produce only one type of data. This restriction is most
341 * likely to be abolished in the future.
342 * @param pConsumer a component and consumer of the data produced by this component
343 * @param tgtList reference to a vector list to receive the matching data types.
344 * @return >= 0 success, neg. error code if failed
345 */
8ede8717 346 int FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList);
f23a6e1a 347
bfccbf68 348 /**
349 * Set the global component handler.
350 * The static method is needed for the automatic registration of components.
351 */
85869391 352 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
bfccbf68 353
354 /**
355 * Clear the global component handler.
356 * The static method is needed for the automatic registration of components.
357 */
85869391 358 static int UnsetGlobalComponentHandler();
bfccbf68 359
9ce4bf4a 360 /**
361 * Helper function to convert the data type to a string.
362 */
363 static string DataType2Text( const AliHLTComponentDataType& type );
364
5f5b708b 365 /**
366 * Helper function to print content of data type.
367 */
368 void PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format=NULL) const;
369
9ce4bf4a 370 /**
371 * helper function to initialize AliHLTComponentEventData structure
372 */
373 static void FillEventData(AliHLTComponentEventData& evtData);
374
375 /**
376 * Print info on an AliHLTComponentDataType structure
377 * This is just a helper function to examine an @ref AliHLTComponentDataType
378 * structur.
379 */
380 void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
381
90ebac25 382 /**
383 * Stopwatch type for benchmarking.
384 */
385 enum AliHLTStopwatchType {
386 /** total time for event processing */
387 kSWBase,
388 /** detector algorithm w/o interface callbacks */
389 kSWDA,
390 /** data sources */
391 kSWInput,
392 /** data sinks */
393 kSWOutput,
394 /** number of types */
395 kSWTypeCount
396 };
397
398 /**
399 * Helper class for starting and stopping a stopwatch.
400 * The guard can be used by instantiating an object in a function. The
401 * specified stopwatch is started and the previous stopwatch put on
402 * hold. When the function is terminated, the object is deleted automatically
403 * deleted, stopping the stopwatch and starting the one on hold.<br>
404 * \em IMPORTANT: never create dynamic objects from this guard as this violates
405 * the idea of a guard.
406 */
407 class AliHLTStopwatchGuard {
408 public:
409 /** standard constructor (not for use) */
410 AliHLTStopwatchGuard();
411 /** constructor */
412 AliHLTStopwatchGuard(TStopwatch* pStart);
413 /** copy constructor (not for use) */
e419b223 414 AliHLTStopwatchGuard(const AliHLTStopwatchGuard&);
415 /** assignment operator (not for use) */
416 AliHLTStopwatchGuard& operator=(const AliHLTStopwatchGuard&);
90ebac25 417 /** destructor */
418 ~AliHLTStopwatchGuard();
419
420 private:
421 /**
422 * Hold the previous guard for the existence of this guard.
423 * Checks whether this guard controls a new stopwatch. In that case, the
424 * previous guard and its stopwatch are put on hold.
425 * @param pSucc instance of the stopwatch of the new guard
426 * @return 1 if pSucc is a different stopwatch which should
427 * be started<br>
428 * 0 if it controls the same stopwatch
429 */
430 int Hold(TStopwatch* pSucc);
431
432 /**
433 * Resume the previous guard.
434 * Checks whether the peceeding guard controls a different stopwatch. In that
435 * case, the its stopwatch is resumed.
436 * @param pSucc instance of the stopwatch of the new guard
437 * @return 1 if pSucc is a different stopwatch which should
438 * be stopped<br>
439 * 0 if it controls the same stopwatch
440 */
441 int Resume(TStopwatch* pSucc);
442
443 /** the stopwatch controlled by this guard */
444 TStopwatch* fpStopwatch; //!transient
445
446 /** previous stopwatch guard, put on hold during existence of the guard */
447 AliHLTStopwatchGuard* fpPrec; //!transient
448
449 /** active stopwatch guard */
450 static AliHLTStopwatchGuard* fgpCurrent; //!transient
451 };
452
453 /**
454 * Set a stopwatch for a given purpose.
455 * @param pSW stopwatch object
456 * @param type type of the stopwatch
457 */
458 int SetStopwatch(TObject* pSW, AliHLTStopwatchType type=kSWBase);
459
460 /**
461 * Init a set of stopwatches.
462 * @param pStopwatches object array of stopwatches
463 */
464 int SetStopwatches(TObjArray* pStopwatches);
a655eae3 465
f23a6e1a 466 protected:
71d7c760 467
bfccbf68 468 /**
8ede8717 469 * Fill AliHLTComponentBlockData structure with default values.
bfccbf68 470 * @param blockData reference to data structure
471 */
70ed7d01 472 void FillBlockData( AliHLTComponentBlockData& blockData ) const;
bfccbf68 473
474 /**
8ede8717 475 * Fill AliHLTComponentShmData structure with default values.
bfccbf68 476 * @param shmData reference to data structure
477 */
70ed7d01 478 void FillShmData( AliHLTComponentShmData& shmData ) const;
bfccbf68 479
480 /**
8ede8717 481 * Fill AliHLTComponentDataType structure with default values.
bfccbf68 482 * @param dataType reference to data structure
483 */
70ed7d01 484 void FillDataType( AliHLTComponentDataType& dataType ) const;
f23a6e1a 485
2d7ff710 486 /**
487 * Copy data type structure
488 * Copies the value an AliHLTComponentDataType structure to another one
489 * @param[out] tgtdt target structure
490 * @param[in] srcdt source structure
491 */
492 void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
493
494 /**
495 * Set the ID and Origin of an AliHLTComponentDataType structure.
496 * The function sets the fStructureSize member and copies the strings
497 * to the ID and Origin. Only characters from the valid part of the string
498 * are copied, the rest is fille with 0's.
499 * Please note that the fID and fOrigin members are not strings, just arrays of
500 * chars of size @ref kAliHLTComponentDataTypefIDsize and
21745ddc 501 * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
2d7ff710 502 * a terminating zero.
9ce4bf4a 503 * @param tgtdt target data type structure
2d7ff710 504 * @param id ID string
505 * @param origin Origin string
506 */
507 void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
508
bfccbf68 509 /**
510 * Default method for the internal initialization.
511 * The method is called by @ref Init
512 */
53feaef5 513 virtual int DoInit( int argc, const char** argv );
f23a6e1a 514
bfccbf68 515 /**
516 * Default method for the internal clean-up.
517 * The method is called by @ref Deinit
518 */
53feaef5 519 virtual int DoDeinit();
f23a6e1a 520
bfccbf68 521 /**
522 * General memory allocation method.
523 * All memory which is going to be used 'outside' of the interface must
524 * be provided by the framework (online or offline).
525 * The method is redirected to a function provided by the current
526 * framework. Function pointers are transferred via the @ref
527 * AliHLTComponentEnvironment structure.
528 */
85869391 529 void* AllocMemory( unsigned long size );
f23a6e1a 530
bfccbf68 531 /**
532 * Helper function to create a monolithic BlockData description block out
533 * of a list BlockData descriptors.
534 * For convenience, inside the interface vector lists are used, to make the
535 * interface pure C style, monilithic blocks must be exchanged.
536 * The method is redirected to a function provided by the current
537 * framework. Function pointers are transferred via the @ref
538 * AliHLTComponentEnvironment structure.
539 */
8ede8717 540 int MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
541 AliHLTComponentBlockData** outputBlocks );
f23a6e1a 542
bfccbf68 543 /**
544 * Fill the EventDoneData structure.
545 * The method is redirected to a function provided by the current
546 * framework. Function pointers are transferred via the @ref
547 * AliHLTComponentEnvironment structure.
548 */
8ede8717 549 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd );
f23a6e1a 550
bfccbf68 551 /**
552 * Helper function to convert the data type to a string.
553 */
70ed7d01 554 void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]) const;
fa2e9b7c 555
3cde846d 556 /**
557 * Get event number.
558 * @return value of the internal event counter
559 */
70ed7d01 560 int GetEventCount() const;
3cde846d 561
a655eae3 562 /**
563 * Get the number of input blocks.
564 * @return number of input blocks
565 */
66043029 566 int GetNumberOfInputBlocks() const;
a655eae3 567
568 /**
569 * Get the first object of a specific data type from the input data.
570 * The hight-level methods provide functionality to transfer ROOT data
571 * structures which inherit from TObject.
572 * The method looks for the first ROOT object of type dt in the input stream.
573 * If also the class name is provided, the object is checked for the right
574 * class type. The input data block needs a certain structure, namely the
575 * buffer size as first word. If the cross check fails, the retrieval is
8451168b 576 * silently abondoned, unless the \em bForce parameter is set.<br>
577 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
a655eae3 578 * @param dt data type of the object
579 * @param classname class name of the object
580 * @param bForce force the retrieval of an object, error messages
581 * are suppressed if \em bForce is not set
582 * @return pointer to @ref TObject, NULL if no objects of specified type
583 * available
584 */
585 const TObject* GetFirstInputObject(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
586 const char* classname=NULL,
587 int bForce=0);
588
589 /**
590 * Get the first object of a specific data type from the input data.
591 * The hight-level methods provide functionality to transfer ROOT data
592 * structures which inherit from TObject.
593 * The method looks for the first ROOT object of type specified by the ID and
594 * Origin strings in the input stream.
595 * If also the class name is provided, the object is checked for the right
596 * class type. The input data block needs a certain structure, namely the
597 * buffer size as first word. If the cross check fails, the retrieval is
8451168b 598 * silently abondoned, unless the \em bForce parameter is set.<br>
599 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
a655eae3 600 * @param dtID data type ID of the object
601 * @param dtOrigin data type origin of the object
602 * @param classname class name of the object
603 * @param bForce force the retrieval of an object, error messages
604 * are suppressed if \em bForce is not set
605 * @return pointer to @ref TObject, NULL if no objects of specified type
606 * available
607 */
608 const TObject* GetFirstInputObject(const char* dtID,
609 const char* dtOrigin,
610 const char* classname=NULL,
611 int bForce=0);
612
613 /**
614 * Get the next object of a specific data type from the input data.
615 * The hight-level methods provide functionality to transfer ROOT data
616 * structures which inherit from TObject.
617 * The method looks for the next ROOT object of type and class specified
8451168b 618 * to the previous @ref GetFirstInputObject call.<br>
619 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
a655eae3 620 * @param bForce force the retrieval of an object, error messages
621 * are suppressed if \em bForce is not set
622 * @return pointer to @ref TObject, NULL if no more objects available
623 */
624 const TObject* GetNextInputObject(int bForce=0);
625
626 /**
627 * Get data type of an input block.
628 * Get data type of the object previously fetched via
629 * GetFirstInputObject/NextInputObject or the last one if no object
630 * specified.
631 * @param pObject pointer to TObject
632 * @return data specification, kAliHLTVoidDataSpec if failed
633 */
634 AliHLTComponentDataType GetDataType(const TObject* pObject=NULL);
635
636 /**
637 * Get data specification of an input block.
638 * Get data specification of the object previously fetched via
639 * GetFirstInputObject/NextInputObject or the last one if no object
640 * specified.
641 * @param pObject pointer to TObject
642 * @return data specification, kAliHLTVoidDataSpec if failed
643 */
644 AliHLTUInt32_t GetSpecification(const TObject* pObject=NULL);
645
646 /**
647 * Get the first block of a specific data type from the input data.
648 * The method looks for the first block of type dt in the input stream. It is intended
8451168b 649 * to be used within the high-level interface.<br>
650 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 651 * @param dt data type of the block
652 * @return pointer to @ref AliHLTComponentBlockData
653 */
654 const AliHLTComponentBlockData* GetFirstInputBlock(const AliHLTComponentDataType& dt=kAliHLTAnyDataType);
655
656 /**
657 * Get the first block of a specific data type from the input data.
658 * The method looks for the first block of type specified by the ID and
659 * Origin strings in the input stream. It is intended
8451168b 660 * to be used within the high-level interface.<br>
661 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 662 * @param dtID data type ID of the block
663 * @param dtOrigin data type origin of the block
664 * @return pointer to @ref AliHLTComponentBlockData
665 */
666 const AliHLTComponentBlockData* GetFirstInputBlock(const char* dtID,
667 const char* dtOrigin);
668
669 /**
8451168b 670 * Get input block by index.<br>
671 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 672 * @return pointer to AliHLTComponentBlockData, NULL if index out of range
673 */
674 const AliHLTComponentBlockData* GetInputBlock(int index);
675
676 /**
677 * Get the next block of a specific data type from the input data.
678 * The method looks for the next block of type and class specified
679 * to the previous @ref GetFirstInputBlock call.
8451168b 680 * To be used within the high-level interface.<br>
681 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 682 */
683 const AliHLTComponentBlockData* GetNextInputBlock();
684
685 /**
686 * Get data specification of an input block.
687 * Get data specification of the input bblock previously fetched via
688 * GetFirstInputObject/NextInputObject or the last one if no block
689 * specified.
690 * @param pBlock pointer to input block
691 * @return data specification, kAliHLTVoidDataSpec if failed
692 */
693 AliHLTUInt32_t GetSpecification(const AliHLTComponentBlockData* pBlock=NULL);
694
695 /**
696 * Insert an object into the output.
79c114b5 697 * If header is specified, it will be inserted before the root object,
698 * default is no header.
a655eae3 699 * @param pObject pointer to root object
700 * @param dt data type of the object
701 * @param spec data specification
79c114b5 702 * @param pHeader pointer to header
703 * @param headerSize size of Header
a655eae3 704 * @return neg. error code if failed
705 */
706 int PushBack(TObject* pObject, const AliHLTComponentDataType& dt,
79c114b5 707 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
708 void* pHeader=NULL, int headerSize=0);
a655eae3 709
710 /**
711 * Insert an object into the output.
79c114b5 712 * If header is specified, it will be inserted before the root object,
713 * default is no header.
a655eae3 714 * @param pObject pointer to root object
715 * @param dtID data type ID of the object
716 * @param dtOrigin data type origin of the object
717 * @param spec data specification
79c114b5 718 * @param pHeader pointer to header
719 * @param headerSize size of Header
a655eae3 720 * @return neg. error code if failed
721 */
722 int PushBack(TObject* pObject, const char* dtID, const char* dtOrigin,
79c114b5 723 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
724 void* pHeader=NULL, int headerSize=0);
725
a655eae3 726 /**
727 * Insert an object into the output.
728 * @param pBuffer pointer to buffer
729 * @param iSize size of the buffer
730 * @param dt data type of the object
731 * @param spec data specification
732 * @return neg. error code if failed
733 */
734 int PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt,
735 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
736
737 /**
738 * Insert an object into the output.
739 * @param pBuffer pointer to buffer
740 * @param iSize size of the buffer
741 * @param dtID data type ID of the object
742 * @param dtOrigin data type origin of the object
743 * @param spec data specification
744 * @return neg. error code if failed
745 */
746 int PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin,
747 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
748
8451168b 749 /**
750 * Estimate size of a TObject
751 * @param pObject
752 * @return buffer size in byte
753 */
754 int EstimateObjectSize(TObject* pObject) const;
755
79c114b5 756 /**
757 * Create a memory file in the output stream.
758 * This method creates a TFile object which stores all data in
759 * memory instead of disk. The TFile object is published as binary data.
760 * The instance can be used like a normal TFile object. The TFile::Close
761 * or @ref CloseMemoryFile method has to be called in order to flush the
762 * output stream.
763 *
764 * \b Note: The returned object is deleted by the framework.
765 * @param capacity total size reserved for the memory file
766 * @param dtID data type ID of the file
767 * @param dtOrigin data type origin of the file
768 * @param spec data specification
769 * @return file handle, NULL if failed
770 */
771 AliHLTMemoryFile* CreateMemoryFile(int capacity, const char* dtID, const char* dtOrigin,
772 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
773
774 /**
775 * Create a memory file in the output stream.
776 * This method creates a TFile object which stores all data in
777 * memory instead of disk. The TFile object is published as binary data.
778 * The instance can be used like a normal TFile object. The TFile::Close
779 * or @ref CloseMemoryFile method has to be called in order to flush the
780 * output stream.
781 *
782 * \b Note: The returned object is deleted by the framework.
783 * @param capacity total size reserved for the memory file
784 * @param dt data type of the file
785 * @param spec data specification
786 * @return file handle, NULL if failed
787 */
788 AliHLTMemoryFile* CreateMemoryFile(int capacity,
789 const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
790 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
791
792 /**
793 * Create a memory file in the output stream.
794 * This method creates a TFile object which stores all data in
795 * memory instead of disk. The TFile object is published as binary data.
796 * The instance can be used like a normal TFile object. The TFile::Close
797 * or @ref CloseMemoryFile method has to be called in order to flush the
798 * output stream.
799 *
800 * \b Note: The returned object is deleted by the framework.
801 * @param dtID data type ID of the file
802 * @param dtOrigin data type origin of the file
803 * @param spec data specification
804 * @param capacity fraction of the available output buffer size
805 * @return file handle, NULL if failed
806 */
807 AliHLTMemoryFile* CreateMemoryFile(const char* dtID, const char* dtOrigin,
808 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
809 float capacity=1.0);
810
811 /**
812 * Create a memory file in the output stream.
813 * This method creates a TFile object which stores all data in
814 * memory instead of disk. The TFile object is published as binary data.
815 * The instance can be used like a normal TFile object. The TFile::Close
816 * or @ref CloseMemoryFile method has to be called in order to flush the
817 * output stream.
818 *
819 * \b Note: The returned object is deleted by the framework.
820 * @param dt data type of the file
821 * @param spec data specification
822 * @param capacity fraction of the available output buffer size
823 * @return file handle, NULL if failed
824 */
825 AliHLTMemoryFile* CreateMemoryFile(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
826 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
827 float capacity=1.0);
828
829 /**
830 * Write an object to memory file in the output stream.
831 * @param pFile file handle
832 * @param pObject pointer to root object
833 * @param key key in ROOT file
834 * @param option options, see TObject::Write
835 * @return neg. error code if failed
836 * - -ENOSPC no space left
837 */
838 int Write(AliHLTMemoryFile* pFile, const TObject* pObject, const char* key=NULL, int option=TObject::kOverwrite);
839
840 /**
841 * Close object memory file.
842 * @param pFile file handle
843 * @return neg. error code if failed
844 * - -ENOSPC buffer size too small
845 */
846 int CloseMemoryFile(AliHLTMemoryFile* pFile);
847
a655eae3 848 /**
849 * Insert event-done data information into the output.
850 * @param edd event-done data information
851 */
852 int CreateEventDoneData(AliHLTComponentEventDoneData edd);
853
f23a6e1a 854 private:
3cde846d 855 /**
856 * Increment the internal event counter.
857 * To be used by the friend classes AliHLTProcessor, AliHLTDataSource
858 * and AliHLTDataSink.
859 * @return new value of the internal event counter
a655eae3 860 * @internal
3cde846d 861 */
862 int IncrementEventCounter();
863
a655eae3 864 /**
865 * Find the first input block of specified data type beginning at index.
1edbbe49 866 * Input blocks containing a TObject have the size of the object as an
867 * unsigned 32 bit number in the first 4 bytes. This has to match the block
868 * size minus 4.
a655eae3 869 * @param dt data type
870 * @param startIdx index to start the search
1edbbe49 871 * @param bObject check if this is an object
a655eae3 872 * @return index of the block, -ENOENT if no block found
873 *
874 * @internal
875 */
1edbbe49 876 int FindInputBlock(const AliHLTComponentDataType& dt, int startIdx=-1, int bObject=0) const;
a655eae3 877
878 /**
879 * Get index in the array of input bocks.
880 * Calculate index and check integrety of a block data structure pointer.
881 * @param pBlock pointer to block data
882 * @return index of the block, -ENOENT if no block found
883 *
884 * @internal
885 */
66043029 886 int FindInputBlock(const AliHLTComponentBlockData* pBlock) const;
a655eae3 887
888 /**
889 * Create an object from a specified input block.
890 * @param idx index of the input block
891 * @param bForce force the retrieval of an object, error messages
892 * are suppressed if \em bForce is not set
893 * @return pointer to TObject, caller must delete the object after use
894 *
895 * @internal
896 */
897 TObject* CreateInputObject(int idx, int bForce=0);
898
899 /**
900 * Get input object
8451168b 901 * Get object from the input block list. The methods first checks whether the
902 * object was already created. If not, it is created by @ref CreateInputObject
903 * and inserted into the list of objects.
a655eae3 904 * @param idx index in the input block list
905 * @param classname name of the class, object is checked for correct class
906 * name if set
907 * @param bForce force the retrieval of an object, error messages
908 * are suppressed if \em bForce is not set
909 * @return pointer to TObject
910 *
911 * @internal
912 */
913 TObject* GetInputObject(int idx, const char* classname=NULL, int bForce=0);
914
8451168b 915 /**
916 * Clean the list of input objects.
917 * Cleanup is done at the end of each event processing.
918 */
919 int CleanupInputObjects();
920
a655eae3 921 /**
922 * Insert a buffer into the output block stream.
923 * This is the only method to insert blocks into the output stream, called
924 * from all types of the Pushback method. The actual data might have been
925 * written to the output buffer already. In that case NULL can be provided
79c114b5 926 * as buffer, only the block descriptor will be build. If a header is specified,
927 * it will be inserted before the buffer, default is no header.
a655eae3 928 * @param pBuffer pointer to buffer
929 * @param iSize size of the buffer in byte
930 * @param dt data type
931 * @param spec data specification
79c114b5 932 * @param pHeader pointer to header
933 * @param iHeaderSize size of Header
a655eae3 934 */
79c114b5 935 int InsertOutputBlock(void* pBuffer, int iBufferSize,
a655eae3 936 const AliHLTComponentDataType& dt,
79c114b5 937 AliHLTUInt32_t spec,
938 void* pHeader=NULL, int iHeaderSize=0);
a655eae3 939
bfccbf68 940 /** The global component handler instance */
a655eae3 941 static AliHLTComponentHandler* fgpComponentHandler; //! transient
70ed7d01 942
bfccbf68 943 /** The environment where the component is running in */
a655eae3 944 AliHLTComponentEnvironment fEnvironment; // see above
f23a6e1a 945
a655eae3 946 /** Set by ProcessEvent before the processing starts */
947 AliHLTEventID_t fCurrentEvent; // see above
f23a6e1a 948
3cde846d 949 /** internal event no */
a655eae3 950 int fEventCount; // see above
951
952 /** the number of failed events */
953 int fFailedEvents; // see above
954
955 /** event data struct of the current event under processing */
956 AliHLTComponentEventData fCurrentEventData; // see above
957
958 /** array of input data blocks of the current event */
959 const AliHLTComponentBlockData* fpInputBlocks; //! transient
960
961 /** index of the current input block */
962 int fCurrentInputBlock; // see above
963
964 /** data type of the last block search */
965 AliHLTComponentDataType fSearchDataType; // see above
966
967 /** name of the class for the object to search for */
968 string fClassName; // see above
969
970 /** array of generated input objects */
971 TObjArray* fpInputObjects; //! transient
972
973 /** the output buffer */
974 AliHLTUInt8_t* fpOutputBuffer; //! transient
975
976 /** size of the output buffer */
977 AliHLTUInt32_t fOutputBufferSize; // see above
978
979 /** size of data written to output buffer */
980 AliHLTUInt32_t fOutputBufferFilled; // see above
981
982 /** list of ouput block data descriptors */
983 vector<AliHLTComponentBlockData> fOutputBlocks; // see above
3cde846d 984
90ebac25 985 /** stopwatch array */
986 TObjArray* fpStopwatches; //! transient
987
79c114b5 988 /** array of memory files AliHLTMemoryFile */
989 vector<AliHLTMemoryFile*> fMemFiles; //! transient
990
991 ClassDef(AliHLTComponent, 3)
f23a6e1a 992};
993#endif