Ignore:
Timestamp:
05/16/03 13:11:23 (22 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mdata
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mdata/MDataChain.cc

    r2098 r2117  
    8282//   randl(x)  returns gRandom->Landau(0, x)
    8383//
     84//
     85// Constants are implemented in ParseDataMember, namely:
     86//   kPi:      TMath::Pi()
     87//   kRad2Deg: 180/kPi
     88//   kDeg2Rad: kPi/180
     89//
     90// You can also defined constants which are defined in TMath by:
     91//   kLn10      for   static Double_t TMath::Ln10();
     92//   kLogE      for   static Double_t TMath::LogE();
     93//   kRadToDeg  for   static Double_t TMath::RadToDeg();
     94//   kDegToRad  for   static Double_t TMath::DegToRad();
     95// Remark: In older root versions only Pi() and E() are implemented in
     96//         TMath.
     97//
     98//
    8499// REMARK:
    85100//         - All the random functions are returning 0 if gRandom==0
     
    100115
    101116#include <TRandom.h>
     117#include <TMethodCall.h>
    102118
    103119#include "MLog.h"
     
    126142// --------------------------------------------------------------------------
    127143//
    128 //  Default constructor
    129 //
    130 MDataChain::MDataChain()
    131     : fMember(NULL), fOperatorType(kENoop)
    132 {
    133 }
    134 
    135 // --------------------------------------------------------------------------
    136 //
    137144// Constructor taking a rule as an argument. For more details see
    138145// class description
    139146//
    140147MDataChain::MDataChain(const char *rule, const char *name, const char *title)
    141     : fOperatorType(kENoop)
     148    : fMember(NULL), fOperatorType(kENoop)
    142149{
    143150    fName  = name  ? name  : "MDataChain";
    144151    fTitle = title ? title : rule;
     152
     153    if (TString(rule).IsNull())
     154        return;
    145155
    146156    *fLog << inf << "Trying to resolve rule... " << flush;
     
    259269// --------------------------------------------------------------------------
    260270//
     271// Here the names of data members are interpreted. This can be used to
     272// check for constants.
     273//
     274MData *MDataChain::ParseDataMember(TString txt)
     275{
     276    //txt.ToLower();
     277
     278    if (txt=="kRad2Deg") return new MDataValue(kRad2Deg);
     279    if (txt=="kDeg2Rad") return new MDataValue(1./kRad2Deg);
     280
     281    if (!txt.BeginsWith("k"))
     282        return new MDataMember(txt.Data());
     283
     284    const TString name = txt(1, txt.Length());
     285    TMethodCall call(TMath::Class(), name, "");
     286    switch (call.ReturnType())
     287    {
     288    case TMethodCall::kLong:
     289        Long_t l;
     290        call.Execute(l);
     291        return new MDataValue(l);
     292    case TMethodCall::kDouble:
     293        Double_t d;
     294        call.Execute(d);
     295        return new MDataValue(d);
     296    default:
     297        break;
     298    }
     299
     300    return new MDataMember(txt.Data());
     301}
     302
     303// --------------------------------------------------------------------------
     304//
    261305// Core of the data chain. Here the chain is constructed out of the rule.
    262306//
     
    418462            if ((txt.IsNull() || txt[0]!='(') && text[0]!='-' && text[0]!='+')
    419463            {
    420                 newmember = new MDataMember(text.Data());
     464                newmember = ParseDataMember(text.Data());
    421465                break;
    422466            }
     
    469513    if (!fMember)
    470514    {
    471         *fLog << warn << "MDataChain not valid." << endl;
     515        //*fLog << warn << "MDataChain not valid." << endl;
    472516        return 0;
    473517    }
  • trunk/MagicSoft/Mars/mdata/MDataChain.h

    r1853 r2117  
    5959
    6060    MData *ParseString(TString txt, Int_t level);
     61    MData *ParseDataMember(TString txt);
    6162
    6263    MDataChain(const char *rule, OperatorType_t op);
    6364
    6465public:
    65     MDataChain();
    66     MDataChain(const char *rule, const char *name=NULL, const char *title=NULL);
     66    MDataChain(const char *rule=NULL, const char *name=NULL, const char *title=NULL);
    6767    ~MDataChain();
    6868
Note: See TracChangeset for help on using the changeset viewer.