source: trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc@ 2057

Last change on this file since 2057 was 1965, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 7.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@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26// //
27// MReadMarsFile //
28// //
29// This task works more or less like MReadTree, but in addition PreProcess //
30// reads all the information from the 'RunHeader' tree. //
31// //
32// Warning: Until now this works only for 'one run header per file' //
33// //
34/////////////////////////////////////////////////////////////////////////////
35
36#include "MReadMarsFile.h"
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MParList.h"
42#include "MTaskList.h"
43
44#include "MRawRunHeader.h"
45#include "MStatusDisplay.h"
46
47#include "MMcRunHeader.hxx"
48
49ClassImp(MReadMarsFile);
50
51// --------------------------------------------------------------------------
52//
53// Default constructor. Don't use it.
54//
55MReadMarsFile::MReadMarsFile() : fRun(NULL)
56{
57 fName = "MRead";
58 fTitle = "Read tree and run headers from Mars file.";
59}
60
61// --------------------------------------------------------------------------
62//
63// Default constructor. It creates a MReadTree object to read the
64// RunHeaders and disables Auto Scheme for this tree.
65//
66MReadMarsFile::MReadMarsFile(const char *tname, const char *fname,
67 const char *name, const char *title)
68 : MReadTree(tname, fname)
69{
70 fName = name ? name : "MRead";
71 fTitle = title ? title : "Read tree and run headers from Mars file.";
72
73 //
74 // open the input stream
75 //
76 fRun = new MReadTree("RunHeaders", fname, "ReadRunHeaders");
77
78 //
79 // This disables the auto scheme. because reading new runheader is done
80 // at a low frequency we don't loose time if we always read all
81 // runheaders
82 //
83 fRun->DisableAutoScheme();
84}
85
86// --------------------------------------------------------------------------
87//
88// Destructor. Deleted the MReadTree object for the RunHeaders
89//
90MReadMarsFile::~MReadMarsFile()
91{
92 delete fRun;
93}
94
95// --------------------------------------------------------------------------
96//
97// see MReadTree::AddFile, too. The file is also added to the chain for
98// the run headers. If adding file gives a different result for both
99// chains -1 is returned, otherwise the number of files which were added.
100//
101Int_t MReadMarsFile::AddFile(const char *fname, Int_t entries)
102{
103 //
104 // FIXME! A check is missing whether the file already exists or not.
105 //
106 //
107 // returns the number of file which were added
108 //
109 Int_t n1 = fRun->AddFile(fname);
110 Int_t n2 = MReadTree::AddFile(fname, entries);
111
112 return n1 != n2 ? -1 : n1;
113}
114
115// --------------------------------------------------------------------------
116//
117// This overload MReadTree::Notify. Before the MReadTree Notify
118// TObjects are called the RunHeaders of the next files are read.
119//
120// WARNING: This doesn't work correctly yet, if the files are not read in
121// increasing order.
122//
123Bool_t MReadMarsFile::Notify()
124{
125 Int_t runtype = -1;
126
127 const MRawRunHeader *rawheader = (MRawRunHeader*)fParList->FindObject("MRawRunHeader");
128 if (rawheader)
129 runtype = rawheader->GetRunType();
130
131 //
132 // Try to read the new run headers. If reading the new run header
133 // was successfull call the ReInits
134 //
135 const Int_t idx = GetFileIndex();
136 fRun->SetEventNum(idx<0?0:idx); // Assumption: One Entry per File!
137 if (!fRun->Process())
138 {
139 *fLog << err << "ERROR - Cannot read new runheaders #" << idx;
140 *fLog << " after reading event #" << GetNumEntry() << endl;
141 return kFALSE;
142 }
143
144 *fLog << inf << "MReadMarsFile: Switching to #" << GetFileIndex();
145 *fLog << " '" << GetFileName() << "' (before event #";
146 *fLog << GetNumEntry()-1 << ")" << endl;
147
148 if (fDisplay)
149 {
150 TString txt = GetFileName();
151 txt += " @ ";
152 txt += GetNumEntry()-1;
153 fDisplay->SetStatusLine2(txt);
154 }
155
156 if (rawheader)
157 {
158 if (runtype != rawheader->GetRunType())
159 *fLog << warn << "Warning - You are mixing files with different run types!" << endl;
160 }
161
162 const MMcRunHeader *mcheader = (MMcRunHeader*)fParList->FindObject("MMcRunHeader");
163 if (mcheader)
164 {
165 if (mcheader->GetReflVersion()<=40 && mcheader->GetTelesTheta()>15)
166 {
167 *fLog << warn << "Warning - You may use Monte Carlo data produced with a version" << endl;
168 *fLog << "of the reflector program < 0.4 and a zenith angle > 15," << endl;
169 *fLog << "in this case you may get less photons than you would expect." << endl;
170 }
171 if (mcheader->GetCamVersion()==50)
172 {
173 *fLog << warn << "Warning - You are using a file created with Camera 0.5." << endl;
174 *fLog << "In this camera version some events have undefined Impact-Values" << endl;
175 *fLog << "(MMcEvt::fImpact) Please don't use it for MC studies using the" << endl;
176 *fLog << "impact parameter." << endl;
177 }
178 }
179
180 MTaskList *tlist = (MTaskList*)fParList->FindObject("MTaskList");
181 if (!tlist)
182 {
183 *fLog << err << dbginf << "ERROR - Task List not found in Parameter List." << endl;
184 return kFALSE;
185 }
186
187 if (tlist->ReInit())
188 return kTRUE;
189
190 //MReadTree::Notify();
191
192 *fLog << err << "ERROR - ReInit of '" << tlist->GetName() << "' failed." << endl;
193 return kFALSE;
194}
195
196// --------------------------------------------------------------------------
197//
198// PreProcessed the MReadTree to read the run headers and its base class.
199// see MReadTree::PreProcess for more information
200//
201Bool_t MReadMarsFile::PreProcess(MParList *pList)
202{
203 fParList = pList;
204
205 if (!fRun->PreProcess(pList))
206 {
207 *fLog << err << "Error - PreProcessing MReadMarsFile::fRun... aborting." << endl;
208 return kFALSE;
209 }
210
211 const Int_t idx = GetFileIndex();
212 fRun->SetEventNum(idx<0?0:idx); // Assumption: One Entry per File!
213 if (!fRun->Process())
214 {
215 *fLog << err << "Error - Processing MReadMarsFile::fRun... aborting." << endl;
216 return kFALSE;
217 }
218
219 return MReadTree::PreProcess(pList);
220}
Note: See TracBrowser for help on using the repository browser.