New class for raw data processing (T.Kuhr)
authorhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 25 Jun 2003 16:05:06 +0000 (16:05 +0000)
committerhristov <hristov@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 25 Jun 2003 16:05:06 +0000 (16:05 +0000)
STEER/AliRawReader.cxx [new file with mode: 0644]
STEER/AliRawReader.h [new file with mode: 0644]
STEER/STEERLinkDef.h
STEER/libSTEER.pkg

diff --git a/STEER/AliRawReader.cxx b/STEER/AliRawReader.cxx
new file mode 100644 (file)
index 0000000..88ef189
--- /dev/null
@@ -0,0 +1,137 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// This is the base class for reading a raw data file and providing
+// information about digits
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include "AliRawReader.h"
+
+ClassImp(AliRawReader)
+
+
+AliRawReader::AliRawReader(const char* fileName, Bool_t addNumber)
+{
+// create an object to read digits from the given input file(s)
+// if addNumber is true, a number starting at 1 is appended to the file name
+
+  fFileName = fileName;
+  if (!addNumber) {
+    fFileNumber = -1;
+    fStream = new fstream(fileName, ios::binary|ios::in);
+  } else {
+    fFileNumber = 0;
+    fStream = NULL;
+    OpenNextFile();
+  }
+  fCount = 0;
+}
+
+AliRawReader::~AliRawReader()
+{
+// close the input file
+
+  if (fStream) {
+    if (fStream->is_open()) fStream->close();
+    delete fStream;
+  }
+}
+
+
+Bool_t AliRawReader::OpenNextFile()
+{
+  if (fStream) {
+    if (fStream->is_open()) fStream->close();
+    delete fStream;
+    fStream = NULL;
+  }
+  if (fFileNumber < 0) return kFALSE;
+
+  fFileNumber++;
+  char fileName[256];
+  sprintf(fileName, "%s%d", fFileName, fFileNumber);
+  fStream = new fstream(fileName, ios::binary|ios::in);
+  return (fStream->is_open());
+}
+
+
+Bool_t AliRawReader::ReadMiniHeader()
+{
+// read a mini header at the current stream position
+// returns kFALSE if the mini header could not be read
+
+  if (!fStream) return kFALSE;
+  while (!fStream->read((char*) &fMiniHeader, sizeof(fMiniHeader))) {
+    if (!OpenNextFile()) return kFALSE;
+  }
+  if ((fMiniHeader.fMagicWord[2] != 0x12) ||
+      (fMiniHeader.fMagicWord[1] != 0x34) ||
+      (fMiniHeader.fMagicWord[0] != 0x56))
+    Error("ReadMiniHeader", "wrong magic word!");
+  fCount = fMiniHeader.fSize;
+  return kTRUE;
+}
+
+Bool_t AliRawReader::ReadNextInt(UInt_t& data)
+{
+// reads the next 4 bytes at the current stream position
+// returns kFALSE if the data not be read
+
+  while (fCount == 0) {
+    if (!ReadMiniHeader()) return kFALSE;
+  }
+  if (!fStream->read((char*) &data, sizeof(data))) {
+    Error("ReadNextInt", "could not read data!");
+    return kFALSE;
+  }
+  fCount -= sizeof(data);
+  return kTRUE;
+}
+
+Bool_t AliRawReader::ReadNextShort(UShort_t& data)
+{
+// reads the next 2 bytes at the current stream position
+// returns kFALSE if the data not be read
+
+  while (fCount == 0) {
+    if (!ReadMiniHeader()) return kFALSE;
+  }
+  if (!fStream->read((char*) &data, sizeof(data))) {
+    Error("ReadNextShort", "could not read data!");
+    return kFALSE;
+  }
+  fCount -= sizeof(data);
+  return kTRUE;
+}
+
+Bool_t AliRawReader::ReadNextChar(UChar_t& data)
+{
+// reads the next 1 byte at the current stream position
+// returns kFALSE if the data not be read
+
+  while (fCount == 0) {
+    if (!ReadMiniHeader()) return kFALSE;
+  }
+  if (!fStream->read((char*) &data, sizeof(data))) {
+    Error("ReadNextChar", "could not read data!");
+    return kFALSE;
+  }
+  fCount -= sizeof(data);
+  return kTRUE;
+}
+
diff --git a/STEER/AliRawReader.h b/STEER/AliRawReader.h
new file mode 100644 (file)
index 0000000..d84fc4c
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef ALIRAWREADER_H
+#define ALIRAWREADER_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+#include <TObject.h>
+#include <Riostream.h>
+
+
+struct AliMiniHeader {
+  UInt_t    fSize;
+  UChar_t   fDetectorID;
+  UChar_t   fMagicWord[3];
+  UChar_t   fVersion;
+  UChar_t   fCompressionFlag;
+  UShort_t  fDDLID;
+};
+
+class AliRawReader: public TObject {
+  public :
+    AliRawReader(const char* fileName, Bool_t addNumber = kTRUE);
+    virtual ~AliRawReader();
+
+    inline Int_t     GetDetectorID() const {return fMiniHeader.fDetectorID;};
+    inline Int_t     GetDDLID() const {return fMiniHeader.fDDLID;};
+    inline Int_t     GetVersion() const {return fMiniHeader.fVersion;};
+    inline Bool_t    IsCompressed() const {return fMiniHeader.fCompressionFlag != 0;};
+
+    Bool_t           ReadNextInt(UInt_t& data);
+    Bool_t           ReadNextShort(UShort_t& data);
+    Bool_t           ReadNextChar(UChar_t& data);
+
+  protected :
+    Bool_t           OpenNextFile();
+
+    Bool_t           ReadMiniHeader();
+
+    const char*      fFileName;    // name of input files
+    Int_t            fFileNumber;  // number of current input file
+    fstream*         fStream;      // stream of raw digits
+    AliMiniHeader    fMiniHeader;  // current mini header
+    Int_t            fCount;       // counter of bytes to be read for current DDL
+
+    ClassDef(AliRawReader, 0) // base class for reading raw digits
+};
+
+#endif
index 8b6c4195d3e04990e4727663e21abf444dc3c829..fc65cb19be0adda5aafa8900e16ee75d8d75acd4 100644 (file)
@@ -65,6 +65,7 @@
 #pragma link C++ class  AliCollisionGeometry+;
 #pragma link C++ class  AliMemoryWatcher+;
 #pragma link C++ class  AliBarrelTrack+;
+#pragma link C++ class  AliRawReader+;
 #endif
 
 
index 27b678d5b453956d2444cb555c1738002b79e224..175fbba1422d85c73f0f36438e3f909515389a03 100644 (file)
@@ -16,7 +16,8 @@ AliMergeCombi.cxx AliMagFMaps.cxx AliFieldMap.cxx \
 AliGausCorr.cxx AliTrackReference.cxx AliESD.cxx \
 AliTrackMap.cxx AliTrackMapper.cxx AliCollisionGeometry.cxx \
 AliMemoryWatcher.cxx AliBarrelTrack.cxx \
-AliESDtrack.cxx AliESDvertex.cxx AliESDpid.cxx
+AliESDtrack.cxx AliESDvertex.cxx AliESDpid.cxx \
+AliRawReader.cxx
 
 HDRS:= $(SRCS:.cxx=.h)