Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions | Static Public Attributes | Private Attributes | List of all members
python.ConfigBlock.ConfigBlock Class Reference
Collaboration diagram for python.ConfigBlock.ConfigBlock:

Public Member Functions

def __init__ (self)
 
def setBlockName (self, name)
 
def getBlockName (self)
 
def addDependency (self, dependencyName, required=True)
 
def hasDependencies (self)
 
def getDependencies (self)
 
def addOption (self, name, defaultValue, *type, info='', noneAction='ignore', required=False)
 
def setOptionValue (self, name, value)
 
def getOptionValue (self, name)
 
def getOptions (self)
 
def printOptions (self, verbose=False, width=60, indent=" ")
 
def hasOption (self, name)
 
def __eq__ (self, blockName)
 
def __str__ (self)
 
def get_instance_count (cls)
 

Static Public Attributes

dictionary instance_counts = {}
 

Private Attributes

 _blockName
 
 _dependencies
 
 _options
 

Detailed Description

the base class for classes implementing individual blocks of
configuration

A configuration block is a sequence of one or more algorithms that
should always be scheduled together, e.g. the muon four momentum
corrections could be a single block, muon selection could then be
another block.  The blocks themselves generally have their own
configuration options/properties specific to the block, and will
perform a dynamic configuration based on those options as well as
the overall job.

The actual configuration of the algorithms in the block will
depend on what other blocks are scheduled before and afterwards,
most importantly some algorithms will introduce shallow copies
that subsequent algorithms will need to run on, and some
algorithms will add selection decorations that subquent algorithms
should use as preselections.

The algorithms get created in a multi-step process (that may be
extended in the future): As a first step each block retrieves
references to the containers it uses (essentially marking its spot
in the processing chain) and also registering any shallow copies
that will be made.  In the second/last step each block then
creates the fully configured algorithms.

One goal is that when the algorithms get created they will have
their final configuration and there needs to be no
meta-configuration data attached to the algorithms, essentially an
inversion of the approach in AnaAlgSequence in which the
algorithms got created first with associated meta-configuration
and then get modified in susequent configuration steps.

For now this is mostly an empty base class, but another goal of
this approach is to make it easier to build another configuration
layer on top of this one, and this class will likely be extended
and get data members at that point.

The child class needs to implement two methods,
`collectReferences` and `makeAlgs` which are each given a single
`ConfigAccumulator` type argument.  The first is for the first
configuration step, and should only collect references to the
containers to be used.  The second is for the second configuration
step, and should create the actual algorithms.

Definition at line 43 of file ConfigBlock.py.

Constructor & Destructor Documentation

◆ __init__()

def python.ConfigBlock.ConfigBlock.__init__ (   self)

Definition at line 93 of file ConfigBlock.py.

93  def __init__ (self) :
94  self._blockName = ''
95  self._dependencies = []
96  self._options = {}
97  # used with block configuration to set arbitrary option
98  self.addOption('groupName', '', type=str,
99  info=('Used to specify this block when setting an'
100  ' option at an arbitrary location.'))
101  self.addOption('skipOnData', False, type=bool,
102  info=('User option to prevent the block from running'
103  ' on data. This only affects blocks that are'
104  ' intended to run on data.'))
105  self.addOption('skipOnMC', False, type=bool,
106  info=('User option to prevent the block from running'
107  ' on MC. This only affects blocks that are'
108  ' intended to run on MC.'))
109  self.addOption('onlyForDSIDs', [], type=list,
110  info=('Used to specify which MC DSIDs to allow this'
111  ' block to run on. Each element of the list'
112  ' can be a full DSID (e.g. 410470), or a regex'
113  ' (e.g. 410.* to select all 410xxx DSIDs, or'
114  ' ^(?!410) to veto them). An empty list means no'
115  ' DSID restriction.'))
116  # Increment the instance count for the current class
117  cls = type(self) # Get the actual class of the instance (also derived!)
118  if cls not in ConfigBlock.instance_counts:
119  ConfigBlock.instance_counts[cls] = 0
120  # Note: we do need to check in the call stack that we are
121  # in a real makeConfig situation, and not e.g. printAlgs
122  stack = inspect.stack()
123  for frame_info in stack:
124  # Get the class name (if any) from the frame
125  parent_cls = frame_info.frame.f_locals.get('self', None)
126  if parent_cls is None or not isinstance(parent_cls, ConfigBlock):
127  # If the frame does not belong to an instance of ConfigBlock, it's an external caller
128  if frame_info.function == "makeConfig":
129  ConfigBlock.instance_counts[cls] += 1
130  break
131 
132 

Member Function Documentation

◆ __eq__()

