]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReaderRoot.cxx
hole region in front of PHOS detector: update of sectors' numbers
[u/mrichter/AliRoot.git] / RAW / AliRawReaderRoot.cxx
index 760fce690f77504ee6ed1020ae6f1fa084fa7769..2e96838cc9e019d5915c8a881657a1cd6bb062b6 100644 (file)
@@ -320,6 +320,30 @@ Int_t AliRawReaderRoot::GetEquipmentHeaderSize() const
   return fEquipment->GetEquipmentHeader()->HeaderSize();
 }
 
+// _________________________________________________________________________
+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* buf = (UInt_t*) inbuf;    // temporary integers buffer
+  for (UInt_t i=0; i<intCount; i++, buf++) {
+      UInt_t value = SwapWord(*buf);
+      if (i==(intCount-1))
+         memcpy((UInt_t*)outbuf+i, &value, size%sizeof(UInt_t));
+      else
+         memcpy((UInt_t*)outbuf+i, &value, sizeof(UInt_t));
+  }
+}
+// _________________________________________________________________________
 
 Bool_t AliRawReaderRoot::ReadHeader()
 {
@@ -390,6 +414,10 @@ Bool_t AliRawReaderRoot::ReadHeader()
 
       // "read" the data header
       fHeader = (AliRawDataHeader*) fPosition;
+#ifndef R__BYTESWAP
+      SwapData((void*) fHeader, (void*) fHeaderSwapped, sizeof(AliRawDataHeader));
+      fHeader=fHeaderSwapped;
+#endif
       if ((fPosition + fHeader->fSize) != fEnd) {
        Warning("ReadHeader",
                "Equipment %d : raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
@@ -448,7 +476,61 @@ Bool_t AliRawReaderRoot::ReadNext(UChar_t* data, Int_t size)
     fErrorCode = kErrOutOfBounds;
     return kFALSE;
   }
+#ifndef R__BYTESWAP
+  // relative position in the raw data buffer
+  UInt_t pos  = (UInt_t) (fPosition-(UChar_t*)fRawData->GetBuffer());  
+
+  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;
   return kTRUE;
@@ -476,7 +558,7 @@ Bool_t AliRawReaderRoot::NextEvent()
 {
 // go to the next event in the root file
 
-  if (!fFile) return kFALSE;
+  if (!fBranch) return kFALSE;
 
   do {
     delete fEvent;
@@ -494,7 +576,7 @@ Bool_t AliRawReaderRoot::RewindEvents()
 {
 // go back to the beginning of the root file
 
-  if (!fFile) return kFALSE;
+  if (!fBranch) return kFALSE;
 
   fEventIndex = -1;
   delete fEvent;