]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RAW/AliRawReaderFile.cxx
A raw-data file and Tree size limit is increased to 20GB. Wherever is needed the...
[u/mrichter/AliRoot.git] / RAW / AliRawReaderFile.cxx
CommitLineData
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
bea6b2a4 16/* $Id$ */
17
04fa961a 18///////////////////////////////////////////////////////////////////////////////
bea6b2a4 19///
20/// This is a class for reading raw data files.
21///
22/// The files of one event are expected to be in one directory. The name
23/// of the directory is "raw" + the event number. Each file contains
24/// the raw data (with data header) of one DDL. The convention for the
25/// file names is "DET_#DDL.ddl". "DET" is the name of the detector and
26/// "#DDL" is the unique equipment ID.
27///
28/// The constructor of AliRawReaderFile takes the event number or the
29/// directory name as argument.
30///
04fa961a 31///////////////////////////////////////////////////////////////////////////////
32
33#include "AliRawReaderFile.h"
39f9963f 34#include <TSystem.h>
04fa961a 35
36
37ClassImp(AliRawReaderFile)
38
39
39f9963f 40AliRawReaderFile::AliRawReaderFile(Int_t eventNumber) :
dd9a70fe 41 fEventIndex(eventNumber),
42 fDirName("."),
39f9963f 43 fDirectory(NULL),
44 fStream(NULL),
45 fEquipmentId(-1),
46 fBuffer(NULL),
47 fBufferSize(0)
04fa961a 48{
39f9963f 49// create an object to read digits from the given event
dd9a70fe 50// in the current directory
04fa961a 51
dd9a70fe 52 fDirectory = OpenDirectory();
39f9963f 53 OpenNextFile();
54 fHeader = new AliRawDataHeader;
55}
56
dd9a70fe 57AliRawReaderFile::AliRawReaderFile(const char* dirName, Int_t eventNumber) :
58 fEventIndex(eventNumber),
39f9963f 59 fDirName(dirName),
60 fDirectory(NULL),
61 fStream(NULL),
62 fEquipmentId(-1),
63 fBuffer(NULL),
64 fBufferSize(0)
65{
66// create an object to read digits from the given directory
67
dd9a70fe 68 fDirectory = OpenDirectory();
39f9963f 69 OpenNextFile();
70 fHeader = new AliRawDataHeader;
04fa961a 71}
72
73AliRawReaderFile::~AliRawReaderFile()
74{
75// close the input file
76
39f9963f 77 if (fDirectory) gSystem->FreeDirectory(fDirectory);
04fa961a 78 if (fStream) {
79#if defined(__HP_aCC) || defined(__DECCXX)
80 if (fStream->rdbuf()->is_open()) fStream->close();
81#else
82 if (fStream->is_open()) fStream->close();
83#endif
84 delete fStream;
85 }
39f9963f 86 delete fHeader;
04fa961a 87 if (fBuffer) delete[] fBuffer;
88}
89
299738b9 90void AliRawReaderFile::RequireHeader(Bool_t required)
91{
92 // Reading of raw data in case of missing
93 // raw data header is not implemented for
94 // this class
95 if (!required)
96 Fatal("AliRawReaderFile","Reading of raw data without raw data header is not implemented !");
97
98 AliRawReader::RequireHeader(required);
99}
04fa961a 100
dd9a70fe 101TString AliRawReaderFile::GetDirName() const
102{
103// return the current directory name
104
105 TString dirName(fDirName);
106 if (fEventIndex >= 0) {
107 dirName += "/raw";
108 dirName += fEventIndex;
109 }
110 return dirName;
111}
112
113void* AliRawReaderFile::OpenDirectory()
114{
115// open and return the directory
116
117 TString dirName = GetDirName();
118 void* directory = gSystem->OpenDirectory(dirName);
119 if (!directory) {
120 Error("OpenDirectory", "could not open directory %s", dirName.Data());
121 }
122 return directory;
123}
124
04fa961a 125Bool_t AliRawReaderFile::OpenNextFile()
126{
42d20574 127// open the next file
128// returns kFALSE if the current file is the last one
129
04fa961a 130 if (fStream) {
131#if defined(__HP_aCC) || defined(__DECCXX)
132 if (fStream->rdbuf()->is_open()) fStream->close();
133#else
134 if (fStream->is_open()) fStream->close();
135#endif
136 delete fStream;
137 fStream = NULL;
39f9963f 138 fEquipmentId = -1;
04fa961a 139 }
04fa961a 140
39f9963f 141 if (!fDirectory) return kFALSE;
142 TString entry;
143 while (entry = gSystem->GetDirEntry(fDirectory)) {
144 if (entry.IsNull()) return kFALSE;
145 if (!entry.EndsWith(".ddl")) continue;
dd9a70fe 146 char* fileName = gSystem->ConcatFileName(GetDirName(), entry);
04fa961a 147#ifndef __DECCXX
39f9963f 148 fStream = new fstream(fileName, ios::binary|ios::in);
04fa961a 149#else
39f9963f 150 fStream = new fstream(fileName, ios::in);
04fa961a 151#endif
39f9963f 152 break;
153 }
154
155 if (!fStream) return kFALSE;
156 entry.Remove(0, entry.Last('_')+1);
157 entry.Remove(entry.Length()-4);
158 fEquipmentId = atoi(entry.Data());
04fa961a 159#if defined(__HP_aCC) || defined(__DECCXX)
160 return (fStream->rdbuf()->is_open());
161#else
162 return (fStream->is_open());
163#endif
164}
165
166
39f9963f 167Bool_t AliRawReaderFile::ReadHeader()
04fa961a 168{
39f9963f 169// read a data header at the current stream position
04fa961a 170// returns kFALSE if the mini header could not be read
171
172 if (!fStream) return kFALSE;
173 do {
174 if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
39f9963f 175 while (!fStream->read((char*) fHeader, sizeof(AliRawDataHeader))) {
04fa961a 176 if (!OpenNextFile()) return kFALSE;
177 }
39f9963f 178 if (fHeader->fSize != 0xFFFFFFFF) {
179 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
180 } else {
181 UInt_t currentPos = fStream->tellg();
182 fStream->seekg(0, ios::end);
183 fCount = UInt_t(fStream->tellg()) - currentPos;
184 fStream->seekg(currentPos);
185 }
04fa961a 186 } while (!IsSelected());
187 return kTRUE;
188}
189
190Bool_t AliRawReaderFile::ReadNextData(UChar_t*& data)
191{
192// reads the next payload at the current stream position
193// returns kFALSE if the data could not be read
194
195 while (fCount == 0) {
39f9963f 196 if (!ReadHeader()) return kFALSE;
04fa961a 197 }
198 if (fBufferSize < fCount) {
199 if (fBuffer) delete[] fBuffer;
200 fBufferSize = Int_t(fCount*1.2);
201 fBuffer = new UChar_t[fBufferSize];
202 }
203 if (!fStream->read((char*) fBuffer, fCount)) {
204 Error("ReadNext", "could not read data!");
205 return kFALSE;
206 }
207 fCount = 0;
208
209 data = fBuffer;
210 return kTRUE;
211}
212
213Bool_t AliRawReaderFile::ReadNext(UChar_t* data, Int_t size)
214{
215// reads the next block of data at the current stream position
216// returns kFALSE if the data could not be read
217
218 if (!fStream->read((char*) data, size)) {
219 Error("ReadNext", "could not read data!");
220 return kFALSE;
221 }
222 fCount -= size;
223 return kTRUE;
224}
225
226
227Bool_t AliRawReaderFile::Reset()
228{
dd9a70fe 229// reset the current stream position to the first DDL file of the curevent
04fa961a 230
dd9a70fe 231 void* directory = OpenDirectory();
232 if (!directory) return kFALSE;
39f9963f 233
234 if (fStream) {
04fa961a 235#if defined(__HP_aCC) || defined(__DECCXX)
236 if (fStream->rdbuf()->is_open()) fStream->close();
237#else
238 if (fStream->is_open()) fStream->close();
239#endif
240 delete fStream;
241 fStream = NULL;
04fa961a 242 }
243
39f9963f 244 if (fDirectory) gSystem->FreeDirectory(fDirectory);
245 fDirectory = directory;
04fa961a 246
39f9963f 247 OpenNextFile();
04fa961a 248 fCount = 0;
249 return kTRUE;
250}
251
dd9a70fe 252Bool_t AliRawReaderFile::NextEvent()
253{
254// go to the next event directory
255
256 if (fEventIndex < -1) return kFALSE;
257
258 do {
259 TString dirName = fDirName + "/raw";
260 dirName += (fEventIndex + 1);
261 void* directory = gSystem->OpenDirectory(dirName);
262 if (!directory) return kFALSE;
263 gSystem->FreeDirectory(directory);
264
265 fEventIndex++;
266 Reset();
267 } while (!IsEventSelected());
268
38cf12f3 269 fEventNumber++;
270
dd9a70fe 271 return kTRUE;
272}
273
274Bool_t AliRawReaderFile::RewindEvents()
275{
276// reset the event counter
277
278 if (fEventIndex >= 0) fEventIndex = -1;
38cf12f3 279 fEventNumber = -1;
dd9a70fe 280 return Reset();
281}