All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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__
 
def initROOT
 
def pass_floats
 
def purify_native
 
def purify_ROOT
 

Static Public Member Functions

def sanitize
 

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 
)

Member Function Documentation

def RemoveMathFromGDML.GDMLexpressionRemover.initROOT (   self)

Definition at line 91 of file RemoveMathFromGDML.py.

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

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

Definition at line 114 of file RemoveMathFromGDML.py.

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

Definition at line 126 of file RemoveMathFromGDML.py.

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

Definition at line 88 of file RemoveMathFromGDML.py.

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

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: