Ignore:
Timestamp:
04/06/04 13:41:56 (20 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mdata
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mdata/DataLinkDef.h

    r1524 r3666  
    1212#pragma link C++ class MDataMember+;
    1313#pragma link C++ class MDataChain+;
     14#pragma link C++ class MDataFormula+;
    1415
    1516#endif
  • trunk/MagicSoft/Mars/mdata/MDataChain.cc

    r3572 r3666  
    2525/////////////////////////////////////////////////////////////////////////////
    2626//
    27 //   MDataChain
     27// MDataChain
     28// ==========
    2829//
    2930// With this chain you can concatenate simple mathematical operations on
    3031// members of mars containers.
     32//
     33//
     34// Rules
     35// -----
    3136//
    3237// In the constructor you can give rule, like
     
    3641// in the containers. The result will be fDist divided by fLength.
    3742//
     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//
    3847// You can also use brackets:
    3948//   "HillasDource.fDist / (MHillas.fLength + MHillas.fWidth)"
    4049//
    41 // The allowed operations are: +, -, *, /, %
     50//
     51// Operators
     52// ---------
     53//
     54// The allowed operations are: +, -, *, /, %, ^
    4255//
    4356// While a%b returns the floating point reminder of a/b.
     57// While a^b returns a to the power of b
    4458//
    4559// Warning: There is no priority rule build in. So better use brackets
     
    98112// inf is the symbol for an infinite number.
    99113//
     114//
     115// Constants
     116// ---------
     117//
    100118// Constants are implemented in ParseDataMember, namely:
    101 //   kPi:      TMath::Pi()
    102 //   kRad2Deg: 180/kPi
    103 //   kDeg2Rad: kPi/180
     119//   kPi:       TMath::Pi()
     120//   kRad2Deg:  180/kPi
     121//   kDeg2Rad:  kPi/180
    104122//
    105123// 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// ------------------------
    114137// If you want to use variables, eg for fits you can use [0], [1], ...
    115138// These values are initialized with 0 and set by calling
    116139// SetVariables().
    117140//
     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//
    118153// 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.
    126162//
    127163/////////////////////////////////////////////////////////////////////////////
     
    141177#include "MDataValue.h"
    142178#include "MDataMember.h"
     179#include "MDataFormula.h"
    143180#include "MDataElement.h"
    144181
     
    222259    for (int i=0; i<l; i++)
    223260    {
    224         if (!isalnum(txt[i]) && txt[i]!='.' && txt[i]!=';' &&
     261        if (!isalnum(txt[i]) && txt[i]!='.' && txt[i]!=':' && txt[i]!=';' &&
    225262            /*txt[i]!='['&&txt[i]!=']'&&*/
    226263            ((txt[i]!='-' && txt[i]!='+') || i!=0))
     
    394431        case '/':
    395432        case '%':
     433        case '^':
    396434            if (member0)
    397435            {
     
    507545
    508546            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
    509552            if (op==kENoop)
    510553            {
     554                newmember = new MDataFormula(Form("%s(%s)", (const char*)text, (const char*)sub));
     555                if (newmember->IsValid())
     556                    break;
     557
    511558                *fLog << err << dbginf << "Syntax Error: Operator '" << text << "' unknown." << endl;
    512559                if (member0)
     
    514561                return NULL;
    515562            }
    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);
    520563
    521564            newmember = new MDataChain(sub, op);
     
    604647    return 0;
    605648}
    606 
    607     /*
    608 void MDataChain::Print(Option_t *opt) const
    609 {
    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         */
    646649
    647650// --------------------------------------------------------------------------
  • trunk/MagicSoft/Mars/mdata/MDataChain.h

    r3572 r3666  
    1717{
    1818private:
    19     MData *fMember; // Filter
     19    MData    *fMember; // Filter
    2020
    2121    // PLEASE, always add new enums to the end of the enumeration,
  • trunk/MagicSoft/Mars/mdata/MDataList.cc

    r3572 r3666  
    7979        fSign = kEModul;
    8080        return;
     81    case '^':
     82        fSign = kEPow;
     83        return;
    8184    default:
    8285        fSign = kENone;
     
    142145        while ((member=(MData*)Next()))
    143146        {
    144             Double_t d = member->GetValue();
     147            const Double_t d = member->GetValue();
    145148            if (d==0)
    146149            {
    147                 *fLog << warn << "Warning: Division by zero (" << member->GetName() << ")" << endl;
     150                *fLog << warn << "Warning: Division by zero: " << member->GetRule() << endl;
    148151                return 0;
    149152            }
     
    155158        while ((member=(MData*)Next()))
    156159        {
    157             Double_t d = member->GetValue();
     160            const Double_t d = member->GetValue();
    158161            if (d==0)
    159162            {
    160                 *fLog << warn << "Warning: Modulo division by zero (" << member->GetName() << ")" << endl;
     163                *fLog << warn << "Warning: Modulo division by zero: " << member->GetRule() << endl;
    161164                return 0;
    162165            }
     
    164167        }
    165168        break;
     169    case kEPow:
     170        while ((member=(MData*)Next()))
     171            val = pow(val, member->GetValue());
     172        break;
    166173    }
    167174    return val;
     
    185192}
    186193
     194Bool_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
    187206// --------------------------------------------------------------------------
    188207//
    189208// 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.
    191210//
    192211Bool_t MDataList::AddToList(MData *member)
     
    335354            str += "%";
    336355            break;
     356
     357        case kEPow:
     358            str += "^";
     359            break;
    337360        }
    338361
  • trunk/MagicSoft/Mars/mdata/MDataList.h

    r3572 r3666  
    2323    TOrdCollection fMembers;    // Container for the filters
    2424
    25     typedef enum { kENone, kEPlus, kEMinus, kEMult, kEDiv, kEModul } SignType_t;
     25    typedef enum { kENone, kEPlus, kEMinus, kEMult, kEDiv, kEModul, kEPow } SignType_t;
    2626    SignType_t fSign;
    2727
     
    4141    void SetOwner(Bool_t enable=kTRUE) { enable ? SetBit(kIsOwner) : ResetBit(kIsOwner); }
    4242
    43     Bool_t IsValid() const { return fMembers.GetSize() ? kTRUE : kFALSE; }
     43    Bool_t IsValid() const;// { return fMembers.GetSize() ? kTRUE : kFALSE; }
    4444    Bool_t IsReadyToSave() const;
    4545
  • trunk/MagicSoft/Mars/mdata/Makefile

    r2800 r3666  
    3737           MDataValue.cc \
    3838           MDataList.cc \
    39            MDataChain.cc
     39           MDataChain.cc \
     40           MDataFormula.cc
    4041
    4142SRCS    = $(SRCFILES)
Note: See TracChangeset for help on using the changeset viewer.