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 ///////////////////////////////////////////////////////////////////////////////
34 #include "AliRawReaderFile.h"
38 ClassImp(AliRawReaderFile)
41 AliRawReaderFile::AliRawReaderFile(Int_t eventNumber) :
42 fEventIndex(eventNumber),
51 // create an object to read digits from the given event
52 // in the current directory
54 fDirectory = OpenDirectory();
56 fHeader = new AliRawDataHeader;
59 AliRawReaderFile::AliRawReaderFile(const char* dirName, Int_t eventNumber) :
60 fEventIndex(eventNumber),
69 // create an object to read digits from the given directory
71 fDirectory = OpenDirectory();
73 fHeader = new AliRawDataHeader;
76 AliRawReaderFile::~AliRawReaderFile()
78 // close the input file
80 if (fDirectory) gSystem->FreeDirectory(fDirectory);
82 #if defined(__HP_aCC) || defined(__DECCXX)
83 if (fStream->rdbuf()->is_open()) fStream->close();
85 if (fStream->is_open()) fStream->close();
89 if (fHeader) delete fHeader;
90 if (fBuffer) delete[] fBuffer;
93 void AliRawReaderFile::RequireHeader(Bool_t required)
95 // Reading of raw data in case of missing
96 // raw data header is not implemented for
99 Warning("AliRawReaderFile","Reading of raw data without raw data header is not implemented !");
100 if (fHeader) delete fHeader;
104 if (!fHeader) fHeader = new AliRawDataHeader;
107 AliRawReader::RequireHeader(required);
110 TString AliRawReaderFile::GetDirName() const
112 // return the current directory name
114 TString dirName(fDirName);
115 if (fEventIndex >= 0) {
117 dirName += fEventIndex;
122 void* AliRawReaderFile::OpenDirectory()
124 // open and return the directory
126 TString dirName = GetDirName();
127 void* directory = gSystem->OpenDirectory(dirName);
129 Error("OpenDirectory", "could not open directory %s", dirName.Data());
134 Bool_t AliRawReaderFile::OpenNextFile()
136 // open the next file
137 // returns kFALSE if the current file is the last one
140 #if defined(__HP_aCC) || defined(__DECCXX)
141 if (fStream->rdbuf()->is_open()) fStream->close();
143 if (fStream->is_open()) fStream->close();
151 if (!fDirectory) return kFALSE;
153 while (entry = gSystem->GetDirEntry(fDirectory)) {
154 if (entry.IsNull()) return kFALSE;
155 if (!entry.EndsWith(".ddl")) continue;
156 char* fileName = gSystem->ConcatFileName(GetDirName(), entry);
158 fStream = new fstream(fileName, ios::binary|ios::in);
160 fStream = new fstream(fileName, ios::in);
165 if (!fStream) return kFALSE;
166 entry.Remove(0, entry.Last('_')+1);
167 entry.Remove(entry.Length()-4);
168 fEquipmentId = atoi(entry.Data());
169 #if defined(__HP_aCC) || defined(__DECCXX)
170 return (fStream->rdbuf()->is_open());
172 return (fStream->is_open());
177 Bool_t AliRawReaderFile::ReadHeader()
179 // read a data header at the current stream position
180 // returns kFALSE if the mini header could not be read
182 if (!fStream) return kFALSE;
184 if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
186 while (!fStream->read((char*) fHeader, sizeof(AliRawDataHeader))) {
187 if (!OpenNextFile()) return kFALSE;
190 if (fHeader && fHeader->fSize != 0xFFFFFFFF) {
191 fCount = fHeader->fSize - sizeof(AliRawDataHeader);
193 UInt_t currentPos = fStream->tellg();
194 fStream->seekg(0, ios::end);
195 fCount = UInt_t(fStream->tellg()) - currentPos;
196 fStream->seekg(currentPos);
198 fEquipmentSize = fCount;
199 if (fHeader) fEquipmentSize += sizeof(AliRawDataHeader);
200 } while (!IsSelected());
204 Bool_t AliRawReaderFile::ReadNextData(UChar_t*& data)
206 // reads the next payload at the current stream position
207 // returns kFALSE if the data could not be read
209 while (fCount == 0) {
210 if (!ReadHeader()) return kFALSE;
212 if (fBufferSize < fCount) {
213 if (fBuffer) delete[] fBuffer;
214 fBufferSize = Int_t(fCount*1.2);
215 fBuffer = new UChar_t[fBufferSize];
217 if (!fStream->read((char*) fBuffer, fCount)) {
218 Error("ReadNext", "could not read data!");
227 Bool_t AliRawReaderFile::ReadNext(UChar_t* data, Int_t size)
229 // reads the next block of data at the current stream position
230 // returns kFALSE if the data could not be read
232 if (!fStream->read((char*) data, size)) {
233 Error("ReadNext", "could not read data!");
241 Bool_t AliRawReaderFile::Reset()
243 // reset the current stream position to the first DDL file of the curevent
245 void* directory = OpenDirectory();
246 if (!directory) return kFALSE;
249 #if defined(__HP_aCC) || defined(__DECCXX)
250 if (fStream->rdbuf()->is_open()) fStream->close();
252 if (fStream->is_open()) fStream->close();
258 if (fDirectory) gSystem->FreeDirectory(fDirectory);
259 fDirectory = directory;
266 Bool_t AliRawReaderFile::NextEvent()
268 // go to the next event directory
270 if (fEventIndex < -1) return kFALSE;
273 TString dirName = fDirName + "/raw";
274 dirName += (fEventIndex + 1);
275 void* directory = gSystem->OpenDirectory(dirName);
276 if (!directory) return kFALSE;
277 gSystem->FreeDirectory(directory);
281 } while (!IsEventSelected());
288 Bool_t AliRawReaderFile::RewindEvents()
290 // reset the event counter
292 if (fEventIndex >= 0) fEventIndex = -1;