ATLAS Offline Software
Public Member Functions | 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, name)
 
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)
 

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 42 of file ConfigBlock.py.

Constructor & Destructor Documentation

◆ __init__()

def python.ConfigBlock.ConfigBlock.__init__ (   self)

Definition at line 89 of file ConfigBlock.py.

89  def __init__ (self) :
90  self._blockName = ''
91  self._dependencies = []
92  self._options = {}
93  # used with block configuration to set arbitrary option
94  self.addOption('groupName', '', type=str,
95  info=('Used to specify this block when setting an'
96  ' option at an arbitrary location.'))
97  self.addOption('skipOnData', False, type=bool,
98  info=('User option to prevent the block from running'
99  ' on data. This only affects blocks that are'
100  ' intended to run on data.'))
101  self.addOption('skipOnMC', False, type=bool,
102  info=('User option to prevent the block from running'
103  ' on MC. This only affects blocks that are'
104  ' intended to run on MC.'))
105  self.addOption('onlyForDSIDs', [], type=list,
106  info=('Used to specify which MC DSIDs to allow this'
107  ' block to run on. Each element of the list'
108  ' can be a full DSID (e.g. 410470), or a regex'
109  ' (e.g. 410.* to select all 410xxx DSIDs, or'
110  ' ^(?!410) to veto them). An empty list means no'
111  ' DSID restriction.'))
112 
113 

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 238 of file ConfigBlock.py.

238  def __eq__(self, blockName):
239  """
240  Implementation of == operator. Used for seaching configSeque.
241  E.g. if blockName in configSeq:
242  """
243  return self._blockName == blockName
244 
245 

◆ __str__()

def python.ConfigBlock.ConfigBlock.__str__ (   self)

Definition at line 246 of file ConfigBlock.py.

246  def __str__(self):
247  return self._blockName

◆ 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 122 of file ConfigBlock.py.

122  def addDependency(self, dependencyName, required=True):
123  """
124  Add a dependency for the block. Dependency is corresponds to the
125  blockName of another block. If required is True, will throw an
126  error if dependency is not present; otherwise will move this
127  block after the required block. If required is False, will do
128  nothing if required block is not present; otherwise, it will
129  move block after required block.
130  """
131  if not self.hasDependencies():
132  # add option to block ignore dependencies
133  self.addOption('ignoreDependencies', [], type=list,
134  info='List of dependencies defined in the ConfigBlock to ignore.')
135  self._dependencies.append(ConfigBlockDependency(dependencyName, required))
136 

◆ 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 145 of file ConfigBlock.py.

145  def addOption (self, name, defaultValue, *,
146  type, info='', noneAction='ignore', required=False) :
147  """declare the given option on the configuration block
148 
149  This should only be called in the constructor of the
150  configuration block.
151 
152  NOTE: The backend to option handling is slated to be replaced
153  at some point. This particular function should essentially
154  stay the same, but some behavior may change.
155  """
156  if name in self._options :
157  raise KeyError (f'duplicate option: {name}')
158  if type not in [str, bool, int, float, list, None] :
159  raise TypeError (f'unknown option type: {type}')
160  noneActions = ['error', 'set', 'ignore']
161  if noneAction not in noneActions :
162  raise ValueError (f'invalid noneAction: {noneAction} [allowed values: {noneActions}]')
163  setattr (self, name, defaultValue)
164  self._options[name] = ConfigBlockOption(type=type, info=info,
165  noneAction=noneAction, required=required, default=defaultValue)
166 
167 

◆ getBlockName()

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

Definition at line 118 of file ConfigBlock.py.

118  def getBlockName(self, name):
119  """Get blockName"""
120  return self._blockName
121 

◆ getDependencies()

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

Definition at line 141 of file ConfigBlock.py.

141  def getDependencies(self):
142  """Return the list of dependencies. """
143  return self._dependencies
144 

◆ getOptions()

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

Definition at line 201 of file ConfigBlock.py.

201  def getOptions(self):
202  """Return a copy of the options associated with the block"""
203  return self._options.copy()
204 
205 

◆ getOptionValue()

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

Definition at line 195 of file ConfigBlock.py.

195  def getOptionValue(self, name):
196  """Returns config option value, if present; otherwise return None"""
197  if name in self._options:
198  return getattr(self, name)
199 
200 

◆ hasDependencies()

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

Definition at line 137 of file ConfigBlock.py.

137  def hasDependencies(self):
138  """Return True if there is a dependency."""
139  return bool(self._dependencies)
140 

◆ 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 228 of file ConfigBlock.py.

228  def hasOption (self, name) :
229  """whether the configuration block has the given option
230 
231  WARNING: The backend to option handling is slated to be
232  replaced at some point. This particular function may change
233  behavior, interface or be removed/replaced entirely.
234  """
235  return name in self._options
236 
237 

◆ printOptions()

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

Definition at line 206 of file ConfigBlock.py.

206  def printOptions(self, verbose=False, width=60, indent=" "):
207  """
208  Prints options and their values
209  """
210  def printWrap(text, width=60, indent=" "):
211  wrapper = textwrap.TextWrapper(width=width, initial_indent=indent,
212  subsequent_indent=indent)
213  for line in wrapper.wrap(text=text):
214  logCPAlgCfgBlock.info(line)
215 
216  for opt, vals in self.getOptions().items():
217  if verbose:
218  logCPAlgCfgBlock.info(indent + f"\033[4m{opt}\033[0m: {self.getOptionValue(opt)}")
219  logCPAlgCfgBlock.info(indent*2 + f"\033[4mtype\033[0m: {vals.type}")
220  logCPAlgCfgBlock.info(indent*2 + f"\033[4mdefault\033[0m: {vals.default}")
221  logCPAlgCfgBlock.info(indent*2 + f"\033[4mrequired\033[0m: {vals.required}")
222  logCPAlgCfgBlock.info(indent*2 + f"\033[4mnoneAction\033[0m: {vals.noneAction}")
223  printWrap(f"\033[4minfo\033[0m: {vals.info}", indent=indent*2)
224  else:
225  logCPAlgCfgBlock.info(indent + f"{ opt}: {self.getOptionValue(opt)}")
226 
227 

◆ setBlockName()

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

Definition at line 114 of file ConfigBlock.py.

114  def setBlockName(self, name):
115  """Set blockName"""
116  self._blockName = name
117 

◆ 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 168 of file ConfigBlock.py.

168  def setOptionValue (self, name, value) :
169  """set the given option on the 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 
176  if name not in self._options :
177  raise KeyError (f'unknown option "{name}" in block "{self.__class__.__name__}"')
178  noneAction = self._options[name].noneAction
179  if value is not None or noneAction == 'set' :
180  # check type if specified
181  optType = self._options[name].type
182  # convert int to float to prevent crash
183  if optType is float and type(value) is int:
184  value = float(value)
185  if optType is not None and optType != type(value):
186  raise ValueError(f'{name} for block {self.__class__.__name__} should '
187  f'be of type {optType} not {type(value)}')
188  setattr (self, name, value)
189  elif noneAction == 'ignore' :
190  pass
191  elif noneAction == 'error' :
192  raise ValueError (f'passed None for setting option {name} with noneAction=error')
193 
194 

Member Data Documentation

◆ _blockName

python.ConfigBlock.ConfigBlock._blockName
private

Definition at line 90 of file ConfigBlock.py.

◆ _dependencies

python.ConfigBlock.ConfigBlock._dependencies
private

Definition at line 91 of file ConfigBlock.py.

◆ _options

python.ConfigBlock.ConfigBlock._options
private

Definition at line 92 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