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

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