4 #include "boost/algorithm/string.hpp" 7 #include "cetlib/container_algorithms.h" 17 using namespace fhicl;
20 using VCBDMP = vector<BranchDescription const*>;
29 partial_match(
string const& regularExpression,
string const& branchstring)
31 return regularExpression.empty() ?
33 std::regex_match(branchstring, std::regex(regularExpression));
44 static auto const branchTypeString =
45 "[Ii]n(?:(Event)|(SubRun)|(Run)|(Results))"s;
46 static std::regex
const branchTypeRE(branchTypeString);
48 static std::string
const rulesMsg =
49 "Syntax: keep|drop <spec> [<branchtype]>\n" 50 "where <spec> is EITHER \"*\" OR:\n" 51 "<friendly-type>_<module-label>_<instance-name>_<process-name>\n" 52 "Wildcards are permissible within each field: * (any number of " 54 "? (any single permissible character).\n" 55 "Permissible non-wildcard characters in all fields: [A-Za-z0-9].\n" 56 "Additionally, \"::\" is permissible in friendly type names, and\n" 57 "\"#\" is permissible in module labels.\n";
60 parseComponents(std::string
s,
61 std::string
const& parameterName,
62 std::string
const& owner,
66 std::smatch ruleMatch;
67 static std::regex
const re(
"(keep|drop)\\s+(\\*|(?:[^_]*)_(?:[^_]*)_(?:[^_]" 68 "*)_(?:[^_\\s]*))(?:\\s+(.*))?");
70 if (!std::regex_match(s, ruleMatch, re)) {
72 <<
"Illegal product selection rule \"" << s
73 <<
"\" failed initial checks in " << owner <<
'.' << parameterName
77 selectflag = (ruleMatch[1].str() ==
"keep");
78 if (ruleMatch[2].str() ==
"*") {
88 if (!errMsg.empty()) {
90 << errMsg <<
"Error occurred in " << owner <<
'.' << parameterName
91 <<
" (exactly four components required if not \"*\").\n" 99 << errMsg <<
"Error occurred in " << owner <<
'.' << parameterName
112 if ((ruleMatch[3].length() > 0) &&
113 (ruleMatch[3] !=
"*")) {
115 auto const foundBT = ruleMatch[3].str();
116 if (std::regex_match(foundBT, btMatch, branchTypeRE)) {
118 assert(btMatch.size() ==
120 auto itFirstMatch = btMatch.begin();
122 auto it = std::find_if(itFirstMatch, btMatch.end(), [](
auto&
s) {
123 return (s.length() > 0);
125 assert(it != btMatch.end());
126 components.
branchType_ = std::distance(itFirstMatch, it);
129 <<
"Invalid branch type specification \"" << ruleMatch[3] <<
"\" in " 130 << owner <<
" parameter named '" << parameterName
132 "If the optional branch type is specified, it must satisfy the " 133 "following regex: \"^" 134 << 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 friendlyClassName_
void applyToAll(std::vector< BranchSelectState > &branchstates) const
std::string const & moduleLabel() const
BranchType branchType() const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::string const & productInstanceName() const
std::vector< Rule > rules_
void applyToOne(BranchDescription const *branch, bool &result) const
std::string const & processName() const
std::string const & friendlyClassName() const
Rule(std::string const &s, std::string const ¶meterName, std::string const &owner)