source: trunk/MagicSoft/Mars/mfilter/MFDataMember.cc@ 1283

Last change on this file since 1283 was 1283, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 4.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 01/2002 <mailto:tbretz@uni-sw.gwdg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MFDataMember
28//
29// With this filter you can filter in all variables from Mars parameter
30// containers.
31//
32// In the constructor you can give the filter variable, like
33// "MHillas.fLength"
34// Where MHillas is the name of the parameter container in the parameter
35// list and fLength is the name of the data member which should be used
36// for the filter rule. If the name of the container is use specified
37// (MyHillas) the name to give would be:
38// "MyHillas.fLength"
39//
40// For example:
41// MFDataMember filter("MHillas.fLength", '<', 150);
42//
43/////////////////////////////////////////////////////////////////////////////
44
45#include "MFDataMember.h"
46
47#include <TMethodCall.h>
48
49#include "MParList.h"
50
51#include "MLog.h"
52#include "MLogManip.h"
53
54ClassImp(MFDataMember);
55
56// --------------------------------------------------------------------------
57//
58MFDataMember::MFDataMember(const char *member, const char type, const Double_t val,
59 const char *name, const char *title)
60{
61 fName = name ? name : "MFDataMember";
62 fTitle = title ? title : "Filter using any data member of a class";
63
64 fFilterType = (type=='<' ? kELowerThan : kEGreaterThan);
65
66 if (type!='<' && type!='>')
67 *fLog << warn << dbginf << "Warning: Neither '<' nor '>' specified... using '>'." << endl;
68
69 fValue = val;
70
71 fDataMember = member;
72
73 AddToBranchList(fDataMember);
74}
75
76// --------------------------------------------------------------------------
77//
78Bool_t MFDataMember::PreProcess(MParList *plist)
79{
80 TString cname(fDataMember);
81 TString mname(fDataMember);
82
83 const char *dot = strrchr(cname, '.');
84
85 if (dot)
86 {
87 const int pos = dot-cname;
88
89 cname.Remove(pos);
90 mname.Remove(0, pos+1);
91 }
92
93 fObject = (MParContainer*)plist->FindObject(cname);
94 if (!fObject)
95 {
96 *fLog << err << "Object '" << cname << "' not in parameter list... aborting." << endl;
97 return kFALSE;
98 }
99
100 fMethodCall = fObject->GetterMethod(mname);
101
102 return fMethodCall ? kTRUE : kFALSE;
103}
104
105// --------------------------------------------------------------------------
106//
107Bool_t MFDataMember::Process()
108{
109 Double_t v;
110 switch (fMethodCall->ReturnType())
111 {
112 case TMethodCall::kLong:
113 Long_t l;
114 fMethodCall->Execute(fObject, l);
115 v = l;
116 return kTRUE;
117
118 case TMethodCall::kDouble:
119 fMethodCall->Execute(fObject, v);
120 return kTRUE;
121
122 default:
123 *fLog << err << "DataMember " << fDataMember << " of ";
124 *fLog << fObject->GetName() << " neither int nor float... abort." << endl;
125 return kFALSE;
126 }
127
128 switch (fFilterType)
129 {
130 case kELowerThan:
131 fResult = (v < fValue);
132 break;
133 case kEGreaterThan:
134 fResult = (v > fValue);
135 break;
136 }
137
138 return kTRUE;
139}
140
141void MFDataMember::Print(Option_t *) const
142{
143 *fLog << fDataMember << (fFilterType==kELowerThan?"<":">");
144 *fLog << fValue << flush;
145}
Note: See TracBrowser for help on using the repository browser.