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 | //
|
---|
32 | // RAW DATA FORMAT VERSION
|
---|
33 | // =======================
|
---|
34 | //
|
---|
35 | // Format Version 5:
|
---|
36 | // -----------------
|
---|
37 | // - now the sub millisecond information of the time is valid and decoded
|
---|
38 | // which enhances the precision from 51.2us to 200ns
|
---|
39 | //
|
---|
40 | // Format Version 4:
|
---|
41 | // -----------------
|
---|
42 | // - added support for pixels with negative IDs
|
---|
43 | //
|
---|
44 | // Format Version 3:
|
---|
45 | // -----------------
|
---|
46 | // - ???
|
---|
47 | //
|
---|
48 | // Format Version 2:
|
---|
49 | // -----------------
|
---|
50 | // - removed mjd from data
|
---|
51 | // - added start time
|
---|
52 | // - added stop time
|
---|
53 | //
|
---|
54 | //
|
---|
55 | // MRawRunHeader CLASS VERSION
|
---|
56 | // ===========================
|
---|
57 | //
|
---|
58 | // Class Version 2:
|
---|
59 | // ----------------
|
---|
60 | // - removed fMJD, fYear, fMonth, fDay
|
---|
61 | // - added fRunStart
|
---|
62 | // - added fRunStop
|
---|
63 | //
|
---|
64 | // Class Version 1:
|
---|
65 | // ----------------
|
---|
66 | // - first implementation
|
---|
67 | //
|
---|
68 | ////////////////////////////////////////////////////////////////////////////
|
---|
69 |
|
---|
70 | #include "MRawRunHeader.h"
|
---|
71 |
|
---|
72 | #include <fstream>
|
---|
73 | #include <iomanip>
|
---|
74 |
|
---|
75 | #include "MLog.h"
|
---|
76 | #include "MLogManip.h"
|
---|
77 |
|
---|
78 | #include "MArrayS.h"
|
---|
79 |
|
---|
80 | ClassImp(MRawRunHeader);
|
---|
81 |
|
---|
82 | using namespace std;
|
---|
83 |
|
---|
84 | const UShort_t MRawRunHeader::kMagicNumber = 0xc0c0;
|
---|
85 | const Byte_t MRawRunHeader::kMaxFormatVersion = 5;
|
---|
86 |
|
---|
87 | // --------------------------------------------------------------------------
|
---|
88 | //
|
---|
89 | // Default constructor. Creates array which stores the pixel assignment.
|
---|
90 | //
|
---|
91 | //
|
---|
92 | MRawRunHeader::MRawRunHeader(const char *name, const char *title) : fPixAssignment(NULL)
|
---|
93 | {
|
---|
94 | fName = name ? name : "MRawRunHeader";
|
---|
95 | fTitle = title ? title : "Raw Run Header Information";
|
---|
96 |
|
---|
97 | fPixAssignment = new MArrayS(0);
|
---|
98 |
|
---|
99 | fFormatVersion=0;
|
---|
100 | fSoftVersion=0;
|
---|
101 | fRunType=kRTNone; // use 0xffff for invalidation, 0 means: Data run
|
---|
102 | fRunNumber=0;
|
---|
103 | fProjectName[0]=0;
|
---|
104 | fSourceName[0]=0;
|
---|
105 | fSourceEpochChar[0]=0;
|
---|
106 | fSourceEpochDate=0;
|
---|
107 | fNumCrates=0;
|
---|
108 | fNumPixInCrate=0;
|
---|
109 | fNumSamplesLoGain=0;
|
---|
110 | fNumSamplesHiGain=0;
|
---|
111 | fNumEvents=0;
|
---|
112 | }
|
---|
113 |
|
---|
114 | // --------------------------------------------------------------------------
|
---|
115 | //
|
---|
116 | // Destructor. Deletes the 'pixel-assignment-array'
|
---|
117 | //
|
---|
118 | MRawRunHeader::~MRawRunHeader()
|
---|
119 | {
|
---|
120 | delete fPixAssignment;
|
---|
121 | }
|
---|
122 |
|
---|
123 | // --------------------------------------------------------------------------
|
---|
124 | //
|
---|
125 | // Read in one run header from the binary file
|
---|
126 | //
|
---|
127 | Bool_t MRawRunHeader::ReadEvt(istream& fin)
|
---|
128 | {
|
---|
129 | //
|
---|
130 | // read one RUN HEADER from the input stream
|
---|
131 | //
|
---|
132 | fMagicNumber = 0;
|
---|
133 |
|
---|
134 | fin.read((char*)&fMagicNumber, 2); // Total=2
|
---|
135 |
|
---|
136 | //
|
---|
137 | // check whether the the file has the right file type or not
|
---|
138 | //
|
---|
139 | if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
|
---|
140 | {
|
---|
141 | *fLog << err << "Error: Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
|
---|
142 | return kFALSE;
|
---|
143 | }
|
---|
144 |
|
---|
145 | if (fMagicNumber == kMagicNumber+1)
|
---|
146 | *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
|
---|
147 |
|
---|
148 | Byte_t dummy[16];
|
---|
149 |
|
---|
150 | fin.read((char*)&fFormatVersion, 2); // Total=4
|
---|
151 | if (fFormatVersion>kMaxFormatVersion)
|
---|
152 | {
|
---|
153 | *fLog << err << "WARNING - File vormat V" << fFormatVersion << " not implemented!" << endl;
|
---|
154 | return kFALSE;
|
---|
155 | }
|
---|
156 |
|
---|
157 | fin.read((char*)&fSoftVersion, 2); // Total=6
|
---|
158 | fin.read((char*)&fRunType, 2); // Total=8
|
---|
159 | fin.read((char*)&fRunNumber, 4); // Total=12
|
---|
160 | fin.read((char*)&fProjectName, 22); // Total=34
|
---|
161 | fin.read((char*)&fSourceName, 12); // Total=46
|
---|
162 | fin.read((char*)dummy, 4); // was RA (moved to tracking system)
|
---|
163 | fin.read((char*)dummy, 4); // was DEC (moved to tracking system)
|
---|
164 | fin.read((char*)&fSourceEpochChar, 2); // Total=56
|
---|
165 | fin.read((char*)&fSourceEpochDate, 2); // Total=58
|
---|
166 | if (fFormatVersion<2) // Total += 10
|
---|
167 | {
|
---|
168 | UShort_t y, m, d;
|
---|
169 | fin.read((char*)dummy, 4); // Former fMJD[4],
|
---|
170 | fin.read((char*)&y, 2); // Former fDateYear[2]
|
---|
171 | fin.read((char*)&m, 2); // Former fDateMonth[2]
|
---|
172 | fin.read((char*)&d, 2); // Former fDateDay[2]
|
---|
173 | fRunStart.Set(y, m, d, 0, 0, 0, 0);
|
---|
174 | }
|
---|
175 | fin.read((char*)&fNumCrates, 2); // Total=60
|
---|
176 | fin.read((char*)&fNumPixInCrate, 2); // Total=62
|
---|
177 | fin.read((char*)&fNumSamplesLoGain, 2); // Total=64
|
---|
178 | fin.read((char*)&fNumSamplesHiGain, 2); // Total=66
|
---|
179 | fin.read((char*)&fNumEvents, 4); // Total=70
|
---|
180 | if (fFormatVersion>1)
|
---|
181 | {
|
---|
182 | fRunStart.ReadBinary(fin); // Total += 7
|
---|
183 | fRunStop.ReadBinary(fin); // Total += 7
|
---|
184 | }
|
---|
185 |
|
---|
186 | //
|
---|
187 | // calculate size of array, create it and fill it
|
---|
188 | //
|
---|
189 | Int_t nPixel = fNumCrates*fNumPixInCrate;
|
---|
190 | fPixAssignment->Set(nPixel);
|
---|
191 |
|
---|
192 | fin.read((char*)fPixAssignment->GetArray(), nPixel*2);
|
---|
193 | fin.read((char*)&dummy, 16);
|
---|
194 |
|
---|
195 | return kTRUE;
|
---|
196 | }
|
---|
197 |
|
---|
198 | // --------------------------------------------------------------------------
|
---|
199 | //
|
---|
200 | // Return the run type as string ("Data", "Pedestal", ...), for example
|
---|
201 | // to print it as readable text.
|
---|
202 | //
|
---|
203 | const char *MRawRunHeader::GetRunTypeStr() const
|
---|
204 | {
|
---|
205 | switch (fRunType)
|
---|
206 | {
|
---|
207 | case kRTData:
|
---|
208 | return "Data";
|
---|
209 | case kRTPedestal:
|
---|
210 | return "Pedestal";
|
---|
211 | case kRTCalibration:
|
---|
212 | return "Calibration";
|
---|
213 | case kRTPointRun:
|
---|
214 | return "Point-Run";
|
---|
215 | case kRTMonteCarlo:
|
---|
216 | return "Monte Carlo";
|
---|
217 | case kRTNone:
|
---|
218 | return "<none>";
|
---|
219 | default:
|
---|
220 | return "<unknown>";
|
---|
221 | }
|
---|
222 | }
|
---|
223 |
|
---|
224 | // --------------------------------------------------------------------------
|
---|
225 | //
|
---|
226 | // print run header information on *fLog. The option 'header' supresses
|
---|
227 | // the pixel index translation table.
|
---|
228 | //
|
---|
229 | void MRawRunHeader::Print(Option_t *t) const
|
---|
230 | {
|
---|
231 | *fLog << all << endl;
|
---|
232 | *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - ";
|
---|
233 | switch (fMagicNumber)
|
---|
234 | {
|
---|
235 | case kMagicNumber: *fLog << "OK"; break;
|
---|
236 | case kMagicNumber+1: *fLog << "File not closed!"; break;
|
---|
237 | default: *fLog << "Wrong!"; break;
|
---|
238 | }
|
---|
239 | *fLog << endl;
|
---|
240 | *fLog << "Version: " << dec << "Format=" << fFormatVersion << " ";
|
---|
241 | *fLog << "Software=" << fSoftVersion << endl;
|
---|
242 | *fLog << "RunNumber: " << fRunNumber << " (Type=" << GetRunTypeStr() << ")" << endl;
|
---|
243 | *fLog << "ProjectName: '" << fProjectName << "'" << endl;
|
---|
244 | *fLog << "Source: '" << fSourceName << "' " << " ";
|
---|
245 | *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
|
---|
246 | *fLog << "Run Start: " << fRunStart << endl;
|
---|
247 | *fLog << "Run Stop: " << fRunStop << endl;
|
---|
248 | *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
|
---|
249 | *fLog << "Num Pixels: " << GetNumNormalPixels() << " (normal) + " << GetNumSpecialPixels() << " (special) = " << GetNumConnectedPixels() << " (total)" << endl;
|
---|
250 | *fLog << "Samples: " << fNumSamplesHiGain << "/" << fNumSamplesLoGain << " (hi/lo) = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate /1024 << "kB/Evt" << endl;
|
---|
251 | *fLog << "Evt Counter: " << fNumEvents << endl;
|
---|
252 |
|
---|
253 | if (TString(t).Contains("header", TString::kIgnoreCase))
|
---|
254 | return;
|
---|
255 |
|
---|
256 | *fLog << inf << hex;
|
---|
257 | for (int i=0; i<GetNumPixel(); i++)
|
---|
258 | *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
|
---|
259 |
|
---|
260 | *fLog << endl;
|
---|
261 | }
|
---|
262 |
|
---|
263 | // --------------------------------------------------------------------------
|
---|
264 | //
|
---|
265 | // Return the assigned pixel number for the given FADC channel
|
---|
266 | //
|
---|
267 | Short_t MRawRunHeader::GetPixAssignment(UShort_t i) const
|
---|
268 | {
|
---|
269 | // FIXME: Do we need a range check here?
|
---|
270 | return (Short_t)(*fPixAssignment)[i];
|
---|
271 | }
|
---|
272 |
|
---|
273 | // --------------------------------------------------------------------------
|
---|
274 | //
|
---|
275 | // Return the number of pixel which are markes as connected in the
|
---|
276 | // pix assignment (!=0)
|
---|
277 | //
|
---|
278 | UShort_t MRawRunHeader::GetNumConnectedPixels() const
|
---|
279 | {
|
---|
280 | const Int_t num = fPixAssignment->GetSize();
|
---|
281 |
|
---|
282 | UShort_t rc = 0;
|
---|
283 | for (int i=0; i<num; i++)
|
---|
284 | {
|
---|
285 | if (GetPixAssignment(i)!=0)
|
---|
286 | rc++;
|
---|
287 | }
|
---|
288 | return rc;
|
---|
289 | }
|
---|
290 |
|
---|
291 | // --------------------------------------------------------------------------
|
---|
292 | //
|
---|
293 | // Return the number of pixel which are markes as connected and so-called
|
---|
294 | // 'normal' pixels in the pix assignment (>0)
|
---|
295 | //
|
---|
296 | UShort_t MRawRunHeader::GetNumNormalPixels() const
|
---|
297 | {
|
---|
298 | const Int_t num = fPixAssignment->GetSize();
|
---|
299 |
|
---|
300 | UShort_t rc = 0;
|
---|
301 | for (int i=0; i<num; i++)
|
---|
302 | {
|
---|
303 | if (GetPixAssignment(i)>0)
|
---|
304 | rc++;
|
---|
305 | }
|
---|
306 | return rc;
|
---|
307 | }
|
---|
308 |
|
---|
309 | // --------------------------------------------------------------------------
|
---|
310 | //
|
---|
311 | // Return the number of pixel which are markes as connected and so-called
|
---|
312 | // 'special' pixels in the pix assignment (<0)
|
---|
313 | //
|
---|
314 | UShort_t MRawRunHeader::GetNumSpecialPixels() const
|
---|
315 | {
|
---|
316 | const Int_t num = fPixAssignment->GetSize();
|
---|
317 |
|
---|
318 | UShort_t rc = 0;
|
---|
319 | for (int i=0; i<num; i++)
|
---|
320 | {
|
---|
321 | if (GetPixAssignment(i)<0)
|
---|
322 | rc++;
|
---|
323 | }
|
---|
324 | return rc;
|
---|
325 | }
|
---|
326 |
|
---|
327 | // --------------------------------------------------------------------------
|
---|
328 | //
|
---|
329 | // Return the maximum id which exists in the pix assignment
|
---|
330 | //
|
---|
331 | UShort_t MRawRunHeader::GetMaxPixId() const
|
---|
332 | {
|
---|
333 | const Int_t num = fPixAssignment->GetSize();
|
---|
334 |
|
---|
335 | Short_t rc = 0;
|
---|
336 | for (int i=0; i<num; i++)
|
---|
337 | rc = TMath::Max(GetPixAssignment(i), rc);
|
---|
338 |
|
---|
339 | return rc;
|
---|
340 | }
|
---|
341 |
|
---|
342 | // --------------------------------------------------------------------------
|
---|
343 | //
|
---|
344 | // Return minus th minimum id which exists in the pix assignment
|
---|
345 | //
|
---|
346 | UShort_t MRawRunHeader::GetMinPixId() const
|
---|
347 | {
|
---|
348 | const Int_t num = fPixAssignment->GetSize();
|
---|
349 |
|
---|
350 | Short_t rc = 0;
|
---|
351 | for (int i=0; i<num; i++)
|
---|
352 | rc = TMath::Min(GetPixAssignment(i), rc);
|
---|
353 |
|
---|
354 | return (UShort_t)-rc;
|
---|
355 | }
|
---|
356 |
|
---|
357 | // --------------------------------------------------------------------------
|
---|
358 | //
|
---|
359 | // Return the number of pixel in this event.
|
---|
360 | //
|
---|
361 | // WARNING: This is the number of pixels stored in this file which is
|
---|
362 | // a multiple of the number of pixels per crate and in general
|
---|
363 | // a number which is larger than the camera size!
|
---|
364 | //
|
---|
365 | // To know the range of the pixel indices please use the geometry
|
---|
366 | // container!
|
---|
367 | //
|
---|
368 | UShort_t MRawRunHeader::GetNumPixel() const
|
---|
369 | {
|
---|
370 | return fPixAssignment->GetSize();
|
---|
371 | }
|
---|
372 |
|
---|
373 | // --------------------------------------------------------------------------
|
---|
374 | //
|
---|
375 | // Returns absolute size in bytes of the run header as read from a raw file.
|
---|
376 | // This must be done _after_ the header is read, because the header doesn't
|
---|
377 | // have a fixed size (used in MRawSocketRead)
|
---|
378 | //
|
---|
379 | Int_t MRawRunHeader::GetNumTotalBytes() const
|
---|
380 | {
|
---|
381 | switch (fFormatVersion)
|
---|
382 | {
|
---|
383 | case 1:
|
---|
384 | return 80+fNumCrates*fNumPixInCrate*2+16;
|
---|
385 | case 2:
|
---|
386 | return 84+fNumCrates*fNumPixInCrate*2+16;
|
---|
387 | }
|
---|
388 | return 0;
|
---|
389 | }
|
---|