ATLAS Offline Software
Loading...
Searching...
No Matches
Root::RegularFormula Class Reference

#include <RegularFormula.h>

Inheritance diagram for Root::RegularFormula:
Collaboration diagram for Root::RegularFormula:

Public Member Functions

 RegularFormula ()
 RegularFormula (const char *name, const char *expression)
virtual ~RegularFormula ()
 RegularFormula (const Root::RegularFormula &other)
RegularFormulaoperator= (const RegularFormula &other)
Int_t setFormula (const char *expression)
unsigned int getNPars () const
const std::list< TString > & getParNames () const

Private Member Functions

void parseExpression (const char *expression, TString &expr)

Private Attributes

TString m_expr
std::list< TString > m_par

Detailed Description

Definition at line 22 of file RegularFormula.h.

Constructor & Destructor Documentation

◆ RegularFormula() [1/3]

Root::RegularFormula::RegularFormula ( )

◆ RegularFormula() [2/3]

Root::RegularFormula::RegularFormula ( const char * name,
const char * expression )

Definition at line 28 of file RegularFormula.cxx.

29 : TFormula(name,"1")
30{
31 (void) setFormula(expression);
32}
Int_t setFormula(const char *expression)

◆ ~RegularFormula()

Root::RegularFormula::~RegularFormula ( )
virtual

Definition at line 34 of file RegularFormula.cxx.

35{
36}

◆ RegularFormula() [3/3]

Root::RegularFormula::RegularFormula ( const Root::RegularFormula & other)

Definition at line 39 of file RegularFormula.cxx.

40 : TFormula(other)
41 , m_expr(other.m_expr)
42 , m_par(other.m_par)
43{
44}
std::list< TString > m_par

Member Function Documentation

◆ getNPars()

unsigned int Root::RegularFormula::getNPars ( ) const
inline

Definition at line 35 of file RegularFormula.h.

35{ return m_par.size(); }

◆ getParNames()

const std::list< TString > & Root::RegularFormula::getParNames ( ) const
inline

Definition at line 36 of file RegularFormula.h.

36{ return m_par; }

◆ operator=()

Root::RegularFormula & Root::RegularFormula::operator= ( const RegularFormula & other)

Definition at line 48 of file RegularFormula.cxx.

49{
50 if (&other==this) {
51 return *this;
52 }
53
54 TFormula::operator=(other) ;
55 m_expr = other.m_expr;
56 m_par = other.m_par;
57
58 return *this ;
59}

◆ parseExpression()

void Root::RegularFormula::parseExpression ( const char * expression,
TString & expr )
private

Definition at line 63 of file RegularFormula.cxx.

64{
65 expr = expression;
66 TString parStr(expression);
67
68 TRegexp specialChars("[+-/*%&=!><()|]+");
69 int lastIdx = -1;
70 do {
71 //search for special characters and determine if they're escaped
72 lastIdx = parStr.Index(specialChars, lastIdx+1);
73 if (lastIdx >= 0) {
74 bool needsReplacement = false;
75 if (lastIdx > 0) {
76 //if a match is found and it's not the first character of the string
77 char isEscape = parStr[lastIdx-1];
78 if (isEscape == '\\') {
79 //this is an escpaed special character, keep it but remove escape
80 // both on parStr as well as in expr
81 parStr = parStr.Remove(lastIdx-1, 1);
82 expr = expr.Remove(lastIdx-1, 1);
83 needsReplacement = false;
84 lastIdx--; //we removed one character from the string
85 } else {
86 needsReplacement = true;
87 }
88 } else {
89 //matched the first character
90 needsReplacement = true;
91 }
92
93 if (needsReplacement) {
94 //not escaped, just replace with a space to allow parameters parsing below
95 parStr = parStr.Replace(lastIdx, 1, " ");
96 }
97 }
98 } while (lastIdx >= 0);
99
100 TMsgLogger mylogger( "RegularFormula" );
101 mylogger << kINFO << "Now parsing regular expression : " << expression << GEndl;
102 mylogger << kINFO << "Please be aware that Cling errors are expected and aren't inherently a problem" << GEndl;
103
104 TFormula analyzer("analyzer","1");
105 TObjArray* parArr = parStr.Tokenize(" ");
106 for (int count(0), i(0); i<parArr->GetEntries(); ++i) {
107 TString myPar = ((TObjString*)parArr->At(i))->GetString();
108 if ( 0==analyzer.Compile(myPar.Data()) ||
109 0==analyzer.Compile(Form("%s(1)",myPar.Data())) ) {
110 continue;
111 } else {
112 std::list<TString>::iterator itrF = std::find(m_par.begin(),m_par.end(),myPar);
113 if (itrF==m_par.end()) {
114 expr = expr.ReplaceAll(myPar,Form("[%d]",count));
115 m_par.push_back(myPar);
116 count++;
117 }
118 }
119 }
120 delete parArr;
121
122 mylogger << kINFO << "Number of interpreted input parameters : " << m_par.size() << GEndl;
123 mylogger << kINFO << "Parsed regular expression : " << expr << GEndl;
124}
#define GEndl
Definition TMsgLogger.h:147
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
@ kINFO
Definition TMsgLogger.h:40
str expression
Definition HION12.py:55

◆ setFormula()

Int_t Root::RegularFormula::setFormula ( const char * expression)

Definition at line 128 of file RegularFormula.cxx.

129{
130 m_par.clear();
131 this->parseExpression(expression,m_expr);
132 return this->Compile(m_expr.Data());
133}
void parseExpression(const char *expression, TString &expr)

Member Data Documentation

◆ m_expr

TString Root::RegularFormula::m_expr
private

Definition at line 42 of file RegularFormula.h.

◆ m_par

std::list<TString> Root::RegularFormula::m_par
private

Definition at line 43 of file RegularFormula.h.


The documentation for this class was generated from the following files: