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 |
|
---|
48 | ClassImp(MReadMarsFile);
|
---|
49 |
|
---|
50 | // --------------------------------------------------------------------------
|
---|
51 | //
|
---|
52 | // Default constructor. Don't use it.
|
---|
53 | //
|
---|
54 | MReadMarsFile::MReadMarsFile() : fRun(NULL)
|
---|
55 | {
|
---|
56 | fName = "MRead";
|
---|
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 | //
|
---|
65 | MReadMarsFile::MReadMarsFile(const char *tname, const char *fname,
|
---|
66 | const char *name, const char *title)
|
---|
67 | : MReadTree(tname, fname)
|
---|
68 | {
|
---|
69 | fName = name ? name : "MRead";
|
---|
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 | //
|
---|
89 | MReadMarsFile::~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 | //
|
---|
100 | Int_t MReadMarsFile::AddFile(const char *fname, Int_t entries)
|
---|
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, entries);
|
---|
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 | //
|
---|
122 | Bool_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 #" << GetNumEntry() << endl;
|
---|
140 | return kFALSE;
|
---|
141 | }
|
---|
142 |
|
---|
143 | *fLog << inf << "MReadMarsFile: Switching to #" << GetFileIndex();
|
---|
144 | *fLog << " '" << GetFileName() << "' (before event #";
|
---|
145 | *fLog << GetNumEntry()-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 | if (mcheader->GetCamVersion()==50)
|
---|
163 | {
|
---|
164 | *fLog << warn << "Warning - You are using a file created with Camera 0.5." << endl;
|
---|
165 | *fLog << "In this camera version some events have undefined Impact-Values" << endl;
|
---|
166 | *fLog << "(MMcEvt::fImpact) Please don't use it for MC studies using the" << endl;
|
---|
167 | *fLog << "impact parameter." << endl;
|
---|
168 | }
|
---|
169 | }
|
---|
170 |
|
---|
171 | MTaskList *tlist = (MTaskList*)fParList->FindObject("MTaskList");
|
---|
172 | if (!tlist)
|
---|
173 | {
|
---|
174 | *fLog << err << dbginf << "ERROR - Task List not found in Parameter List." << endl;
|
---|
175 | return kFALSE;
|
---|
176 | }
|
---|
177 |
|
---|
178 | if (tlist->ReInit())
|
---|
179 | return kTRUE;
|
---|
180 |
|
---|
181 | //MReadTree::Notify();
|
---|
182 |
|
---|
183 | *fLog << err << "ERROR - ReInit of '" << tlist->GetName() << "' failed." << endl;
|
---|
184 | return kFALSE;
|
---|
185 | }
|
---|
186 |
|
---|
187 | // --------------------------------------------------------------------------
|
---|
188 | //
|
---|
189 | // PreProcessed the MReadTree to read the run headers and its base class.
|
---|
190 | // see MReadTree::PreProcess for more information
|
---|
191 | //
|
---|
192 | Bool_t MReadMarsFile::PreProcess(MParList *pList)
|
---|
193 | {
|
---|
194 | fParList = pList;
|
---|
195 |
|
---|
196 | if (!fRun->PreProcess(pList))
|
---|
197 | {
|
---|
198 | *fLog << err << "Error - PreProcessing MReadMarsFile::fRun... aborting." << endl;
|
---|
199 | return kFALSE;
|
---|
200 | }
|
---|
201 |
|
---|
202 | const Int_t idx = GetFileIndex();
|
---|
203 | fRun->SetEventNum(idx<0?0:idx); // Assumption: One Entry per File!
|
---|
204 | if (!fRun->Process())
|
---|
205 | {
|
---|
206 | *fLog << err << "Error - Processing MReadMarsFile::fRun... aborting." << endl;
|
---|
207 | return kFALSE;
|
---|
208 | }
|
---|
209 |
|
---|
210 | return MReadTree::PreProcess(pList);
|
---|
211 | }
|
---|