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()
{
// "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 !",
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;
{
// go to the next event in the root file
- if (!fFile) return kFALSE;
+ if (!fBranch) return kFALSE;
do {
delete fEvent;
{
// go back to the beginning of the root file
- if (!fFile) return kFALSE;
+ if (!fBranch) return kFALSE;
fEventIndex = -1;
delete fEvent;