ATLAS Offline Software
Public Member Functions | Static Public Attributes | Static Private Member Functions | Private Attributes | List of all members
python.AnaAlgorithmConfig.AnaAlgorithmConfig Class Reference
Inheritance diagram for python.AnaAlgorithmConfig.AnaAlgorithmConfig:
Collaboration diagram for python.AnaAlgorithmConfig.AnaAlgorithmConfig:

Public Member Functions

def __init__ (self, typeAndName, **kwargs)
 
def getName (self)
 
def getType (self)
 
def __getattr__ (self, name)
 
def __setattr__ (self, key, value)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __str__ (self)
 
def addPrivateTool (self, name, type)
 
def addPrivateToolInArray (self, name, type)
 

Static Public Attributes

int printHeaderWidth = 80
 
int printHeaderPre = 3
 

Static Private Member Functions

def _printHeader (title)
 
def _printFooter (title)
 

Private Attributes

 _props
 

Detailed Description

Standalone Analysis Algorithm Configuration

This class is used to describe the configuration of an analysis algorithm
(a C++ class inheriting from EL::AnaAlgorithm) in Python. It behaves
similar to an Athena configurable, but is implemented in a much simpler
way.

An example of using it in configuring an EventLoop job could look like:

   job = ROOT.EL.Job()
   ...
   from AnaAlgorithm.AnaAlgorithmConfig import AnaAlgorithmConfig
   alg = AnaAlgorithmConfig( "EL::UnitTestAlg2/TestAlg",
                             property = 1.23 )
   alg.string_property = "Foo"
   job.algsAdd( alg )

Note that the python code doesn't know what properties can actually be set
on any given C++ algorithm. Any mistake made in the Python configuration
(apart from syntax errors) is only discovered while initialising the
analysis job.

Definition at line 8 of file AnaAlgorithmConfig.py.

Constructor & Destructor Documentation

◆ __init__()

def python.AnaAlgorithmConfig.AnaAlgorithmConfig.__init__ (   self,
  typeAndName,
**  kwargs 
)
Constructor for an algorithm configuration object

Keyword arguments:
  typeAndName -- The type/instance name of the algorithm

Note that you can pass (initial) properties to the constructor like:

   alg = AnaAlgorithmConfig( "EL::UnitTestAlg2/TestAlg",
                     property = 1.23 )

Definition at line 36 of file AnaAlgorithmConfig.py.

36  def __init__( self, typeAndName, **kwargs ):
37  """Constructor for an algorithm configuration object
38 
39  Keyword arguments:
40  typeAndName -- The type/instance name of the algorithm
41 
42  Note that you can pass (initial) properties to the constructor like:
43 
44  alg = AnaAlgorithmConfig( "EL::UnitTestAlg2/TestAlg",
45  property = 1.23 )
46  """
47 
48  # Call the base class's constructor. Use the default constructor instead
49  # of the one receiving the type and name, to avoid ROOT-10872.
50  super( AnaAlgorithmConfig, self ).__init__()
51  self.setTypeAndName( typeAndName )
52 
53  # Initialise the properties of the algorihm:
54  self._props = {}
55 
56  # Set the properties on the object:
57  for key, value in kwargs.items():
58  self.setPropertyFromString( key, stringPropValue( value ) )
59  self._props[ key ] = copy.deepcopy( value )
60  pass
61 
62  pass
63 

Member Function Documentation

◆ __eq__()

def python.AnaAlgorithmConfig.AnaAlgorithmConfig.__eq__ (   self,
  other 
)
Check for equality with another object

The implementation of this is very simple. We only check that the type
and the name of the algorithms would match.

Definition at line 127 of file AnaAlgorithmConfig.py.

127  def __eq__( self, other ):
128  """Check for equality with another object
129 
130  The implementation of this is very simple. We only check that the type
131  and the name of the algorithms would match.
132  """
133 
134  # First check that the other object is also an AnaAlgorithmConfig one:
135  if not isinstance( other, AnaAlgorithmConfig ):
136  return False
137 
138  # Now check whether the type and the name of the algorithms agree:
139  return ( ( self.type() == other.type() ) and
140  ( self.name() == other.name() ) )
141 

◆ __getattr__()

