6 #include "boost/algorithm/string.hpp"
17 typedef std::vector<edm::BranchDescription const*>
VCBDP;
27 partial_match(
const boost::regex& regularExpression,
28 const std::string& branchstring)
30 if (regularExpression.empty()) {
31 if (branchstring ==
"")
return true;
34 return boost::regex_match(branchstring, regularExpression);
75 <<
"Invalid statement in configuration file\n"
76 <<
"In " << owner <<
" parameter named '" << parameterName <<
"'\n"
77 <<
"Rule must have at least 6 characters because it must\n"
78 <<
"specify 'keep ' or 'drop ' and also supply a pattern.\n"
79 <<
"This is the invalid output configuration rule:\n"
81 <<
"Exception thrown from GroupSelectorRules::Rule\n";
83 if (s.substr(0,4) ==
"keep")
85 else if (s.substr(0,4) ==
"drop")
89 <<
"Invalid statement in configuration file\n"
90 <<
"In " << owner <<
" parameter named '" << parameterName <<
"'\n"
91 <<
"Rule must specify 'keep ' or 'drop ' and also supply a pattern.\n"
92 <<
"This is the invalid output configuration rule:\n"
94 <<
"Exception thrown from GroupSelectorRules::Rule\n";
96 if ( !std::isspace(s[4]) ) {
99 <<
"Invalid statement in configuration file\n"
100 <<
"In " << owner <<
" parameter named '" << parameterName <<
"'\n"
101 <<
"In each rule, 'keep' or 'drop' must be followed by a space\n"
102 <<
"This is the invalid output configuration rule:\n"
104 <<
"Exception thrown from GroupSelectorRules::Rule\n";
112 std::string spec(s.begin()+5, s.end());
127 std::vector<std::string>
parts;
132 bool good = (parts.size() == 4);
138 for (
int i = 0;
i < 4; ++
i) {
139 std::string& field = parts[
i];
140 int size = field.size();
141 for (
int j = 0;
j <
size; ++
j) {
142 if ( !(isalnum(field[
j]) || field[j] ==
'*' || field[j] ==
'?') ) {
151 boost::replace_all(parts[
i],
"*",
".*");
152 boost::replace_all(parts[i],
"?",
".");
159 <<
"Invalid statement in configuration file\n"
160 <<
"In " << owner <<
" parameter named '" << parameterName <<
"'\n"
161 <<
"In each rule, after 'keep ' or 'drop ' there must\n"
162 <<
"be a branch specification of the form 'type_label_instance_process'\n"
163 <<
"There must be 4 fields separated by underscores\n"
164 <<
"The fields can only contain alphanumeric characters and the wildcards * or ?\n"
165 <<
"Alternately, a single * is also allowed for the branch specification\n"
166 <<
"This is the invalid output configuration rule:\n"
168 <<
"Exception thrown from GroupSelectorRules::Rule\n";
184 std::vector<BranchSelectState>::iterator it = branchstates.begin();
185 std::vector<BranchSelectState>::iterator
end = branchstates.end();
186 for (; it !=
end; ++it) applyToOne(it->desc, it->selectMe);
191 std::vector<Rule>::const_iterator it =
rules_.begin();
192 std::vector<Rule>::const_iterator
end =
rules_.end();
193 for (; it !=
end; ++it) it->applyToAll(branchstates);
212 if (this->appliesTo(branch)) result = selectflag_;
220 partial_match(moduleLabel_, branch->
moduleLabel()) &&
222 partial_match(processName_, branch->
processName());
227 std::vector<std::string> defaultStrings(1U, std::string(
"keep *"));
228 desc.
addUntracked<std::vector<std::string> >(parameterName, defaultStrings)
229 ->setComment(
"Specifies which branches are kept or dropped.");
233 std::string
const& parameterName,
234 std::string
const& parameterOwnerName) :
242 std::vector<std::string> defaultCommands(1U, std::string(
"keep *"));
244 std::vector<std::string> commands =
247 if (commands.empty()) {
248 commands.push_back(defaultCommands[0]);
250 rules_.reserve(commands.size());
251 for(std::vector<std::string>::const_iterator it = commands.begin(),
end = commands.end();
253 rules_.push_back(
Rule(*it, parameterName, parameterOwnerName));
255 keepAll_ = commands.size() == 1 && commands[0] == defaultCommands[0];
T getUntrackedParameter(std::string const &, T const &) const
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
std::string parameterName_
std::string const & processName() const
static void fillDescription(ParameterSetDescription &desc, char const *parameterName)
boost::regex instanceName_
std::string parameterOwnerName_
void applyToOne(BranchDescription const *branch, bool &result) const
std::string const & moduleLabel() const
std::string const & productInstanceName() const
std::string const & friendlyClassName() const
boost::regex processName_
void applyToAll(std::vector< BranchSelectState > &branchstates) const
std::vector< edm::BranchDescription const * > VCBDP
Rule(std::string const &s, std::string const ¶meterName, std::string const &owner)
boost::regex moduleLabel_
boost::regex productType_
GroupSelectorRules(ParameterSet const &pset, std::string const ¶meterName, std::string const ¶meterOwnerName)
bool appliesTo(BranchDescription const *branch) const
std::vector< Rule > rules_
void applyToAll(std::vector< BranchSelectState > &branchstates) const
tuple size
Write out results.