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

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