CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
fastmatch Class Reference

#include <DQMStore.h>

Public Member Functions

 fastmatch (std::string fastString)
 
bool match (std::string const &s) const
 

Private Types

enum  MatchingHeuristicEnum { UseFull, OneStarStart, OneStarEnd, TwoStar }
 

Private Member Functions

bool compare_strings (std::string const &pattern, std::string const &input) const
 
bool compare_strings_reverse (std::string const &pattern, std::string const &input) const
 

Private Attributes

std::string fastString_
 
MatchingHeuristicEnum matching_
 
std::unique_ptr< lat::Regexp > regexp_ {nullptr}
 

Detailed Description

Implements RegEx patterns which occur often in a high-performant mattern. For all other expressions, the full RegEx engine is used. Note: this class can only be used for lat::Regexp::Wildcard-like patterns.

Definition at line 54 of file DQMStore.h.

Member Enumeration Documentation

Enumerator
UseFull 
OneStarStart 
OneStarEnd 
TwoStar 

Definition at line 55 of file DQMStore.h.

Constructor & Destructor Documentation

fastmatch::fastmatch ( std::string  fastString)

Definition at line 141 of file DQMStore.cc.

References MillePedeFileConverter_cfg::e, fastString_, matching_, eostools::move(), OneStarEnd, OneStarStart, raiseDQMError(), regexp_, TwoStar, and UseFull.

141  :
142  fastString_{move(fastString)}, matching_{UseFull}
143 {
144  try {
145  regexp_ = std::make_unique<lat::Regexp>(fastString_, 0, lat::Regexp::Wildcard);
146  regexp_->study();
147  }
148  catch (lat::Error&e) {
149  raiseDQMError("DQMStore", "Invalid wildcard pattern '%s' in quality"
150  " test specification", fastString_.c_str());
151  }
152 
153  // count stars ( "*" )
154  size_t starCount = 0;
155  int pos = -1;
156  while (true) {
157  pos = fastString_.find('*', pos + 1 );
158  if ((size_t)pos == std::string::npos)
159  break;
160  ++starCount;
161  }
162 
163  // investigate for heuristics
164  if ((fastString_.find('"') != std::string::npos) ||
165  (fastString_.find(']') != std::string::npos) ||
166  (fastString_.find('?') != std::string::npos) ||
167  (fastString_.find('\\') != std::string::npos) ||
168  (starCount > 2)) {
169  // no fast version can be used
170  return;
171  }
172 
173  // match for pattern "*MyString" and "MyString*"
174  if (starCount == 1) {
175  if (boost::algorithm::starts_with(fastString_, "*")) {
177  fastString_.erase(0,1);
178  return;
179  }
180 
181  if (boost::algorithm::ends_with(fastString_, "*")) {
183  fastString_.erase(fastString_.length()-1,1);
184  return;
185  }
186  }
187 
188  // match for pattern "*MyString*"
189  if (starCount == 2) {
190  if (boost::algorithm::starts_with(fastString_, "*") &&
191  boost::algorithm::ends_with(fastString_, "*")) {
192  matching_ = TwoStar;
193  fastString_.erase(0,1);
194  fastString_.erase(fastString_.size() - 1, 1);
195  return;
196  }
197  }
198 }
edm::ErrorSummaryEntry Error
MatchingHeuristicEnum matching_
Definition: DQMStore.h:72
std::string fastString_
Definition: DQMStore.h:71
def move(src, dest)
Definition: eostools.py:511
std::unique_ptr< lat::Regexp > regexp_
Definition: DQMStore.h:70
void raiseDQMError(const char *context, const char *fmt,...)
Definition: DQMError.cc:11

Member Function Documentation

bool fastmatch::compare_strings ( std::string const &  pattern,
std::string const &  input 
) const
private

Definition at line 220 of file DQMStore.cc.

Referenced by match().

222 {
223  if (input.size() < pattern.size())
224  return false;
225 
226  // compare the two strings character by character for equalness:
227  // this does not create uneeded copies of std::string. The
228  // boost::algorithm implementation does.
229  auto rit_pattern = pattern.cbegin();
230  auto rit_input = input.cbegin();
231 
232  for (; rit_pattern < pattern.end(); ++rit_pattern, ++rit_input) {
233  if (*rit_pattern != *rit_input)
234  // found a difference, fail
235  return false;
236  }
237  return true;
238 }
static std::string const input
Definition: EdmProvDump.cc:48
bool fastmatch::compare_strings_reverse ( std::string const &  pattern,
std::string const &  input 
) const
private

Definition at line 200 of file DQMStore.cc.

Referenced by match().

202 {
203  if (input.size() < pattern.size())
204  return false;
205 
206  // compare the two strings character by character for equalness:
207  // this does not create uneeded copies of std::string. The
208  // boost::algorithm implementation does
209  auto rit_pattern = pattern.crbegin();
210  auto rit_input = input.crbegin();
211 
212  for (; rit_pattern < pattern.rend(); ++rit_pattern, ++rit_input) {
213  if (*rit_pattern != *rit_input)
214  // found a difference, fail
215  return false;
216  }
217  return true;
218 }
static std::string const input
Definition: EdmProvDump.cc:48
bool fastmatch::match ( std::string const &  s) const

Definition at line 240 of file DQMStore.cc.

References compare_strings(), compare_strings_reverse(), fastString_, matching_, OneStarEnd, OneStarStart, regexp_, and TwoStar.

241 {
242  switch (matching_) {
243  case OneStarStart:
245 
246  case OneStarEnd:
247  return compare_strings(fastString_, s);
248 
249  case TwoStar:
250  return (s.find(fastString_) != std::string::npos);
251 
252  default:
253  return regexp_->match(s);
254  }
255 }
bool compare_strings_reverse(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:200
MatchingHeuristicEnum matching_
Definition: DQMStore.h:72
std::string fastString_
Definition: DQMStore.h:71
bool compare_strings(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:220
std::unique_ptr< lat::Regexp > regexp_
Definition: DQMStore.h:70

Member Data Documentation

std::string fastmatch::fastString_
private

Definition at line 71 of file DQMStore.h.

Referenced by fastmatch(), and match().

MatchingHeuristicEnum fastmatch::matching_
private

Definition at line 72 of file DQMStore.h.

Referenced by fastmatch(), and match().

std::unique_ptr<lat::Regexp> fastmatch::regexp_ {nullptr}
private

Definition at line 70 of file DQMStore.h.

Referenced by fastmatch(), and match().