HPS-MC
test_tools_javatools.py
Go to the documentation of this file.
1 import unittest
2 import configparser
3 import os
4 
5 from hpsmc.tools import JavaTool, EvioToLcio, FilterBunches, ExtractEventsWithHitAtHodoEcal
6 
7 
8 class TestJavaTool(unittest.TestCase):
9 
10  def test_init(self):
11  java_tool = JavaTool(name="java_tool", java_class="java_class")
12  self.assertEqual(java_tool.name, "java_tool")
13  self.assertEqual(java_tool.java_class, "java_class")
14  self.assertEqual(java_tool.command, "java")
15 
17  java_tool = JavaTool(name="java_tool", java_class="java_class")
18  self.assertEqual(java_tool.required_config(), ["hps_java_bin_jar", "hps_fieldmaps_dir"])
19 
20  def test_config(self):
21  java_tool = JavaTool(name="java_tool", java_class="java_class")
22  parser = configparser.ConfigParser()
23  config_file = ['test_helpers/.hpsmc_test_cfg']
24  parser.read(config_file)
25  java_tool.config(parser)
26  self.assertEqual(java_tool.hps_fieldmaps_dir, "some/fieldmaps/dir")
27  self.assertEqual(java_tool.hps_java_bin_jar, "some/path/to/hps-java-bin.jar")
28  self.assertEqual(java_tool.conditions_url, "http://some/path/to/conditions")
29 
30  def test_setup(self):
31  java_tool = JavaTool(name="java_tool", java_class="java_class")
32  parser = configparser.ConfigParser()
33  config_file = ['test_helpers/.hpsmc_test_cfg']
34  parser.read(config_file)
35  java_tool.config(parser)
36  java_tool.setup()
37  self.assertTrue(os.path.islink(os.getcwd() + "/fieldmap"))
38  os.remove(os.getcwd() + "/fieldmap")
39 
40  def test_cmd_args(self):
41  java_tool = JavaTool(name="java_tool", java_class="java_class")
42  parser = configparser.ConfigParser()
43  config_file = ['test_helpers/.hpsmc_test_cfg']
44  parser.read(config_file)
45  java_tool.config(parser)
46  self.assertEqual(java_tool.cmd_args(), ["args", "-Dorg.hps.conditions.url=http://some/path/to/conditions", "-cp", "some/path/to/hps-java-bin.jar", "java_class"])
47 
48 
49 class TestEvioToLcio(unittest.TestCase):
50 
51  def test_init(self):
52  evio_to_lcio = EvioToLcio(steering="steering_file")
53  self.assertEqual(evio_to_lcio.name, "evio_to_lcio")
54  self.assertEqual(evio_to_lcio.java_class, "org.hps.evio.EvioToLcio")
55  self.assertEqual(evio_to_lcio.steering, "steering_file")
56  self.assertEqual(evio_to_lcio.output_ext, ".slcio")
57 
59  evio_to_lcio = EvioToLcio()
60  self.assertEqual(evio_to_lcio.required_parameters(), ["detector", "steering_files"])
61 
63  evio_to_lcio = EvioToLcio()
64  self.assertEqual(evio_to_lcio.optional_parameters(), ["run_number", "skip_events", "nevents", "event_print_interval"])
65 
66  def test_setup(self):
67  evio_to_lcio = EvioToLcio(steering="steering")
68  parser = configparser.ConfigParser()
69  config_file = ['test_helpers/.hpsmc_test_cfg']
70  parser.read(config_file)
71  evio_to_lcio.config(parser)
72  evio_to_lcio.set_parameters({"steering_files": {"steering": "steering_file"}, "detector": "detector"})
73  evio_to_lcio.setup()
74  self.assertEqual(evio_to_lcio.steering_file, "steering_file")
75 
76  def test_cmd_args(self):
77  evio_to_lcio = EvioToLcio(steering="steering", inputs=["input1.evio", "input2.evio"], outputs=["output.slcio"])
78  parser = configparser.ConfigParser()
79  config_file = ['test_helpers/.hpsmc_test_cfg']
80  parser.read(config_file)
81  evio_to_lcio.config(parser)
82  evio_to_lcio.set_parameters({"steering_files": {"steering": "steering_file"}, "detector": "detector", "skip_events": 10, "nevents": 100, "event_print_interval": 10, "run_number": 1234})
83  evio_to_lcio.setup()
84  self.assertEqual(evio_to_lcio.cmd_args(), ["args", "-Dorg.hps.conditions.url=http://some/path/to/conditions", "-cp", "some/path/to/hps-java-bin.jar", "org.hps.evio.EvioToLcio", "-DoutputFile=output", "-d", "detector", "-R", "1234", "-s", "10", "-r", "-x", "steering_file", "-n", "100", "-b", "input1.evio", "input2.evio", "-e", "10"])
85 
86 
87 class TestFilterBunches(unittest.TestCase):
88 
89  def test_init(self):
90  filter_bunches = FilterBunches(filter_no_cuts=True, filter_ecal_pairs=True, filter_ecal_hit_ecut=1.0, filter_event_interval=10, filter_nevents_read=1, filter_nevents_write=10)
91  self.assertEqual(filter_bunches.name, "filter_bunches")
92  self.assertEqual(filter_bunches.java_class, "org.hps.util.FilterMCBunches")
93  self.assertEqual(filter_bunches.append_tok, 'filt')
94  self.assertEqual(filter_bunches.filter_no_cuts, True)
95  self.assertEqual(filter_bunches.filter_ecal_pairs, True)
96  self.assertEqual(filter_bunches.filter_ecal_hit_ecut, 1.0)
97  self.assertEqual(filter_bunches.filter_event_interval, 10)
98  self.assertEqual(filter_bunches.filter_nevents_read, 1)
99  self.assertEqual(filter_bunches.filter_nevents_write, 10)
100 
102  filter_bunches = FilterBunches()
103  self.assertEqual(filter_bunches.optional_parameters(), ["filter_ecal_hit_ecut", "filter_event_interval", "filter_nevents_read", "filter_nevents_write", "filter_no_cuts"])
104 
106  filter_bunches = FilterBunches()
107  self.assertEqual(filter_bunches.required_config(), ["hps_java_bin_jar"])
108 
109  def test_config(self):
110  filter_bunches = FilterBunches()
111  parser = configparser.ConfigParser()
112  config_file = ['test_helpers/.hpsmc_test_cfg']
113  parser.read(config_file)
114  filter_bunches.config(parser)
115  self.assertEqual(filter_bunches.hps_java_bin_jar, "some/path/to/hps-java-bin.jar")
116 
117  def test_cmd_args(self):
118  filter_bunches = FilterBunches(inputs=["input1.slcio", "input2.slcio"], outputs=["output.slcio"], filter_no_cuts=True, filter_ecal_pairs=True, filter_ecal_hit_ecut=1.0, filter_event_interval=10, filter_nevents_read=100, filter_nevents_write=100)
119  parser = configparser.ConfigParser()
120  config_file = ['test_helpers/.hpsmc_test_cfg']
121  parser.read(config_file)
122  filter_bunches.config(parser)
123  self.assertEqual(filter_bunches.cmd_args(), ["args", "-Dorg.hps.conditions.url=http://some/path/to/conditions", "-cp", "some/path/to/hps-java-bin.jar", "org.hps.util.FilterMCBunches", "-e", "10", "input1.slcio", "input2.slcio", "output.slcio", "-d", "-E", "1.0", "-n", "100", "-w", "100", "-a"])
124 
125 
126 class TestExtractEventsWithHitAtHodoEcal(unittest.TestCase):
127 
128  def test_init(self):
129  extract_events = ExtractEventsWithHitAtHodoEcal(num_hodo_hits=1, event_interval=10)
130  self.assertEqual(extract_events.name, "filter_events")
131  self.assertEqual(extract_events.java_class, "org.hps.util.ExtractEventsWithHitAtHodoEcal")
132  self.assertEqual(extract_events.append_tok, 'filt')
133  self.assertEqual(extract_events.num_hodo_hits, 1)
134  self.assertEqual(extract_events.event_interval, 10)
135 
137  extract_events = ExtractEventsWithHitAtHodoEcal()
138  self.assertEqual(extract_events.optional_parameters(), ["num_hodo_hits", "event_interval"])
139 
140  def test_cmd_args(self):
141  extract_events = ExtractEventsWithHitAtHodoEcal(inputs=["input1.slcio", "input2.slcio"], outputs=["output.slcio"], num_hodo_hits=1, event_interval=10, nevents=100)
142  parser = configparser.ConfigParser()
143  config_file = ['test_helpers/.hpsmc_test_cfg']
144  parser.read(config_file)
145  extract_events.config(parser)
146  self.assertEqual(extract_events.cmd_args(), ["args", "-Dorg.hps.conditions.url=http://some/path/to/conditions", "-cp", "some/path/to/hps-java-bin.jar", "org.hps.util.ExtractEventsWithHitAtHodoEcal", "-e", "10", "input1.slcio", "input2.slcio", "output.slcio", "-M", "1", "-w", "100"])
147 
148 
149 if __name__ == '__main__':
150  unittest.main()
Convert EVIO events to LCIO using the hps-java EvioToLcio command line tool.
Definition: tools.py:957
Apply hodo-hit filter and space MC events to process before readout.
Definition: tools.py:1160
Space MC events and apply energy filters to process before readout.
Definition: tools.py:1048
Generic base class for Java based tools.
Definition: tools.py:910
Tools that can be used in HPSMC jobs.
Definition: tools.py:1