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

Last change on this file since 2371 was 2299, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.5 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#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
43ClassImp(MRawRunHeader);
44
45using namespace std;
46
47// --------------------------------------------------------------------------
48//
49// Default constructor. Creates array which stores the pixel assignment.
50//
51//
52MRawRunHeader::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//
82MRawRunHeader::~MRawRunHeader()
83{
84 delete fPixAssignment;
85}
86
87// --------------------------------------------------------------------------
88//
89// Read in one run header from the binary file
90//
91void MRawRunHeader::ReadEvt(istream& fin)
92{
93 //
94 // read one RUN HEADER from the input stream
95 //
96 fin.read((char*)&fMagicNumber, 2);
97
98 //
99 // check whether the the file has the right file type or not
100 //
101 if (fMagicNumber != kMagicNumber && fMagicNumber != kMagicNumber+1)
102 {
103 *fLog << err << "Error: Wrong Magic Number: Not a Magic File!" << endl;
104 return;
105 }
106
107 if (fMagicNumber == kMagicNumber && fMagicNumber != kMagicNumber+1)
108 *fLog << warn << "WARNING - This file maybe broken (0xc0c1) - DAQ didn't close it correctly!" << endl;
109
110 Byte_t dummy[16];
111
112 fin.read((char*)&fFormatVersion, 2);
113 fin.read((char*)&fSoftVersion, 2);
114 fin.read((char*)&fRunType, 2);
115 fin.read((char*)&fRunNumber, 4);
116 fin.read((char*)&fProjectName, 22);
117 fin.read((char*)&fSourceName, 12);
118 fin.read((char*)dummy, 4); // was RA (moved to tracking system)
119 fin.read((char*)dummy, 4); // was DEC (moved to tracking system)
120 fin.read((char*)&fSourceEpochChar, 2);
121 fin.read((char*)&fSourceEpochDate, 2);
122 fin.read((char*)&fMJD, 4);
123 fin.read((char*)&fDateYear, 2);
124 fin.read((char*)&fDateMonth, 2);
125 fin.read((char*)&fDateDay, 2);
126 fin.read((char*)&fNumCrates, 2);
127 fin.read((char*)&fNumPixInCrate, 2);
128 fin.read((char*)&fNumSamplesLoGain, 2);
129 fin.read((char*)&fNumSamplesHiGain, 2);
130 fin.read((char*)&fNumEvents, 4);
131
132
133 //
134 // calculate size of array, create it and fill it
135 //
136 Int_t nPixel = fNumCrates*fNumPixInCrate;
137 fPixAssignment->Set(nPixel);
138
139 fin.read((char*)fPixAssignment->GetArray(), nPixel*2);
140 fin.read((char*)&dummy, 16);
141}
142
143// --------------------------------------------------------------------------
144//
145// print run header information on *fLog
146//
147void MRawRunHeader::Print(Option_t *t) const
148{
149 *fLog << all << endl;
150 *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - " << (fMagicNumber==kMagicNumber?"OK":"Wrong!") << endl;
151 *fLog << "Version: " << dec << "Format=" << fFormatVersion << " ";
152 *fLog << "Software=" << fSoftVersion << endl;
153 *fLog << "RunNumber: " << fRunNumber << " (Type=";
154 switch (fRunType)
155 {
156 case kRTData:
157 *fLog << "Data";
158 break;
159 case kRTPedestal:
160 *fLog << "Pedestal";
161 break;
162 case kRTCalibration:
163 *fLog << "Calibration";
164 break;
165 case kRTMonteCarlo:
166 *fLog << "Monte Carlo Data";
167 break;
168 }
169 *fLog << ")" << endl;
170 *fLog << "ProjectName: '" << fProjectName << "'" << endl;
171 *fLog << "Source: '" << fSourceName << "' " << " ";
172 *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
173 *fLog << "Date: " << setprecision(1) << setiosflags(ios::fixed) << fMJD << " (MJD) " << fDateYear << "/" << fDateMonth << "/" << fDateDay << endl;
174 *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
175 *fLog << "Samples: " << fNumSamplesLoGain << "/" << fNumSamplesHiGain << " (lo/hi) = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate /1024 << "kB/Evt" << endl;
176 *fLog << "Evt Counter: " << fNumEvents << endl;
177
178 *fLog << inf << hex;
179 for (int i=0; i<GetNumPixel(); i++)
180 *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
181 *fLog << hex << endl;
182
183 *fLog << endl;
184}
185
186// --------------------------------------------------------------------------
187//
188// Return the assigned pixel number for the given FADC channel
189//
190UShort_t MRawRunHeader::GetPixAssignment(UShort_t i) const
191{
192 // FIXME: Do we need a range check here?
193 return (*fPixAssignment)[i];
194}
195
196UShort_t MRawRunHeader::GetNumConnectedPixels() const
197{
198 const Int_t num = fPixAssignment->GetSize();
199
200 UShort_t rc = 0;
201 for (int i=0; i<num; i++)
202 if (GetPixAssignment(i)>0)
203 rc++;
204 return rc;
205}
206
207// --------------------------------------------------------------------------
208//
209// return the number of pixel in this event.
210//
211UShort_t MRawRunHeader::GetNumPixel() const
212{
213 return fPixAssignment->GetSize();
214}
Note: See TracBrowser for help on using the repository browser.