+
+ typedef vector<AliHLTOUTHandlerListEntry> AliHLTOUTHandlerListEntryVector;
+ typedef vector<AliHLTOUTBlockDescriptor> AliHLTOUTBlockDescriptorVector;
+ typedef vector<AliHLTOUT*> AliHLTOUTPVector;
+
+ /**
+ * Selection guard for the AliHLTOUT object.
+ * If the object is locked, the selection of data blocks can not be changed.
+ */
+ class AliHLTOUTSelectionGuard {
+ public:
+ /** constructor */
+ AliHLTOUTSelectionGuard(AliHLTOUT* pInstance) : fpInstance(pInstance)
+ {if (fpInstance) fpInstance->SelectDataBlock();}
+ /** constructor */
+ AliHLTOUTSelectionGuard(AliHLTOUT* pInstance, const AliHLTOUTHandlerListEntry* pHandlerDesc) : fpInstance(pInstance)
+ {if (fpInstance) fpInstance->SelectDataBlocks(pHandlerDesc);}
+ /** destructor */
+ ~AliHLTOUTSelectionGuard()
+ {if (fpInstance) fpInstance->DisableBlockSelection();}
+
+ private:
+ /** standard constructor prohibited */
+ AliHLTOUTSelectionGuard();
+ /** copy constructor prohibited */
+ AliHLTOUTSelectionGuard(const AliHLTOUTSelectionGuard&);
+ /** assignment operator prohibited */
+ AliHLTOUTSelectionGuard& operator=(const AliHLTOUTSelectionGuard&);
+
+ /** the AliHLTOUT instance the guard is locking */
+ AliHLTOUT* fpInstance; //!transient
+ };
+
+ /**
+ * Init for processing.
+ * The HLTOUT is scanned for all available data blocks and the
+ * AliHLTOUTHandler objects for the data blocks are created according
+ * to the module agents (see AliHLTModuleAgent).
+ */
+ int Init();
+
+ /**
+ * Reset and clear all data block descriptors.
+ * @note Since sub-collections are only referred via the block
+ * descriptors, all information on sub-collections is also lost.
+ * Child classes should implement ResetInput in order to cleanup
+ * the input devices.
+ */
+ int Reset();
+
+ /**
+ * Get the current event id
+ */
+ AliHLTUInt64_t EventId() {return fCurrentEventId;}
+
+ /**
+ * Get number of data blocks in the HLTOUT data
+ */
+ int GetNofDataBlocks();
+
+ /**
+ * Select the first data block of a certain data type and specification.
+ * The selection criteria can be of kAliHLTAnyDataType and/or
+ * kAliHLTVoidDataSpec in order to be ignored and just match any data block.
+ *
+ * The search criteria can be combined with a handler type (e.g. kRawReader)
+ * @param dt [in] data type to match <br>
+ * @param spec [in] data specification to match <br>
+ * @param handlerType [in] type of the handler
+ * @param skipProcessed [in] skip all block marked processed
+ * @return block index: >= 0 if success, -ENOENT if no block found <br>
+ * neg. error code if failed <br>
+ * -EPERM if access denied (object locked)
+ */
+ int SelectFirstDataBlock(AliHLTComponentDataType dt=kAliHLTAnyDataType,
+ AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
+ AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=AliHLTModuleAgent::kUnknownOutput,
+ bool skipProcessed=true);
+
+ /**
+ * Select the next data block of data type and specification of the previous
+ * call to @ref SelectFirstDataBlock.
+ * @return block index: >= 0 if success, -ENOENT if no block found <br>
+ * neg. error code if failed <br>
+ * -EPERM if access denied (object locked)
+ */
+ int SelectNextDataBlock();
+
+ /**
+ * Get properties of the selected data block.
+ * @param dt [out] data type of the selected block
+ * @param spec [out] data specification of the selected block
+ */
+ int GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec);
+
+ /**
+ * Get handler description of the current data block.
+ */
+ const AliHLTOUTHandlerListEntry& GetDataBlockHandlerDesc();
+
+ /**
+ * Get handler type of the selected data block.
+ * @return handler type for the selected data block
+ */
+ AliHLTModuleAgent::AliHLTOUTHandlerType GetDataBlockHandlerType();
+
+ /**
+ * Get the index of the current data block.
+ * @return index, AliHLTOUTInvalidIndex if no block selected
+ */
+ AliHLTUInt32_t GetDataBlockIndex();
+
+ /**
+ * Get buffer of the selected data block.
+ * @param pBuffer [out] buffer of the selected data block
+ * @param size [out] size of the selected data block
+ */
+ int GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size);
+
+ /**
+ * Release buffer after use.
+ * @param pBuffer [in] buffer of the selected data block
+ */
+ int ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer);
+
+ /**
+ * Get a TObject from the data buffer
+ * @return TObject pointer if data block is a streamed object
+ */
+ TObject* GetDataObject();
+
+ /**
+ * Release data object
+ */
+ int ReleaseDataObject(TObject* pObject);
+
+ /**
+ * Add the current data block to the selection.
+ * Note: enables also the block selection
+ */
+ int SelectDataBlock();
+
+ /**
+ * Add the all data blocks of a certain handler to the selection.
+ * Note: enables also the block selection
+ */
+ int SelectDataBlocks(const AliHLTOUTHandlerListEntry* pHandlerDesc);
+
+ /**
+ * Enable the selection of data blocks.
+ */
+ int EnableBlockSelection();
+
+ /**
+ * Disable the selection of data blocks.
+ */
+ int DisableBlockSelection();
+
+ /**
+ * Reset the data block selection.
+ * Resets the selection list, none of the blocks is selected.
+ */
+ int ResetBlockSelection();
+
+ /**
+ * Mark the current block as processed.
+ */
+ int MarkDataBlockProcessed();
+
+ /**
+ * Mark all data blocks of a certain handler processed.
+ */
+ int MarkDataBlocksProcessed(const AliHLTOUTHandlerListEntry* pHandlerDesc);
+
+ /**
+ * Add a sub collection to the HLTOUT.
+ */
+ int AddSubCollection(AliHLTOUT* pCollection);
+
+ /**
+ * Release a previously added sub collection.
+ */
+ int ReleaseSubCollection(AliHLTOUT* pCollection);
+
+ /**
+ * Get module agent for the selected data block.
+ */
+ AliHLTModuleAgent* GetAgent();
+
+ /**
+ * Get handler for the selected data block.
+ */
+ AliHLTOUTHandler* GetHandler();
+
+ /**
+ * Convert data buffer to ESD.
+ * The buffer is supposed to describe a streamed AliESDEvent object.
+ * If no target object is specified, the ESD is written to a file AliHLTdetESDs.root,
+ * where 'det' is derived from the data type origin. Each time the function is invoked
+ * a new event is created. Dummy events are added if the previous events did not contain
+ *
+ * The function needs AliRoot and might not be implemented by all AliHLTOUT
+ * implementations.
+ * a data block of this specification.
+ * @param pBuffer [in] the data buffer
+ * @param size [in] data buffer size
+ * @param dt [in] data type of the block
+ * @param tgtesd [out] optional target
+ */
+ virtual int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt, AliESDEvent* tgtesd=NULL) const;
+
+ enum AliHLTOUTByteOrder {
+ /** no data block selected */
+ kInvalidByteOrder=-1,
+ kUnknownByteOrder=0,
+ kLittleEndian,
+ kBigEndian
+ };
+
+ enum AliHLTOUTDataType {
+ kUint64 = 0,
+ kUint32 = 1,
+ kUint16 = 2,
+ kUint8 = 3,
+ kDouble = 4,
+ kFloat = 5
+ };
+
+ /**
+ * Check byte order of selected block
+ */
+ AliHLTOUTByteOrder CheckByteOrder();
+
+ /**
+ * Check alignment of selected block
+ */
+ int CheckAlignment(AliHLTOUT::AliHLTOUTDataType type);
+
+ /**
+ * Helper function to byte swap a 64 bit value.
+ */
+ static AliHLTUInt64_t ByteSwap64(AliHLTUInt64_t src);
+
+ /**
+ * Helper function to byte swap a 32 bit value.
+ */
+ static AliHLTUInt32_t ByteSwap32(AliHLTUInt32_t src);
+
+ /**
+ * Insert a handler item.
+ * The current list entries are checked if the handler is already in
+ * the list. It is added if not in the list, otherwise the block index
+ * is added to the existing entry.
+ * @param list the handler list
+ * @param entry handler list entry
+ * @return 0 if added, EEXIST (non negative!) if merged with existing entry <br>
+ * neg. error code if failed
+ */
+ static int InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry);