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

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)
 

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 Service Configuration

This class is used to describe the configuration of an analysis service
(a C++ class inheriting from asg::AsgService) 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.asg.Job()
   ...
   from AsgServices.AsgServiceConfig import AsgServiceConfig
   service = AsgServiceConfig( "asg::UnitTestService1/TestService",
                             property = 1.23 )
   service.string_property = "Foo"
   job.servicesAdd( service )

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

Definition at line 17 of file AsgServiceConfig.py.

Constructor & Destructor Documentation

◆ __init__()

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

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

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

   service = AsgServiceConfig( "asg::UnitTestService1/TestService",
                     property = 1.23 )

Definition at line 45 of file AsgServiceConfig.py.

45  def __init__( self, typeAndName, **kwargs ):
46  """Constructor for an service configuration object
47 
48  Keyword arguments:
49  typeAndName -- The type/instance name of the service
50 
51  Note that you can pass (initial) properties to the constructor like:
52 
53  service = AsgServiceConfig( "asg::UnitTestService1/TestService",
54  property = 1.23 )
55  """
56 
57  # Call the base class's constructor. Use the default constructor instead
58  # of the one receiving the type and name, to avoid ROOT-10872.
59  super( AsgServiceConfig, self ).__init__()
60  self.setTypeAndName( typeAndName )
61 
62  # Initialise the properties of the service:
63  self._props = {}
64 
65  # Set the properties on the object:
66  for key, value in kwargs.items():
67  self.setPropertyFromString( key, stringPropValue( value ) )
68  self._props[ key ] = copy.deepcopy( value )
69  pass
70 
71  pass
72 

Member Function Documentation

◆ __eq__()

def python.AsgServiceConfig.AsgServiceConfig.__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 services would match.

Definition at line 136 of file AsgServiceConfig.py.

136  def __eq__( self, other ):
137  """Check for equality with another object
138 
139  The implementation of this is very simple. We only check that the type
140  and the name of the services would match.
141  """
142 
143  # First check that the other object is also an AsgServiceConfig one:
144  if not isinstance( other, AsgServiceConfig ):
145  return False
146 
147  # Now check whether the type and the name of the services agree:
148  return ( ( self.type() == other.type() ) and
149  ( self.name() == other.name() ) )
150 

◆ __getattr__()

def python.AsgServiceConfig.AsgServiceConfig.__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 service, to possibly use it in some configuration
decisions in the Python code itself.

Keyword arguments:
  name -- The name of the property

Definition at line 91 of file AsgServiceConfig.py.

91  def __getattr__( self, name ):
92  """Get a previously set property value from the configuration
93 
94  This function allows us to retrieve the value of a property that was
95  already set for the service, to possibly use it in some configuration
96  decisions in the Python code itself.
97 
98  Keyword arguments:
99  name -- The name of the property
100  """
101 
102  # Fail if the property was not (yet) set:
103  if not name in self._props:
104  raise AttributeError( 'Property \'%s\' was not set on \'%s/%s\'' %
105  ( name, self.type(), self.name() ) )
106 
107  # Return the property value:
108  return self._props[ name ]
109 

◆ __ne__()

def python.AsgServiceConfig.AsgServiceConfig.__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 151 of file AsgServiceConfig.py.

151  def __ne__( self, other ):
152  """Check for an inequality with another object
153 
154  This is just defined to make the '!=' operator of Python behave
155  consistently with the '==' operator for such objects.
156  """
157  return not self.__eq__( other )
158 

◆ __setattr__()

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

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

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

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

Definition at line 110 of file AsgServiceConfig.py.

110  def __setattr__( self, key, value ):
111  """Set an service property on an existing configuration object
112 
113  This function allows us to set/override properties on an service
114  configuration object. Allowing for the following syntax:
115 
116  service = ...
117  service.IntProperty = 66
118  service.FloatProperty = 3.141592
119  service.StringProperty = "Foo"
120 
121  Keyword arguments:
122  key -- The key/name of the property
123  value -- The value to set for the property
124  """
125 
126  # Private variables should be set directly:
127  if key[ 0 ] == '_':
128  return super( AsgServiceConfig, self ).__setattr__( key, value )
129 
130  # Set the property, and remember its value:
131  super( AsgServiceConfig,
132  self ).setPropertyFromString( key, stringPropValue( value ) )
133  self._props[ key ] = copy.deepcopy( value )
134  pass
135 

