source: trunk/MagicSoft/Mars/manalysis/MGeomApply.cc@ 6230

Last change on this file since 6230 was 5844, checked in by tbretz, 20 years ago
*** empty log message ***
File size: 7.2 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, 09/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
19! Markus Gaug, 03/2004 <mailto:markus@ifae.es>
20! Hendrik Bartko, 07/2003 <mailto:hbartko@mppmu.mpg.de>
21!
22! Copyright: MAGIC Software Development, 2000-2004
23!
24!
25\* ======================================================================== */
26//////////////////////////////////////////////////////////////////////////////
27//
28// MGeomApply
29//
30// Applies the geometry to geometry dependant containers.
31//
32// It changes the size of the arrays in the containers to a size
33// matching the number of pixels, eg:
34//
35// MPedestalCam
36// MCalibrationChargeCam
37// MCalibrationRelTimeCam
38// MCalibrationQECam
39// MCalibrationPedCam
40// MPedPhotCam
41// MExtractedSignalCam
42// MArrivalTimeCam
43// MArrivalTime
44//
45// It uses the geometry (MGeomCam) found in the parameter list.
46// If it is not found the task tries to create the geometry
47// specified in the constructor. The default geometry is
48// MGeomCamMagic.
49//
50// In a standard setup all containers in the parameter list which derive
51// from MCamEvent are processed automatically in ReInit. To allow having
52// two parallel geometries in the parameter list or for MCamEvent in the
53// parameter list you can switch off the automatic procedure by adding
54// the containers to be processed using AddCamEvent().
55//
56//
57// Input Containers:
58// [MGeomCam]
59// [all MCamEvent]
60//
61// Output Containers:
62// [all MCamEvent]
63//
64//////////////////////////////////////////////////////////////////////////////
65#include "MGeomApply.h"
66
67#include <fstream>
68
69#include <TObjString.h>
70
71#include "MLog.h"
72#include "MLogManip.h"
73
74#include "MParList.h"
75
76#include "MGeomCam.h"
77#include "MCamEvent.h"
78
79ClassImp(MGeomApply);
80
81using namespace std;
82
83// --------------------------------------------------------------------------
84//
85// Default constructor. MGeomCamMagic is the default geometry.
86//
87MGeomApply::MGeomApply(const char *name, const char *title)
88 : fGeomName("MGeomCamMagic"), fNamesList(0), fList(0)
89{
90 fName = name ? name : "MGeomApply";
91 fTitle = title ? title : "Task to apply geometry settings";
92}
93
94// --------------------------------------------------------------------------
95//
96// Delete fList if available.
97//
98MGeomApply::~MGeomApply()
99{
100 if (fList)
101 delete fList;
102 if (fNamesList)
103 delete fNamesList;
104}
105
106// --------------------------------------------------------------------------
107//
108// Try to find 'MGeomCam' in the Parameter List. If it is not found,
109// try to create a fGeomName object.
110//
111Int_t MGeomApply::PreProcess(MParList *pList)
112{
113 MGeomCam *cam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
114 if (cam)
115 return kTRUE;
116
117 cam = (MGeomCam*)pList->FindCreateObj(AddSerialNumber(fGeomName), "MGeomCam");
118
119 return cam ? kTRUE : kFALSE;
120}
121
122// --------------------------------------------------------------------------
123//
124// Check the whole parameter list for MCamEvent. For all MCamEvent
125// MCamEvent::Init(MGeomCam&) is called.
126//
127void MGeomApply::ProcessAutomatic(MParList &list, const MGeomCam &geom) const
128{
129 TIter Next(list);
130 TObject *o = 0;
131
132 while ((o=Next()))
133 {
134 MCamEvent *cam = dynamic_cast<MCamEvent*>(o);
135 if (cam)
136 cam->Init(geom);
137 }
138}
139
140// --------------------------------------------------------------------------
141//
142// Check all containers in fNamesList and fList. For all MCamEvent
143// MCamEvent::Init(MGeomCam&) is called.
144//
145Bool_t MGeomApply::ProcessManual(MParList &list, const MGeomCam &geom) const
146{
147 TIter NextN(fNamesList);
148 TObject *o = 0;
149
150 while ((o=NextN()))
151 {
152 TObject *cont = list.FindObject(o->GetName(), "MCamEvent");
153 if (!cont)
154 {
155 *fLog << err << o->GetName() << " [MCamEvent] not found... abort." << endl;
156 return kFALSE;
157 }
158
159 MCamEvent *cam = dynamic_cast<MCamEvent*>(o);
160 cam->Init(geom);
161 }
162
163 TIter NextL(fList);
164 while ((o=NextL()))
165 {
166 MCamEvent *cam = dynamic_cast<MCamEvent*>(o);
167 cam->Init(geom);
168 }
169
170 return kTRUE;
171}
172
173// --------------------------------------------------------------------------
174//
175// Try to find 'MGeomCam' in the Parameter List. If it is not found,
176// processing is stopped.
177//
178Bool_t MGeomApply::ReInit(MParList *pList)
179{
180 MGeomCam *geom = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
181 if (!geom)
182 {
183 *fLog << err << GetDescriptor() << ": No MGeomCam found... aborting." << endl;
184 return kFALSE;
185 }
186
187 // FIXME, workaround: this call to CalcPixRatio is here just to allow
188 // the use of some camera files from the 0.7 beta version in which the
189 // array containing pixel ratios is not initialized.
190 geom->CalcPixRatio();
191
192 if (fList)
193 return ProcessManual(*pList, *geom);
194
195 ProcessAutomatic(*pList, *geom);
196
197 return kTRUE;
198}
199
200// --------------------------------------------------------------------------
201//
202// Implementation of SavePrimitive. Used to write the call to a constructor
203// to a macro. In the original root implementation it is used to write
204// gui elements to a macro-file.
205//
206void MGeomApply::StreamPrimitive(ofstream &out) const
207{
208 out << " " << ClassName() << " " << GetUniqueName() << "(\"";
209 out << "\"" << fName << "\", \"" << fTitle << "\");" << endl;
210
211 if (fGeomName.IsNull())
212 return;
213
214 out << " " << GetUniqueName() << ".SetGeometry(\"";
215 out << fGeomName << "\");" << endl;
216}
217
218// --------------------------------------------------------------------------
219//
220// Add a MCamEvent to be processed. This switches off the automatic
221// processing of all MCamEvent in the parameter list completely!
222//
223void MGeomApply::AddCamEvent(TObject *obj)
224{
225 if (!obj->InheritsFrom(MCamEvent::Class()))
226 {
227 *fLog << warn << "MGeomApply::AddCamEvent - WARNING: Object doesn't inherit from MCamEvent... ignored." << endl;
228 return;
229 }
230
231 if (!fList)
232 {
233 fList = new TList;
234 fNamesList = new TList;
235
236 fNamesList->SetOwner();
237 }
238
239 fList->Add(obj);
240}
241
242// --------------------------------------------------------------------------
243//
244// Add a MCamEvent to be processed. This switches off the automatic
245// processing of all MCamEvent in the parameter list completely!
246//
247void MGeomApply::AddCamEvent(const char *name)
248{
249 if (!fList)
250 {
251 fList = new TList;
252 fNamesList = new TList;
253
254 fNamesList->SetOwner();
255 }
256
257 fNamesList->Add(new TObjString(name));
258}
Note: See TracBrowser for help on using the repository browser.