]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTOUT.h
- cleaning up debug output
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUT.h
1 //-*- Mode: C++ -*-
2 // @(#) $Id$
3
4 #ifndef ALIHLTOUT_H
5 #define ALIHLTOUT_H
6 //* This file is property of and copyright by the ALICE HLT Project        * 
7 //* ALICE Experiment at CERN, All rights reserved.                         *
8 //* See cxx source for full Copyright notice                               *
9
10 /** @file   AliHLTOUT.h
11     @author Matthias Richter
12     @date   
13     @brief  The control class for HLTOUT data.
14 */
15
16 #include <vector>
17 #include "AliHLTLogging.h"
18 #include "AliHLTModuleAgent.h"
19
20 class AliHLTOUTHandler;
21 class AliHLTOUTHandlerDesc; // AliHLTModuleAgent.h
22 class AliESDEvent;
23 class AliHLTReconstructor;
24 class AliRawReader;
25 class TTree;
26
27 #define AliHLTOUTInvalidIndex (~(AliHLTUInt32_t)0)
28
29 typedef vector<AliHLTUInt32_t> AliHLTOUTIndexList;
30
31 /**
32  * @class AliHLTOUT
33  * The control class for HLTOUT data.
34  * The output of the HLT, either from the HLTOUT nodes or simulated output,
35  * is transferred and stored in the HOMER format. The AliHLTOUT class 
36  * implements scanning of the HOMER data for all HLTOUT DDL links and
37  * abstracts access to the complete HLTOUT data.
38  * 
39  */
40 class AliHLTOUT {
41  public:
42   /** standard constructor */
43   AliHLTOUT();
44   /** standard destructor */
45   virtual ~AliHLTOUT();
46
47   /**
48    * Create an AliHLTOUTRawReader instance.
49    * Helper function to transparently access classes from the
50    * libHLTrec library.
51    */
52   static AliHLTOUT* New(AliRawReader* pRawReader);
53
54   /**
55    * Create an AliHLTOUTDigitReader instance
56    * Helper function to transparently access classes from the
57    * libHLTrec library.
58    */
59   static AliHLTOUT* New(TTree* pDigitTree, int event=-1);
60
61   /**
62    * Get the global instance.
63    * The global instance is set temporarily by the AliHLTOUTGlobalInstanceGuard
64    * mainly for the sake of data input to an analysis chain. The
65    * AliHLTOUTPublisherComponent objects can access the global instance.
66    */
67   static AliHLTOUT* GetGlobalInstance() {return fgGlobalInstance;}
68
69   /**
70    * Delete an instance of the HLTOUT.
71    * Helper function to transparently access classes from the
72    * libHLTrec library. Before deleting, the availability of the
73    * library is checked.
74    */
75   static void Delete(AliHLTOUT* pInstance);
76
77   /**
78    * Locking guard for the AliHLTOUT object.
79    * If the object is locked, the selection of data blocks can not be changed.
80    */
81   class AliHLTOUTLockGuard {
82   public:
83     /** constructor */
84     AliHLTOUTLockGuard(AliHLTOUT* pInstance) : fpInstance(pInstance)
85     {if (fpInstance) fpInstance->SetStatusFlag(kLocked);}
86     /** destructor */
87     ~AliHLTOUTLockGuard()
88     {if (fpInstance) fpInstance->ClearStatusFlag(kLocked);}
89
90   private:
91     /** standard constructor prohibited */
92     AliHLTOUTLockGuard();
93     /** copy constructor prohibited */
94     AliHLTOUTLockGuard(const AliHLTOUTLockGuard&);
95     /** assignment operator prohibited */
96     AliHLTOUTLockGuard& operator=(const AliHLTOUTLockGuard&);
97
98     /** the AliHLTOUT instance the guard is locking */
99     AliHLTOUT* fpInstance; //!transient
100   };
101
102   /**
103    * Guard for handling of global AliHLTOUT instance.
104    * The global HLTOUT instance can be set for certain steps of the
105    * processing. The initial objective is to support input to the
106    * AliHLTOUTPublisherComponent running in a kChain handler.
107    *
108    * The Guard restores the original instance when closed.
109    */
110   class AliHLTOUTGlobalInstanceGuard {
111   public:
112     /** constructor */
113     AliHLTOUTGlobalInstanceGuard(AliHLTOUT* pInstance) : fpLastInstance(AliHLTOUT::fgGlobalInstance)
114     {AliHLTOUT::fgGlobalInstance=pInstance;}
115     /** destructor */
116     ~AliHLTOUTGlobalInstanceGuard()
117     {AliHLTOUT::fgGlobalInstance=fpLastInstance;}
118
119   private:
120     /** standard constructor prohibited */
121     AliHLTOUTGlobalInstanceGuard();
122     /** copy constructor prohibited */
123     AliHLTOUTGlobalInstanceGuard(const AliHLTOUTGlobalInstanceGuard&);
124     /** assignment operator prohibited */
125     AliHLTOUTGlobalInstanceGuard& operator=(const AliHLTOUTGlobalInstanceGuard&);
126
127     /** the AliHLTOUT instance the guard is locking */
128     AliHLTOUT* fpLastInstance; //!transient
129   };
130
131   /**
132    * The HLT OUT Event Header.
133    * Defined between HLT and DAQ.
134    */
135   struct AliHLTOUTEventHeader {
136     /**Total length of the data in bytes, including HLT event header, excluding CDH. */
137     AliHLTUInt32_t fLength; //! see above
138     /** version of the header */
139     AliHLTUInt32_t fVersion; //! see above
140     /** High 32 bit word of event id */
141     AliHLTUInt32_t fEventIDHigh; //! see above
142     /** Low 32 bit word of event id */
143     AliHLTUInt32_t fEventIDLow; //! see above
144   };
145
146   enum {
147     /// versions 1 of the HLT header
148     kVersion1 = 1,
149     /// versions 2 of the HLT header
150     kVersion2 = 2
151   };
152
153   enum {
154     /// size of HLT decision in data format version 1: 29x4
155     kSizeDecisionVersion1 = 116,
156     /// size of HLT decision in data format version 2: 30x4
157     kSizeDecisionVersion2 = 120
158   };
159
160   // definitions from ALICE internal notes ALICE-INT-2002-010 and
161   // ALICE-INT-2006-XXX
162   enum {
163     /** the 32bit word in the CDH containing the status flags */
164     kCDHStatusWord=4, //! see above
165     /** start of the flags in word fgkCDHStatusWord */
166     kCDHStatusFlagsOffset=12, //! see above
167     /** bit indicating HLT decision in the HLTOUT*/
168     kCDHFlagsHLTDecision=6, //! see above
169     /** bit indicating HLT payload in the HLTOUT*/
170     kCDHFlagsHLTPayload=7 //! see above
171   };
172
173   class AliHLTOUTHandlerListEntry;
174   /**
175    * Block descriptor.
176    */
177   class AliHLTOUTBlockDescriptor {
178   public:
179     AliHLTOUTBlockDescriptor(AliHLTComponentDataType dt, AliHLTUInt32_t spec, AliHLTUInt32_t index, AliHLTOUT* pCollection)
180       : fDataType(dt), fSpecification(spec), fIndex(index), fSelected(false), fProcessed(false), fpCollection(pCollection) {};
181     AliHLTOUTBlockDescriptor(const AliHLTOUTBlockDescriptor& src)
182       : fDataType(src.fDataType), fSpecification(src.fSpecification), fIndex(src.fIndex), fSelected(false), fProcessed(false), fpCollection(src.fpCollection) {}
183     AliHLTOUTBlockDescriptor& operator=(const AliHLTOUTBlockDescriptor& src)
184     { fDataType=src.fDataType; fSpecification=src.fSpecification; fIndex=src.fIndex; fSelected=false; fProcessed=false; fpCollection=src.fpCollection; return *this; }
185     ~AliHLTOUTBlockDescriptor() {}
186
187     operator AliHLTComponentDataType() const {return fDataType;}
188     operator AliHLTUInt32_t() const {return fSpecification;}
189     int operator==(AliHLTComponentDataType dt) const {return dt==fDataType;}
190     int operator==(AliHLTUInt32_t spec) const {return spec==fSpecification;}
191     int operator==(AliHLTOUT* collection) const {return collection==fpCollection;}
192
193     AliHLTUInt32_t GetIndex() const {return fIndex;}
194     AliHLTOUT* GetCollection() const {return fpCollection;}
195
196     bool IsSelected() const {return fSelected;}
197     void Select(bool selected=true) {fSelected=selected;}
198     bool IsProcessed() const {return fProcessed;}
199     void MarkProcessed() {fProcessed=true;}
200
201     /**
202      * Get the data buffer
203      * @param pBuffer [out] buffer of the selected data block
204      * @param size    [out] size of the selected data block
205      */
206     int GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size) {
207       if (fpCollection) return fpCollection->GetDataBuffer(GetIndex(), pBuffer, size);
208       return -ENODEV;
209     }
210
211     /**
212      * Get the handler descriptor
213      */
214     const AliHLTOUTHandlerListEntry& GetHandlerDesc();
215
216   private:      
217     /** data type of the block */
218     AliHLTComponentDataType fDataType; //!transient
219     /** data specification of the block */
220     AliHLTUInt32_t          fSpecification; //!transient
221     /** index in the data stream */
222     AliHLTUInt32_t          fIndex; //!transient
223     /** selection flag */
224     bool                    fSelected; //!transient
225     /** processed flag */
226     bool                    fProcessed; //!transient
227     /** the collection */
228     AliHLTOUT*              fpCollection; //!transient
229   };
230
231   class AliHLTOUTHandlerListEntry {
232   public:
233     AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler, 
234                               AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
235                               AliHLTModuleAgent* pAgent,
236                               AliHLTUInt32_t index);
237
238     /** copy constructor for vector handling */
239     AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src);
240
241     /** assignment operator for vector handling */
242     AliHLTOUTHandlerListEntry& operator=(const AliHLTOUTHandlerListEntry& src);
243
244     ~AliHLTOUTHandlerListEntry();
245
246     static const AliHLTOUTHandlerListEntry fgkVoidHandlerListEntry; //! initializer
247
248     operator AliHLTOUTHandler*() const {return fpHandler;}
249
250     // please note that fpHandlerDesc is really a pointer and is created
251     // in the constructor. Thats why it is dereferenced here. The pointer
252     // type is on purpose, even though it is a bit confusing with the 
253     // argument by reference in the AliHLTOUTHandlerListEntry constructor.
254     operator const AliHLTModuleAgent::AliHLTOUTHandlerDesc&() const 
255     {return fpHandlerDesc?*fpHandlerDesc:AliHLTModuleAgent::fgkVoidHandlerDesc;}
256     operator AliHLTModuleAgent*() const {return fpAgent;}
257
258     /**
259      * Two list entries are considered to be equal if the handlers
260      * are equal.
261      */
262     bool operator==(const AliHLTOUTHandlerListEntry& entry) const;
263
264     bool operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const;
265
266     /**
267      * Compare the handler descriptor of this list entry with another
268      * descriptor.
269      * @return true if both handler and agent match
270      */
271     bool operator==(const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc) const; 
272
273     AliHLTUInt32_t operator[](int i) const;
274
275     /**
276      * Add a block index to this descriptor.
277      * One descriptor can serve multiple blocks if the agent returns the
278      * same handler for all of the blocks. Instead of creating a new entry
279      * the block index ist just added
280      */
281     void AddIndex(AliHLTUInt32_t index);
282
283     /**
284      * Add all indices of the descriptor.
285      */
286     void AddIndex(AliHLTOUTHandlerListEntry &desc);
287
288     /**
289      * Check if an index is served by this descriptor.
290      * @return true if the index is in the table
291      */
292     bool HasIndex(AliHLTUInt32_t index) const;
293
294     /**
295      * Invalidate all block indices
296      */
297     void InvalidateBlocks() {fBlocks.clear();}
298
299     /**
300      * Check whether the entry has valid blocks.
301      */
302     bool IsEmpty() {return fBlocks.size()==0;}
303
304   private:
305     /** standard constructor prohibited */
306     AliHLTOUTHandlerListEntry();
307
308     /** pointer to the handler */
309     AliHLTOUTHandler* fpHandler; //! transient
310
311     /** pointer to handler description */
312     AliHLTModuleAgent::AliHLTOUTHandlerDesc* fpHandlerDesc; //! transient
313
314     /** pointer to module agent */
315     AliHLTModuleAgent* fpAgent; //! transient
316
317     /** list of block indices */
318     AliHLTOUTIndexList fBlocks; //!transient
319   };
320
321   typedef vector<AliHLTOUTHandlerListEntry> AliHLTOUTHandlerListEntryVector;
322   typedef vector<AliHLTOUTBlockDescriptor>  AliHLTOUTBlockDescriptorVector;
323   typedef vector<AliHLTOUT*>                AliHLTOUTPVector;
324
325   /**
326    * Selection guard for the AliHLTOUT object.
327    * If the object is locked, the selection of data blocks can not be changed.
328    */
329   class AliHLTOUTSelectionGuard {
330   public:
331     /** constructor */
332     AliHLTOUTSelectionGuard(AliHLTOUT* pInstance) : fpInstance(pInstance)
333     {if (fpInstance) fpInstance->SelectDataBlock();}
334     /** constructor */
335     AliHLTOUTSelectionGuard(AliHLTOUT* pInstance, const AliHLTOUTHandlerListEntry* pHandlerDesc) : fpInstance(pInstance)
336     {if (fpInstance) fpInstance->SelectDataBlocks(pHandlerDesc);}
337     /** destructor */
338     ~AliHLTOUTSelectionGuard()
339     {if (fpInstance) fpInstance->DisableBlockSelection();}
340
341   private:
342     /** standard constructor prohibited */
343     AliHLTOUTSelectionGuard();
344     /** copy constructor prohibited */
345     AliHLTOUTSelectionGuard(const AliHLTOUTSelectionGuard&);
346     /** assignment operator prohibited */
347     AliHLTOUTSelectionGuard& operator=(const AliHLTOUTSelectionGuard&);
348
349     /** the AliHLTOUT instance the guard is locking */
350     AliHLTOUT* fpInstance; //!transient
351   };
352
353   /**
354    * Init for processing.
355    * The HLTOUT is scanned for all available data blocks and the
356    * AliHLTOUTHandler objects for the data blocks are created according
357    * to the module agents (see AliHLTModuleAgent).
358    */
359   int Init();
360
361   /**
362    * Reset and clear all data block descriptors.
363    * @note Since sub-collections are only referred via the block
364    * descriptors, all information on sub-collections is also lost.
365    * Child classes should implement ResetInput in order to cleanup
366    * the input devices.
367    */
368   int Reset();
369
370   /**
371    * Get the current event id
372    */
373   AliHLTUInt64_t EventId() {return fCurrentEventId;}
374
375   /**
376    * Get number of data blocks in the HLTOUT data
377    */
378   int GetNofDataBlocks();
379
380   /**
381    * Select the first data block of a certain data type and specification.
382    * The selection criteria can be of kAliHLTAnyDataType and/or
383    * kAliHLTVoidDataSpec in order to be ignored and just match any data block.
384    *
385    * The search criteria can be combined with a handler type (e.g. kRawReader)
386    * @param dt    [in]  data type to match                                <br>
387    * @param spec  [in]  data specification to match                       <br>
388    * @param handlerType [in]  type of the handler
389    * @param skipProcessed [in] skip all block marked processed
390    * @return block index: >= 0 if success, -ENOENT if no block found      <br>
391    *         neg. error code if failed                                    <br>
392    *                        -EPERM if access denied (object locked)
393    */
394   int SelectFirstDataBlock(AliHLTComponentDataType dt=kAliHLTAnyDataType,
395                            AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
396                            AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=AliHLTModuleAgent::kUnknownOutput,
397                            bool skipProcessed=true);
398
399   /**
400    * Select the next data block of data type and specification of the previous
401    * call to @ref SelectFirstDataBlock.
402    * @return block index: >= 0 if success, -ENOENT if no block found      <br>
403    *         neg. error code if failed                                    <br>
404    *                        -EPERM if access denied (object locked)
405    */
406   int SelectNextDataBlock();
407
408   /**
409    * Get properties of the selected data block.
410    * @param dt    [out] data type of the selected block
411    * @param spec  [out] data specification of the selected block
412    */
413   int GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec);
414
415   /**
416    * Get handler description of the current data block.
417    */
418   const AliHLTOUTHandlerListEntry& GetDataBlockHandlerDesc();
419
420   /**
421    * Get handler type of the selected data block.
422    * @return handler type for the selected data block
423    */
424   AliHLTModuleAgent::AliHLTOUTHandlerType GetDataBlockHandlerType();
425
426   /**
427    * Get the index of the current data block.
428    * @return index, AliHLTOUTInvalidIndex if no block selected
429    */
430   AliHLTUInt32_t GetDataBlockIndex();
431
432   /**
433    * Get buffer of the selected data block.
434    * @param pBuffer [out] buffer of the selected data block
435    * @param size    [out] size of the selected data block
436    */
437   int GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size);
438
439   /**
440    * Release buffer after use.
441    * @param pBuffer [in]  buffer of the selected data block
442    */
443   int ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer);
444
445   /**
446    * Get a TObject from the data buffer
447    * @return TObject pointer if data block is a streamed object
448    */
449   TObject* GetDataObject();
450
451   /**
452    * Release data object
453    */
454   int ReleaseDataObject(TObject* pObject);
455
456   /**
457    * Add the current data block to the selection.
458    * Note: enables also the block selection
459    */
460   int SelectDataBlock();
461
462   /**
463    * Add the all data blocks of a certain handler to the selection.
464    * Note: enables also the block selection
465    */
466   int SelectDataBlocks(const AliHLTOUTHandlerListEntry* pHandlerDesc);
467
468   /**
469    * Enable the selection of data blocks.
470    */
471   int EnableBlockSelection();
472
473   /**
474    * Disable the selection of data blocks.
475    */
476   int DisableBlockSelection();
477
478   /**
479    * Reset the data block selection.
480    * Resets the selection list, none of the blocks is selected.
481    */
482   int ResetBlockSelection();
483
484   /**
485    * Mark the current block as processed.
486    */
487   int MarkDataBlockProcessed();
488
489   /**
490    * Mark all data blocks of a certain handler processed.
491    */
492   int MarkDataBlocksProcessed(const AliHLTOUTHandlerListEntry* pHandlerDesc);
493
494   /**
495    * Add a sub collection to the HLTOUT.
496    */
497   int AddSubCollection(AliHLTOUT* pCollection);
498
499   /**
500    * Release a previously added sub collection.
501    */
502   int ReleaseSubCollection(AliHLTOUT* pCollection);
503
504   /**
505    * Get module agent for the selected data block.
506    */
507   AliHLTModuleAgent* GetAgent();
508
509   /**
510    * Get handler for the selected data block.
511    */
512   AliHLTOUTHandler* GetHandler();
513
514   /**
515    * Convert data buffer to ESD.
516    * The buffer is supposed to describe a streamed AliESDEvent object.
517    * If no target object is specified, the ESD is written to a file AliHLTdetESDs.root,
518    * where 'det' is derived from the data type origin. Each time the function is invoked
519    * a new event is created. Dummy events are added if the previous events did not contain
520    *
521    * The function needs AliRoot and might not be implemented by all AliHLTOUT
522    * implementations.
523    * a data block of this specification.
524    * @param pBuffer  [in] the data buffer
525    * @param size     [in] data buffer size
526    * @param dt       [in] data type of the block
527    * @param tgtesd   [out] optional target
528    */
529   virtual int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt, AliESDEvent* tgtesd=NULL) const;
530
531   enum AliHLTOUTByteOrder {
532     /** no data block selected */
533     kInvalidByteOrder=-1,
534     kUnknownByteOrder=0,
535     kLittleEndian,
536     kBigEndian
537   };
538
539   enum AliHLTOUTDataType {
540     kUint64 = 0,
541     kUint32 = 1,
542     kUint16 = 2,
543     kUint8  = 3,
544     kDouble = 4,
545     kFloat  = 5
546   };
547
548   /**
549    * Check byte order of selected block
550    */
551   AliHLTOUTByteOrder CheckByteOrder();
552
553   /**
554    * Check alignment of selected block
555    */
556   int CheckAlignment(AliHLTOUT::AliHLTOUTDataType type);
557
558   /**
559    * Helper function to byte swap a 64 bit value.
560    */
561   static AliHLTUInt64_t ByteSwap64(AliHLTUInt64_t src);
562
563   /**
564    * Helper function to byte swap a 32 bit value.
565    */
566   static AliHLTUInt32_t ByteSwap32(AliHLTUInt32_t src);
567
568   /**
569    * Insert a handler item.
570    * The current list entries are checked if the handler is already in
571    * the list. It is added if not in the list, otherwise the block index
572    * is added to the existing entry.
573    * @param list     the handler list
574    * @param entry    handler list entry
575    * @return 0 if added, EEXIST (non negative!) if merged with existing entry <br>
576    *         neg. error code if failed
577    */
578   static int InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry);
579   
580   /**
581    * Insert all handlers of the specified type to the list.
582    */
583   int FillHandlerList(AliHLTOUTHandlerListEntryVector& list, AliHLTModuleAgent::AliHLTOUTHandlerType handlerType);
584
585   /**
586    * Remove empty items which have a duplicate in the list.
587    */
588   static int RemoveEmptyDuplicateHandlers(AliHLTOUTHandlerListEntryVector& list);
589
590   /**
591    * Find an entry of a certain description in the list.
592    * @return index of the entry if found, -ENOENT if not found
593    */
594   static int FindHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc);
595
596   /**
597    * Invalidate all blocks of the handlers in the list
598    */
599   static int InvalidateBlocks(AliHLTOUTHandlerListEntryVector& list);
600
601  protected:
602   /**
603    * Add a block descriptor.
604    * This is done by the child classes generating the index. The AliHLTOUT
605    * object must be locked for index generation.
606    * @param desc    the block descriptor
607    * @return 0 if success, -EPERM if access denied
608    */
609   int AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc);
610
611   /**
612    * Set the event id, only for child classes
613    */
614   void SetEventId(AliHLTUInt64_t id);
615
616   /**
617    * Print output or suppress.
618    */
619   bool BeVerbose() {return fbVerbose;}
620
621   /**
622    * Switch output.
623    */
624   void SwitchVerbosity(bool verbose) {fbVerbose=verbose;}
625
626  private:
627   /** copy constructor prohibited */
628   AliHLTOUT(const AliHLTOUT&);
629   /** assignment operator prohibited */
630   AliHLTOUT& operator=(const AliHLTOUT&);
631
632   /**
633    * Internal status flags
634    */
635   enum {
636     /** the HLTOUT object is locked with the current data block selection */
637     kLocked = 0x1,
638     /** childs can add block descriptors */
639     kCollecting = 0x2,
640     /** user of the data block has checked the byte order */
641     kByteOrderChecked = 0x4,
642     /** warning on byte order missmatch has been printed */
643     kByteOrderWarning = 0x8,
644     /** user of the data block has checked the alignment */
645     kAlignmentChecked = 0x10,
646     /** warning on alignment missmatch has been printed */
647     kAlignmentWarning = 0x20,
648     /** enable block selection list */
649     kBlockSelection = 0x40,
650     /** skip processed data blocks */
651     kSkipProcessed = 0x80,
652     /** marked as sub collection */
653     kIsSubCollection = 0x100
654   };
655
656   /**
657    * Generate the index of the HLTOUT data.
658    * Must be implemented by the child classes.
659    */
660   virtual int GenerateIndex()=0;
661
662   /**
663    * Find AliHLTOUTHandler objects for the data blocks.
664    * The available AliHLTModuleAgents are probed whether they provide
665    * handlers for data processing.
666    */
667   int InitHandlers();
668
669   /**
670    * Cleanup and reset the data input.
671    */
672   virtual int ResetInput();
673
674   /**
675    * Get the data buffer
676    * @param index   [in]  index of the block
677    * @param pBuffer [out] buffer of the selected data block
678    * @param size    [out] size of the selected data block
679    */
680   virtual int GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer, 
681                             AliHLTUInt32_t& size)=0;
682
683   /**
684    * Check byte order of data block
685    */
686   virtual AliHLTOUTByteOrder CheckBlockByteOrder(AliHLTUInt32_t index)=0;
687
688   /**
689    * Check alignment of data block
690    */
691   virtual int CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType type)=0;
692
693   /**
694    * Select the data block of data type and specification of the previous
695    * call to @ref SelectFirstDataBlock. Core function of @ref SelectFirstDataBlock
696    * and @ref SelectNextDataBlock, starts to find a block at the current list
697    * position.
698    * 
699    * The data block is searched from the conditions of fSearchDataType,
700    * fSearchSpecification, fSearchHandlerType and the selection list.
701    *
702    * @return identifier >=0 if success, neg. error code if failed         <br>
703    *                        -ENOENT if no block found                     <br>
704    *                        -EPERM if access denied (object locked)
705    */
706   int FindAndSelectDataBlock();
707
708   /**
709    * Set status flag.
710    * @param flag     flag to set
711    * @return current status flags
712    */
713   unsigned int SetStatusFlag(unsigned int flag) {return fFlags|=flag;}
714
715   /**
716    * Clear status flag.
717    * @param flag     flag to clear
718    * @return current status flags
719    */
720   unsigned int ClearStatusFlag(unsigned int flag) {return fFlags&=~flag;}
721
722   /**
723    * Check status flag.
724    * @param flag     flag to check
725    * @return 1 if flag is set
726    */
727   int CheckStatusFlag(unsigned int flag) const {return (fFlags&flag)==flag;}
728
729   /**
730    * Find handler description for a certain block index.
731    */
732   const AliHLTOUTHandlerListEntry& FindHandlerDesc(AliHLTUInt32_t blockIndex);
733
734   /**
735    * Internal New function for the external HLTOUT instances.
736    * Currently supported classes are AliHLTOUTRawReader and
737    * AliHLTOUTDigitReader, both implemented in libHLTrec.so.
738    */
739   static AliHLTOUT* New(const char* classname);
740
741   /**
742    * Set the RawReader as parameter.
743    * The function is for internal use only in conjunction with the
744    * New() functions.
745    */
746   virtual void SetParam(AliRawReader* pRawReader);
747
748   /**
749    * Set the RunLoader as parameter
750    * The function is for internal use only in conjunction with the
751    * New() functions.
752    */
753   virtual void SetParam(TTree* pDigitTree, int event=-1);
754
755   /** data type for the current block search, set from @ref SelectFirstDataBlock */
756   AliHLTComponentDataType fSearchDataType; //!transient
757
758   /** data specification for the current block search */
759   AliHLTUInt32_t fSearchSpecification; //!transient
760
761   /** handler type for the current block search */
762   AliHLTModuleAgent::AliHLTOUTHandlerType fSearchHandlerType; // !transient
763
764   /** instance flags: locked, collecting, ... */
765   unsigned int fFlags; //!transient
766
767   /** list of block descriptors */
768   AliHLTOUTBlockDescriptorVector fBlockDescList; //!transient
769
770   /** current position in the list */
771   unsigned int fCurrent; //!transient
772
773   /** data buffer under processing */
774   const AliHLTUInt8_t* fpBuffer; //!transient
775
776   /** list of AliHLTOUTHandlers */
777   AliHLTOUTHandlerListEntryVector fDataHandlers; // !transient
778
779   /** verbose or silent output */
780   bool fbVerbose; //!transient
781
782   /** gobal instance set for certain steps of the analysis */
783   static AliHLTOUT* fgGlobalInstance; //! transient
784
785   /** logging methods */
786   AliHLTLogging fLog; //! transient
787
788   /** current buffer converted to a TObject */
789   TObject* fpDataObject; //!
790   const AliHLTUInt8_t* fpObjectBuffer; //!
791   AliHLTUInt32_t fObjectBufferSize; //!
792
793   /** current event id */
794   AliHLTUInt64_t fCurrentEventId; //!
795
796   ClassDef(AliHLTOUT, 6)
797 };
798 #endif