Belle II Software development
run.py
1
8
9import argparse
10import pickle
11
12from tracking.run.event_generation import StandardEventGenerationRun
13from tracking.run.mixins import BrowseTFileOnTerminateRunMixin, PostProcessingRunMixin
14
15
17 """Harvester to select crops, postprocess, and inspect"""
18
19
20 output_file_name = None
21
22 def harvesting_module(self, path=None):
23 """This virtual method must be overridden by the inheriting class"""
24 raise RuntimeError("Override the harvesting_module method")
25
26 def create_argument_parser(self, **kwds):
27 """Parse the arguments and append them to the harvester's list"""
28 argument_parser = super().create_argument_parser(**kwds)
29 harvesting_argument_group = argument_parser.add_argument_group("Harvest arguments")
30
31 harvesting_argument_group.add_argument(
32 "-o",
33 "--output",
34 dest="output_file_name",
35 default=argparse.SUPPRESS,
36 help="File name for the harvest products"
37 )
38
39 return argument_parser
40
41 def pickle_crops(self, harvesting_module, crops, **kwds):
42 """Save the raw crops as a pickle file"""
43 with open(self.output_file_nameoutput_file_name + ".pickle", "wb") as pickle_file:
44 pickle.dump(crops, pickle_file)
45
46 def unpickle_crops(self):
47 """Load the raw crops from a pickle file"""
48 with open(self.output_file_nameoutput_file_name + ".pickle", "rb") as pickle_file:
49 return pickle.load(pickle_file)
50
51 def postprocess(self):
52 """Post-process the crops"""
53 if self.postprocess_only:
54 harvesting_module = self.harvesting_module()
56 harvesting_module.output_file_name = self.output_file_nameoutput_file_name
57 try:
58 crops = self.unpickle_crops()
59 except FileNotFoundError:
60 print("Crops pickle file not found. Create it now.")
61 else:
62 harvesting_module.refine(crops)
63
64 super().postprocess()
65
66 def adjust_path(self, path):
67 """Add the harvester to the basf2 path"""
68 super().adjust_path(path)
69 harvesting_module = self.harvesting_module()
71 harvesting_module.output_file_name = self.output_file_nameoutput_file_name
72 harvesting_module.refiners.append(self.pickle_crops)
73 path.add_module(harvesting_module)
74 return path
75
76
78 """Harvester to generate MC events followed by crop selection, postprocessing, inspection"""
def create_argument_parser(self, **kwds)
Definition: run.py:26
def harvesting_module(self, path=None)
Definition: run.py:22
None output_file_name
Disable the writing of an output ROOT file.
Definition: run.py:20
def pickle_crops(self, harvesting_module, crops, **kwds)
Definition: run.py:41
None output_file_name
There is no default for the name of the output TFile.
Definition: mixins.py:60
bool postprocess_only
By default, browse the output TFile too.
Definition: mixins.py:29