source: trunk/MagicSoft/Mars/mraw/MRawRunHeader.cc@ 8969

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