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()
75 // close the input file
77 if (fDirectory) gSystem->FreeDirectory(fDirectory);
79 #if defined(__HP_aCC) || defined(__DECCXX)
80 if (fStream->rdbuf()->is_open()) fStream->close();
82 if (fStream->is_open()) fStream->close();
87 if (fBuffer) delete[] fBuffer;
90 void AliRawReaderFile::RequireHeader(Bool_t required)
92 // Reading of raw data in case of missing
93 // raw data header is not implemented for
96 Fatal("AliRawReaderFile","Reading of raw data without raw data header is not implemented !");
98 AliRawReader::RequireHeader(required);
101 TString AliRawReaderFile::GetDirName() const
103 // return the current directory name
105 TString dirName(fDirName);
106 if (fEventIndex >= 0) {
108 dirName += fEventIndex;
113 void* AliRawReaderFile::OpenDirectory()
115 // open and return the directory
117 TString dirName = GetDirName();
118 void* directory = gSystem->OpenDirectory(dirName);
120 Error("OpenDirectory", "could not open directory %s", dirName.Data());
125 Bool_t AliRawReaderFile::OpenNextFile()
127 // open the next file
128 // returns kFALSE if the current file is the last one
131 #if defined(__HP_aCC) || defined(__DECCXX)
132 if (fStream->rdbuf()->is_open()) fStream->close();
134 if (fStream->is_open()) fStream->close();
141 if (!fDirectory) return kFALSE;
143 while (entry = gSystem->GetDirEntry(fDirectory)) {
144 if (entry.IsNull()) return kFALSE;
145 if (!entry.EndsWith(".ddl")) continue;
146 char* fileName = gSystem->ConcatFileName(GetDirName(), entry);
148 fStream = new fstream(fileName, ios::binary|ios::in);
150 fStream = new fstream(fileName, ios::in);
155 if (!fStream) return kFALSE;
156 entry.Remove(0, entry.Last('_')+1);
157 entry.Remove(entry.Length()-4);
158 fEquipmentId = atoi(entry.Data());
159 #if defined(__HP_aCC) || defined(__DECCXX)
160 return (fStream->rdbuf()->is_open());
162 return (fStream->is_open());
167 Bool_t AliRawReaderFile::ReadHeader()
169 // read a data header at the current stream position
170 // returns kFALSE if the mini header could not be read
172 if (!fStream) return kFALSE;
174 if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
175 while (!fStream->read((char*) fHeader, sizeof(AliRawDataHeader))) {
176 if (!OpenNextFile()) return kFALSE;
178 if (fHeader->fSize != 0xFFFFFFFF) {
179 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
181 UInt_t currentPos = fStream->tellg();
182 fStream->seekg(0, ios::end);
183 fCount = UInt_t(fStream->tellg()) - currentPos;
184 fStream->seekg(currentPos);
186 } while (!IsSelected());
190 Bool_t AliRawReaderFile::ReadNextData(UChar_t*& data)
192 // reads the next payload at the current stream position
193 // returns kFALSE if the data could not be read
195 while (fCount == 0) {
196 if (!ReadHeader()) return kFALSE;
198 if (fBufferSize < fCount) {
199 if (fBuffer) delete[] fBuffer;
200 fBufferSize = Int_t(fCount*1.2);
201 fBuffer = new UChar_t[fBufferSize];
203 if (!fStream->read((char*) fBuffer, fCount)) {
204 Error("ReadNext", "could not read data!");
213 Bool_t AliRawReaderFile::ReadNext(UChar_t* data, Int_t size)
215 // reads the next block of data at the current stream position
216 // returns kFALSE if the data could not be read
218 if (!fStream->read((char*) data, size)) {
219 Error("ReadNext", "could not read data!");
227 Bool_t AliRawReaderFile::Reset()
229 // reset the current stream position to the first DDL file of the curevent
231 void* directory = OpenDirectory();
232 if (!directory) return kFALSE;
235 #if defined(__HP_aCC) || defined(__DECCXX)
236 if (fStream->rdbuf()->is_open()) fStream->close();
238 if (fStream->is_open()) fStream->close();
244 if (fDirectory) gSystem->FreeDirectory(fDirectory);
245 fDirectory = directory;
252 Bool_t AliRawReaderFile::NextEvent()
254 // go to the next event directory
256 if (fEventIndex < -1) return kFALSE;
259 TString dirName = fDirName + "/raw";
260 dirName += (fEventIndex + 1);
261 void* directory = gSystem->OpenDirectory(dirName);
262 if (!directory) return kFALSE;
263 gSystem->FreeDirectory(directory);
267 } while (!IsEventSelected());
274 Bool_t AliRawReaderFile::RewindEvents()
276 // reset the event counter
278 if (fEventIndex >= 0) fEventIndex = -1;