Changeset 3666 for trunk/MagicSoft/Mars/mdata
- Timestamp:
- 04/06/04 13:41:56 (21 years ago)
- Location:
- trunk/MagicSoft/Mars/mdata
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mdata/DataLinkDef.h
r1524 r3666 12 12 #pragma link C++ class MDataMember+; 13 13 #pragma link C++ class MDataChain+; 14 #pragma link C++ class MDataFormula+; 14 15 15 16 #endif -
trunk/MagicSoft/Mars/mdata/MDataChain.cc
r3572 r3666 25 25 ///////////////////////////////////////////////////////////////////////////// 26 26 // 27 // MDataChain 27 // MDataChain 28 // ========== 28 29 // 29 30 // With this chain you can concatenate simple mathematical operations on 30 31 // members of mars containers. 32 // 33 // 34 // Rules 35 // ----- 31 36 // 32 37 // In the constructor you can give rule, like … … 36 41 // in the containers. The result will be fDist divided by fLength. 37 42 // 43 // In case you want to access a data-member which is a data member object 44 // you can acces it with (Remark: it must derive from MParContainer): 45 // "MCameraLV.fPowerSupplyA.fVoltagePos5V" 46 // 38 47 // You can also use brackets: 39 48 // "HillasDource.fDist / (MHillas.fLength + MHillas.fWidth)" 40 49 // 41 // The allowed operations are: +, -, *, /, % 50 // 51 // Operators 52 // --------- 53 // 54 // The allowed operations are: +, -, *, /, %, ^ 42 55 // 43 56 // While a%b returns the floating point reminder of a/b. 57 // While a^b returns a to the power of b 44 58 // 45 59 // Warning: There is no priority rule build in. So better use brackets … … 98 112 // inf is the symbol for an infinite number. 99 113 // 114 // 115 // Constants 116 // --------- 117 // 100 118 // Constants are implemented in ParseDataMember, namely: 101 // kPi: TMath::Pi()102 // kRad2Deg: 180/kPi103 // kDeg2Rad: kPi/180119 // kPi: TMath::Pi() 120 // kRad2Deg: 180/kPi 121 // kDeg2Rad: kPi/180 104 122 // 105 123 // You can also defined constants which are defined in TMath by: 106 // kLn10 for static Double_t TMath::Ln10(); 107 // kLogE for static Double_t TMath::LogE(); 108 // kRadToDeg for static Double_t TMath::RadToDeg(); 109 // kDegToRad for static Double_t TMath::DegToRad(); 110 // 111 // Remark: In older root versions only Pi() and E() are implemented in 112 // TMath. 113 // 124 // kLn10 for static Double_t TMath::Ln10(); 125 // kLogE for static Double_t TMath::LogE(); 126 // kRadToDeg for static Double_t TMath::RadToDeg(); 127 // kDegToRad for static Double_t TMath::DegToRad(); 128 // ... 129 // 130 // Remark: 131 // In older root versions only Pi() and E() are implemented 132 // in TMath. 133 // 134 // 135 // Variable Parameters 136 // ------------------------ 114 137 // If you want to use variables, eg for fits you can use [0], [1], ... 115 138 // These values are initialized with 0 and set by calling 116 139 // SetVariables(). 117 140 // 141 // 142 // Multi-argument functions 143 // ------------------------ 144 // You can use multi-argument functions, too. The access is implemented 145 // via TFormula, which slows down thing a lot. If you can avoid usage 146 // of such expression you accelerate the access a lot. Example: 147 // "TMath::Hypot(MHillas.fMeanX, MHillas.MeanY)" 148 // "pow(MHillas.fMeanX*MHillas.MeanY, -1.2)" 149 // It should be possible to use all functions which are accessible 150 // via the root-dictionary. 151 // 152 // 118 153 // REMARK: 119 // - All the random functions are returning 0 if gRandom==0 120 // - You may get better results if you are using a TRandom3 121 // 122 // FIXME: The possibility to use other objects inheriting from MData 123 // is missing. 124 // Maybe we can use gInterpreter->Calc("") for this. 125 // gROOT->ProcessLineFast("line"); 154 // - All the random functions are returning 0 if gRandom==0 155 // - You may get better results if you are using a TRandom3 156 // 157 // To Do: 158 // - The possibility to use other objects inheriting from MData 159 // is missing. 160 // - By automatic pre-adding brackets to the rule it would be possible 161 // to implement priorities for operators. 126 162 // 127 163 ///////////////////////////////////////////////////////////////////////////// … … 141 177 #include "MDataValue.h" 142 178 #include "MDataMember.h" 179 #include "MDataFormula.h" 143 180 #include "MDataElement.h" 144 181 … … 222 259 for (int i=0; i<l; i++) 223 260 { 224 if (!isalnum(txt[i]) && txt[i]!='.' && txt[i]!=' ;' &&261 if (!isalnum(txt[i]) && txt[i]!='.' && txt[i]!=':' && txt[i]!=';' && 225 262 /*txt[i]!='['&&txt[i]!=']'&&*/ 226 263 ((txt[i]!='-' && txt[i]!='+') || i!=0)) … … 394 431 case '/': 395 432 case '%': 433 case '^': 396 434 if (member0) 397 435 { … … 507 545 508 546 OperatorType_t op = ParseOperator(text); 547 548 Int_t first = GetBracket(txt, '(', ')'); 549 TString sub = op==kENegative || op==kEPositive ? text.Remove(0,1) + txt : txt(1, first-1); 550 txt.Remove(0, first+1); 551 509 552 if (op==kENoop) 510 553 { 554 newmember = new MDataFormula(Form("%s(%s)", (const char*)text, (const char*)sub)); 555 if (newmember->IsValid()) 556 break; 557 511 558 *fLog << err << dbginf << "Syntax Error: Operator '" << text << "' unknown." << endl; 512 559 if (member0) … … 514 561 return NULL; 515 562 } 516 517 Int_t first = GetBracket(txt, '(', ')');518 TString sub = op==kENegative || op==kEPositive ? text.Remove(0,1) + txt : txt(1, first-1);519 txt.Remove(0, first+1);520 563 521 564 newmember = new MDataChain(sub, op); … … 604 647 return 0; 605 648 } 606 607 /*608 void MDataChain::Print(Option_t *opt) const609 {610 *fLog << GetRule() << flush;611 Bool_t bracket = fOperatorType!=kENoop && !fMember->InheritsFrom(MDataList::Class());612 613 switch (fOperatorType)614 {615 case kEAbs: *fLog << "abs" << flush; break;616 case kELog: *fLog << "log" << flush; break;617 case kELog10: *fLog << "log10" << flush; break;618 case kESin: *fLog << "sin" << flush; break;619 case kECos: *fLog << "cos" << flush; break;620 case kETan: *fLog << "tan" << flush; break;621 case kESinH: *fLog << "sinh" << flush; break;622 case kECosH: *fLog << "cosh" << flush; break;623 case kETanH: *fLog << "tanh" << flush; break;624 case kEASin: *fLog << "asin" << flush; break;625 case kEACos: *fLog << "acos" << flush; break;626 case kEATan: *fLog << "atan" << flush; break;627 case kESqrt: *fLog << "sqrt" << flush; break;628 case kEExp: *fLog << "exp" << flush; break;629 case kEPow10: *fLog << "pow10" << flush; break;630 case kESgn: *fLog << "sgn" << flush; break;631 case kENegative: *fLog << "-" << flush; break;632 case kEPositive: *fLog << "+" << flush; break;633 case kENoop:634 break;635 }636 637 if (bracket)638 *fLog << "(" << flush;639 640 fMember->Print();641 642 if (bracket)643 *fLog << ")" << flush;644 }645 */646 649 647 650 // -------------------------------------------------------------------------- -
trunk/MagicSoft/Mars/mdata/MDataChain.h
r3572 r3666 17 17 { 18 18 private: 19 MData *fMember; // Filter19 MData *fMember; // Filter 20 20 21 21 // PLEASE, always add new enums to the end of the enumeration, -
trunk/MagicSoft/Mars/mdata/MDataList.cc
r3572 r3666 79 79 fSign = kEModul; 80 80 return; 81 case '^': 82 fSign = kEPow; 83 return; 81 84 default: 82 85 fSign = kENone; … … 142 145 while ((member=(MData*)Next())) 143 146 { 144 Double_t d = member->GetValue();147 const Double_t d = member->GetValue(); 145 148 if (d==0) 146 149 { 147 *fLog << warn << "Warning: Division by zero (" << member->GetName() << ")"<< endl;150 *fLog << warn << "Warning: Division by zero: " << member->GetRule() << endl; 148 151 return 0; 149 152 } … … 155 158 while ((member=(MData*)Next())) 156 159 { 157 Double_t d = member->GetValue();160 const Double_t d = member->GetValue(); 158 161 if (d==0) 159 162 { 160 *fLog << warn << "Warning: Modulo division by zero (" << member->GetName() << ")"<< endl;163 *fLog << warn << "Warning: Modulo division by zero: " << member->GetRule() << endl; 161 164 return 0; 162 165 } … … 164 167 } 165 168 break; 169 case kEPow: 170 while ((member=(MData*)Next())) 171 val = pow(val, member->GetValue()); 172 break; 166 173 } 167 174 return val; … … 185 192 } 186 193 194 Bool_t MDataList::IsValid() const 195 { 196 TIter Next(&fMembers); 197 198 MData *data = NULL; 199 while ((data=(MData*)Next())) 200 if (!data->IsValid()) 201 return kFALSE; 202 203 return kTRUE; 204 } 205 187 206 // -------------------------------------------------------------------------- 188 207 // 189 208 // If you want to add a new member to the list call this function with the 190 // pointer to the member to be added. 209 // pointer to the member to be added. 191 210 // 192 211 Bool_t MDataList::AddToList(MData *member) … … 335 354 str += "%"; 336 355 break; 356 357 case kEPow: 358 str += "^"; 359 break; 337 360 } 338 361 -
trunk/MagicSoft/Mars/mdata/MDataList.h
r3572 r3666 23 23 TOrdCollection fMembers; // Container for the filters 24 24 25 typedef enum { kENone, kEPlus, kEMinus, kEMult, kEDiv, kEModul } SignType_t;25 typedef enum { kENone, kEPlus, kEMinus, kEMult, kEDiv, kEModul, kEPow } SignType_t; 26 26 SignType_t fSign; 27 27 … … 41 41 void SetOwner(Bool_t enable=kTRUE) { enable ? SetBit(kIsOwner) : ResetBit(kIsOwner); } 42 42 43 Bool_t IsValid() const { return fMembers.GetSize() ? kTRUE : kFALSE; }43 Bool_t IsValid() const;// { return fMembers.GetSize() ? kTRUE : kFALSE; } 44 44 Bool_t IsReadyToSave() const; 45 45 -
trunk/MagicSoft/Mars/mdata/Makefile
r2800 r3666 37 37 MDataValue.cc \ 38 38 MDataList.cc \ 39 MDataChain.cc 39 MDataChain.cc \ 40 MDataFormula.cc 40 41 41 42 SRCS = $(SRCFILES)
Note:
See TracChangeset
for help on using the changeset viewer.