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

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