10#include <calibration/modules/TriggerSkim/TriggerSkimModule.h>
11#include <hlt/softwaretrigger/core/utilities.h>
12#include <framework/core/ModuleParam.templateDetails.h>
13#include <framework/utilities/Utils.h>
27Module will return an overall result (True/False) based on whether or not ANY or
28ALL (depending on ``logicMode``) of the specified triggers returned the given
29value (``expectedResult``) from the SoftwareTriggerResult.
31Optionally it can apply prescales on each trigger line. In that case ``logicMode='and'``
32might not be very meaningful as the return value will only be true if all trigger
33lines were accepted after their own prescale.
39 "Trigger lines to skim on. This can either be just a list of names or "
40 "each item can also optionally be a tuple with name and prescale factor. "
41 "So either ``['hadron', 'cosmic']`` or ``[('hadron', 1), ('cosmic', 20)]`` "
44 "The SoftwareTriggerResult value that each trigger line in the ``triggerLines`` "
45 "parameter will be tested for.",
int(1));
47 "Each trigger line in ``triggerLines`` will be tested against the ``expectedResult`` parameter. "
48 "The logic mode controls whether we test using 'and' or 'or' logic to get a return value. "
49 "'and' means that all trigger lines must have ``results == expectedResult``, 'or' means that only "
50 "one of the trigger lines must match the expectedResult value.",
m_logicMode);
52 "or a counter (False) for applying the prescale. In the latter case, the module will retain exactly "
53 "one event every N processed, where N (the counter value) is set for each line via the "
56 "If this is set to None a FATAL error will be raised if the results are missing. Otherwise the value "
59 "If the module is used inside the hbasf2, like HLT storage, the first event need to be skipped.",
m_firstEvent);
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 =
"";
115 available_lines += line +
"(" + std::to_string((
int)result) +
") ";
118 B2WARNING(
"Software trigger line not found" <<
LogVar(
"requested", name)
119 <<
LogVar(
"available", available_lines)
127 B2FATAL(
"Software trigger line not found (if this is expected, please use the `resultOnMissing` parameter)"
128 <<
LogVar(
"requested", name)
129 <<
LogVar(
"available", available_lines)
151 B2FATAL(
"No HLT Trigger result available (if this is expected to be possible "
152 "please use the `resultOnMissing` parameter");
155 size_t numAccepted(0);
157 size_t counterIndex{0};
161 [
this, &counterIndex](
const std::tuple<std::string, unsigned int>& line) {
162 const auto& [name, prescale] = line;
167 [
this](
const std::string& name) {
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
void setReturnValue(int value)
Sets the return value for this module as integer.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
bool m_firstEvent
Check event is the first event for hbasf2 usage, especiaaly for HLT storage.
std::string m_logicMode
do we want each or any trigger line?
virtual void initialize() override
Initialize.
std::optional< int > m_resultOnMissing
value to return if there's no SoftwareTriggerResult
virtual void event() override
Event function.
int m_expectedResult
Result we want for each or any trigger line.
std::vector< boost::variant< std::string, std::tuple< std::string, unsigned int > > > m_triggerLines
List of triggerlines we're interested in.
std::vector< uint32_t > m_prescaleCounters
if we don't use random prescale we need counters
bool m_useRandomNumbersForPreScale
and do we want random prescale or counters ?
StoreObjPtr< SoftwareTriggerResult > m_trigResults
Required input for trigger results.
StoreObjPtr< EventMetaData > m_eventMetaDataPtr
EventMetaData is used to report warning/error messages.
bool checkTrigger(const std::string &name, unsigned int prescale=1, uint32_t *counter=nullptr) const
Check a single trigger line for the expected result.
TriggerSkimModule()
Constructor: Sets the description, the properties and the parameters of the module.
Class to store variables with their name which were sent to the logging service.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
SoftwareTriggerCutResult
Enumeration with all possible results of the SoftwareTriggerCut.
Abstract base class for different kinds of events.
Helper struct for the C++17 std::visit overload pattern to allow simple use of variants.