10def list_to_vector(lst):
12 Helper function to convert a python list into a std::vector of the same type.
13 Is not a very general
and good method, but works
for the different use cases
in
15 :param lst: The list to convert
16 :
return: A std::vector
with the same content
as the input list.
19 type_of_first_element = type(lst[0]).__name__
20 if type_of_first_element ==
"str":
21 type_of_first_element =
"string"
23 vec = std.vector(type_of_first_element)()
39 Python function to upload the given software trigger cut to the database.
40 Additional to the software trigger cut, the base- as well
as the cut identifier
41 have to be given. Optionally, the interval of validity can be defined
42 (default
is always valid).
44 from ROOT
import Belle2
49 if isinstance(prescale_factor, list):
51 "The only allowed type for the prescaling is a single factor")
55 cut_string, prescale_factor, reject_cut)
64def upload_trigger_menu_to_db(
70 Python function to upload the given software trigger enu to the database.
71 Additional to the software trigger menu, the base identifier
72 has to be given. Optionally, the interval of validity can be defined
73 (default is always valid).
75 from ROOT
import Belle2
80 cut_identifiers = list_to_vector(cut_identifiers)
83 db_handler.uploadTriggerMenu(
90def download_cut_from_db(base_name, cut_name, do_set_event_number=True):
92 Python function to download a cut from the database. As each cut
is uniquely identified by a
93 base
and a cut name, you have to give
in both here.
94 Please remember that the database access depends on the current event number. If you do
not call
95 this function
in a basf2 module environment, you can use the set_event_number function
in this
96 python file to set the event number correctly nevertheless.
97 :param base_name: the base name of the cut
98 :param cut_name: the specific name of the cut
99 :param do_set_event_number: it
is important to always have a proper event number set
for the database to work.
100 This
is why this functions sets the event number
in all cases to (1, 0, 0). If you want to prevent this
101 (because you maybe want to use another event number), set this flag to
False.
102 :
return: the downloaded cut
or None,
if the name can
not be found.
104 from ROOT
import Belle2
106 if do_set_event_number:
107 set_event_number(1, 0, 0)
110 result = db_handler.download(base_name, cut_name)
116def download_trigger_menu_from_db(base_name, do_set_event_number=True):
118 Python function to download a trigger menu from the database. As each trigger menu
is uniquely identified by a
119 base name, you have to give here.
120 Please remember that the database access depends on the current event number. If you do
not call
121 this function
in a basf2 module environment, you can use the set_event_number function
in this
122 python file to set the event number correctly nevertheless.
123 :param base_name: the base name of the menu
124 :param do_set_event_number: it
is important to always have a proper event number set
for the database to work.
125 This
is why this functions sets the event number
in all cases to (1, 0, 0). If you want to prevent this
126 (because you maybe want to use another event number), set this flag to
False.
127 :
return: the downloaded cut
or None,
if the name can
not be found.
129 from ROOT
import Belle2
131 if do_set_event_number:
132 set_event_number(1, 0, 0)
135 result = db_handler.downloadTriggerMenu(base_name)
141def set_event_number(evt_number, run_number, exp_number):
143 Helper function to set the event number although we are not in a typical
144 "module-path" setup. This
is done by initializing the database,
145 creating an EventMetaData
and string the requested numbers
in it.
147 from ROOT
import Belle2
150 Belle2.EventMetaData.Class(),
"EventMetaData")
154 event_meta_data_pointer.registerInDataStore()
155 event_meta_data_pointer.create(
False)
156 event_meta_data_pointer.setEvent(evt_number)
157 event_meta_data_pointer.setRun(run_number)
158 event_meta_data_pointer.setExperiment(exp_number)
164 for base_identifier
in [
"filter",
"skim"]:
165 menu = download_trigger_menu_from_db(
166 base_name=base_identifier, do_set_event_number=
False)
169 cuts = [str(cut)
for cut
in menu.getCutIdentifiers()]
170 for cut_identifier
in cuts:
171 cut = download_cut_from_db(
172 base_name=base_identifier,
173 cut_name=cut_identifier,
174 do_set_event_number=
False)
176 "Base Identifier": base_identifier,
177 "Reject Menu": menu.isAcceptMode(),
178 "Cut Identifier": cut_identifier,
179 "Cut Condition": cut.decompile(),
180 "Cut Prescaling": cut.getPreScaleFactor(),
181 "Reject Cut": cut.isRejectCut()
185if __name__ ==
"__main__":
186 print(
"This tool is now replaced by 'b2hlt_triggers print'.")
static DataStore & Instance()
Instance of singleton Store.
A class that describes the interval of experiments/runs for which an object in the database is valid.
a (simplified) python wrapper for StoreObjPtr.
static std::unique_ptr< SoftwareTriggerCut > compile(const std::string &cut_string, const unsigned int prescaleFactor, const bool rejectCut=false)
Compile a new SoftwareTriggerCut from a cut string (by using the GeneralCut::compile function) and an...
Helper class for performing up- and downloads of SoftwareTriggerCuts from the database.