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

Last change on this file since 646 was 609, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 4.0 KB
Line 
1/////////////////////////////////////////////////////////////////////////////
2//
3// MRawRunHeader
4//
5// Root storage container for the RUN HEADER information
6//
7////////////////////////////////////////////////////////////////////////////
8
9#include "MRawRunHeader.h"
10
11#include <fstream.h>
12#include <iomanip.h>
13
14#include "MLog.h"
15#include "MArrayS.h"
16
17ClassImp(MRawRunHeader)
18
19MRawRunHeader::MRawRunHeader(const char *name, const char *title) : fPixAssignment(NULL)
20{
21 *fName = name ? name : "MRawRunHeader";
22 *fTitle = title ? title : "Raw Run Header Information";
23
24 fPixAssignment = new MArrayS(0);
25
26 // This is only valid for root > 3.0
27 // IsA()->CanIgnoreTObjectStreamer();
28}
29
30MRawRunHeader::~MRawRunHeader()
31{
32 delete fPixAssignment;
33}
34
35void MRawRunHeader::ReadEvt(ifstream& fin)
36{
37 //
38 // read one RUN HEADER from the input stream
39 //
40 fin.read((Byte_t*)&fMagicNumber, 2);
41
42 //
43 // check whether the the file has the right file type or not
44 //
45 if (fMagicNumber != kMagicNumber)
46 {
47 *fLog << "Error: Wrong Magic Number: Not a Magic File!" << endl;
48 return;
49 }
50
51 Byte_t dummy[16];
52
53 fin.read((Byte_t*)&fFormatVersion, 2);
54 fin.read((Byte_t*)&fSoftVersion, 2);
55 fin.read((Byte_t*)&fRunType, 2);
56 fin.read((Byte_t*)&fRunNumber, 4);
57 fin.read((Byte_t*)&fProjectName, 22);
58 fin.read((Byte_t*)&fSourceName, 12);
59 fin.read((Byte_t*)dummy, 4); // was RA
60 fin.read((Byte_t*)dummy, 4); // was DEC
61 fin.read((Byte_t*)&fSourceEpochChar, 2);
62 fin.read((Byte_t*)&fSourceEpochDate, 2);
63 fin.read((Byte_t*)&fMJD, 4);
64 fin.read((Byte_t*)&fDateYear, 2);
65 fin.read((Byte_t*)&fDateMonth, 2);
66 fin.read((Byte_t*)&fDateDay, 2);
67 fin.read((Byte_t*)&fNumCrates, 2);
68 fin.read((Byte_t*)&fNumPixInCrate, 2);
69 fin.read((Byte_t*)&fNumSamplesLoGain, 2);
70 fin.read((Byte_t*)&fNumSamplesHiGain, 2);
71 fin.read((Byte_t*)&fNumEvents, 4);
72
73
74 //
75 // calculate size of array, create it and fill it
76 //
77 Int_t nPixel = fNumCrates*fNumPixInCrate;
78 fPixAssignment->Set(nPixel);
79
80 fin.read((Byte_t*)fPixAssignment->GetArray(), nPixel*2);
81 fin.read((Byte_t*)&dummy, 16);
82}
83
84void MRawRunHeader::Print(Option_t *t)
85{
86 //
87 // print run header information on screen
88 //
89 *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - " << (fMagicNumber==0xc0c0?"OK":"Wrong!") << endl;
90 *fLog << "Version: " << dec << "Format=" << fFormatVersion << " ";
91 *fLog << "Software=" << fSoftVersion << endl;
92 *fLog << "RunNumber: " << fRunNumber << " (Type=";
93 switch (fRunType)
94 {
95 case 0:
96 *fLog << "Data";
97 break;
98 case 1:
99 *fLog << "Pedestal";
100 break;
101 case 2:
102 *fLog << "Calibration";
103 break;
104 }
105 *fLog << ")" << endl;
106 *fLog << "ProjectName: '" << fProjectName << "'" << endl;
107 *fLog << "Source: '" << fSourceName << "' " << " ";
108 *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
109 *fLog << "Date: " << setprecision(1) << setiosflags(ios::fixed) << fMJD << " (MJD) " << fDateYear << "/" << fDateMonth << "/" << fDateDay << endl;
110 *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
111 *fLog << "Samples: " << fNumSamplesLoGain << "/" << fNumSamplesHiGain << " (lo/hi) = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate /1024 << "kB/Evt" << endl;
112 *fLog << "Evt Counter: " << fNumEvents << endl;
113
114 *fLog << hex;
115 for (int i=0; i<GetNumPixel(); i++)
116 *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
117 *fLog << hex << endl;
118
119 *fLog << endl;
120}
121
122UShort_t MRawRunHeader::GetPixAssignment(UShort_t i) const
123{
124 // FIXME: Do we need a range check here?
125 return (*fPixAssignment)[i];
126}
127
128UShort_t MRawRunHeader::GetNumPixel() const
129{
130 return fPixAssignment->GetSize();
131}
Note: See TracBrowser for help on using the repository browser.