12 #include <calibration/modules/TriggerSkim/TriggerSkimModule.h>
13 #include <hlt/softwaretrigger/core/utilities.h>
14 #include <framework/core/ModuleParam.templateDetails.h>
15 #include <framework/utilities/Utils.h>
27 setDescription(R
"DOC(Trigger Skim Module
29 Module will return an overall result (True/False) based on whether or not ANY or
30 ALL (depending on ``logicMode``) of the specified triggers returned the given
31 value (``expectedResult``) from the SoftwareTriggerResult.
33 Optionally it can apply prescales on each trigger line. In that case ``logicMode='and'``
34 might not be very meaningful as the return value will only be true if all trigger
35 lines were accepted after their own prescale.
37 setPropertyFlags(c_ParallelProcessingCertified);
40 addParam(
"triggerLines", m_triggerLines,
41 "Trigger lines to skim on. This can either be just a list of names or "
42 "each item can also optionally be a tuple with name and prescale factor. "
43 "So either ``['hadron', 'cosmic']`` or ``[('hadron', 1), ('cosmic', 20)]`` "
45 addParam(
"expectedResult", m_expectedResult,
46 "The SoftwareTriggerResult value that each trigger line in the ``triggerLines`` "
47 "parameter will be tested for.",
int(1));
48 addParam(
"logicMode", m_logicMode,
49 "Each trigger line in ``triggerLines`` will be tested against the ``expectedResult`` parameter. "
50 "The logic mode controls whether we test using 'and' or 'or' logic to get a return value. "
51 "'and' means that all trigger lines must have ``results == expectedResult``, 'or' means that only "
52 "one of the trigger lines must match the expectedResult value.", m_logicMode);
53 addParam(
"useRandomNumbersForPreScale", m_useRandomNumbersForPreScale,
"Flag to use random numbers (True) "
54 "or a counter (False) for applying the prescale. In the latter case, the module will retain exactly "
55 "one event every N processed, where N (the counter value) is set for each line via the "
56 "``triggerLines`` option. By default, random numbers are used.", m_useRandomNumbersForPreScale);
57 addParam(
"resultOnMissing", m_resultOnMissing,
"Value to return if there's no hlt trigger result available. "
58 "If this is set to None a FATAL error will be raised if the results are missing. Otherwise the value "
59 "given will be set as return value of the module", m_resultOnMissing);
70 B2FATAL(
"You have entered an invalid parameter for logicMode. "
71 "Valid strings are any of ['or', 'and']");
73 if(m_expectedResult < -1 or m_expectedResult > 1) {
74 B2FATAL(
"Expected trigger result needs to be -1, 0 or 1");
81 [&havePrescales](
const std::tuple<std::string, unsigned int>& line) {
82 const auto& [name, prescale] = line;
84 B2ERROR(
"Prescale is not positive, needs to be at least 1"
85 <<
LogVar(
"trigger line", name) <<
LogVar(
"prescale", prescale));
88 B2DEBUG(20,
"Prescale of " << prescale <<
" to be applied to " << name);
90 [](
const std::string& name) {
92 B2DEBUG(20,
"No prescales to be applied to " << name);
106 if(accepted and prescale != 1) {
107 accepted &= SoftwareTrigger::makePreScale(prescale, counter);
110 }
catch(std::out_of_range &e) {
112 std::string available_lines =
"";
114 available_lines += line +
"(" + std::to_string((
int)result) +
") ";
116 B2FATAL(
"software trigger line not found" <<
LogVar(
"requested", name) <<
LogVar(
"available", available_lines));
128 B2FATAL(
"No HLT Trigger result available (if this is expected to be possible "
129 "please use the `resultOnMissing` parameter");
132 size_t numAccepted(0);
134 size_t counterIndex{0};
138 [
this, &counterIndex](
const std::tuple<std::string, unsigned int>& line) {
139 const auto& [name, prescale] = line;
144 [
this](
const std::string& name) {