]>
Commit | Line | Data |
---|---|---|
240d63be | 1 | // @(#) $Id$ |
2 | ||
3 | // Author: Constantin Loizides <mailto:loizides@ikf.uni-frankfurt.de> | |
4 | //*-- Copyright © ALICE HLT Group | |
5 | ||
de3c3890 | 6 | #ifdef use_root |
7 | #include <Riostream.h> | |
8 | #else | |
9 | #include <iostream.h> | |
10 | #endif | |
11 | ||
4aa41877 | 12 | #include "AliHLTRootTypes.h" |
13 | #include "AliHLTStandardIncludes.h" | |
14 | #include "AliHLTLogging.h" | |
240d63be | 15 | |
4aa41877 | 16 | #include "AliHLTDDLRawReaderFile.h" |
240d63be | 17 | |
0bd0c1ef | 18 | #if __GNUC__ == 3 |
19 | using namespace std; | |
20 | #endif | |
21 | ||
240d63be | 22 | /************************************************************************** |
23 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
24 | * * | |
25 | * Author: The ALICE Off-line Project. * | |
26 | * Contributors are mentioned in the code where appropriate. * | |
27 | * * | |
28 | * Permission to use, copy, modify and distribute this software and its * | |
29 | * documentation strictly for non-commercial purposes is hereby granted * | |
30 | * without fee, provided that the above copyright notice appears in all * | |
31 | * copies and that both the copyright notice and this permission notice * | |
32 | * appear in the supporting documentation. The authors make no claims * | |
33 | * about the suitability of this software for any purpose. It is * | |
34 | * provided "as is" without express or implied warranty. * | |
35 | **************************************************************************/ | |
36 | ||
4aa41877 | 37 | /** \class AliHLTDDLRawReaderFile |
240d63be | 38 | <pre> |
39 | //_____________________________________________________________ | |
4aa41877 | 40 | // AliHLTDDLRawReaderFile (taken from the offline AliROOT code, |
240d63be | 41 | // original authors: D.Favretto and A.K.Mohanty) |
42 | // | |
43 | // This is the base class for reading ddl raw data | |
44 | // and providing information about digits | |
45 | </pre> | |
46 | */ | |
47 | ||
4aa41877 | 48 | ClassImp(AliHLTDDLRawReaderFile) |
240d63be | 49 | |
4aa41877 | 50 | AliHLTDDLRawReaderFile::AliHLTDDLRawReaderFile(const Char_t* name, Bool_t addnum) |
240d63be | 51 | { |
52 | // create an object to read digits from the given input file(s) | |
53 | // if addNumber is true, a number starting at 1 is appended to the file name | |
54 | ||
55 | fFileName = new Char_t[1024]; | |
56 | strcpy(fFileName,name); | |
57 | if (!addnum) { | |
58 | fFileNumber = -1; | |
d349eb82 | 59 | #ifndef __DECCXX |
240d63be | 60 | fStream = new fstream(fFileName, ios::binary|ios::in); |
d349eb82 | 61 | #else |
62 | fStream = new fstream(fFileName, ios::in); | |
63 | #endif | |
240d63be | 64 | } else { |
65 | fFileNumber = 0; | |
66 | fStream = NULL; | |
67 | OpenNextFile(); | |
68 | } | |
4aa41877 | 69 | fMiniHeader = new AliHLTDDLMiniHeader; |
240d63be | 70 | fBuffer = NULL; |
71 | fBufferSize = 0; | |
72 | } | |
73 | ||
4aa41877 | 74 | AliHLTDDLRawReaderFile::~AliHLTDDLRawReaderFile() |
240d63be | 75 | { |
76 | // close the input file | |
77 | if(fFileName) delete fFileName; | |
78 | ||
79 | if (fStream) { | |
d349eb82 | 80 | #if defined(__HP_aCC) || defined(__DECCXX) |
81 | if (fStream->rdbuf()->is_open()) fStream->close(); | |
82 | #else | |
240d63be | 83 | if (fStream->is_open()) fStream->close(); |
d349eb82 | 84 | #endif |
240d63be | 85 | delete fStream; |
86 | } | |
87 | delete fMiniHeader; | |
88 | if (fBuffer) delete[] fBuffer; | |
89 | } | |
90 | ||
4aa41877 | 91 | Bool_t AliHLTDDLRawReaderFile::OpenNextFile() |
240d63be | 92 | { |
93 | if (fStream) { | |
d349eb82 | 94 | #if defined(__HP_aCC) || defined(__DECCXX) |
95 | if (fStream->rdbuf()->is_open()) fStream->close(); | |
96 | #else | |
240d63be | 97 | if (fStream->is_open()) fStream->close(); |
d349eb82 | 98 | #endif |
240d63be | 99 | delete fStream; |
100 | fStream = NULL; | |
101 | } | |
102 | if (fFileNumber < 0) { | |
4aa41877 | 103 | LOG(AliHLTLog::kError,"AliHLTDDLRawReaderFile::OpenNextFile","File") |
240d63be | 104 | <<"Could not open file, file number is negative."<<ENDLOG; |
105 | return kFALSE; | |
106 | } | |
107 | ||
108 | fFileNumber++; | |
109 | Char_t fileName[1024]; | |
110 | sprintf(fileName, "%s%d", fFileName, fFileNumber); | |
111 | ||
d349eb82 | 112 | #ifndef __DECCXX |
240d63be | 113 | fStream = new fstream(fileName, ios::binary|ios::in); |
d349eb82 | 114 | #else |
115 | fStream = new fstream(fileName, ios::in); | |
116 | #endif | |
117 | #if defined(__HP_aCC) || defined(__DECCXX) | |
118 | return (fStream->rdbuf()->is_open()); | |
119 | #else | |
240d63be | 120 | return (fStream->is_open()); |
d349eb82 | 121 | #endif |
240d63be | 122 | } |
123 | ||
4aa41877 | 124 | Bool_t AliHLTDDLRawReaderFile::ReadMiniHeader() |
240d63be | 125 | { |
126 | // read a mini header at the current stream position | |
127 | // returns kFALSE if the mini header could not be read | |
128 | ||
129 | if (!fStream) return kFALSE; | |
130 | do { | |
131 | if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount); | |
4aa41877 | 132 | while (!fStream->read((Char_t*) fMiniHeader, sizeof(AliHLTDDLMiniHeader))) { |
240d63be | 133 | if (!OpenNextFile()) return kFALSE; |
134 | } | |
135 | //cout << fMiniHeader->fSize << " " << fMiniHeader->fDetectorID << " " << fMiniHeader->fVersion << " " << fMiniHeader->fCompressionFlag << " " << fMiniHeader->fDDLID << endl; | |
136 | //cout << "loop here " << (Int_t)fMiniHeader->fDDLID<< endl; | |
137 | CheckMiniHeader(); | |
138 | fCount = fMiniHeader->fSize; | |
139 | } while (!IsSelected()); | |
140 | return kTRUE; | |
141 | } | |
142 | ||
4aa41877 | 143 | Bool_t AliHLTDDLRawReaderFile::ReadNextData(UChar_t*& data) |
240d63be | 144 | { |
145 | // reads the next payload at the current stream position | |
146 | // returns kFALSE if the data could not be read | |
147 | ||
148 | while (fCount == 0) { | |
149 | if (!ReadMiniHeader()) return kFALSE; | |
150 | } | |
151 | if (fBufferSize < fCount) { | |
152 | if (fBuffer) delete[] fBuffer; | |
153 | fBufferSize = Int_t(fCount*1.2); | |
154 | fBuffer = new UChar_t[fBufferSize]; | |
155 | } | |
156 | if (!fStream->read((Char_t*) fBuffer, fCount)) { | |
4aa41877 | 157 | LOG(AliHLTLog::kError,"AliHLTDDLRawReaderFile::ReadNextData","Data") |
240d63be | 158 | <<"Could not read next data!"<<ENDLOG; |
159 | return kFALSE; | |
160 | } | |
161 | fCount = 0; | |
162 | ||
163 | data = fBuffer; | |
164 | return kTRUE; | |
165 | } | |
166 | ||
4aa41877 | 167 | Bool_t AliHLTDDLRawReaderFile::ReadNext(UChar_t* data, Int_t size) |
240d63be | 168 | { |
169 | // reads the next block of data at the current stream position | |
170 | // returns kFALSE if the data could not be read | |
171 | ||
172 | if (!fStream->read((Char_t*) data, size)) { | |
4aa41877 | 173 | LOG(AliHLTLog::kError,"AliHLTDDLRawReaderFile::ReadNext","Data") |
240d63be | 174 | <<"Could not read next data!"<<ENDLOG; |
175 | return kFALSE; | |
176 | } | |
177 | fCount -= size; | |
178 | return kTRUE; | |
179 | } | |
180 | ||
4aa41877 | 181 | Bool_t AliHLTDDLRawReaderFile::Reset() |
240d63be | 182 | { |
183 | // reset the current stream position to the beginning of the file | |
184 | ||
185 | if ((fFileNumber > 0) && fStream) { | |
d349eb82 | 186 | #if defined(__HP_aCC) || defined(__DECCXX) |
187 | if (fStream->rdbuf()->is_open()) fStream->close(); | |
188 | #else | |
240d63be | 189 | if (fStream->is_open()) fStream->close(); |
d349eb82 | 190 | #endif |
240d63be | 191 | delete fStream; |
192 | fStream = NULL; | |
193 | fFileNumber = 0; | |
194 | } | |
195 | ||
196 | if (!fStream) { | |
197 | if (fFileNumber < 0) { | |
d349eb82 | 198 | #ifndef __DECCXX |
240d63be | 199 | fStream = new fstream(fFileName, ios::binary|ios::in); |
d349eb82 | 200 | #else |
201 | fStream = new fstream(fFileName, ios::in); | |
202 | #endif | |
240d63be | 203 | } else { |
204 | if (!OpenNextFile()){ | |
4aa41877 | 205 | LOG(AliHLTLog::kError,"AliHLTDDLRawReaderFile::Reset","Data") |
240d63be | 206 | <<"Could not reset data stream!"<<ENDLOG; |
207 | return kFALSE; | |
208 | } | |
209 | } | |
210 | } | |
211 | ||
212 | if (!fStream || !fStream->rdbuf()->is_open()) return kFALSE; | |
213 | fStream->seekg(0); | |
214 | fCount = 0; | |
215 | return kTRUE; | |
216 | } |