]>
Commit | Line | Data |
---|---|---|
04fa961a | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | /////////////////////////////////////////////////////////////////////////////// | |
17 | // | |
18 | // This is a class for reading a raw data file and providing | |
19 | // information about digits | |
20 | // | |
21 | /////////////////////////////////////////////////////////////////////////////// | |
22 | ||
23 | #include "AliRawReaderFile.h" | |
24 | ||
25 | ||
26 | ClassImp(AliRawReaderFile) | |
27 | ||
28 | ||
29 | AliRawReaderFile::AliRawReaderFile(const char* fileName, Bool_t addNumber) | |
30 | { | |
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 | |
33 | ||
34 | fFileName = fileName; | |
35 | if (!addNumber) { | |
36 | fFileNumber = -1; | |
37 | #ifndef __DECCXX | |
38 | fStream = new fstream(fileName, ios::binary|ios::in); | |
39 | #else | |
40 | fStream = new fstream(fileName, ios::in); | |
41 | #endif | |
42 | } else { | |
43 | fFileNumber = 0; | |
44 | fStream = NULL; | |
45 | OpenNextFile(); | |
46 | } | |
47 | fMiniHeader = new AliMiniHeader; | |
48 | fBuffer = NULL; | |
49 | fBufferSize = 0; | |
50 | } | |
51 | ||
42d20574 | 52 | AliRawReaderFile::AliRawReaderFile(const AliRawReaderFile& rawReader) : |
53 | AliRawReader(rawReader) | |
54 | { | |
55 | Fatal("AliRawReaderFile", "copy constructor not implemented"); | |
56 | } | |
57 | ||
58 | AliRawReaderFile& AliRawReaderFile::operator = (const AliRawReaderFile& | |
59 | /* rawReader */) | |
60 | { | |
61 | Fatal("operator =", "assignment operator not implemented"); | |
62 | return *this; | |
63 | } | |
64 | ||
04fa961a | 65 | AliRawReaderFile::~AliRawReaderFile() |
66 | { | |
67 | // close the input file | |
68 | ||
69 | if (fStream) { | |
70 | #if defined(__HP_aCC) || defined(__DECCXX) | |
71 | if (fStream->rdbuf()->is_open()) fStream->close(); | |
72 | #else | |
73 | if (fStream->is_open()) fStream->close(); | |
74 | #endif | |
75 | delete fStream; | |
76 | } | |
77 | delete fMiniHeader; | |
78 | if (fBuffer) delete[] fBuffer; | |
79 | } | |
80 | ||
81 | ||
82 | Bool_t AliRawReaderFile::OpenNextFile() | |
83 | { | |
42d20574 | 84 | // open the next file |
85 | // returns kFALSE if the current file is the last one | |
86 | ||
04fa961a | 87 | if (fStream) { |
88 | #if defined(__HP_aCC) || defined(__DECCXX) | |
89 | if (fStream->rdbuf()->is_open()) fStream->close(); | |
90 | #else | |
91 | if (fStream->is_open()) fStream->close(); | |
92 | #endif | |
93 | delete fStream; | |
94 | fStream = NULL; | |
95 | } | |
96 | if (fFileNumber < 0) return kFALSE; | |
97 | ||
98 | fFileNumber++; | |
99 | char fileName[256]; | |
100 | sprintf(fileName, "%s%d", fFileName.Data(), fFileNumber); | |
101 | #ifndef __DECCXX | |
102 | fStream = new fstream(fileName, ios::binary|ios::in); | |
103 | #else | |
104 | fStream = new fstream(fileName, ios::in); | |
105 | #endif | |
106 | #if defined(__HP_aCC) || defined(__DECCXX) | |
107 | return (fStream->rdbuf()->is_open()); | |
108 | #else | |
109 | return (fStream->is_open()); | |
110 | #endif | |
111 | } | |
112 | ||
113 | ||
114 | Bool_t AliRawReaderFile::ReadMiniHeader() | |
115 | { | |
116 | // read a mini header at the current stream position | |
117 | // returns kFALSE if the mini header could not be read | |
118 | ||
119 | if (!fStream) return kFALSE; | |
120 | do { | |
121 | if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount); | |
122 | while (!fStream->read((char*) fMiniHeader, sizeof(AliMiniHeader))) { | |
123 | if (!OpenNextFile()) return kFALSE; | |
124 | } | |
125 | CheckMiniHeader(); | |
126 | fCount = fMiniHeader->fSize; | |
127 | } while (!IsSelected()); | |
128 | return kTRUE; | |
129 | } | |
130 | ||
131 | Bool_t AliRawReaderFile::ReadNextData(UChar_t*& data) | |
132 | { | |
133 | // reads the next payload at the current stream position | |
134 | // returns kFALSE if the data could not be read | |
135 | ||
136 | while (fCount == 0) { | |
137 | if (!ReadMiniHeader()) return kFALSE; | |
138 | } | |
139 | if (fBufferSize < fCount) { | |
140 | if (fBuffer) delete[] fBuffer; | |
141 | fBufferSize = Int_t(fCount*1.2); | |
142 | fBuffer = new UChar_t[fBufferSize]; | |
143 | } | |
144 | if (!fStream->read((char*) fBuffer, fCount)) { | |
145 | Error("ReadNext", "could not read data!"); | |
146 | return kFALSE; | |
147 | } | |
148 | fCount = 0; | |
149 | ||
150 | data = fBuffer; | |
151 | return kTRUE; | |
152 | } | |
153 | ||
154 | Bool_t AliRawReaderFile::ReadNext(UChar_t* data, Int_t size) | |
155 | { | |
156 | // reads the next block of data at the current stream position | |
157 | // returns kFALSE if the data could not be read | |
158 | ||
159 | if (!fStream->read((char*) data, size)) { | |
160 | Error("ReadNext", "could not read data!"); | |
161 | return kFALSE; | |
162 | } | |
163 | fCount -= size; | |
164 | return kTRUE; | |
165 | } | |
166 | ||
167 | ||
168 | Bool_t AliRawReaderFile::Reset() | |
169 | { | |
170 | // reset the current stream position to the beginning of the file | |
171 | ||
172 | if ((fFileNumber > 0) && fStream) { | |
173 | #if defined(__HP_aCC) || defined(__DECCXX) | |
174 | if (fStream->rdbuf()->is_open()) fStream->close(); | |
175 | #else | |
176 | if (fStream->is_open()) fStream->close(); | |
177 | #endif | |
178 | delete fStream; | |
179 | fStream = NULL; | |
180 | fFileNumber = 0; | |
181 | } | |
182 | ||
183 | if (!fStream) { | |
184 | if (fFileNumber < 0) { | |
185 | #ifndef __DECCXX | |
186 | fStream = new fstream(fFileName, ios::binary|ios::in); | |
187 | #else | |
188 | fStream = new fstream(fFileName, ios::in); | |
189 | #endif | |
190 | } else { | |
191 | if (!OpenNextFile()) return kFALSE; | |
192 | } | |
193 | } | |
194 | ||
195 | if (!fStream || !fStream->rdbuf()->is_open()) return kFALSE; | |
196 | fStream->seekg(0); | |
197 | fCount = 0; | |
198 | return kTRUE; | |
199 | } | |
200 |