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"
27 ClassImp(AliRawReaderFile)
30 AliRawReaderFile::AliRawReaderFile(Int_t eventNumber) :
38 // create an object to read digits from the given event
40 fDirName += eventNumber;
41 fDirectory = gSystem->OpenDirectory(fDirName);
43 Error("AliRawReaderFile", "could not open directory %s", fDirName.Data());
46 fHeader = new AliRawDataHeader;
49 AliRawReaderFile::AliRawReaderFile(const char* dirName) :
57 // create an object to read digits from the given directory
59 fDirectory = gSystem->OpenDirectory(fDirName);
61 Error("AliRawReaderFile", "could not open directory %s", fDirName.Data());
64 fHeader = new AliRawDataHeader;
67 AliRawReaderFile::AliRawReaderFile(const AliRawReaderFile& rawReader) :
68 AliRawReader(rawReader)
70 Fatal("AliRawReaderFile", "copy constructor not implemented");
73 AliRawReaderFile& AliRawReaderFile::operator = (const AliRawReaderFile&
76 Fatal("operator =", "assignment operator not implemented");
80 AliRawReaderFile::~AliRawReaderFile()
82 // close the input file
84 if (fDirectory) gSystem->FreeDirectory(fDirectory);
86 #if defined(__HP_aCC) || defined(__DECCXX)
87 if (fStream->rdbuf()->is_open()) fStream->close();
89 if (fStream->is_open()) fStream->close();
94 if (fBuffer) delete[] fBuffer;
98 Bool_t AliRawReaderFile::OpenNextFile()
100 // open the next file
101 // returns kFALSE if the current file is the last one
104 #if defined(__HP_aCC) || defined(__DECCXX)
105 if (fStream->rdbuf()->is_open()) fStream->close();
107 if (fStream->is_open()) fStream->close();
114 if (!fDirectory) return kFALSE;
116 while (entry = gSystem->GetDirEntry(fDirectory)) {
117 if (entry.IsNull()) return kFALSE;
118 if (!entry.EndsWith(".ddl")) continue;
119 char* fileName = gSystem->ConcatFileName(fDirName, entry);
121 fStream = new fstream(fileName, ios::binary|ios::in);
123 fStream = new fstream(fileName, ios::in);
128 if (!fStream) return kFALSE;
129 entry.Remove(0, entry.Last('_')+1);
130 entry.Remove(entry.Length()-4);
131 fEquipmentId = atoi(entry.Data());
132 #if defined(__HP_aCC) || defined(__DECCXX)
133 return (fStream->rdbuf()->is_open());
135 return (fStream->is_open());
140 Bool_t AliRawReaderFile::ReadHeader()
142 // read a data header at the current stream position
143 // returns kFALSE if the mini header could not be read
145 if (!fStream) return kFALSE;
147 if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
148 while (!fStream->read((char*) fHeader, sizeof(AliRawDataHeader))) {
149 if (!OpenNextFile()) return kFALSE;
151 if (fHeader->fSize != 0xFFFFFFFF) {
152 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
154 UInt_t currentPos = fStream->tellg();
155 fStream->seekg(0, ios::end);
156 fCount = UInt_t(fStream->tellg()) - currentPos;
157 fStream->seekg(currentPos);
159 } while (!IsSelected());
163 Bool_t AliRawReaderFile::ReadNextData(UChar_t*& data)
165 // reads the next payload at the current stream position
166 // returns kFALSE if the data could not be read
168 while (fCount == 0) {
169 if (!ReadHeader()) return kFALSE;
171 if (fBufferSize < fCount) {
172 if (fBuffer) delete[] fBuffer;
173 fBufferSize = Int_t(fCount*1.2);
174 fBuffer = new UChar_t[fBufferSize];
176 if (!fStream->read((char*) fBuffer, fCount)) {
177 Error("ReadNext", "could not read data!");
186 Bool_t AliRawReaderFile::ReadNext(UChar_t* data, Int_t size)
188 // reads the next block of data at the current stream position
189 // returns kFALSE if the data could not be read
191 if (!fStream->read((char*) data, size)) {
192 Error("ReadNext", "could not read data!");
200 Bool_t AliRawReaderFile::Reset()
202 // reset the current stream position to the beginning of the file
204 void* directory = gSystem->OpenDirectory(fDirName);
206 Error("Reset", "could not open directory %s", fDirName.Data());
211 #if defined(__HP_aCC) || defined(__DECCXX)
212 if (fStream->rdbuf()->is_open()) fStream->close();
214 if (fStream->is_open()) fStream->close();
220 if (fDirectory) gSystem->FreeDirectory(fDirectory);
221 fDirectory = directory;