Changeset 6569 for trunk/MagicSoft/Mars/mdata
- Timestamp:
- 02/17/05 17:09:00 (20 years ago)
- Location:
- trunk/MagicSoft/Mars/mdata
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mdata/MDataChain.cc
r6515 r6569 52 52 // --------- 53 53 // 54 // The allowed operations are: +, -, *, /, %, ^ 54 // The allowed operations are: +, -, *, /, %, ^ and ** for ^ 55 55 // 56 56 // While a%b returns the floating point reminder of a/b. 57 57 // While a^b returns a to the power of b 58 58 // 59 // Warning: There is no priority rule build in. So better use parantheses60 // to get correct results. The rule is parsed/evaluated from the left61 // to the right, which means:62 // 63 // "MHillas.fWidth + MHillas.fLength / HillasSource.fDist"64 // 65 // is parses as66 // 67 // "(MHillas.fWidth + MHillas.fLength) / HillasSource.fDist"59 // Priority 60 // -------- 61 // 62 // The priority of the operators is build in as: 63 // ^ (highest), %, *, /, +, - 64 // 65 // Priorities are evaluated before parsing the rule by inserting 66 // artificial paranthesis. If you find ANY problem with this please 67 // report it immediatly! It is highly recommended to check the result! 68 68 // 69 69 // You can also use mathmatical operators, eg: … … 168 168 #include <stdlib.h> // strtod, ... 169 169 170 #include <TRegexp.h> 170 171 #include <TRandom.h> 171 172 #include <TMethodCall.h> … … 371 372 } 372 373 374 // -------------------------------------------------------------------------- 375 // 376 // Remove all whitespaces 377 // Replace all kind of double +/- by a single + or - 378 // 373 379 void MDataChain::SimplifyString(TString &txt) const 374 380 { 381 txt.ReplaceAll(" ", ""); 382 txt.ReplaceAll("**", "^"); 383 375 384 while (txt.First("--")>=0 || txt.First("++")>=0 || 376 385 txt.First("+-")>=0 || txt.First("-+")>=0) … … 385 394 // -------------------------------------------------------------------------- 386 395 // 396 // Add Parenthesis depending on the priority of the operators. The 397 // priorities are defined by the default of the second argument. 398 // 399 void MDataChain::AddParenthesis(TString &test, const TString op) const 400 { 401 const TString low = op(1, op.Length()); 402 if (low.Length()==0) 403 return; 404 405 //cout << "--- " << Form("[%c]", op[0]) << " ---" << endl; 406 407 int offset = 0; 408 while (1) 409 { 410 const TString check = test(offset, test.Length()); 411 if (check.IsNull()) 412 break; 413 414 const Ssiz_t pos = check.First(op[0]); 415 if (pos<0) 416 break; 417 418 int cnt=0; 419 420 int i; 421 for (i=pos-1; i>=0; i--) 422 { 423 if (check[i]==')') 424 cnt++; 425 if (check[i]=='(') 426 cnt--; 427 if (cnt>0 || low.First(check[i])<0) 428 continue; 429 break; 430 } 431 432 cnt=0; 433 int j; 434 for (j=pos; j<check.Length(); j++) 435 { 436 if (check[j]=='(') 437 cnt++; 438 if (check[j]==')') 439 cnt--; 440 if (cnt>0 || low.First(check[j])<0) 441 continue; 442 break; 443 } 444 445 const TString sub = test(offset+i+1, j-i-1); 446 447 // Check if it contains operators, 448 // otherwise we can simply skip it 449 static const TRegexp regexp("[%/*^+-]"); 450 if (sub.Index(regexp)>0) 451 { 452 test.Insert(offset+j, ")"); 453 test.Insert(offset+i+1, "("); 454 offset += 2; 455 } 456 offset += j+1; 457 } 458 459 AddParenthesis(test, low); 460 } 461 462 // -------------------------------------------------------------------------- 463 // 387 464 // Core of the data chain. Here the chain is constructed out of the rule. 388 465 // … … 390 467 { 391 468 if (level==0) 469 { 392 470 SimplifyString(txt); 471 AddParenthesis(txt); 472 } 393 473 394 474 MData *member0=NULL; … … 828 908 return kTRUE; 829 909 } 910 /* 911 void MDataChain::ReconstructElements() 912 { 913 if (!fMember) 914 return; 915 916 if (fMember->InheritsFrom(MDataElement::Class())) 917 { 918 MData *data = ((MDataElement*)fMember)->CloneColumn(); 919 delete fMember; 920 fMember = data; 921 } 922 923 fMember->ReconstructElements(); 924 } 925 */ -
trunk/MagicSoft/Mars/mdata/MDataChain.h
r5956 r6569 45 45 46 46 void SimplifyString(TString &txt) const; 47 void AddParenthesis(TString &test, const TString op="^%*/+-") const; 47 48 MData *ParseString(TString txt, Int_t level); 48 49 MData *ParseDataMember(TString txt); … … 62 63 TString GetRule() const; 63 64 TString GetDataMember() const; 65 //void ReconstructElements() { if (fMember) fMember->ReconstructElements(); } 64 66 65 67 // MParContainer
Note:
See TracChangeset
for help on using the changeset viewer.