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=11;
|
---|
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 | fSourceEpochChar[1]=0;
|
---|
196 | fSourceEpochDate=0;
|
---|
197 | fNumCrates=0;
|
---|
198 | fNumPixInCrate=0;
|
---|
199 | fNumSamplesLoGain=0;
|
---|
200 | fNumSamplesHiGain=0;
|
---|
201 | fNumEvents=0;
|
---|
202 | fNumEventsRead=0;
|
---|
203 | fNumBytesPerSample=1;
|
---|
204 | fSamplingFrequency=300;
|
---|
205 | fFadcResolution=8;
|
---|
206 |
|
---|
207 | fHeaderSizeRun=0;
|
---|
208 | fHeaderSizeEvt=0;
|
---|
209 | fHeaderSizeCrate=0;
|
---|
210 | }
|
---|
211 |
|
---|
212 | // --------------------------------------------------------------------------
|
---|
213 | //
|
---|
214 | // Destructor. Deletes the 'pixel-assignment-array'
|
---|
215 | //
|
---|
216 | MRawRunHeader::~MRawRunHeader()
|
---|
217 | {
|
---|
218 | delete fPixAssignment;
|
---|
219 | }
|
---|
220 |
|
---|
221 | // --------------------------------------------------------------------------
|
---|
222 | //
|
---|
223 | // Swap the assignment of the pixels with hardware id id0 and id1
|
---|
224 | //
|
---|
225 | Bool_t MRawRunHeader::SwapAssignment(Short_t id0, Short_t id1)
|
---|
226 | {
|
---|
227 | const Int_t n = fPixAssignment->GetSize();
|
---|
228 |
|
---|
229 | // Look-up-table
|
---|
230 | UShort_t *lut = fPixAssignment->GetArray();
|
---|
231 |
|
---|
232 | // Search for one of the hardware indices to get exchanged
|
---|
233 | int i;
|
---|
234 | for (i=0; i<n; i++)
|
---|
235 | if (lut[i]==id0 || lut[i]==id1)
|
---|
236 | break;
|
---|
237 |
|
---|
238 | // Check if one of the two pixels were found
|
---|
239 | if (i==n)
|
---|
240 | {
|
---|
241 | *fLog << warn << "WARNING - Assignment of pixels with hardware ID " << id0 << " and " << id1;
|
---|
242 | *fLog << " should be exchanged, but none were found." << endl;
|
---|
243 | return kTRUE;
|
---|
244 | }
|
---|
245 |
|
---|
246 | // Store first index
|
---|
247 | const Int_t idx0 = i;
|
---|
248 |
|
---|
249 | // Search for the other hardware indices to get exchanged
|
---|
250 | for (i++; i<n; i++)
|
---|
251 | if (lut[i]==id0 || lut[i]==id1)
|
---|
252 | break;
|
---|
253 |
|
---|
254 | // Check if the second pixel was found
|
---|
255 | if (i==n)
|
---|
256 | {
|
---|
257 | *fLog << err << "ERROR - Assignment of pixels with hardware ID " << id0 << " and " << id1;
|
---|
258 | *fLog << " should be exchanged, but only one was found." << endl;
|
---|
259 | return kFALSE;
|
---|
260 | }
|
---|
261 |
|
---|
262 | const Int_t idx1 = i;
|
---|
263 |
|
---|
264 | const Short_t p0 = lut[idx0];
|
---|
265 | const Short_t p1 = lut[idx1];
|
---|
266 |
|
---|
267 | lut[idx0] = p1;
|
---|
268 | lut[idx1] = p0;
|
---|
269 |
|
---|
270 | *fLog << inf << "Assignment of pixels with hardware ID " << id0 << " and " << id1 << " exchanged." << endl;
|
---|
271 |
|
---|
272 | return kTRUE;
|
---|
273 | }
|
---|
274 |
|
---|
275 | // --------------------------------------------------------------------------
|
---|
276 | //
|
---|
277 | // Return Telescope number, runnumber and filenumber on the form:
|
---|
278 | // run
|
---|
279 | // as string for runnumber<1000000 and
|
---|
280 | // telescope:run/file
|
---|
281 | // otherwise.
|
---|
282 | //
|
---|
283 | TString MRawRunHeader::GetStringID() const
|
---|
284 | {
|
---|
285 | return fRunNumber<1000000?MString::Format("%d", fRunNumber):MString::Format("%d:%d/%d", fTelescopeNumber, fRunNumber, fFileNumber);
|
---|
286 | }
|
---|
287 |
|
---|
288 | // --------------------------------------------------------------------------
|
---|
289 | //
|
---|
290 | // Consistency checks. See code for detils.
|
---|
291 | //
|
---|
292 | Bool_t MRawRunHeader::IsConsistent() const
|
---|
293 | {
|
---|
294 | // FIXME: Match first digits of run-number with telescope number
|
---|
295 |
|
---|
296 | if (fFormatVersion>10)
|
---|
297 | {
|
---|
298 | if (GetTypeID()!=fTelescopeNumber &&
|
---|
299 | GetTypeID()!=fTelescopeNumber*10U &&
|
---|
300 | GetTypeID()!=fTelescopeNumber*10U+5U)
|
---|
301 | {
|
---|
302 | *fLog << err << "ERROR - Telscope number " << fTelescopeNumber << " doesn't match the first two digits of the run number " << fRunNumber << "." << endl;
|
---|
303 | return kFALSE;
|
---|
304 | }
|
---|
305 |
|
---|
306 | // Old formats can not contain a run number larger 999999
|
---|
307 | if (fRunNumber<1000000)
|
---|
308 | {
|
---|
309 | *fLog << err << "ERROR - Run number " << fRunNumber << " smaller than 1000000." << endl;
|
---|
310 | return kFALSE;
|
---|
311 | }
|
---|
312 | }
|
---|
313 |
|
---|
314 | // Check for correct number of bytes in data stream
|
---|
315 | if (fFormatVersion>7 && fNumBytesPerSample!=2)
|
---|
316 | {
|
---|
317 | *fLog << err << "ERROR - " << fNumBytesPerSample << " bytes per sample are not supported!" << endl;
|
---|
318 | return kFALSE;
|
---|
319 | }
|
---|
320 |
|
---|
321 | // If we have a vlid stop time check its consistency with the start time
|
---|
322 | if (fRunStop!=MTime() && fRunStop<fRunStart)
|
---|
323 | {
|
---|
324 | *fLog << err << "ERROR - Stop time smaller than start time." << endl;
|
---|
325 | return kFALSE;
|
---|
326 | }
|
---|
327 |
|
---|
328 | // No file numbers larger than 999 allowed in general
|
---|
329 | if (fFileNumber>999)
|
---|
330 | {
|
---|
331 | *fLog << err << "ERROR - File number " << fFileNumber << " larger than 999." << endl;
|
---|
332 | return kFALSE;
|
---|
333 | }
|
---|
334 |
|
---|
335 | // Old formats can not contain a run number larger 0
|
---|
336 | if (fFormatVersion<11 && fFileNumber>0)
|
---|
337 | {
|
---|
338 | *fLog << err << "ERROR - File number " << fFileNumber << " larger than 0." << endl;
|
---|
339 | return kFALSE;
|
---|
340 | }
|
---|
341 |
|
---|
342 | if (fFormatVersion>1)
|
---|
343 | {
|
---|
344 | // For most of the formats the start time must be valid
|
---|
345 | if (fRunStart==MTime())
|
---|
346 | {
|
---|
347 | *fLog << err << "ERROR - Start time invalid." << endl;
|
---|
348 | return kFALSE;
|
---|
349 | }
|
---|
350 |
|
---|
351 | // For most of the formats an invalid stop time cannot happen if file closed
|
---|
352 | if (fMagicNumber==kMagicNumber && fRunStop==MTime())
|
---|
353 | {
|
---|
354 | *fLog << err << "ERROR - File closed but stop time invalid." << endl;
|
---|
355 | return kFALSE;
|
---|
356 | }
|
---|
357 | }
|
---|
358 | return kTRUE;
|
---|
359 | }
|
---|
360 |
|
---|
361 | void MRawRunHeader::FixRunNumbers()
|
---|
362 | {
|
---|
363 | if (fFormatVersion<11 || fTelescopeNumber!=1)
|
---|
364 | return;
|
---|
365 |
|
---|
366 | // Map 1:1001349 to 47:1001395
|
---|
367 | if (fRunNumber<48 &&
|
---|
368 | fRunStart.GetMjd()>54674.5 && fRunStart.GetMjd()<56476.5)
|
---|
369 | {
|
---|
370 | fRunNumber += 1001348;
|
---|
371 | *fLog << warn << "Format >V10: Wrong run number increased by 1001348 to " << fRunNumber << "." << endl;
|
---|
372 | }
|
---|
373 |
|
---|
374 | // Map 1001916:1001922 to 1002349:1002355
|
---|
375 | if (fRunNumber>1001915 && fRunNumber<1001923 &&
|
---|
376 | fRunStart.GetMjd()>54710.5 && fRunStart.GetMjd()<54711.5)
|
---|
377 | {
|
---|
378 | fRunNumber += 433;
|
---|
379 | *fLog << warn << "Format >V10: Wrong run number increased by 434 to " << fRunNumber << "." << endl;
|
---|
380 | }
|
---|
381 |
|
---|
382 | // Map 10000342:1000343 to 10000351:1000351
|
---|
383 | if (fRunNumber>10000342 && fRunNumber<10000352 &&
|
---|
384 | fRunStart.GetMjd()>54254.5 && fRunStart.GetMjd()<54255.5)
|
---|
385 | {
|
---|
386 | fRunNumber -= 9000000;
|
---|
387 | *fLog << warn << "Format >V10: Wrong run number decreased by 9000000 to " << fRunNumber << "." << endl;
|
---|
388 | }
|
---|
389 |
|
---|
390 | if (fRunNumber==1000382 &&
|
---|
391 | fRunStart.GetMjd()>54256.5 && fRunStart.GetMjd()<54257.5 &&
|
---|
392 | !strcmp(fSourceName, "GRB080605-2347"))
|
---|
393 | {
|
---|
394 | fFileNumber += 99;
|
---|
395 | *fLog << warn << "Format >V10: Ambiguous file number increased by 99 to " << fFileNumber << "." << endl;
|
---|
396 | }
|
---|
397 | }
|
---|
398 |
|
---|
399 | // --------------------------------------------------------------------------
|
---|
400 | //
|
---|
401 | // This implements a fix of the pixel assignment before 25.9.2005
|
---|
402 | //
|
---|
403 | // From magic_online (the pixel numbers are hardware indices):
|
---|
404 | // --------------------------------------------------------------------------
|
---|
405 | // From: Florian Goebel <fgoebel@mppmu.mpg.de>
|
---|
406 | // Date: Sun Sep 25 2005 - 05:13:19 CEST
|
---|
407 | //
|
---|
408 | // [...]
|
---|
409 | // - problem 2: pixels were swaped
|
---|
410 | // - cause: opical fibers were wrongly connected to receiver board
|
---|
411 | // 554 <-> 559
|
---|
412 | // 555 <-> 558
|
---|
413 | // 556 <-> 557
|
---|
414 | // - action: reconnect correctly
|
---|
415 | // - result: ok now
|
---|
416 | // - comment: I don't know when this error was introduced, so backward
|
---|
417 | // correction of the data is difficult.
|
---|
418 | // Fortunately the effect is not too large since the affected 6 pixels are
|
---|
419 | // on the outermost edge of the camera
|
---|
420 | // Since this board has special pixels the optical fibers have been
|
---|
421 | // unplugged several times.
|
---|
422 | // !!!!! Whenever you unplug and reconnect optical fibers make really !!!!!
|
---|
423 | // !!!!! sure you connect them back correctly. !!!!!
|
---|
424 | // !!!!! Always contact me before you do so and if you have any doubts !!!!!
|
---|
425 | // !!!!! how to reconnect the fibers ask me. !!!!!
|
---|
426 | // These swapped pixels have only been found by chance when doing the
|
---|
427 | // flatfielding.
|
---|
428 | // [...]
|
---|
429 | //
|
---|
430 | // --------------------------------------------------------------------------
|
---|
431 | //
|
---|
432 | // MAGIC runbook CC_2006_04_22_22_28_52.rbk
|
---|
433 | //
|
---|
434 | // [2006-04-22 23:14:13]
|
---|
435 | //
|
---|
436 | // [...]
|
---|
437 | // Found 2 pairs of swapped pixels.
|
---|
438 | // We corrected swapped pixels 54<->55 in the receiver boards. We probably
|
---|
439 | // swapped today in the camera.
|
---|
440 | // We did not correct 92<-<93 which are likely swapped. Will check and correct
|
---|
441 | // tomorrow.
|
---|
442 | //
|
---|
443 | // ---
|
---|
444 | //
|
---|
445 | // comments:
|
---|
446 | // - 54<->55 were corrected but have not been swapped, hence they are swapped
|
---|
447 | // since then (run 88560 ok, run 88669 swapped; between them mostly dummy and
|
---|
448 | // test runs)
|
---|
449 | // - 92<->93 are never swapped, always ok.
|
---|
450 | //
|
---|
451 | // --------------------------------------------------------------------------
|
---|
452 | //
|
---|
453 | // MAGIC runbook CC_2006_08_28_19_40_18.rbk
|
---|
454 | //
|
---|
455 | // [2006-08-28 23:09:07]
|
---|
456 | // While doing a flatfielding we have found out that the signals for pixels
|
---|
457 | // 119 and 120 were swapped. We have fixed it by exchanging the corresponding
|
---|
458 | // fibers at the input of the receivers (not before the splitters!).
|
---|
459 | //
|
---|
460 | // ---
|
---|
461 | //
|
---|
462 | // MAGIC runbook CC_2006_08_29_15_19_14.rbk
|
---|
463 | //
|
---|
464 | // [2006-08-29 16:43:09]
|
---|
465 | // In the last hours we have found out and fixed a good number of pixels which
|
---|
466 | // were swapped: 119-120, 160-161-162 and 210-263. According to Florian,
|
---|
467 | // 160-161-162 and 210-263 were swapped since November 2005.
|
---|
468 | //
|
---|
469 | // ---
|
---|
470 | //
|
---|
471 | // mail Florian Goebel (08/30/2006 03:13 PM):
|
---|
472 | //
|
---|
473 | // As far as I can tell pixels 161 and 162 as well as 263 and 210 were
|
---|
474 | // swapped in the trigger. This leads to some inefficiency of the trigger.
|
---|
475 | // However, they were not swapped in the readout. So, you don't have to
|
---|
476 | // correct anything in the data for these pixels.
|
---|
477 | //
|
---|
478 | // ---
|
---|
479 | //
|
---|
480 | // comments:
|
---|
481 | // - 119-120 swapped between run 93251 (not swapped) and 93283 (swapped)
|
---|
482 | // (only testruns between these runs)
|
---|
483 | // corrected since run 99354 (== runbook [2006-08-28 23:09:07])
|
---|
484 | // - 160 never swapped
|
---|
485 | // - 161-162 were only swapped in the trigger, but nevertheless were
|
---|
486 | // "corrected" also in the signal. Hence signal swapped since 99354
|
---|
487 | //
|
---|
488 | Bool_t MRawRunHeader::FixAssignment()
|
---|
489 | {
|
---|
490 | if (!fTelescopeNumber==1)
|
---|
491 | return kTRUE;
|
---|
492 |
|
---|
493 | if (fRunNumber>=53300 && fRunNumber<=68754)
|
---|
494 | {
|
---|
495 | if (!SwapAssignment(554, 559))
|
---|
496 | return kFALSE;
|
---|
497 | if (!SwapAssignment(555, 558))
|
---|
498 | return kFALSE;
|
---|
499 | if (!SwapAssignment(556, 557))
|
---|
500 | return kFALSE;
|
---|
501 | }
|
---|
502 |
|
---|
503 | if (fRunNumber>=93283 && fRunNumber<99354)
|
---|
504 | {
|
---|
505 | if (!SwapAssignment(119, 120))
|
---|
506 | return kFALSE;
|
---|
507 | }
|
---|
508 |
|
---|
509 | if (fRunNumber>=99354 && fRunNumber<=101789)
|
---|
510 | {
|
---|
511 | if (!SwapAssignment(161, 162))
|
---|
512 | return kFALSE;
|
---|
513 | if (!SwapAssignment(210, 263))
|
---|
514 | return kFALSE;
|
---|
515 | }
|
---|
516 |
|
---|
517 | if (fRunNumber>=88669)
|
---|
518 | {
|
---|
519 | if (!SwapAssignment(54, 55))
|
---|
520 | return kFALSE;
|
---|
521 | }
|
---|
522 |
|
---|
523 | if (fRunNumber>=200000)
|
---|
524 | {
|
---|
525 | if (!SwapAssignment(428, 429))
|
---|
526 | return kFALSE;
|
---|
527 | }
|
---|
528 |
|
---|
529 | return kTRUE;
|
---|
530 | }
|
---|
531 |
|
---|
532 | // --------------------------------------------------------------------------
|
---|
533 | //
|
---|
534 | // Fixes to fix bugs in the run header
|
---|
535 | //
|
---|
536 | Bool_t MRawRunHeader::Fixes()
|
---|
537 | {
|
---|
538 | FixRunNumbers();
|
---|
539 |
|
---|
540 | if (fFormatVersion>8 && fRunNumber>326152 && fTelescopeNumber==1)
|
---|
541 | {
|
---|
542 | fNumEvents--;
|
---|
543 | fNumEventsRead--;
|
---|
544 | *fLog << inf << "Format >V8 and Run>M1:326152: Stored number of events decreased by 1." << endl;
|
---|
545 | }
|
---|
546 |
|
---|
547 | return FixAssignment();
|
---|
548 | }
|
---|
549 |
|
---|
550 | // --------------------------------------------------------------------------
|
---|
551 | //
|
---|
552 | // Reading function to read/interpret the file formats 1-10
|
---|
553 | //
|
---|
554 | Bool_t MRawRunHeader::ReadEvtOld(istream& fin)
|
---|
555 | {
|
---|
556 | if (fFormatVersion==7)
|
---|
557 | {
|
---|
558 | *fLog << err << "ERROR - File format V7 was for testing only and is not correctly implemented!" << endl;
|
---|
559 | return kFALSE;
|
---|
560 | }
|
---|
561 |
|
---|
562 | // ----- DAQ software format version -----
|
---|
563 | fin.read((char*)&fSoftVersion, 2); // Total=6
|
---|
564 |
|
---|
565 |
|
---|
566 | fFadcType = 1;
|
---|
567 | if (fFormatVersion>7)
|
---|
568 | fin.read((char*)&fFadcType, 2);
|
---|
569 |
|
---|
570 | // ----- Camera geometry and telescope number -----
|
---|
571 | fCameraVersion = 1;
|
---|
572 | fTelescopeNumber = 1;
|
---|
573 | if (fFormatVersion>5)
|
---|
574 | {
|
---|
575 | fin.read((char*)&fCameraVersion, 2); // (+2)
|
---|
576 | fin.read((char*)&fTelescopeNumber, 2); // (+2)
|
---|
577 | }
|
---|
578 |
|
---|
579 | // ----- Run information -----
|
---|
580 | fin.read((char*)&fRunType, 2); // Total=8
|
---|
581 |
|
---|
582 | fin.read((char*)&fRunNumber, 4); // Total=12
|
---|
583 | fin.read((char*)&fProjectName, fFormatVersion>5?100:22); // Total=34 (+78)
|
---|
584 | fin.read((char*)&fSourceName, fFormatVersion>5? 80:12); // Total=46 (+58)
|
---|
585 |
|
---|
586 | if (fFormatVersion>5)
|
---|
587 | fin.read((char*)fObservationMode, 60); // (+60)
|
---|
588 | // Maybe we should set fObservationMode to something
|
---|
589 | // in case of fFormatVersion<6
|
---|
590 |
|
---|
591 | // ----- Source position -----
|
---|
592 | fin.seekg(fFormatVersion>5 ? 16 : 8, ios::cur);
|
---|
593 | /*
|
---|
594 | if (fFormatVersion>5)
|
---|
595 | {
|
---|
596 | fin.read((char*)&fSourceRa, 4); // F32 SourceRA; Total=48
|
---|
597 | fin.read((char*)&fSourceDec, 4); // F32 SourceDEC; Total=52
|
---|
598 | }
|
---|
599 | fin.read((char*)&fTelescopeRa, 4); // F32 TelescopeRA; (+4)
|
---|
600 | fin.read((char*)&fTelescopeDec, 4); // F32 TelescopeDEC; (+4)
|
---|
601 | */
|
---|
602 |
|
---|
603 | // Maybe we should set these to something
|
---|
604 | // in case of fFormatVersion<6
|
---|
605 | fin.read((char*)&fSourceEpochChar, 2); // Total=56
|
---|
606 | fin.read((char*)&fSourceEpochDate, 2); // Total=58
|
---|
607 |
|
---|
608 | // ----- Old Start time -----
|
---|
609 | if (fFormatVersion<2) // Total += 10
|
---|
610 | {
|
---|
611 | UShort_t y, m, d;
|
---|
612 | fin.seekg(4, ios::cur); // Former fMJD[4],
|
---|
613 | fin.read((char*)&y, 2); // Former fDateYear[2]
|
---|
614 | fin.read((char*)&m, 2); // Former fDateMonth[2]
|
---|
615 | fin.read((char*)&d, 2); // Former fDateDay[2]
|
---|
616 | fRunStart.Set(y, m, d, 0, 0, 0, 0);
|
---|
617 | }
|
---|
618 |
|
---|
619 | // ----- Data Geometry -----
|
---|
620 |
|
---|
621 | fin.read((char*)&fNumCrates, 2); // MUX: number of channels
|
---|
622 | fin.read((char*)&fNumPixInCrate, 2); // MUX: number of pix in channel
|
---|
623 | fin.read((char*)&fNumSamplesLoGain, 2); // MUX: dummy (must be 0 for MUX data)
|
---|
624 | fin.read((char*)&fNumSamplesHiGain, 2); // MUX: Number of samples per pixel
|
---|
625 |
|
---|
626 | char dummy[16];
|
---|
627 | if (fFormatVersion>8)
|
---|
628 | fin.read(dummy, 4); // 2xU16 (NumSamplesRemovedHead and NumSamplesRemovedTail)
|
---|
629 |
|
---|
630 | // ----- Number of events -----
|
---|
631 | fin.read((char*)&fNumEvents, 4); // Total=70
|
---|
632 |
|
---|
633 | if (fFormatVersion>8)
|
---|
634 | fin.read((char*)&fNumEventsRead, 4);
|
---|
635 |
|
---|
636 | // New in general features: (should they be included in new MAGIC1 formats, too?)
|
---|
637 | fNumBytesPerSample = 1; // 2 for MUX DATA
|
---|
638 | fSamplingFrequency = 300;
|
---|
639 | fFadcResolution = 8;
|
---|
640 |
|
---|
641 | if (fFormatVersion>7)
|
---|
642 | {
|
---|
643 | fin.read((char*)&fNumBytesPerSample, 2);
|
---|
644 | fin.read((char*)&fSamplingFrequency, 2); // [MHz], 2000 for MuxFadc
|
---|
645 | fin.read((char*)&fFadcResolution, 1); // nominal resolution [# Bits], 10 for MuxFadc
|
---|
646 | }
|
---|
647 |
|
---|
648 | // ----- Start/Stop time -----
|
---|
649 | if (fFormatVersion>1)
|
---|
650 | {
|
---|
651 | fRunStart.ReadBinary(fin); // Total += 7
|
---|
652 | fRunStop.ReadBinary(fin); // Total += 7
|
---|
653 | }
|
---|
654 |
|
---|
655 | //
|
---|
656 | // calculate size of array, create it and fill it
|
---|
657 | //
|
---|
658 | const Int_t nPixel = fNumCrates*fNumPixInCrate;
|
---|
659 | fPixAssignment->Set(nPixel);
|
---|
660 |
|
---|
661 | // ----- Pixel Assignement -----
|
---|
662 | fin.read((char*)fPixAssignment->GetArray(), nPixel*2);
|
---|
663 |
|
---|
664 | if (fFormatVersion<7)
|
---|
665 | fin.read(dummy, 16);
|
---|
666 |
|
---|
667 | // ----- Fixes for broken files or contents -----
|
---|
668 | if (!Fixes())
|
---|
669 | return kFALSE;
|
---|
670 |
|
---|
671 | // ----- Consistency checks -----
|
---|
672 | return IsConsistent();
|
---|
673 | }
|
---|
674 |
|
---|
675 | // --------------------------------------------------------------------------
|
---|
676 | //
|
---|
677 | // Read in one run header from the binary file
|
---|
678 | //
|
---|
679 | Bool_t MRawRunHeader::ReadEvt(istream& fin)
|
---|
680 | {
|
---|
681 | //
|
---|
682 | // read one RUN HEADER from the input stream
|
---|
683 | //
|
---|
684 | fMagicNumber = 0;
|
---|
685 |
|
---|
686 | fin.read((char*)&fMagicNumber, 2); // Total=2
|
---|
687 |
|
---|
688 | //
|
---|
689 | // check whether the the file has the right file type or not
|
---|
690 | //
|
---|
691 | if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
|
---|
692 | {
|
---|
693 | *fLog << err << "ERROR - Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
|
---|
694 | return kFALSE;
|
---|
695 | }
|
---|
696 |
|
---|
697 | if (fMagicNumber == kMagicNumber+1)
|
---|
698 | *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
|
---|
699 |
|
---|
700 | // ----- File format version -----
|
---|
701 | fin.read((char*)&fFormatVersion, 2); // Total=4
|
---|
702 | if (fFormatVersion==10 || fFormatVersion>kMaxFormatVersion)
|
---|
703 | {
|
---|
704 | *fLog << err << "ERROR - File format V" << fFormatVersion << " not implemented!" << endl;
|
---|
705 | return kFALSE;
|
---|
706 | }
|
---|
707 |
|
---|
708 | // ----- Process old file formats -----
|
---|
709 | if (fFormatVersion<10)
|
---|
710 | return ReadEvtOld(fin);
|
---|
711 |
|
---|
712 | // ----- Overwrite format version for format 11 -----
|
---|
713 | fin.read((char*)&fFormatVersion, 4);
|
---|
714 | if (fFormatVersion<11)
|
---|
715 | {
|
---|
716 | *fLog << err << "ERROR - Format Version <11." << endl;
|
---|
717 | return kFALSE;
|
---|
718 | }
|
---|
719 |
|
---|
720 | // ----- Read Header by size as written in the header -----
|
---|
721 | fin.read((char*)&fHeaderSizeRun, 4);
|
---|
722 | if (fHeaderSizeRun<346)
|
---|
723 | {
|
---|
724 | *fLog << err << "ERROR - Event header too small (<388b)." << endl;
|
---|
725 | return kFALSE;
|
---|
726 | }
|
---|
727 |
|
---|
728 | TArrayC h(fHeaderSizeRun-12);
|
---|
729 | fin.read(h.GetArray(), h.GetSize());
|
---|
730 | if (!fin)
|
---|
731 | return kFALSE;
|
---|
732 |
|
---|
733 | // ----- convert -----
|
---|
734 | const Byte_t *Char = reinterpret_cast<Byte_t* >(h.GetArray());
|
---|
735 | const UInt_t *Int = reinterpret_cast<UInt_t* >(h.GetArray());
|
---|
736 | //const Float_t *Float = reinterpret_cast<Float_t*>(h.GetArray());
|
---|
737 |
|
---|
738 | // ----- Start interpretation -----
|
---|
739 |
|
---|
740 | fHeaderSizeEvt = Int[0];
|
---|
741 | fHeaderSizeCrate = Int[1];
|
---|
742 | fSoftVersion = Int[2];
|
---|
743 | fFadcType = Int[3];
|
---|
744 | fCameraVersion = Int[4];
|
---|
745 | fTelescopeNumber = Int[5];
|
---|
746 | fRunType = Int[6];
|
---|
747 | fRunNumber = Int[7];
|
---|
748 | fFileNumber = Int[8];
|
---|
749 |
|
---|
750 | memcpy(fProjectName, Char+ 36, 100); // 25
|
---|
751 | memcpy(fSourceName, Char+136, 80); // 20
|
---|
752 | memcpy(fObservationMode, Char+216, 60); // 15
|
---|
753 |
|
---|
754 | //F32 fSourceRA = Float[69];
|
---|
755 | //F32 fSourceDEC = Float[70];
|
---|
756 | //F32 fTelescopeRA = Float[71];
|
---|
757 | //F32 fTelescopeDEC = Float[72];
|
---|
758 |
|
---|
759 | memcpy(fSourceEpochChar, Char+232, 4);
|
---|
760 |
|
---|
761 | fSourceEpochDate = Int[74];
|
---|
762 | fNumCrates = Int[75];
|
---|
763 | fNumPixInCrate = Int[76];
|
---|
764 | fNumSamplesHiGain = Int[77];
|
---|
765 | fNumSamplesLoGain = 0;
|
---|
766 |
|
---|
767 | //fNumSamplesRemovedHead = Int[78];
|
---|
768 | //fNumSamplesRemovedTail = Int[79];
|
---|
769 |
|
---|
770 | fNumEvents = Int[80];
|
---|
771 | fNumEventsRead = Int[81];
|
---|
772 | fNumBytesPerSample = Int[82];
|
---|
773 | fSamplingFrequency = Int[83];
|
---|
774 | fFadcResolution = Int[84];
|
---|
775 |
|
---|
776 | fRunStart.SetBinary(Int+85);
|
---|
777 | fRunStop.SetBinary(Int+91);
|
---|
778 |
|
---|
779 | // ----- 388 bytes so far -----
|
---|
780 |
|
---|
781 | const UInt_t n = fNumCrates*fNumPixInCrate;
|
---|
782 | if (fHeaderSizeRun<388+n*4)
|
---|
783 | {
|
---|
784 | *fLog << err << "ERROR - Event header too small to contain pix assignment." << endl;
|
---|
785 | return kFALSE;
|
---|
786 | }
|
---|
787 |
|
---|
788 | // ----- Pixel Assignment -----
|
---|
789 | fPixAssignment->Set(n);
|
---|
790 |
|
---|
791 | for (UInt_t i=0; i<n; i++)
|
---|
792 | (*fPixAssignment)[i] = Int[97+i];
|
---|
793 |
|
---|
794 | // ----- Fixes for broken files or contents -----
|
---|
795 | if (!Fixes())
|
---|
796 | return kFALSE;
|
---|
797 |
|
---|
798 | // ----- Consistency checks -----
|
---|
799 | return IsConsistent();
|
---|
800 | }
|
---|
801 | /*
|
---|
802 | Bool_t MRawRunHeader::WriteEvt(ostream& out) const
|
---|
803 | {
|
---|
804 | //
|
---|
805 | // write one RUN HEADER from the input stream
|
---|
806 | //
|
---|
807 | const UInt_t n = fNumCrates*fNumPixInCrate;
|
---|
808 |
|
---|
809 | const UShort_t magicnumber = kMagicNumber;
|
---|
810 | const UInt_t formatversion = 11;
|
---|
811 | const UInt_t headersizerun = (97+n)*4; //???
|
---|
812 |
|
---|
813 | // FIXME: Write fixed number (c0c0)
|
---|
814 | out.write((char*)&magicnumber, 2); // Total=2
|
---|
815 | out.write((char*)&formatversion, 2); // Total=4
|
---|
816 | out.write((char*)&formatversion, 4);
|
---|
817 | out.write((char*)&headersizerun, 4);
|
---|
818 |
|
---|
819 | TArrayC h(headersizerun-12);
|
---|
820 |
|
---|
821 | // ----- convert -----
|
---|
822 | Byte_t *Char = reinterpret_cast<Byte_t* >(h.GetArray());
|
---|
823 | UInt_t *Int = reinterpret_cast<UInt_t* >(h.GetArray());
|
---|
824 | //const Float_t *Float = reinterpret_cast<Float_t*>(h.GetArray());
|
---|
825 |
|
---|
826 | // ----- Start interpretation -----
|
---|
827 |
|
---|
828 | Int[0] = 0; // fHeaderSizeEvt;
|
---|
829 | Int[1] = 0; // fHeaderSizeCrate;
|
---|
830 | Int[2] = 0; // fSoftVersion;
|
---|
831 | Int[3] = fFadcType;
|
---|
832 | Int[4] = fCameraVersion;
|
---|
833 | Int[5] = fTelescopeNumber;
|
---|
834 | Int[5] = fRunType;
|
---|
835 | Int[6] = fRunNumber;
|
---|
836 | Int[7] = fFileNumber;
|
---|
837 |
|
---|
838 | memcpy(Char+ 36, fProjectName, 100); // 25
|
---|
839 | memcpy(Char+136, fSourceName, 80); // 20
|
---|
840 | memcpy(Char+216, fObservationMode, 60); // 15
|
---|
841 |
|
---|
842 | //F32 fSourceRA = Float[69];
|
---|
843 | //F32 fSourceDEC = Float[70];
|
---|
844 | //F32 fTelescopeRA = Float[71];
|
---|
845 | //F32 fTelescopeDEC = Float[72];
|
---|
846 |
|
---|
847 | memcpy(Char+232, fSourceEpochChar, 4);
|
---|
848 |
|
---|
849 | Int[74] = fSourceEpochDate;
|
---|
850 | Int[75] = fNumCrates;
|
---|
851 | Int[76] = fNumPixInCrate;
|
---|
852 | Int[77] = fNumSamplesHiGain;
|
---|
853 |
|
---|
854 | //fNumSamplesRemovedHead = Int[78];
|
---|
855 | //fNumSamplesRemovedTail = Int[79];
|
---|
856 |
|
---|
857 | Int[80] = fNumEvents;
|
---|
858 | Int[81] = fNumEvents; //fNumEventsRead;
|
---|
859 | Int[82] = fNumBytesPerSample;
|
---|
860 | Int[83] = fSamplingFrequency;
|
---|
861 | Int[84] = fFadcResolution;
|
---|
862 |
|
---|
863 | fRunStart.GetBinary(Int+85);
|
---|
864 | fRunStop.GetBinary(Int+91);
|
---|
865 |
|
---|
866 | // ----- 388 bytes so far -----
|
---|
867 |
|
---|
868 | //const UInt_t n = fNumCrates*fNumPixInCrate;
|
---|
869 | //if (fHeaderSizeRun<(97+n)*4)
|
---|
870 | //{
|
---|
871 | // *fLog << err << "ERROR - Event header too small to contain pix assignment." << endl;
|
---|
872 | // return kFALSE;
|
---|
873 | //}
|
---|
874 |
|
---|
875 | // ----- Pixel Assignment -----
|
---|
876 | for (UInt_t i=0; i<n; i++)
|
---|
877 | Int[97+i] = (*fPixAssignment)[i];
|
---|
878 |
|
---|
879 | out.write(h.GetArray(), h.GetSize());
|
---|
880 |
|
---|
881 | return out;
|
---|
882 | }
|
---|
883 | */
|
---|
884 | // --------------------------------------------------------------------------
|
---|
885 | //
|
---|
886 | // Return the run type as string ("Data", "Pedestal", ...), for example
|
---|
887 | // to print it as readable text.
|
---|
888 | //
|
---|
889 | const char *MRawRunHeader::GetRunTypeStr() const
|
---|
890 | {
|
---|
891 | switch (fRunType)
|
---|
892 | {
|
---|
893 | case kRTData:
|
---|
894 | return "Data";
|
---|
895 | case kRTPedestal:
|
---|
896 | return "Pedestal";
|
---|
897 | case kRTCalibration:
|
---|
898 | return "Calibration";
|
---|
899 | case kRTLinearity:
|
---|
900 | return "Linearity";
|
---|
901 | case kRTPointRun:
|
---|
902 | return "Point-Run";
|
---|
903 | case kRTMonteCarlo:
|
---|
904 | return "Monte Carlo";
|
---|
905 | case kRTNone:
|
---|
906 | return "<none>";
|
---|
907 | default:
|
---|
908 | return "<unknown>";
|
---|
909 | }
|
---|
910 | }
|
---|
911 |
|
---|
912 | // --------------------------------------------------------------------------
|
---|
913 | //
|
---|
914 | // print run header information on *fLog. The option 'header' supresses
|
---|
915 | // the pixel index translation table.
|
---|
916 | //
|
---|
917 | void MRawRunHeader::Print(Option_t *t) const
|
---|
918 | {
|
---|
919 | *fLog << all << endl;
|
---|
920 | *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - ";
|
---|
921 | switch (fMagicNumber)
|
---|
922 | {
|
---|
923 | case kMagicNumber: *fLog << "OK"; break;
|
---|
924 | case kMagicNumber+1: *fLog << "File not closed!"; break;
|
---|
925 | default: *fLog << "Wrong!"; break;
|
---|
926 | }
|
---|
927 | *fLog << endl;
|
---|
928 | *fLog << "Versions: " << dec << "Format=" << fFormatVersion << " ";
|
---|
929 | *fLog << "Software=" << fSoftVersion << " ";
|
---|
930 | if (fFormatVersion>5)
|
---|
931 | *fLog << "Camera=" << fCameraVersion;
|
---|
932 | *fLog << endl;
|
---|
933 | if (fFormatVersion>10)
|
---|
934 | *fLog << "Header sizes: " << fHeaderSizeRun << "b (run), " << fHeaderSizeEvt << "b (evt), " << fHeaderSizeCrate << "b (crate)" << endl;
|
---|
935 | if (fRunNumber>0)
|
---|
936 | {
|
---|
937 | if (fFormatVersion>5)
|
---|
938 | *fLog << "Telescope: " << fTelescopeNumber << endl;
|
---|
939 | *fLog << "RunNumber: " << fRunNumber;
|
---|
940 | if (fFormatVersion>10)
|
---|
941 | *fLog << "/" << fFileNumber << " (id=" << GetFileID() << ")";
|
---|
942 | *fLog << " (Type=" << GetRunTypeStr() << ")" << endl;
|
---|
943 | }
|
---|
944 | if (fFormatVersion>7)
|
---|
945 | {
|
---|
946 | *fLog << "FadcType: " << fFadcType << " (";
|
---|
947 | switch (fFadcType)
|
---|
948 | {
|
---|
949 | case 1: *fLog << "Siegen"; break;
|
---|
950 | case 2: *fLog << "MUX"; break;
|
---|
951 | case 0xffff: *fLog << "artificial"; break;
|
---|
952 | default: *fLog << "unknown";
|
---|
953 | }
|
---|
954 | *fLog << ")" << endl;
|
---|
955 | }
|
---|
956 | *fLog << "ProjectName: '" << fProjectName << "'" << endl;
|
---|
957 | if (fFormatVersion>5)
|
---|
958 | *fLog << "Observation: '" << fObservationMode << "'" << endl;
|
---|
959 | *fLog << "Source: '" << fSourceName << "' " << " ";
|
---|
960 | *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
|
---|
961 | if (fRunStart)
|
---|
962 | *fLog << "Run Start: " << fRunStart << endl;
|
---|
963 | if (fRunStop)
|
---|
964 | *fLog << "Run Stop: " << fRunStop << endl;
|
---|
965 | if (fNumCrates>0 || fNumPixInCrate>0)
|
---|
966 | *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
|
---|
967 | if (GetNumConnectedPixels()>0)
|
---|
968 | *fLog << "Num Pixels: " << GetNumNormalPixels() << " (normal) + " << GetNumSpecialPixels() << " (special) = " << GetNumConnectedPixels() << " (total)" << endl;
|
---|
969 | if (fFormatVersion>6)
|
---|
970 | *fLog << "Sampling: " << fSamplingFrequency << "MHz with " << (int)fFadcResolution << " significant bits" << endl;
|
---|
971 | *fLog << "Samples: " << fNumSamplesHiGain << "/" << fNumSamplesLoGain << " (hi/lo) * " << fNumBytesPerSample << "B/sample = ";
|
---|
972 | if (fNumCrates>0)
|
---|
973 | *fLog << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate * fNumBytesPerSample/1000 << "kB/Evt" << endl;
|
---|
974 | else
|
---|
975 | *fLog << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumBytesPerSample << "B/pix" << endl;
|
---|
976 | *fLog << "Evt Counter: " << fNumEvents;
|
---|
977 | if (fFormatVersion>8)
|
---|
978 | *fLog << " (read=" << fNumEventsRead << ")";
|
---|
979 | *fLog << endl;
|
---|
980 |
|
---|
981 | if (TString(t).Contains("header", TString::kIgnoreCase))
|
---|
982 | return;
|
---|
983 |
|
---|
984 | *fLog << inf3 << "Assignment:" << hex << endl;
|
---|
985 | for (int i=0; i<GetNumPixel(); i++)
|
---|
986 | *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
|
---|
987 |
|
---|
988 | *fLog << dec << setfill(' ') << endl;
|
---|
989 | }
|
---|
990 |
|
---|
991 | // --------------------------------------------------------------------------
|
---|
992 | //
|
---|
993 | // Return the assigned pixel number for the given FADC channel
|
---|
994 | //
|
---|
995 | Short_t MRawRunHeader::GetPixAssignment(UShort_t i) const
|
---|
996 | {
|
---|
997 | // FIXME: Do we need a range check here?
|
---|
998 | return (Short_t)(*fPixAssignment)[i];
|
---|
999 | }
|
---|
1000 |
|
---|
1001 | // --------------------------------------------------------------------------
|
---|
1002 | //
|
---|
1003 | // Return the number of pixel which are markes as connected in the
|
---|
1004 | // pix assignment (!=0)
|
---|
1005 | //
|
---|
1006 | UShort_t MRawRunHeader::GetNumConnectedPixels() const
|
---|
1007 | {
|
---|
1008 | const Int_t num = fPixAssignment->GetSize();
|
---|
1009 |
|
---|
1010 | UShort_t rc = 0;
|
---|
1011 | for (int i=0; i<num; i++)
|
---|
1012 | {
|
---|
1013 | if (GetPixAssignment(i)!=0)
|
---|
1014 | rc++;
|
---|
1015 | }
|
---|
1016 | return rc;
|
---|
1017 | }
|
---|
1018 |
|
---|
1019 | // --------------------------------------------------------------------------
|
---|
1020 | //
|
---|
1021 | // Return the number of pixel which are markes as connected and so-called
|
---|
1022 | // 'normal' pixels in the pix assignment (>0)
|
---|
1023 | //
|
---|
1024 | UShort_t MRawRunHeader::GetNumNormalPixels() const
|
---|
1025 | {
|
---|
1026 | const Int_t num = fPixAssignment->GetSize();
|
---|
1027 |
|
---|
1028 | UShort_t rc = 0;
|
---|
1029 | for (int i=0; i<num; i++)
|
---|
1030 | {
|
---|
1031 | if (GetPixAssignment(i)>0)
|
---|
1032 | rc++;
|
---|
1033 | }
|
---|
1034 | return rc;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | // --------------------------------------------------------------------------
|
---|
1038 | //
|
---|
1039 | // Return the number of pixel which are markes as connected and so-called
|
---|
1040 | // 'special' pixels in the pix assignment (<0)
|
---|
1041 | //
|
---|
1042 | UShort_t MRawRunHeader::GetNumSpecialPixels() const
|
---|
1043 | {
|
---|
1044 | const Int_t num = fPixAssignment->GetSize();
|
---|
1045 |
|
---|
1046 | UShort_t rc = 0;
|
---|
1047 | for (int i=0; i<num; i++)
|
---|
1048 | {
|
---|
1049 | if (GetPixAssignment(i)<0)
|
---|
1050 | rc++;
|
---|
1051 | }
|
---|
1052 | return rc;
|
---|
1053 | }
|
---|
1054 |
|
---|
1055 | // --------------------------------------------------------------------------
|
---|
1056 | //
|
---|
1057 | // Return the maximum id which exists in the pix assignment
|
---|
1058 | //
|
---|
1059 | UShort_t MRawRunHeader::GetMaxPixId() const
|
---|
1060 | {
|
---|
1061 | const Int_t num = fPixAssignment->GetSize();
|
---|
1062 |
|
---|
1063 | Short_t rc = 0;
|
---|
1064 | for (int i=0; i<num; i++)
|
---|
1065 | rc = TMath::Max(GetPixAssignment(i), rc);
|
---|
1066 |
|
---|
1067 | return rc;
|
---|
1068 | }
|
---|
1069 |
|
---|
1070 | // --------------------------------------------------------------------------
|
---|
1071 | //
|
---|
1072 | // Return minus th minimum id which exists in the pix assignment
|
---|
1073 | //
|
---|
1074 | UShort_t MRawRunHeader::GetMinPixId() const
|
---|
1075 | {
|
---|
1076 | const Int_t num = fPixAssignment->GetSize();
|
---|
1077 |
|
---|
1078 | Short_t rc = 0;
|
---|
1079 | for (int i=0; i<num; i++)
|
---|
1080 | rc = TMath::Min(GetPixAssignment(i), rc);
|
---|
1081 |
|
---|
1082 | return (UShort_t)-rc;
|
---|
1083 | }
|
---|
1084 |
|
---|
1085 | // --------------------------------------------------------------------------
|
---|
1086 | //
|
---|
1087 | // Return the number of pixel in this event.
|
---|
1088 | //
|
---|
1089 | // WARNING: This is the number of pixels stored in this file which is
|
---|
1090 | // a multiple of the number of pixels per crate and in general
|
---|
1091 | // a number which is larger than the camera size!
|
---|
1092 | //
|
---|
1093 | // To know the range of the pixel indices please use the geometry
|
---|
1094 | // container!
|
---|
1095 | //
|
---|
1096 | UShort_t MRawRunHeader::GetNumPixel() const
|
---|
1097 | {
|
---|
1098 | return fPixAssignment->GetSize();
|
---|
1099 | }
|
---|
1100 |
|
---|
1101 | // --------------------------------------------------------------------------
|
---|
1102 | //
|
---|
1103 | // Returns absolute size in bytes of the run header as read from a raw file.
|
---|
1104 | // This must be done _after_ the header is read, because the header doesn't
|
---|
1105 | // have a fixed size (used in MRawSocketRead)
|
---|
1106 | //
|
---|
1107 | Int_t MRawRunHeader::GetNumTotalBytes() const
|
---|
1108 | {
|
---|
1109 | switch (fFormatVersion)
|
---|
1110 | {
|
---|
1111 | case 1:
|
---|
1112 | return 80+fNumCrates*fNumPixInCrate*2+16;
|
---|
1113 | case 2:
|
---|
1114 | case 3:
|
---|
1115 | case 4:
|
---|
1116 | case 5:
|
---|
1117 | return 84+fNumCrates*fNumPixInCrate*2+16;
|
---|
1118 | case 6:
|
---|
1119 | return 84+fNumCrates*fNumPixInCrate*2+16 +4+78+58+60+8;
|
---|
1120 | case 7:
|
---|
1121 | return 84+fNumCrates*fNumPixInCrate*2+16 +4+78+58+60+8 +3-16;
|
---|
1122 | }
|
---|
1123 | return 0;
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | // --------------------------------------------------------------------------
|
---|
1127 | //
|
---|
1128 | // Monte Carlo Interface
|
---|
1129 | //
|
---|
1130 | // This is a (prelimiary) way to setup an existing FADC system.
|
---|
1131 | //
|
---|
1132 | // 1: Siegen FADCs
|
---|
1133 | // 2: MUX FADCs
|
---|
1134 | //
|
---|
1135 | void MRawRunHeader::InitFadcType(UShort_t type)
|
---|
1136 | {
|
---|
1137 | switch (type)
|
---|
1138 | {
|
---|
1139 | case 1:
|
---|
1140 | fNumSamplesHiGain = 15;
|
---|
1141 | fNumSamplesLoGain = 15;
|
---|
1142 | fNumBytesPerSample = 1; // number of bytes per sample
|
---|
1143 | fSamplingFrequency = 300; // Sampling Frequency [MHz]
|
---|
1144 | fFadcResolution = 8; // number of significant bits
|
---|
1145 | break;
|
---|
1146 | case 2:
|
---|
1147 | fNumSamplesHiGain = 50;
|
---|
1148 | fNumSamplesLoGain = 0;
|
---|
1149 | fNumBytesPerSample = 2; // number of bytes per sample
|
---|
1150 | fSamplingFrequency = 2000; // Sampling Frequency [MHz]
|
---|
1151 | fFadcResolution = 12; // number of significant bits
|
---|
1152 | break;
|
---|
1153 | case 3:
|
---|
1154 | fNumSamplesHiGain = 150;
|
---|
1155 | fNumSamplesLoGain = 0;
|
---|
1156 | fNumBytesPerSample = 2; // number of bytes per sample
|
---|
1157 | fSamplingFrequency = 1000; // Sampling Frequency [MHz]
|
---|
1158 | fFadcResolution = 12; // number of significant bits
|
---|
1159 | break;
|
---|
1160 | }
|
---|
1161 |
|
---|
1162 | fFadcType = type;
|
---|
1163 | }
|
---|
1164 |
|
---|
1165 | // --------------------------------------------------------------------------
|
---|
1166 | //
|
---|
1167 | // Monte Carlo Interface
|
---|
1168 | //
|
---|
1169 | // Init a camera
|
---|
1170 | //
|
---|
1171 | void MRawRunHeader::InitCamera(UShort_t type, UShort_t pix)
|
---|
1172 | {
|
---|
1173 | switch (type)
|
---|
1174 | {
|
---|
1175 | case 1:
|
---|
1176 | fNumCrates = 1;
|
---|
1177 | fNumPixInCrate = 577;
|
---|
1178 | break;
|
---|
1179 | case 2:
|
---|
1180 | fNumCrates = 1;
|
---|
1181 | fNumPixInCrate = 703;
|
---|
1182 | break;
|
---|
1183 | case (UShort_t)-1:
|
---|
1184 | fNumCrates = 1;
|
---|
1185 | fNumPixInCrate = pix;
|
---|
1186 | break;
|
---|
1187 | }
|
---|
1188 |
|
---|
1189 | fCameraVersion = type;
|
---|
1190 |
|
---|
1191 | const Int_t n = fNumCrates*fNumPixInCrate;
|
---|
1192 |
|
---|
1193 | fPixAssignment->Set(n);
|
---|
1194 |
|
---|
1195 | for (int i=0; i<n; i++)
|
---|
1196 | (*fPixAssignment)[i] = i+1;
|
---|
1197 | }
|
---|
1198 |
|
---|
1199 | // --------------------------------------------------------------------------
|
---|
1200 | //
|
---|
1201 | // Monte Carlo Interface
|
---|
1202 | //
|
---|
1203 | // Set telescope number, run-number and file-number
|
---|
1204 | //
|
---|
1205 | void MRawRunHeader::SetRunInfo(UShort_t tel, UInt_t run, UInt_t file)
|
---|
1206 | {
|
---|
1207 | fTelescopeNumber = tel;
|
---|
1208 | fRunNumber = run;
|
---|
1209 | fFileNumber = file;
|
---|
1210 | }
|
---|
1211 |
|
---|
1212 | // --------------------------------------------------------------------------
|
---|
1213 | //
|
---|
1214 | // Monte Carlo Interface
|
---|
1215 | //
|
---|
1216 | // Set source-name, epoch (default J) and date (default 2000)
|
---|
1217 | //
|
---|
1218 | void MRawRunHeader::SetSourceInfo(const TString src, char epoch, UShort_t date)
|
---|
1219 | {
|
---|
1220 | strncpy(fSourceName, src.Data(), 80);
|
---|
1221 |
|
---|
1222 | fSourceEpochChar[0] = epoch; // epoch char of the source
|
---|
1223 | fSourceEpochDate = date; // epoch date of the source
|
---|
1224 | }
|
---|
1225 |
|
---|
1226 | // --------------------------------------------------------------------------
|
---|
1227 | //
|
---|
1228 | // Monte Carlo Interface
|
---|
1229 | //
|
---|
1230 | // Set run-start and -stop time
|
---|
1231 | //
|
---|
1232 | void MRawRunHeader::SetRunTime(const MTime &start, const MTime &end)
|
---|
1233 | {
|
---|
1234 | fRunStart = start;
|
---|
1235 | fRunStop = end;
|
---|
1236 | }
|
---|
1237 |
|
---|
1238 | // --------------------------------------------------------------------------
|
---|
1239 | //
|
---|
1240 | // Monte Carlo Interface
|
---|
1241 | //
|
---|
1242 | // Set project name and observation mode
|
---|
1243 | //
|
---|
1244 | void MRawRunHeader::SetObservation(const TString mode, const TString proj)
|
---|
1245 | {
|
---|
1246 | strncpy(fProjectName, proj.Data(), 100);
|
---|
1247 | strncpy(fObservationMode, mode.Data(), 60);
|
---|
1248 | }
|
---|
1249 |
|
---|
1250 | // --------------------------------------------------------------------------
|
---|
1251 | //
|
---|
1252 | // Monte Carlo Interface
|
---|
1253 | //
|
---|
1254 | // Set number of events in file.
|
---|
1255 | //
|
---|
1256 | void MRawRunHeader::SetNumEvents(UInt_t num)
|
---|
1257 | {
|
---|
1258 | fNumEvents = num;
|
---|
1259 | fNumEventsRead = num;
|
---|
1260 | }
|
---|
1261 |
|
---|
1262 | // --------------------------------------------------------------------------
|
---|
1263 | //
|
---|
1264 | // NumSamples: 50
|
---|
1265 | // NumBytePerSample: 2
|
---|
1266 | // SamplingFrequency: 2000
|
---|
1267 | // FadcResolution: 12
|
---|
1268 | // FadcType: XXXX
|
---|
1269 | //
|
---|
1270 | Int_t MRawRunHeader::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
1271 | {
|
---|
1272 | Bool_t rc = kFALSE;
|
---|
1273 |
|
---|
1274 | if (IsEnvDefined(env, prefix, "NumSamples", print))
|
---|
1275 | {
|
---|
1276 | rc = kTRUE;
|
---|
1277 | fNumSamplesHiGain = GetEnvValue(env, prefix, "NumSamples", fNumSamplesHiGain);
|
---|
1278 | fNumSamplesLoGain = 0;
|
---|
1279 | }
|
---|
1280 |
|
---|
1281 | if (IsEnvDefined(env, prefix, "NumBytesPerSample", print))
|
---|
1282 | {
|
---|
1283 | rc = kTRUE;
|
---|
1284 | fNumBytesPerSample = GetEnvValue(env, prefix, "NumBytesPerSample", fNumBytesPerSample);
|
---|
1285 | }
|
---|
1286 |
|
---|
1287 | if (IsEnvDefined(env, prefix, "SamplingFrequency", print))
|
---|
1288 | {
|
---|
1289 | rc = kTRUE;
|
---|
1290 | fSamplingFrequency = GetEnvValue(env, prefix, "SamplingFrequency", fSamplingFrequency);
|
---|
1291 | }
|
---|
1292 |
|
---|
1293 | if (IsEnvDefined(env, prefix, "FadcResolution", print))
|
---|
1294 | {
|
---|
1295 | rc = kTRUE;
|
---|
1296 | fFadcResolution = GetEnvValue(env, prefix, "FadcResolution", fFadcResolution);
|
---|
1297 | }
|
---|
1298 | // Saturation behaviour etc.
|
---|
1299 | if (IsEnvDefined(env, prefix, "FadcType", print))
|
---|
1300 | {
|
---|
1301 | //rc = kTRUE;
|
---|
1302 | //TString type = GetEnvValue(env, prefix, "FadcType", "");
|
---|
1303 | // Eval "Siegen", "MUX", Dwarf"
|
---|
1304 | }
|
---|
1305 | else
|
---|
1306 | if (rc)
|
---|
1307 | fFadcType = 0xffff; // "Artificial"
|
---|
1308 |
|
---|
1309 | return rc;
|
---|
1310 | }
|
---|
1311 |
|
---|