CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

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

Detailed Description

Definition at line 49 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 66 of file ProductSelectorRules.cc.

References edm::errors::Configuration, Exception, i, instanceName_, j, moduleLabel_, contentValuesFiles::parts, processName_, productType_, selectflag_, findQualityFiles::size, split, and AlCaHLTBitMon_QueryRunRegistry::string.

66  :
67  selectflag_(),
68  productType_(),
69  moduleLabel_(),
70  instanceName_(),
71  processName_()
72  {
73  if (s.size() < 6)
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"
80  << " " << s << "\n"
81  << "Exception thrown from ProductSelectorRules::Rule\n";
82 
83  if (s.substr(0,4) == "keep")
84  selectflag_ = true;
85  else if (s.substr(0,4) == "drop")
86  selectflag_ = false;
87  else
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"
93  << " " << s << "\n"
94  << "Exception thrown from ProductSelectorRules::Rule\n";
95 
96  if ( !std::isspace(s[4]) ) {
97 
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"
103  << " " << s << "\n"
104  << "Exception thrown from ProductSelectorRules::Rule\n";
105  }
106 
107  // Now pull apart the std::string to get at the bits and pieces of the
108  // specification...
109 
110  // Grab from after 'keep/drop ' (note the space!) to the end of
111  // the std::string...
112  std::string spec(s.begin()+5, s.end());
113 
114  // Trim any leading and trailing whitespace from spec
115  boost::trim(spec);
116 
117  if (spec == "*") // special case for wildcard
118  {
119  productType_ = ".*";
120  moduleLabel_ = ".*";
121  instanceName_ = ".*";
122  processName_ = ".*";
123  return;
124  }
125  else
126  {
127  std::vector<std::string> parts;
128  boost::split(parts, spec, boost::is_any_of("_"));
129 
130  // The std::vector must contain at least 4 parts
131  // and none may be empty.
132  bool good = (parts.size() == 4);
133 
134  // Require all the std::strings to contain only alphanumberic
135  // characters or "*" or "?"
136  if (good)
137  {
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] == '?') ) {
143  good = false;
144  }
145  }
146 
147  // We are using the boost regex library to deal with the wildcards.
148  // The configuration file uses a syntax that accepts "*" and "?"
149  // as wildcards so we need to convert these to the syntax used in
150  // regular expressions.
151  boost::replace_all(parts[i], "*", ".*");
152  boost::replace_all(parts[i], "?", ".");
153  }
154  }
155 
156  if (!good)
157  {
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"
167  << " " << s << "\n"
168  << "Exception thrown from ProductSelectorRules::Rule\n";
169  }
170 
171  // Assign the std::strings to the regex (regular expression) objects
172  // If the std::string is empty we skip the assignment and leave
173  // the regular expression also empty.
174 
175  if (parts[0] != "") productType_ = parts[0];
176  if (parts[1] != "") moduleLabel_ = parts[1];
177  if (parts[2] != "") instanceName_ = parts[2];
178  if (parts[3] != "") processName_ = parts[3];
179  }
180  }
int i
Definition: DBlmapReader.cc:9
int j
Definition: DBlmapReader.cc:9
double split
Definition: MVATrainer.cc:139
tuple size
Write out results.

Member Function Documentation

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

Definition at line 216 of file ProductSelectorRules.cc.

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

217  {
218  return
219  partial_match(productType_, branch->friendlyClassName()) &&
220  partial_match(moduleLabel_, branch->moduleLabel()) &&
221  partial_match(instanceName_, branch->productInstanceName()) &&
222  partial_match(processName_, branch->processName());
223  }
void edm::ProductSelectorRules::Rule::applyToAll ( std::vector< BranchSelectState > &  branchstates) const

Definition at line 183 of file ProductSelectorRules.cc.

References end.

183  {
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);
187  }
void applyToOne(BranchDescription const *branch, bool &result) const
#define end
Definition: vmac.h:37
void edm::ProductSelectorRules::Rule::applyToOne ( edm::BranchDescription const *  branch,
bool &  result 
) const

Definition at line 209 of file ProductSelectorRules.cc.

211  {
212  if (this->appliesTo(branch)) result = selectflag_;
213  }
tuple result
Definition: query.py:137
bool appliesTo(BranchDescription const *branch) const

Member Data Documentation

boost::regex edm::ProductSelectorRules::Rule::instanceName_
private

Definition at line 77 of file ProductSelectorRules.h.

Referenced by Rule().

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

Definition at line 78 of file ProductSelectorRules.h.

Referenced by Rule().

boost::regex edm::ProductSelectorRules::Rule::productType_
private

Definition at line 75 of file ProductSelectorRules.h.

Referenced by Rule().

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

Definition at line 74 of file ProductSelectorRules.h.

Referenced by Rule().