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 const &_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 51 of file DQMStore.h.

Member Enumeration Documentation

Enumerator
UseFull 
OneStarStart 
OneStarEnd 
TwoStar 

Definition at line 54 of file DQMStore.h.

Constructor & Destructor Documentation

fastmatch::fastmatch ( std::string const &  _fastString)

Definition at line 132 of file DQMStore.cc.

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

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

Definition at line 202 of file DQMStore.cc.

References NULL, and regexp_.

203 {
204  if (regexp_ != NULL)
205  delete regexp_;
206 }
#define NULL
Definition: scimark2.h:8
lat::Regexp * regexp_
Definition: DQMStore.h:70

Member Function Documentation

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

Definition at line 229 of file DQMStore.cc.

Referenced by match().

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

Referenced by match().

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

Definition at line 250 of file DQMStore.cc.

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

251 {
252  switch (matching_)
253  {
254  case OneStarStart:
256 
257  case OneStarEnd:
258  return compare_strings(fastString_, s);
259 
260  case TwoStar:
261  return (s.find(fastString_) != std::string::npos);
262 
263  default:
264  return regexp_->match(s);
265  }
266 }
bool compare_strings_reverse(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:208
MatchingHeuristicEnum matching_
Definition: DQMStore.h:72
lat::Regexp * regexp_
Definition: DQMStore.h:70
std::string fastString_
Definition: DQMStore.h:71
bool compare_strings(std::string const &pattern, std::string const &input) const
Definition: DQMStore.cc:229

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

lat::Regexp* fastmatch::regexp_
private

Definition at line 70 of file DQMStore.h.

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