| 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@astro.uni-wueruburg.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 | // You can test '<', '>' and '='. Warning: Using '=' may give strange results
|
|---|
| 44 | // in case you are comparing floating point values.
|
|---|
| 45 | //
|
|---|
| 46 | // In case the data member is detected to be an integer value, both
|
|---|
| 47 | // the data member and the val given as argument in the constructor
|
|---|
| 48 | // are castet to Long_t.
|
|---|
| 49 | //
|
|---|
| 50 | // To test != use the SetInverted() member function.
|
|---|
| 51 | //
|
|---|
| 52 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 53 | #include "MFDataMember.h"
|
|---|
| 54 |
|
|---|
| 55 | #include <fstream>
|
|---|
| 56 |
|
|---|
| 57 | #include <TMethodCall.h>
|
|---|
| 58 |
|
|---|
| 59 | #include "MParList.h"
|
|---|
| 60 |
|
|---|
| 61 | #include "MLog.h"
|
|---|
| 62 | #include "MLogManip.h"
|
|---|
| 63 |
|
|---|
| 64 | ClassImp(MFDataMember);
|
|---|
| 65 |
|
|---|
| 66 | using namespace std;
|
|---|
| 67 |
|
|---|
| 68 | // --------------------------------------------------------------------------
|
|---|
| 69 | //
|
|---|
| 70 | MFDataMember::MFDataMember(const char *member, const char type, const Double_t val,
|
|---|
| 71 | const char *name, const char *title)
|
|---|
| 72 | : fData(member), fValue(val)
|
|---|
| 73 | {
|
|---|
| 74 | fName = name ? name : "MFDataMember";
|
|---|
| 75 | fTitle = title ? title : "Filter using any data member of a class";
|
|---|
| 76 |
|
|---|
| 77 | AddToBranchList(member);
|
|---|
| 78 |
|
|---|
| 79 | switch (type)
|
|---|
| 80 | {
|
|---|
| 81 | case '>': fFilterType = kEGreaterThan; break;
|
|---|
| 82 | case '<': fFilterType = kELowerThan; break;
|
|---|
| 83 | case '=': fFilterType = kEEqual; break;
|
|---|
| 84 | default: fFilterType = kEGreaterThan; break;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | if (type!='<' && type!='=' && type!='>')
|
|---|
| 88 | *fLog << warn << dbginf << "Warning: Neither '<' nor '=' nor '>' specified... using '>'." << endl;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | // --------------------------------------------------------------------------
|
|---|
| 92 | //
|
|---|
| 93 | Int_t MFDataMember::PreProcess(MParList *plist)
|
|---|
| 94 | {
|
|---|
| 95 | return fData.PreProcess(plist);
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | // --------------------------------------------------------------------------
|
|---|
| 99 | //
|
|---|
| 100 | Int_t MFDataMember::Process()
|
|---|
| 101 | {
|
|---|
| 102 | if (fData.IsInt())
|
|---|
| 103 | {
|
|---|
| 104 | switch (fFilterType)
|
|---|
| 105 | {
|
|---|
| 106 | case kELowerThan:
|
|---|
| 107 | fResult = ((Long_t)fData.GetValue() < (Long_t)fValue);
|
|---|
| 108 | return kTRUE;
|
|---|
| 109 | case kEGreaterThan:
|
|---|
| 110 | fResult = ((Long_t)fData.GetValue() > (Long_t)fValue);
|
|---|
| 111 | return kTRUE;
|
|---|
| 112 | case kEEqual:
|
|---|
| 113 | fResult = ((Long_t)fData.GetValue() == (Long_t)fValue);
|
|---|
| 114 | return kTRUE;
|
|---|
| 115 | }
|
|---|
| 116 | }
|
|---|
| 117 | else
|
|---|
| 118 | {
|
|---|
| 119 | switch (fFilterType)
|
|---|
| 120 | {
|
|---|
| 121 | case kELowerThan:
|
|---|
| 122 | fResult = (fData.GetValue() < fValue);
|
|---|
| 123 | return kTRUE;
|
|---|
| 124 | case kEGreaterThan:
|
|---|
| 125 | fResult = (fData.GetValue() > fValue);
|
|---|
| 126 | return kTRUE;
|
|---|
| 127 | case kEEqual:
|
|---|
| 128 | fResult = (fData.GetValue() == fValue);
|
|---|
| 129 | return kTRUE;
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | return kFALSE;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | void MFDataMember::Print(Option_t *) const
|
|---|
| 137 | {
|
|---|
| 138 | *fLog << GetRule() << flush;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | void MFDataMember::StreamPrimitive(ostream &out) const
|
|---|
| 142 | {
|
|---|
| 143 | out << " MFDataMember " << GetUniqueName() << "(\"";
|
|---|
| 144 | out << fData.GetRule() << "\", '";
|
|---|
| 145 | switch (fFilterType)
|
|---|
| 146 | {
|
|---|
| 147 | case kEGreaterThan: out << '>'; break;
|
|---|
| 148 | case kELowerThan: out << '<'; break;
|
|---|
| 149 | case kEEqual: out << '='; break;
|
|---|
| 150 | }
|
|---|
| 151 | out << "', " << fValue << ");" << endl;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | TString MFDataMember::GetRule() const
|
|---|
| 155 | {
|
|---|
| 156 | TString ret = fData.GetRule();
|
|---|
| 157 | switch (fFilterType)
|
|---|
| 158 | {
|
|---|
| 159 | case kEGreaterThan: ret +='>'; break;
|
|---|
| 160 | case kELowerThan: ret +='<'; break;
|
|---|
| 161 | case kEEqual: ret +='='; break;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | TString str;
|
|---|
| 165 | str += fValue;
|
|---|
| 166 |
|
|---|
| 167 | return ret+str.Strip(TString::kBoth);
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | TString MFDataMember::GetDataMember() const
|
|---|
| 171 | {
|
|---|
| 172 | return fData.GetDataMember();
|
|---|
| 173 | }
|
|---|