def python.AnaAlgorithmConfig.AnaAlgorithmConfig.__getattr__ (   self,
  name 
)
Get a previously set property value from the configuration

This function allows us to retrieve the value of a property that was
already set for the algorithm, to possibly use it in some configuration
decisions in the Python code itself.

Keyword arguments:
  name -- The name of the property

Definition at line 82 of file AnaAlgorithmConfig.py.

82  def __getattr__( self, name ):
83  """Get a previously set property value from the configuration
84 
85  This function allows us to retrieve the value of a property that was
86  already set for the algorithm, to possibly use it in some configuration
87  decisions in the Python code itself.
88 
89  Keyword arguments:
90  name -- The name of the property
91  """
92 
93  # Fail if the property was not (yet) set:
94  if not name in self._props:
95  raise AttributeError( 'Property \'%s\' was not set on \'%s/%s\'' %
96  ( name, self.type(), self.name() ) )
97 
98  # Return the property value:
99  return self._props[ name ]
100 

◆ __ne__()

def python.AnaAlgorithmConfig.AnaAlgorithmConfig.__ne__ (   self,
  other 
)
Check for an inequality with another object

This is just defined to make the '!=' operator of Python behave
consistently with the '==' operator for such objects.

Definition at line 142 of file AnaAlgorithmConfig.py.

142  def __ne__( self, other ):
143  """Check for an inequality with another object
144 
145  This is just defined to make the '!=' operator of Python behave
146  consistently with the '==' operator for such objects.
147  """
148  return not self.__eq__( other )
149 

◆ __setattr__()

def python.AnaAlgorithmConfig.AnaAlgorithmConfig.__setattr__ (   self,
  key,
  value 
)
Set an algorithm property on an existing configuration object

This function allows us to set/override properties on an algorithm
configuration object. Allowing for the following syntax:

   alg = ...
   alg.IntProperty = 66
   alg.FloatProperty = 3.141592
   alg.StringProperty = "Foo"

Keyword arguments:
  key   -- The key/name of the property
  value -- The value to set for the property

Definition at line 101 of file AnaAlgorithmConfig.py.

101  def __setattr__( self, key, value ):
102  """Set an algorithm property on an existing configuration object
103 
104  This function allows us to set/override properties on an algorithm
105  configuration object. Allowing for the following syntax:
106 
107  alg = ...
108  alg.IntProperty = 66
109  alg.FloatProperty = 3.141592
110  alg.StringProperty = "Foo"
111 
112  Keyword arguments:
113  key -- The key/name of the property
114  value -- The value to set for the property
115  """
116 
117  # Private variables should be set directly:
118  if key[ 0 ] == '_':
119  return super( AnaAlgorithmConfig, self ).__setattr__( key, value )
120 
121  # Set the property, and remember its value:
122  super( AnaAlgorithmConfig,
123  self ).setPropertyFromString( key, stringPropValue( value ) )
124  self._props[ key ] = copy.deepcopy( value )
125  pass
126 

◆ __str__()

def python.AnaAlgorithmConfig.AnaAlgorithmConfig.__str__ (   self)
Print the algorithm configuration in a user friendly way

This is just to help with debugging configurations, allowing
the user to get a nice printout of their job configuration.

Definition at line 150 of file AnaAlgorithmConfig.py.

150  def __str__( self ):
151  """Print the algorithm configuration in a user friendly way
152 
153  This is just to help with debugging configurations, allowing
154  the user to get a nice printout of their job configuration.
155  """
156 
157  name = ''
158  if self.isPublicTool():
159  name = 'Public Tool %s/%s' % ( self.type(), self.name() )
160  else:
161  name = 'Algorithm %s/%s' % ( self.type(), self.name() )
162  pass
163  result = AnaAlgorithmConfig._printHeader( name )
164  result += '\n'
165  for key, value in sorted( self._props.items() ):
166  if isinstance( value, str ):
167  printedValue = "'%s'" % value
168  else:
169  printedValue = value
170  pass
171  result += "|- %s: %s\n" % ( key, indentBy( printedValue, "| " ) )
172  pass
173  result += AnaAlgorithmConfig._printFooter( name )
174  return result
175 

◆ _printFooter()