def python.ConfigBlock.ConfigBlock.__eq__ (   self,
  blockName 
)
Implementation of == operator. Used for seaching configSeque.
E.g. if blockName in configSeq:

Definition at line 257 of file ConfigBlock.py.

257  def __eq__(self, blockName):
258  """
259  Implementation of == operator. Used for seaching configSeque.
260  E.g. if blockName in configSeq:
261  """
262  return self._blockName == blockName
263 
264 

◆ __str__()

def python.ConfigBlock.ConfigBlock.__str__ (   self)

Definition at line 265 of file ConfigBlock.py.

265  def __str__(self):
266  return self._blockName
267 
268 

◆ addDependency()

def python.ConfigBlock.ConfigBlock.addDependency (   self,
  dependencyName,
  required = True 
)
Add a dependency for the block. Dependency is corresponds to the
blockName of another block. If required is True, will throw an
error if dependency is not present; otherwise will move this
block after the required block. If required is False, will do
nothing if required block is not present; otherwise, it will
move block after required block.

Definition at line 141 of file ConfigBlock.py.

141  def addDependency(self, dependencyName, required=True):
142  """
143  Add a dependency for the block. Dependency is corresponds to the
144  blockName of another block. If required is True, will throw an
145  error if dependency is not present; otherwise will move this
146  block after the required block. If required is False, will do
147  nothing if required block is not present; otherwise, it will
148  move block after required block.
149  """
150  if not self.hasDependencies():
151  # add option to block ignore dependencies
152  self.addOption('ignoreDependencies', [], type=list,
153  info='List of dependencies defined in the ConfigBlock to ignore.')
154  self._dependencies.append(ConfigBlockDependency(dependencyName, required))
155 

◆ addOption()

def python.ConfigBlock.ConfigBlock.addOption (   self,
  name,
  defaultValue,
type,
  info = '',
  noneAction = 'ignore',
  required = False 
)
declare the given option on the configuration block

This should only be called in the constructor of the
configuration block.

NOTE: The backend to option handling is slated to be replaced
at some point.  This particular function should essentially
stay the same, but some behavior may change.

Definition at line 164 of file ConfigBlock.py.

164  def addOption (self, name, defaultValue, *,
165  type, info='', noneAction='ignore', required=False) :
166  """declare the given option on the configuration block
167 
168  This should only be called in the constructor of the
169  configuration block.
170 
171  NOTE: The backend to option handling is slated to be replaced
172  at some point. This particular function should essentially
173  stay the same, but some behavior may change.
174  """
175  if name in self._options :
176  raise KeyError (f'duplicate option: {name}')
177  if type not in [str, bool, int, float, list, None] :
178  raise TypeError (f'unknown option type: {type}')
179  noneActions = ['error', 'set', 'ignore']
180  if noneAction not in noneActions :
181  raise ValueError (f'invalid noneAction: {noneAction} [allowed values: {noneActions}]')
182  setattr (self, name, defaultValue)
183  self._options[name] = ConfigBlockOption(type=type, info=info,
184  noneAction=noneAction, required=required, default=defaultValue)
185 
186 

◆ get_instance_count()

def python.ConfigBlock.ConfigBlock.get_instance_count (   cls)

Definition at line 270 of file ConfigBlock.py.

270  def get_instance_count(cls):
271  # Access the current count for this class
272  return ConfigBlock.instance_counts.get(cls, 0)

◆ getBlockName()

def python.ConfigBlock.ConfigBlock.getBlockName (   self)
Get blockName

Definition at line 137 of file ConfigBlock.py.

137  def getBlockName(self):
138  """Get blockName"""
139  return self._blockName
140 

◆ getDependencies()

def python.ConfigBlock.ConfigBlock.getDependencies (   self)
Return the list of dependencies. 

Definition at line 160 of file ConfigBlock.py.

160  def getDependencies(self):
161  """Return the list of dependencies. """
162  return self._dependencies
163 

◆ getOptions()

def python.ConfigBlock.ConfigBlock.getOptions (   self)
Return a copy of the options associated with the block

Definition at line 220 of file ConfigBlock.py.

220  def getOptions(self):
221  """Return a copy of the options associated with the block"""
222  return self._options.copy()
223 
224 

◆ getOptionValue()

def python.ConfigBlock.ConfigBlock.getOptionValue (   self,
  name 
)
Returns config option value, if present; otherwise return None

Definition at line 214 of file ConfigBlock.py.

214  def getOptionValue(self, name):
215  """Returns config option value, if present; otherwise return None"""
216  if name in self._options:
217  return getattr(self, name)
218 
219 

◆ hasDependencies()

def python.ConfigBlock.ConfigBlock.hasDependencies (   self)
Return True if there is a dependency.

Definition at line 156 of file ConfigBlock.py.

