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) :
41 fEventIndex(eventNumber),
49 // create an object to read digits from the given event
50 // in the current directory
52 fDirectory = OpenDirectory();
54 fHeader = new AliRawDataHeader;
57 AliRawReaderFile::AliRawReaderFile(const char* dirName, Int_t eventNumber) :
58 fEventIndex(eventNumber),
66 // create an object to read digits from the given directory
68 fDirectory = OpenDirectory();
70 fHeader = new AliRawDataHeader;
73 AliRawReaderFile::AliRawReaderFile(const AliRawReaderFile& rawReader) :
74 AliRawReader(rawReader)
76 Fatal("AliRawReaderFile", "copy constructor not implemented");
79 AliRawReaderFile& AliRawReaderFile::operator = (const AliRawReaderFile&
82 Fatal("operator =", "assignment operator not implemented");
86 AliRawReaderFile::~AliRawReaderFile()
88 // close the input file
90 if (fDirectory) gSystem->FreeDirectory(fDirectory);
92 #if defined(__HP_aCC) || defined(__DECCXX)
93 if (fStream->rdbuf()->is_open()) fStream->close();
95 if (fStream->is_open()) fStream->close();
100 if (fBuffer) delete[] fBuffer;
104 TString AliRawReaderFile::GetDirName() const
106 // return the current directory name
108 TString dirName(fDirName);
109 if (fEventIndex >= 0) {
111 dirName += fEventIndex;
116 void* AliRawReaderFile::OpenDirectory()
118 // open and return the directory
120 TString dirName = GetDirName();
121 void* directory = gSystem->OpenDirectory(dirName);
123 Error("OpenDirectory", "could not open directory %s", dirName.Data());
128 Bool_t AliRawReaderFile::OpenNextFile()
130 // open the next file
131 // returns kFALSE if the current file is the last one
134 #if defined(__HP_aCC) || defined(__DECCXX)
135 if (fStream->rdbuf()->is_open()) fStream->close();
137 if (fStream->is_open()) fStream->close();
144 if (!fDirectory) return kFALSE;
146 while (entry = gSystem->GetDirEntry(fDirectory)) {
147 if (entry.IsNull()) return kFALSE;
148 if (!entry.EndsWith(".ddl")) continue;
149 char* fileName = gSystem->ConcatFileName(GetDirName(), entry);
151 fStream = new fstream(fileName, ios::binary|ios::in);
153 fStream = new fstream(fileName, ios::in);
158 if (!fStream) return kFALSE;
159 entry.Remove(0, entry.Last('_')+1);
160 entry.Remove(entry.Length()-4);
161 fEquipmentId = atoi(entry.Data());
162 #if defined(__HP_aCC) || defined(__DECCXX)
163 return (fStream->rdbuf()->is_open());
165 return (fStream->is_open());
170 Bool_t AliRawReaderFile::ReadHeader()
172 // read a data header at the current stream position
173 // returns kFALSE if the mini header could not be read
175 if (!fStream) return kFALSE;
177 if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
178 while (!fStream->read((char*) fHeader, sizeof(AliRawDataHeader))) {
179 if (!OpenNextFile()) return kFALSE;
181 if (fHeader->fSize != 0xFFFFFFFF) {
182 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
184 UInt_t currentPos = fStream->tellg();
185 fStream->seekg(0, ios::end);
186 fCount = UInt_t(fStream->tellg()) - currentPos;
187 fStream->seekg(currentPos);
189 } while (!IsSelected());
193 Bool_t AliRawReaderFile::ReadNextData(UChar_t*& data)
195 // reads the next payload at the current stream position
196 // returns kFALSE if the data could not be read
198 while (fCount == 0) {
199 if (!ReadHeader()) return kFALSE;
201 if (fBufferSize < fCount) {
202 if (fBuffer) delete[] fBuffer;
203 fBufferSize = Int_t(fCount*1.2);
204 fBuffer = new UChar_t[fBufferSize];
206 if (!fStream->read((char*) fBuffer, fCount)) {
207 Error("ReadNext", "could not read data!");
216 Bool_t AliRawReaderFile::ReadNext(UChar_t* data, Int_t size)
218 // reads the next block of data at the current stream position
219 // returns kFALSE if the data could not be read
221 if (!fStream->read((char*) data, size)) {
222 Error("ReadNext", "could not read data!");
230 Bool_t AliRawReaderFile::Reset()
232 // reset the current stream position to the first DDL file of the curevent
234 void* directory = OpenDirectory();
235 if (!directory) return kFALSE;
238 #if defined(__HP_aCC) || defined(__DECCXX)
239 if (fStream->rdbuf()->is_open()) fStream->close();
241 if (fStream->is_open()) fStream->close();
247 if (fDirectory) gSystem->FreeDirectory(fDirectory);
248 fDirectory = directory;
255 Bool_t AliRawReaderFile::NextEvent()
257 // go to the next event directory
259 if (fEventIndex < -1) return kFALSE;
262 TString dirName = fDirName + "/raw";
263 dirName += (fEventIndex + 1);
264 void* directory = gSystem->OpenDirectory(dirName);
265 if (!directory) return kFALSE;
266 gSystem->FreeDirectory(directory);
270 } while (!IsEventSelected());
275 Bool_t AliRawReaderFile::RewindEvents()
277 // reset the event counter
279 if (fEventIndex >= 0) fEventIndex = -1;