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;
103 void AliRawReaderFile::RequireHeader(Bool_t required)
105 // Reading of raw data in case of missing
106 // raw data header is not implemented for
109 Fatal("AliRawReaderFile","Reading of raw data without raw data header is not implemented !");
111 AliRawReader::RequireHeader(required);
114 TString AliRawReaderFile::GetDirName() const
116 // return the current directory name
118 TString dirName(fDirName);
119 if (fEventIndex >= 0) {
121 dirName += fEventIndex;
126 void* AliRawReaderFile::OpenDirectory()
128 // open and return the directory
130 TString dirName = GetDirName();
131 void* directory = gSystem->OpenDirectory(dirName);
133 Error("OpenDirectory", "could not open directory %s", dirName.Data());
138 Bool_t AliRawReaderFile::OpenNextFile()
140 // open the next file
141 // returns kFALSE if the current file is the last one
144 #if defined(__HP_aCC) || defined(__DECCXX)
145 if (fStream->rdbuf()->is_open()) fStream->close();
147 if (fStream->is_open()) fStream->close();
154 if (!fDirectory) return kFALSE;
156 while (entry = gSystem->GetDirEntry(fDirectory)) {
157 if (entry.IsNull()) return kFALSE;
158 if (!entry.EndsWith(".ddl")) continue;
159 char* fileName = gSystem->ConcatFileName(GetDirName(), entry);
161 fStream = new fstream(fileName, ios::binary|ios::in);
163 fStream = new fstream(fileName, ios::in);
168 if (!fStream) return kFALSE;
169 entry.Remove(0, entry.Last('_')+1);
170 entry.Remove(entry.Length()-4);
171 fEquipmentId = atoi(entry.Data());
172 #if defined(__HP_aCC) || defined(__DECCXX)
173 return (fStream->rdbuf()->is_open());
175 return (fStream->is_open());
180 Bool_t AliRawReaderFile::ReadHeader()
182 // read a data header at the current stream position
183 // returns kFALSE if the mini header could not be read
185 if (!fStream) return kFALSE;
187 if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
188 while (!fStream->read((char*) fHeader, sizeof(AliRawDataHeader))) {
189 if (!OpenNextFile()) return kFALSE;
191 if (fHeader->fSize != 0xFFFFFFFF) {
192 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
194 UInt_t currentPos = fStream->tellg();
195 fStream->seekg(0, ios::end);
196 fCount = UInt_t(fStream->tellg()) - currentPos;
197 fStream->seekg(currentPos);
199 } while (!IsSelected());
203 Bool_t AliRawReaderFile::ReadNextData(UChar_t*& data)
205 // reads the next payload at the current stream position
206 // returns kFALSE if the data could not be read
208 while (fCount == 0) {
209 if (!ReadHeader()) return kFALSE;
211 if (fBufferSize < fCount) {
212 if (fBuffer) delete[] fBuffer;
213 fBufferSize = Int_t(fCount*1.2);
214 fBuffer = new UChar_t[fBufferSize];
216 if (!fStream->read((char*) fBuffer, fCount)) {
217 Error("ReadNext", "could not read data!");
226 Bool_t AliRawReaderFile::ReadNext(UChar_t* data, Int_t size)
228 // reads the next block of data at the current stream position
229 // returns kFALSE if the data could not be read
231 if (!fStream->read((char*) data, size)) {
232 Error("ReadNext", "could not read data!");
240 Bool_t AliRawReaderFile::Reset()
242 // reset the current stream position to the first DDL file of the curevent
244 void* directory = OpenDirectory();
245 if (!directory) return kFALSE;
248 #if defined(__HP_aCC) || defined(__DECCXX)
249 if (fStream->rdbuf()->is_open()) fStream->close();
251 if (fStream->is_open()) fStream->close();
257 if (fDirectory) gSystem->FreeDirectory(fDirectory);
258 fDirectory = directory;
265 Bool_t AliRawReaderFile::NextEvent()
267 // go to the next event directory
269 if (fEventIndex < -1) return kFALSE;
272 TString dirName = fDirName + "/raw";
273 dirName += (fEventIndex + 1);
274 void* directory = gSystem->OpenDirectory(dirName);
275 if (!directory) return kFALSE;
276 gSystem->FreeDirectory(directory);
280 } while (!IsEventSelected());
285 Bool_t AliRawReaderFile::RewindEvents()
287 // reset the event counter
289 if (fEventIndex >= 0) fEventIndex = -1;