source: trunk/MagicSoft/Mars/mraw/MRawFileRead.cc@ 943

Last change on this file since 943 was 860, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 6.0 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Thomas Bretz 12/2000 (tbretz@uni-sw.gwdg.de)
19!
20! Copyright: MAGIC Software Development, 2000-2001
21!
22!
23\* ======================================================================== */
24
25////////////////////////////////////////////////////////////////////////
26//
27// MRawFile
28//
29// This tasks reads the raw binary file like specified in the TDAS???
30// and writes the data in the corresponding containers which are
31// either retrieved from the parameter list or created and added.
32//
33// Input Containers:
34// -/-
35//
36// Output Containers:
37// MRawRunHeader, MRawEvtHeader, MRawEvtData, MRawCrateArray, MRawEvtTime
38//
39////////////////////////////////////////////////////////////////////////
40
41#include "MRawFileRead.h"
42
43#include <fstream.h>
44
45#include "MLog.h"
46#include "MTime.h"
47#include "MParList.h"
48#include "MRawRunHeader.h"
49#include "MRawEvtHeader.h"
50#include "MRawEvtData.h"
51#include "MRawCrateData.h"
52#include "MRawCrateArray.h"
53
54ClassImp(MRawFileRead);
55
56
57/*/ ----------- please don't delete and don't care about (Thomas) ------------
58#define kBUFSZ 1024
59
60class bifstream : public istream, public streambuf
61{
62private:
63 char fBuffer[kBUFSZ]; //!
64 FILE *fd;
65
66 int sync()
67 {
68 memset(fBuffer, 0, kBUFSZ);
69 return 0;
70 }
71 int underflow()
72 {
73 int sz=fread(fBuffer, kBUFSZ, 1, fd);
74 setg(fBuffer, fBuffer, fBuffer+kBUFSZ);
75
76 return sz==kBUFSZ ? *(unsigned char*)fBuffer : EOF;//EOF;
77 }
78public:
79 bifstream(const char *name) : istream(this)
80 {
81 fd = fopen(name, "rb");
82 setbuf(fBuffer, kBUFSZ);
83 }
84};
85*/
86
87// --------------------------------------------------------------------------
88//
89// Default constructor. It tries to open the given file.
90//
91MRawFileRead::MRawFileRead(const char *fname, const char *name, const char *title)
92{
93 *fName = name ? name : "MRawFileRead";
94 *fTitle = title ? title : "Read task to read DAQ binary files";
95
96 //
97 // open the input stream
98 //
99 fFileName = fname;
100 fIn = new ifstream(fname);
101}
102
103// --------------------------------------------------------------------------
104//
105// Destructor. Delete input stream.
106//
107MRawFileRead::~MRawFileRead()
108{
109 delete fIn;
110}
111
112// --------------------------------------------------------------------------
113//
114// The PreProcess of this task checks for the following containers in the
115// list:
116// MRawRunHeader <output> if not found it is created
117// MRawEvtHeader <output> if not found it is created
118// MRawEvtData <output> if not found it is created
119// MRawCrateArray <output> if not found it is created
120// MRawEvtTime <output> if not found it is created (MTime)
121//
122// If all containers are found or created the run header is read from the
123// binary file and printed. If the Magic-Number (file identification)
124// doesn't match we stop the eventloop.
125//
126// Now the EvtHeader and EvtData containers are initialized.
127//
128Bool_t MRawFileRead::PreProcess(MParList *pList)
129{
130 //
131 // first of all check if opening the file in the constructor was
132 // successfull
133 //
134 if (!(*fIn))
135 {
136 *fLog << "Error: Cannot open file '" << fFileName << "'" << endl;
137 return kFALSE;
138 }
139
140 //
141 // check if all necessary containers exist in the Parameter list.
142 // if not create one and add them to the list
143 //
144 fRawRunHeader = (MRawRunHeader*)pList->FindCreateObj("MRawRunHeader");
145 if (!fRawRunHeader)
146 return kFALSE;
147
148 fRawEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
149 if (!fRawEvtHeader)
150 return kFALSE;
151
152 fRawEvtData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
153 if (!fRawEvtData)
154 return kFALSE;
155
156 fRawCrateArray = (MRawCrateArray*)pList->FindCreateObj("MRawCrateArray");
157 if (!fRawCrateArray)
158 return kFALSE;
159
160 fRawEvtTime = (MTime*)pList->FindCreateObj("MTime", "MRawEvtTime");
161 if (!fRawEvtTime)
162 return kTRUE;
163
164 //
165 // Read RUN HEADER (see specification) from input stream
166 //
167 fRawRunHeader->ReadEvt(*fIn);
168 fRawRunHeader->Print();
169
170 if (fRawRunHeader->GetMagicNumber()!=kMagicNumber)
171 return kFALSE;
172
173 //
174 // Give the run header information to the 'sub-classes'
175 //
176 fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
177 fRawEvtData ->Init(fRawRunHeader);
178
179 return kTRUE;
180}
181
182// --------------------------------------------------------------------------
183//
184// The Process reads one event from the binary file:
185// - The event header is read
186// - the run header is read
187// - all crate information is read
188// - the raw data information of one event is read
189//
190Bool_t MRawFileRead::Process()
191{
192 //
193 // Read in the next EVENT HEADER (see specification),
194 // if there is no next event anymore stop eventloop
195 //
196 if (!fRawEvtHeader->ReadEvt(*fIn))
197 return kFALSE;
198
199 //
200 // Delete arrays which stores the pixel information (time slices)
201 //
202 fRawEvtData->DeletePixels();
203
204 //
205 // clear the TClonesArray which stores the Crate Information
206 //
207 fRawCrateArray->Clear();
208
209 //
210 // Get number of crates from the run header
211 //
212 const UShort_t nc = fRawRunHeader->GetNumCrates();
213
214 //
215 // read the CRATE DATA (see specification) from file
216 //
217 for (int i=0; i<nc; i++)
218 {
219 fRawCrateArray->GetEntry(i)->ReadEvt(*fIn);
220
221 fRawEvtData->ReadEvt(*fIn);
222 }
223
224 return kTRUE;
225}
226
Note: See TracBrowser for help on using the repository browser.