From 91f76e9bf9dc8e0f8aabc081227674e41036278c Mon Sep 17 00:00:00 2001 From: cvetan Date: Wed, 17 Oct 2007 16:05:01 +0000 Subject: [PATCH] COrrect handling of integers and shorts in case of big-endian platform (Marco) --- RAW/AliRawReader.cxx | 20 +++++++++++++ RAW/AliRawReader.h | 3 ++ RAW/AliRawReaderRoot.cxx | 63 +--------------------------------------- RAW/AliRawReaderRoot.h | 1 - 4 files changed, 24 insertions(+), 63 deletions(-) diff --git a/RAW/AliRawReader.cxx b/RAW/AliRawReader.cxx index ffce953f47a..e820a42891a 100644 --- a/RAW/AliRawReader.cxx +++ b/RAW/AliRawReader.cxx @@ -297,6 +297,20 @@ Bool_t AliRawReader::IsEventSelected() const return kTRUE; } +UInt_t AliRawReader::SwapWord(UInt_t x) const +{ + // Swap the endianess of the integer value 'x' + + return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) << 8) | + ((x & 0x00ff0000U) >> 8) | ((x & 0xff000000U) >> 24)); +} + +UShort_t AliRawReader::SwapShort(UShort_t x) const +{ + // Swap the endianess of the short value 'x' + + return (((x & 0x00ffU) << 8) | ((x & 0xff00U) >> 8)) ; +} Bool_t AliRawReader::ReadNextInt(UInt_t& data) { @@ -315,6 +329,9 @@ Bool_t AliRawReader::ReadNextInt(UInt_t& data) Error("ReadNextInt", "could not read data!"); return kFALSE; } +#ifndef R__BYTESWAP + data=SwapWord(data); +#endif return kTRUE; } @@ -335,6 +352,9 @@ Bool_t AliRawReader::ReadNextShort(UShort_t& data) Error("ReadNextShort", "could not read data!"); return kFALSE; } +#ifndef R__BYTESWAP + data=SwapShort(data); +#endif return kTRUE; } diff --git a/RAW/AliRawReader.h b/RAW/AliRawReader.h index d1d0cb98107..9b3b3d9dbc4 100644 --- a/RAW/AliRawReader.h +++ b/RAW/AliRawReader.h @@ -156,6 +156,9 @@ class AliRawReader: public TObject { AliRawDataHeader* fHeaderSwapped; // temporary buffer for swapping header on PowerPC + UInt_t SwapWord(UInt_t x) const; + UShort_t SwapShort(UShort_t x) const; + ClassDef(AliRawReader, 0) // base class for reading raw digits }; diff --git a/RAW/AliRawReaderRoot.cxx b/RAW/AliRawReaderRoot.cxx index 2e96838cc9e..cca560de79c 100644 --- a/RAW/AliRawReaderRoot.cxx +++ b/RAW/AliRawReaderRoot.cxx @@ -321,18 +321,10 @@ Int_t AliRawReaderRoot::GetEquipmentHeaderSize() const } // _________________________________________________________________________ -UInt_t AliRawReaderRoot::SwapWord(UInt_t x) const -{ - // Swap the endianess of the integer value 'x' - - return (((x & 0x000000ffU) << 24) | ((x & 0x0000ff00U) << 8) | - ((x & 0x00ff0000U) >> 8) | ((x & 0xff000000U) >> 24)); -} - void AliRawReaderRoot::SwapData(const void* inbuf, const void* outbuf, UInt_t size) { // The method swaps the contents of the // raw-data event header - UInt_t intCount = (size+sizeof(UInt_t)-1)/sizeof(UInt_t); + UInt_t intCount = (size+3)/sizeof(UInt_t); UInt_t* buf = (UInt_t*) inbuf; // temporary integers buffer for (UInt_t i=0; iGetBuffer()); - - UInt_t gapL = pos%sizeof(UInt_t); - UInt_t gapR = (pos+size)%sizeof(UInt_t); - if ( gapR > 0 ) gapR = sizeof(UInt_t) - gapR; - - UChar_t* firstWord = fPosition - gapL; // pointer to the begin of the 1st word - UChar_t* lastWord = fPosition + size + gapR; // pointer to the begin of the 1st word following the buffer and not included - - // Loop through the all words and write each of them swapped - UInt_t bytesWritten = 0; - while (firstWord < lastWord) - { - UInt_t* value = (UInt_t*) firstWord; - UInt_t valueInv = SwapWord( *value ); - - if ( (gapL+size)<=sizeof(UInt_t) ) - { - // invert only byte(s) within the 1st (and unique) word - memcpy((UInt_t*)(data+bytesWritten), &valueInv+gapL, size); - bytesWritten += size; - } - else - { - if ( gapL>0 ) - { - // 1st word unaligned - memcpy((UInt_t*)(data+bytesWritten), &valueInv+gapL, sizeof(UInt_t)-gapL); - bytesWritten += sizeof(UInt_t) - gapL; - } - else - { - if ( gapR>0 ) - { - // last word unaligned - memcpy((UInt_t*)(data+bytesWritten), &valueInv, sizeof(UInt_t)-gapR); - bytesWritten += sizeof(UInt_t) - gapR; - } - else - { - // no unalignements - memcpy((UInt_t*)(data+bytesWritten), &valueInv, sizeof(UInt_t)); - bytesWritten += sizeof(UInt_t); - } - } - } - - firstWord += sizeof(UInt_t); - } -#else memcpy(data, fPosition, size); -#endif fPosition += size; fCount -= size; diff --git a/RAW/AliRawReaderRoot.h b/RAW/AliRawReaderRoot.h index 0bf94cb019c..f3156134e21 100644 --- a/RAW/AliRawReaderRoot.h +++ b/RAW/AliRawReaderRoot.h @@ -72,7 +72,6 @@ class AliRawReaderRoot: public AliRawReader { UChar_t* fPosition; // current position in the raw data UChar_t* fEnd; // end position of the current subevent - UInt_t SwapWord(UInt_t x) const; void SwapData(const void* inbuf, const void* outbuf, UInt_t size); -- 2.43.0