6 #include "boost/algorithm/string.hpp" 17 typedef std::vector<edm::BranchDescription const*>
VCBDP;
24 inline bool partial_match(
const std::regex& regularExpression,
const std::string& branchstring) {
25 return std::regex_match(branchstring, regularExpression);
58 : selectflag_(), productType_(), moduleLabel_(), instanceName_(), processName_() {
61 <<
"Invalid statement in configuration file\n" 62 <<
"In " << owner <<
" parameter named '" << parameterName <<
"'\n" 63 <<
"Rule must have at least 6 characters because it must\n" 64 <<
"specify 'keep ' or 'drop ' and also supply a pattern.\n" 65 <<
"This is the invalid output configuration rule:\n" 67 <<
"Exception thrown from ProductSelectorRules::Rule\n";
69 if (s.substr(0, 4) ==
"keep")
71 else if (s.substr(0, 4) ==
"drop")
75 <<
"Invalid statement in configuration file\n" 76 <<
"In " << owner <<
" parameter named '" << parameterName <<
"'\n" 77 <<
"Rule must specify 'keep ' or 'drop ' and also supply a pattern.\n" 78 <<
"This is the invalid output configuration rule:\n" 80 <<
"Exception thrown from ProductSelectorRules::Rule\n";
82 if (!std::isspace(s[4])) {
84 <<
"Invalid statement in configuration file\n" 85 <<
"In " << owner <<
" parameter named '" << parameterName <<
"'\n" 86 <<
"In each rule, 'keep' or 'drop' must be followed by a space\n" 87 <<
"This is the invalid output configuration rule:\n" 89 <<
"Exception thrown from ProductSelectorRules::Rule\n";
110 std::vector<std::string>
parts;
115 bool good = (parts.size() == 4);
120 for (
int i = 0;
i < 4; ++
i) {
122 int size = field.size();
123 for (
int j = 0; j <
size; ++j) {
124 if (!(isalnum(field[j]) || field[j] ==
'*' || field[j] ==
'?')) {
133 boost::replace_all(parts[
i],
"*",
".*");
134 boost::replace_all(parts[i],
"?",
".");
140 <<
"Invalid statement in configuration file\n" 141 <<
"In " << owner <<
" parameter named '" << parameterName <<
"'\n" 142 <<
"In each rule, after 'keep ' or 'drop ' there must\n" 143 <<
"be a branch specification of the form 'type_label_instance_process'\n" 144 <<
"There must be 4 fields separated by underscores\n" 145 <<
"The fields can only contain alphanumeric characters and the wildcards * or ?\n" 146 <<
"Alternately, a single * is also allowed for the branch specification\n" 147 <<
"This is the invalid output configuration rule:\n" 149 <<
"Exception thrown from ProductSelectorRules::Rule\n";
160 std::vector<BranchSelectState>::iterator it = branchstates.begin();
161 std::vector<BranchSelectState>::iterator
end = branchstates.end();
162 for (; it !=
end; ++it)
167 std::vector<Rule>::const_iterator it =
rules_.begin();
168 std::vector<Rule>::const_iterator
end =
rules_.end();
169 for (; it !=
end; ++it)
170 it->applyToAll(branchstates);
198 static const std::vector<std::string> s_defaultStrings(1
U,
std::string(
"keep *"));
199 return s_defaultStrings;
203 char const* parameterName,
204 std::vector<std::string>
const& defaultStrings) {
206 desc.
addUntracked<std::vector<std::string> >(parameterName, defaultStrings)
207 ->setComment(
"Specifies which branches are kept or dropped.");
217 std::vector<std::string> defaultCommands(1
U,
std::string(
"keep *"));
221 if (commands.empty()) {
222 commands.push_back(defaultCommands[0]);
224 rules_.reserve(commands.size());
225 for (std::vector<std::string>::const_iterator it = commands.begin(),
end = commands.end(); it !=
end; ++it) {
226 rules_.push_back(
Rule(*it, parameterName, parameterOwnerName));
228 keepAll_ = commands.size() == 1 && commands[0] == defaultCommands[0];
T getUntrackedParameter(std::string const &, T const &) const
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static const std::vector< std::string > & defaultSelectionStrings()
void applyToOne(BranchDescription const *branch, bool &result) const
static void trim(std::string &s)
std::string const & processName() const
static void fillDescription(ParameterSetDescription &desc, char const *parameterName, std::vector< std::string > const &defaultStrings=defaultSelectionStrings())
void applyToAll(std::vector< BranchSelectState > &branchstates) const
Rule(std::string const &s, std::string const ¶meterName, std::string const &owner)
std::string const & moduleLabel() const
std::string const & productInstanceName() const
ProductSelectorRules(ParameterSet const &pset, std::string const ¶meterName, std::string const ¶meterOwnerName)
std::vector< Rule > rules_
commands
min number of hits for refit layers to remove
bool appliesTo(BranchDescription const *branch) const
std::string const & friendlyClassName() const
std::string parameterName_
std::vector< edm::BranchDescription const * > VCBDP
void applyToAll(std::vector< BranchSelectState > &branchstates) const
std::string parameterOwnerName_