Skip to content

Commit

Permalink
DDSim: ConfigHelper: prevent using unknown properties
Browse files Browse the repository at this point in the history
Everywhere but in Meta, where we want to allow adding arbitrary information
  • Loading branch information
andresailer committed Jul 17, 2023
1 parent 41f4004 commit af7c77e
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions DDG4/python/DDSim/DD4hepSimulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ def __parseAllHelper(self, parsed):
self._errorMessages.append("ERROR: %s " % e)
if logger.level <= logging.DEBUG:
self._errorMessages.append(traceback.format_exc())
obj._checkProperties()

def __checkOutputLevel(self, level):
"""return outputlevel as int so we don't have to import anything for faster startup"""
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/Action.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self):
self._mapActions = dict()
self._trackerSDTypes = ['tracker']
self._calorimeterSDTypes = ['calorimeter']
self._closeProperties()

@property
def tracker(self):
Expand Down
16 changes: 16 additions & 0 deletions DDG4/python/DDSim/Helper/ConfigHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,25 @@
class ConfigHelper(object):
"""Base class for configuration helper"""

# We need a static set of properties, because steeringFile parsing creates new Helper objects!
_setOfProperties = dict()

def __init__(self):
pass

def _name(self):
return self.__class__.__name__

def _closeProperties(self):
"""Store the list of properties."""
self._setOfProperties[self._name()] = set(vars(self))

def _checkProperties(self):
newProps = set(vars(self))
if existingProps := self._setOfProperties.get(self._name(), set()):
if newProps - existingProps:
raise RuntimeError(f"{self._name()} error: Trying to add unknown propert(y/ies): {newProps - existingProps}!")

def getOptions(self):
finalVars = {}

Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/Filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self):
self._calo = "edep0"
self._filters = {}
self._createDefaultFilters()
self._closeProperties()

@property
def tracker(self):
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/Geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(self):

self._dumpDGDML_EXTRA = {"help": "If not empty, filename to dump the Geometry as GDML"}
self.dumpGDML = ""
self._closeProperties()

def constructGeometry(self, kernel, geant4, geoPrintLevel=2, numberOfThreads=1):
"""Construct Geant4 geometry."""
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/GuineaPig.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class GuineaPig(Input):
def __init__(self):
super(GuineaPig, self).__init__()
self._parameters["ParticlesPerEvent"] = -1
self._closeProperties()

@property
def particlesPerEvent(self):
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/Gun.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self):
'eta', 'pseudorapidity',
'ffbar']} # (1+cos^2 theta)
self._distribution = None
self._closeProperties()

@property
def distribution(self):
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/HepMC3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __init__(self):
self._parameters["Flow2"] = "flow2"
# this option will evaluate to True if the HEPMC3 plugin was build
self._useHepMC3 = ("@DD4HEP_USE_HEPMC3@" != "OFF")
self._closeProperties()

@property
def useHepMC3(self):
Expand Down
2 changes: 1 addition & 1 deletion DDG4/python/DDSim/Helper/Input.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Input(ConfigHelper):

def __init__(self):
super(Input, self).__init__()

self.__parameters = {}
self._closeProperties()

def getParameters(self):
return self.__parameters
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/InputConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class InputConfig(ConfigHelper):
def __init__(self):
super(InputConfig, self).__init__()
self._userPlugin = []
self._closeProperties()

@property
def userInputPlugin(self):
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/LCIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class LCIO(Input):
def __init__(self):
super(LCIO, self).__init__()
self._parameters["MCParticleCollectionName"] = "MCParticle"
self._closeProperties()

@property
def mcParticleCollectionName(self):
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/MagneticField.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ def __init__(self):
self.delta_intersection = 0.001 * mm
self.delta_one_step = 0.01 * mm
self.largest_step = 10 * m
self._closeProperties()
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/Meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self):
" E.g setting it to 42 will start counting events from 42 instead of 0",
'type': int}
self.eventNumberOffset = 0
# no closeProperties, allow adding arbitrary information to runHeader

def parseEventParameters(self):
"""
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/Output.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self):

self._geometry_EXTRA = {'choices': OUTPUT_CHOICES, 'type': outputLevelType}
self._geometry = outputLevel('DEBUG')
self._closeProperties()

@property
def inputStage(self):
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/OutputConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(self):
self._forceLCIO = False
self._forceEDM4HEP = False
self._forceDD4HEP = False
self._closeProperties()

def _checkConsistency(self):
"""Raise error if more than one force flag is true."""
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/ParticleHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self):
self._minDistToParentVertex = 2.2e-14 * mm
self._enableDetailedHitsAndParticleInfo = False
self._userParticleHandler = "Geant4TCUserParticleHandler"
self._closeProperties()

@property
def enableDetailedHitsAndParticleInfo(self):
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/Physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self):
5101, 5103, 5201, 5203, 5301, 5303, 5401, 5403, 5503} # b? diquarks
self._zeroTimePDGs = {11, 13, 15, 17}
self._userFunctions = []
self._closeProperties()

@property
def rejectPDGs(self):
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/Random.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def __init__(self):
"on eventID and runID\nAllows reproducibility even when"
"SkippingEvents"}
self.enableEventSeed = False
self._closeProperties()

def initialize(self, DDG4, kernel, output):
""" initialize the random generator
Expand Down
1 change: 1 addition & 0 deletions DDG4/python/DDSim/Helper/UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self):
self._commandsPostRun = []
self._commandsPreRun = []
self._commandsTerminate = []
self._closeProperties()

@property
def commandsConfigure(self):
Expand Down

0 comments on commit af7c77e

Please sign in to comment.