9 #include "cetlib/container_algorithms.h" 14 #include "range/v3/view.hpp" 29 path_position(vector<string>
const& trigger_path_names,
32 return distance(trigger_path_names.begin(), it);
36 remove_noexception(std::string
const& full_path_specifier,
37 std::string& specifier)
39 string const noexLiteral{
"&noexception"};
40 auto const noexception_pos = specifier.find(noexLiteral);
41 if (noexception_pos == string::npos) {
45 if ((noexception_pos + noexLiteral.length()) < specifier.length()) {
47 <<
"EventSelector::init, A module is using SelectEvents\n" 48 <<
"to request a trigger name that has extra characters after " 50 <<
"The improper trigger name is: " << full_path_specifier <<
'\n';
52 specifier.erase(noexception_pos);
57 remove_negation(std::string& specifier)
59 if (specifier[0] !=
'!') {
62 specifier.erase(0, 1);
67 remove_exception(std::string
const& full_path_specifier,
68 std::string& specifier)
71 string const exLiteral{
"exception@"};
72 auto const pos = specifier.find(exLiteral);
74 specifier.erase(0, exLiteral.length());
79 if (pos != string::npos) {
81 <<
"EventSelector::init, A module is using SelectEvents\n" 82 <<
"to request a trigger name that has disallowed characters before " 84 <<
"The improper trigger name is: " << full_path_specifier <<
'\n';
93 any_bit(vector<BitInfo>
const& bits,
99 begin(bits),
end(bits), [check_for_exception, &tr](
auto const& b) {
103 return tr.
at(b.pos).
state() == bstate;
112 return std::all_of(
begin(bits),
end(bits), [&tr](
auto const& b) {
114 return tr.
at(b.pos).
state() == bstate;
121 if (
empty(path_specs)) {
127 bool unrestricted_star =
false;
128 bool negated_star =
false;
129 bool exception_star =
false;
131 for (
string const& pathSpecifier : path_specs) {
134 if (pathSpecifier ==
"*") {
135 unrestricted_star =
true;
136 }
else if (pathSpecifier ==
"!*") {
138 }
else if (pathSpecifier ==
"exception@*") {
139 exception_star =
true;
142 return unrestricted_star && negated_star && exception_star;
166 <<
"EventSelector::acceptEvent cannot find the trigger names for\n" 167 <<
"a process for which the configuration has requested that the\n" 168 <<
"OutputModule use TriggerResults to select events from. This " 170 <<
"be impossible, please send information to reproduce this problem " 172 <<
"the art developers at artists@fnal.gov.\n";
174 auto const trigger_path_specs =
175 pset.
get<vector<string>>(
"trigger_paths", {});
176 if (trigger_path_specs.size() != tr.
size()) {
178 <<
"EventSelector::acceptEvent: Trigger names vector and\n" 179 <<
"TriggerResults are different sizes. This should be impossible,\n" 180 <<
"please send information to reproduce this problem to\n" 181 <<
"the art developers.\n";
184 std::vector<BitInfo> absolute_acceptors;
185 std::vector<BitInfo> conditional_acceptors;
186 std::vector<BitInfo> exception_acceptors;
187 std::vector<std::vector<BitInfo>> all_must_fail;
188 std::vector<std::vector<BitInfo>> all_must_fail_noex;
191 string specifier{pathSpecifier};
193 bool const noex_demanded = remove_noexception(pathSpecifier, specifier);
194 bool const negative_criterion = remove_negation(specifier);
195 bool const exception_spec = remove_exception(pathSpecifier, specifier);
197 if (negative_criterion && exception_spec) {
199 <<
"EventSelector::init, A module is using SelectEvents\n" 200 <<
"to request a trigger name starting with !exception@.\n" 201 <<
"This is not supported.\n" 202 <<
"The improper trigger name is: " << pathSpecifier <<
'\n';
205 if (noex_demanded && exception_spec) {
207 <<
"EventSelector::init, A module is using SelectEvents\n" 208 <<
"to request a trigger name starting with exception@ " 209 <<
"and also demanding &noexception.\n" 210 <<
"The improper trigger name is: " << pathSpecifier <<
'\n';
218 string const& realname{specifier};
219 auto const matches =
regexMatch(trigger_path_specs, realname);
220 if (matches.empty()) {
223 <<
"EventSelector::init, A module is using SelectEvents\n" 224 "to request a wildcarded trigger name that does not match any " 226 "The wildcarded trigger name is: " 228 <<
" (from trigger-path specification: " << pathSpecifier <<
")";
231 <<
"EventSelector::init, A module is using SelectEvents\n" 232 "to request a trigger name that does not exist.\n" 233 "The unknown trigger name is: " 235 <<
" (from trigger-path specification: " << pathSpecifier <<
") \n";
239 auto makeBitInfoPass = [&trigger_path_specs](
auto m) {
240 return BitInfo{path_position(trigger_path_specs, m),
true};
242 auto makeBitInfoFail = [&trigger_path_specs](
auto m) {
243 return BitInfo{path_position(trigger_path_specs, m),
false};
246 if (!negative_criterion && !noex_demanded && !exception_spec) {
248 matches, back_inserter(absolute_acceptors), makeBitInfoPass);
252 if (!negative_criterion && noex_demanded) {
254 matches, back_inserter(conditional_acceptors), makeBitInfoPass);
258 if (exception_spec) {
260 matches, back_inserter(exception_acceptors), makeBitInfoPass);
264 if (negative_criterion && !noex_demanded) {
265 if (matches.empty()) {
267 <<
"EventSelector::init, A module is using SelectEvents\n" 268 "to request all fails on a set of trigger names that do not " 270 <<
"The problematic name is: " << pathSpecifier <<
'\n';
273 if (matches.size() == 1) {
274 BitInfo bi{path_position(trigger_path_specs, matches[0]),
false};
275 absolute_acceptors.push_back(bi);
278 auto must_fail = matches |
279 ::ranges::views::transform(makeBitInfoFail) |
281 all_must_fail.push_back(std::move(must_fail));
286 if (negative_criterion && noex_demanded) {
287 if (matches.empty()) {
289 <<
"EventSelector::init, A module is using SelectEvents\n" 290 "to request all fails on a set of trigger names that do not " 292 <<
"The problematic name is: " << pathSpecifier <<
'\n';
295 if (matches.size() == 1) {
296 BitInfo bi{path_position(trigger_path_specs, matches[0]),
false};
297 conditional_acceptors.push_back(bi);
299 auto must_fail = matches |
300 ::ranges::views::transform(makeBitInfoFail) |
302 all_must_fail_noex.push_back(std::move(must_fail));
308 conditional_acceptors,
341 bool exceptionPresent =
false;
342 bool exceptionsLookedFor =
false;
344 exceptionPresent = tr.
error();
345 if (!exceptionPresent) {
348 exceptionsLookedFor =
true;
356 if (all_bits(
f, tr)) {
362 if (all_bits(fn, tr)) {
363 if (!exceptionsLookedFor) {
364 exceptionPresent = tr.
error();
366 return !exceptionPresent;
std::vector< std::string > const path_specs_
PerScheduleContainer< ScheduleData > acceptors_
static collection_type const & get() noexcept
std::vector< std::vector< std::string >::const_iterator > regexMatch(std::vector< std::string > const &strings, std::string const &pattern)
std::vector< BitInfo > conditional_acceptors
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
fhicl::ParameterSetID const & parameterSetID() const
std::vector< std::vector< BitInfo > > all_must_fail_noex
std::vector< PathSpec > path_specs(std::vector< std::string > const &path_spec_strs)
bool acceptEvent(ScheduleID id, TriggerResults const &tr) const
T get(std::string const &key) const
std::vector< BitInfo > absolute_acceptors
bool has_whitespace(std::string const &str)
std::vector< std::vector< BitInfo > > all_must_fail
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
HLTPathStatus const & at(unsigned const i) const
ScheduleData data_for(TriggerResults const &tr) const
bool selectionDecision(ScheduleData const &data, HLTGlobalStatus const &) const
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
EventSelector::BitInfo BitInfo
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
hlt::HLTState state() const
std::vector< BitInfo > exception_acceptors
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
bool is_glob(std::string const &pattern)
EventSelector(std::vector< std::string > const &pathspecs)