]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponent.h
debug build off by default, started filtering of class names in HLT logging
[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();
bfccbf68 212 /** standard destructor */
f23a6e1a 213 virtual ~AliHLTComponent();
214
bfccbf68 215 /** component type definitions */
f23a6e1a 216 enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
bfccbf68 217
218 /**
219 * Init function to prepare data processing.
220 * Initialization of common data structures for a sequence of events.
221 * The call is redirected to the internal method @ref DoInit which can be
222 * overridden by the child class.<br>
223 * During Init also the environment structure is passed to the component.
224 * @param environ environment pointer with environment dependend function
225 * calls
70ed7d01 226 * @param environParam additionel parameter for function calls, the pointer
bfccbf68 227 * is passed as it is
228 * @param argc size of the argument array
229 * @param argv agument array for component initialization
230 */
70ed7d01 231 virtual int Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv );
bfccbf68 232
233 /**
234 * Clean-up function to terminate data processing.
235 * Clean-up of common data structures after data processing.
236 * The call is redirected to the internal method @ref DoDeinit which can be
237 * overridden by the child class.
238 */
f23a6e1a 239 virtual int Deinit();
bfccbf68 240
241 /**
242 * Processing of one event.
3cde846d 243 * The method is the entrance of the event processing. The parameters are
244 * cached for uses with the high-level interface and the DoProcessing
245 * implementation is called.
246 *
247 * @param evtData
248 * @param blocks
249 * @param trigData
250 * @param outputPtr
251 * @param size
252 * @param outputBlockCnt out: size of the output block array, set by the component
253 * @param outputBlocks out: the output block array is allocated internally
254 * @param edd
255 * @return neg. error code if failed
256 */
257 int ProcessEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
258 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
259 AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt,
260 AliHLTComponentBlockData*& outputBlocks,
261 AliHLTComponentEventDoneData*& edd );
262
263 /**
264 * Internal processing of one event.
bfccbf68 265 * The method is pure virtual and implemented by the child classes
266 * - @ref AliHLTProcessor
267 * - @ref AliHLTDataSource
268 * - @ref AliHLTDataSink
269 *
270 * @param evtData
271 * @param blocks
272 * @param trigData
273 * @param outputPtr
274 * @param size
2d7ff710 275 * @param outputBlocks out: the output block array is allocated internally
bfccbf68 276 * @param edd
277 * @return neg. error code if failed
278 */
3cde846d 279 virtual int DoProcessing( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
8ede8717 280 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
a655eae3 281 AliHLTUInt32_t& size,
282 vector<AliHLTComponentBlockData>& outputBlocks,
8ede8717 283 AliHLTComponentEventDoneData*& edd ) = 0;
f23a6e1a 284
285 // Information member functions for registration.
bfccbf68 286
287 /**
288 * Get the type of the component.
289 * The function is pure virtual and must be implemented by the child class.
290 * @return component type id
291 */
f23a6e1a 292 virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
bfccbf68 293
294 /**
295 * Get the id of the component.
296 * Each component is identified by a unique id.
297 * The function is pure virtual and must be implemented by the child class.
298 * @return component id (string)
299 */
f23a6e1a 300 virtual const char* GetComponentID() = 0;
bfccbf68 301
302 /**
303 * Get the input data types of the component.
304 * The function is pure virtual and must be implemented by the child class.
305 * @return list of data types in the vector reference
306 */
8ede8717 307 virtual void GetInputDataTypes( vector<AliHLTComponentDataType>& ) = 0;
bfccbf68 308
309 /**
310 * Get the output data type of the component.
311 * The function is pure virtual and must be implemented by the child class.
312 * @return output data type
313 */
8ede8717 314 virtual AliHLTComponentDataType GetOutputDataType() = 0;
bfccbf68 315
316 /**
317 * Get a ratio by how much the data volume is shrinked or enhanced.
318 * The function is pure virtual and must be implemented by the child class.
319 * @param constBase <i>return</i>: additive part, independent of the
320 * input data volume
321 * @param inputMultiplier <i>return</i>: multiplication ratio
322 * @return values in the reference variables
323 */
71d7c760 324 virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
f23a6e1a 325
bfccbf68 326 /**
327 * Spawn function.
328 * Each component must implement a spawn function to create a new instance of
329 * the class. Basically the function must return <i>new <b>my_class_name</b></i>.
330 * @return new class instance
331 */
f23a6e1a 332 virtual AliHLTComponent* Spawn() = 0;
0c0c9d99 333
bfccbf68 334 /**
335 * Find matching data types between this component and a consumer component.
336 * Currently, a component can produce only one type of data. This restriction is most
337 * likely to be abolished in the future.
338 * @param pConsumer a component and consumer of the data produced by this component
339 * @param tgtList reference to a vector list to receive the matching data types.
340 * @return >= 0 success, neg. error code if failed
341 */
8ede8717 342 int FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList);
f23a6e1a 343
bfccbf68 344 /**
345 * Set the global component handler.
346 * The static method is needed for the automatic registration of components.
347 */
85869391 348 static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0);
bfccbf68 349
350 /**
351 * Clear the global component handler.
352 * The static method is needed for the automatic registration of components.
353 */
85869391 354 static int UnsetGlobalComponentHandler();
bfccbf68 355
9ce4bf4a 356 /**
357 * Helper function to convert the data type to a string.
358 */
359 static string DataType2Text( const AliHLTComponentDataType& type );
360
5f5b708b 361 /**
362 * Helper function to print content of data type.
363 */
364 void PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format=NULL) const;
365
9ce4bf4a 366 /**
367 * helper function to initialize AliHLTComponentEventData structure
368 */
369 static void FillEventData(AliHLTComponentEventData& evtData);
370
371 /**
372 * Print info on an AliHLTComponentDataType structure
373 * This is just a helper function to examine an @ref AliHLTComponentDataType
374 * structur.
375 */
376 void PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt);
377
90ebac25 378 /**
379 * Stopwatch type for benchmarking.
380 */
381 enum AliHLTStopwatchType {
382 /** total time for event processing */
383 kSWBase,
384 /** detector algorithm w/o interface callbacks */
385 kSWDA,
386 /** data sources */
387 kSWInput,
388 /** data sinks */
389 kSWOutput,
390 /** number of types */
391 kSWTypeCount
392 };
393
394 /**
395 * Helper class for starting and stopping a stopwatch.
396 * The guard can be used by instantiating an object in a function. The
397 * specified stopwatch is started and the previous stopwatch put on
398 * hold. When the function is terminated, the object is deleted automatically
399 * deleted, stopping the stopwatch and starting the one on hold.<br>
400 * \em IMPORTANT: never create dynamic objects from this guard as this violates
401 * the idea of a guard.
402 */
403 class AliHLTStopwatchGuard {
404 public:
405 /** standard constructor (not for use) */
406 AliHLTStopwatchGuard();
407 /** constructor */
408 AliHLTStopwatchGuard(TStopwatch* pStart);
409 /** copy constructor (not for use) */
e419b223 410 AliHLTStopwatchGuard(const AliHLTStopwatchGuard&);
411 /** assignment operator (not for use) */
412 AliHLTStopwatchGuard& operator=(const AliHLTStopwatchGuard&);
90ebac25 413 /** destructor */
414 ~AliHLTStopwatchGuard();
415
416 private:
417 /**
418 * Hold the previous guard for the existence of this guard.
419 * Checks whether this guard controls a new stopwatch. In that case, the
420 * previous guard and its stopwatch are put on hold.
421 * @param pSucc instance of the stopwatch of the new guard
422 * @return 1 if pSucc is a different stopwatch which should
423 * be started<br>
424 * 0 if it controls the same stopwatch
425 */
426 int Hold(TStopwatch* pSucc);
427
428 /**
429 * Resume the previous guard.
430 * Checks whether the peceeding guard controls a different stopwatch. In that
431 * case, the its stopwatch is resumed.
432 * @param pSucc instance of the stopwatch of the new guard
433 * @return 1 if pSucc is a different stopwatch which should
434 * be stopped<br>
435 * 0 if it controls the same stopwatch
436 */
437 int Resume(TStopwatch* pSucc);
438
439 /** the stopwatch controlled by this guard */
440 TStopwatch* fpStopwatch; //!transient
441
442 /** previous stopwatch guard, put on hold during existence of the guard */
443 AliHLTStopwatchGuard* fpPrec; //!transient
444
445 /** active stopwatch guard */
446 static AliHLTStopwatchGuard* fgpCurrent; //!transient
447 };
448
449 /**
450 * Set a stopwatch for a given purpose.
451 * @param pSW stopwatch object
452 * @param type type of the stopwatch
453 */
454 int SetStopwatch(TObject* pSW, AliHLTStopwatchType type=kSWBase);
455
456 /**
457 * Init a set of stopwatches.
458 * @param pStopwatches object array of stopwatches
459 */
460 int SetStopwatches(TObjArray* pStopwatches);
a655eae3 461
f23a6e1a 462 protected:
71d7c760 463
bfccbf68 464 /**
8ede8717 465 * Fill AliHLTComponentBlockData structure with default values.
bfccbf68 466 * @param blockData reference to data structure
467 */
70ed7d01 468 void FillBlockData( AliHLTComponentBlockData& blockData ) const;
bfccbf68 469
470 /**
8ede8717 471 * Fill AliHLTComponentShmData structure with default values.
bfccbf68 472 * @param shmData reference to data structure
473 */
70ed7d01 474 void FillShmData( AliHLTComponentShmData& shmData ) const;
bfccbf68 475
476 /**
8ede8717 477 * Fill AliHLTComponentDataType structure with default values.
bfccbf68 478 * @param dataType reference to data structure
479 */
70ed7d01 480 void FillDataType( AliHLTComponentDataType& dataType ) const;
f23a6e1a 481
2d7ff710 482 /**
483 * Copy data type structure
484 * Copies the value an AliHLTComponentDataType structure to another one
485 * @param[out] tgtdt target structure
486 * @param[in] srcdt source structure
487 */
488 void CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt);
489
490 /**
491 * Set the ID and Origin of an AliHLTComponentDataType structure.
492 * The function sets the fStructureSize member and copies the strings
493 * to the ID and Origin. Only characters from the valid part of the string
494 * are copied, the rest is fille with 0's.
495 * Please note that the fID and fOrigin members are not strings, just arrays of
496 * chars of size @ref kAliHLTComponentDataTypefIDsize and
21745ddc 497 * @ref kAliHLTComponentDataTypefOriginSize respectively and not necessarily with
2d7ff710 498 * a terminating zero.
9ce4bf4a 499 * @param tgtdt target data type structure
2d7ff710 500 * @param id ID string
501 * @param origin Origin string
502 */
503 void SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin);
504
bfccbf68 505 /**
506 * Default method for the internal initialization.
507 * The method is called by @ref Init
508 */
53feaef5 509 virtual int DoInit( int argc, const char** argv );
f23a6e1a 510
bfccbf68 511 /**
512 * Default method for the internal clean-up.
513 * The method is called by @ref Deinit
514 */
53feaef5 515 virtual int DoDeinit();
f23a6e1a 516
bfccbf68 517 /**
518 * General memory allocation method.
519 * All memory which is going to be used 'outside' of the interface must
520 * be provided by the framework (online or offline).
521 * The method is redirected to a function provided by the current
522 * framework. Function pointers are transferred via the @ref
523 * AliHLTComponentEnvironment structure.
524 */
85869391 525 void* AllocMemory( unsigned long size );
f23a6e1a 526
bfccbf68 527 /**
528 * Helper function to create a monolithic BlockData description block out
529 * of a list BlockData descriptors.
530 * For convenience, inside the interface vector lists are used, to make the
531 * interface pure C style, monilithic blocks must be exchanged.
532 * The method is redirected to a function provided by the current
533 * framework. Function pointers are transferred via the @ref
534 * AliHLTComponentEnvironment structure.
535 */
8ede8717 536 int MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
537 AliHLTComponentBlockData** outputBlocks );
f23a6e1a 538
bfccbf68 539 /**
540 * Fill the EventDoneData structure.
541 * The method is redirected to a function provided by the current
542 * framework. Function pointers are transferred via the @ref
543 * AliHLTComponentEnvironment structure.
544 */
8ede8717 545 int GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd );
f23a6e1a 546
bfccbf68 547 /**
548 * Helper function to convert the data type to a string.
549 */
70ed7d01 550 void DataType2Text(const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2]) const;
fa2e9b7c 551
3cde846d 552 /**
553 * Get event number.
554 * @return value of the internal event counter
555 */
70ed7d01 556 int GetEventCount() const;
3cde846d 557
a655eae3 558 /**
559 * Get the number of input blocks.
560 * @return number of input blocks
561 */
66043029 562 int GetNumberOfInputBlocks() const;
a655eae3 563
564 /**
565 * Get the first object of a specific data type from the input data.
566 * The hight-level methods provide functionality to transfer ROOT data
567 * structures which inherit from TObject.
568 * The method looks for the first ROOT object of type dt in the input stream.
569 * If also the class name is provided, the object is checked for the right
570 * class type. The input data block needs a certain structure, namely the
571 * buffer size as first word. If the cross check fails, the retrieval is
8451168b 572 * silently abondoned, unless the \em bForce parameter is set.<br>
573 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
a655eae3 574 * @param dt data type of the object
575 * @param classname class name of the object
576 * @param bForce force the retrieval of an object, error messages
577 * are suppressed if \em bForce is not set
578 * @return pointer to @ref TObject, NULL if no objects of specified type
579 * available
580 */
581 const TObject* GetFirstInputObject(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
582 const char* classname=NULL,
583 int bForce=0);
584
585 /**
586 * Get the first object of a specific data type from the input data.
587 * The hight-level methods provide functionality to transfer ROOT data
588 * structures which inherit from TObject.
589 * The method looks for the first ROOT object of type specified by the ID and
590 * Origin strings in the input stream.
591 * If also the class name is provided, the object is checked for the right
592 * class type. The input data block needs a certain structure, namely the
593 * buffer size as first word. If the cross check fails, the retrieval is
8451168b 594 * silently abondoned, unless the \em bForce parameter is set.<br>
595 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
a655eae3 596 * @param dtID data type ID of the object
597 * @param dtOrigin data type origin of the object
598 * @param classname class name of the object
599 * @param bForce force the retrieval of an object, error messages
600 * are suppressed if \em bForce is not set
601 * @return pointer to @ref TObject, NULL if no objects of specified type
602 * available
603 */
604 const TObject* GetFirstInputObject(const char* dtID,
605 const char* dtOrigin,
606 const char* classname=NULL,
607 int bForce=0);
608
609 /**
610 * Get the next object of a specific data type from the input data.
611 * The hight-level methods provide functionality to transfer ROOT data
612 * structures which inherit from TObject.
613 * The method looks for the next ROOT object of type and class specified
8451168b 614 * to the previous @ref GetFirstInputObject call.<br>
615 * \em Note: THE OBJECT MUST NOT BE DELETED by the caller.
a655eae3 616 * @param bForce force the retrieval of an object, error messages
617 * are suppressed if \em bForce is not set
618 * @return pointer to @ref TObject, NULL if no more objects available
619 */
620 const TObject* GetNextInputObject(int bForce=0);
621
622 /**
623 * Get data type of an input block.
624 * Get data type of the object previously fetched via
625 * GetFirstInputObject/NextInputObject or the last one if no object
626 * specified.
627 * @param pObject pointer to TObject
628 * @return data specification, kAliHLTVoidDataSpec if failed
629 */
630 AliHLTComponentDataType GetDataType(const TObject* pObject=NULL);
631
632 /**
633 * Get data specification of an input block.
634 * Get data specification of the object previously fetched via
635 * GetFirstInputObject/NextInputObject or the last one if no object
636 * specified.
637 * @param pObject pointer to TObject
638 * @return data specification, kAliHLTVoidDataSpec if failed
639 */
640 AliHLTUInt32_t GetSpecification(const TObject* pObject=NULL);
641
642 /**
643 * Get the first block of a specific data type from the input data.
644 * The method looks for the first block of type dt in the input stream. It is intended
8451168b 645 * to be used within the high-level interface.<br>
646 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 647 * @param dt data type of the block
648 * @return pointer to @ref AliHLTComponentBlockData
649 */
650 const AliHLTComponentBlockData* GetFirstInputBlock(const AliHLTComponentDataType& dt=kAliHLTAnyDataType);
651
652 /**
653 * Get the first block of a specific data type from the input data.
654 * The method looks for the first block of type specified by the ID and
655 * Origin strings in the input stream. It is intended
8451168b 656 * to be used within the high-level interface.<br>
657 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 658 * @param dtID data type ID of the block
659 * @param dtOrigin data type origin of the block
660 * @return pointer to @ref AliHLTComponentBlockData
661 */
662 const AliHLTComponentBlockData* GetFirstInputBlock(const char* dtID,
663 const char* dtOrigin);
664
665 /**
8451168b 666 * Get input block by index.<br>
667 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 668 * @return pointer to AliHLTComponentBlockData, NULL if index out of range
669 */
670 const AliHLTComponentBlockData* GetInputBlock(int index);
671
672 /**
673 * Get the next block of a specific data type from the input data.
674 * The method looks for the next block of type and class specified
675 * to the previous @ref GetFirstInputBlock call.
8451168b 676 * To be used within the high-level interface.<br>
677 * \em Note: THE BLOCK DESCRIPTOR MUST NOT BE DELETED by the caller.
a655eae3 678 */
679 const AliHLTComponentBlockData* GetNextInputBlock();
680
681 /**
682 * Get data specification of an input block.
683 * Get data specification of the input bblock previously fetched via
684 * GetFirstInputObject/NextInputObject or the last one if no block
685 * specified.
686 * @param pBlock pointer to input block
687 * @return data specification, kAliHLTVoidDataSpec if failed
688 */
689 AliHLTUInt32_t GetSpecification(const AliHLTComponentBlockData* pBlock=NULL);
690
691 /**
692 * Insert an object into the output.
79c114b5 693 * If header is specified, it will be inserted before the root object,
694 * default is no header.
a655eae3 695 * @param pObject pointer to root object
696 * @param dt data type of the object
697 * @param spec data specification
79c114b5 698 * @param pHeader pointer to header
699 * @param headerSize size of Header
a655eae3 700 * @return neg. error code if failed
701 */
702 int PushBack(TObject* pObject, const AliHLTComponentDataType& dt,
79c114b5 703 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
704 void* pHeader=NULL, int headerSize=0);
a655eae3 705
706 /**
707 * Insert an object into the output.
79c114b5 708 * If header is specified, it will be inserted before the root object,
709 * default is no header.
a655eae3 710 * @param pObject pointer to root object
711 * @param dtID data type ID of the object
712 * @param dtOrigin data type origin of the object
713 * @param spec data specification
79c114b5 714 * @param pHeader pointer to header
715 * @param headerSize size of Header
a655eae3 716 * @return neg. error code if failed
717 */
718 int PushBack(TObject* pObject, const char* dtID, const char* dtOrigin,
79c114b5 719 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
720 void* pHeader=NULL, int headerSize=0);
721
a655eae3 722 /**
723 * Insert an object into the output.
724 * @param pBuffer pointer to buffer
725 * @param iSize size of the buffer
726 * @param dt data type of the object
727 * @param spec data specification
728 * @return neg. error code if failed
729 */
730 int PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt,
731 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
732
733 /**
734 * Insert an object into the output.
735 * @param pBuffer pointer to buffer
736 * @param iSize size of the buffer
737 * @param dtID data type ID of the object
738 * @param dtOrigin data type origin of the object
739 * @param spec data specification
740 * @return neg. error code if failed
741 */
742 int PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin,
743 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
744
8451168b 745 /**
746 * Estimate size of a TObject
747 * @param pObject
748 * @return buffer size in byte
749 */
750 int EstimateObjectSize(TObject* pObject) const;
751
79c114b5 752 /**
753 * Create a memory file in the output stream.
754 * This method creates a TFile object which stores all data in
755 * memory instead of disk. The TFile object is published as binary data.
756 * The instance can be used like a normal TFile object. The TFile::Close
757 * or @ref CloseMemoryFile method has to be called in order to flush the
758 * output stream.
759 *
760 * \b Note: The returned object is deleted by the framework.
761 * @param capacity total size reserved for the memory file
762 * @param dtID data type ID of the file
763 * @param dtOrigin data type origin of the file
764 * @param spec data specification
765 * @return file handle, NULL if failed
766 */
767 AliHLTMemoryFile* CreateMemoryFile(int capacity, const char* dtID, const char* dtOrigin,
768 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
769
770 /**
771 * Create a memory file in the output stream.
772 * This method creates a TFile object which stores all data in
773 * memory instead of disk. The TFile object is published as binary data.
774 * The instance can be used like a normal TFile object. The TFile::Close
775 * or @ref CloseMemoryFile method has to be called in order to flush the
776 * output stream.
777 *
778 * \b Note: The returned object is deleted by the framework.
779 * @param capacity total size reserved for the memory file
780 * @param dt data type of the file
781 * @param spec data specification
782 * @return file handle, NULL if failed
783 */
784 AliHLTMemoryFile* CreateMemoryFile(int capacity,
785 const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
786 AliHLTUInt32_t spec=kAliHLTVoidDataSpec);
787
788 /**
789 * Create a memory file in the output stream.
790 * This method creates a TFile object which stores all data in
791 * memory instead of disk. The TFile object is published as binary data.
792 * The instance can be used like a normal TFile object. The TFile::Close
793 * or @ref CloseMemoryFile method has to be called in order to flush the
794 * output stream.
795 *
796 * \b Note: The returned object is deleted by the framework.
797 * @param dtID data type ID of the file
798 * @param dtOrigin data type origin of the file
799 * @param spec data specification
800 * @param capacity fraction of the available output buffer size
801 * @return file handle, NULL if failed
802 */
803 AliHLTMemoryFile* CreateMemoryFile(const char* dtID, const char* dtOrigin,
804 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
805 float capacity=1.0);
806
807 /**
808 * Create a memory file in the output stream.
809 * This method creates a TFile object which stores all data in
810 * memory instead of disk. The TFile object is published as binary data.
811 * The instance can be used like a normal TFile object. The TFile::Close
812 * or @ref CloseMemoryFile method has to be called in order to flush the
813 * output stream.
814 *
815 * \b Note: The returned object is deleted by the framework.
816 * @param dt data type of the file
817 * @param spec data specification
818 * @param capacity fraction of the available output buffer size
819 * @return file handle, NULL if failed
820 */
821 AliHLTMemoryFile* CreateMemoryFile(const AliHLTComponentDataType& dt=kAliHLTAnyDataType,
822 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
823 float capacity=1.0);
824
825 /**
826 * Write an object to memory file in the output stream.
827 * @param pFile file handle
828 * @param pObject pointer to root object
829 * @param key key in ROOT file
830 * @param option options, see TObject::Write
831 * @return neg. error code if failed
832 * - -ENOSPC no space left
833 */
834 int Write(AliHLTMemoryFile* pFile, const TObject* pObject, const char* key=NULL, int option=TObject::kOverwrite);
835
836 /**
837 * Close object memory file.
838 * @param pFile file handle
839 * @return neg. error code if failed
840 * - -ENOSPC buffer size too small
841 */
842 int CloseMemoryFile(AliHLTMemoryFile* pFile);
843
a655eae3 844 /**
845 * Insert event-done data information into the output.
846 * @param edd event-done data information
847 */
848 int CreateEventDoneData(AliHLTComponentEventDoneData edd);
849
559631d5 850 /**
851 * Get current run number
852 */
853 AliHLTUInt32_t GetRunNo() const;
854
855 /**
856 * Get the current run type.
857 */
858 AliHLTUInt32_t GetRunType() const;
859
860 /**
861 * Copy a struct from block data.
862 * The function checks for block size and struct size. The least common
863 * size will be copied to the target struct, remaining fields are initialized
864 * to zero.<br>
865 * The target struct must have a 32bit struct size indicator as first member.
866 * @param pStruct target struct
867 * @param iStructSize size of the struct
868 * @param pData block data
869 * @param iBlockNo index of input block
870 * @param structname name of the struct (log messages)
871 * @param eventname name of the event (log messages)
872 * @return size copied, neg. error if failed
873 */
874 int CopyStruct(void* pStruct, int iStructSize, int iBlockNo,
875 const char* structname="", const char* eventname="");
876
f23a6e1a 877 private:
559631d5 878 /** not a valid copy constructor, defined according to effective C++ style */
879 AliHLTComponent(const AliHLTComponent&);
880 /** not a valid assignment op, but defined according to effective C++ style */
881 AliHLTComponent& operator=(const AliHLTComponent&);
882
3cde846d 883 /**
884 * Increment the internal event counter.
885 * To be used by the friend classes AliHLTProcessor, AliHLTDataSource
886 * and AliHLTDataSink.
887 * @return new value of the internal event counter
a655eae3 888 * @internal
3cde846d 889 */
890 int IncrementEventCounter();
891
a655eae3 892 /**
893 * Find the first input block of specified data type beginning at index.
1edbbe49 894 * Input blocks containing a TObject have the size of the object as an
895 * unsigned 32 bit number in the first 4 bytes. This has to match the block
896 * size minus 4.
a655eae3 897 * @param dt data type
898 * @param startIdx index to start the search
1edbbe49 899 * @param bObject check if this is an object
a655eae3 900 * @return index of the block, -ENOENT if no block found
901 *
902 * @internal
903 */
1edbbe49 904 int FindInputBlock(const AliHLTComponentDataType& dt, int startIdx=-1, int bObject=0) const;
a655eae3 905
906 /**
907 * Get index in the array of input bocks.
908 * Calculate index and check integrety of a block data structure pointer.
909 * @param pBlock pointer to block data
910 * @return index of the block, -ENOENT if no block found
911 *
912 * @internal
913 */
66043029 914 int FindInputBlock(const AliHLTComponentBlockData* pBlock) const;
a655eae3 915
916 /**
917 * Create an object from a specified input block.
918 * @param idx index of the input block
919 * @param bForce force the retrieval of an object, error messages
920 * are suppressed if \em bForce is not set
921 * @return pointer to TObject, caller must delete the object after use
922 *
923 * @internal
924 */
925 TObject* CreateInputObject(int idx, int bForce=0);
926
927 /**
928 * Get input object
8451168b 929 * Get object from the input block list. The methods first checks whether the
930 * object was already created. If not, it is created by @ref CreateInputObject
931 * and inserted into the list of objects.
a655eae3 932 * @param idx index in the input block list
933 * @param classname name of the class, object is checked for correct class
934 * name if set
935 * @param bForce force the retrieval of an object, error messages
936 * are suppressed if \em bForce is not set
937 * @return pointer to TObject
938 *
939 * @internal
940 */
941 TObject* GetInputObject(int idx, const char* classname=NULL, int bForce=0);
942
8451168b 943 /**
944 * Clean the list of input objects.
945 * Cleanup is done at the end of each event processing.
946 */
947 int CleanupInputObjects();
948
a655eae3 949 /**
950 * Insert a buffer into the output block stream.
951 * This is the only method to insert blocks into the output stream, called
952 * from all types of the Pushback method. The actual data might have been
953 * written to the output buffer already. In that case NULL can be provided
79c114b5 954 * as buffer, only the block descriptor will be build. If a header is specified,
955 * it will be inserted before the buffer, default is no header.
a655eae3 956 * @param pBuffer pointer to buffer
32db4144 957 * @param iBufferSize size of the buffer in byte
a655eae3 958 * @param dt data type
959 * @param spec data specification
79c114b5 960 * @param pHeader pointer to header
961 * @param iHeaderSize size of Header
a655eae3 962 */
79c114b5 963 int InsertOutputBlock(void* pBuffer, int iBufferSize,
a655eae3 964 const AliHLTComponentDataType& dt,
79c114b5 965 AliHLTUInt32_t spec,
966 void* pHeader=NULL, int iHeaderSize=0);
a655eae3 967
bfccbf68 968 /** The global component handler instance */
a655eae3 969 static AliHLTComponentHandler* fgpComponentHandler; //! transient
70ed7d01 970
bfccbf68 971 /** The environment where the component is running in */
a655eae3 972 AliHLTComponentEnvironment fEnvironment; // see above
f23a6e1a 973
a655eae3 974 /** Set by ProcessEvent before the processing starts */
975 AliHLTEventID_t fCurrentEvent; // see above
f23a6e1a 976
3cde846d 977 /** internal event no */
a655eae3 978 int fEventCount; // see above
979
980 /** the number of failed events */
981 int fFailedEvents; // see above
982
983 /** event data struct of the current event under processing */
984 AliHLTComponentEventData fCurrentEventData; // see above
985
986 /** array of input data blocks of the current event */
987 const AliHLTComponentBlockData* fpInputBlocks; //! transient
988
989 /** index of the current input block */
990 int fCurrentInputBlock; // see above
991
992 /** data type of the last block search */
993 AliHLTComponentDataType fSearchDataType; // see above
994
995 /** name of the class for the object to search for */
996 string fClassName; // see above
997
998 /** array of generated input objects */
999 TObjArray* fpInputObjects; //! transient
1000
1001 /** the output buffer */
1002 AliHLTUInt8_t* fpOutputBuffer; //! transient
1003
1004 /** size of the output buffer */
1005 AliHLTUInt32_t fOutputBufferSize; // see above
1006
1007 /** size of data written to output buffer */
1008 AliHLTUInt32_t fOutputBufferFilled; // see above
1009
1010 /** list of ouput block data descriptors */
1011 vector<AliHLTComponentBlockData> fOutputBlocks; // see above
3cde846d 1012
90ebac25 1013 /** stopwatch array */
1014 TObjArray* fpStopwatches; //! transient
1015
79c114b5 1016 /** array of memory files AliHLTMemoryFile */
1017 vector<AliHLTMemoryFile*> fMemFiles; //! transient
1018
559631d5 1019 /** descriptor of the current run */
1020 AliHLTRunDesc* fpRunDesc; //! transient
1021
1022 /** the current DDL list */
1023 AliHLTEventDDL* fpDDLList; //! transient
1024
79c114b5 1025 ClassDef(AliHLTComponent, 3)
f23a6e1a 1026};
1027#endif