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@uni-sw.gwdg.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MRawRunHeader
|
---|
28 | //
|
---|
29 | // Root storage container for the RUN HEADER information
|
---|
30 | //
|
---|
31 | ////////////////////////////////////////////////////////////////////////////
|
---|
32 |
|
---|
33 | #include "MRawRunHeader.h"
|
---|
34 |
|
---|
35 | #include <fstream>
|
---|
36 | #include <iomanip>
|
---|
37 |
|
---|
38 | #include "MLog.h"
|
---|
39 | #include "MLogManip.h"
|
---|
40 |
|
---|
41 | #include "MArrayS.h"
|
---|
42 |
|
---|
43 | ClassImp(MRawRunHeader);
|
---|
44 |
|
---|
45 | using namespace std;
|
---|
46 |
|
---|
47 | // --------------------------------------------------------------------------
|
---|
48 | //
|
---|
49 | // Default constructor. Creates array which stores the pixel assignment.
|
---|
50 | //
|
---|
51 | //
|
---|
52 | MRawRunHeader::MRawRunHeader(const char *name, const char *title) : fPixAssignment(NULL)
|
---|
53 | {
|
---|
54 | fName = name ? name : "MRawRunHeader";
|
---|
55 | fTitle = title ? title : "Raw Run Header Information";
|
---|
56 |
|
---|
57 | fPixAssignment = new MArrayS(0);
|
---|
58 |
|
---|
59 | fFormatVersion=0;
|
---|
60 | fSoftVersion=0;
|
---|
61 | fRunType=0;
|
---|
62 | fRunNumber=0;
|
---|
63 | fProjectName[0]=0;
|
---|
64 | fSourceName[0]=0;
|
---|
65 | fSourceEpochChar[0]=0;
|
---|
66 | fSourceEpochDate=0;
|
---|
67 | fMJD=0;
|
---|
68 | fDateYear=0;
|
---|
69 | fDateMonth=0;
|
---|
70 | fDateDay=0;
|
---|
71 | fNumCrates=0;
|
---|
72 | fNumPixInCrate=0;
|
---|
73 | fNumSamplesLoGain=0;
|
---|
74 | fNumSamplesHiGain=0;
|
---|
75 | fNumEvents=0;
|
---|
76 | }
|
---|
77 |
|
---|
78 | // --------------------------------------------------------------------------
|
---|
79 | //
|
---|
80 | // Destructor. Deletes the 'pixel-assignment-array'
|
---|
81 | //
|
---|
82 | MRawRunHeader::~MRawRunHeader()
|
---|
83 | {
|
---|
84 | delete fPixAssignment;
|
---|
85 | }
|
---|
86 |
|
---|
87 | // --------------------------------------------------------------------------
|
---|
88 | //
|
---|
89 | // Read in one run header from the binary file
|
---|
90 | //
|
---|
91 | void MRawRunHeader::ReadEvt(istream& fin)
|
---|
92 | {
|
---|
93 | //
|
---|
94 | // read one RUN HEADER from the input stream
|
---|
95 | //
|
---|
96 | fMagicNumber = 0;
|
---|
97 |
|
---|
98 | fin.read((char*)&fMagicNumber, 2); // Total=2
|
---|
99 |
|
---|
100 | //
|
---|
101 | // check whether the the file has the right file type or not
|
---|
102 | //
|
---|
103 | if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
|
---|
104 | {
|
---|
105 | *fLog << err << "Error: Wrong Magic Number (0x" << hex << fMagicNumber << "): Not a Magic File!" << endl;
|
---|
106 | return;
|
---|
107 | }
|
---|
108 |
|
---|
109 | if (fMagicNumber == kMagicNumber+1)
|
---|
110 | *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
|
---|
111 |
|
---|
112 | Byte_t dummy[16];
|
---|
113 |
|
---|
114 | fin.read((char*)&fFormatVersion, 2); // Total=4
|
---|
115 | fin.read((char*)&fSoftVersion, 2); // Total=6
|
---|
116 | fin.read((char*)&fRunType, 2); // Total=8
|
---|
117 | fin.read((char*)&fRunNumber, 4); // Total=12
|
---|
118 | fin.read((char*)&fProjectName, 22); // Total=34
|
---|
119 | fin.read((char*)&fSourceName, 12); // Total=46
|
---|
120 | fin.read((char*)dummy, 4); // was RA (moved to tracking system)
|
---|
121 | fin.read((char*)dummy, 4); // was DEC (moved to tracking system)
|
---|
122 | fin.read((char*)&fSourceEpochChar, 2); // Total=56
|
---|
123 | fin.read((char*)&fSourceEpochDate, 2); // Total=58
|
---|
124 | fin.read((char*)&fMJD, 4); // Total=62
|
---|
125 | fin.read((char*)&fDateYear, 2); // Total=64
|
---|
126 | fin.read((char*)&fDateMonth, 2); // Total=66
|
---|
127 | fin.read((char*)&fDateDay, 2); // Total=68
|
---|
128 | fin.read((char*)&fNumCrates, 2); // Total=70
|
---|
129 | fin.read((char*)&fNumPixInCrate, 2); // Total=72
|
---|
130 | fin.read((char*)&fNumSamplesLoGain, 2); // Total=74
|
---|
131 | fin.read((char*)&fNumSamplesHiGain, 2); // Total=76
|
---|
132 | fin.read((char*)&fNumEvents, 4); // Total=80
|
---|
133 |
|
---|
134 |
|
---|
135 | //
|
---|
136 | // calculate size of array, create it and fill it
|
---|
137 | //
|
---|
138 | Int_t nPixel = fNumCrates*fNumPixInCrate;
|
---|
139 | fPixAssignment->Set(nPixel);
|
---|
140 |
|
---|
141 | fin.read((char*)fPixAssignment->GetArray(), nPixel*2);
|
---|
142 | fin.read((char*)&dummy, 16);
|
---|
143 | }
|
---|
144 |
|
---|
145 | // --------------------------------------------------------------------------
|
---|
146 | //
|
---|
147 | // print run header information on *fLog
|
---|
148 | //
|
---|
149 | void MRawRunHeader::Print(Option_t *t) const
|
---|
150 | {
|
---|
151 | *fLog << all << endl;
|
---|
152 | *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - ";
|
---|
153 | switch (fMagicNumber)
|
---|
154 | {
|
---|
155 | case kMagicNumber: *fLog << "OK"; break;
|
---|
156 | case kMagicNumber+1: *fLog << "File not closed!"; break;
|
---|
157 | default: *fLog << "Wrong!"; break;
|
---|
158 | }
|
---|
159 | *fLog << endl;
|
---|
160 | *fLog << "Version: " << dec << "Format=" << fFormatVersion << " ";
|
---|
161 | *fLog << "Software=" << fSoftVersion << endl;
|
---|
162 | *fLog << "RunNumber: " << fRunNumber << " (Type=";
|
---|
163 | switch (fRunType)
|
---|
164 | {
|
---|
165 | case kRTData:
|
---|
166 | *fLog << "Data";
|
---|
167 | break;
|
---|
168 | case kRTPedestal:
|
---|
169 | *fLog << "Pedestal";
|
---|
170 | break;
|
---|
171 | case kRTCalibration:
|
---|
172 | *fLog << "Calibration";
|
---|
173 | break;
|
---|
174 | case kRTMonteCarlo:
|
---|
175 | *fLog << "Monte Carlo Data";
|
---|
176 | break;
|
---|
177 | }
|
---|
178 | *fLog << ")" << endl;
|
---|
179 | *fLog << "ProjectName: '" << fProjectName << "'" << endl;
|
---|
180 | *fLog << "Source: '" << fSourceName << "' " << " ";
|
---|
181 | *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
|
---|
182 | *fLog << "Date: " << setprecision(1) << setiosflags(ios::fixed) << fMJD << " (MJD) " << fDateYear << "/" << fDateMonth << "/" << fDateDay << endl;
|
---|
183 | *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
|
---|
184 | *fLog << "Samples: " << fNumSamplesLoGain << "/" << fNumSamplesHiGain << " (lo/hi) = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate /1024 << "kB/Evt" << endl;
|
---|
185 | *fLog << "Evt Counter: " << fNumEvents << endl;
|
---|
186 |
|
---|
187 | *fLog << inf << hex;
|
---|
188 | for (int i=0; i<GetNumPixel(); i++)
|
---|
189 | *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
|
---|
190 | *fLog << hex << endl;
|
---|
191 |
|
---|
192 | *fLog << endl;
|
---|
193 | }
|
---|
194 |
|
---|
195 | // --------------------------------------------------------------------------
|
---|
196 | //
|
---|
197 | // Return the assigned pixel number for the given FADC channel
|
---|
198 | //
|
---|
199 | UShort_t MRawRunHeader::GetPixAssignment(UShort_t i) const
|
---|
200 | {
|
---|
201 | // FIXME: Do we need a range check here?
|
---|
202 | return (*fPixAssignment)[i];
|
---|
203 | }
|
---|
204 |
|
---|
205 | UShort_t MRawRunHeader::GetNumConnectedPixels() const
|
---|
206 | {
|
---|
207 | const Int_t num = fPixAssignment->GetSize();
|
---|
208 |
|
---|
209 | UShort_t rc = 0;
|
---|
210 | for (int i=0; i<num; i++)
|
---|
211 | if (GetPixAssignment(i)>0)
|
---|
212 | rc++;
|
---|
213 | return rc;
|
---|
214 | }
|
---|
215 |
|
---|
216 | // --------------------------------------------------------------------------
|
---|
217 | //
|
---|
218 | // return the number of pixel in this event.
|
---|
219 | //
|
---|
220 | UShort_t MRawRunHeader::GetNumPixel() const
|
---|
221 | {
|
---|
222 | return fPixAssignment->GetSize();
|
---|
223 | }
|
---|
224 |
|
---|
225 | // --------------------------------------------------------------------------
|
---|
226 | //
|
---|
227 | // Returns absolute size in bytes of the run header as read from a raw file.
|
---|
228 | // This must be done _after_ the header is read, because the header doesn't
|
---|
229 | // have a fixed size (used in MRawSocketRead)
|
---|
230 | //
|
---|
231 | Int_t MRawRunHeader::GetNumTotalBytes() const
|
---|
232 | {
|
---|
233 | return 80+fNumCrates*fNumPixInCrate*2+16;
|
---|
234 | }
|
---|