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