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-2008
|
---|
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 11:
|
---|
36 | // -----------------
|
---|
37 | // * all variables got four bytes
|
---|
38 | // * header sizes allow to make the format backward compatible
|
---|
39 | // + fHeaderSizeRun
|
---|
40 | // + fHeaderSizeEvt
|
---|
41 | // + fHeaderSizeCrate
|
---|
42 | // + fFileNumber
|
---|
43 | // + fNumSamplesRemovedHead
|
---|
44 | // + fNumSamplesRemovedTail
|
---|
45 | //
|
---|
46 | // Format Version 10:
|
---|
47 | // -----------------
|
---|
48 | // ?
|
---|
49 | //
|
---|
50 | // Format Version 9:
|
---|
51 | // -----------------
|
---|
52 | // + fNumEventsRead;
|
---|
53 | // + fSamplingFrequency
|
---|
54 | // - fFreqSampling
|
---|
55 | // + fFadcResolution;
|
---|
56 | // - fNumSignificantBits
|
---|
57 | //
|
---|
58 | // Format Version 8:
|
---|
59 | // -----------------
|
---|
60 | // + fNumBytesPerSample;
|
---|
61 | // + fFreqSampling;
|
---|
62 | // + fNumSignificantBits
|
---|
63 | // * changes in MRawCrateHeader
|
---|
64 | //
|
---|
65 | // Format Version 7:
|
---|
66 | // -----------------
|
---|
67 | // - unused
|
---|
68 | //
|
---|
69 | // Format Version 6:
|
---|
70 | // -----------------
|
---|
71 | // + added CameraVersion
|
---|
72 | // + added TelescopeNumber
|
---|
73 | // + added ObservationMode
|
---|
74 | // + added dummies for TelescopeRa/Dec
|
---|
75 | //
|
---|
76 | // Format Version 5:
|
---|
77 | // -----------------
|
---|
78 | // - now the sub millisecond information of the time is valid and decoded
|
---|
79 | // which enhances the precision from 51.2us to 200ns
|
---|
80 | //
|
---|
81 | // Format Version 4:
|
---|
82 | // -----------------
|
---|
83 | // - added support for pixels with negative IDs
|
---|
84 | //
|
---|
85 | // Format Version 3:
|
---|
86 | // -----------------
|
---|
87 | // - ???
|
---|
88 | //
|
---|
89 | // Format Version 2:
|
---|
90 | // -----------------
|
---|
91 | // - removed mjd from data
|
---|
92 | // - added start time
|
---|
93 | // - added stop time
|
---|
94 | //
|
---|
95 | //
|
---|
96 | // MRawRunHeader CLASS VERSION
|
---|
97 | // ===========================
|
---|
98 | //
|
---|
99 | // Format Version 10:
|
---|
100 | // -----------------
|
---|
101 | // - added fHeaderSizeRun
|
---|
102 | // - added fHeaderSizeEvt
|
---|
103 | // - added fHeaderSizeCrate
|
---|
104 | // - added fFileNumber
|
---|
105 | // - increased fSourceEpochChar
|
---|
106 | //
|
---|
107 | // Format Version 7:
|
---|
108 | // -----------------
|
---|
109 | // - added fNumEventsRead;
|
---|
110 | // * renamed fFreqSampling to fSamplingFrequency
|
---|
111 | // * renamed fNumSignificantBits to fFadcResolution
|
---|
112 | //
|
---|
113 | // Format Version 6:
|
---|
114 | // -----------------
|
---|
115 | // - added fNumBytesPerSample;
|
---|
116 | // - added fSamplingFrequency;
|
---|
117 | // - added fFadcResolution;
|
---|
118 | //
|
---|
119 | // Class Version 5:
|
---|
120 | // -----------------
|
---|
121 | // - for compatibility with newer camera versions
|
---|
122 | //
|
---|
123 | // Class Version 4:
|
---|
124 | // -----------------
|
---|
125 | // - added fCameraVersion
|
---|
126 | // - added fTelescopeNumber
|
---|
127 | // - changed length of fProjectName to 101
|
---|
128 | // - changed length of fSourceName to 81
|
---|
129 | //
|
---|
130 | // Class Version 3:
|
---|
131 | // ----------------
|
---|
132 | // - enhanced SourceName and ProjectName by one character, because
|
---|
133 | // without telling us the guranteed trailing \0-character has
|
---|
134 | // skipped
|
---|
135 | //
|
---|
136 | // Class Version 2:
|
---|
137 | // ----------------
|
---|
138 | // - removed fMJD, fYear, fMonth, fDay
|
---|
139 | // - added fRunStart
|
---|
140 | // - added fRunStop
|
---|
141 | //
|
---|
142 | // Class Version 1:
|
---|
143 | // ----------------
|
---|
144 | // - first implementation
|
---|
145 | //
|
---|
146 | ////////////////////////////////////////////////////////////////////////////
|
---|
147 | #include "MRawRunHeader.h"
|
---|
148 |
|
---|
149 | #include <fstream>
|
---|
150 | #include <iomanip>
|
---|
151 |
|
---|
152 | #include <TArrayC.h>
|
---|
153 |
|
---|
154 | #include "MLog.h"
|
---|
155 | #include "MLogManip.h"
|
---|
156 |
|
---|
157 | #include "MArrayS.h"
|
---|
158 | #include "MString.h"
|
---|
159 |
|
---|
160 | ClassImp(MRawRunHeader);
|
---|
161 |
|
---|
162 | using namespace std;
|
---|
163 |
|
---|
164 | const UShort_t MRawRunHeader::kMagicNumber = 0xc0c0;
|
---|
165 | const Byte_t MRawRunHeader::kMaxFormatVersion = 11;
|
---|
166 |
|
---|
167 | // --------------------------------------------------------------------------
|
---|
168 | //
|
---|
169 | // Default constructor. Creates array which stores the pixel assignment.
|
---|
170 | //
|
---|
171 | //
|
---|
172 | MRawRunHeader::MRawRunHeader(const char *name, const char *title) : fPixAssignment(NULL)
|
---|
173 | {
|
---|
174 | fName = name ? name : "MRawRunHeader";
|
---|
175 | fTitle = title ? title : "Raw Run Header Information";
|
---|
176 |
|
---|
177 | fPixAssignment = new MArrayS(0);
|
---|
178 |
|
---|
179 | // Remark: If we read old MC data from a root file which do not
|
---|
180 | // yet contain one of these variable, the value given here is
|
---|
181 | // the default. Do not mix files with and without a value if the
|
---|
182 | // files with the value do not match the default!
|
---|
183 | fFormatVersion=0;
|
---|
184 | fSoftVersion=0;
|
---|
185 | fTelescopeNumber=1;
|
---|
186 | fCameraVersion=1;
|
---|
187 | fFadcType=1;
|
---|
188 | fRunType=kRTNone; // use 0xffff for invalidation, 0 means: Data run
|
---|
189 | fRunNumber=0;
|
---|
190 | fFileNumber=0;
|
---|
191 | memset(fProjectName, 0, 101);
|
---|
192 | memset(fSourceName, 0, 81);
|
---|
193 | memset(fObservationMode, 0, 61);
|
---|
194 | fSourceEpochChar[0]=0;
|
---|
195 | fSourceEpochDate=0;
|
---|
196 | fNumCrates=0;
|
---|
197 | fNumPixInCrate=0;
|
---|
198 | fNumSamplesLoGain=0;
|
---|
199 | fNumSamplesHiGain=0;
|
---|
200 | fNumEvents=0;
|
---|
201 | fNumBytesPerSample=1;
|
---|
202 | fSamplingFrequency=300;
|
---|
203 | fFadcResolution=8;
|
---|
204 | }
|
---|
205 |
|
---|
206 | // --------------------------------------------------------------------------
|
---|
207 | //
|
---|
208 | // Destructor. Deletes the 'pixel-assignment-array'
|
---|
209 | //
|
---|
210 | MRawRunHeader::~MRawRunHeader()
|
---|
211 | {
|
---|
212 | delete fPixAssignment;
|
---|
213 | }
|
---|
214 |
|
---|
215 | // --------------------------------------------------------------------------
|
---|
216 | //
|
---|
217 | // Swap the assignment of the pixels with hardware id id0 and id1
|
---|
218 | //
|
---|
219 | Bool_t MRawRunHeader::SwapAssignment(Short_t id0, Short_t id1)
|
---|
220 | {
|
---|
221 | const Int_t n = fPixAssignment->GetSize();
|
---|
222 |
|
---|
223 | // Look-up-table
|
---|
224 | UShort_t *lut = fPixAssignment->GetArray();
|
---|
225 |
|
---|
226 | // Search for one of the hardware indices to get exchanged
|
---|
227 | int i;
|
---|
228 | for (i=0; i<n; i++)
|
---|
229 | if (lut[i]==id0 || lut[i]==id1)
|
---|
230 | break;
|
---|
231 |
|
---|
232 | // Check if one of the two pixels were found
|
---|
233 | if (i==n)
|
---|
234 | {
|
---|
235 | *fLog << warn << "WARNING - Assignment of pixels with hardware ID " << id0 << " and " << id1;
|
---|
236 | *fLog << " should be exchanged, but none were found." << endl;
|
---|
237 | return kTRUE;
|
---|
238 | }
|
---|
239 |
|
---|
240 | // Store first index
|
---|
241 | const Int_t idx0 = i;
|
---|
242 |
|
---|
243 | // Search for the other hardware indices to get exchanged
|
---|
244 | for (i++; i<n; i++)
|
---|
245 | if (lut[i]==id0 || lut[i]==id1)
|
---|
246 | break;
|
---|
247 |
|
---|
248 | // Check if the second pixel was found
|
---|
249 | if (i==n)
|
---|
250 | {
|
---|
251 | *fLog << err << "ERROR - Assignment of pixels with hardware ID " << id0 << " and " << id1;
|
---|
252 | *fLog << " should be exchanged, but only one was found." << endl;
|
---|
253 | return kFALSE;
|
---|
254 | }
|
---|
255 |
|
---|
256 | const Int_t idx1 = i;
|
---|
257 |
|
---|
258 | const Short_t p0 = lut[idx0];
|
---|
259 | const Short_t p1 = lut[idx1];
|
---|
260 |
|
---|
261 | lut[idx0] = p1;
|
---|
262 | lut[idx1] = p0;
|
---|
263 |
|
---|
264 | *fLog << inf << "Assignment of pixels with hardware ID " << id0 << " and " << id1 << " exchanged." << endl;
|
---|
265 |
|
---|
266 | return kTRUE;
|
---|
267 | }
|
---|
268 |
|
---|
269 | // --------------------------------------------------------------------------
|
---|
270 | //
|
---|
271 | // Return Telescope number, runnumber and filenumber on the form:
|
---|
272 | // run
|
---|
273 | // as string for runnumber<1000000 and
|
---|
274 | // telescope:run/file
|
---|
275 | // otherwise.
|
---|
276 | //
|
---|
277 | TString MRawRunHeader::GetStringID() const
|
---|
278 | {
|
---|
279 | return fRunNumber<1000000?MString::Format("%d", fRunNumber):MString::Format("%d:%d/%d", fTelescopeNumber, fRunNumber, fFileNumber);
|
---|
280 | }
|
---|
281 |
|
---|
282 | // --------------------------------------------------------------------------
|
---|
283 | //
|
---|
284 | // Consistency checks. See code for detils.
|
---|
285 | //
|
---|
286 | Bool_t MRawRunHeader::IsConsistent() const
|
---|
287 | {
|
---|
288 | // FIXME: Match first digits of run-number with telescope number
|
---|
289 |
|
---|
290 | if (fFormatVersion>10)
|
---|
291 | {
|
---|
292 | if (GetTypeID()!=fTelescopeNumber &&
|
---|
293 | GetTypeID()!=fTelescopeNumber*10U &&
|
---|
294 | GetTypeID()!=fTelescopeNumber*10U+5U)
|
---|
295 | {
|
---|
296 | *fLog << err << "ERROR - Telscope number " << fTelescopeNumber << " doesn't match the first two digits of the run number " << fRunNumber << "." << endl;
|
---|
297 | return kFALSE;
|
---|
298 | }
|
---|
299 |
|
---|
300 | // Old formats can not contain a run number larger 0
|
---|
301 | if (fRunNumber<1000000)
|
---|
302 | {
|
---|
303 | *fLog << err << "ERROR - Run number " << fRunNumber << " smaller than 1000000." << endl;
|
---|
304 | return kFALSE;
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | // Check for correct number of bytes in data stream
|
---|
309 | if (fFormatVersion>7 && fNumBytesPerSample!=2)
|
---|
310 | {
|
---|
311 | *fLog << err << "ERROR - " << fNumBytesPerSample << " bytes per sample are not supported!" << endl;
|
---|
312 | return kFALSE;
|
---|
313 | }
|
---|
314 |
|
---|
315 | // If we have a vlid stop time check its consistency with the start time
|
---|
316 | if (fRunStop!=MTime() && fRunStop<fRunStart)
|
---|
317 | {
|
---|
318 | *fLog << err << "ERROR - Stop time smaller than start time." << endl;
|
---|
319 | return kFALSE;
|
---|
320 | }
|
---|
321 |
|
---|
322 | // No file numbers larger than 999 allowed in general
|
---|
323 | if (fFileNumber>999)
|
---|
324 | {
|
---|
325 | *fLog << err << "ERROR - File number " << fFileNumber << " larger than 999." << endl;
|
---|
326 | return kFALSE;
|
---|
327 | }
|
---|
328 |
|
---|
329 | // Old formats can not contain a run number larger 0
|
---|
330 | if (fFormatVersion<11 && fFileNumber>0)
|
---|
331 | {
|
---|
332 | *fLog << err << "ERROR - File number " << fFileNumber << " larger than 0." << endl;
|
---|
333 | return kFALSE;
|
---|
334 | }
|
---|
335 |
|
---|
336 | if (fFormatVersion>1)
|
---|
337 | {
|
---|
338 | // For most of the formats the start time must be valid
|
---|
339 | if (fRunStart==MTime())
|
---|
340 | {
|
---|
341 | *fLog << err << "ERROR - Start time invalid." << endl;
|
---|
342 | return kFALSE;
|
---|
343 | }
|
---|
344 |
|
---|
345 | // For most of the formats an invalid stop time cannot happen if file closed
|
---|
346 | if (fMagicNumber==kMagicNumber && fRunStop==MTime())
|
---|
347 | {
|
---|
348 | *fLog << err << "ERROR - File closed but stop time invalid." << endl;
|
---|
349 | return kFALSE;
|
---|
350 | }
|
---|
351 | }
|
---|
352 | return kTRUE;
|
---|
353 | }
|
---|
354 |
|
---|
355 | // --------------------------------------------------------------------------
|
---|
356 | //
|
---|
357 | // This implements a fix of the pixel assignment before 25.9.2005
|
---|
358 | //
|
---|
359 | // From magic_online (the pixel numbers are hardware indices):
|
---|
360 | // --------------------------------------------------------------------------
|
---|
361 | // From: Florian Goebel <fgoebel@mppmu.mpg.de>
|
---|
362 | // Date: Sun Sep 25 2005 - 05:13:19 CEST
|
---|
363 | //
|
---|
364 | // [...]
|
---|
365 | // - problem 2: pixels were swaped
|
---|
366 | // - cause: opical fibers were wrongly connected to receiver board
|
---|
367 | // 554 <-> 559
|
---|
368 | // 555 <-> 558
|
---|
369 | // 556 <-> 557
|
---|
370 | // - action: reconnect correctly
|
---|
371 | // - result: ok now
|
---|
372 | // - comment: I don't know when this error was introduced, so backward
|
---|
373 | // correction of the data is difficult.
|
---|
374 | // Fortunately the effect is not too large since the affected 6 pixels are
|
---|
375 | // on the outermost edge of the camera
|
---|
376 | // Since this board has special pixels the optical fibers have been
|
---|
377 | // unplugged several times.
|
---|
378 | // !!!!! Whenever you unplug and reconnect optical fibers make really !!!!!
|
---|
379 | // !!!!! sure you connect them back correctly. !!!!!
|
---|
380 | // !!!!! Always contact me before you do so and if you have any doubts !!!!!
|
---|
381 | // !!!!! how to reconnect the fibers ask me. !!!!!
|
---|
382 | // These swapped pixels have only been found by chance when doing the
|
---|
383 | // flatfielding.
|
---|
384 | // [...]
|
---|
385 | //
|
---|
386 | // --------------------------------------------------------------------------
|
---|
387 | //
|
---|
388 | // MAGIC runbook CC_2006_04_22_22_28_52.rbk
|
---|
389 | //
|
---|
390 | // [2006-04-22 23:14:13]
|
---|
391 | //
|
---|
392 | // [...]
|
---|
393 | // Found 2 pairs of swapped pixels.
|
---|
394 | // We corrected swapped pixels 54<->55 in the receiver boards. We probably
|
---|
395 | // swapped today in the camera.
|
---|
396 | // We did not correct 92<-<93 which are likely swapped. Will check and correct
|
---|
397 | // tomorrow.
|
---|
398 | //
|
---|
399 | // ---
|
---|
400 | //
|
---|
401 | // comments:
|
---|
402 | // - 54<->55 were corrected but have not been swapped, hence they are swapped
|
---|
403 | // since then (run 88560 ok, run 88669 swapped; between them mostly dummy and
|
---|
404 | // test runs)
|
---|
405 | // - 92<->93 are never swapped, always ok.
|
---|
406 | //
|
---|
407 | // --------------------------------------------------------------------------
|
---|
408 | //
|
---|
409 | // MAGIC runbook CC_2006_08_28_19_40_18.rbk
|
---|
410 | //
|
---|
411 | // [2006-08-28 23:09:07]
|
---|
412 | // While doing a flatfielding we have found out that the signals for pixels
|
---|
413 | // 119 and 120 were swapped. We have fixed it by exchanging the corresponding
|
---|
414 | // fibers at the input of the receivers (not before the splitters!).
|
---|
415 | //
|
---|
416 | // ---
|
---|
417 | //
|
---|
418 | // MAGIC runbook CC_2006_08_29_15_19_14.rbk
|
---|
419 | //
|
---|
420 | // [2006-08-29 16:43:09]
|
---|
421 | // In the last hours we have found out and fixed a good number of pixels which
|
---|
422 | // were swapped: 119-120, 160-161-162 and 210-263. According to Florian,
|
---|
423 | // 160-161-162 and 210-263 were swapped since November 2005.
|
---|
424 | //
|
---|
425 | // ---
|
---|
426 | //
|
---|
427 | // mail Florian Goebel (08/30/2006 03:13 PM):
|
---|
428 | //
|
---|
429 | // As far as I can tell pixels 161 and 162 as well as 263 and 210 were
|
---|
430 | // swapped in the trigger. This leads to some inefficiency of the trigger.
|
---|
431 | // However, they were not swapped in the readout. So, you don't have to
|
---|
432 | // correct anything in the data for these pixels.
|
---|
433 | //
|
---|
434 | // ---
|
---|
435 | //
|
---|
436 | // comments:
|
---|
437 | // - 119-120 swapped between run 93251 (not swapped) and 93283 (swapped)
|
---|
438 | // (only testruns between these runs)
|
---|
439 | // corrected since run 99354 (== runbook [2006-08-28 23:09:07])
|
---|
440 | // - 160 never swapped
|
---|
441 | // - 161-162 were only swapped in the trigger, but nevertheless were
|
---|
442 | // "corrected" also in the signal. Hence signal swapped since 99354
|
---|
443 | //
|
---|
444 | Bool_t MRawRunHeader::FixAssignment()
|
---|
445 | {
|
---|
446 | if (fRunNumber>=53300 && fRunNumber<=68754)
|
---|
447 | {
|
---|
448 | if (!SwapAssignment(554, 559))
|
---|
449 | return kFALSE;
|
---|
450 | if (!SwapAssignment(555, 558))
|
---|
451 | return kFALSE;
|
---|
452 | if (!SwapAssignment(556, 557))
|
---|
453 | return kFALSE;
|
---|
454 | }
|
---|
455 |
|
---|
456 | if (fRunNumber>=93283 && fRunNumber<99354)
|
---|
457 | {
|
---|
458 | if (!SwapAssignment(119, 120))
|
---|
459 | return kFALSE;
|
---|
460 | }
|
---|
461 |
|
---|
462 | if (fRunNumber>=99354 && fRunNumber<=101789)
|
---|
463 | {
|
---|
464 | if (!SwapAssignment(161, 162))
|
---|
465 | return kFALSE;
|
---|
466 | if (!SwapAssignment(210, 263))
|
---|
467 | return kFALSE;
|
---|
468 | }
|
---|
469 |
|
---|
470 | if (fRunNumber>=88669)
|
---|
471 | {
|
---|
472 | if (!SwapAssignment(54, 55))
|
---|
473 | return kFALSE;
|
---|
474 | }
|
---|
475 |
|
---|
476 | if (fRunNumber>=200000)
|
---|
477 | {
|
---|
478 | if (!SwapAssignment(428, 429))
|
---|
479 | return kFALSE;
|
---|
480 | }
|
---|
481 |
|
---|
482 | return kTRUE;
|
---|
483 | }
|
---|
484 |
|
---|
485 | // --------------------------------------------------------------------------
|
---|
486 | //
|
---|
487 | // Fixes to fix bugs in the run header
|
---|
488 | //
|
---|
489 | Bool_t MRawRunHeader::Fixes()
|
---|
490 | {
|
---|
491 | if (fFormatVersion>8)
|
---|
492 | {
|
---|
493 | fNumEvents--;
|
---|
494 | fNumEventsRead--;
|
---|
495 | *fLog << inf << "Format >V8: Stored number of events decreased by 1." << endl;
|
---|
496 | }
|
---|
497 |
|
---|
498 | return FixAssignment();
|
---|
499 | }
|
---|
500 |
|
---|
501 | // --------------------------------------------------------------------------
|
---|
502 | //
|
---|
503 | // Reading function to read/interpret the file formats 1-10
|
---|
504 | //
|
---|
505 | Bool_t MRawRunHeader::ReadEvtOld(istream& fin)
|
---|
506 | {
|
---|
507 | if (fFormatVersion==7)
|
---|
508 | {
|
---|
509 | *fLog << err << "ERROR - File format V7 was for testing only and is not correctly implemented!" << endl;
|
---|
510 | return kFALSE;
|
---|
511 | }
|
---|
512 |
|
---|
513 | // ----- DAQ software format version -----
|
---|
514 | fin.read((char*)&fSoftVersion, 2); // Total=6
|
---|
515 |
|
---|
516 |
|
---|
517 | fFadcType = 1;
|
---|
518 | if (fFormatVersion>7)
|
---|
519 | fin.read((char*)&fFadcType, 2);
|
---|
520 |
|
---|
521 | // ----- Camera geometry and telescope number -----
|
---|
522 | fCameraVersion = 1;
|
---|
523 | fTelescopeNumber = 1;
|
---|
524 | if (fFormatVersion>5)
|
---|
525 | {
|
---|
526 | fin.read((char*)&fCameraVersion, 2); // (+2)
|
---|
527 | fin.read((char*)&fTelescopeNumber, 2); // (+2)
|
---|
528 | }
|
---|
529 |
|
---|
530 | // ----- Run information -----
|
---|
531 | fin.read((char*)&fRunType, 2); // Total=8
|
---|
532 |
|
---|
533 | fin.read((char*)&fRunNumber, 4); // Total=12
|
---|
534 | fin.read((char*)&fProjectName, fFormatVersion>5?100:22); // Total=34 (+78)
|
---|
535 | fin.read((char*)&fSourceName, fFormatVersion>5? 80:12); // Total=46 (+58)
|
---|
536 |
|
---|
537 | if (fFormatVersion>5)
|
---|
538 | fin.read((char*)fObservationMode, 60); // (+60)
|
---|
539 | // Maybe we should set fObservationMode to something
|
---|
540 | // in case of fFormatVersion<6
|
---|
541 |
|
---|
542 | // ----- Source position -----
|
---|
543 | fin.seekg(fFormatVersion>5 ? 16 : 8, ios::cur);
|
---|
544 | /*
|
---|
545 | if (fFormatVersion>5)
|
---|
546 | {
|
---|
547 | fin.read((char*)&fSourceRa, 4); // F32 SourceRA; Total=48
|
---|
548 | fin.read((char*)&fSourceDec, 4); // F32 SourceDEC; Total=52
|
---|
549 | }
|
---|
550 | fin.read((char*)&fTelescopeRa, 4); // F32 TelescopeRA; (+4)
|
---|
551 | fin.read((char*)&fTelescopeDec, 4); // F32 TelescopeDEC; (+4)
|
---|
552 | */
|
---|
553 |
|
---|
554 | // Maybe we should set these to something
|
---|
555 | // in case of fFormatVersion<6
|
---|
556 | fin.read((char*)&fSourceEpochChar, 2); // Total=56
|
---|
557 | fin.read((char*)&fSourceEpochDate, 2); // Total=58
|
---|
558 |
|
---|
559 | // ----- Old Start time -----
|
---|
560 | if (fFormatVersion<2) // Total += 10
|
---|
561 | {
|
---|
562 | UShort_t y, m, d;
|
---|
563 | fin.seekg(4, ios::cur); // Former fMJD[4],
|
---|
564 | fin.read((char*)&y, 2); // Former fDateYear[2]
|
---|
565 | fin.read((char*)&m, 2); // Former fDateMonth[2]
|
---|
566 | fin.read((char*)&d, 2); // Former fDateDay[2]
|
---|
567 | fRunStart.Set(y, m, d, 0, 0, 0, 0);
|
---|
568 | }
|
---|
569 |
|
---|
570 | // ----- Data Geometry -----
|
---|
571 |
|
---|
572 | fin.read((char*)&fNumCrates, 2); // MUX: number of channels
|
---|
573 | fin.read((char*)&fNumPixInCrate, 2); // MUX: number of pix in channel
|
---|
574 | fin.read((char*)&fNumSamplesLoGain, 2); // MUX: dummy (must be 0 for MUX data)
|
---|
575 | fin.read((char*)&fNumSamplesHiGain, 2); // MUX: Number of samples per pixel
|
---|
576 |
|
---|
577 | char dummy[16];
|
---|
578 | if (fFormatVersion>8)
|
---|
579 | fin.read(dummy, 4); // 2xU16 (NumSamplesRemovedHead and NumSamplesRemovedTail)
|
---|
580 |
|
---|
581 | // ----- Number of events -----
|
---|
582 | fin.read((char*)&fNumEvents, 4); // Total=70
|
---|
583 |
|
---|
584 | if (fFormatVersion>8)
|
---|
585 | fin.read((char*)&fNumEventsRead, 4);
|
---|
586 |
|
---|
587 | // New in general features: (should they be included in new MAGIC1 formats, too?)
|
---|
588 | fNumBytesPerSample = 1; // 2 for MUX DATA
|
---|
589 | fSamplingFrequency = 300;
|
---|
590 | fFadcResolution = 8;
|
---|
591 |
|
---|
592 | if (fFormatVersion>7)
|
---|
593 | {
|
---|
594 | fin.read((char*)&fNumBytesPerSample, 2);
|
---|
595 | fin.read((char*)&fSamplingFrequency, 2); // [MHz], 2000 for MuxFadc
|
---|
596 | fin.read((char*)&fFadcResolution, 1); // nominal resolution [# Bits], 10 for MuxFadc
|
---|
597 | }
|
---|
598 |
|
---|
599 | // ----- Start/Stop time -----
|
---|
600 | if (fFormatVersion>1)
|
---|
601 | {
|
---|
602 | fRunStart.ReadBinary(fin); // Total += 7
|
---|
603 | fRunStop.ReadBinary(fin); // Total += 7
|
---|
604 | }
|
---|
605 |
|
---|
606 | // ----- Consistency checks -----
|
---|
607 | if (!IsConsistent())
|
---|
608 | return kFALSE;
|
---|
609 |
|
---|
610 | //
|
---|
611 | // calculate size of array, create it and fill it
|
---|
612 | //
|
---|
613 | const Int_t nPixel = fNumCrates*fNumPixInCrate;
|
---|
614 | fPixAssignment->Set(nPixel);
|
---|
615 |
|
---|
616 | // ----- Pixel Assignement -----
|
---|
617 | fin.read((char*)fPixAssignment->GetArray(), nPixel*2);
|
---|
618 |
|
---|
619 | if (fFormatVersion<7)
|
---|
620 | fin.read(dummy, 16);
|
---|
621 |
|
---|
622 | return Fixes();
|
---|
623 | }
|
---|
624 |
|
---|
625 | // --------------------------------------------------------------------------
|
---|
626 | //
|
---|
627 | // Read in one run header from the binary file
|
---|
628 | //
|
---|
629 | Bool_t MRawRunHeader::ReadEvt(istream& fin)
|
---|
630 | {
|
---|
631 | //
|
---|
632 | // read one RUN HEADER from the input stream
|
---|
633 | //
|
---|
634 | fMagicNumber = 0;
|
---|
635 |
|
---|
636 | fin.read((char*)&fMagicNumber, 2); // Total=2
|
---|
637 |
|
---|
638 | //
|
---|
639 | // check whether the the file has the right file type or not
|
---|
640 | //
|
---|
641 | if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
|
---|
642 | {
|
---|
643 | *fLog << err << "ERROR - Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
|
---|
644 | return kFALSE;
|
---|
645 | }
|
---|
646 |
|
---|
647 | if (fMagicNumber == kMagicNumber+1)
|
---|
648 | *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
|
---|
649 |
|
---|
650 | // ----- File format version -----
|
---|
651 | fin.read((char*)&fFormatVersion, 2); // Total=4
|
---|
652 | if (fFormatVersion==10 || fFormatVersion>kMaxFormatVersion)
|
---|
653 | {
|
---|
654 | *fLog << err << "ERROR - File format V" << fFormatVersion << " not implemented!" << endl;
|
---|
655 | return kFALSE;
|
---|
656 | }
|
---|
657 |
|
---|
658 | // ----- Process old file formats -----
|
---|
659 | if (fFormatVersion<10)
|
---|
660 | return ReadEvtOld(fin);
|
---|
661 |
|
---|
662 | // ----- Overwrite format version for format 11 -----
|
---|
663 | fin.read((char*)&fFormatVersion, 4);
|
---|
664 | if (fFormatVersion<11)
|
---|
665 | {
|
---|
666 | *fLog << err << "ERROR - Format Version <11." << endl;
|
---|
667 | return kFALSE;
|
---|
668 | }
|
---|
669 |
|
---|
670 | // ----- Read Header by size as written in the header -----
|
---|
671 | fin.read((char*)&fHeaderSizeRun, 4);
|
---|
672 | if (fHeaderSizeRun<346)
|
---|
673 | {
|
---|
674 | *fLog << err << "ERROR - Event header too small (<388b)." << endl;
|
---|
675 | return kFALSE;
|
---|
676 | }
|
---|
677 |
|
---|
678 | TArrayC h(fHeaderSizeRun-12);
|
---|
679 | fin.read(h.GetArray(), h.GetSize());
|
---|
680 | if (!fin)
|
---|
681 | return kFALSE;
|
---|
682 |
|
---|
683 | // ----- convert -----
|
---|
684 | const Byte_t *Char = reinterpret_cast<Byte_t* >(h.GetArray());
|
---|
685 | const UInt_t *Int = reinterpret_cast<UInt_t* >(h.GetArray());
|
---|
686 | //const Float_t *Float = reinterpret_cast<Float_t*>(h.GetArray());
|
---|
687 |
|
---|
688 | // ----- Start interpretation -----
|
---|
689 |
|
---|
690 | fHeaderSizeEvt = Int[0];
|
---|
691 | fHeaderSizeCrate = Int[1];
|
---|
692 | fSoftVersion = Int[2];
|
---|
693 | fFadcType = Int[3];
|
---|
694 | fCameraVersion = Int[4];
|
---|
695 | fTelescopeNumber = Int[5];
|
---|
696 | fRunType = Int[6];
|
---|
697 | fRunNumber = Int[7];
|
---|
698 | fFileNumber = Int[8];
|
---|
699 |
|
---|
700 | memcpy(fProjectName, Char+ 36, 100); // 25
|
---|
701 | memcpy(fSourceName, Char+136, 80); // 20
|
---|
702 | memcpy(fObservationMode, Char+216, 60); // 15
|
---|
703 |
|
---|
704 | //F32 fSourceRA = Float[69];
|
---|
705 | //F32 fSourceDEC = Float[70];
|
---|
706 | //F32 fTelescopeRA = Float[71];
|
---|
707 | //F32 fTelescopeDEC = Float[72];
|
---|
708 |
|
---|
709 | memcpy(fSourceEpochChar, Char+232, 4);
|
---|
710 |
|
---|
711 | fSourceEpochDate = Int[74];
|
---|
712 | fNumCrates = Int[75];
|
---|
713 | fNumPixInCrate = Int[76];
|
---|
714 | fNumSamplesHiGain = Int[77];
|
---|
715 | fNumSamplesLoGain = 0;
|
---|
716 |
|
---|
717 | //fNumSamplesRemovedHead = Int[78];
|
---|
718 | //fNumSamplesRemovedTail = Int[79];
|
---|
719 |
|
---|
720 | fNumEvents = Int[80];
|
---|
721 | fNumEventsRead = Int[81];
|
---|
722 | fNumBytesPerSample = Int[82];
|
---|
723 | fSamplingFrequency = Int[83];
|
---|
724 | fFadcResolution = Int[84];
|
---|
725 |
|
---|
726 | fRunStart.SetBinary(Int+85);
|
---|
727 | fRunStop.SetBinary(Int+91);
|
---|
728 |
|
---|
729 | // ----- Consistency checks -----
|
---|
730 | if (!IsConsistent())
|
---|
731 | return kFALSE;
|
---|
732 |
|
---|
733 | // ----- 388 bytes so far -----
|
---|
734 |
|
---|
735 | const UInt_t n = fNumCrates*fNumPixInCrate;
|
---|
736 | if (fHeaderSizeRun<388+n*4)
|
---|
737 | {
|
---|
738 | *fLog << err << "ERROR - Event header too small to contain pix assignment." << endl;
|
---|
739 | return kFALSE;
|
---|
740 | }
|
---|
741 |
|
---|
742 | // ----- Pixel Assignment -----
|
---|
743 | fPixAssignment->Set(n);
|
---|
744 |
|
---|
745 | for (UInt_t i=0; i<n; i++)
|
---|
746 | (*fPixAssignment)[i] = Int[97+i];
|
---|
747 |
|
---|
748 | return Fixes();
|
---|
749 | }
|
---|
750 |
|
---|
751 | // --------------------------------------------------------------------------
|
---|
752 | //
|
---|
753 | // Return the run type as string ("Data", "Pedestal", ...), for example
|
---|
754 | // to print it as readable text.
|
---|
755 | //
|
---|
756 | const char *MRawRunHeader::GetRunTypeStr() const
|
---|
757 | {
|
---|
758 | switch (fRunType)
|
---|
759 | {
|
---|
760 | case kRTData:
|
---|
761 | return "Data";
|
---|
762 | case kRTPedestal:
|
---|
763 | return "Pedestal";
|
---|
764 | case kRTCalibration:
|
---|
765 | return "Calibration";
|
---|
766 | case kRTPointRun:
|
---|
767 | return "Point-Run";
|
---|
768 | case kRTMonteCarlo:
|
---|
769 | return "Monte Carlo";
|
---|
770 | case kRTNone:
|
---|
771 | return "<none>";
|
---|
772 | default:
|
---|
773 | return "<unknown>";
|
---|
774 | }
|
---|
775 | }
|
---|
776 |
|
---|
777 | // --------------------------------------------------------------------------
|
---|
778 | //
|
---|
779 | // print run header information on *fLog. The option 'header' supresses
|
---|
780 | // the pixel index translation table.
|
---|
781 | //
|
---|
782 | void MRawRunHeader::Print(Option_t *t) const
|
---|
783 | {
|
---|
784 | *fLog << all << endl;
|
---|
785 | *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - ";
|
---|
786 | switch (fMagicNumber)
|
---|
787 | {
|
---|
788 | case kMagicNumber: *fLog << "OK"; break;
|
---|
789 | case kMagicNumber+1: *fLog << "File not closed!"; break;
|
---|
790 | default: *fLog << "Wrong!"; break;
|
---|
791 | }
|
---|
792 | *fLog << endl;
|
---|
793 | *fLog << "Versions: " << dec << "Format=" << fFormatVersion << " ";
|
---|
794 | *fLog << "Software=" << fSoftVersion << " ";
|
---|
795 | if (fFormatVersion>5)
|
---|
796 | *fLog << "Camera=" << fCameraVersion;
|
---|
797 | *fLog << endl;
|
---|
798 | if (fFormatVersion>10)
|
---|
799 | *fLog << "Header sizes: " << fHeaderSizeRun << "b (run), " << fHeaderSizeEvt << "b (evt), " << fHeaderSizeCrate << "b (crate)" << endl;
|
---|
800 | if (fFormatVersion>5)
|
---|
801 | *fLog << "Telescope: " << fTelescopeNumber << endl;
|
---|
802 | if (fFormatVersion>7)
|
---|
803 | {
|
---|
804 | *fLog << "FadcType: " << fFadcType << " (";
|
---|
805 | switch (fFadcType)
|
---|
806 | {
|
---|
807 | case 1: *fLog << "Siegen"; break;
|
---|
808 | case 2: *fLog << "MUX"; break;
|
---|
809 | default: *fLog << "unknown";
|
---|
810 | }
|
---|
811 | *fLog << ")" << endl;
|
---|
812 | }
|
---|
813 | *fLog << "RunNumber: " << fRunNumber << " (Type=" << GetRunTypeStr() << ")" << endl;
|
---|
814 | *fLog << "ProjectName: '" << fProjectName << "'" << endl;
|
---|
815 | if (fFormatVersion>5)
|
---|
816 | *fLog << "Observation: '" << fObservationMode << "'" << endl;
|
---|
817 | *fLog << "Source: '" << fSourceName << "' " << " ";
|
---|
818 | *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
|
---|
819 | *fLog << "Run Start: " << fRunStart << endl;
|
---|
820 | *fLog << "Run Stop: " << fRunStop << endl;
|
---|
821 | *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
|
---|
822 | *fLog << "Num Pixels: " << GetNumNormalPixels() << " (normal) + " << GetNumSpecialPixels() << " (special) = " << GetNumConnectedPixels() << " (total)" << endl;
|
---|
823 | if (fFormatVersion>6)
|
---|
824 | *fLog << "Sampling: " << fSamplingFrequency << "MHz with " << (int)fFadcResolution << " significant bits" << endl;
|
---|
825 | *fLog << "Samples: " << fNumSamplesHiGain << "/" << fNumSamplesLoGain << " (hi/lo) * " << fNumBytesPerSample << "B/sample = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate * fNumBytesPerSample/1000 << "kB/Evt" << endl;
|
---|
826 | *fLog << "Evt Counter: " << fNumEvents;
|
---|
827 | if (fFormatVersion>8)
|
---|
828 | *fLog << " (read=" << fNumEventsRead << ")";
|
---|
829 | *fLog << endl;
|
---|
830 |
|
---|
831 | if (TString(t).Contains("header", TString::kIgnoreCase))
|
---|
832 | return;
|
---|
833 |
|
---|
834 | *fLog << inf3 << "Assignment:" << hex << endl;
|
---|
835 | for (int i=0; i<GetNumPixel(); i++)
|
---|
836 | *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
|
---|
837 |
|
---|
838 | *fLog << dec << setfill(' ') << endl;
|
---|
839 | }
|
---|
840 |
|
---|
841 | // --------------------------------------------------------------------------
|
---|
842 | //
|
---|
843 | // Return the assigned pixel number for the given FADC channel
|
---|
844 | //
|
---|
845 | Short_t MRawRunHeader::GetPixAssignment(UShort_t i) const
|
---|
846 | {
|
---|
847 | // FIXME: Do we need a range check here?
|
---|
848 | return (Short_t)(*fPixAssignment)[i];
|
---|
849 | }
|
---|
850 |
|
---|
851 | // --------------------------------------------------------------------------
|
---|
852 | //
|
---|
853 | // Return the number of pixel which are markes as connected in the
|
---|
854 | // pix assignment (!=0)
|
---|
855 | //
|
---|
856 | UShort_t MRawRunHeader::GetNumConnectedPixels() const
|
---|
857 | {
|
---|
858 | const Int_t num = fPixAssignment->GetSize();
|
---|
859 |
|
---|
860 | UShort_t rc = 0;
|
---|
861 | for (int i=0; i<num; i++)
|
---|
862 | {
|
---|
863 | if (GetPixAssignment(i)!=0)
|
---|
864 | rc++;
|
---|
865 | }
|
---|
866 | return rc;
|
---|
867 | }
|
---|
868 |
|
---|
869 | // --------------------------------------------------------------------------
|
---|
870 | //
|
---|
871 | // Return the number of pixel which are markes as connected and so-called
|
---|
872 | // 'normal' pixels in the pix assignment (>0)
|
---|
873 | //
|
---|
874 | UShort_t MRawRunHeader::GetNumNormalPixels() const
|
---|
875 | {
|
---|
876 | const Int_t num = fPixAssignment->GetSize();
|
---|
877 |
|
---|
878 | UShort_t rc = 0;
|
---|
879 | for (int i=0; i<num; i++)
|
---|
880 | {
|
---|
881 | if (GetPixAssignment(i)>0)
|
---|
882 | rc++;
|
---|
883 | }
|
---|
884 | return rc;
|
---|
885 | }
|
---|
886 |
|
---|
887 | // --------------------------------------------------------------------------
|
---|
888 | //
|
---|
889 | // Return the number of pixel which are markes as connected and so-called
|
---|
890 | // 'special' pixels in the pix assignment (<0)
|
---|
891 | //
|
---|
892 | UShort_t MRawRunHeader::GetNumSpecialPixels() const
|
---|
893 | {
|
---|
894 | const Int_t num = fPixAssignment->GetSize();
|
---|
895 |
|
---|
896 | UShort_t rc = 0;
|
---|
897 | for (int i=0; i<num; i++)
|
---|
898 | {
|
---|
899 | if (GetPixAssignment(i)<0)
|
---|
900 | rc++;
|
---|
901 | }
|
---|
902 | return rc;
|
---|
903 | }
|
---|
904 |
|
---|
905 | // --------------------------------------------------------------------------
|
---|
906 | //
|
---|
907 | // Return the maximum id which exists in the pix assignment
|
---|
908 | //
|
---|
909 | UShort_t MRawRunHeader::GetMaxPixId() const
|
---|
910 | {
|
---|
911 | const Int_t num = fPixAssignment->GetSize();
|
---|
912 |
|
---|
913 | Short_t rc = 0;
|
---|
914 | for (int i=0; i<num; i++)
|
---|
915 | rc = TMath::Max(GetPixAssignment(i), rc);
|
---|
916 |
|
---|
917 | return rc;
|
---|
918 | }
|
---|
919 |
|
---|
920 | // --------------------------------------------------------------------------
|
---|
921 | //
|
---|
922 | // Return minus th minimum id which exists in the pix assignment
|
---|
923 | //
|
---|
924 | UShort_t MRawRunHeader::GetMinPixId() const
|
---|
925 | {
|
---|
926 | const Int_t num = fPixAssignment->GetSize();
|
---|
927 |
|
---|
928 | Short_t rc = 0;
|
---|
929 | for (int i=0; i<num; i++)
|
---|
930 | rc = TMath::Min(GetPixAssignment(i), rc);
|
---|
931 |
|
---|
932 | return (UShort_t)-rc;
|
---|
933 | }
|
---|
934 |
|
---|
935 | // --------------------------------------------------------------------------
|
---|
936 | //
|
---|
937 | // Return the number of pixel in this event.
|
---|
938 | //
|
---|
939 | // WARNING: This is the number of pixels stored in this file which is
|
---|
940 | // a multiple of the number of pixels per crate and in general
|
---|
941 | // a number which is larger than the camera size!
|
---|
942 | //
|
---|
943 | // To know the range of the pixel indices please use the geometry
|
---|
944 | // container!
|
---|
945 | //
|
---|
946 | UShort_t MRawRunHeader::GetNumPixel() const
|
---|
947 | {
|
---|
948 | return fPixAssignment->GetSize();
|
---|
949 | }
|
---|
950 |
|
---|
951 | // --------------------------------------------------------------------------
|
---|
952 | //
|
---|
953 | // Returns absolute size in bytes of the run header as read from a raw file.
|
---|
954 | // This must be done _after_ the header is read, because the header doesn't
|
---|
955 | // have a fixed size (used in MRawSocketRead)
|
---|
956 | //
|
---|
957 | Int_t MRawRunHeader::GetNumTotalBytes() const
|
---|
958 | {
|
---|
959 | switch (fFormatVersion)
|
---|
960 | {
|
---|
961 | case 1:
|
---|
962 | return 80+fNumCrates*fNumPixInCrate*2+16;
|
---|
963 | case 2:
|
---|
964 | case 3:
|
---|
965 | case 4:
|
---|
966 | case 5:
|
---|
967 | return 84+fNumCrates*fNumPixInCrate*2+16;
|
---|
968 | case 6:
|
---|
969 | return 84+fNumCrates*fNumPixInCrate*2+16 +4+78+58+60+8;
|
---|
970 | case 7:
|
---|
971 | return 84+fNumCrates*fNumPixInCrate*2+16 +4+78+58+60+8 +3-16;
|
---|
972 | }
|
---|
973 | return 0;
|
---|
974 | }
|
---|