- Timestamp:
- 03/22/04 14:30:09 (21 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r3572 r3573 99 99 100 100 * mdata/MDataArray.[h,cc], mdata/MDataElement.h, 101 mdata/MDataList.[h,cc], mdata/MDataMember.h: 101 mdata/MDataList.[h,cc], mdata/MDataMember.h, 102 mfbase/MFDataMember.[h,cc], mfbase/MFilterList.[h,cc]: 102 103 - added SetVariables 103 104 … … 110 111 - added support for an index 111 112 - added SetVariables 112 113 114 * mfbase/MF.[h,cc]: 115 - removed support for {}. This case is now detected 116 automatically 117 - added SetVariables 118 - added support for expressiond like 119 "MHillas.fLength<2*MHillas.fWidth" 120 121 * mfbase/MFDataChain.[h,cc]: 122 - added fCond data member 123 - addednew constructor to support fCond 124 - added support for new condition type 125 - adapted Print and GetRule 113 126 114 127 -
trunk/MagicSoft/Mars/NEWS
r3393 r3573 1 1 -*-*- END -*-*- 2 2 *** Version <cvs> 3 4 - added support in MF for expressiond like 5 "MHillas.fWidth<2*MHillas.fLength" 6 7 - MDataChain is now able to support variables like [0], [1], ... 8 which can be used in fit functions as parameters. The interface 9 is implemented through the new virtual function 10 MParContainer::SetVariables 3 11 4 12 - added new class MArrivalTimeCam/MArrivalTimePix: -
trunk/MagicSoft/Mars/mfbase/MF.cc
r3330 r3573 71 71 // 72 72 // 73 // If you intend to use Data Chains in filters enclose the chains in74 // this {}-parenthesis, eg.75 //76 // "{MHillas.fSize*MHillas.fWidth}<0.5"77 //78 73 // FIXME: The possibility to use also complete filters is missing. 79 74 // Maybe we can use gInterpreter->Calc("") for this. … … 166 161 MFilter *MF::ParseRule(TString &txt, MFilter *filter0, Int_t level) const 167 162 { 168 TString text; 169 170 Bool_t isrule = kFALSE; 171 172 if (txt[0]=='{') 173 { 174 // 175 // Search for the corresponding bracket 176 // 177 Int_t first=1; 178 for (int cnt=0; first<txt.Length(); first++) 179 { 180 if (txt[first]=='{') 181 cnt++; 182 if (txt[first]=='}') 183 cnt--; 184 185 if (cnt==-1) 186 break; 187 } 188 189 if (first==txt.Length()) 190 { 191 *fLog << err << dbginf << "Syntax Error: '}' missing." << endl; 192 return NULL; 193 } 194 195 // 196 // Make a copy of the 'interieur' and delete the substringä 197 // including the brackets 198 // 199 TString sub = txt(1, first-1); 200 txt.Remove(0, first+1); 201 202 text=sub; 203 isrule = kTRUE; 204 } 205 else 206 { 207 int i = IsAlNum(txt); 208 209 if (i==0) 210 { 211 *fLog << err << dbginf << "Syntax Error: Name of data member missing in '" << txt << "'" << endl; 212 return NULL; 213 } 214 215 text = txt(0, i); 216 217 txt.Remove(0, i); 218 } 219 220 txt = txt.Strip(TString::kBoth); 221 222 if (txt.IsNull()) 223 { 224 *fLog << err << dbginf << "Syntax Error: No conditional in '" << text << "'" << endl; 163 // For backward compatibility 164 txt.ReplaceAll("{", "("); 165 txt.ReplaceAll("}", ")"); 166 167 const Int_t fg = txt.First('>'); 168 const Int_t lg = txt.First('>'); 169 const Int_t fl = txt.First('<'); 170 const Int_t ll = txt.First('<'); 171 172 if (fg<0 && fl<0) 173 { 174 *fLog << err << dbginf << "Syntax Error: No coditional sign found in " << txt << endl; 225 175 return NULL; 226 176 } 227 228 char c; 229 switch (txt[0]) 230 { 231 case '>': 232 case '<': 233 c = txt[0]; 234 txt.Remove(0, 1); 235 break; 236 237 default: 238 *fLog << err << dbginf << "Syntax Error: Conditional '" << txt[0] << "' unknown." << endl; 177 if (fg>=0 && fl>=0) 178 { 179 *fLog << err << dbginf << "Syntax Error: Two coditional signs found in " << txt << endl; 180 *fLog << "Currently you have to enclose all conditions in brackets, like: \"(x<y) && (z<5)\"" << endl; 239 181 return NULL; 240 182 } 241 242 char *end; 243 Double_t num = strtod(txt.Data(), &end); 244 if (!end || txt.Data()==end) 245 { 246 *fLog << err << dbginf << "Error trying to convert '" << txt << "' to value." << endl; 183 if (fg!=lg || fl!=ll) 184 { 185 *fLog << err << dbginf << "Syntax Error: Coditional sign found twice " << txt << endl; 247 186 return NULL; 248 187 } 249 188 250 txt.Remove(0, end-txt.Data()); 251 252 MFilter *newfilter; 253 if (isrule) 254 { 255 Int_t lvl = gLog.GetDebugLevel(); 256 gLog.SetDebugLevel(1); 257 newfilter = new MFDataChain(text.Data(), c, num); 258 newfilter->SetName(Form("Chain%02d%c%f", level, c, num)); 259 gLog.SetDebugLevel(lvl); 260 } 261 else 262 { 263 newfilter = new MFDataMember(text.Data(), c, num); 264 newfilter->SetName(Form("%s%c%f", text.Data(), c, num)); 265 } 266 267 return newfilter; 189 const Int_t cond = fg<0 ? fl : fg; 190 191 const TString rule1 = txt(0, cond); 192 const TString rule2 = txt(cond+1, txt.Length()); 193 194 Int_t lvl = gLog.GetDebugLevel(); 195 gLog.SetDebugLevel(1); 196 MFilter *f = new MFDataChain(rule1.Data(), txt[cond], rule2.Data()); 197 f->SetName(Form("Chain%02d%c", level, txt[cond])); 198 gLog.SetDebugLevel(lvl); 199 200 txt = ""; 201 202 return f; 268 203 } 269 204 // -------------------------------------------------------------------------- -
trunk/MagicSoft/Mars/mfbase/MF.h
r3330 r3573 23 23 MFilter *fF; // Filter 24 24 25 Int_t IsRule(TString &txt, TString &rule) const; 26 Int_t IsVal(const TString &txt) const; 25 27 Int_t IsAlNum(TString txt) const; 26 28 … … 43 45 void Print(Option_t *opt="") const; 44 46 47 void SetVariables(const TArrayD &arr) { if (fF) fF->SetVariables(arr); } 48 45 49 ClassDef(MF, 0) // A Filter for cuts in any data member 46 50 }; -
trunk/MagicSoft/Mars/mfbase/MFDataChain.cc
r3330 r3573 40 40 // For example: 41 41 // MFDataChain filter("sqr(MHillas.fLength)", '<', 150); 42 // MFDataChain filter("MHillas.fLength", '<', "MHillas.fWidth"); 42 43 // 43 44 ///////////////////////////////////////////////////////////////////////////// … … 50 51 #include "MParList.h" 51 52 53 #include "MDataValue.h" 54 52 55 #include "MLog.h" 53 56 #include "MLogManip.h" … … 57 60 using namespace std; 58 61 62 MFDataChain::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 59 69 // -------------------------------------------------------------------------- 60 70 // 61 MFDataChain::MFDataChain(const char * member, const char type, const Double_t val,71 MFDataChain::MFDataChain(const char *rule, const char type, const Double_t val, 62 72 const char *name, const char *title) 63 : fData( member), fValue(val)73 : fData(rule), fCond(new MDataValue(val)) 64 74 { 65 75 fName = name ? name : "MFDataChain"; … … 74 84 } 75 85 86 MFDataChain::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 101 MFDataChain::~MFDataChain() 102 { 103 if (fCond) 104 delete fCond; 105 } 106 76 107 // -------------------------------------------------------------------------- 77 108 // 78 109 Int_t MFDataChain::PreProcess(MParList *plist) 79 110 { 80 return fData.PreProcess(plist); 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); 81 117 } 82 118 … … 85 121 Int_t MFDataChain::Process() 86 122 { 123 const Double_t data = fData.GetValue(); 124 const Double_t cond = fCond->GetValue(); 125 87 126 switch (fFilterType) 88 127 { 89 128 case kELowerThan: 90 fResult = ( fData.GetValue() < fValue);129 fResult = (data < cond); 91 130 return kTRUE; 92 131 case kEGreaterThan: 93 fResult = ( fData.GetValue() > fValue);132 fResult = (data > cond); 94 133 return kTRUE; 95 134 } … … 108 147 out << fData.GetRule() << "\", '"; 109 148 out << (fFilterType==kELowerThan?"<":">"); 110 out << "', " << fValue << ");" << endl; 149 out << "', "; 150 151 if (fCond->InheritsFrom(MDataValue::Class())) 152 out << ((MDataValue*)fCond)->GetValue(); 153 else 154 out << "\"" << fCond->GetRule() << "\""; 155 156 out << ");" << endl; 111 157 } 112 158 113 159 TString MFDataChain::GetRule() const 114 160 { 115 TString ret = "{";161 TString ret;// = "{"; 116 162 ret += fData.GetRule(); 117 ret += "}";163 //ret += "}"; 118 164 ret += fFilterType==kELowerThan?"<":">"; 119 165 120 166 TString str; 121 str += fValue; 122 167 str += fCond->GetRule(); 123 168 ret += str.Strip(TString::kBoth); 124 169 return ret; 125 170 } 126 -
trunk/MagicSoft/Mars/mfbase/MFDataChain.h
r3330 r3573 21 21 private: 22 22 MDataChain fData; 23 MData *fCond; 23 24 24 25 typedef enum { kELowerThan, kEGreaterThan } FilterType_t; … … 26 27 27 28 Bool_t fResult; //! 28 Double_t fValue;29 29 30 30 void StreamPrimitive(ofstream &out) const; … … 34 34 35 35 public: 36 MFDataChain(const char *member, const char type, const Double_t val, 36 MFDataChain(const char *name=NULL, const char *title=NULL); 37 MFDataChain(const char *rule, const char type, const Double_t val, 37 38 const char *name=NULL, const char *title=NULL); 39 MFDataChain(const char *rule, const char type, const char *cond, 40 const char *name=NULL, const char *title=NULL); 41 ~MFDataChain(); 38 42 39 43 Bool_t IsExpressionTrue() const { return fResult; } … … 42 46 TString GetRule() const; 43 47 48 void SetVariables(const TArrayD &arr) 49 { 50 fData.SetVariables(arr); 51 if (fCond) 52 fCond->SetVariables(arr); 53 } 54 44 55 ClassDef(MFDataChain, 1) // A Filter for cuts in any data member 45 56 }; -
trunk/MagicSoft/Mars/mfbase/MFDataMember.cc
r3330 r3573 167 167 return ret+str.Strip(TString::kBoth); 168 168 } 169 -
trunk/MagicSoft/Mars/mfbase/MFDataMember.h
r3330 r3573 39 39 TString GetRule() const; 40 40 41 void SetVariables(const TArrayD &arr) { fData.SetVariables(arr); } 42 41 43 ClassDef(MFDataMember, 1) // A Filter for cuts in any data member 42 44 }; -
trunk/MagicSoft/Mars/mfbase/MFilterList.cc
r3330 r3573 379 379 return ret+")"; 380 380 } 381 382 void MFilterList::SetVariables(const TArrayD &arr) 383 { 384 fFilters.ForEach(MFilter, SetVariables)(arr); 385 } -
trunk/MagicSoft/Mars/mfbase/MFilterList.h
r3330 r3573 53 53 Int_t PostProcess(); 54 54 55 void SetVariables(const TArrayD &arr); 56 55 57 ClassDef(MFilterList, 1) // List to combine several filters logically 56 58 };
Note:
See TracChangeset
for help on using the changeset viewer.