From a6e7b125bb402a34531276676022bb0f534aa87c Mon Sep 17 00:00:00 2001 From: hristov Date: Wed, 25 Jun 2003 16:05:06 +0000 Subject: [PATCH] New class for raw data processing (T.Kuhr) --- STEER/AliRawReader.cxx | 137 +++++++++++++++++++++++++++++++++++++++++ STEER/AliRawReader.h | 47 ++++++++++++++ STEER/STEERLinkDef.h | 1 + STEER/libSTEER.pkg | 3 +- 4 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 STEER/AliRawReader.cxx create mode 100644 STEER/AliRawReader.h diff --git a/STEER/AliRawReader.cxx b/STEER/AliRawReader.cxx new file mode 100644 index 00000000000..88ef1890ced --- /dev/null +++ b/STEER/AliRawReader.cxx @@ -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 index 00000000000..d84fc4c5a03 --- /dev/null +++ b/STEER/AliRawReader.h @@ -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 +#include + + +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 diff --git a/STEER/STEERLinkDef.h b/STEER/STEERLinkDef.h index 8b6c4195d3e..fc65cb19be0 100644 --- a/STEER/STEERLinkDef.h +++ b/STEER/STEERLinkDef.h @@ -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 diff --git a/STEER/libSTEER.pkg b/STEER/libSTEER.pkg index 27b678d5b45..175fbba1422 100644 --- a/STEER/libSTEER.pkg +++ b/STEER/libSTEER.pkg @@ -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) -- 2.31.1