ATLAS Offline Software
configurable.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaCommon import Logging
4 from ..parameters import Parameter, Registry
5 
6 
7 logger = Logging.logging.getLogger("PowhegControl")
8 
9 
11  """! Class for any process which can be configured.
12 
13  @author James Robinson <james.robinson@cern.ch>
14  """
15 
16  def __init__(self):
17  """! Constructor."""
18 
19  self.parameters = []
20 
21  def add_keyword(self, keyword, value=None, name=None, frozen=None, hidden=None, description=None, **kwargs):
22  """! Register configurable parameter that is exposed to the user.
23 
24  @param keyword Powheg keyword that gets written to the runcard.
25  @param value Value of the parameter.
26  @param name Configurable parameter name exposed to the user.
27  @param hidden True if this parameter should be hidden from the user.
28  @param frozen True if this parameter cannot be changed.
29  @param description Description for the run card.
30  @param parameter Name used in the run card if different.
31  """
32  # Retrieve default settings from registry overriding if requested
33  defaults = Registry().get_defaults(keyword)
34  if value == defaults["value"] and value is not None and (hidden is not True):
35  if keyword not in ["ebeam1", "ebeam2"]:
36  logger.debug("Unnecessarily setting parameter {} to {} which is its default value!".format(keyword, value))
37  value = [value, defaults["value"]][value is None]
38  name = [name, defaults["name"]][name is None]
39  description = [description, defaults["description"]][description is None]
40  hidden = [hidden, defaults["hidden"]][hidden is None]
41  frozen = [frozen, defaults["frozen"]][frozen is None]
42  if keyword in [p.keyword for p in self.parameters]:
43  raise AttributeError("Keyword '{}' has already been defined for this process".format(keyword))
44  self.parameters.append(Parameter(keyword, name=name, value=value, frozen=frozen, hidden=hidden, description=description, **kwargs))
45 
46  def expose(self):
47  """! Add all names to the interface of this object."""
48  for parameter in self.parameters:
49  setattr(self, parameter.name, parameter.value)
50 
51  def has_keyword(self, keyword):
52  return (len(list(self.parameters_by_keyword(keyword))) > 0)
53 
54  def has_parameter(self, parameter):
55  return (len(list(self.parameters_by_name(parameter))) > 0)
56 
57  def parameters_by_keyword(self, keyword):
58  """! Retrieve all parameters that use a given keyword.
59 
60  @param keyword Powheg keyword that gets written to the runcard.
61  """
62  return [p for p in self.parameters if p.keyword == keyword]
63 
64  def parameters_by_name(self, name):
65  """! Retrieve all parameters that use a given name.
66 
67  @param name Configurable parameter name exposed to the user.
68  """
69  return [p for p in self.parameters if p.name == name]
python.processes.configurable.Configurable.expose
def expose(self)
Add all names to the interface of this object.
Definition: configurable.py:46
vtune_athena.format
format
Definition: vtune_athena.py:14
python.processes.configurable.Configurable.parameters_by_name
def parameters_by_name(self, name)
Retrieve all parameters that use a given name.
Definition: configurable.py:64
python.processes.configurable.Configurable.add_keyword
def add_keyword(self, keyword, value=None, name=None, frozen=None, hidden=None, description=None, **kwargs)
Register configurable parameter that is exposed to the user.
Definition: configurable.py:21
python.processes.configurable.Configurable.has_parameter
def has_parameter(self, parameter)
Definition: configurable.py:54
python.processes.configurable.Configurable.__init__
def __init__(self)
Constructor.
Definition: configurable.py:16
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.processes.configurable.Configurable.parameters_by_keyword
def parameters_by_keyword(self, keyword)
Retrieve all parameters that use a given keyword.
Definition: configurable.py:57
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.parameters.registry.Registry
Class to store information about Powheg parameters.
Definition: registry.py:9
pickleTool.object
object
Definition: pickleTool.py:30
python.parameters.parameter.Parameter
Class to store information about a single Powheg parameter.
Definition: parameter.py:6
python.processes.configurable.Configurable.has_keyword
def has_keyword(self, keyword)
Definition: configurable.py:51
python.processes.configurable.Configurable.parameters
parameters
List of available parameters.
Definition: configurable.py:19
python.processes.configurable.Configurable
Class for any process which can be configured.
Definition: configurable.py:10