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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 /// This is a class for reading raw data files.
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.
28 /// The constructor of AliRawReaderFile takes the event number or the
29 /// directory name as argument.
31 ///////////////////////////////////////////////////////////////////////////////
33 #include "AliRawReaderFile.h"
37 ClassImp(AliRawReaderFile)
40 AliRawReaderFile::AliRawReaderFile(Int_t eventNumber) :
48 // create an object to read digits from the given event
50 fDirName += eventNumber;
51 fDirectory = gSystem->OpenDirectory(fDirName);
53 Error("AliRawReaderFile", "could not open directory %s", fDirName.Data());
56 fHeader = new AliRawDataHeader;
59 AliRawReaderFile::AliRawReaderFile(const char* dirName) :
67 // create an object to read digits from the given directory
69 fDirectory = gSystem->OpenDirectory(fDirName);
71 Error("AliRawReaderFile", "could not open directory %s", fDirName.Data());
74 fHeader = new AliRawDataHeader;
77 AliRawReaderFile::AliRawReaderFile(const AliRawReaderFile& rawReader) :
78 AliRawReader(rawReader)
80 Fatal("AliRawReaderFile", "copy constructor not implemented");
83 AliRawReaderFile& AliRawReaderFile::operator = (const AliRawReaderFile&
86 Fatal("operator =", "assignment operator not implemented");
90 AliRawReaderFile::~AliRawReaderFile()
92 // close the input file
94 if (fDirectory) gSystem->FreeDirectory(fDirectory);
96 #if defined(__HP_aCC) || defined(__DECCXX)
97 if (fStream->rdbuf()->is_open()) fStream->close();
99 if (fStream->is_open()) fStream->close();
104 if (fBuffer) delete[] fBuffer;
108 Bool_t AliRawReaderFile::OpenNextFile()
110 // open the next file
111 // returns kFALSE if the current file is the last one
114 #if defined(__HP_aCC) || defined(__DECCXX)
115 if (fStream->rdbuf()->is_open()) fStream->close();
117 if (fStream->is_open()) fStream->close();
124 if (!fDirectory) return kFALSE;
126 while (entry = gSystem->GetDirEntry(fDirectory)) {
127 if (entry.IsNull()) return kFALSE;
128 if (!entry.EndsWith(".ddl")) continue;
129 char* fileName = gSystem->ConcatFileName(fDirName, entry);
131 fStream = new fstream(fileName, ios::binary|ios::in);
133 fStream = new fstream(fileName, ios::in);
138 if (!fStream) return kFALSE;
139 entry.Remove(0, entry.Last('_')+1);
140 entry.Remove(entry.Length()-4);
141 fEquipmentId = atoi(entry.Data());
142 #if defined(__HP_aCC) || defined(__DECCXX)
143 return (fStream->rdbuf()->is_open());
145 return (fStream->is_open());
150 Bool_t AliRawReaderFile::ReadHeader()
152 // read a data header at the current stream position
153 // returns kFALSE if the mini header could not be read
155 if (!fStream) return kFALSE;
157 if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
158 while (!fStream->read((char*) fHeader, sizeof(AliRawDataHeader))) {
159 if (!OpenNextFile()) return kFALSE;
161 if (fHeader->fSize != 0xFFFFFFFF) {
162 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
164 UInt_t currentPos = fStream->tellg();
165 fStream->seekg(0, ios::end);
166 fCount = UInt_t(fStream->tellg()) - currentPos;
167 fStream->seekg(currentPos);
169 } while (!IsSelected());
173 Bool_t AliRawReaderFile::ReadNextData(UChar_t*& data)
175 // reads the next payload at the current stream position
176 // returns kFALSE if the data could not be read
178 while (fCount == 0) {
179 if (!ReadHeader()) return kFALSE;
181 if (fBufferSize < fCount) {
182 if (fBuffer) delete[] fBuffer;
183 fBufferSize = Int_t(fCount*1.2);
184 fBuffer = new UChar_t[fBufferSize];
186 if (!fStream->read((char*) fBuffer, fCount)) {
187 Error("ReadNext", "could not read data!");
196 Bool_t AliRawReaderFile::ReadNext(UChar_t* data, Int_t size)
198 // reads the next block of data at the current stream position
199 // returns kFALSE if the data could not be read
201 if (!fStream->read((char*) data, size)) {
202 Error("ReadNext", "could not read data!");
210 Bool_t AliRawReaderFile::Reset()
212 // reset the current stream position to the beginning of the file
214 void* directory = gSystem->OpenDirectory(fDirName);
216 Error("Reset", "could not open directory %s", fDirName.Data());
221 #if defined(__HP_aCC) || defined(__DECCXX)
222 if (fStream->rdbuf()->is_open()) fStream->close();
224 if (fStream->is_open()) fStream->close();
230 if (fDirectory) gSystem->FreeDirectory(fDirectory);
231 fDirectory = directory;