]>
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 | ||
240d63be | 12 | #include "AliL3RootTypes.h" |
13 | #include "AliL3StandardIncludes.h" | |
14 | #include "AliL3Logging.h" | |
15 | ||
16 | #include "AliL3DDLRawReaderFile.h" | |
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 | ||
37 | /** \class AliL3DDLRawReaderFile | |
38 | <pre> | |
39 | //_____________________________________________________________ | |
40 | // AliL3DDLRawReaderFile (taken from the offline AliROOT code, | |
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 | ||
240d63be | 48 | ClassImp(AliL3DDLRawReaderFile) |
49 | ||
240d63be | 50 | AliL3DDLRawReaderFile::AliL3DDLRawReaderFile(const Char_t* name, Bool_t addnum) |
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; | |
59 | fStream = new fstream(fFileName, ios::binary|ios::in); | |
60 | } else { | |
61 | fFileNumber = 0; | |
62 | fStream = NULL; | |
63 | OpenNextFile(); | |
64 | } | |
65 | fMiniHeader = new AliL3DDLMiniHeader; | |
66 | fBuffer = NULL; | |
67 | fBufferSize = 0; | |
68 | } | |
69 | ||
70 | AliL3DDLRawReaderFile::~AliL3DDLRawReaderFile() | |
71 | { | |
72 | // close the input file | |
73 | if(fFileName) delete fFileName; | |
74 | ||
75 | if (fStream) { | |
76 | if (fStream->is_open()) fStream->close(); | |
77 | delete fStream; | |
78 | } | |
79 | delete fMiniHeader; | |
80 | if (fBuffer) delete[] fBuffer; | |
81 | } | |
82 | ||
83 | Bool_t AliL3DDLRawReaderFile::OpenNextFile() | |
84 | { | |
85 | if (fStream) { | |
86 | if (fStream->is_open()) fStream->close(); | |
87 | delete fStream; | |
88 | fStream = NULL; | |
89 | } | |
90 | if (fFileNumber < 0) { | |
91 | LOG(AliL3Log::kError,"AliL3DDLRawReaderFile::OpenNextFile","File") | |
92 | <<"Could not open file, file number is negative."<<ENDLOG; | |
93 | return kFALSE; | |
94 | } | |
95 | ||
96 | fFileNumber++; | |
97 | Char_t fileName[1024]; | |
98 | sprintf(fileName, "%s%d", fFileName, fFileNumber); | |
99 | ||
100 | fStream = new fstream(fileName, ios::binary|ios::in); | |
101 | return (fStream->is_open()); | |
102 | } | |
103 | ||
104 | Bool_t AliL3DDLRawReaderFile::ReadMiniHeader() | |
105 | { | |
106 | // read a mini header at the current stream position | |
107 | // returns kFALSE if the mini header could not be read | |
108 | ||
109 | if (!fStream) return kFALSE; | |
110 | do { | |
111 | if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount); | |
112 | while (!fStream->read((Char_t*) fMiniHeader, sizeof(AliL3DDLMiniHeader))) { | |
113 | if (!OpenNextFile()) return kFALSE; | |
114 | } | |
115 | //cout << fMiniHeader->fSize << " " << fMiniHeader->fDetectorID << " " << fMiniHeader->fVersion << " " << fMiniHeader->fCompressionFlag << " " << fMiniHeader->fDDLID << endl; | |
116 | //cout << "loop here " << (Int_t)fMiniHeader->fDDLID<< endl; | |
117 | CheckMiniHeader(); | |
118 | fCount = fMiniHeader->fSize; | |
119 | } while (!IsSelected()); | |
120 | return kTRUE; | |
121 | } | |
122 | ||
123 | Bool_t AliL3DDLRawReaderFile::ReadNextData(UChar_t*& data) | |
124 | { | |
125 | // reads the next payload at the current stream position | |
126 | // returns kFALSE if the data could not be read | |
127 | ||
128 | while (fCount == 0) { | |
129 | if (!ReadMiniHeader()) return kFALSE; | |
130 | } | |
131 | if (fBufferSize < fCount) { | |
132 | if (fBuffer) delete[] fBuffer; | |
133 | fBufferSize = Int_t(fCount*1.2); | |
134 | fBuffer = new UChar_t[fBufferSize]; | |
135 | } | |
136 | if (!fStream->read((Char_t*) fBuffer, fCount)) { | |
137 | LOG(AliL3Log::kError,"AliL3DDLRawReaderFile::ReadNextData","Data") | |
138 | <<"Could not read next data!"<<ENDLOG; | |
139 | return kFALSE; | |
140 | } | |
141 | fCount = 0; | |
142 | ||
143 | data = fBuffer; | |
144 | return kTRUE; | |
145 | } | |
146 | ||
147 | Bool_t AliL3DDLRawReaderFile::ReadNext(UChar_t* data, Int_t size) | |
148 | { | |
149 | // reads the next block of data at the current stream position | |
150 | // returns kFALSE if the data could not be read | |
151 | ||
152 | if (!fStream->read((Char_t*) data, size)) { | |
153 | LOG(AliL3Log::kError,"AliL3DDLRawReaderFile::ReadNext","Data") | |
154 | <<"Could not read next data!"<<ENDLOG; | |
155 | return kFALSE; | |
156 | } | |
157 | fCount -= size; | |
158 | return kTRUE; | |
159 | } | |
160 | ||
161 | Bool_t AliL3DDLRawReaderFile::Reset() | |
162 | { | |
163 | // reset the current stream position to the beginning of the file | |
164 | ||
165 | if ((fFileNumber > 0) && fStream) { | |
166 | if (fStream->is_open()) fStream->close(); | |
167 | delete fStream; | |
168 | fStream = NULL; | |
169 | fFileNumber = 0; | |
170 | } | |
171 | ||
172 | if (!fStream) { | |
173 | if (fFileNumber < 0) { | |
174 | fStream = new fstream(fFileName, ios::binary|ios::in); | |
175 | } else { | |
176 | if (!OpenNextFile()){ | |
177 | LOG(AliL3Log::kError,"AliL3DDLRawReaderFile::Reset","Data") | |
178 | <<"Could not reset data stream!"<<ENDLOG; | |
179 | return kFALSE; | |
180 | } | |
181 | } | |
182 | } | |
183 | ||
184 | if (!fStream || !fStream->rdbuf()->is_open()) return kFALSE; | |
185 | fStream->seekg(0); | |
186 | fCount = 0; | |
187 | return kTRUE; | |
188 | } |