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
 
 ~fastmatch ()
 

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_
 
lat::Regexp * regexp_
 

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

Constructor & Destructor Documentation

fastmatch::fastmatch ( std::string  _fastString)

Definition at line 134 of file DQMStore.cc.

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

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

Definition at line 204 of file DQMStore.cc.

References regexp_.

205 {
206  if (regexp_ != nullptr)
207  delete regexp_;
208 }
lat::Regexp * regexp_
Definition: DQMStore.h:73

Member Function Documentation

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

Definition at line 231 of file DQMStore.cc.

Referenced by match().

233 {
234  if (input.size() < pattern.size())
235  return false;
236 
237  // compare the two strings character by character for equalness:
238  // this does not create uneeded copies of std::string. The
239  // boost::algorithm implementation does.
240  std::string::const_iterator rit_pattern = pattern.begin();
241  std::string::const_iterator rit_input = input.begin();
242 
243  for (; rit_pattern < pattern.end(); rit_pattern++, rit_input++)
244  {
245  if (*rit_pattern != *rit_input)
246  // found a difference, fail
247  return false;
248  }
249  return true;
250 }
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 210 of file DQMStore.cc.

Referenced by match().

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

Definition at line 252 of file DQMStore.cc.

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

253 {
254  switch (matching_)
255  {
256  case OneStarStart:
258 
259  case OneStarEnd:
260  return compare_strings(fastString_, s);
261 
262  case TwoStar:
263  return (s.find(fastString_) != std::string::npos);
264 
265  default:
266  return regexp_->match(s);
267  }
268 }
bool compare_strings_reverse(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:210
MatchingHeuristicEnum matching_
Definition: DQMStore.h:75
lat::Regexp * regexp_
Definition: DQMStore.h:73
std::string fastString_
Definition: DQMStore.h:74
bool compare_strings(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:231

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().

lat::Regexp* fastmatch::regexp_
private

Definition at line 73 of file DQMStore.h.

Referenced by fastmatch(), match(), and ~fastmatch().