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

Last change on this file since 9012 was 8907, 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
79ClassImp(MFilter);
80
81using namespace std;
82
83// --------------------------------------------------------------------------
84//
85// Default constructor for a filter. Initializes fInverted with kFALSE
86//
87MFilter::MFilter(const char *name, const char *title) : fInverted(kFALSE)
88{
89 fName = name ? name : "MFilter";
90 fTitle = title ? title : "Base Class for a filter";
91}
92
93// --------------------------------------------------------------------------
94//
95// return the Rule corresponding to this filter (see MF and MDataChain)
96//
97TString MFilter::GetRule() const
98{
99 return Form("(%s)", ClassName()); //"<GetRule n/a for " + fName + ">";
100}
101
102// --------------------------------------------------------------------------
103//
104// This is used to print the output in the PostProcess/Finalize.
105// Or everywhere else in a nice fashioned and unified way.
106//
107void MFilter::PrintSkipped(UInt_t n, const char *str)
108{
109 *fLog << " " << setw(7) << n << " (";
110 *fLog << setw(3) << TMath::Nint(100.*n/GetNumExecutions());
111 *fLog << "%) Evts fullfilled: " << str << endl;
112}
113
114// --------------------------------------------------------------------------
115//
116// Check for corresponding entries in resource file and setup filters.
117//
118// Assuming your filter is called (Set/GetName): MyFilter
119//
120// First you can setup whether the filter is inverted or not:
121// MyFilter.Inverted: yes, no <default=no>
122//
123Int_t MFilter::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
124{
125 if (IsEnvDefined(env, prefix, "Inverted", print))
126 {
127 SetInverted(GetEnvValue(env, prefix, "Inverted", IsInverted()));
128 return kTRUE;
129 }
130 return kFALSE;
131}
Note: See TracBrowser for help on using the repository browser.