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 <math.h>
5 #include <regex.h>
6 #include <glob.h>
7 
8 #include "TCanvas.h"
9 #include "TVector3.h"
10 
11 using namespace std;
12 using namespace pftools;
13 bool Utils::StringMatch(const char* str, const char* pattern) {
14  int status;
15  regex_t re;
16 
17  if( regcomp(&re, pattern, REG_EXTENDED|REG_NOSUB) != 0 )
18  return false;
19 
20  status = regexec(&re, str, (size_t)0, NULL, 0);
21  regfree(&re);
22 
23  if (status != 0)
24  return false;
25 
26  return true;
27 }
28 
29 
30 TCanvas* Utils::DivideCanvas( TCanvas *cv, int nPads ) {
31  if( !cv ) return 0;
32 
33  if( nPads<=1 ) return cv;
34  int sqnP = (unsigned int) (sqrt( nPads ));
35  int nC = sqnP;
36  int nL = sqnP;
37 
38  while( nC*nL < nPads )
39  if( nC < nL ) nC++;
40  else nL++;
41 
42  cv->Divide( nC, nL, 0.005, 0.005, 0 );
43  return cv;
44 }
45 
46 vector<string> Utils::Glob(const char* pattern) {
47 
48  glob_t globbuf;
49 
50  globbuf.gl_offs = 2;
51  glob(pattern, GLOB_TILDE|GLOB_BRACE|GLOB_MARK, NULL, &globbuf);
52 
53  vector<string> results;
54  for(unsigned i=0; i<globbuf.gl_pathc; i++) {
55  results.push_back(globbuf.gl_pathv[i]);
56  }
57 
58  globfree(&globbuf);
59  return results;
60 }
61 
62 string Utils::Date() {
63  string date("date +%d%b%Y_%H%M%S");
64  FILE *in = popen(date.c_str(), "r");
65  char result[100];
66  if(fscanf(in,"%s",result) != EOF) {
67  return string(result);
68  }
69  else return string("");
70 }
71 
72 
73 TVector3 Utils::VectorEPRtoXYZ( const TVector3& posepr ) {
74  TVector3 posxyz(1,1,1); // to be called before a SetMag
75  posxyz.SetMag( posepr.Z() );
76  double theta = 2*atan( exp( - posepr.X() ) );
77  posxyz.SetTheta( theta );
78  posxyz.SetPhi( posepr.Y() );
79 
80  return posxyz;
81 }
82 
83 
int i
Definition: DBlmapReader.cc:9
Geom::Theta< T > theta() const
#define NULL
Definition: scimark2.h:8
T sqrt(T t)
Definition: SSEVec.h:48
tuple result
Definition: query.py:137
dictionary cv
Definition: cuy.py:362
tuple status
Definition: ntuplemaker.py:245