◆ __str__()

def python.AsgServiceConfig.AsgServiceConfig.__str__ (   self)
Print the service 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 159 of file AsgServiceConfig.py.

159  def __str__( self ):
160  """Print the service configuration in a user friendly way
161 
162  This is just to help with debugging configurations, allowing
163  the user to get a nice printout of their job configuration.
164  """
165 
166  name = 'Service %s/%s' % ( self.type(), self.name() )
167  result = AsgServiceConfig._printHeader( name )
168  result += '\n'
169  for key, value in sorted( self._props.items() ):
170  if isinstance( value, str ):
171  printedValue = "'%s'" % value
172  else:
173  printedValue = value
174  pass
175  result += "|- %s: %s\n" % ( key, indentBy( printedValue, "| " ) )
176  pass
177  result += AsgServiceConfig._printFooter( name )
178  return result
179 

◆ _printFooter()

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

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

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

Definition at line 241 of file AsgServiceConfig.py.

241  def _printFooter( title ):
242  """Produce a nice footer when printing the configuration
243 
244  This function is used for printing the footer of both services
245  and tools.
246 
247  Keyword arguments:
248  indentString -- String used as indentation
249  title -- The title of the service/tool
250  """
251 
252  preLength = AsgServiceConfig.printHeaderPre
253  postLength = AsgServiceConfig.printHeaderWidth - 12 - preLength - \
254  len( title )
255  return '\\%s (End of %s) %s' % ( preLength * '-', title,
256  postLength * '-' )
257 

◆ _printHeader()

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

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

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

Definition at line 224 of file AsgServiceConfig.py.

224  def _printHeader( title ):
225  """Produce a nice header when printing the configuration
226 
227  This function is used for printing the header of both services
228  and tools.
229 
230  Keyword arguments:
231  indentString -- String used as indentation
232  title -- The title of the service/tool
233  """
234 
235  preLength = AsgServiceConfig.printHeaderPre
236  postLength = AsgServiceConfig.printHeaderWidth - 3 - preLength - \
237  len( title )
238  return '/%s %s %s' % ( preLength * '*', title, postLength * '*' )
239 

◆ addPrivateTool()

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

This function is used in 'standalone' mode to declare a private tool
for the service, 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 180 of file AsgServiceConfig.py.

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

◆ getName()

def python.AsgServiceConfig.AsgServiceConfig.getName (   self)
Get the instance name of the service

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

Definition at line 73 of file AsgServiceConfig.py.

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

◆ getType()

def python.AsgServiceConfig.AsgServiceConfig.getType (   self)
Get the type name of the service

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

Definition at line 82 of file AsgServiceConfig.py.

82  def getType( self ):
83  """Get the type name of the service
84 
85  This is for compatibility with the getType() function of Athena
86  configurables.
87  """
88 
89  return self.type()
90 

Member Data Documentation

◆ _props

python.AsgServiceConfig.AsgServiceConfig._props
private

Definition at line 63 of file AsgServiceConfig.py.

◆ printHeaderPre

int python.AsgServiceConfig.AsgServiceConfig.printHeaderPre = 3
static

Definition at line 43 of file AsgServiceConfig.py.

◆ printHeaderWidth

int python.AsgServiceConfig.AsgServiceConfig.printHeaderWidth = 80
static

Definition at line 42 of file AsgServiceConfig.py.


The documentation for this class was generated from the following file:
python.AsgServiceConfig.stringPropValue
def stringPropValue(value)
Definition: AsgServiceConfig.py:354
python.DualUseConfig.addPrivateTool
def addPrivateTool(alg, toolName, typeName)
Definition: DualUseConfig.py:180
dumpTruth.getName
getName
Definition: dumpTruth.py:34
DiTauMassTools::ignore
void ignore(T &&)
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:58
python.AsgServiceConfig.indentBy
def indentBy(propValue, indent)
Definition: AsgServiceConfig.py:364
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.PyAthenaComps.__setattr__
__setattr__
Definition: PyAthenaComps.py:39
Ringer::getType
T getType(const char *cStr)
Return Ringer enumeration of type T identifying string type: