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