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 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2004
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MRawRunHeader
|
---|
28 | //
|
---|
29 | // Root storage container for the RUN HEADER information
|
---|
30 | //
|
---|
31 | // Format Version 2:
|
---|
32 | // -----------------
|
---|
33 | // - removed mjd from data
|
---|
34 | // - added start time
|
---|
35 | // - added stop time
|
---|
36 | //
|
---|
37 | // Class Version 2:
|
---|
38 | // ----------------
|
---|
39 | // - removed fMJD, fYear, fMonth, fDay
|
---|
40 | // - added fRunStart
|
---|
41 | // - added fRunStop
|
---|
42 | //
|
---|
43 | // Class Version 1:
|
---|
44 | // ----------------
|
---|
45 | // - first implementation
|
---|
46 | //
|
---|
47 | ////////////////////////////////////////////////////////////////////////////
|
---|
48 |
|
---|
49 | #include "MRawRunHeader.h"
|
---|
50 |
|
---|
51 | #include <fstream>
|
---|
52 | #include <iomanip>
|
---|
53 |
|
---|
54 | #include "MLog.h"
|
---|
55 | #include "MLogManip.h"
|
---|
56 |
|
---|
57 | #include "MArrayS.h"
|
---|
58 |
|
---|
59 | ClassImp(MRawRunHeader);
|
---|
60 |
|
---|
61 | using namespace std;
|
---|
62 |
|
---|
63 | // --------------------------------------------------------------------------
|
---|
64 | //
|
---|
65 | // Default constructor. Creates array which stores the pixel assignment.
|
---|
66 | //
|
---|
67 | //
|
---|
68 | MRawRunHeader::MRawRunHeader(const char *name, const char *title) : fPixAssignment(NULL)
|
---|
69 | {
|
---|
70 | fName = name ? name : "MRawRunHeader";
|
---|
71 | fTitle = title ? title : "Raw Run Header Information";
|
---|
72 |
|
---|
73 | fPixAssignment = new MArrayS(0);
|
---|
74 |
|
---|
75 | fFormatVersion=0;
|
---|
76 | fSoftVersion=0;
|
---|
77 | fRunType=kRTNone; // use 0xffff for invalidation, 0 means: Data run
|
---|
78 | fRunNumber=0;
|
---|
79 | fProjectName[0]=0;
|
---|
80 | fSourceName[0]=0;
|
---|
81 | fSourceEpochChar[0]=0;
|
---|
82 | fSourceEpochDate=0;
|
---|
83 | fNumCrates=0;
|
---|
84 | fNumPixInCrate=0;
|
---|
85 | fNumSamplesLoGain=0;
|
---|
86 | fNumSamplesHiGain=0;
|
---|
87 | fNumEvents=0;
|
---|
88 | }
|
---|
89 |
|
---|
90 | // --------------------------------------------------------------------------
|
---|
91 | //
|
---|
92 | // Destructor. Deletes the 'pixel-assignment-array'
|
---|
93 | //
|
---|
94 | MRawRunHeader::~MRawRunHeader()
|
---|
95 | {
|
---|
96 | delete fPixAssignment;
|
---|
97 | }
|
---|
98 |
|
---|
99 | // --------------------------------------------------------------------------
|
---|
100 | //
|
---|
101 | // Read in one run header from the binary file
|
---|
102 | //
|
---|
103 | Bool_t MRawRunHeader::ReadEvt(istream& fin)
|
---|
104 | {
|
---|
105 | //
|
---|
106 | // read one RUN HEADER from the input stream
|
---|
107 | //
|
---|
108 | fMagicNumber = 0;
|
---|
109 |
|
---|
110 | fin.read((char*)&fMagicNumber, 2); // Total=2
|
---|
111 |
|
---|
112 | //
|
---|
113 | // check whether the the file has the right file type or not
|
---|
114 | //
|
---|
115 | if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
|
---|
116 | {
|
---|
117 | *fLog << err << "Error: Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
|
---|
118 | return kFALSE;
|
---|
119 | }
|
---|
120 |
|
---|
121 | if (fMagicNumber == kMagicNumber+1)
|
---|
122 | *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
|
---|
123 |
|
---|
124 | Byte_t dummy[16];
|
---|
125 |
|
---|
126 | fin.read((char*)&fFormatVersion, 2); // Total=4
|
---|
127 | if (fFormatVersion>kMaxFormatVersion)
|
---|
128 | {
|
---|
129 | *fLog << err << "WARNING - File vormat V" << fFormatVersion << " not implemented!" << endl;
|
---|
130 | return kFALSE;
|
---|
131 | }
|
---|
132 |
|
---|
133 | fin.read((char*)&fSoftVersion, 2); // Total=6
|
---|
134 | fin.read((char*)&fRunType, 2); // Total=8
|
---|
135 | fin.read((char*)&fRunNumber, 4); // Total=12
|
---|
136 | fin.read((char*)&fProjectName, 22); // Total=34
|
---|
137 | fin.read((char*)&fSourceName, 12); // Total=46
|
---|
138 | fin.read((char*)dummy, 4); // was RA (moved to tracking system)
|
---|
139 | fin.read((char*)dummy, 4); // was DEC (moved to tracking system)
|
---|
140 | fin.read((char*)&fSourceEpochChar, 2); // Total=56
|
---|
141 | fin.read((char*)&fSourceEpochDate, 2); // Total=58
|
---|
142 | if (fFormatVersion<2) // Total += 10
|
---|
143 | {
|
---|
144 | UShort_t y, m, d;
|
---|
145 | fin.read((char*)dummy, 4); // Former fMJD[4],
|
---|
146 | fin.read((char*)&y, 2); // Former fDateYear[2]
|
---|
147 | fin.read((char*)&m, 2); // Former fDateMonth[2]
|
---|
148 | fin.read((char*)&d, 2); // Former fDateDay[2]
|
---|
149 | fRunStart.Set(y, m, d, 0, 0, 0, 0);
|
---|
150 | }
|
---|
151 | fin.read((char*)&fNumCrates, 2); // Total=60
|
---|
152 | fin.read((char*)&fNumPixInCrate, 2); // Total=62
|
---|
153 | fin.read((char*)&fNumSamplesLoGain, 2); // Total=64
|
---|
154 | fin.read((char*)&fNumSamplesHiGain, 2); // Total=66
|
---|
155 | fin.read((char*)&fNumEvents, 4); // Total=70
|
---|
156 | if (fFormatVersion>1)
|
---|
157 | {
|
---|
158 | fRunStart.ReadBinary(fin); // Total += 7
|
---|
159 | fRunStop.ReadBinary(fin); // Total += 7
|
---|
160 | }
|
---|
161 |
|
---|
162 | //
|
---|
163 | // calculate size of array, create it and fill it
|
---|
164 | //
|
---|
165 | Int_t nPixel = fNumCrates*fNumPixInCrate;
|
---|
166 | fPixAssignment->Set(nPixel);
|
---|
167 |
|
---|
168 | fin.read((char*)fPixAssignment->GetArray(), nPixel*2);
|
---|
169 | fin.read((char*)&dummy, 16);
|
---|
170 |
|
---|
171 | return kTRUE;
|
---|
172 | }
|
---|
173 |
|
---|
174 | // --------------------------------------------------------------------------
|
---|
175 | //
|
---|
176 | // Return the run type as string ("Data", "Pedestal", ...), for example
|
---|
177 | // to print it as readable text.
|
---|
178 | //
|
---|
179 | const char *MRawRunHeader::GetRunTypeStr() const
|
---|
180 | {
|
---|
181 | switch (fRunType)
|
---|
182 | {
|
---|
183 | case kRTData:
|
---|
184 | return "Data";
|
---|
185 | case kRTPedestal:
|
---|
186 | return "Pedestal";
|
---|
187 | case kRTCalibration:
|
---|
188 | return "Calibration";
|
---|
189 | case kRTMonteCarlo:
|
---|
190 | return "Monte Carlo";
|
---|
191 | case kRTNone:
|
---|
192 | return "<none>";
|
---|
193 | default:
|
---|
194 | return "<unknown>";
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | // --------------------------------------------------------------------------
|
---|
199 | //
|
---|
200 | // print run header information on *fLog
|
---|
201 | //
|
---|
202 | void MRawRunHeader::Print(Option_t *t) const
|
---|
203 | {
|
---|
204 | *fLog << all << endl;
|
---|
205 | *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - ";
|
---|
206 | switch (fMagicNumber)
|
---|
207 | {
|
---|
208 | case kMagicNumber: *fLog << "OK"; break;
|
---|
209 | case kMagicNumber+1: *fLog << "File not closed!"; break;
|
---|
210 | default: *fLog << "Wrong!"; break;
|
---|
211 | }
|
---|
212 | *fLog << endl;
|
---|
213 | *fLog << "Version: " << dec << "Format=" << fFormatVersion << " ";
|
---|
214 | *fLog << "Software=" << fSoftVersion << endl;
|
---|
215 | *fLog << "RunNumber: " << fRunNumber << " (Type=" << GetRunTypeStr() << ")" << endl;
|
---|
216 | *fLog << "ProjectName: '" << fProjectName << "'" << endl;
|
---|
217 | *fLog << "Source: '" << fSourceName << "' " << " ";
|
---|
218 | *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
|
---|
219 | *fLog << "Run Start: " << fRunStart << endl;
|
---|
220 | *fLog << "Run Stop: " << fRunStop << endl;
|
---|
221 | *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
|
---|
222 | *fLog << "Samples: " << fNumSamplesLoGain << "/" << fNumSamplesHiGain << " (lo/hi) = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate /1024 << "kB/Evt" << endl;
|
---|
223 | *fLog << "Evt Counter: " << fNumEvents << endl;
|
---|
224 |
|
---|
225 | *fLog << inf << hex;
|
---|
226 | for (int i=0; i<GetNumPixel(); i++)
|
---|
227 | *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
|
---|
228 |
|
---|
229 | *fLog << endl;
|
---|
230 | }
|
---|
231 |
|
---|
232 | // --------------------------------------------------------------------------
|
---|
233 | //
|
---|
234 | // Return the assigned pixel number for the given FADC channel
|
---|
235 | //
|
---|
236 | UShort_t MRawRunHeader::GetPixAssignment(UShort_t i) const
|
---|
237 | {
|
---|
238 | // FIXME: Do we need a range check here?
|
---|
239 | return (*fPixAssignment)[i];
|
---|
240 | }
|
---|
241 |
|
---|
242 | // --------------------------------------------------------------------------
|
---|
243 | //
|
---|
244 | // Return the number of pixel which are markes as connected in the
|
---|
245 | // pix assignment (>0)
|
---|
246 | //
|
---|
247 | UShort_t MRawRunHeader::GetNumConnectedPixels() const
|
---|
248 | {
|
---|
249 | const Int_t num = fPixAssignment->GetSize();
|
---|
250 |
|
---|
251 | UShort_t rc = 0;
|
---|
252 | for (int i=0; i<num; i++)
|
---|
253 | {
|
---|
254 | if (GetPixAssignment(i)>0)
|
---|
255 | rc++;
|
---|
256 | }
|
---|
257 | return rc;
|
---|
258 | }
|
---|
259 |
|
---|
260 | // --------------------------------------------------------------------------
|
---|
261 | //
|
---|
262 | // Return the maximum id which exists in the pix assignment
|
---|
263 | //
|
---|
264 | UShort_t MRawRunHeader::GetMaxPixId() const
|
---|
265 | {
|
---|
266 | const Int_t num = fPixAssignment->GetSize();
|
---|
267 |
|
---|
268 | UShort_t rc = 0;
|
---|
269 | for (int i=0; i<num; i++)
|
---|
270 | rc = TMath::Max(GetPixAssignment(i), rc);
|
---|
271 |
|
---|
272 | return rc;
|
---|
273 | }
|
---|
274 |
|
---|
275 | // --------------------------------------------------------------------------
|
---|
276 | //
|
---|
277 | // Return the number of pixel in this event.
|
---|
278 | //
|
---|
279 | // WARNING: This is the number of pixels stored in this file which is
|
---|
280 | // a multiple of the number of pixels per crate and in general
|
---|
281 | // a number which is larger than the camera size!
|
---|
282 | //
|
---|
283 | // To know the range of the pixel indices please use the geometry
|
---|
284 | // container!
|
---|
285 | //
|
---|
286 | UShort_t MRawRunHeader::GetNumPixel() const
|
---|
287 | {
|
---|
288 | return fPixAssignment->GetSize();
|
---|
289 | }
|
---|
290 |
|
---|
291 | // --------------------------------------------------------------------------
|
---|
292 | //
|
---|
293 | // Returns absolute size in bytes of the run header as read from a raw file.
|
---|
294 | // This must be done _after_ the header is read, because the header doesn't
|
---|
295 | // have a fixed size (used in MRawSocketRead)
|
---|
296 | //
|
---|
297 | Int_t MRawRunHeader::GetNumTotalBytes() const
|
---|
298 | {
|
---|
299 | switch (fFormatVersion)
|
---|
300 | {
|
---|
301 | case 1:
|
---|
302 | return 80+fNumCrates*fNumPixInCrate*2+16;
|
---|
303 | case 2:
|
---|
304 | return 84+fNumCrates*fNumPixInCrate*2+16;
|
---|
305 | }
|
---|
306 | return 0;
|
---|
307 | }
|
---|