Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDSim: prevent use of unknown properties #1145

Merged
merged 5 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
LCG: ["LCG_99/x86_64-centos7-gcc10-opt"]
LCG: ["dev4/x86_64-centos7-gcc11-opt"]
steps:
- uses: actions/checkout@v3
- uses: cvmfs-contrib/github-action-cvmfs@v3
Expand Down
10 changes: 5 additions & 5 deletions DDCore/python/dd4hepFactories.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def dumpInventory(self, summary_only=False, dump=True, load=False, interactive=T
ret = 'D'
if interactive:
try:
ret = input("%s%s%s%s" % ("<CR> to DUMP the list of components \n",
"<Q> to QUIT \n",
"<D> to DUMP the list of components \n",
"<S> to SKIP this particular library\n",
"<L> to no longer LOAD libraries \n"))
ret = input("<CR> to DUMP the list of components \n"
"<Q> to QUIT \n"
"<D> to DUMP the list of components \n"
"<S> to SKIP this particular library\n"
"<L> to no longer LOAD libraries \n")
except Exception:
ret = 'D'
if not len(ret):
Expand Down
2 changes: 1 addition & 1 deletion DDDigi/python/dddigi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def loadDDDigi():

# Try to load libglapi to avoid issues with TLS Static
# Turn off all errors from ROOT about the library missing
if('libglapi' not in gSystem.GetLibraries()):
if 'libglapi' not in gSystem.GetLibraries():
orgLevel = ROOT.gErrorIgnoreLevel
ROOT.gErrorIgnoreLevel = 6000
gSystem.Load("libglapi")
Expand Down
2 changes: 1 addition & 1 deletion DDG4/python/DDG4.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def loadDDG4():

# Try to load libglapi to avoid issues with TLS Static
# Turn off all errors from ROOT about the library missing
if('libglapi' not in gSystem.GetLibraries()):
if 'libglapi' not in gSystem.GetLibraries():
orgLevel = ROOT.gErrorIgnoreLevel
ROOT.gErrorIgnoreLevel = 6000
gSystem.Load("libglapi")
Expand Down
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 unknownProps := newProps - existingProps:
raise RuntimeError(f"{self._name()} error: Trying to add unknown propert(y/ies): {unknownProps}!")

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
# no closeProperties, allow custom ones for userPlugin configuration

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
Loading