ATLAS Offline Software
parameter.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 import collections
4 
5 
7  """! Class to store information about a single Powheg parameter.
8 
9  @author James Robinson <james.robinson@cern.ch>
10  """
11 
12  def __init__(self, keyword=None, name=None, value=None, description=None, frozen=False, hidden=False, needs_processing=False):
13  """! Initialise a parameter object.
14 
15  @param keyword Powheg keyword.
16  @param name User-visible name.
17  @param value Current value.
18  @param description Human-readable description string.
19  @param frozen True if this parameter cannot be changed.
20  @param hidden True if this parameter should be hidden from the user.
21  @param needs_processing True if this parameter needs further processing.
22  """
23  self.__keyword = keyword
24  self.__name = name
25  self.__description = description
26  self.__value = value
27  self.__default_value = None
28  self.__frozen = frozen
29  self.__hidden = hidden
30  self.__needs_processing = needs_processing
31 
32  def __str__(self):
33  """! String representation."""
34  current_value = [self.value, "'{}'".format(self.value)][any(x in self.name for x in ("lhrwgt", "rwl_file"))] # some parameters need to be in quotes
35  pwg_cmd = "{} {}".format(self.keyword, self.__single_element(current_value)) # construct command for PowhegBox
36  return "{:<40}! [ATLAS default: {}] {}".format(pwg_cmd, self.default_value, self.description)
37 
38  def ensure_default(self):
39  """! Ensure that default value exists."""
40  if self.__default_value is None:
41  self.__default_value = self.value
42 
43  def __single_element(self, to_check):
44  """! Return the first element if input is a list, or the input otherwise.
45 
46  @param to_check An iterable or non-iterable parameter
47  """
48  if isinstance(to_check, collections.abc.Iterable) and not isinstance(to_check, str) and len(to_check) > 0:
49  return to_check[0]
50  return to_check
51 
52  def freeze(self):
53  """! Freeze this parameter so that it cannot be changed."""
54  self.__frozen = True
55 
56  @property
57  def keyword(self):
58  """! Retrieve the Powheg keyword."""
59  return self.__keyword
60 
61  @property
62  def name(self):
63  """! Retrieve the user-visible name."""
64  return self.__name
65 
66  @property
67  def needs_processing(self):
68  """! Indicator that this parameter needs further processing."""
69  return self.__needs_processing
70 
71  @property
72  def value(self):
73  """! Retrieve the current value of this parameter."""
74  return self.__value
75 
76  @property
77  def default_value(self):
78  """! Retrieve the default value of this parameter (if it exists)."""
79  if self.__default_value is None:
80  return self.value
81  return self.__default_value
82 
83  @property
84  def description(self):
85  """! Retrieve the human-readable description string."""
86  return self.__description
87 
88  @property
89  def is_frozen(self):
90  """! Boolean indicating whether this parameter can be changed."""
91  return self.__frozen
92 
93  @property
94  def is_hidden(self):
95  """! Boolean indicating whether this parameter is visible to the user."""
96  return self.__hidden
97 
98  @property
99  def is_visible(self):
100  """! Boolean indicating whether this parameter should be hidden from the user."""
101  return not (self.__frozen or self.__hidden)
102 
103  @value.setter
104  def value(self, value):
105  """! Set the value of this parameter (if it is not frozen)."""
106  if self.__frozen:
107  raise AttributeError("Parameter {} cannot be changed in jobOptions.".format(self.name))
108  else:
109  self.__value = value
vtune_athena.format
format
Definition: vtune_athena.py:14
python.parameters.parameter.Parameter.needs_processing
def needs_processing(self)
Indicator that this parameter needs further processing.
Definition: parameter.py:67
python.parameters.parameter.Parameter.__init__
def __init__(self, keyword=None, name=None, value=None, description=None, frozen=False, hidden=False, needs_processing=False)
Initialise a parameter object.
Definition: parameter.py:12
python.parameters.parameter.Parameter.__str__
def __str__(self)
String representation.
Definition: parameter.py:32
python.parameters.parameter.Parameter.freeze
def freeze(self)
Freeze this parameter so that it cannot be changed.
Definition: parameter.py:52
python.parameters.parameter.Parameter.__hidden
__hidden
Definition: parameter.py:29
python.parameters.parameter.Parameter.__keyword
__keyword
Definition: parameter.py:23
python.parameters.parameter.Parameter.__needs_processing
__needs_processing
Definition: parameter.py:30
python.parameters.parameter.Parameter.ensure_default
def ensure_default(self)
Ensure that default value exists.
Definition: parameter.py:38
python.parameters.parameter.Parameter.__single_element
def __single_element(self, to_check)
Return the first element if input is a list, or the input otherwise.
Definition: parameter.py:43
python.parameters.parameter.Parameter.__value
__value
Definition: parameter.py:26
python.parameters.parameter.Parameter.description
def description(self)
Retrieve the human-readable description string.
Definition: parameter.py:84
python.parameters.parameter.Parameter.value
def value(self)
Retrieve the current value of this parameter.
Definition: parameter.py:72
python.parameters.parameter.Parameter.default_value
def default_value(self)
Retrieve the default value of this parameter (if it exists).
Definition: parameter.py:77
python.parameters.parameter.Parameter.keyword
def keyword(self)
Retrieve the Powheg keyword.
Definition: parameter.py:57
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.parameters.parameter.Parameter.__frozen
__frozen
Definition: parameter.py:28
python.parameters.parameter.Parameter.is_frozen
def is_frozen(self)
Boolean indicating whether this parameter can be changed.
Definition: parameter.py:89
python.parameters.parameter.Parameter.__description
__description
Definition: parameter.py:25
python.parameters.parameter.Parameter.name
def name(self)
Retrieve the user-visible name.
Definition: parameter.py:62
python.parameters.parameter.Parameter.__name
__name
Definition: parameter.py:24
python.parameters.parameter.Parameter.is_hidden
def is_hidden(self)
Boolean indicating whether this parameter is visible to the user.
Definition: parameter.py:94
python.parameters.parameter.Parameter.is_visible
def is_visible(self)
Boolean indicating whether this parameter should be hidden from the user.
Definition: parameter.py:99
python.parameters.parameter.Parameter.__default_value
__default_value
Definition: parameter.py:27