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