]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReaderRoot.cxx
Adding the fitting for transformation with
[u/mrichter/AliRoot.git] / RAW / AliRawReaderRoot.cxx
index a32bafc508cd08aa4ddfdf5e649dc45de748c033..f720d42146591c86f75c1b8659bb00f4ce0bd23c 100644 (file)
@@ -186,6 +186,13 @@ AliRawReaderRoot::~AliRawReaderRoot()
   }
 }
 
+const AliRawEventHeaderBase* AliRawReaderRoot::GetEventHeader() const
+{
+  // Get the even header
+  // Return NULL in case of failure
+  if (!fEvent) return NULL;
+  return fEvent->GetHeader();
+}
 
 UInt_t AliRawReaderRoot::GetType() const
 {
@@ -259,6 +266,11 @@ UInt_t AliRawReaderRoot::GetGDCId() const
   return fEvent->GetHeader()->Get("GdcId");
 }
 
+UInt_t AliRawReaderRoot::GetTimestamp() const
+{
+  if (!fEvent) return 0;
+  return fEvent->GetHeader()->Get("Timestamp");
+}
 
 Int_t AliRawReaderRoot::GetEquipmentSize() const
 {
@@ -300,6 +312,30 @@ Int_t AliRawReaderRoot::GetEquipmentElementSize() const
   return fEquipment->GetEquipmentHeader()->GetBasicSizeType();
 }
 
+Int_t AliRawReaderRoot::GetEquipmentHeaderSize() const
+{
+// get the size of the equipment header (28 bytes by default)
+
+  if (!fEvent || !fEquipment || !fEquipment->GetEquipmentHeader()) return 0;
+  return fEquipment->GetEquipmentHeader()->HeaderSize();
+}
+
+// _________________________________________________________________________
+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+3)/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()
 {
@@ -340,6 +376,10 @@ Bool_t AliRawReaderRoot::ReadHeader()
       fCount = 0;
       fEquipment = fSubEvent->GetEquipment(fEquipmentIndex++);
       if (!fEquipment) continue;
+      if (!IsSelected()) {
+       fPosition = fEnd;
+       continue;
+      }
       fRawData = fEquipment->GetRawData();
       if (!fRawData) {
        fPosition = fEnd;
@@ -366,6 +406,17 @@ 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) {
+       if (fHeader->fSize != 0xFFFFFFFF)
+         Warning("ReadHeader",
+                 "Equipment %d : raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
+                 fEquipment->GetEquipmentHeader()->GetId(),fHeader->fSize, fEnd - fPosition);
+       fHeader->fSize = fEnd - fPosition;
+      }
       fPosition += sizeof(AliRawDataHeader);
     }
 
@@ -419,6 +470,7 @@ Bool_t AliRawReaderRoot::ReadNext(UChar_t* data, Int_t size)
     return kFALSE;
   }
   memcpy(data, fPosition, size);
+
   fPosition += size;
   fCount -= size;
   return kTRUE;
@@ -446,17 +498,17 @@ Bool_t AliRawReaderRoot::NextEvent()
 {
 // go to the next event in the root file
 
-  if (!fFile) return kFALSE;
+  if (!fBranch) return kFALSE;
 
   do {
-    if (fBranch->GetEntry(fEventIndex+1) <= 0) {
-      delete fEvent;
-      fEvent = new AliRawEvent;
-      fBranch->SetAddress(&fEvent);
+    delete fEvent;
+    fEvent = new AliRawEvent;
+    fBranch->SetAddress(&fEvent);
+    if (fBranch->GetEntry(fEventIndex+1) <= 0)
       return kFALSE;
-    }
     fEventIndex++;
   } while (!IsEventSelected());
+  fEventNumber++;
   return Reset();
 }
 
@@ -464,12 +516,13 @@ 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;
   fEvent = new AliRawEvent;
   fBranch->SetAddress(&fEvent);
+  fEventNumber = -1;
   return Reset();
 }
 
@@ -525,10 +578,16 @@ Int_t AliRawReaderRoot::CheckData() const
 
       // check consistency of data size in the header and in the equipment
       AliRawDataHeader* header = (AliRawDataHeader*) position;
-      if (header->fSize != 0xFFFFFFFF) {
-       if (position + header->fSize > end) result |= kErrSize;
+      if ((position + header->fSize) != end) {
+       if (header->fSize != 0xFFFFFFFF)
+         Warning("ReadHeader",
+                 "Equipment %d : raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
+                 equipment->GetEquipmentHeader()->GetId(),header->fSize, end - position);
+       header->fSize = end - position;
+       result |= kErrSize;
       }
     }
+    position = end;
   };
 
   return result;