source: trunk/MagicSoft/Mars/mbase/MReadMarsFile.cc@ 1355

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