class DriftChamber: """ Objects of this class represent an instance of the program. """ def __init__(self, p_args=None): """ Constructor. :param p_args The command line arguments. Only use this for testing purposes and let it default to sys.argv otherwise. """ # The configuration class also parses the command line arguments. # Hence, in order for the argument parser to be the first to stream to the standard output. No output should be streamed before the next line is executed. self._args = p_args self._init_commandline_argument_parser() self._init_confiuration() self._init_data_store() self._init_run_engine() def _init_commandline_argument_parser(self): self._commandLineKeyOfConfigurationFile = "config" self._commandLineFlagOfConfigurationFile = "--" + self._commandLineKeyOfConfigurationFile self._argumentParser = ArgumentParser( 'Drift Chamber Project of Team A') self._argumentParser.add_argument( self._commandLineFlagOfConfigurationFile, type=str, help= 'Path to a file that holds the configuration for this program run.' ) self._parsedArgs = vars(self._argumentParser.parse_args(self._args)) def _init_confiuration(self): self._configuration = Configuration( self._parsedArgs[self._commandLineKeyOfConfigurationFile], driftChamberConfig_generalSpecification) def _init_data_store(self): self._dataStore = DataStore() self._dataStore.put('nEvent', self._configuration['General_nEvent'], ObjectLifetime.Application) self._dataStore.put('configuration', self._configuration, ObjectLifetime.Application) self._dataStore.put('driftChamber', self, ObjectLifetime.Application) def _init_run_engine(self): self._run_engine = RunEngineFactory( self._configuration["Modules_moduleSequence"], self._dataStore).get_run_engine() def start_simulation(self): logging.info("'Drift Chamber Simulation' started.") self._run_engine.log_configuration() self._run_engine.run() logging.info("'Drift Chamber Simulation' done.")
class DriftChamber: """ Objects of this class represent an instance of the program. """ def __init__(self, p_args = None): """ Constructor. :param p_args The command line arguments. Only use this for testing purposes and let it default to sys.argv otherwise. """ # The configuration class also parses the command line arguments. # Hence, in order for the argument parser to be the first to stream to the standard output. No output should be streamed before the next line is executed. self._args = p_args self._init_commandline_argument_parser() self._init_confiuration() self._init_data_store() self._init_run_engine() def _init_commandline_argument_parser(self): self._commandLineKeyOfConfigurationFile = "config" self._commandLineFlagOfConfigurationFile = "--" + self._commandLineKeyOfConfigurationFile self._argumentParser = ArgumentParser('Drift Chamber Project of Team A') self._argumentParser.add_argument( self._commandLineFlagOfConfigurationFile, type=str, help='Path to a file that holds the configuration for this program run.') self._parsedArgs = vars(self._argumentParser.parse_args(self._args)) def _init_confiuration(self): self._configuration = Configuration( self._parsedArgs[self._commandLineKeyOfConfigurationFile], driftChamberConfig_generalSpecification) def _init_data_store(self): self._dataStore = DataStore() self._dataStore.put('nEvent', self._configuration['General_nEvent'], ObjectLifetime.Application) self._dataStore.put('configuration', self._configuration, ObjectLifetime.Application) self._dataStore.put('driftChamber', self, ObjectLifetime.Application) def _init_run_engine(self): self._run_engine = RunEngineFactory(self._configuration["Modules_moduleSequence"], self._dataStore).get_run_engine() def start_simulation(self): logging.info("'Drift Chamber Simulation' started.") self._run_engine.log_configuration() self._run_engine.run() logging.info("'Drift Chamber Simulation' done.")
def test_run(self): moduleFactory = ModuleFactory('TestModule', self.path_to_default_test_config_file, self.path_to_test_modules, self.path_to_test_modules_py) module = moduleFactory.get_module_instance() data_store = DataStore() data_store.put('nEvent', 2) run_engine = RunEngineFactory([moduleFactory], data_store).get_run_engine() self.assertIsInstance(run_engine, RunEngine) run_engine.run() self.assertEqual(module.beginCalled, 1) self.assertEqual(module.eventCalled, 2) self.assertEqual(module.endCalled, 1)
class MultiModule(Module): def begin(self, datastore): configuration = datastore.get(self) self._run_engine = RunEngineFactory( configuration['MultiModule_moduleSequence'], datastore).get_run_engine() self._run_engine.call_all_begin_methods() def event(self, datastore): self._run_engine.call_next_event_methods() def end(self, datastore): self._run_engine.call_all_end_methods()
class MultiModule(Module): def begin(self, datastore): configuration = datastore.get(self) self._run_engine = RunEngineFactory(configuration['MultiModule_moduleSequence'], datastore).get_run_engine() self._run_engine.call_all_begin_methods() def event(self, datastore): self._run_engine.call_next_event_methods() def end(self, datastore): self._run_engine.call_all_end_methods()
def begin(self, datastore): configuration = datastore.get(self) self._run_engine = RunEngineFactory( configuration['MultiModule_moduleSequence'], datastore).get_run_engine() self._run_engine.call_all_begin_methods()
def _init_run_engine(self): self._run_engine = RunEngineFactory( self._configuration["Modules_moduleSequence"], self._dataStore).get_run_engine()
def begin(self, datastore): configuration = datastore.get(self) self._run_engine = RunEngineFactory(configuration['MultiModule_moduleSequence'], datastore).get_run_engine() self._run_engine.call_all_begin_methods()
def _init_run_engine(self): self._run_engine = RunEngineFactory(self._configuration["Modules_moduleSequence"], self._dataStore).get_run_engine()