1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 ///////////////////////////////////////////////////////////////////////////////
18 // This is a class for reading a raw data file and providing
19 // information about digits
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "AliRawReaderFile.h"
26 ClassImp(AliRawReaderFile)
29 AliRawReaderFile::AliRawReaderFile(const char* fileName, Bool_t addNumber)
31 // create an object to read digits from the given input file(s)
32 // if addNumber is true, a number starting at 1 is appended to the file name
38 fStream = new fstream(fileName, ios::binary|ios::in);
40 fStream = new fstream(fileName, ios::in);
47 fMiniHeader = new AliMiniHeader;
52 AliRawReaderFile::AliRawReaderFile(const AliRawReaderFile& rawReader) :
53 AliRawReader(rawReader)
55 Fatal("AliRawReaderFile", "copy constructor not implemented");
58 AliRawReaderFile& AliRawReaderFile::operator = (const AliRawReaderFile&
61 Fatal("operator =", "assignment operator not implemented");
65 AliRawReaderFile::~AliRawReaderFile()
67 // close the input file
70 #if defined(__HP_aCC) || defined(__DECCXX)
71 if (fStream->rdbuf()->is_open()) fStream->close();
73 if (fStream->is_open()) fStream->close();
78 if (fBuffer) delete[] fBuffer;
82 Bool_t AliRawReaderFile::OpenNextFile()
85 // returns kFALSE if the current file is the last one
88 #if defined(__HP_aCC) || defined(__DECCXX)
89 if (fStream->rdbuf()->is_open()) fStream->close();
91 if (fStream->is_open()) fStream->close();
96 if (fFileNumber < 0) return kFALSE;
100 sprintf(fileName, "%s%d", fFileName.Data(), fFileNumber);
102 fStream = new fstream(fileName, ios::binary|ios::in);
104 fStream = new fstream(fileName, ios::in);
106 #if defined(__HP_aCC) || defined(__DECCXX)
107 return (fStream->rdbuf()->is_open());
109 return (fStream->is_open());
114 Bool_t AliRawReaderFile::ReadMiniHeader()
116 // read a mini header at the current stream position
117 // returns kFALSE if the mini header could not be read
119 if (!fStream) return kFALSE;
121 if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
122 while (!fStream->read((char*) fMiniHeader, sizeof(AliMiniHeader))) {
123 if (!OpenNextFile()) return kFALSE;
126 fCount = fMiniHeader->fSize;
127 } while (!IsSelected());
131 Bool_t AliRawReaderFile::ReadNextData(UChar_t*& data)
133 // reads the next payload at the current stream position
134 // returns kFALSE if the data could not be read
136 while (fCount == 0) {
137 if (!ReadMiniHeader()) return kFALSE;
139 if (fBufferSize < fCount) {
140 if (fBuffer) delete[] fBuffer;
141 fBufferSize = Int_t(fCount*1.2);
142 fBuffer = new UChar_t[fBufferSize];
144 if (!fStream->read((char*) fBuffer, fCount)) {
145 Error("ReadNext", "could not read data!");
154 Bool_t AliRawReaderFile::ReadNext(UChar_t* data, Int_t size)
156 // reads the next block of data at the current stream position
157 // returns kFALSE if the data could not be read
159 if (!fStream->read((char*) data, size)) {
160 Error("ReadNext", "could not read data!");
168 Bool_t AliRawReaderFile::Reset()
170 // reset the current stream position to the beginning of the file
172 if ((fFileNumber > 0) && fStream) {
173 #if defined(__HP_aCC) || defined(__DECCXX)
174 if (fStream->rdbuf()->is_open()) fStream->close();
176 if (fStream->is_open()) fStream->close();
184 if (fFileNumber < 0) {
186 fStream = new fstream(fFileName, ios::binary|ios::in);
188 fStream = new fstream(fFileName, ios::in);
191 if (!OpenNextFile()) return kFALSE;
195 if (!fStream || !fStream->rdbuf()->is_open()) return kFALSE;