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