]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - RAW/AliRawReaderFile.cxx
Preparing the raw reader for the new raw-data format. Minor additions to the warning...
[u/mrichter/AliRoot.git] / RAW / AliRawReaderFile.cxx
index 1b5edc3840ca95cdedcefafc1a35935cd73544e3..fe33f776157d003f77ea0b4fab3ac75d1564f1d9 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+/* $Id$ */
+
 ///////////////////////////////////////////////////////////////////////////////
-//
-// This is a class for reading a raw data file and providing
-// information about digits
-//
+/// 
+/// This is a class for reading raw data files.
+///
+/// The files of one event are expected to be in one directory. The name 
+/// of the directory is "raw" + the event number. Each file contains
+/// the raw data (with data header) of one DDL. The convention for the
+/// file names is "DET_#DDL.ddl". "DET" is the name of the detector and
+/// "#DDL" is the unique equipment ID.
+///
+/// The constructor of AliRawReaderFile takes the event number or the
+/// directory name as argument.
+/// 
 ///////////////////////////////////////////////////////////////////////////////
 
 #include "AliRawReaderFile.h"
@@ -28,7 +38,8 @@ ClassImp(AliRawReaderFile)
 
 
 AliRawReaderFile::AliRawReaderFile(Int_t eventNumber) :
-  fDirName("raw"),
+  fEventIndex(eventNumber),
+  fDirName("."),
   fDirectory(NULL),
   fStream(NULL),
   fEquipmentId(-1),
@@ -36,17 +47,15 @@ AliRawReaderFile::AliRawReaderFile(Int_t eventNumber) :
   fBufferSize(0)
 {
 // create an object to read digits from the given event
+// in the current directory
 
-  fDirName += eventNumber;
-  fDirectory = gSystem->OpenDirectory(fDirName);
-  if (!fDirectory) {
-    Error("AliRawReaderFile", "could not open directory %s", fDirName.Data());
-  }
+  fDirectory = OpenDirectory();
   OpenNextFile();
   fHeader = new AliRawDataHeader;
 }
 
-AliRawReaderFile::AliRawReaderFile(const char* dirName) :
+AliRawReaderFile::AliRawReaderFile(const char* dirName, Int_t eventNumber) :
+  fEventIndex(eventNumber),
   fDirName(dirName),
   fDirectory(NULL),
   fStream(NULL),
@@ -56,27 +65,11 @@ AliRawReaderFile::AliRawReaderFile(const char* dirName) :
 {
 // create an object to read digits from the given directory
 
-  fDirectory = gSystem->OpenDirectory(fDirName);
-  if (!fDirectory) {
-    Error("AliRawReaderFile", "could not open directory %s", fDirName.Data());
-  }
+  fDirectory = OpenDirectory();
   OpenNextFile();
   fHeader = new AliRawDataHeader;
 }
 
-AliRawReaderFile::AliRawReaderFile(const AliRawReaderFile& rawReader) :
-  AliRawReader(rawReader)
-{
-  Fatal("AliRawReaderFile", "copy constructor not implemented");
-}
-
-AliRawReaderFile& AliRawReaderFile::operator = (const AliRawReaderFile& 
-                                             /* rawReader */)
-{
-  Fatal("operator =", "assignment operator not implemented");
-  return *this;
-}
-
 AliRawReaderFile::~AliRawReaderFile()
 {
 // close the input file
@@ -94,6 +87,40 @@ AliRawReaderFile::~AliRawReaderFile()
   if (fBuffer) delete[] fBuffer;
 }
 
+void AliRawReaderFile::RequireHeader(Bool_t required)
+{
+  // Reading of raw data in case of missing
+  // raw data header is not implemented for
+  // this class
+  if (!required)
+    Fatal("AliRawReaderFile","Reading of raw data without raw data header is not implemented !");
+
+  AliRawReader::RequireHeader(required);
+}
+
+TString AliRawReaderFile::GetDirName() const
+{
+// return the current directory name
+
+  TString dirName(fDirName);
+  if (fEventIndex >= 0) {
+    dirName += "/raw";
+    dirName += fEventIndex;
+  }
+  return dirName;
+}
+
+void* AliRawReaderFile::OpenDirectory()
+{
+// open and return the directory
+
+  TString dirName = GetDirName();
+  void* directory = gSystem->OpenDirectory(dirName);
+  if (!directory) {
+    Error("OpenDirectory", "could not open directory %s", dirName.Data());
+  }
+  return directory;
+}
 
 Bool_t AliRawReaderFile::OpenNextFile()
 {
@@ -116,7 +143,7 @@ Bool_t AliRawReaderFile::OpenNextFile()
   while (entry = gSystem->GetDirEntry(fDirectory)) {
     if (entry.IsNull()) return kFALSE;
     if (!entry.EndsWith(".ddl")) continue;
-    char* fileName = gSystem->ConcatFileName(fDirName, entry);
+    char* fileName = gSystem->ConcatFileName(GetDirName(), entry);
 #ifndef __DECCXX 
     fStream = new fstream(fileName, ios::binary|ios::in);
 #else
@@ -199,13 +226,10 @@ Bool_t AliRawReaderFile::ReadNext(UChar_t* data, Int_t size)
 
 Bool_t AliRawReaderFile::Reset()
 {
-// reset the current stream position to the beginning of the file
+// reset the current stream position to the first DDL file of the curevent
 
-  void* directory = gSystem->OpenDirectory(fDirName);
-  if (!directory) {
-    Error("Reset", "could not open directory %s", fDirName.Data());
-    return kFALSE;
-  }
+  void* directory = OpenDirectory();
+  if (!directory) return kFALSE;
 
   if (fStream) {
 #if defined(__HP_aCC) || defined(__DECCXX)
@@ -225,3 +249,33 @@ Bool_t AliRawReaderFile::Reset()
   return kTRUE;
 }
 
+Bool_t AliRawReaderFile::NextEvent()
+{
+// go to the next event directory
+
+  if (fEventIndex < -1) return kFALSE;
+
+  do {
+    TString dirName = fDirName + "/raw";
+    dirName += (fEventIndex + 1);
+    void* directory = gSystem->OpenDirectory(dirName);
+    if (!directory) return kFALSE;
+    gSystem->FreeDirectory(directory);
+
+    fEventIndex++;
+    Reset();
+  } while (!IsEventSelected());
+
+  fEventNumber++;
+
+  return kTRUE;
+}
+
+Bool_t AliRawReaderFile::RewindEvents()
+{
+// reset the event counter
+
+  if (fEventIndex >= 0)  fEventIndex = -1;
+  fEventNumber = -1;
+  return Reset();
+}