3 Helper function to convert a python list into a std::vector of the same type.
4 Is not a very general and good method, but works for the different use cases in
6 :param l: The list to convert
7 :return: A std::vector with the same content as the input list.
10 type_of_first_element = type(l[0]).__name__
11 if type_of_first_element ==
"str":
12 type_of_first_element =
"string"
14 vec = std.vector(type_of_first_element)()
22 def upload_cut_to_db(cut_string, base_identifier, cut_identifier, prescale_factor=1, reject_cut=False, iov=None):
24 Python function to upload the given software trigger cut to the database.
25 Additional to the software trigger cut, the base- as well as the cut identifier
26 have to be given. Optionally, the interval of validity can be defined
27 (default is always valid).
29 from ROOT
import Belle2
34 if isinstance(prescale_factor, list):
35 raise AttributeError(
"The only allowed type for the prescaling is a single factor")
39 cut_string, prescale_factor, reject_cut)
41 db_handler.upload(software_trigger_cut, base_identifier, cut_identifier, iov)
44 def upload_trigger_menu_to_db(base_identifier, cut_identifiers, accept_mode=False, iov=None):
46 Python function to upload the given software trigger enu to the database.
47 Additional to the software trigger menu, the base identifier
48 has to be given. Optionally, the interval of validity can be defined
49 (default is always valid).
51 from ROOT
import Belle2
56 cut_identifiers = list_to_vector(cut_identifiers)
59 db_handler.uploadTriggerMenu(base_identifier, cut_identifiers, accept_mode, iov)
62 def download_cut_from_db(base_name, cut_name, do_set_event_number=True):
64 Python function to download a cut from the database. As each cut is uniquely identified by a
65 base and a cut name, you have to give in both here.
66 Please remember that the database access depends on the current event number. If you do not call
67 this function in a basf2 module environment, you can use the set_event_number function in this
68 python file to set the event number correctly nevertheless.
69 :param base_name: the base name of the cut
70 :param cut_name: the specific name of the cut
71 :param do_set_event_number: it is important to always have a proper event number set for the database to work.
72 This is why this functions sets the event number in all cases to (1, 0, 0). If you want to prevent this
73 (because you maybe want to use another event number), set this flag to False.
74 :return: the downloaded cut or None, if the name can not be found.
76 from ROOT
import Belle2
78 if do_set_event_number:
79 set_event_number(1, 0, 0)
82 result = db_handler.download(base_name, cut_name)
88 def download_trigger_menu_from_db(base_name, do_set_event_number=True):
90 Python function to download a trigger menu from the database. As each trigger menu is uniquely identified by a
91 base name, you have to give here.
92 Please remember that the database access depends on the current event number. If you do not call
93 this function in a basf2 module environment, you can use the set_event_number function in this
94 python file to set the event number correctly nevertheless.
95 :param base_name: the base name of the menu
96 :param do_set_event_number: it is important to always have a proper event number set for the database to work.
97 This is why this functions sets the event number in all cases to (1, 0, 0). If you want to prevent this
98 (because you maybe want to use another event number), set this flag to False.
99 :return: the downloaded cut or None, if the name can not be found.
101 from ROOT
import Belle2
103 if do_set_event_number:
104 set_event_number(1, 0, 0)
107 result = db_handler.downloadTriggerMenu(base_name)
113 def set_event_number(evt_number, run_number, exp_number):
115 Helper function to set the event number although we are not in a typical
116 "module-path" setup. This is done by initializing the database,
117 creating an EventMetaData and string the requested numbers in it.
119 from ROOT
import Belle2
121 event_meta_data_pointer =
Belle2.PyStoreObj(Belle2.EventMetaData.Class(),
"EventMetaData")
125 event_meta_data_pointer.registerInDataStore()
126 event_meta_data_pointer.create(
False)
127 event_meta_data_pointer.setEvent(evt_number)
128 event_meta_data_pointer.setRun(run_number)
129 event_meta_data_pointer.setExperiment(exp_number)
135 for base_identifier
in [
"filter",
"skim"]:
136 menu = download_trigger_menu_from_db(base_name=base_identifier, do_set_event_number=
False)
139 cuts = menu.getCutIdentifiers()
140 for cut_identifier
in cuts:
141 cut = download_cut_from_db(base_name=base_identifier, cut_name=cut_identifier, do_set_event_number=
False)
143 "Base Identifier": base_identifier,
144 "Reject Menu": menu.isAcceptMode(),
145 "Cut Identifier": cut_identifier,
146 "Cut Condition": cut.decompile(),
147 "Cut Prescaling": cut.getPreScaleFactor(),
148 "Reject Cut": cut.isRejectCut()
152 if __name__ ==
"__main__":
153 print(
"This tool is now replaced by 'b2hlt_triggers print'.")