Changeset 1332 for trunk/MagicSoft/Mars/mdata
- Timestamp:
- 05/06/02 11:41:44 (23 years ago)
- Location:
- trunk/MagicSoft/Mars/mdata
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mdata/MDataChain.cc
r1326 r1332 51 51 // "(MHillas.fWidth + MHillas.fLength) / HillasSource.fDist" 52 52 // 53 // You can also use mathmatical operators, eg: 54 // "5*log10(MMcEvt.fEnergy*MHillas.fSize)" 55 // 56 // The allowed operators are: 57 // exp(x) e^x 58 // log(x) natural logarithm of x 59 // pow10(x) 10^x 60 // log10(x) logarithm of x to base ten 61 // cos(x) cosine of x 62 // sin(x) sine of x 63 // tan(x) tangent of x 64 // cosh(x) hyperbolic cosine of x 65 // sinh(x) hyperbolic sine of x 66 // tanh(x) hyperbolic tangent of x 67 // acos(x) arc cosine (inverse cosine) of x 68 // asin(x) arc sine (inverse sine) of x 69 // atan(x) arc tangent (inverse tangent) of x 70 // sqrt(x) square root of x 71 // abs(x) absolute value of x, |x| 72 // 53 73 // 54 74 // FIXME: The possibility to use other objects inheriting from MData … … 72 92 # 73 93 ClassImp(MDataChain); 94 95 MDataChain::MDataChain(const char *rule, OperatorType_t op) 96 : fOperatorType(op) 97 { 98 fName = "MDataChain"; 99 fTitle = rule; 100 101 fMember=ParseString(rule, 1); 102 } 74 103 75 104 MDataChain::MDataChain(const char *rule, const char *name, const char *title) … … 124 153 } 125 154 155 Int_t MDataChain::GetBracket(TString txt) 156 { 157 Int_t first=1; 158 for (int cnt=0; first<txt.Length(); first++) 159 { 160 if (txt[first]=='(') 161 cnt++; 162 if (txt[first]==')') 163 cnt--; 164 if (cnt==-1) 165 break; 166 } 167 return first; 168 } 169 170 // -------------------------------------------------------------------------- 171 // 172 // Compare a given text with the known operators. If no operator match 173 // kENoop is retunred, otherwise the corresponding OperatorType_t 174 // 175 MDataChain::OperatorType_t MDataChain::ParseOperator(TString txt) const 176 { 177 txt.ToLower(); 178 179 if (txt=="abs") return kEAbs; 180 if (txt=="log") return kELog; 181 if (txt=="log10") return kELog10; 182 if (txt=="sin") return kESin; 183 if (txt=="cos") return kECos; 184 if (txt=="tan") return kETan; 185 if (txt=="sinh") return kESinH; 186 if (txt=="cosh") return kECosH; 187 if (txt=="tanh") return kETanH; 188 if (txt=="asin") return kEASin; 189 if (txt=="acos") return kEACos; 190 if (txt=="atan") return kEATan; 191 if (txt=="sqrt") return kESqrt; 192 if (txt=="exp") return kEExp; 193 if (txt=="pow10") return kEPow10; 194 195 return kENoop; 196 } 197 126 198 MData *MDataChain::ParseString(TString txt, Int_t level) 127 199 { … … 144 216 // Search for the corresponding bracket 145 217 // 146 Int_t first=1; 147 for (int cnt=0; first<txt.Length(); first++) 148 { 149 if (txt[first]=='(') 150 cnt++; 151 if (txt[first]==')') 152 cnt--; 153 154 if (cnt==-1) 155 break; 156 } 218 Int_t first=GetBracket(txt); 157 219 158 220 if (first==txt.Length()) … … 208 270 // filter list with the new conditional 209 271 // 210 if ( !member0->InheritsFrom(MDataMember::Class()) ||type!=is)272 if (/*!member0->InheritsFrom(MDataMember::Class()) ||*/ type!=is) 211 273 { 212 274 MDataList *list = new MDataList(is); … … 269 331 270 332 txt.Remove(0, i); 271 272 // *fLog << all << "Creating: '" << text.Data() << "'" << endl; 273 274 newmember = new MDataMember(text.Data()); 333 txt = txt.Strip(TString::kBoth); 334 335 if (txt.IsNull() || txt[0]!='(') 336 { 337 newmember = new MDataMember(text.Data()); 338 break; 339 } 340 341 OperatorType_t op = ParseOperator(text); 342 if (op==kENoop) 343 { 344 *fLog << err << dbginf << "Syntax Error: Operator '" << text << "' unknown." << endl; 345 if (member0) 346 delete member0; 347 return NULL; 348 } 349 350 Int_t first = GetBracket(txt); 351 TString sub = txt(1, first-1); 352 txt.Remove(0, first+1); 353 354 newmember = new MDataChain(sub, op); 355 356 if (!newmember->IsValid()) 357 { 358 *fLog << err << dbginf << "Syntax Error: Error parsing contents '" << sub << "' of operator " << text << endl; 359 delete newmember; 360 if (member0) 361 delete member0; 362 return NULL; 363 } 275 364 } 276 365 … … 292 381 Double_t MDataChain::GetValue() const 293 382 { 294 return fMember ? fMember->GetValue() : 0; 383 if (!fMember) 384 return 0; 385 386 const Double_t val = fMember->GetValue(); 387 388 switch (fOperatorType) 389 { 390 case kEAbs: return fabs(val); 391 case kELog: return log(val); 392 case kELog10: return log10(val); 393 case kESin: return sin(val); 394 case kECos: return cos(val); 395 case kETan: return tan(val); 396 case kESinH: return sinh(val); 397 case kECosH: return cosh(val); 398 case kETanH: return tanh(val); 399 case kEASin: return asin(val); 400 case kEACos: return acos(val); 401 case kEATan: return atan(val); 402 case kESqrt: return sqrt(val); 403 case kEExp: return exp(val); 404 case kEPow10: return pow(10, val); 405 case kENoop: return val; 406 } 407 408 return 0; 295 409 } 296 410 297 411 void MDataChain::Print(Option_t *opt) const 298 412 { 413 Bool_t bracket = fOperatorType!=kENoop && !fMember->InheritsFrom(MDataList::Class()); 414 415 switch (fOperatorType) 416 { 417 case kEAbs: *fLog << "abs" << flush; break; 418 case kELog: *fLog << "log" << flush; break; 419 case kELog10: *fLog << "log10" << flush; break; 420 case kESin: *fLog << "sin" << flush; break; 421 case kECos: *fLog << "cos" << flush; break; 422 case kETan: *fLog << "tan" << flush; break; 423 case kESinH: *fLog << "sinh" << flush; break; 424 case kECosH: *fLog << "cosh" << flush; break; 425 case kETanH: *fLog << "tanh" << flush; break; 426 case kEASin: *fLog << "asin" << flush; break; 427 case kEACos: *fLog << "acos" << flush; break; 428 case kEATan: *fLog << "atan" << flush; break; 429 case kESqrt: *fLog << "sqrt" << flush; break; 430 case kEExp: *fLog << "exp" << flush; break; 431 case kEPow10: *fLog << "pow10" << flush; break; 432 case kENoop: 433 break; 434 } 435 436 if (bracket) 437 *fLog << "(" << flush; 438 299 439 fMember->Print(); 300 } 440 441 if (bracket) 442 *fLog << ")" << flush; 443 } -
trunk/MagicSoft/Mars/mdata/MDataChain.h
r1305 r1332 19 19 MData *fMember; // Filter 20 20 21 typedef enum { 22 kENoop, 23 kELog10, 24 kELog, 25 kEAbs, 26 kESin, 27 kECos, 28 kETan, 29 kESinH, 30 kECosH, 31 kETanH, 32 kEASin, 33 kEACos, 34 kEATan, 35 kESqrt, 36 kEPow10, 37 kEExp 38 } OperatorType_t; 39 40 OperatorType_t fOperatorType; 41 42 OperatorType_t ParseOperator(TString txt) const; 43 21 44 Int_t IsAlNum(TString txt); 45 Int_t GetBracket(TString txt); 22 46 23 47 MData *ParseString(TString txt, Int_t level); 24 48 49 MDataChain(const char *rule, OperatorType_t op); 50 25 51 public: 26 MDataChain(const char * text, const char *name=NULL, const char *title=NULL);52 MDataChain(const char *rule, const char *name=NULL, const char *title=NULL); 27 53 ~MDataChain(); 28 54
Note:
See TracChangeset
for help on using the changeset viewer.