]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReaderRoot.cxx
New IsRawReaderValid() method which returns false in case the raw-data file, chain...
[u/mrichter/AliRoot.git] / RAW / AliRawReaderRoot.cxx
index 71aabc0b3f4cb4ab74781d85a19760f499d16bfa..27f4d269d181e3f51d02dc01831422eb91f54a81 100644 (file)
 
 ClassImp(AliRawReaderRoot)
 
+AliRawReaderRoot::AliRawReaderRoot() :
+  fFile(NULL),
+  fBranch(NULL),
+  fEventIndex(-1),
+  fEvent(NULL),
+  fSubEventIndex(0),
+  fSubEvent(NULL),
+  fEquipmentIndex(0),
+  fEquipment(NULL),
+  fRawData(NULL),
+  fPosition(NULL),
+  fEnd(NULL)
+{
+// default constructor
+
+}
 
 AliRawReaderRoot::AliRawReaderRoot(const char* fileName, Int_t eventNumber) :
   fFile(NULL),
@@ -62,16 +78,19 @@ AliRawReaderRoot::AliRawReaderRoot(const char* fileName, Int_t eventNumber) :
   dir->cd();
   if (!fFile || !fFile->IsOpen()) {
     Error("AliRawReaderRoot", "could not open file %s", fileName);
+    fIsValid = kFALSE;
     return;
   }
   TTree* tree = (TTree*) fFile->Get("RAW");
   if (!tree) {
     Error("AliRawReaderRoot", "no raw data tree found");
+    fIsValid = kFALSE;
     return;
   }
   fBranch = tree->GetBranch("rawevent");
   if (!fBranch) {
     Error("AliRawReaderRoot", "no raw data branch found");
+    fIsValid = kFALSE;
     return;
   }
 
@@ -80,6 +99,7 @@ AliRawReaderRoot::AliRawReaderRoot(const char* fileName, Int_t eventNumber) :
   if (fEventIndex >= 0) {
     if (fBranch->GetEntry(fEventIndex) <= 0) {
       Error("AliRawReaderRoot", "no event with number %d found", fEventIndex);
+      fIsValid = kFALSE;
       return;
     }
   }
@@ -99,7 +119,7 @@ AliRawReaderRoot::AliRawReaderRoot(AliRawEvent* event) :
   fEnd(NULL)
 {
 // create an object to read digits from the given raw event
-
+  if (!fEvent) fIsValid = kFALSE;
 }
 
 AliRawReaderRoot::AliRawReaderRoot(const AliRawReaderRoot& rawReader) :
@@ -125,16 +145,19 @@ AliRawReaderRoot::AliRawReaderRoot(const AliRawReaderRoot& rawReader) :
     if (!fFile || !fFile->IsOpen()) {
       Error("AliRawReaderRoot", "could not open file %s", 
            rawReader.fFile->GetName());
+      fIsValid = kFALSE;
       return;
     }
     TTree* tree = (TTree*) fFile->Get("RAW");
     if (!tree) {
       Error("AliRawReaderRoot", "no raw data tree found");
+      fIsValid = kFALSE;
       return;
     }
     fBranch = tree->GetBranch("rawevent");
     if (!fBranch) {
       Error("AliRawReaderRoot", "no raw data branch found");
+      fIsValid = kFALSE;
       return;
     }
 
@@ -144,6 +167,7 @@ AliRawReaderRoot::AliRawReaderRoot(const AliRawReaderRoot& rawReader) :
       if (fBranch->GetEntry(fEventIndex) <= 0) {
        Error("AliRawReaderRoot", "no event with number %d found", 
              fEventIndex);
+       fIsValid = kFALSE;
        return;
       }
     }
@@ -186,6 +210,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 +290,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
 {
@@ -308,6 +344,22 @@ Int_t AliRawReaderRoot::GetEquipmentHeaderSize() const
   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()
 {
@@ -348,6 +400,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;
@@ -374,10 +430,15 @@ 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",
-               "raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
-               fHeader->fSize, fEnd - fPosition);
+       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);
@@ -433,6 +494,7 @@ Bool_t AliRawReaderRoot::ReadNext(UChar_t* data, Int_t size)
     return kFALSE;
   }
   memcpy(data, fPosition, size);
+
   fPosition += size;
   fCount -= size;
   return kTRUE;
@@ -460,7 +522,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;
@@ -470,6 +532,7 @@ Bool_t AliRawReaderRoot::NextEvent()
       return kFALSE;
     fEventIndex++;
   } while (!IsEventSelected());
+  fEventNumber++;
   return Reset();
 }
 
@@ -477,15 +540,43 @@ 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();
+}
+
+Bool_t  AliRawReaderRoot::GotoEvent(Int_t event)
+{
+  // go to a particular event
+  // Uses the absolute event index inside the
+  // raw-data file
+
+  if (!fBranch) return kFALSE;
+
+  delete fEvent;
+  fEvent = new AliRawEvent;
+  fBranch->SetAddress(&fEvent);
+  if (fBranch->GetEntry(event) <= 0)
+    return kFALSE;
+  fEventIndex = event;
+  fEventNumber++;
   return Reset();
 }
 
+Int_t AliRawReaderRoot::GetNumberOfEvents() const
+{
+  // Get the total number of events in
+  // the raw-data tree
+
+  if (!fBranch) return -1;
+
+  return fBranch->GetEntries();
+}
 
 Int_t AliRawReaderRoot::CheckData() const
 {
@@ -539,9 +630,10 @@ Int_t AliRawReaderRoot::CheckData() const
       // check consistency of data size in the header and in the equipment
       AliRawDataHeader* header = (AliRawDataHeader*) position;
       if ((position + header->fSize) != end) {
-       Warning("ReadHeader",
-               "raw data size found in the header is wrong (%d != %d)! Using the equipment size instead !",
-               header->fSize, end - position);
+       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;
       }