]> 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 9b51241e24a14590ded5a615ad0e2be69ad53aae..27f4d269d181e3f51d02dc01831422eb91f54a81 100644 (file)
@@ -78,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;
   }
 
@@ -96,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;
     }
   }
@@ -115,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) :
@@ -141,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;
     }
 
@@ -160,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;
       }
     }
@@ -542,6 +550,33 @@ Bool_t AliRawReaderRoot::RewindEvents()
   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
 {