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

Last change on this file since 7545 was 6869, checked in by tbretz, 20 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 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
144// --------------------------------------------------------------------------
145//
146// Crahses if default constructor called.
147//
148void MFDataChain::StreamPrimitive(ofstream &out) const
149{
150 out << " MFDataChain " << GetUniqueName() << "(\"";
151 out << fData.GetRule() << "\", '";
152 out << (fFilterType==kELowerThan?"<":">");
153 out << "', ";
154
155 if (fCond->InheritsFrom(MDataValue::Class()))
156 out << ((MDataValue*)fCond)->GetValue();
157 else
158 out << "\"" << fCond->GetRule() << "\"";
159
160 out << ");" << endl;
161}
162
163// --------------------------------------------------------------------------
164//
165// Crahses if default constructor called.
166//
167TString MFDataChain::GetRule() const
168{
169 TString ret(fData.GetRule());
170 ret += fFilterType==kELowerThan?"<":">";
171
172 TString str;
173 str += fCond->GetRule();
174 ret += str.Strip(TString::kBoth);
175 return ret;
176}
177
178// --------------------------------------------------------------------------
179//
180// Crahses if default constructor called.
181//
182TString MFDataChain::GetDataMember() const
183{
184 if (!fData.IsValid())
185 return "";
186
187 TString ret(fData.GetDataMember());
188 ret += ",";
189 ret += fCond->GetDataMember();
190 return ret;
191}
Note: See TracBrowser for help on using the repository browser.