]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
The fixes are related to the correct swapping of event,sub-event and equipment header...
authorcvetan <cvetan@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 27 Jul 2007 09:53:23 +0000 (09:53 +0000)
committercvetan <cvetan@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 27 Jul 2007 09:53:23 +0000 (09:53 +0000)
RAW/AliMDC.cxx
RAW/AliRawEquipmentHeader.cxx
RAW/AliRawEquipmentHeader.h
RAW/AliRawEventHeaderBase.cxx
RAW/AliRawEventHeaderBase.h

index 3dfd39c9ca0a6c13991d5343b83031415e670050..06867a9ebfcdf5394a33868263ca03a380067a8c 100644 (file)
@@ -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(),
index 329528fa048b4a5e665406c66259418114908c32..51ac92e4f0686e82c39703b388dda137830196a2 100644 (file)
@@ -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]);
 }
 
 //______________________________________________________________________________
index 5104c5860f444fd8d8d4aa02a79952649cfd8550..8efdf45bd3bb473f01b9f4c285249bff27713a31 100644 (file)
@@ -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; }
index 59ae47e649cb035e68a756591c4e19ba24ab207a..12b852ffca133079204ff2d12e15914418dc7b70 100644 (file)
@@ -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; i<intCount; i++, buf++) {
+      UInt_t value = SwapWord(*buf);
+      memcpy((UInt_t*)outbuf+i, &value, sizeof(UInt_t)); 
+  }
+}
+
 //______________________________________________________________________________
 Int_t AliRawEventHeaderBase::ReadHeader(char*& data)
 {
@@ -257,12 +277,12 @@ Int_t AliRawEventHeaderBase::ReadHeader(char*& data)
   Long_t start = (Long_t)data;
   // Swap header data if needed
   if (DataIsSwapped()) {
-    swab(data,HeaderBaseBegin(), HeaderBaseSize());
+    SwapData(data, HeaderBaseBegin(), HeaderBaseSize());
     data += HeaderBaseSize();
-    swab(data, HeaderBegin(), HeaderSize());
+    SwapData(data, HeaderBegin(), HeaderSize());
     data += HeaderSize();
     if(GetExtendedDataSize()>0) {
-      swab(data, GetExtendedData(), GetExtendedDataSize());
+      SwapData(data, GetExtendedData(), GetExtendedDataSize());
       data += GetExtendedDataSize();
     }
   }
index ce0692adcb90a592b13bf1c884b78f8d9f0e4e96..cd1ccfe6ffbc266a54bcd695acd7907a0e59b09f 100644 (file)
@@ -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; }