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

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