source: trunk/MagicSoft/Mars/mcorsika/MCorsikaRunHeader.cc@ 9182

Last change on this file since 9182 was 9182, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 6.8 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 Qi Zhe, 06/2007 <mailto:qizhe@astro.uni-wuerzburg.de>
20
21! Copyright: MAGIC Software Development, 2000-2004
22!
23!
24\* ======================================================================== */
25
26/////////////////////////////////////////////////////////////////////////////
27//
28// MCorsikaRunHeader
29//
30// Root storage container for the RUN HEADER information
31//
32//
33// RAW DATA FORMAT VERSION
34// =======================
35//
36// Format Version 8:
37// -----------------
38// + fNumBytesPerSample;
39// + fFreqSampling;
40// + fNumSignificantBits;
41// * changes in MRawCrateHeader
42//
43// Format Version 7:
44// -----------------
45// - unused
46//
47// Format Version 6:
48// -----------------
49// + added CameraVersion
50// + added TelescopeNumber
51// + added ObservationMode
52// + added dummies for TelescopeRa/Dec
53//
54// Format Version 5:
55// -----------------
56// - now the sub millisecond information of the time is valid and decoded
57// which enhances the precision from 51.2us to 200ns
58//
59// Format Version 4:
60// -----------------
61// - added support for pixels with negative IDs
62//
63// Format Version 3:
64// -----------------
65// - ???
66//
67// Format Version 2:
68// -----------------
69// - removed mjd from data
70// - added start time
71// - added stop time
72//
73//
74// MCorsikaRunHeader CLASS VERSION
75// ===========================
76//
77// Format Version 6:
78// -----------------
79// - added fNumBytesPerSample;
80// - added fFreqSampling;
81// - added fNumSignificantBits;
82//
83// Class Version 5:
84// -----------------
85// - for compatibility with newer camera versions
86//
87// Class Version 4:
88// -----------------
89// - added fCameraVersion
90// - added fTelescopeNumber
91// - changed length of fProjectName to 101
92// - changed length of fSourceName to 81
93//
94// Class Version 3:
95// ----------------
96// - enhanced SourceName and ProjectName by one character, because
97// without telling us the guranteed trailing \0-character has
98// skipped
99//
100// Class Version 2:
101// ----------------
102// - removed fMJD, fYear, fMonth, fDay
103// - added fRunStart
104// - added fRunStop
105//
106// Class Version 1:
107// ----------------
108// - first implementation
109//
110////////////////////////////////////////////////////////////////////////////
111
112#include "MCorsikaRunHeader.h"
113
114#include <fstream>
115#include <iomanip>
116
117#include "MLog.h"
118#include "MLogManip.h"
119
120ClassImp(MCorsikaRunHeader);
121
122using namespace std;
123
124// --------------------------------------------------------------------------
125//
126// Default constructor. Creates array which stores the pixel assignment.
127//
128//
129MCorsikaRunHeader::MCorsikaRunHeader(const char *name, const char *title)
130 : fNumObsLevel(0),
131 fZdMin(0), fZdMax(-1), fAzMin(0), fAzMax(0),
132fViewConeInnerAngle(0), fViewConeOuterAngle(-1)
133{
134 fName = name ? name : "MCorsikaRunHeader";
135 fTitle = title ? title : "Raw Run Header Information";
136}
137
138// --------------------------------------------------------------------------
139//
140// Read in one run header from the binary file
141//
142Bool_t MCorsikaRunHeader::ReadEvt(istream& fin)
143{
144 char runh[4];
145 fin.read(runh, 4);
146 if (memcmp(runh, "RUNH", 4))
147 {
148 *fLog << err << "ERROR - Wrong identifier: RUNH expected." << endl;
149 return kFALSE;
150 }
151
152 Float_t f[68];
153 fin.read((char*)f, 68);
154
155 fRunNumber = TMath::Nint(f[0]);
156 fNumEvents = 0;
157
158 fRunStart.SetCorsikaTime(f[1]);
159
160 fProgramVersion = f[2]; //FIXME: INT???
161 fNumObsLevel = TMath::Nint(f[3]);
162
163 memset(fObsLevel, 0, 10*4);
164 memcpy(fObsLevel, f+4, fNumObsLevel*4);
165
166 fSlopeSpectrum = f[14];
167 fEnergyMin = f[15];
168 fEnergyMax = f[16];
169
170 fin.seekg(1020, ios::cur); // skip the remaining data of this block
171
172 return kTRUE;
173}
174
175Bool_t MCorsikaRunHeader::ReadEvtEnd(istream& fin)
176{
177 char runh[4];
178 fin.read(runh, 4);
179 if (memcmp(runh, "RUNE", 4))
180 {
181 *fLog << err << "ERROR - Wrong identifier: RUNE expected." << endl;
182 return kFALSE;
183 }
184
185 Float_t f[2];
186 fin.read((char*)f, 2*4);
187
188 const UInt_t runnum = TMath::Nint(f[0]);
189 if (runnum!=fRunNumber)
190 {
191 *fLog << err << "ERROR - Mismatch in stream: Run number in RUNE (";
192 *fLog << runnum << ") doesn't match RUNH (" << fRunNumber << ")." << endl;
193 return kFALSE;
194 }
195
196 fNumEvents = TMath::Nint(f[1]);
197
198 fin.seekg(270*4, ios::cur); // skip the remaining data of this block
199
200 return kTRUE;
201}
202
203Bool_t MCorsikaRunHeader::SeekEvtEnd(istream &fin)
204{
205 // Search subblockwise backward (Block: 5733*4 = 21*273*4)
206 for (int i=1; i<22; i++)
207 {
208 fin.seekg(-i*273*4, ios::end);
209
210 char runh[4];
211 fin.read(runh, 4);
212
213 if (!memcmp(runh, "RUNE", 4))
214 {
215 fin.seekg(-4, ios::cur);
216 return kTRUE;
217 }
218 }
219
220 return kFALSE;
221}
222
223// --------------------------------------------------------------------------
224//
225// print run header information on *fLog. The option 'header' supresses
226// the pixel index translation table.
227//
228void MCorsikaRunHeader::Print(Option_t *t) const
229{
230 *fLog << all << endl;
231 *fLog << "Run Number: " << fRunNumber << " (" << fRunStart.GetStringFmt("%d.%m.%Y") << ", V" << fProgramVersion << ")" << endl;
232 if (fNumEvents>0)
233 *fLog << "Num Events: " << fNumEvents << endl;
234 *fLog << "Obs Level: ";
235 for (Byte_t i=0; i<fNumObsLevel; i++)
236 *fLog << " " << fObsLevel[i]/100. << "m";
237 *fLog << endl;
238 *fLog << "Spectrum: Slope=" << fSlopeSpectrum << " (" << fEnergyMin << "GeV-" << fEnergyMax << "GeV)" << endl;
239
240 if (fViewConeOuterAngle>0)
241 *fLog << "ViewCone: " << fViewConeInnerAngle << "deg-" << fViewConeOuterAngle << "deg" << endl;
242
243 if (fZdMax>=0)
244 {
245 *fLog << "Zd/Az: " << fZdMin << "deg";
246 if (fZdMin==fZdMax)
247 *fLog << " (fixed)";
248 else
249 *fLog << "-" << fZdMax << "deg";
250 *fLog << " / " << fAzMin << "deg";
251 if (fAzMin==fAzMax)
252 *fLog << " (fixed)";
253 else
254 *fLog << "-" << fAzMax << "deg";
255 *fLog << endl;
256 }
257}
258
Note: See TracBrowser for help on using the repository browser.