source: trunk/MagicSoft/Mars/mbase/MContinue.cc@ 5919

Last change on this file since 5919 was 5910, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 6.9 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 10/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MContinue
28//
29// Does nothing than return kCONTINUE in the Process-function
30// (use with filters). For more details see the description of the
31// constructors.
32//
33// To invert the meaning of the contained filter call SetInverted()
34//
35// Input Containers:
36// -/-
37//
38// Output Containers:
39// -/-
40//
41/////////////////////////////////////////////////////////////////////////////
42#include "MContinue.h"
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MF.h"
48#include "MParList.h"
49#include "MTaskList.h"
50
51ClassImp(MContinue);
52
53using namespace std;
54
55// --------------------------------------------------------------------------
56//
57// Default constructor.
58//
59// Use this constructor if a rule (see MF for more details) shell be used.
60// MContinue will create a MF object and use it as a filter for the
61// instance. The MF-Task is added to the tasklist in front of the MContinue
62// instance and also automatically deleted, eg.
63// MContinue cont("MHillas.fSize<20");
64// tasklist.AddToList(&cont);
65// would skip all events which fullfill "MHillas.fSize<20" from this point
66// in the tasklist.
67// It is not necessary to put the filter in the tasklist. The PreProcess
68// will search for the filter and if it isn't found in the tasklist it
69// is added to the tasklist in front of MContinue.
70//
71// Use the default constructor (or an empty rule) if you want to read the
72// rule from a resource file.
73//
74MContinue::MContinue(const TString rule, const char *name, const char *title)
75{
76 fName = name ? name : "MContinue";
77 fTitle = title ? title : "Task returning kCONTINUE";
78
79 if (rule.IsNull())
80 return;
81
82 SetBit(kIsOwner);
83
84 MTask::SetFilter(new MF(rule, TString("MF(")+fName+")"));
85}
86
87// --------------------------------------------------------------------------
88//
89// Use this if you have a filter. Would be the same as if you would call:
90// MContinue cont;
91// cont.SetFilter(f);
92// It is not necessary to put the filter in the tasklist. The PreProcess
93// will search for the filter and if it isn't found in the tasklist it
94// is added to the tasklist in front of MContinue.
95//
96MContinue::MContinue(MFilter *f, const char *name, const char *title)
97{
98 fName = name ? name : "MContinue";
99 fTitle = title ? title : "Task returning kCONTINUE";
100
101 SetFilter(f);
102}
103
104// --------------------------------------------------------------------------
105//
106// Delete the filter if it was created automatically
107//
108MContinue::~MContinue()
109{
110 if (TestBit(kIsOwner))
111 delete GetFilter();
112}
113
114// --------------------------------------------------------------------------
115//
116// PreProcess tries to find the tasklist MTaskList, adds the filter
117// before this instance to the tasklist and preprocesses the filter.
118//
119Int_t MContinue::PreProcess(MParList *list)
120{
121 if (!GetFilter())
122 {
123 *fLog << err << dbginf << "Unknown fatal Error! (fFilter=NULL?!?)" << endl;
124 return kFALSE;
125 }
126
127 fTaskList = (MTaskList*)list->FindTaskListWithTask(this);
128 if (!fTaskList)
129 {
130 *fLog << err << dbginf << "ERROR - MTasklist not found... abort." << endl;
131 return kFALSE;
132 }
133
134 if (fTaskList->FindObject(GetFilter()))
135 {
136 *fLog << inf << dbginf << "The filter is already in the tasklist..." << endl;
137 return kTRUE;
138 }
139
140 if (!fTaskList->AddToListBefore(GetFilter(), this))
141 {
142 *fLog << err << dbginf << "ERROR - Adding filter before MContinue... abort." << endl;
143 return kFALSE;
144 }
145
146 GetFilter()->SetDisplay(fDisplay);
147 GetFilter()->SetLogStream(fLog);
148
149 SetBit(kFilterIsPrivate);
150
151 return GetFilter()->CallPreProcess(list);
152}
153
154// --------------------------------------------------------------------------
155//
156// Propagate display to filter (if set)
157//
158void MContinue::SetDisplay(MStatusDisplay *d)
159{
160 if (GetFilter())
161 GetFilter()->SetDisplay(d);
162
163 MTask::SetDisplay(d);
164}
165
166// --------------------------------------------------------------------------
167//
168// Propagate log stream to filter (if set)
169//
170void MContinue::SetLogStream(MLog *lg)
171{
172 if (GetFilter())
173 GetFilter()->SetLogStream(lg);
174
175 MTask::SetLogStream(lg);
176}
177
178// --------------------------------------------------------------------------
179//
180// If the filter was added to the tasklist automatically it is removed
181// from the tasklist.
182//
183Int_t MContinue::PostProcess()
184{
185 if (!TestBit(kFilterIsPrivate))
186 return kTRUE;
187
188 if (fTaskList->RemoveFromList(GetFilter()))
189 return kTRUE;
190
191 *fLog << err << "ERROR: MContinue::PostProcess - Cannot remove Filter from tasklist" << endl;
192
193 return kFALSE;
194}
195
196// --------------------------------------------------------------------------
197//
198// If a filter is setup, call its 'IsInverted' to invert its meaning
199// (boolean "not")
200//
201void MContinue::SetInverted(Bool_t i)
202{
203 if (GetFilter())
204 GetFilter()->SetInverted(i);
205}
206
207// --------------------------------------------------------------------------
208//
209// If a filter is setup, its IsInverted status is returned. If now filter
210// has been setup yet, kFALSE is returned.
211//
212Bool_t MContinue::IsInverted() const
213{
214 return GetFilter() ? GetFilter()->IsInverted() : kFALSE;
215}
216
217// --------------------------------------------------------------------------
218//
219// Check for corresponding entries in resource file and setup filters.
220// Avoid trailing 0's!
221//
222// Example:
223// test.C:
224// MContinue cont("", "MyContinue");
225//
226// test.rc:
227// MyContinue.Condition: {0} && {1}
228// MyContinue.Inverted: yes
229// MyContinue.0: MHillas.fSize>1000
230// MyContinue.1: MHillas.fSize<10000
231//
232// For more details see MF::ReadEnv
233//
234Int_t MContinue::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
235{
236 MF *f = new MF;
237 f->SetName(fName);
238
239 const Bool_t rc = f->ReadEnv(env, prefix, print);
240 if (rc!=kTRUE)
241 {
242 delete f;
243 return rc;
244 }
245
246 if (TestBit(kIsOwner))
247 delete GetFilter();
248
249 SetBit(kIsOwner);
250 MTask::SetFilter(f);
251
252 f->SetName(Form("MF:%s", fName.Data()));
253
254 return kTRUE;
255}
Note: See TracBrowser for help on using the repository browser.