156  def hasDependencies(self):
157  """Return True if there is a dependency."""
158  return bool(self._dependencies)
159 

◆ hasOption()

def python.ConfigBlock.ConfigBlock.hasOption (   self,
  name 
)
whether the configuration block has the given option

WARNING: The backend to option handling is slated to be
replaced at some point.  This particular function may change
behavior, interface or be removed/replaced entirely.

Definition at line 247 of file ConfigBlock.py.

247  def hasOption (self, name) :
248  """whether the configuration block has the given option
249 
250  WARNING: The backend to option handling is slated to be
251  replaced at some point. This particular function may change
252  behavior, interface or be removed/replaced entirely.
253  """
254  return name in self._options
255 
256 

◆ printOptions()

def python.ConfigBlock.ConfigBlock.printOptions (   self,
  verbose = False,
  width = 60,
  indent = "    " 
)
Prints options and their values

Definition at line 225 of file ConfigBlock.py.

225  def printOptions(self, verbose=False, width=60, indent=" "):
226  """
227  Prints options and their values
228  """
229  def printWrap(text, width=60, indent=" "):
230  wrapper = textwrap.TextWrapper(width=width, initial_indent=indent,
231  subsequent_indent=indent)
232  for line in wrapper.wrap(text=text):
233  logCPAlgCfgBlock.info(line)
234 
235  for opt, vals in self.getOptions().items():
236  if verbose:
237  logCPAlgCfgBlock.info(indent + f"\033[4m{opt}\033[0m: {self.getOptionValue(opt)}")
238  logCPAlgCfgBlock.info(indent*2 + f"\033[4mtype\033[0m: {vals.type}")
239  logCPAlgCfgBlock.info(indent*2 + f"\033[4mdefault\033[0m: {vals.default}")
240  logCPAlgCfgBlock.info(indent*2 + f"\033[4mrequired\033[0m: {vals.required}")
241  logCPAlgCfgBlock.info(indent*2 + f"\033[4mnoneAction\033[0m: {vals.noneAction}")
242  printWrap(f"\033[4minfo\033[0m: {vals.info}", indent=indent*2)
243  else:
244  logCPAlgCfgBlock.info(indent + f"{ opt}: {self.getOptionValue(opt)}")
245 
246 

◆ setBlockName()

def python.ConfigBlock.ConfigBlock.setBlockName (   self,
  name 
)
Set blockName

Definition at line 133 of file ConfigBlock.py.

133  def setBlockName(self, name):
134  """Set blockName"""
135  self._blockName = name
136 

◆ setOptionValue()

def python.ConfigBlock.ConfigBlock.setOptionValue (   self,
  name,
  value 
)
set the given option on the configuration block

NOTE: The backend to option handling is slated to be replaced
at some point.  This particular function should essentially
stay the same, but some behavior may change.

Definition at line 187 of file ConfigBlock.py.

187  def setOptionValue (self, name, value) :
188  """set the given option on the configuration block
189 
190  NOTE: The backend to option handling is slated to be replaced
191  at some point. This particular function should essentially
192  stay the same, but some behavior may change.
193  """
194 
195  if name not in self._options :
196  raise KeyError (f'unknown option "{name}" in block "{self.__class__.__name__}"')
197  noneAction = self._options[name].noneAction
198  if value is not None or noneAction == 'set' :
199  # check type if specified
200  optType = self._options[name].type
201  # convert int to float to prevent crash
202  if optType is float and type(value) is int:
203  value = float(value)
204  if optType is not None and optType != type(value):
205  raise ValueError(f'{name} for block {self.__class__.__name__} should '
206  f'be of type {optType} not {type(value)}')
207  setattr (self, name, value)
208  elif noneAction == 'ignore' :
209  pass
210  elif noneAction == 'error' :
211  raise ValueError (f'passed None for setting option {name} with noneAction=error')
212 
213 

Member Data Documentation

◆ _blockName

python.ConfigBlock.ConfigBlock._blockName
private

Definition at line 94 of file ConfigBlock.py.

◆ _dependencies

python.ConfigBlock.ConfigBlock._dependencies
private

Definition at line 95 of file ConfigBlock.py.

◆ _options

python.ConfigBlock.ConfigBlock._options
private

Definition at line 96 of file ConfigBlock.py.

◆ instance_counts

dictionary python.ConfigBlock.ConfigBlock.instance_counts = {}
static

Definition at line 91 of file ConfigBlock.py.


The documentation for this class was generated from the following file:
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
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.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
calibdata.copy
bool copy
Definition: calibdata.py:27
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
FlavorTagDiscriminants::getOptions
GNNOptions getOptions(const GNNToolProperties &)
Definition: GNNToolifiers.cxx:24
readCCLHist.float
float
Definition: readCCLHist.py:83