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 |
|
---|
49 | ClassImp(MReadMarsFile);
|
---|
50 |
|
---|
51 | // --------------------------------------------------------------------------
|
---|
52 | //
|
---|
53 | // Default constructor. Don't use it.
|
---|
54 | //
|
---|
55 | MReadMarsFile::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 | //
|
---|
66 | MReadMarsFile::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 | //
|
---|
90 | MReadMarsFile::~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 | //
|
---|
101 | Int_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 | //
|
---|
123 | Bool_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 | if (!MReadTree::Notify())
|
---|
145 | return kFALSE;
|
---|
146 |
|
---|
147 | if (fDisplay)
|
---|
148 | {
|
---|
149 | TString txt = GetFileName();
|
---|
150 | txt += " @ ";
|
---|
151 | txt += GetNumEntry()-1;
|
---|
152 | fDisplay->SetStatusLine2(txt);
|
---|
153 | }
|
---|
154 |
|
---|
155 | if (rawheader)
|
---|
156 | {
|
---|
157 | if (runtype != rawheader->GetRunType())
|
---|
158 | *fLog << warn << "Warning - You are mixing files with different run types!" << endl;
|
---|
159 | }
|
---|
160 |
|
---|
161 | const MMcRunHeader *mcheader = (MMcRunHeader*)fParList->FindObject("MMcRunHeader");
|
---|
162 | if (mcheader)
|
---|
163 | {
|
---|
164 | if (mcheader->GetReflVersion()<=40 && mcheader->GetTelesTheta()>15)
|
---|
165 | {
|
---|
166 | *fLog << warn << "Warning - You may use Monte Carlo data produced with a version" << endl;
|
---|
167 | *fLog << "of the reflector program < 0.4 and a zenith angle > 15," << endl;
|
---|
168 | *fLog << "in this case you may get less photons than you would expect." << endl;
|
---|
169 | }
|
---|
170 | if (mcheader->GetCamVersion()==50)
|
---|
171 | {
|
---|
172 | *fLog << warn << "Warning - You are using a file created with Camera 0.5." << endl;
|
---|
173 | *fLog << "In this camera version some events have undefined Impact-Values" << endl;
|
---|
174 | *fLog << "(MMcEvt::fImpact) Please don't use it for MC studies using the" << endl;
|
---|
175 | *fLog << "impact parameter." << endl;
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | MTaskList *tlist = (MTaskList*)fParList->FindObject("MTaskList");
|
---|
180 | if (!tlist)
|
---|
181 | {
|
---|
182 | *fLog << err << dbginf << "ERROR - Task List not found in Parameter List." << endl;
|
---|
183 | return kFALSE;
|
---|
184 | }
|
---|
185 |
|
---|
186 | if (tlist->ReInit())
|
---|
187 | return kTRUE;
|
---|
188 |
|
---|
189 | //MReadTree::Notify();
|
---|
190 |
|
---|
191 | *fLog << err << "ERROR - ReInit of '" << tlist->GetName() << "' failed." << endl;
|
---|
192 | return kFALSE;
|
---|
193 | }
|
---|
194 |
|
---|
195 | // --------------------------------------------------------------------------
|
---|
196 | //
|
---|
197 | // PreProcessed the MReadTree to read the run headers and its base class.
|
---|
198 | // see MReadTree::PreProcess for more information
|
---|
199 | //
|
---|
200 | Bool_t MReadMarsFile::PreProcess(MParList *pList)
|
---|
201 | {
|
---|
202 | fParList = pList;
|
---|
203 |
|
---|
204 | if (!fRun->PreProcess(pList))
|
---|
205 | {
|
---|
206 | *fLog << err << "Error - PreProcessing MReadMarsFile::fRun... aborting." << endl;
|
---|
207 | return kFALSE;
|
---|
208 | }
|
---|
209 |
|
---|
210 | const Int_t idx = GetFileIndex();
|
---|
211 | fRun->SetEventNum(idx<0?0:idx); // Assumption: One Entry per File!
|
---|
212 | if (!fRun->Process())
|
---|
213 | {
|
---|
214 | *fLog << err << "Error - Processing MReadMarsFile::fRun... aborting." << endl;
|
---|
215 | return kFALSE;
|
---|
216 | }
|
---|
217 |
|
---|
218 | return MReadTree::PreProcess(pList);
|
---|
219 | }
|
---|