source: trunk/MagicSoft/Mars/mbase/MFilter.cc@ 9482

Last change on this file since 9482 was 9302, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 4.7 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, 07/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2008
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MFilter
28//
29// This is a base class which defines an interface to create your own
30// filters. To do it derive a class from MFilter.
31//
32// You can invert the meaning of a filter (logical NOT '!') by calling
33// SetInverted().
34//
35// You can create two types of Filters:
36// - static Filters and
37// - dynamic Filters
38//
39// Static Filters:
40// A static filter is a filter which value doesn't change dynamically,
41// which mean only once while running through your tasklist. To create
42// a static filter override the Process-function of MFilter (this is
43// the function in which the filer-value should be updated). If
44// necessary you can also overwrite Pre-/PostProcess. The process
45// function should calculate the return value of IsExpressionTrue.
46// IsExpressionTrue should simply return this value. This kind of
47// filter must be added to the tasklist at a point which is forseen to
48// update the value of the filter (eg. after the reading task).
49//
50// Dynamic Filters:
51// A dynamic filter is a filter which returns a value which must be
52// calculated at the time the filter is called. To create such a
53// filter you have to overwrite IsExpressionTrue only. If there is
54// no need for a 'one-point' update this filter must not be added to
55// the tasklist.
56//
57// Usage:
58// A Filter is connected to a task by calling MTask::SetFilter. The
59// task is now executed when IsExpressionTrue returns a value
60// (different from kFALSE) only.
61//
62// Remarks:
63// - Make sure, that all tasks which depends on this filter are either
64// collected in a MTaskList-object or are conected to the same
65// filter.
66// - If you want to use different filters (combined logically) for one
67// task please look for the MFilterList class.
68// - Be careful, the return value of IsExpressionTrue is NOT a real
69// boolean. You can return other values, too.
70//
71/////////////////////////////////////////////////////////////////////////////
72#include "MFilter.h"
73
74#include <TMath.h>
75
76#include "MLog.h"
77#include "MLogManip.h"
78
79#include "MString.h"
80
81ClassImp(MFilter);
82
83using namespace std;
84
85// --------------------------------------------------------------------------
86//
87// Default constructor for a filter. Initializes fInverted with kFALSE
88//
89MFilter::MFilter(const char *name, const char *title) : fInverted(kFALSE)
90{
91 fName = name ? name : "MFilter";
92 fTitle = title ? title : "Base Class for a filter";
93}
94
95// --------------------------------------------------------------------------
96//
97// return the Rule corresponding to this filter (see MF and MDataChain)
98//
99TString MFilter::GetRule() const
100{
101 return MString::Format("(%s)", ClassName()); //"<GetRule n/a for " + fName + ">";
102}
103
104// --------------------------------------------------------------------------
105//
106// This is used to print the output in the PostProcess/Finalize.
107// Or everywhere else in a nice fashioned and unified way.
108//
109void MFilter::PrintSkipped(UInt_t n, const char *str)
110{
111 *fLog << " " << setw(7) << n << " (";
112 *fLog << setw(3) << TMath::Nint(100.*n/GetNumExecutions());
113 *fLog << "%) Evts fullfilled: " << str << endl;
114}
115
116// --------------------------------------------------------------------------
117//
118// Check for corresponding entries in resource file and setup filters.
119//
120// Assuming your filter is called (Set/GetName): MyFilter
121//
122// First you can setup whether the filter is inverted or not:
123// MyFilter.Inverted: yes, no <default=no>
124//
125Int_t MFilter::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
126{
127 if (IsEnvDefined(env, prefix, "Inverted", print))
128 {
129 SetInverted(GetEnvValue(env, prefix, "Inverted", IsInverted()));
130 return kTRUE;
131 }
132 return kFALSE;
133}
Note: See TracBrowser for help on using the repository browser.