CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Utils.cc
Go to the documentation of this file.
2 
3 #include <stdio.h>
4 #include <regex.h>
5 
6 
7 using namespace std;
8 
9 bool Utils::stringMatch(const char* str, const char* pattern) {
10  int status;
11  regex_t re;
12 
13  if( regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0 )
14  return false;
15 
16  status = regexec(&re, str, (size_t)0, NULL, 0);
17  regfree(&re);
18 
19  if (status != 0)
20  return false;
21 
22  return true;
23 }
24 
25 vector<string> Utils::myGlob(const char* pattern) {
26 
27  glob_t globbuf;
28 
29  globbuf.gl_offs = 2;
30  glob(pattern, GLOB_TILDE|GLOB_BRACE|GLOB_MARK, NULL, &globbuf);
31 
32  vector<string> results;
33  for(unsigned i=0; i<globbuf.gl_pathc; i++) {
34  results.push_back(globbuf.gl_pathv[i]);
35  }
36 
37  globfree(&globbuf);
38  return results;
39 }
40 
41 string Utils::date() {
42  string date("date +%d%b%Y_%H%M%S");
43  FILE *in = popen(date.c_str(), "r");
44  char result[100];
45  if(fscanf(in,"%s",result) != EOF) {
46  return string(result);
47  }
48  else return string("");
49 }
50 
51 
52 double Utils::mpi_pi(double angle) {
53 
54  const double pi = 3.14159265358979323;
55  const double pi2 = pi*2.;
56  while(angle>pi) angle -= pi2;
57  while(angle<-pi) angle += pi2;
58  return angle;
59 }
int i
Definition: DBlmapReader.cc:9
static std::vector< std::string > myGlob(const char *pattern)
get all files matching pattern
Definition: Utils.cc:25
const double pi2
Definition: Thrust.cc:4
#define NULL
Definition: scimark2.h:8
tuple result
Definition: query.py:137
static std::string date()
returns the date
Definition: Utils.cc:41
static bool stringMatch(const char *string, const char *pattern)
match a string to a regexp
Definition: Utils.cc:9
static double mpi_pi(double angle)
returns angle between mpi and pi
Definition: Utils.cc:52
double pi
tuple status
Definition: ntuplemaker.py:245
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11