Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
RemoveMathFromGDML.GDMLexpressionRemover Class Reference
Inheritance diagram for RemoveMathFromGDML.GDMLexpressionRemover:
RemoveMathFromGDML.GDMLpurifier RemoveMathFromGDML.XMLpurifier

Public Member Functions

def __init__ (self, options=None)
 
def initROOT (self)
 
def pass_floats (self, expression)
 
def purify_native (self, expression)
 
def purify_ROOT (self, expression)
 

Static Public Member Functions

def sanitize (s)
 

Public Attributes

 constants
 
 environment
 
 options
 
 formula
 
 purify
 
 ROOT
 

Detailed Description

Definition at line 74 of file RemoveMathFromGDML.py.

Constructor & Destructor Documentation

def RemoveMathFromGDML.GDMLexpressionRemover.__init__ (   self,
  options = None 
)

Definition at line 75 of file RemoveMathFromGDML.py.

75  def __init__(self, options = None):
76  self.constants = {}
77  self.environment = vars(math)
78  self.options = options
79  if not self.options.NoROOTformula:
80  self.initROOT()
81  self.formula = self.ROOT.TFormula("GDMLexpressionRemoverFormula", "0");
82  self.purify = self.purify_ROOT
83  else:
84  self.purify = self.purify_native

Member Function Documentation

def RemoveMathFromGDML.GDMLexpressionRemover.initROOT (   self)

Definition at line 91 of file RemoveMathFromGDML.py.

91  def initROOT(self):
92  try:
93  import ROOT
94  except ImportError:
95  raise ConfigurationError \
96  ("Can't load ROOT module: I can't use ROOT to evaluate formulas.")
97  ROOT.gErrorIgnoreLevel = ROOT.kFatal # do not even print errors
98  f = ROOT.TFormula("FTest", "1/2*2");
99  if f.Eval(0.) != 1.:
100  raise ConfigurationError(
101  """This script won't work with ROOT version (%s);\n"""
102  """Please set upa recent version 5.\n"""
103  """(quick test: 'TFormula("F", "1/2*2").Eval(0.)' should return 1)"""
104  % ROOT.gROOT.GetVersion()
105  )
106  self.ROOT = ROOT # store the module for loca use
def RemoveMathFromGDML.GDMLexpressionRemover.pass_floats (   self,
  expression 
)

Definition at line 109 of file RemoveMathFromGDML.py.

109  def pass_floats(self, expression):
110  float(expression) # just throw an exception if not a float
111  return expression
def RemoveMathFromGDML.GDMLexpressionRemover.purify_native (   self,
  expression 
)

Definition at line 114 of file RemoveMathFromGDML.py.

114  def purify_native(self, expression):
115  try: return self.pass_floats(expression)
116  except ValueError: pass
117 
118  # is it a valid expression?
119  try:
120  sanitized = self.sanitize(expression)
121  return str(eval(sanitized, self.environment, self.constants))
122  except:
123  return expression
static QCString str
def RemoveMathFromGDML.GDMLexpressionRemover.purify_ROOT (   self,
  expression 
)

Definition at line 126 of file RemoveMathFromGDML.py.

126  def purify_ROOT(self, expression):
127  try: return self.pass_floats(expression)
128  except ValueError: pass
129 
130  # is it a valid expression?
131  if self.formula.Compile(expression) == 0:
132  return str(self.formula.Eval(0.))
133  else:
134  return expression
static QCString str
def RemoveMathFromGDML.GDMLexpressionRemover.sanitize (   s)
static

Definition at line 88 of file RemoveMathFromGDML.py.

88  def sanitize(s):
89  return s.replace("^", "**")
90 

Member Data Documentation

RemoveMathFromGDML.GDMLexpressionRemover.constants

Definition at line 76 of file RemoveMathFromGDML.py.

RemoveMathFromGDML.GDMLexpressionRemover.environment

Definition at line 77 of file RemoveMathFromGDML.py.

RemoveMathFromGDML.GDMLexpressionRemover.formula

Definition at line 81 of file RemoveMathFromGDML.py.

RemoveMathFromGDML.GDMLexpressionRemover.options

Definition at line 78 of file RemoveMathFromGDML.py.

RemoveMathFromGDML.GDMLexpressionRemover.purify

Definition at line 82 of file RemoveMathFromGDML.py.

RemoveMathFromGDML.GDMLexpressionRemover.ROOT

Definition at line 106 of file RemoveMathFromGDML.py.


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