Go to the documentation of this file.00001 #include "RecoParticleFlow/PFProducer/interface/Utils.h"
00002
00003 #include <stdio.h>
00004 #include <regex.h>
00005
00006
00007 using namespace std;
00008
00009 bool Utils::stringMatch(const char* str, const char* pattern) {
00010 int status;
00011 regex_t re;
00012
00013 if( regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0 )
00014 return false;
00015
00016 status = regexec(&re, str, (size_t)0, NULL, 0);
00017 regfree(&re);
00018
00019 if (status != 0)
00020 return false;
00021
00022 return true;
00023 }
00024
00025 vector<string> Utils::myGlob(const char* pattern) {
00026
00027 glob_t globbuf;
00028
00029 globbuf.gl_offs = 2;
00030 glob(pattern, GLOB_TILDE|GLOB_BRACE|GLOB_MARK, NULL, &globbuf);
00031
00032 vector<string> results;
00033 for(unsigned i=0; i<globbuf.gl_pathc; i++) {
00034 results.push_back(globbuf.gl_pathv[i]);
00035 }
00036
00037 globfree(&globbuf);
00038 return results;
00039 }
00040
00041 string Utils::date() {
00042 string date("date +%d%b%Y_%H%M%S");
00043 FILE *in = popen(date.c_str(), "r");
00044 char result[100];
00045 if(fscanf(in,"%s",result) != EOF) {
00046 return string(result);
00047 }
00048 else return string("");
00049 }
00050
00051
00052 double Utils::mpi_pi(double angle) {
00053
00054 const double pi = 3.14159265358979323;
00055 const double pi2 = pi*2.;
00056 while(angle>pi) angle -= pi2;
00057 while(angle<-pi) angle += pi2;
00058 return angle;
00059 }