source: trunk/Mars/mfbase/MFDataChain.cc@ 19344

Last change on this file since 19344 was 8076, checked in by tbretz, 18 years ago
*** empty log message ***
File size: 5.4 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 MDataPhrase).
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#include "MDataPhrase.h"
55
56#include "MLog.h"
57#include "MLogManip.h"
58
59ClassImp(MFDataChain);
60
61using namespace std;
62
63MFDataChain::MFDataChain(const char *name, const char *title)
64 : fCond(0)
65{
66 fName = name ? name : "MFDataChain";
67 fTitle = title ? title : "Filter using any data member of a class";
68}
69
70// --------------------------------------------------------------------------
71//
72MFDataChain::MFDataChain(const char *rule, const char type, const Double_t val,
73 const char *name, const char *title)
74 : fData(rule), fCond(new MDataValue(val))
75{
76 fName = name ? name : "MFDataChain";
77 fTitle = title ? title : "Filter using any data member of a class";
78
79 //AddToBranchList(member);
80
81 fFilterType = (type=='<' ? kELowerThan : kEGreaterThan);
82
83 if (type!='<' && type!='>')
84 *fLog << warn << dbginf << "Warning: Neither '<' nor '>' specified... using '>'." << endl;
85}
86
87MFDataChain::MFDataChain(const char *rule, const char type, const char *cond,
88 const char *name, const char *title)
89 : fData(rule), fCond(new MDataPhrase(cond))
90{
91 fName = name ? name : "MFDataChain";
92 fTitle = title ? title : "Filter using any data member of a class";
93
94 //AddToBranchList(member);
95
96 fFilterType = (type=='<' ? kELowerThan : kEGreaterThan);
97
98 if (type!='<' && type!='>')
99 *fLog << warn << dbginf << "Warning: Neither '<' nor '>' specified... using '>'." << endl;
100}
101
102MFDataChain::~MFDataChain()
103{
104 if (fCond)
105 delete fCond;
106}
107
108// --------------------------------------------------------------------------
109//
110Int_t MFDataChain::PreProcess(MParList *plist)
111{
112 if (!fCond)
113 {
114 *fLog << "No condition available - don't call default constructor!" << endl;
115 return kFALSE;
116 }
117 return fData.PreProcess(plist) && fCond->PreProcess(plist);
118}
119
120// --------------------------------------------------------------------------
121//
122Int_t MFDataChain::Process()
123{
124 const Double_t data = fData.GetValue();
125 const Double_t cond = fCond->GetValue();
126
127 switch (fFilterType)
128 {
129 case kELowerThan:
130 fResult = (data < cond);
131 return kTRUE;
132 case kEGreaterThan:
133 fResult = (data > cond);
134 return kTRUE;
135 }
136
137 return kFALSE;
138}
139
140void MFDataChain::Print(Option_t *) const
141{
142 *fLog << GetRule() << flush;
143}
144
145// --------------------------------------------------------------------------
146//
147// Crahses if default constructor called.
148//
149void MFDataChain::StreamPrimitive(ostream &out) const
150{
151 out << " MFDataChain " << GetUniqueName() << "(\"";
152 out << fData.GetRule() << "\", '";
153 out << (fFilterType==kELowerThan?"<":">");
154 out << "', ";
155
156 if (fCond->InheritsFrom(MDataValue::Class()))
157 out << ((MDataValue*)fCond)->GetValue();
158 else
159 out << "\"" << fCond->GetRule() << "\"";
160
161 out << ");" << endl;
162}
163
164// --------------------------------------------------------------------------
165//
166// Crahses if default constructor called.
167//
168TString MFDataChain::GetRule() const
169{
170 TString ret(fData.GetRule());
171 ret += fFilterType==kELowerThan?"<":">";
172
173 TString str;
174 str += fCond->GetRule();
175 ret += str.Strip(TString::kBoth);
176 return ret;
177}
178
179// --------------------------------------------------------------------------
180//
181// Crahses if default constructor called.
182//
183TString MFDataChain::GetDataMember() const
184{
185 if (!fData.IsValid())
186 return "";
187
188 TString ret(fData.GetDataMember());
189 ret += ",";
190 ret += fCond->GetDataMember();
191 return ret;
192}
Note: See TracBrowser for help on using the repository browser.