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 55 of file DQMStore.h.

Member Enumeration Documentation

Enumerator
UseFull 
OneStarStart 
OneStarEnd 
TwoStar 

Definition at line 58 of file DQMStore.h.

Constructor & Destructor Documentation

fastmatch::fastmatch ( std::string  _fastString)

Definition at line 137 of file DQMStore.cc.

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

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

Referenced by match().

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

Definition at line 205 of file DQMStore.cc.

Referenced by match().

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

Definition at line 247 of file DQMStore.cc.

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

248 {
249  switch (matching_)
250  {
251  case OneStarStart:
253 
254  case OneStarEnd:
255  return compare_strings(fastString_, s);
256 
257  case TwoStar:
258  return (s.find(fastString_) != std::string::npos);
259 
260  default:
261  return regexp_->match(s);
262  }
263 }
bool compare_strings_reverse(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:205
MatchingHeuristicEnum matching_
Definition: DQMStore.h:75
std::string fastString_
Definition: DQMStore.h:74
bool compare_strings(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:226
std::unique_ptr< lat::Regexp > regexp_
Definition: DQMStore.h:73

Member Data Documentation

std::string fastmatch::fastString_
private

Definition at line 74 of file DQMStore.h.

Referenced by fastmatch(), and match().

MatchingHeuristicEnum fastmatch::matching_
private

Definition at line 75 of file DQMStore.h.

Referenced by fastmatch(), and match().

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

Definition at line 73 of file DQMStore.h.

Referenced by fastmatch(), and match().