ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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 27 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 }

◆ ~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 }

Member Function Documentation

◆ getNPars()

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

Definition at line 45 of file RegularFormula.h.

◆ getParNames()

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

Definition at line 46 of file RegularFormula.h.

◆ 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 }

◆ setFormula()

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

Definition at line 128 of file RegularFormula.cxx.

129 {
130  m_par.clear();
132  return this->Compile(m_expr.Data());
133 }

Member Data Documentation

◆ m_expr

TString Root::RegularFormula::m_expr
private

Definition at line 52 of file RegularFormula.h.

◆ m_par

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

Definition at line 53 of file RegularFormula.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
Root::RegularFormula::parseExpression
void parseExpression(const char *expression, TString &expr)
Definition: RegularFormula.cxx:63
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
GEndl
#define GEndl
Definition: TMsgLogger.h:151
HION12.expression
string expression
Definition: HION12.py:56
lumiFormat.i
int i
Definition: lumiFormat.py:92
Root::kINFO
@ kINFO
Definition: TMsgLogger.h:50
Root::RegularFormula::setFormula
Int_t setFormula(const char *expression)
Definition: RegularFormula.cxx:128
Root::RegularFormula::m_par
std::list< TString > m_par
Definition: RegularFormula.h:53
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Root::RegularFormula::m_expr
TString m_expr
Definition: RegularFormula.h:52