def python.AnaAlgorithmConfig.AnaAlgorithmConfig._printFooter (   title)
staticprivate
Produce a nice footer when printing the configuration

This function is used for printing the footer of both algorithms
and tools.

Keyword arguments:
  indentString -- String used as indentation
  title        -- The title of the algorithm/tool

Definition at line 278 of file AnaAlgorithmConfig.py.

278  def _printFooter( title ):
279  """Produce a nice footer when printing the configuration
280 
281  This function is used for printing the footer of both algorithms
282  and tools.
283 
284  Keyword arguments:
285  indentString -- String used as indentation
286  title -- The title of the algorithm/tool
287  """
288 
289  preLength = AnaAlgorithmConfig.printHeaderPre
290  postLength = AnaAlgorithmConfig.printHeaderWidth - 12 - preLength - \
291  len( title )
292  return '\\%s (End of %s) %s' % ( preLength * '-', title,
293  postLength * '-' )
294 

◆ _printHeader()

def python.AnaAlgorithmConfig.AnaAlgorithmConfig._printHeader (   title)
staticprivate
Produce a nice header when printing the configuration

This function is used for printing the header of both algorithms
and tools.

Keyword arguments:
  indentString -- String used as indentation
  title        -- The title of the algorithm/tool

Definition at line 261 of file AnaAlgorithmConfig.py.

261  def _printHeader( title ):
262  """Produce a nice header when printing the configuration
263 
264  This function is used for printing the header of both algorithms
265  and tools.
266 
267  Keyword arguments:
268  indentString -- String used as indentation
269  title -- The title of the algorithm/tool
270  """
271 
272  preLength = AnaAlgorithmConfig.printHeaderPre
273  postLength = AnaAlgorithmConfig.printHeaderWidth - 3 - preLength - \
274  len( title )
275  return '/%s %s %s' % ( preLength * '*', title, postLength * '*' )
276 

◆ addPrivateTool()

def python.AnaAlgorithmConfig.AnaAlgorithmConfig.addPrivateTool (   self,
  name,
  type 
)
Create a private tool for the algorithm

This function is used in 'standalone' mode to declare a private tool
for the algorithm, or a private tool for an already declared private
tool.

Can be used like:
  config.addPrivateTool( 'tool1', 'ToolType1' )
  config.addPrivateTool( 'tool1.tool2', 'ToolType2' )

Keyword arguments:
  name -- The full name of the private tool
  type -- The C++ type of the private tool

Definition at line 176 of file AnaAlgorithmConfig.py.

176  def addPrivateTool( self, name, type ):
177  """Create a private tool for the algorithm
178 
179  This function is used in 'standalone' mode to declare a private tool
180  for the algorithm, or a private tool for an already declared private
181  tool.
182 
183  Can be used like:
184  config.addPrivateTool( 'tool1', 'ToolType1' )
185  config.addPrivateTool( 'tool1.tool2', 'ToolType2' )
186 
187  Keyword arguments:
188  name -- The full name of the private tool
189  type -- The C++ type of the private tool
190  """
191 
192  # And now set up the Python object that will take care of setting
193  # properties on this tool.
194 
195  # Tokenize the tool's name. In case it is a subtool of a tool, or
196  # something possibly even deeper.
197  toolNames = name.split( '.' )
198 
199  # Look up the component that we need to set up the private tool on.
200  component = self
201  for tname in toolNames[ 0 : -1 ]:
202  component = getattr( component, tname )
203  pass
204 
205  # Check that the component doesn't have such a (tool) property yet.
206  if hasattr( component, toolNames[ -1 ] ):
207  raise RuntimeError( "Tool with name '%s' already exists" % name )
208  pass
209 
210  # Now set up a smart object as a property on that component.
211  component._props[ toolNames[ -1 ] ] = PrivateToolConfig( self, name,
212  type )
213 
214  # Finally, tell the C++ code what to do.
215  self.createPrivateTool( name, type ).ignore()
216 
217  pass
218 

◆ addPrivateToolInArray()

def python.AnaAlgorithmConfig.AnaAlgorithmConfig.addPrivateToolInArray (   self,
  name,
  type 
)
Create a private tool in an array for the algorithm

This function is used in 'standalone' mode to declare a
private tool in a tool array for the algorithm, or a private
tool in a tool array for an already declared private tool.

