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

Last change on this file since 1963 was 1082, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 5.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@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.h>
36#include <iomanip.h>
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MArrayS.h"
42
43ClassImp(MRawRunHeader);
44
45// --------------------------------------------------------------------------
46//
47// Default constructor. Creates array which stores the pixel assignment.
48//
49//
50MRawRunHeader::MRawRunHeader(const char *name, const char *title) : fPixAssignment(NULL)
51{
52 fName = name ? name : "MRawRunHeader";
53 fTitle = title ? title : "Raw Run Header Information";
54
55 fPixAssignment = new MArrayS(0);
56}
57
58// --------------------------------------------------------------------------
59//
60// Destructor. Deletes the 'pixel-assignment-array'
61//
62MRawRunHeader::~MRawRunHeader()
63{
64 delete fPixAssignment;
65}
66
67// --------------------------------------------------------------------------
68//
69// Read in one run header from the binary file
70//
71void MRawRunHeader::ReadEvt(istream& fin)
72{
73 //
74 // read one RUN HEADER from the input stream
75 //
76 fin.read((Byte_t*)&fMagicNumber, 2);
77
78 //
79 // check whether the the file has the right file type or not
80 //
81 if (fMagicNumber != kMagicNumber)
82 {
83 *fLog << err << "Error: Wrong Magic Number: Not a Magic File!" << endl;
84 return;
85 }
86
87 Byte_t dummy[16];
88
89 fin.read((Byte_t*)&fFormatVersion, 2);
90 fin.read((Byte_t*)&fSoftVersion, 2);
91 fin.read((Byte_t*)&fRunType, 2);
92 fin.read((Byte_t*)&fRunNumber, 4);
93 fin.read((Byte_t*)&fProjectName, 22);
94 fin.read((Byte_t*)&fSourceName, 12);
95 fin.read((Byte_t*)dummy, 4); // was RA (moved to tracking system)
96 fin.read((Byte_t*)dummy, 4); // was DEC (moved to tracking system)
97 fin.read((Byte_t*)&fSourceEpochChar, 2);
98 fin.read((Byte_t*)&fSourceEpochDate, 2);
99 fin.read((Byte_t*)&fMJD, 4);
100 fin.read((Byte_t*)&fDateYear, 2);
101 fin.read((Byte_t*)&fDateMonth, 2);
102 fin.read((Byte_t*)&fDateDay, 2);
103 fin.read((Byte_t*)&fNumCrates, 2);
104 fin.read((Byte_t*)&fNumPixInCrate, 2);
105 fin.read((Byte_t*)&fNumSamplesLoGain, 2);
106 fin.read((Byte_t*)&fNumSamplesHiGain, 2);
107 fin.read((Byte_t*)&fNumEvents, 4);
108
109
110 //
111 // calculate size of array, create it and fill it
112 //
113 Int_t nPixel = fNumCrates*fNumPixInCrate;
114 fPixAssignment->Set(nPixel);
115
116 fin.read((Byte_t*)fPixAssignment->GetArray(), nPixel*2);
117 fin.read((Byte_t*)&dummy, 16);
118}
119
120// --------------------------------------------------------------------------
121//
122// print run header information on *fLog
123//
124void MRawRunHeader::Print(Option_t *t) const
125{
126 *fLog << all << endl;
127 *fLog << "MagicNumber: 0x" << hex << fMagicNumber << " - " << (fMagicNumber==kMagicNumber?"OK":"Wrong!") << endl;
128 *fLog << "Version: " << dec << "Format=" << fFormatVersion << " ";
129 *fLog << "Software=" << fSoftVersion << endl;
130 *fLog << "RunNumber: " << fRunNumber << " (Type=";
131 switch (fRunType)
132 {
133 case kRTData:
134 *fLog << "Data";
135 break;
136 case kRTPedestal:
137 *fLog << "Pedestal";
138 break;
139 case kRTCalibration:
140 *fLog << "Calibration";
141 break;
142 case kRTMonteCarlo:
143 *fLog << "Monte Carlo Data";
144 break;
145 }
146 *fLog << ")" << endl;
147 *fLog << "ProjectName: '" << fProjectName << "'" << endl;
148 *fLog << "Source: '" << fSourceName << "' " << " ";
149 *fLog << fSourceEpochChar << dec << fSourceEpochDate << endl;
150 *fLog << "Date: " << setprecision(1) << setiosflags(ios::fixed) << fMJD << " (MJD) " << fDateYear << "/" << fDateMonth << "/" << fDateDay << endl;
151 *fLog << "Crates: " << fNumCrates << " x " << fNumPixInCrate << " Pixel/Crate = " << fNumCrates*fNumPixInCrate << " Pixel/Evt" << endl;
152 *fLog << "Samples: " << fNumSamplesLoGain << "/" << fNumSamplesHiGain << " (lo/hi) = " << (fNumSamplesLoGain+fNumSamplesHiGain) * fNumCrates * fNumPixInCrate /1024 << "kB/Evt" << endl;
153 *fLog << "Evt Counter: " << fNumEvents << endl;
154
155 *fLog << hex;
156 for (int i=0; i<GetNumPixel(); i++)
157 *fLog << setfill('0') << setw(3) << (*fPixAssignment)[i] << " ";
158 *fLog << hex << endl;
159
160 *fLog << endl;
161}
162
163// --------------------------------------------------------------------------
164//
165// Return the assigned pixel number for the given FADC channel
166//
167UShort_t MRawRunHeader::GetPixAssignment(UShort_t i) const
168{
169 // FIXME: Do we need a range check here?
170 return (*fPixAssignment)[i];
171}
172
173// --------------------------------------------------------------------------
174//
175// return the number of pixel in this event.
176//
177UShort_t MRawRunHeader::GetNumPixel() const
178{
179 return fPixAssignment->GetSize();
180}
Note: See TracBrowser for help on using the repository browser.