4 #include "boost/algorithm/string.hpp" 15 using namespace fhicl;
18 using VCBDMP = vector<BranchDescription const*>;
27 partial_match(
string const& regularExpression,
string const& branchstring)
29 return regularExpression.empty() ?
31 std::regex_match(branchstring, std::regex(regularExpression));
42 static auto const branchTypeString =
43 "[Ii]n(?:(Event)|(SubRun)|(Run)|(Results))"s;
44 static std::regex
const branchTypeRE(branchTypeString);
46 static std::string
const rulesMsg =
47 "Syntax: keep|drop <spec> [<branchtype]>\n" 48 "where <spec> is EITHER \"*\" OR:\n" 49 "<friendly-type>_<module-label>_<instance-name>_<process-name>\n" 50 "Wildcards are permissible within each field: * (any number of " 52 "? (any single permissible character).\n" 53 "Permissible non-wildcard characters in all fields: [A-Za-z0-9].\n" 54 "Additionally, \"::\" is permissible in friendly type names, and\n" 55 "\"#\" is permissible in module labels.\n";
58 parseComponents(std::string s,
59 std::string
const& parameterName,
60 std::string
const& owner,
64 std::smatch ruleMatch;
65 static std::regex
const re(
66 "(keep|drop)\\s+(\\*|(?:[^_]*)_(?:[^_]*)_(?:[^_]*)" 67 "_(?:[^_\\s]*))(?:\\s+(.*))?");
69 if (!std::regex_match(s, ruleMatch, re)) {
71 <<
"Illegal product selection rule \"" << s
72 <<
"\" failed initial checks in " << owner <<
'.' << parameterName
76 selectflag = (ruleMatch[1].str() ==
"keep");
77 if (ruleMatch[2].str() ==
"*") {
87 if (!errMsg.empty()) {
89 << errMsg <<
"Error occurred in " << owner <<
'.' << parameterName
90 <<
" (exactly four components required if not \"*\").\n" 98 << errMsg <<
"Error occurred in " << owner <<
'.' << parameterName
111 if ((ruleMatch[3].length() > 0) &&
112 (ruleMatch[3] !=
"*")) {
114 auto const foundBT = ruleMatch[3].str();
115 if (std::regex_match(foundBT, btMatch, branchTypeRE)) {
117 assert(btMatch.size() ==
119 auto itFirstMatch = btMatch.begin();
121 auto it = std::find_if(itFirstMatch, btMatch.end(), [](
auto& s) {
122 return (s.length() > 0);
124 assert(it != btMatch.end());
125 components.
branchType_ = std::distance(itFirstMatch, it);
128 <<
"Invalid branch type specification \"" << ruleMatch[3] <<
"\" in " 129 << owner <<
" parameter named '" << parameterName
131 "If the optional branch type is specified, it must satisfy the " 132 "following regex: \"^" 133 << branchTypeString <<
"$\".\n" 143 string const& parameterName,
145 : components_{parseComponents(s, parameterName, owner,
selectflag_)}
150 vector<BranchSelectState>& branchstates)
const 152 for (
auto& state : branchstates)
159 for (
auto const& rule :
rules_)
160 rule.applyToAll(branchstates);
185 string const& parameterName,
186 string const& parameterOwnerName)
188 rules_.reserve(commands.size());
189 for (
auto const& cmd : commands) {
190 rules_.emplace_back(cmd, parameterName, parameterOwnerName);
192 keepAll_ = commands.size() == 1 && commands[0] ==
"keep *";
bool appliesTo(BranchDescription const *branch) const
bool checkBranchNameSelector(std::string const &branchNameSelector, std::string &errMsg)
GroupSelectorRules(std::vector< std::string > const &commands, std::string const ¶meterName, std::string const ¶meterOwnerName)
BranchKey splitToComponents(std::string const &branchName, std::string &errMsg)
vector< BranchDescription const * > VCBDMP
std::string productInstanceName_
void applyToAll(std::vector< BranchSelectState > &branchstates) const
std::string const & processName() const noexcept
BranchType branchType() const noexcept
std::string friendlyClassName_
void applyToAll(std::vector< BranchSelectState > &branchstates) const
std::string const & moduleLabel() const noexcept
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::string const & productInstanceName() const noexcept
std::vector< Rule > rules_
void applyToOne(BranchDescription const *branch, bool &result) const
std::string const & friendlyClassName() const noexcept
Rule(std::string const &s, std::string const ¶meterName, std::string const &owner)