From: richterm Date: Tue, 23 Oct 2007 10:01:36 +0000 (+0000) Subject: further work on HLTOUT treatment X-Git-Url: http://git.uio.no/git/?p=u%2Fmrichter%2FAliRoot.git;a=commitdiff_plain;h=049b43b2f4657d2be01bb5ad6702f435c4b42bcd;hp=8c617325a7ab11e4596d6bf5a5ac1ad9b5e8726b further work on HLTOUT treatment --- diff --git a/HLT/BASE/AliHLTOUT.cxx b/HLT/BASE/AliHLTOUT.cxx index cab6fc2f60d..5bdde9a31ff 100644 --- a/HLT/BASE/AliHLTOUT.cxx +++ b/HLT/BASE/AliHLTOUT.cxx @@ -37,7 +37,7 @@ AliHLTOUT::AliHLTOUT() : fSearchDataType(kAliHLTVoidDataType), fSearchSpecification(kAliHLTVoidDataSpec), - fbLocked(0), + fFlags(0), fBlockDescList(), fCurrent(fBlockDescList.begin()), fpBuffer(NULL) @@ -63,23 +63,46 @@ int AliHLTOUT::GetNofDataBlocks() int AliHLTOUT::SelectFirstDataBlock(AliHLTComponentDataType dt, AliHLTUInt32_t spec) { // see header file for class documentation - if (fbLocked) return -EPERM; + if (CheckStatusFlag(kLocked)) return -EPERM; fCurrent=fBlockDescList.begin(); fSearchDataType=dt; fSearchSpecification=spec; - return SelectNextDataBlock(); + return FindAndSelectDataBlock(); } int AliHLTOUT::SelectNextDataBlock() { // see header file for class documentation - if (fbLocked) return -EPERM; + if (CheckStatusFlag(kLocked)) return -EPERM; + fCurrent++; + return FindAndSelectDataBlock(); +} + +int AliHLTOUT::FindAndSelectDataBlock() +{ + // see header file for class documentation + if (CheckStatusFlag(kLocked)) return -EPERM; int iResult=-ENOENT; while (fCurrent!=fBlockDescList.end() && iResult==-ENOENT) { if ((fSearchDataType==kAliHLTAnyDataType || (*fCurrent)==fSearchDataType) && fSearchSpecification==kAliHLTVoidDataSpec || (*fCurrent)==fSearchSpecification) { iResult=0; + // TODO: check the byte order on the current system and the byte order of the + // data block, print warning when missmatch and user did not check + AliHLTOUTByteOrder_t blockBO=CheckByteOrder(); + /* + if (blockBO!=fByteOrder) { + SetStatusFlag(kByteOrderWarning); + + } + */ + ClearStatusFlag(kByteOrderChecked); + + // TODO: check the alignment on the current system and the alignment of the + // data block, print warning when missmatch and user did not check + ClearStatusFlag(kAlignmentChecked); } + fCurrent++; } return iResult; } @@ -125,8 +148,28 @@ int AliHLTOUT::ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer) int AliHLTOUT::AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc) { // see header file for class documentation - if (!fbLocked) return -EPERM; + if (!CheckStatusFlag(kCollecting)) return -EPERM; int iResult=0; fBlockDescList.push_back(desc); return iResult; } + +AliHLTOUT::AliHLTOUTByteOrder_t AliHLTOUT::CheckByteOrder() +{ + if (fCurrent!=fBlockDescList.end()) { + SetStatusFlag(kByteOrderChecked); + AliHLTOUT::AliHLTOUTByteOrder_t order=CheckBlockByteOrder((*fCurrent).GetIndex()); + return order; + } + return kInvalidByteOrder; +} + +int AliHLTOUT::CheckAlignment(AliHLTOUT::AliHLTOUTDataType_t type) +{ + if (fCurrent!=fBlockDescList.end()) { + SetStatusFlag(kAlignmentChecked); + int alignment=CheckBlockAlignment((*fCurrent).GetIndex(), type); + return alignment; + } + return -ENOENT; +} diff --git a/HLT/BASE/AliHLTOUT.h b/HLT/BASE/AliHLTOUT.h index 055d867b12f..7cb94fc9f84 100644 --- a/HLT/BASE/AliHLTOUT.h +++ b/HLT/BASE/AliHLTOUT.h @@ -92,10 +92,10 @@ class AliHLTOUT : public AliHLTLogging { public: /** constructor */ AliHLTOUTLockGuard(AliHLTOUT* pInstance) : fpInstance(pInstance) - {if (fpInstance) fpInstance->fbLocked=1;} + {if (fpInstance) fpInstance->SetStatusFlag(kLocked);} /** destructor */ ~AliHLTOUTLockGuard() - {if (fpInstance) fpInstance->fbLocked=0;} + {if (fpInstance) fpInstance->ClearStatusFlag(kLocked);} private: /** standard constructor prohibited */ @@ -133,6 +133,33 @@ class AliHLTOUT : public AliHLTLogging { AliHLTUInt32_t fIndex; //!transient }; + enum AliHLTOUTByteOrder_t { + /** no data block selected */ + kInvalidByteOrder=-1, + kUnknownByteOrder=0, + kLittleEndian, + kBigEndian + }; + + enum AliHLTOUTDataType_t { + kUint64 = 0, + kUint32 = 1, + kUint16 = 2, + kUint8 = 3, + kDouble = 4, + kFloat = 5 + }; + + /** + * Check byte order of selected block + */ + AliHLTOUTByteOrder_t CheckByteOrder(); + + /** + * Check alignment of selected block + */ + int CheckAlignment(AliHLTOUT::AliHLTOUTDataType_t type); + protected: /** * Add a block descriptor. @@ -149,6 +176,24 @@ class AliHLTOUT : public AliHLTLogging { /** assignment operator prohibited */ AliHLTOUT& operator=(const AliHLTOUT&); + /** + * Internal status flags + */ + enum { + /** the HLTOUT object is locked with the current data block */ + kLocked = 0x1, + /** childs can add block descriptors */ + kCollecting = 0x2, + /** user of the data block has checked the byte order */ + kByteOrderChecked = 0x4, + /** warning on byte order missmatch has been printed */ + kByteOrderWarning = 0x8, + /** user of the data block has checked the alignment */ + kAlignmentChecked = 0x10, + /** warning on alignment missmatch has been printed */ + kAlignmentWarning = 0x20 + }; + /** * Generate the index of the HLTOUT data. * Must be implemented by the child classes. @@ -164,14 +209,56 @@ class AliHLTOUT : public AliHLTLogging { virtual int GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size)=0; + /** + * Check byte order of data block + */ + virtual AliHLTOUTByteOrder_t CheckBlockByteOrder(AliHLTUInt32_t index)=0; + + /** + * Check alignment of data block + */ + virtual int CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType_t type)=0; + + /** + * Select the data block of data type and specification of the previous + * call to @ref SelectFirstDataBlock. Core function of @ref SelectFirstDataBlock + * and @ref SelectNextDataBlock, starts to find a block at the current list + * position. + * @return identifier >=0 if success, neg. error code if failed
+ * -ENOENT if no block found
+ * -EPERM if access denied (object locked) + */ + int FindAndSelectDataBlock(); + + /** + * Set status flag. + * @param flag flag to set + * @return current status flags + */ + unsigned int SetStatusFlag(unsigned int flag) {return fFlags|=flag;} + + /** + * Clear status flag. + * @param flag flag to clear + * @return current status flags + */ + unsigned int ClearStatusFlag(unsigned int flag) {return fFlags&=~flag;} + + /** + * Check status flag. + * @param flag flag to check + * @return 1 if flag is set + */ + int CheckStatusFlag(unsigned int flag) const {return (fFlags&flag)==flag;} + /** data type for the current block search, set from @ref SelectFirstDataBlock */ AliHLTComponentDataType fSearchDataType; //!transient /** data specification for the current block search */ AliHLTUInt32_t fSearchSpecification; //!transient - /** instance locked or not */ - int fbLocked; //!transient + /** instance flags: locked, collecting, ... */ + unsigned int fFlags; //!transient /** list of block descriptors */ vector fBlockDescList; //!transient diff --git a/HLT/BASE/AliHLTOUTHomerBuffer.cxx b/HLT/BASE/AliHLTOUTHomerBuffer.cxx index 0f95b3ca4ba..ebeb347c67a 100644 --- a/HLT/BASE/AliHLTOUTHomerBuffer.cxx +++ b/HLT/BASE/AliHLTOUTHomerBuffer.cxx @@ -19,7 +19,7 @@ /** @file AliHLTOUTHomerBuffer.cxx @author Matthias Richter @date - @brief HLTOUT data wrapper for AliRawReader. */ + @brief HLTOUT data wrapper for buffer in HOMER format. */ // see header file for class documentation // or @@ -28,34 +28,57 @@ // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt #include +#include #include "AliHLTOUTHomerBuffer.h" #include "AliHLTHOMERReader.h" +#include "AliHLTHOMERLibManager.h" /** ROOT macro for the implementation of ROOT specific class methods */ ClassImp(AliHLTOUTHomerBuffer) -AliHLTOUTHomerBuffer::AliHLTOUTHomerBuffer(const AliHLTUInt8_t* pBuffer) +AliHLTOUTHomerBuffer::AliHLTOUTHomerBuffer(const AliHLTUInt8_t* pBuffer, int size) : AliHLTOUT(), fpBuffer(pBuffer), - fpReader(NULL) + fSize(size), + fpReader(NULL), + fpManager(new AliHLTHOMERLibManager) { // see header file for class documentation // or // refer to README to build package // or // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt + assert(sizeof(homer_uint64)==kAliHLTComponentDataTypefIDsize); + assert(sizeof(homer_uint32)==kAliHLTComponentDataTypefOriginSize); + assert(fpManager); } AliHLTOUTHomerBuffer::~AliHLTOUTHomerBuffer() { // see header file for class documentation + if (fpManager) { + if (fpReader) fpManager->DeleteReader(fpReader); + delete fpManager; + fpManager=NULL; + fpReader=NULL; + } } int AliHLTOUTHomerBuffer::GenerateIndex() { // see header file for class documentation int iResult=0; + if (!fpReader) { + if (fpManager) { + fpReader=fpManager->OpenReader(fpBuffer, fSize); + } + } + if (fpReader) { + iResult=ScanReader(fpReader); + } else { + iResult=-ENODEV; + } return iResult; } @@ -75,3 +98,58 @@ int AliHLTOUTHomerBuffer::GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_ } return iResult; } + +AliHLTOUT::AliHLTOUTByteOrder_t AliHLTOUTHomerBuffer::CheckBlockByteOrder(AliHLTUInt32_t index) +{ + if (fpReader) { + return static_cast(fpReader->GetBlockByteOrder(index)); + } + return kInvalidByteOrder; +} + +int AliHLTOUTHomerBuffer::CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType_t type) +{ + if (fpReader) { + return fpReader->GetBlockTypeAlignment(index, static_cast(type)); + } + return -ENODATA; +} + +int AliHLTOUTHomerBuffer::ScanReader(AliHLTHOMERReader* pReader, AliHLTUInt32_t offset) +{ + // see header file for class documentation + int iResult=0; + if (pReader) { + AliHLTUInt32_t nofBlocks=pReader->GetBlockCnt(); + AliHLTUInt32_t tmp1=0x1; + AliHLTUInt32_t tmp2=offset; + + // first check if the offset allows to add all data blocks without exceeding the + // range + while (nofBlocks0) { + if (tmp2&0x1) { + HLTError("index range %#x exceeded for %d data blocks", nofBlocks, offset); + iResult=-ERANGE; + } + tmp2>>1; + tmp1<<1; + } + + // loop over data blocks + HLTDebug("generating index for %d data blocks of reader with offset %#x", nofBlocks, offset); + for (AliHLTUInt32_t i=0; i=0; i++) { + homer_uint64 id=pReader->GetBlockDataType( i ); + homer_uint32 origin=pReader->GetBlockDataOrigin( i ); + homer_uint32 spec=pReader->GetBlockDataSpec( i ); + AliHLTComponentDataType dt; + memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize); + memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize); + AliHLTOUTBlockDescriptor desc(dt, spec, offset|i); + iResult=AddBlockDescriptor(desc); + } + } else { + iResult=-ENODEV; + } + return iResult; +} + diff --git a/HLT/BASE/AliHLTOUTHomerBuffer.h b/HLT/BASE/AliHLTOUTHomerBuffer.h index a1f52c08121..b8c3edbf7df 100644 --- a/HLT/BASE/AliHLTOUTHomerBuffer.h +++ b/HLT/BASE/AliHLTOUTHomerBuffer.h @@ -20,7 +20,8 @@ */ #include "AliHLTOUT.h" -class HOMERReader; +class AliHLTHOMERReader; +class AliHLTHOMERLibManager; /** * @class AliHLTOUTHomerBuffer @@ -29,11 +30,18 @@ class HOMERReader; class AliHLTOUTHomerBuffer : public AliHLTOUT { public: /** constructor */ - AliHLTOUTHomerBuffer(const AliHLTUInt8_t* pBuffer); + AliHLTOUTHomerBuffer(const AliHLTUInt8_t* pBuffer, int size); /** destructor */ virtual ~AliHLTOUTHomerBuffer(); protected: + /** + * Step trough data blocks of a HOMER reader and generate index. + */ + int ScanReader(AliHLTHOMERReader* pReader, AliHLTUInt32_t majorIndex=0); + + /** dynamic loader manager for HOMER library */ + AliHLTHOMERLibManager* fpManager; //!transient private: /** standard constructor prohibited */ @@ -57,11 +65,24 @@ class AliHLTOUTHomerBuffer : public AliHLTOUT { virtual int GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size); + /** + * Check byte order of data block + */ + virtual AliHLTOUTByteOrder_t CheckBlockByteOrder(AliHLTUInt32_t index); + + /** + * Check alignment of data block + */ + virtual int CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType_t type); + /** data buffer */ const AliHLTUInt8_t* fpBuffer; //! transient + /** size of data buffer */ + int fSize; //! transient + /** instance of the HOMER reader */ - HOMERReader* fpReader; //!transient + AliHLTHOMERReader* fpReader; //!transient ClassDef(AliHLTOUTHomerBuffer, 0) };