]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RAW/AliRawReaderFile.cxx
Renove the clusterizer after Reconstruct. Use as much the runloader instead of the...
[u/mrichter/AliRoot.git] / RAW / AliRawReaderFile.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 ///////////////////////////////////////////////////////////////////////////////
17 //
18 // This is a class for reading a raw data file and providing
19 // information about digits
20 //
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #include "AliRawReaderFile.h"
24 #include <TSystem.h>
25
26
27 ClassImp(AliRawReaderFile)
28
29
30 AliRawReaderFile::AliRawReaderFile(Int_t eventNumber) :
31   fDirName("raw"),
32   fDirectory(NULL),
33   fStream(NULL),
34   fEquipmentId(-1),
35   fBuffer(NULL),
36   fBufferSize(0)
37 {
38 // create an object to read digits from the given event
39
40   fDirName += eventNumber;
41   fDirectory = gSystem->OpenDirectory(fDirName);
42   if (!fDirectory) {
43     Error("AliRawReaderFile", "could not open directory %s", fDirName.Data());
44   }
45   OpenNextFile();
46   fHeader = new AliRawDataHeader;
47 }
48
49 AliRawReaderFile::AliRawReaderFile(const char* dirName) :
50   fDirName(dirName),
51   fDirectory(NULL),
52   fStream(NULL),
53   fEquipmentId(-1),
54   fBuffer(NULL),
55   fBufferSize(0)
56 {
57 // create an object to read digits from the given directory
58
59   fDirectory = gSystem->OpenDirectory(fDirName);
60   if (!fDirectory) {
61     Error("AliRawReaderFile", "could not open directory %s", fDirName.Data());
62   }
63   OpenNextFile();
64   fHeader = new AliRawDataHeader;
65 }
66
67 AliRawReaderFile::AliRawReaderFile(const AliRawReaderFile& rawReader) :
68   AliRawReader(rawReader)
69 {
70   Fatal("AliRawReaderFile", "copy constructor not implemented");
71 }
72
73 AliRawReaderFile& AliRawReaderFile::operator = (const AliRawReaderFile& 
74                                               /* rawReader */)
75 {
76   Fatal("operator =", "assignment operator not implemented");
77   return *this;
78 }
79
80 AliRawReaderFile::~AliRawReaderFile()
81 {
82 // close the input file
83
84   if (fDirectory) gSystem->FreeDirectory(fDirectory);
85   if (fStream) {
86 #if defined(__HP_aCC) || defined(__DECCXX)
87     if (fStream->rdbuf()->is_open()) fStream->close();
88 #else
89     if (fStream->is_open()) fStream->close();
90 #endif
91     delete fStream;
92   }
93   delete fHeader;
94   if (fBuffer) delete[] fBuffer;
95 }
96
97
98 Bool_t AliRawReaderFile::OpenNextFile()
99 {
100 // open the next file
101 // returns kFALSE if the current file is the last one
102
103   if (fStream) {
104 #if defined(__HP_aCC) || defined(__DECCXX)
105     if (fStream->rdbuf()->is_open()) fStream->close();
106 #else
107     if (fStream->is_open()) fStream->close();
108 #endif
109     delete fStream;
110     fStream = NULL;
111     fEquipmentId = -1;
112   }
113
114   if (!fDirectory) return kFALSE;
115   TString entry;
116   while (entry = gSystem->GetDirEntry(fDirectory)) {
117     if (entry.IsNull()) return kFALSE;
118     if (!entry.EndsWith(".ddl")) continue;
119     char* fileName = gSystem->ConcatFileName(fDirName, entry);
120 #ifndef __DECCXX 
121     fStream = new fstream(fileName, ios::binary|ios::in);
122 #else
123     fStream = new fstream(fileName, ios::in);
124 #endif
125     break;
126   }
127
128   if (!fStream) return kFALSE;
129   entry.Remove(0, entry.Last('_')+1);
130   entry.Remove(entry.Length()-4);
131   fEquipmentId = atoi(entry.Data());
132 #if defined(__HP_aCC) || defined(__DECCXX)
133   return (fStream->rdbuf()->is_open());
134 #else
135   return (fStream->is_open());
136 #endif
137 }
138
139
140 Bool_t AliRawReaderFile::ReadHeader()
141 {
142 // read a data header at the current stream position
143 // returns kFALSE if the mini header could not be read
144
145   if (!fStream) return kFALSE;
146   do {
147     if (fCount > 0) fStream->seekg(Int_t(fStream->tellg()) + fCount);
148     while (!fStream->read((char*) fHeader, sizeof(AliRawDataHeader))) {
149       if (!OpenNextFile()) return kFALSE;
150     }
151     if (fHeader->fSize != 0xFFFFFFFF) {
152       fCount = fHeader->fSize - sizeof(AliRawDataHeader);
153     } else {
154       UInt_t currentPos = fStream->tellg();
155       fStream->seekg(0, ios::end);
156       fCount = UInt_t(fStream->tellg()) - currentPos;
157       fStream->seekg(currentPos);
158     }
159   } while (!IsSelected());
160   return kTRUE;
161 }
162
163 Bool_t AliRawReaderFile::ReadNextData(UChar_t*& data)
164 {
165 // reads the next payload at the current stream position
166 // returns kFALSE if the data could not be read
167
168   while (fCount == 0) {
169     if (!ReadHeader()) return kFALSE;
170   }
171   if (fBufferSize < fCount) {
172     if (fBuffer) delete[] fBuffer;
173     fBufferSize = Int_t(fCount*1.2);
174     fBuffer = new UChar_t[fBufferSize];
175   }
176   if (!fStream->read((char*) fBuffer, fCount)) {
177     Error("ReadNext", "could not read data!");
178     return kFALSE;
179   }
180   fCount = 0;
181
182   data = fBuffer;
183   return kTRUE;
184 }
185
186 Bool_t AliRawReaderFile::ReadNext(UChar_t* data, Int_t size)
187 {
188 // reads the next block of data at the current stream position
189 // returns kFALSE if the data could not be read
190
191   if (!fStream->read((char*) data, size)) {
192     Error("ReadNext", "could not read data!");
193     return kFALSE;
194   }
195   fCount -= size;
196   return kTRUE;
197 }
198
199
200 Bool_t AliRawReaderFile::Reset()
201 {
202 // reset the current stream position to the beginning of the file
203
204   void* directory = gSystem->OpenDirectory(fDirName);
205   if (!directory) {
206     Error("Reset", "could not open directory %s", fDirName.Data());
207     return kFALSE;
208   }
209
210   if (fStream) {
211 #if defined(__HP_aCC) || defined(__DECCXX)
212     if (fStream->rdbuf()->is_open()) fStream->close();
213 #else
214     if (fStream->is_open()) fStream->close();
215 #endif
216     delete fStream;
217     fStream = NULL;
218   }
219
220   if (fDirectory) gSystem->FreeDirectory(fDirectory);
221   fDirectory = directory;
222
223   OpenNextFile();
224   fCount = 0;
225   return kTRUE;
226 }
227