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

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