source: trunk/MagicSoft/Mars/mfbase/MFDataChain.cc@ 4781

Last change on this file since 4781 was 3573, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.9 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 11/2002 <mailto:tbretz@astro.uni-wueruburg.de>
19!
20! Copyright: MAGIC Software Development, 2000-2002
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MFDataChain
28//
29// With this filter you can filter in all variables from Mars parameter
30// containers using rules (for more details see MDataChain).
31//
32// In the constructor you can give the filter variable, like
33// "sqrt(MHillas.fLength*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// MFDataChain filter("sqr(MHillas.fLength)", '<', 150);
42// MFDataChain filter("MHillas.fLength", '<', "MHillas.fWidth");
43//
44/////////////////////////////////////////////////////////////////////////////
45#include "MFDataChain.h"
46
47#include <fstream>
48
49#include <TMethodCall.h>
50
51#include "MParList.h"
52
53#include "MDataValue.h"
54
55#include "MLog.h"
56#include "MLogManip.h"
57
58ClassImp(MFDataChain);
59
60using namespace std;
61
62MFDataChain::MFDataChain(const char *name, const char *title)
63 : fCond(0)
64{
65 fName = name ? name : "MFDataChain";
66 fTitle = title ? title : "Filter using any data member of a class";
67}
68
69// --------------------------------------------------------------------------
70//
71MFDataChain::MFDataChain(const char *rule, const char type, const Double_t val,
72 const char *name, const char *title)
73 : fData(rule), fCond(new MDataValue(val))
74{
75 fName = name ? name : "MFDataChain";
76 fTitle = title ? title : "Filter using any data member of a class";
77
78 //AddToBranchList(member);
79
80 fFilterType = (type=='<' ? kELowerThan : kEGreaterThan);
81
82 if (type!='<' && type!='>')
83 *fLog << warn << dbginf << "Warning: Neither '<' nor '>' specified... using '>'." << endl;
84}
85
86MFDataChain::MFDataChain(const char *rule, const char type, const char *cond,
87 const char *name, const char *title)
88 : fData(rule), fCond(new MDataChain(cond))
89{
90 fName = name ? name : "MFDataChain";
91 fTitle = title ? title : "Filter using any data member of a class";
92
93 //AddToBranchList(member);
94
95 fFilterType = (type=='<' ? kELowerThan : kEGreaterThan);
96
97 if (type!='<' && type!='>')
98 *fLog << warn << dbginf << "Warning: Neither '<' nor '>' specified... using '>'." << endl;
99}
100
101MFDataChain::~MFDataChain()
102{
103 if (fCond)
104 delete fCond;
105}
106
107// --------------------------------------------------------------------------
108//
109Int_t MFDataChain::PreProcess(MParList *plist)
110{
111 if (!fCond)
112 {
113 *fLog << "No condition available - don't call default constructor!" << endl;
114 return kFALSE;
115 }
116 return fData.PreProcess(plist) && fCond->PreProcess(plist);
117}
118
119// --------------------------------------------------------------------------
120//
121Int_t MFDataChain::Process()
122{
123 const Double_t data = fData.GetValue();
124 const Double_t cond = fCond->GetValue();
125
126 switch (fFilterType)
127 {
128 case kELowerThan:
129 fResult = (data < cond);
130 return kTRUE;
131 case kEGreaterThan:
132 fResult = (data > cond);
133 return kTRUE;
134 }
135
136 return kFALSE;
137}
138
139void MFDataChain::Print(Option_t *) const
140{
141 *fLog << GetRule() << flush;
142}
143
144void MFDataChain::StreamPrimitive(ofstream &out) const
145{
146 out << " MFDataChain " << GetUniqueName() << "(\"";
147 out << fData.GetRule() << "\", '";
148 out << (fFilterType==kELowerThan?"<":">");
149 out << "', ";
150
151 if (fCond->InheritsFrom(MDataValue::Class()))
152 out << ((MDataValue*)fCond)->GetValue();
153 else
154 out << "\"" << fCond->GetRule() << "\"";
155
156 out << ");" << endl;
157}
158
159TString MFDataChain::GetRule() const
160{
161 TString ret;// = "{";
162 ret += fData.GetRule();
163 //ret += "}";
164 ret += fFilterType==kELowerThan?"<":">";
165
166 TString str;
167 str += fCond->GetRule();
168 ret += str.Strip(TString::kBoth);
169 return ret;
170}
Note: See TracBrowser for help on using the repository browser.