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 | ////////////////////////////////////////////////////////////////////////
|
---|
34 |
|
---|
35 | #include "MRawFileRead.h"
|
---|
36 |
|
---|
37 | #include <fstream.h>
|
---|
38 |
|
---|
39 | #include "MLog.h"
|
---|
40 | #include "MTime.h"
|
---|
41 | #include "MParList.h"
|
---|
42 | #include "MRawRunHeader.h"
|
---|
43 | #include "MRawEvtHeader.h"
|
---|
44 | #include "MRawEvtData.h"
|
---|
45 | #include "MRawCrateData.h"
|
---|
46 | #include "MRawCrateArray.h"
|
---|
47 |
|
---|
48 | ClassImp(MRawFileRead)
|
---|
49 |
|
---|
50 |
|
---|
51 | /*/ ----------- please don't delete and don't care about (Thomas) ------------
|
---|
52 | #define kBUFSZ 1024
|
---|
53 |
|
---|
54 | class bifstream : public istream, public streambuf
|
---|
55 | {
|
---|
56 | private:
|
---|
57 | char fBuffer[kBUFSZ]; //!
|
---|
58 | FILE *fd;
|
---|
59 |
|
---|
60 | int sync()
|
---|
61 | {
|
---|
62 | memset(fBuffer, 0, kBUFSZ);
|
---|
63 | return 0;
|
---|
64 | }
|
---|
65 | int underflow()
|
---|
66 | {
|
---|
67 | int sz=fread(fBuffer, kBUFSZ, 1, fd);
|
---|
68 | setg(fBuffer, fBuffer, fBuffer+kBUFSZ);
|
---|
69 |
|
---|
70 | return sz==kBUFSZ ? *(unsigned char*)fBuffer : EOF;//EOF;
|
---|
71 | }
|
---|
72 | public:
|
---|
73 | bifstream(const char *name) : istream(this)
|
---|
74 | {
|
---|
75 | fd = fopen(name, "rb");
|
---|
76 | setbuf(fBuffer, kBUFSZ);
|
---|
77 | }
|
---|
78 | };
|
---|
79 | */
|
---|
80 |
|
---|
81 | // --------------------------------------------------------------------------
|
---|
82 | //
|
---|
83 | // Default constructor. It tries to open the given file.
|
---|
84 | //
|
---|
85 | MRawFileRead::MRawFileRead(const char *fname, const char *name, const char *title)
|
---|
86 | {
|
---|
87 | *fName = name ? name : "MRawFileRead";
|
---|
88 | *fTitle = title ? title : "Read task to read DAQ binary files";
|
---|
89 |
|
---|
90 | //
|
---|
91 | // open the input stream
|
---|
92 | //
|
---|
93 | fIn = new ifstream(fname);
|
---|
94 |
|
---|
95 | if (!(*fIn))
|
---|
96 | *fLog << "Error: Trying to open file '" << fname << "'" << endl;
|
---|
97 | }
|
---|
98 |
|
---|
99 | // --------------------------------------------------------------------------
|
---|
100 | //
|
---|
101 | // Destructor. Delete input stream.
|
---|
102 | //
|
---|
103 | MRawFileRead::~MRawFileRead()
|
---|
104 | {
|
---|
105 | delete fIn;
|
---|
106 | }
|
---|
107 |
|
---|
108 | // --------------------------------------------------------------------------
|
---|
109 | //
|
---|
110 | // The PreProcess of this task checks for the following containers in the
|
---|
111 | // list:
|
---|
112 | // MRawRunHeader <output> if not found it is created
|
---|
113 | // MRawEvtHeader <output> if not found it is created
|
---|
114 | // MRawEvtData <output> if not found it is created
|
---|
115 | // MRawCrateArray <output> if not found it is created
|
---|
116 | // MRawEvtTime <output> if not found it is created (MTime)
|
---|
117 | //
|
---|
118 | // If all containers are found or created the run header is read from the
|
---|
119 | // binary file and printed. If the Magic-Number (file identification)
|
---|
120 | // doesn't match we stop the eventloop.
|
---|
121 | //
|
---|
122 | // Now the EvtHeader and EvtData containers are initialized.
|
---|
123 | //
|
---|
124 | Bool_t MRawFileRead::PreProcess(MParList *pList)
|
---|
125 | {
|
---|
126 | //
|
---|
127 | // remember the pointer to the parameter list fur further usage
|
---|
128 | //
|
---|
129 |
|
---|
130 | //
|
---|
131 | // check if all necessary containers exist in the Parameter list.
|
---|
132 | // if not create one and add them to the list
|
---|
133 | //
|
---|
134 | fRawRunHeader = (MRawRunHeader*)pList->FindCreateObj("MRawRunHeader");
|
---|
135 | if (!fRawRunHeader)
|
---|
136 | return kFALSE;
|
---|
137 |
|
---|
138 | fRawEvtHeader = (MRawEvtHeader*)pList->FindCreateObj("MRawEvtHeader");
|
---|
139 | if (!fRawEvtHeader)
|
---|
140 | return kFALSE;
|
---|
141 |
|
---|
142 | fRawEvtData = (MRawEvtData*)pList->FindCreateObj("MRawEvtData");
|
---|
143 | if (!fRawEvtData)
|
---|
144 | return kFALSE;
|
---|
145 |
|
---|
146 | fRawCrateArray = (MRawCrateArray*)pList->FindCreateObj("MRawCrateArray");
|
---|
147 | if (!fRawCrateArray)
|
---|
148 | return kFALSE;
|
---|
149 |
|
---|
150 | fRawEvtTime = (MTime*)pList->FindCreateObj("MTime", "MRawEvtTime");
|
---|
151 | if (!fRawEvtTime)
|
---|
152 | return kTRUE;
|
---|
153 |
|
---|
154 | //
|
---|
155 | // Read RUN HEADER (see specification) from input stream
|
---|
156 | //
|
---|
157 | fRawRunHeader->ReadEvt(*fIn);
|
---|
158 | fRawRunHeader->Print();
|
---|
159 |
|
---|
160 | if (fRawRunHeader->GetMagicNumber()!=kMagicNumber)
|
---|
161 | return kFALSE;
|
---|
162 |
|
---|
163 | //
|
---|
164 | // Give the run header information to the 'sub-classes'
|
---|
165 | //
|
---|
166 | fRawEvtHeader->Init(fRawRunHeader, fRawEvtTime);
|
---|
167 | fRawEvtData ->Init(fRawRunHeader);
|
---|
168 |
|
---|
169 | return kTRUE;
|
---|
170 | }
|
---|
171 |
|
---|
172 | // --------------------------------------------------------------------------
|
---|
173 | //
|
---|
174 | // The Process reads one event from the binary file:
|
---|
175 | // - The event header is read
|
---|
176 | // - the run header is read
|
---|
177 | // - all crate information is read
|
---|
178 | // - the raw data information of one event is read
|
---|
179 | //
|
---|
180 | Bool_t MRawFileRead::Process()
|
---|
181 | {
|
---|
182 | //
|
---|
183 | // Read in the next EVENT HEADER (see specification),
|
---|
184 | // if there is no next event anymore stop eventloop
|
---|
185 | //
|
---|
186 | if (!fRawEvtHeader->ReadEvt(*fIn))
|
---|
187 | return kFALSE;
|
---|
188 |
|
---|
189 | //
|
---|
190 | // Delete arrays which stores the pixel information (time slices)
|
---|
191 | //
|
---|
192 | fRawEvtData->DeletePixels();
|
---|
193 |
|
---|
194 | //
|
---|
195 | // clear the TClonesArray which stores the Crate Information
|
---|
196 | //
|
---|
197 | fRawCrateArray->Clear();
|
---|
198 |
|
---|
199 | //
|
---|
200 | // Get number of crates from the run header
|
---|
201 | //
|
---|
202 | const UShort_t nc = fRawRunHeader->GetNumCrates();
|
---|
203 |
|
---|
204 | //
|
---|
205 | // read the CRATE DATA (see specification) from file
|
---|
206 | //
|
---|
207 | for (int i=0; i<nc; i++)
|
---|
208 | {
|
---|
209 | fRawCrateArray->GetEntry(i)->ReadEvt(*fIn);
|
---|
210 |
|
---|
211 | fRawEvtData->ReadEvt(*fIn);
|
---|
212 | }
|
---|
213 |
|
---|
214 | return kTRUE;
|
---|
215 | }
|
---|
216 |
|
---|