CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
edm::ProductSelectorRules::Rule Class Reference

Public Member Functions

bool appliesTo (BranchDescription const *branch) const
 
void applyToAll (std::vector< BranchSelectState > &branchstates) const
 
void applyToOne (BranchDescription const *branch, bool &result) const
 
 Rule (std::string const &s, std::string const &parameterName, std::string const &owner)
 

Private Attributes

std::regex instanceName_
 
std::regex moduleLabel_
 
std::regex processName_
 
std::regex productType_
 
bool selectflag_
 

Detailed Description

Definition at line 52 of file ProductSelectorRules.h.

Constructor & Destructor Documentation

edm::ProductSelectorRules::Rule::Rule ( std::string const &  s,
std::string const &  parameterName,
std::string const &  owner 
)

Definition at line 57 of file ProductSelectorRules.cc.

References edm::errors::Configuration, Exception, mps_fire::i, instanceName_, moduleLabel_, CfgNavigationSchool_cfi::parts, processName_, productType_, selectflag_, findQualityFiles::size, split, AlCaHLTBitMon_QueryRunRegistry::string, and trim().

59  if (s.size() < 6)
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"
66  << " " << s << "\n"
67  << "Exception thrown from ProductSelectorRules::Rule\n";
68 
69  if (s.substr(0, 4) == "keep")
70  selectflag_ = true;
71  else if (s.substr(0, 4) == "drop")
72  selectflag_ = false;
73  else
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"
79  << " " << s << "\n"
80  << "Exception thrown from ProductSelectorRules::Rule\n";
81 
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"
88  << " " << s << "\n"
89  << "Exception thrown from ProductSelectorRules::Rule\n";
90  }
91 
92  // Now pull apart the std::string to get at the bits and pieces of the
93  // specification...
94 
95  // Grab from after 'keep/drop ' (note the space!) to the end of
96  // the std::string...
97  std::string spec(s.begin() + 5, s.end());
98 
99  // Trim any leading and trailing whitespace from spec
100  boost::trim(spec);
101 
102  if (spec == "*") // special case for wildcard
103  {
104  productType_ = ".*";
105  moduleLabel_ = ".*";
106  instanceName_ = ".*";
107  processName_ = ".*";
108  return;
109  } else {
110  std::vector<std::string> parts;
111  boost::split(parts, spec, boost::is_any_of("_"));
112 
113  // The std::vector must contain at least 4 parts
114  // and none may be empty.
115  bool good = (parts.size() == 4);
116 
117  // Require all the std::strings to contain only alphanumberic
118  // characters or "*" or "?"
119  if (good) {
120  for (int i = 0; i < 4; ++i) {
121  std::string& field = parts[i];
122  int size = field.size();
123  for (int j = 0; j < size; ++j) {
124  if (!(isalnum(field[j]) || field[j] == '*' || field[j] == '?')) {
125  good = false;
126  }
127  }
128 
129  // We are using the boost regex library to deal with the wildcards.
130  // The configuration file uses a syntax that accepts "*" and "?"
131  // as wildcards so we need to convert these to the syntax used in
132  // regular expressions.
133  boost::replace_all(parts[i], "*", ".*");
134  boost::replace_all(parts[i], "?", ".");
135  }
136  }
137 
138  if (!good) {
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"
148  << " " << s << "\n"
149  << "Exception thrown from ProductSelectorRules::Rule\n";
150  }
151 
152  productType_ = parts[0];
153  moduleLabel_ = parts[1];
154  instanceName_ = parts[2];
155  processName_ = parts[3];
156  }
157  }
size
Write out results.
static void trim(std::string &s)
double split
Definition: MVATrainer.cc:139

Member Function Documentation

bool edm::ProductSelectorRules::Rule::appliesTo ( edm::BranchDescription const *  branch) const

Definition at line 190 of file ProductSelectorRules.cc.

References edm::BranchDescription::friendlyClassName(), instanceName_, edm::BranchDescription::moduleLabel(), moduleLabel_, edm::BranchDescription::processName(), processName_, edm::BranchDescription::productInstanceName(), and productType_.

Referenced by applyToOne().

190  {
191  return partial_match(productType_, branch->friendlyClassName()) &&
192  partial_match(moduleLabel_, branch->moduleLabel()) &&
193  partial_match(instanceName_, branch->productInstanceName()) &&
194  partial_match(processName_, branch->processName());
195  }
void edm::ProductSelectorRules::Rule::applyToAll ( std::vector< BranchSelectState > &  branchstates) const

Definition at line 159 of file ProductSelectorRules.cc.

References applyToOne(), and end.

159  {
160  std::vector<BranchSelectState>::iterator it = branchstates.begin();
161  std::vector<BranchSelectState>::iterator end = branchstates.end();
162  for (; it != end; ++it)
163  applyToOne(it->desc, it->selectMe);
164  }
void applyToOne(BranchDescription const *branch, bool &result) const
#define end
Definition: vmac.h:39
void edm::ProductSelectorRules::Rule::applyToOne ( edm::BranchDescription const *  branch,
bool &  result 
) const

Definition at line 185 of file ProductSelectorRules.cc.

References appliesTo(), and selectflag_.

Referenced by applyToAll().

185  {
186  if (this->appliesTo(branch))
188  }
bool appliesTo(BranchDescription const *branch) const

Member Data Documentation

std::regex edm::ProductSelectorRules::Rule::instanceName_
private

Definition at line 80 of file ProductSelectorRules.h.

Referenced by appliesTo(), and Rule().

std::regex edm::ProductSelectorRules::Rule::moduleLabel_
private
std::regex edm::ProductSelectorRules::Rule::processName_
private

Definition at line 81 of file ProductSelectorRules.h.

Referenced by appliesTo(), and Rule().

std::regex edm::ProductSelectorRules::Rule::productType_
private

Definition at line 78 of file ProductSelectorRules.h.

Referenced by appliesTo(), and Rule().

bool edm::ProductSelectorRules::Rule::selectflag_
private

Definition at line 77 of file ProductSelectorRules.h.

Referenced by applyToOne(), and Rule().