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()
54 // close the input file
57 #if defined(__HP_aCC) || defined(__DECCXX)
58 if (fStream->rdbuf()->is_open()) fStream->close();
60 if (fStream->is_open()) fStream->close();
65 if (fBuffer) delete[] fBuffer;
69 Bool_t AliRawReaderFile::OpenNextFile()
72 #if defined(__HP_aCC) || defined(__DECCXX)
73 if (fStream->rdbuf()->is_open()) fStream->close();
75 if (fStream->is_open()) fStream->close();
80 if (fFileNumber < 0) return kFALSE;
84 sprintf(fileName, "%s%d", fFileName.Data(), fFileNumber);
86 fStream = new fstream(fileName, ios::binary|ios::in);
88 fStream = new fstream(fileName, ios::in);
90 #if defined(__HP_aCC) || defined(__DECCXX)
91 return (fStream->rdbuf()->is_open());
93 return (fStream->is_open());
98 Bool_t AliRawReaderFile::ReadMiniHeader()
100 // read a mini header at the current stream position
101 // returns kFALSE if the mini header could not be read
103 if (!fStream) return kFALSE;
105 if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
106 while (!fStream->read((char*) fMiniHeader, sizeof(AliMiniHeader))) {
107 if (!OpenNextFile()) return kFALSE;
110 fCount = fMiniHeader->fSize;
111 } while (!IsSelected());
115 Bool_t AliRawReaderFile::ReadNextData(UChar_t*& data)
117 // reads the next payload at the current stream position
118 // returns kFALSE if the data could not be read
120 while (fCount == 0) {
121 if (!ReadMiniHeader()) return kFALSE;
123 if (fBufferSize < fCount) {
124 if (fBuffer) delete[] fBuffer;
125 fBufferSize = Int_t(fCount*1.2);
126 fBuffer = new UChar_t[fBufferSize];
128 if (!fStream->read((char*) fBuffer, fCount)) {
129 Error("ReadNext", "could not read data!");
138 Bool_t AliRawReaderFile::ReadNext(UChar_t* data, Int_t size)
140 // reads the next block of data at the current stream position
141 // returns kFALSE if the data could not be read
143 if (!fStream->read((char*) data, size)) {
144 Error("ReadNext", "could not read data!");
152 Bool_t AliRawReaderFile::Reset()
154 // reset the current stream position to the beginning of the file
156 if ((fFileNumber > 0) && fStream) {
157 #if defined(__HP_aCC) || defined(__DECCXX)
158 if (fStream->rdbuf()->is_open()) fStream->close();
160 if (fStream->is_open()) fStream->close();
168 if (fFileNumber < 0) {
170 fStream = new fstream(fFileName, ios::binary|ios::in);
172 fStream = new fstream(fFileName, ios::in);
175 if (!OpenNextFile()) return kFALSE;
179 if (!fStream || !fStream->rdbuf()->is_open()) return kFALSE;