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 999999
|
---|
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 (!fTelescopeNumber==1)
|
---|
447 | return kTRUE;
|
---|
448 |
|
---|
449 | if (fRunNumber>=53300 && fRunNumber<=68754)
|
---|
450 | {
|
---|
451 | if (!SwapAssignment(554, 559))
|
---|
452 | return kFALSE;
|
---|
453 | if (!SwapAssignment(555, 558))
|
---|
454 | return kFALSE;
|
---|
455 | if (!SwapAssignment(556, 557))
|
---|
456 | return kFALSE;
|
---|
457 | }
|
---|
458 |
|
---|
459 | if (fRunNumber>=93283 && fRunNumber<99354)
|
---|
460 | {
|
---|
461 | if (!SwapAssignment(119, 120))
|
---|
462 | return kFALSE;
|
---|
463 | }
|
---|
464 |
|
---|
465 | if (fRunNumber>=99354 && fRunNumber<=101789)
|
---|
466 | {
|
---|
467 | if (!SwapAssignment(161, 162))
|
---|
468 | return kFALSE;
|
---|
469 | if (!SwapAssignment(210, 263))
|
---|
470 | return kFALSE;
|
---|
471 | }
|
---|
472 |
|
---|
473 | if (fRunNumber>=88669)
|
---|
474 | {
|
---|
475 | if (!SwapAssignment(54, 55))
|
---|
476 | return kFALSE;
|
---|
477 | }
|
---|
478 |
|
---|
479 | if (fRunNumber>=200000)
|
---|
480 | {
|
---|
481 | if (!SwapAssignment(428, 429))
|
---|
482 | return kFALSE;
|
---|
483 | }
|
---|
484 |
|
---|
485 | return kTRUE;
|
---|
486 | }
|
---|
487 |
|
---|
488 | // --------------------------------------------------------------------------
|
---|
489 | //
|
---|
490 | // Fixes to fix bugs in the run header
|
---|
491 | //
|
---|
492 | Bool_t MRawRunHeader::Fixes()
|
---|
493 | {
|
---|
494 | if (fFormatVersion>8 && fRunNumber>326152 && fTelescopeNumber==1)
|
---|
495 | {
|
---|
496 | fNumEvents--;
|
---|
497 | fNumEventsRead--;
|
---|
498 | *fLog << inf << "Format >V8 and Run>M1:326152: Stored number of events decreased by 1." << endl;
|
---|
499 | }
|
---|
500 |
|
---|
501 | if (fFormatVersion>10 && fRunNumber<48 &&
|
---|
502 | fRunStart.GetMjd()>54674.5 && fRunStart.GetMjd()<56476.5)
|
---|
503 | {
|
---|
504 | fRunNumber += 1001348;
|
---|
505 | *fLog << warn << "Format >V10: Wrong run number increased by 1001348 to " << fRunNumber << "." << endl;
|
---|
506 | }
|
---|
507 |
|
---|
508 | return FixAssignment();
|
---|
509 | }
|
---|
510 |
|
---|
511 | // --------------------------------------------------------------------------
|
---|
512 | //
|
---|
513 | // Reading function to read/interpret the file formats 1-10
|
---|
514 | //
|
---|
515 | Bool_t MRawRunHeader::ReadEvtOld(istream& fin)
|
---|
516 | {
|
---|
517 | if (fFormatVersion==7)
|
---|
518 | {
|
---|
519 | *fLog << err << "ERROR - File format V7 was for testing only and is not correctly implemented!" << endl;
|
---|
520 | return kFALSE;
|
---|
521 | }
|
---|
522 |
|
---|
523 | // ----- DAQ software format version -----
|
---|
524 | fin.read((char*)&fSoftVersion, 2); // Total=6
|
---|
525 |
|
---|
526 |
|
---|
527 | fFadcType = 1;
|
---|
528 | if (fFormatVersion>7)
|
---|
529 | fin.read((char*)&fFadcType, 2);
|
---|
530 |
|
---|
531 | // ----- Camera geometry and telescope number -----
|
---|
532 | fCameraVersion = 1;
|
---|
533 | fTelescopeNumber = 1;
|
---|
534 | if (fFormatVersion>5)
|
---|
535 | {
|
---|
536 | fin.read((char*)&fCameraVersion, 2); // (+2)
|
---|
537 | fin.read((char*)&fTelescopeNumber, 2); // (+2)
|
---|
538 | }
|
---|
539 |
|
---|
540 | // ----- Run information -----
|
---|
541 | fin.read((char*)&fRunType, 2); // Total=8
|
---|
542 |
|
---|
543 | fin.read((char*)&fRunNumber, 4); // Total=12
|
---|
544 | fin.read((char*)&fProjectName, fFormatVersion>5?100:22); // Total=34 (+78)
|
---|
545 | fin.read((char*)&fSourceName, fFormatVersion>5? 80:12); // Total=46 (+58)
|
---|
546 |
|
---|
547 | if (fFormatVersion>5)
|
---|
548 | fin.read((char*)fObservationMode, 60); // (+60)
|
---|
549 | // Maybe we should set fObservationMode to something
|
---|
550 | // in case of fFormatVersion<6
|
---|
551 |
|
---|
552 | // ----- Source position -----
|
---|
553 | fin.seekg(fFormatVersion>5 ? 16 : 8, ios::cur);
|
---|
554 | /*
|
---|
555 | if (fFormatVersion>5)
|
---|
556 | {
|
---|
557 | fin.read((char*)&fSourceRa, 4); // F32 SourceRA; Total=48
|
---|
558 | fin.read((char*)&fSourceDec, 4); // F32 SourceDEC; Total=52
|
---|
559 | }
|
---|
560 | fin.read((char*)&fTelescopeRa, 4); // F32 TelescopeRA; (+4)
|
---|
561 | fin.read((char*)&fTelescopeDec, 4); // F32 TelescopeDEC; (+4)
|
---|
562 | */
|
---|
563 |
|
---|
564 | // Maybe we should set these to something
|
---|
565 | // in case of fFormatVersion<6
|
---|
566 | fin.read((char*)&fSourceEpochChar, 2); // Total=56
|
---|
567 | fin.read((char*)&fSourceEpochDate, 2); // Total=58
|
---|
568 |
|
---|
569 | // ----- Old Start time -----
|
---|
570 | if (fFormatVersion<2) // Total += 10
|
---|
571 | {
|
---|
572 | UShort_t y, m, d;
|
---|
573 | fin.seekg(4, ios::cur); // Former fMJD[4],
|
---|
574 | fin.read((char*)&y, 2); // Former fDateYear[2]
|
---|
575 | fin.read((char*)&m, 2); // Former fDateMonth[2]
|
---|
576 | fin.read((char*)&d, 2); // Former fDateDay[2]
|
---|
577 | fRunStart.Set(y, m, d, 0, 0, 0, 0);
|
---|
578 | }
|
---|
579 |
|
---|
580 | // ----- Data Geometry -----
|
---|
581 |
|
---|
582 | fin.read((char*)&fNumCrates, 2); // MUX: number of channels
|
---|
583 | fin.read((char*)&fNumPixInCrate, 2); // MUX: number of pix in channel
|
---|
584 | fin.read((char*)&fNumSamplesLoGain, 2); // MUX: dummy (must be 0 for MUX data)
|
---|
585 | fin.read((char*)&fNumSamplesHiGain, 2); // MUX: Number of samples per pixel
|
---|
586 |
|
---|
587 | char dummy[16];
|
---|
588 | if (fFormatVersion>8)
|
---|
589 | fin.read(dummy, 4); // 2xU16 (NumSamplesRemovedHead and NumSamplesRemovedTail)
|
---|
590 |
|
---|
591 | // ----- Number of events -----
|
---|
592 | fin.read((char*)&fNumEvents, 4); // Total=70
|
---|
593 |
|
---|
594 | if (fFormatVersion>8)
|
---|
595 | fin.read((char*)&fNumEventsRead, 4);
|
---|
596 |
|
---|
597 | // New in general features: (should they be included in new MAGIC1 formats, too?)
|
---|
598 | fNumBytesPerSample = 1; // 2 for MUX DATA
|
---|
599 | fSamplingFrequency = 300;
|
---|
600 | fFadcResolution = 8;
|
---|
601 |
|
---|
602 | if (fFormatVersion>7)
|
---|
603 | {
|
---|
604 | fin.read((char*)&fNumBytesPerSample, 2);
|
---|
605 | fin.read((char*)&fSamplingFrequency, 2); // [MHz], 2000 for MuxFadc
|
---|
606 | fin.read((char*)&fFadcResolution, 1); // nominal resolution [# Bits], 10 for MuxFadc
|
---|
607 | }
|
---|
608 |
|
---|
609 | // ----- Start/Stop time -----
|
---|
610 | if (fFormatVersion>1)
|
---|
611 | {
|
---|
612 | fRunStart.ReadBinary(fin); // Total += 7
|
---|
613 | fRunStop.ReadBinary(fin); // Total += 7
|
---|
614 | }
|
---|
615 |
|
---|
616 | //
|
---|
617 | // calculate size of array, create it and fill it
|
---|
618 | //
|
---|
619 | const Int_t nPixel = fNumCrates*fNumPixInCrate;
|
---|
620 | fPixAssignment->Set(nPixel);
|
---|
621 |
|
---|
622 | // ----- Pixel Assignement -----
|
---|
623 | fin.read((char*)fPixAssignment->GetArray(), nPixel*2);
|
---|
624 |
|
---|
625 | if (fFormatVersion<7)
|
---|
626 | fin.read(dummy, 16);
|
---|
627 |
|
---|
628 | // ----- Fixes for broken files or contents -----
|
---|
629 | if (!Fixes())
|
---|
630 | return kFALSE;
|
---|
631 |
|
---|
632 | // ----- Consistency checks -----
|
---|
633 | return IsConsistent();
|
---|
634 | }
|
---|
635 |
|
---|
636 | // --------------------------------------------------------------------------
|
---|
637 | //
|
---|
638 | // Read in one run header from the binary file
|
---|
639 | //
|
---|
640 | Bool_t MRawRunHeader::ReadEvt(istream& fin)
|
---|
641 | {
|
---|
642 | //
|
---|
643 | // read one RUN HEADER from the input stream
|
---|
644 | //
|
---|
645 | fMagicNumber = 0;
|
---|
646 |
|
---|
647 | fin.read((char*)&fMagicNumber, 2); // Total=2
|
---|
648 |
|
---|
649 | //
|
---|
650 | // check whether the the file has the right file type or not
|
---|
651 | //
|
---|
652 | if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
|
---|
653 | {
|
---|
654 | *fLog << err << "ERROR - Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
|
---|
655 | return kFALSE;
|
---|
656 | }
|
---|
657 |
|
---|
658 | if (fMagicNumber == kMagicNumber+1)
|
---|
659 | *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
|
---|
660 |
|
---|
661 | // ----- File format version -----
|
---|
662 | fin.read((char*)&fFormatVersion, 2); // Total=4
|
---|
663 | if (fFormatVersion==10 || fFormatVersion>kMaxFormatVersion)
|
---|
664 | {
|
---|
665 | *fLog << err << "ERROR - File format V" << fFormatVersion << " not implemented!" << endl;
|
---|
666 | return kFALSE;
|
---|
667 | }
|
---|
668 |
|
---|
669 | // ----- Process old file formats -----
|
---|
670 | if (fFormatVersion<10)
|
---|
671 | return ReadEvtOld(fin);
|
---|
672 |
|
---|
673 | // ----- Overwrite format version for format 11 -----
|
---|
674 | fin.read((char*)&fFormatVersion, 4);
|
---|
675 | if (fFormatVersion<11)
|
---|
676 | {
|
---|
677 | *fLog << err << "ERROR - Format Version <11." << endl;
|
---|
678 | return kFALSE;
|
---|
679 | }
|
---|
680 |
|
---|
681 | // ----- Read Header by size as written in the header -----
|
---|
682 | fin.read((char*)&fHeaderSizeRun, 4);
|
---|
683 | if (fHeaderSizeRun<346)
|
---|
684 | {
|
---|
685 | *fLog << err << "ERROR - Event header too small (<388b)." << endl;
|
---|
686 | return kFALSE;
|
---|
687 | }
|
---|
688 |
|
---|
689 | TArrayC h(fHeaderSizeRun-12);
|
---|
690 | fin.read(h.GetArray(), h.GetSize());
|
---|
691 | if (!fin)
|
---|
692 | return kFALSE;
|
---|
693 |
|
---|
694 | // ----- convert -----
|
---|
695 | const Byte_t *Char = reinterpret_cast<Byte_t* >(h.GetArray());
|
---|
696 | const UInt_t *Int = reinterpret_cast<UInt_t* >(h.GetArray());
|
---|
697 | //const Float_t *Float = reinterpret_cast<Float_t*>(h.GetArray());
|
---|
698 |
|
---|
699 | // ----- Start interpretation -----
|
---|
700 |
|
---|
701 | fHeaderSizeEvt = Int[0];
|
---|
702 | fHeaderSizeCrate = Int[1];
|
---|
703 | fSoftVersion = Int[2];
|
---|
704 | fFadcType = Int[3];
|
---|
705 | fCameraVersion = Int[4];
|
---|
706 | fTelescopeNumber = Int[5];
|
---|
707 | fRunType = Int[6];
|
---|
708 | fRunNumber = Int[7];
|
---|
709 | fFileNumber = Int[8];
|
---|
710 |
|
---|
711 | memcpy(fProjectName, Char+ 36, 100); // 25
|
---|
712 | memcpy(fSourceName, Char+136, 80); // 20
|
---|
713 | memcpy(fObservationMode, Char+216, 60); // 15
|
---|
714 |
|
---|
715 | //F32 fSourceRA = Float[69];
|
---|
716 | //F32 fSourceDEC = Float[70];
|
---|
717 | //F32 fTelescopeRA = Float[71];
|
---|
718 | //F32 fTelescopeDEC = Float[72];
|
---|
719 |
|
---|
720 | memcpy(fSourceEpochChar, Char+232, 4);
|
---|
721 |
|
---|
722 | fSourceEpochDate = Int[74];
|
---|
723 | fNumCrates = Int[75];
|
---|
724 | fNumPixInCrate = Int[76];
|
---|
725 | fNumSamplesHiGain = Int[77];
|
---|
726 | fNumSamplesLoGain = 0;
|
---|
727 |
|
---|
728 | //fNumSamplesRemovedHead = Int[78];
|
---|
729 | //fNumSamplesRemovedTail = Int[79];
|
---|
730 |
|
---|
731 | fNumEvents = Int[80];
|
---|
732 | fNumEventsRead = Int[81];
|
---|
733 | fNumBytesPerSample = Int[82];
|
---|
734 | fSamplingFrequency = Int[83];
|
---|
735 | fFadcResolution = Int[84];
|
---|
736 |
|
---|
737 | fRunStart.SetBinary(Int+85);
|
---|
738 | fRunStop.SetBinary(Int+91);
|
---|
739 |
|
---|
740 | // ----- 388 bytes so far -----
|
---|
741 |
|
---|
742 | const UInt_t n = fNumCrates*fNumPixInCrate;
|
---|
743 | if (fHeaderSizeRun<388+n*4)
|
---|
744 | {
|
---|
745 | *fLog << err << "ERROR - Event header too small to contain pix assignment." << endl;
|
---|
746 | return kFALSE;
|
---|
747 | }
|
---|
748 |
|
---|
749 | // ----- Pixel Assignment -----
|
---|
750 | fPixAssignment->Set(n);
|
---|
751 |
|
---|
752 | for (UInt_t i=0; i<n; i++)
|
---|
753 | (*fPixAssignment)[i] = Int[97+i];
|
---|
754 |
|
---|
755 | // ----- Fixes for broken files or contents -----
|
---|
756 | if (!Fixes())
|
---|
757 | return kFALSE;
|
---|
758 |
|
---|
759 | // ----- Consistency checks -----
|
---|
760 | return IsConsistent();
|
---|
761 | }
|
---|
762 |
|
---|
763 | // --------------------------------------------------------------------------
|
---|
764 | //
|
---|
765 | // Return the run type as string ("Data", "Pedestal", ...), for example
|
---|
766 | // to print it as readable text.
|
---|
767 | //
|
---|
768 | const char *MRawRunHeader::GetRunTypeStr() const
|
---|
769 | {
|
---|
770 | switch (fRunType)
|
---|
771 | {
|
---|
772 | case kRTData:
|
---|
773 | return "Data";
|
---|
774 | case kRTPedestal:
|
---|
775 | return "Pedestal";
|
---|
776 | case kRTCalibration:
|
---|
777 | return "Calibration";
|
---|
778 | case kRTLinearity:
|
---|
779 | return "Linearity";
|
---|
780 | case kRTPointRun:
|
---|
781 | return "Point-Run";
|
---|
782 | case kRTMonteCarlo:
|
---|
783 | return "Monte Carlo";
|
---|
784 | case kRTNone:
|
---|
785 | return "<none>";
|
---|
786 | default:
|
---|
787 | return "<unknown>";
|
---|
788 | }
|
---|
789 | }
|
---|
790 |
|
---|
791 | // --------------------------------------------------------------------------
|
---|
792 | //
|
---|
793 | // print run header information on *fLog. The option 'header' supresses
|
---|
794 | // the pixel index translation table.
|
---|
795 | //
|
---|
796 | void MRawRunHeader::Print(Option_t *t) const
|
---|
797 | {
|
---|
798 | *fLog << all << endl;
|
---|
799 | *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - ";
|
---|
800 | switch (fMagicNumber)
|
---|
801 | {
|
---|
802 | case kMagicNumber: *fLog << "OK"; break;
|
---|
803 | case kMagicNumber+1: *fLog << "File not closed!"; break;
|
---|
804 | default: *fLog << "Wrong!"; break;
|
---|
805 | }
|
---|
806 | *fLog << endl;
|
---|
807 | *fLog << "Versions: " << dec << "Format=" << fFormatVersion << " ";
|
---|
808 | *fLog << "Software=" << fSoftVersion << " ";
|
---|
809 | if (fFormatVersion>5)
|
---|
810 | *fLog << "Camera=" << fCameraVersion;
|
---|
811 | *fLog << endl;
|
---|
812 | if (fFormatVersion>10)
|
---|
813 | *fLog << "Header sizes: " << fHeaderSizeRun << "b (run), " << fHeaderSizeEvt << "b (evt), " << fHeaderSizeCrate << "b (crate)" << endl;
|
---|
814 | if (fFormatVersion>5)
|
---|
815 | *fLog << "Telescope: " << fTelescopeNumber << endl;
|
---|
816 | if (fFormatVersion>7)
|
---|
817 | {
|
---|
818 | *fLog << "FadcType: " << fFadcType << " (";
|
---|
819 | switch (fFadcType)
|
---|
820 | {
|
---|
821 | case 1: *fLog << "Siegen"; break;
|
---|
822 | case 2: *fLog << "MUX"; break;
|
---|
823 | default: *fLog << "unknown";
|
---|
824 | }
|
---|
825 | *fLog << ")" << endl;
|
---|
826 | }
|
---|
827 | *fLog << "RunNumber: " << fRunNumber;
|
---|
828 | if (fFormatVersion>10)
|
---|
829 | *fLog << "/" << fFileNumber << " (id=" << GetFileID() << ")";
|
---|
830 | *fLog << " (Type=" << GetRunTypeStr() << ")" << endl;
|
---|
831 | *fLog << "ProjectName: '" << fProjectName << "'" << endl;
|
---|
832 | if (fFormatVersion>5)
|
---|
833 | *fLog << "Observation: '" << fObservationMode << "'" << endl;
|
---|
834 | *fLog << "Source: '" << fSourceName << "' " << " ";
|
---|
835 | *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
|
---|
836 | *fLog << "Run Start: " << fRunStart << endl;
|
---|
837 | *fLog << "Run Stop: " << fRunStop << endl;
|
---|
838 | *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
|
---|
839 | *fLog << "Num Pixels: " << GetNumNormalPixels() << " (normal) + " << GetNumSpecialPixels() << " (special) = " << GetNumConnectedPixels() << " (total)" << endl;
|
---|
840 | if (fFormatVersion>6)
|
---|
841 | *fLog << "Sampling: " << fSamplingFrequency << "MHz with " << (int)fFadcResolution << " significant bits" << endl;
|
---|
842 | *fLog << "Samples: " << fNumSamplesHiGain << "/" << fNumSamplesLoGain << " (hi/lo) * " << fNumBytesPerSample << "B/sample = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate * fNumBytesPerSample/1000 << "kB/Evt" << endl;
|
---|
843 | *fLog << "Evt Counter: " << fNumEvents;
|
---|
844 | if (fFormatVersion>8)
|
---|
845 | *fLog << " (read=" << fNumEventsRead << ")";
|
---|
846 | *fLog << endl;
|
---|
847 |
|
---|
848 | if (TString(t).Contains("header", TString::kIgnoreCase))
|
---|
849 | return;
|
---|
850 |
|
---|
851 | *fLog << inf3 << "Assignment:" << hex << endl;
|
---|
852 | for (int i=0; i<GetNumPixel(); i++)
|
---|
853 | *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
|
---|
854 |
|
---|
855 | *fLog << dec << setfill(' ') << endl;
|
---|
856 | }
|
---|
857 |
|
---|
858 | // --------------------------------------------------------------------------
|
---|
859 | //
|
---|
860 | // Return the assigned pixel number for the given FADC channel
|
---|
861 | //
|
---|
862 | Short_t MRawRunHeader::GetPixAssignment(UShort_t i) const
|
---|
863 | {
|
---|
864 | // FIXME: Do we need a range check here?
|
---|
865 | return (Short_t)(*fPixAssignment)[i];
|
---|
866 | }
|
---|
867 |
|
---|
868 | // --------------------------------------------------------------------------
|
---|
869 | //
|
---|
870 | // Return the number of pixel which are markes as connected in the
|
---|
871 | // pix assignment (!=0)
|
---|
872 | //
|
---|
873 | UShort_t MRawRunHeader::GetNumConnectedPixels() const
|
---|
874 | {
|
---|
875 | const Int_t num = fPixAssignment->GetSize();
|
---|
876 |
|
---|
877 | UShort_t rc = 0;
|
---|
878 | for (int i=0; i<num; i++)
|
---|
879 | {
|
---|
880 | if (GetPixAssignment(i)!=0)
|
---|
881 | rc++;
|
---|
882 | }
|
---|
883 | return rc;
|
---|
884 | }
|
---|
885 |
|
---|
886 | // --------------------------------------------------------------------------
|
---|
887 | //
|
---|
888 | // Return the number of pixel which are markes as connected and so-called
|
---|
889 | // 'normal' pixels in the pix assignment (>0)
|
---|
890 | //
|
---|
891 | UShort_t MRawRunHeader::GetNumNormalPixels() const
|
---|
892 | {
|
---|
893 | const Int_t num = fPixAssignment->GetSize();
|
---|
894 |
|
---|
895 | UShort_t rc = 0;
|
---|
896 | for (int i=0; i<num; i++)
|
---|
897 | {
|
---|
898 | if (GetPixAssignment(i)>0)
|
---|
899 | rc++;
|
---|
900 | }
|
---|
901 | return rc;
|
---|
902 | }
|
---|
903 |
|
---|
904 | // --------------------------------------------------------------------------
|
---|
905 | //
|
---|
906 | // Return the number of pixel which are markes as connected and so-called
|
---|
907 | // 'special' pixels in the pix assignment (<0)
|
---|
908 | //
|
---|
909 | UShort_t MRawRunHeader::GetNumSpecialPixels() const
|
---|
910 | {
|
---|
911 | const Int_t num = fPixAssignment->GetSize();
|
---|
912 |
|
---|
913 | UShort_t rc = 0;
|
---|
914 | for (int i=0; i<num; i++)
|
---|
915 | {
|
---|
916 | if (GetPixAssignment(i)<0)
|
---|
917 | rc++;
|
---|
918 | }
|
---|
919 | return rc;
|
---|
920 | }
|
---|
921 |
|
---|
922 | // --------------------------------------------------------------------------
|
---|
923 | //
|
---|
924 | // Return the maximum id which exists in the pix assignment
|
---|
925 | //
|
---|
926 | UShort_t MRawRunHeader::GetMaxPixId() const
|
---|
927 | {
|
---|
928 | const Int_t num = fPixAssignment->GetSize();
|
---|
929 |
|
---|
930 | Short_t rc = 0;
|
---|
931 | for (int i=0; i<num; i++)
|
---|
932 | rc = TMath::Max(GetPixAssignment(i), rc);
|
---|
933 |
|
---|
934 | return rc;
|
---|
935 | }
|
---|
936 |
|
---|
937 | // --------------------------------------------------------------------------
|
---|
938 | //
|
---|
939 | // Return minus th minimum id which exists in the pix assignment
|
---|
940 | //
|
---|
941 | UShort_t MRawRunHeader::GetMinPixId() const
|
---|
942 | {
|
---|
943 | const Int_t num = fPixAssignment->GetSize();
|
---|
944 |
|
---|
945 | Short_t rc = 0;
|
---|
946 | for (int i=0; i<num; i++)
|
---|
947 | rc = TMath::Min(GetPixAssignment(i), rc);
|
---|
948 |
|
---|
949 | return (UShort_t)-rc;
|
---|
950 | }
|
---|
951 |
|
---|
952 | // --------------------------------------------------------------------------
|
---|
953 | //
|
---|
954 | // Return the number of pixel in this event.
|
---|
955 | //
|
---|
956 | // WARNING: This is the number of pixels stored in this file which is
|
---|
957 | // a multiple of the number of pixels per crate and in general
|
---|
958 | // a number which is larger than the camera size!
|
---|
959 | //
|
---|
960 | // To know the range of the pixel indices please use the geometry
|
---|
961 | // container!
|
---|
962 | //
|
---|
963 | UShort_t MRawRunHeader::GetNumPixel() const
|
---|
964 | {
|
---|
965 | return fPixAssignment->GetSize();
|
---|
966 | }
|
---|
967 |
|
---|
968 | // --------------------------------------------------------------------------
|
---|
969 | //
|
---|
970 | // Returns absolute size in bytes of the run header as read from a raw file.
|
---|
971 | // This must be done _after_ the header is read, because the header doesn't
|
---|
972 | // have a fixed size (used in MRawSocketRead)
|
---|
973 | //
|
---|
974 | Int_t MRawRunHeader::GetNumTotalBytes() const
|
---|
975 | {
|
---|
976 | switch (fFormatVersion)
|
---|
977 | {
|
---|
978 | case 1:
|
---|
979 | return 80+fNumCrates*fNumPixInCrate*2+16;
|
---|
980 | case 2:
|
---|
981 | case 3:
|
---|
982 | case 4:
|
---|
983 | case 5:
|
---|
984 | return 84+fNumCrates*fNumPixInCrate*2+16;
|
---|
985 | case 6:
|
---|
986 | return 84+fNumCrates*fNumPixInCrate*2+16 +4+78+58+60+8;
|
---|
987 | case 7:
|
---|
988 | return 84+fNumCrates*fNumPixInCrate*2+16 +4+78+58+60+8 +3-16;
|
---|
989 | }
|
---|
990 | return 0;
|
---|
991 | }
|
---|