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 |
|
---|
48 | ClassImp(MReadMarsFile);
|
---|
49 |
|
---|
50 | using namespace std;
|
---|
51 |
|
---|
52 | // --------------------------------------------------------------------------
|
---|
53 | //
|
---|
54 | // Default constructor. Don't use it.
|
---|
55 | //
|
---|
56 | MReadMarsFile::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 | //
|
---|
67 | MReadMarsFile::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 | //
|
---|
91 | MReadMarsFile::~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 | //
|
---|
102 | Int_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 | // This overload MReadTree::Notify. Before the MReadTree Notify
|
---|
119 | // TObjects are called the RunHeaders of the next files are read.
|
---|
120 | //
|
---|
121 | // WARNING: This doesn't work correctly yet, if the files are not read in
|
---|
122 | // increasing order.
|
---|
123 | //
|
---|
124 | Bool_t MReadMarsFile::Notify()
|
---|
125 | {
|
---|
126 | Int_t runtype = -1;
|
---|
127 |
|
---|
128 | const MRawRunHeader *rawheader = (MRawRunHeader*)fParList->FindObject("MRawRunHeader");
|
---|
129 | if (rawheader)
|
---|
130 | runtype = rawheader->GetRunType();
|
---|
131 |
|
---|
132 | //
|
---|
133 | // Try to read the new run headers. If reading the new run header
|
---|
134 | // was successfull call the ReInits
|
---|
135 | //
|
---|
136 | const Int_t idx = GetFileIndex();
|
---|
137 | fRun->SetEventNum(idx<0?0:idx); // Assumption: One Entry per File!
|
---|
138 | if (!fRun->Process())
|
---|
139 | {
|
---|
140 | *fLog << err << "ERROR - Cannot read new runheaders #" << idx;
|
---|
141 | *fLog << " after reading event #" << GetNumEntry() << endl;
|
---|
142 | return kFALSE;
|
---|
143 | }
|
---|
144 |
|
---|
145 | if (!MReadTree::Notify())
|
---|
146 | return kFALSE;
|
---|
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 | //
|
---|
201 | Int_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 | }
|
---|