11 sim_base = SimBase(name=
"sim_base")
12 self.assertEqual(sim_base.required_parameters(), [
"detector"])
15 sim_base = SimBase(name=
"sim_base")
16 self.assertEqual(sim_base.optional_parameters(), [
"nevents",
"macros",
"run_number"])
19 sim_base = SimBase(name=
"sim_base")
20 parser = configparser.ConfigParser()
21 config_file = [
'test_helpers/.hpsmc_test_cfg']
22 parser.read(config_file)
23 sim_base.config(parser)
24 params = {
"detector":
"some_detector"}
25 sim_base.set_parameters(params)
26 self.assertEqual(sim_base.detector_file(),
"some/detector/dir/some_detector/some_detector.lcdd")
33 self.assertEqual(sim.name,
"hps-sim")
34 self.assertEqual(sim.command,
"hps-sim")
35 self.assertEqual(sim.output_ext,
".slcio")
39 self.assertEqual(sim.required_config(), [
"hps_sim_dir",
"hps_fieldmaps_dir",
"detector_dir"])
43 parser = configparser.ConfigParser()
44 config_file = [
'test_helpers/.hpsmc_test_cfg']
45 parser.read(config_file)
47 self.assertEqual(sim.detector_dir,
"some/detector/dir")
48 self.assertEqual(sim.hps_fieldmaps_dir,
"some/fieldmaps/dir")
49 self.assertEqual(sim.hps_sim_dir,
"test_helpers/simdir")
52 sim = Sim(inputs=[
"some/path/to/input.stdhep"], outputs=[
"some/path/to/output.slcio"])
53 parser = configparser.ConfigParser()
54 config_file = [
'test_helpers/.hpsmc_test_cfg']
55 parser.read(config_file)
57 params = {
"detector":
"some_detector"}
58 sim.set_parameters(params)
60 self.assertEqual(sim.env_script,
"test_helpers/simdir/bin/hps-sim-env.sh")
61 self.assertTrue(os.path.islink(os.getcwd() + os.path.sep +
"fieldmap"))
62 os.unlink(os.getcwd() +
"/fieldmap")
65 sim = Sim(inputs=[
"some/path/to/input.stdhep"], outputs=[
"some/path/to/output.slcio"], seed=2, nevents=10)
66 parser = configparser.ConfigParser()
67 config_file = [
'test_helpers/.hpsmc_test_cfg']
68 parser.read(config_file)
70 params = {
"detector":
"some_detector",
"macros": [
"macro1.mac",
"macro2.mac"]}
71 sim.set_parameters(params)
74 self.assertTrue(os.path.isfile(
"run.macro"))
75 with open(
"run.macro",
"r")
as f:
77 self.assertEqual(lines[0],
"/lcdd/url some/detector/dir/some_detector/some_detector.lcdd\n")
78 self.assertEqual(lines[1],
"/run/initialize\n")
79 self.assertEqual(lines[2],
"/random/seed 2\n")
80 self.assertEqual(lines[3],
"/hps/generators/create StdHepGen STDHEP\n")
81 self.assertEqual(lines[4],
"/hps/generators/StdHepGen/file some/path/to/input.stdhep\n")
82 self.assertEqual(lines[5],
"/control/execute macro1.mac\n")
83 self.assertEqual(lines[6],
"/control/execute macro2.mac\n")
84 self.assertEqual(lines[7],
"/hps/lcio/recreate\n")
85 self.assertEqual(lines[8],
"/hps/lcio/file some/path/to/output.slcio\n")
86 self.assertEqual(lines[9],
"/run/beamOn 10")
88 os.remove(os.getcwd() +
"/run.macro")
89 os.unlink(os.getcwd() +
"/fieldmap")
92 if __name__ ==
"__main__":