File indexing completed on 2026-07-26 08:23:22
0001 """Class for input plugin configuration"""
0002
0003 from DDSim.Helper.ConfigHelper import ConfigHelper
0004
0005
0006 class InputConfig(ConfigHelper):
0007 """Configuration for Input Files."""
0008
0009 def __init__(self):
0010 super(InputConfig, self).__init__()
0011 self._userPlugin = []
0012 self._closeProperties()
0013
0014 @property
0015 def userInputPlugin(self):
0016 """Set one or more functions to configure input steps.
0017
0018 The functions must take a ``DD4hepSimulation`` object as their only argument and return the created generatorAction
0019 ``gen`` (for example).
0020
0021 For example one can add this to the ddsim steering file:
0022
0023 def exampleUserPlugin(dd4hepSimulation):
0024 '''Example code for user created plugin.
0025
0026 :param DD4hepSimulation dd4hepSimulation: The DD4hepSimulation instance, so all parameters can be accessed
0027 :return: GeneratorAction
0028 '''
0029 from DDG4 import GeneratorAction, Kernel
0030 # Geant4InputAction is the type of plugin, Cry1 just an identifier
0031 gen = GeneratorAction(Kernel(), 'Geant4InputAction/Cry1' , True)
0032 # CRYEventReader is the actual plugin, steeringFile its constructor parameter
0033 gen.Input = 'CRYEventReader|' + 'steeringFile'
0034 # we can give a dictionary of Parameters that has to be interpreted by the setParameters function of the plugin
0035 gen.Parameters = {'DataFilePath': '/path/to/files/data'}
0036 gen.enableUI()
0037 return gen
0038
0039 SIM.inputConfig.userInputPlugin = exampleUserPlugin
0040
0041 Repeat function definition and assignment to add multiple input steps
0042
0043 """
0044 return self._userPlugin
0045
0046 @userInputPlugin.setter
0047 def userInputPlugin(self, userInputPluginConfig):
0048 if not userInputPluginConfig:
0049 return
0050
0051 if isinstance(userInputPluginConfig, list):
0052 if not all(callable(func) for func in userInputPluginConfig):
0053 raise RuntimeError("Some provided userPlugins are not a callable function")
0054 self._userPlugin = userInputPluginConfig
0055 return
0056
0057 if not callable(userInputPluginConfig):
0058 raise RuntimeError("The provided userPlugin is not a callable function: %s, %s" % (type(userInputPluginConfig),
0059 repr(userInputPluginConfig)))
0060 self._userPlugin.append(userInputPluginConfig)