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

Last change on this file since 2057 was 1937, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 5.0 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
53// --------------------------------------------------------------------------
54//
55// Use this constructor if a rule (see MF for more details) shell be used.
56// MContinue will create a MF object and use it as a filter for the
57// instance. The MF-Task is added to the tasklist in front of the MContinue
58// instance and also automatically deleted, eg.
59// MContinue cont("MHillas.fSize<20");
60// tasklist.AddToList(&cont);
61// would skip all events which fullfill "MHillas.fSize<20" from this point
62// in the tasklist.
63// It is not necessary to put the filter in the tasklist. The PreProcess
64// will search for the filter and if it isn't found in the tasklist it
65// is added to the tasklist in front of MContinue.
66//
67MContinue::MContinue(const TString rule, const char *name, const char *title)
68{
69 fName = name ? name : "MContinue";
70 fTitle = title ? title : "Task returning kCONTINUE";
71
72 if (rule.IsNull())
73 return;
74
75 SetBit(kIsOwner);
76
77 MTask::SetFilter(new MF(rule, TString("MF(")+fName+")"));
78}
79
80// --------------------------------------------------------------------------
81//
82// Use this if you have a filter. Would be the same as if you would call:
83// MContinue cont;
84// cont.SetFilter(f);
85// It is not necessary to put the filter in the tasklist. The PreProcess
86// will search for the filter and if it isn't found in the tasklist it
87// is added to the tasklist in front of MContinue.
88//
89MContinue::MContinue(MFilter *f, const char *name, const char *title)
90{
91 fName = name ? name : "MContinue";
92 fTitle = title ? title : "Task returning kCONTINUE";
93
94 SetFilter(f);
95}
96
97// --------------------------------------------------------------------------
98//
99// Delete the filter if it was created automatically
100//
101MContinue::~MContinue()
102{
103 if (TestBit(kIsOwner))
104 delete GetFilter();
105}
106
107// --------------------------------------------------------------------------
108//
109// PreProcess tries to find the tasklist MTaskList, adds the filter
110// before this instance to the tasklist and preprocesses the filter.
111//
112Bool_t MContinue::PreProcess(MParList *list)
113{
114 if (!GetFilter())
115 {
116 *fLog << err << dbginf << "Unknown fatal Error! (fFilter=NULL?!?)" << endl;
117 return kFALSE;
118 }
119
120 fTaskList = (MTaskList*)list->FindObject("MTaskList");
121 if (!fTaskList)
122 {
123 *fLog << err << dbginf << "ERROR - Tasklist 'MTaskList' not found... abort." << endl;
124 return kFALSE;
125 }
126
127 if (fTaskList->FindObject(GetFilter()))
128 {
129 *fLog << warn << dbginf << "WARNING - The filter is already in the tasklist..." << endl;
130 return kTRUE;
131 }
132
133 if (!fTaskList->AddToListBefore(GetFilter(), this))
134 {
135 *fLog << err << dbginf << "ERROR - Adding filter before MContinue... abort." << endl;
136 return kFALSE;
137 }
138
139 SetBit(kFilterIsPrivate);
140
141 return GetFilter()->CallPreProcess(list);
142}
143
144// --------------------------------------------------------------------------
145//
146// If the filter was added to the tasklist automatically it is removed
147// from the tasklist.
148//
149Bool_t MContinue::PostProcess()
150{
151 if (!TestBit(kFilterIsPrivate))
152 return kTRUE;
153
154 if (fTaskList->RemoveFromList(GetFilter()))
155 return kTRUE;
156
157 *fLog << err << "ERROR: MContinue::PostProcess - Cannot remove Filter from tasklist" << endl;
158
159 return kFALSE;
160}
161
162void MContinue::SetInverted(Bool_t i)
163{
164 GetFilter()->SetInverted(i);
165}
166
167Bool_t MContinue::IsInverted() const
168{
169 return GetFilter()->IsInverted();
170}
Note: See TracBrowser for help on using the repository browser.