From e653e3e1877b27fe831125877986308d3327d57c Mon Sep 17 00:00:00 2001 From: cvetan Date: Fri, 27 Jul 2007 09:53:23 +0000 Subject: [PATCH] The fixes are related to the correct swapping of event,sub-event and equipment headers on big-endian platforms. The swapping is driven by the magic word stored in the DATE event header (Marco+Cvetan) --- RAW/AliMDC.cxx | 2 +- RAW/AliRawEquipmentHeader.cxx | 19 ++++++++++++++----- RAW/AliRawEquipmentHeader.h | 1 + RAW/AliRawEventHeaderBase.cxx | 34 +++++++++++++++++++++++++++------- RAW/AliRawEventHeaderBase.h | 2 ++ 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/RAW/AliMDC.cxx b/RAW/AliMDC.cxx index 3dfd39c9ca0..06867a9ebfc 100644 --- a/RAW/AliMDC.cxx +++ b/RAW/AliMDC.cxx @@ -568,7 +568,7 @@ Int_t AliMDC::Run(const char* inputFile, Bool_t loop, eventSize = 2 * hdr->GetEventSize(); event = new char[eventSize]; } - memcpy(event, hdr->HeaderBaseBegin(), hdr->HeaderBaseSize()); + memcpy(event, header.HeaderBaseBegin(), header.HeaderBaseSize()); memcpy(event+hdr->HeaderBaseSize(), hdr->HeaderBegin(), hdr->HeaderSize()); if (hdr->GetExtendedDataSize() != 0) memcpy(event+hdr->HeaderBaseSize()+hdr->HeaderSize(), diff --git a/RAW/AliRawEquipmentHeader.cxx b/RAW/AliRawEquipmentHeader.cxx index 329528fa048..51ac92e4f06 100644 --- a/RAW/AliRawEquipmentHeader.cxx +++ b/RAW/AliRawEquipmentHeader.cxx @@ -40,6 +40,15 @@ AliRawEquipmentHeader::AliRawEquipmentHeader(): fTypeAttribute[i] = 0; } +//______________________________________________________________________________ +UInt_t AliRawEquipmentHeader::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 AliRawEquipmentHeader::Swap() { @@ -47,12 +56,12 @@ void AliRawEquipmentHeader::Swap() // has already been swapped. This method is only called when the // header is read from the DATE event builder (GDC). - fSize = net2host(fSize); - fEquipmentType = net2host(fEquipmentType); - fEquipmentID = net2host(fEquipmentID); - fBasicElementSizeType = net2host(fBasicElementSizeType); + fSize = SwapWord(fSize); + fEquipmentType = SwapWord(fEquipmentType); + fEquipmentID = SwapWord(fEquipmentID); + fBasicElementSizeType = SwapWord(fBasicElementSizeType); for (int i = 0; i < kAttributeWords; i++) - fTypeAttribute[i] = net2host(fTypeAttribute[i]); + fTypeAttribute[i] = SwapWord(fTypeAttribute[i]); } //______________________________________________________________________________ diff --git a/RAW/AliRawEquipmentHeader.h b/RAW/AliRawEquipmentHeader.h index 5104c5860f4..8efdf45bd3b 100644 --- a/RAW/AliRawEquipmentHeader.h +++ b/RAW/AliRawEquipmentHeader.h @@ -25,6 +25,7 @@ public: void *HeaderBegin() { return (void *) &fSize; } Int_t HeaderSize() const { return (Long_t) &fBasicElementSizeType - (Long_t) &fSize + sizeof(fBasicElementSizeType); } + UInt_t SwapWord(UInt_t x) const; void Swap(); UInt_t GetEquipmentSize() const { return fSize; } diff --git a/RAW/AliRawEventHeaderBase.cxx b/RAW/AliRawEventHeaderBase.cxx index 59ae47e649c..12b852ffca1 100644 --- a/RAW/AliRawEventHeaderBase.cxx +++ b/RAW/AliRawEventHeaderBase.cxx @@ -93,6 +93,14 @@ Int_t AliRawEventHeaderBase::HeaderSize() const } //______________________________________________________________________________ +UInt_t AliRawEventHeaderBase::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 AliRawEventHeaderBase::Swap() { // Swap base header data. @@ -102,10 +110,10 @@ void AliRawEventHeaderBase::Swap() if (IsSwapped()) { fIsSwapped = kTRUE; - fSize = net2host(fSize); - fMagic = net2host(fMagic); - fHeadSize = net2host(fHeadSize); - fVersion = net2host(fVersion); + fSize = SwapWord(fSize); + fMagic = SwapWord(fMagic); + fHeadSize = SwapWord(fHeadSize); + fVersion = SwapWord(fVersion); } } @@ -248,6 +256,18 @@ AliRawEventHeaderBase* AliRawEventHeaderBase::Create(char*& data) return hdr; } +void AliRawEventHeaderBase::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); + + UInt_t* buf = (UInt_t*) inbuf; // temporary integers buffer + for (UInt_t i=0; i0) { - swab(data, GetExtendedData(), GetExtendedDataSize()); + SwapData(data, GetExtendedData(), GetExtendedDataSize()); data += GetExtendedDataSize(); } } diff --git a/RAW/AliRawEventHeaderBase.h b/RAW/AliRawEventHeaderBase.h index ce0692adcb9..cd1ccfe6ffb 100644 --- a/RAW/AliRawEventHeaderBase.h +++ b/RAW/AliRawEventHeaderBase.h @@ -30,6 +30,8 @@ public: Bool_t IsSwapped() const { return (fMagic == fgkEventMagicNumberSwapped) ? kTRUE : kFALSE; } Bool_t IsValid() const { return IsSwapped() ? kTRUE : ((fMagic == fgkEventMagicNumber) ? kTRUE : kFALSE); } void Swap(); + UInt_t SwapWord(UInt_t x) const; + void SwapData(const void* data, const void* buf, UInt_t size); UInt_t GetEventSize() const { return fSize; } UInt_t GetMagic() const { return fMagic; } -- 2.43.0