Can be used like:
  tool = config.addPrivateToolInArray( 'tool1', 'ToolType1' )
  tool = config.addPrivateToolInArray( 'tool1.tool2', 'ToolType2' )

Keyword arguments:
  name -- The full name of the private tool
  type -- The C++ type of the private tool

Definition at line 219 of file AnaAlgorithmConfig.py.

219  def addPrivateToolInArray( self, name, type ):
220  """Create a private tool in an array for the algorithm
221 
222  This function is used in 'standalone' mode to declare a
223  private tool in a tool array for the algorithm, or a private
224  tool in a tool array for an already declared private tool.
225 
226  Can be used like:
227  tool = config.addPrivateToolInArray( 'tool1', 'ToolType1' )
228  tool = config.addPrivateToolInArray( 'tool1.tool2', 'ToolType2' )
229 
230  Keyword arguments:
231  name -- The full name of the private tool
232  type -- The C++ type of the private tool
233  """
234 
235  # And now set up the Python object that will take care of setting
236  # properties on this tool.
237 
238  # Tokenize the tool's name. In case it is a subtool of a tool, or
239  # something possibly even deeper.
240  toolNames = name.split( '.' )
241 
242  # Look up the component that we need to set up the private tool on.
243  component = self
244  for tname in toolNames[ 0 : -1 ]:
245  component = getattr( component, tname )
246  pass
247 
248  # Finally, tell the C++ code what to do.
249  actualName = self.createPrivateToolInArray( name, type )
250 
251  # Tokenize the actual tool's name. In case it is a subtool of
252  # a tool, or something possibly even deeper.
253  actualToolNames = actualName.split( '.' )
254 
255  # Now set up a smart object as a property on that component.
256  config = PrivateToolConfig( self, actualName, type )
257  component._props[ actualToolNames[ -1 ] ] = config
258  return config
259 

◆ getName()

def python.AnaAlgorithmConfig.AnaAlgorithmConfig.getName (   self)
Get the instance name of the algorithm

This is for compatibility with the getName() function of Athena
configurables.

Definition at line 64 of file AnaAlgorithmConfig.py.

64  def getName( self ):
65  """Get the instance name of the algorithm
66 
67  This is for compatibility with the getName() function of Athena
68  configurables.
69  """
70 
71  return self.name()
72 

◆ getType()

def python.AnaAlgorithmConfig.AnaAlgorithmConfig.getType (   self)
Get the type name of the algorithm

This is for compatibility with the getType() function of Athena
configurables.

Definition at line 73 of file AnaAlgorithmConfig.py.

73  def getType( self ):
74  """Get the type name of the algorithm
75 
76  This is for compatibility with the getType() function of Athena
77  configurables.
78  """
79 
80  return self.type()
81 

Member Data Documentation

◆ _props

python.AnaAlgorithmConfig.AnaAlgorithmConfig._props
private

Definition at line 54 of file AnaAlgorithmConfig.py.

◆ printHeaderPre

int python.AnaAlgorithmConfig.AnaAlgorithmConfig.printHeaderPre = 3
static

Definition at line 34 of file AnaAlgorithmConfig.py.

◆ printHeaderWidth

int python.AnaAlgorithmConfig.AnaAlgorithmConfig.printHeaderWidth = 80
static

Definition at line 33 of file AnaAlgorithmConfig.py.


The documentation for this class was generated from the following file:
python.DualUseConfig.addPrivateTool
def addPrivateTool(alg, toolName, typeName)
Definition: DualUseConfig.py:180
python.DualUseConfig.addPrivateToolInArray
def addPrivateToolInArray(alg, toolName, typeName)
Definition: DualUseConfig.py:229
DiTauMassTools::ignore
void ignore(T &&)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:54
python.AnaAlgorithmConfig.indentBy
def indentBy(propValue, indent)
Definition: AnaAlgorithmConfig.py:401
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
python.AnaAlgorithmConfig.stringPropValue
def stringPropValue(value)
Definition: AnaAlgorithmConfig.py:391
python.PyAthenaComps.__setattr__
__setattr__
Definition: PyAthenaComps.py:41
Ringer::getType
T getType(const char *cStr)
Return Ringer enumeration of type T identifying string type: