PrintUtils.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2020, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
7  University of Liverpool & STFC Rutherford Appleton Laboratory
8 */
9 //____________________________________________________________________________
10 
11 #include <iostream>
12 #include <fstream>
13 #include <sstream>
14 
15 #include <TSystem.h>
16 
17 #include "Framework/Conventions/GVersion.h"
19 
20 using std::ostringstream;
21 using std::cout;
22 using std::endl;
23 using std::ios;
24 using std::ifstream;
25 
26 //____________________________________________________________________________
27 string genie::utils::print::P4AsString(const TLorentzVector * p)
28 {
29  ostringstream fmt;
30 
31  fmt << "(E = " << p->Energy()
32  << ", px = " << p->Px()
33  << ", py = " << p->Py()
34  << ", pz = " << p->Pz() << ")";
35 
36  double m2 = p->Mag2();
37  if(m2>0.) fmt << " / M = " << TMath::Sqrt(m2);
38  else fmt << " / M^2 = " << m2;
39 
40  fmt << " / P = " << p->P();
41 
42  return fmt.str();
43 }
44 //____________________________________________________________________________
45 string genie::utils::print::P4AsShortString(const TLorentzVector * p)
46 {
47  ostringstream fmt;
48 
49  fmt << "(E = " << p->Energy()
50  << ", px = " << p->Px()
51  << ", py = " << p->Py()
52  << ", pz = " << p->Pz() << ")";
53 
54  return fmt.str();
55 }
56 //____________________________________________________________________________
57 string genie::utils::print::X4AsString(const TLorentzVector * vec4)
58 {
59  ostringstream fmt;
60 
61  fmt << "(t = " << vec4->T()
62  << ", x = " << vec4->X()
63  << ", y = " << vec4->Y()
64  << ", z = " << vec4->Z() << ")";
65 
66  return fmt.str();
67 }
68 //____________________________________________________________________________
69 string genie::utils::print::P3AsString(const TVector3 * vec)
70 {
71  ostringstream fmt;
72 
73  fmt << "(px = " << vec->X()
74  << ", py = " << vec->Y()
75  << ", pz = " << vec->Z() << ")";
76 
77  return fmt.str();
78 }
79 //____________________________________________________________________________
80 string genie::utils::print::Vec3AsString(const TVector3 * vec)
81 {
82  ostringstream fmt;
83 
84  fmt << "(x = " << vec->X()
85  << ", y = " << vec->Y()
86  << ", z = " << vec->Z() << ")";
87 
88  return fmt.str();
89 }
90 //____________________________________________________________________________
92 {
93  return BoolAsTFString(b);
94 }
95 //____________________________________________________________________________
97 {
98  if(b) return "true";
99  else return "false";
100 }
101 //____________________________________________________________________________
103 {
104  if(b) return "ON";
105  else return "OFF";
106 }
107 //____________________________________________________________________________
109 {
110  if(b) return "YES";
111  else return "NO";
112 }
113 //____________________________________________________________________________
115 {
116 // loads & prints the GENIE banner
117 
118  string base_dir = string(gSystem->Getenv("GENIE"));
119 
120 #ifdef __GENIE_DEVEL_VERSION__
121  string warn_dev_banner =
122  base_dir +
123  string("/data/logo/warning_development_version.txt");
124  PrintBanner(warn_dev_banner, 0);
125 #endif
126 
127 #ifdef __GENIE_RELEASE_CANDIDATE__
128  string warn_rc_banner =
129  base_dir +
130  string("/data/logo/warning_release_candidate.txt");
131  PrintBanner(warn_rc_banner, 0);
132 #endif
133 
134  string main_banner =
135  base_dir +
136  string("/data/logo/genie_banner_long.txt");
137  PrintBanner(main_banner, 0);
138 }
139 //___________________________________________________________________________
140 void genie::utils::print::PrintBanner(string filename, UInt_t wait_msec)
141 {
142  ifstream banner(filename.c_str(), ios::in);
143 
144  if( banner.is_open() ) {
145  banner.seekg(0, ios::end);
146 
147  int length = banner.tellg();
148  char * buffer = new char[length];
149 
150  banner.seekg(0, ios::beg);
151  banner.read(buffer, length);
152 
153  //cout << "\n\n" << buffer << "\n" << endl;
154  cout << "\n\n";
155  cout.write(buffer,length);
156  cout << "\n" << endl;
157 
158  delete [] buffer;
159 
160  gSystem->Sleep(wait_msec); // watch the banner for a while
161  }
162 }
163 //___________________________________________________________________________
165  string mesg, unsigned int nl, const char f)
166 {
167  string frame(4+mesg.size(),f);
168 
169  string framed_mesg = string("\n") +
170  frame + string("\n") +
171  string(" ") + mesg + string(" ") + string("\n") +
172  frame;
173 
174  for(unsigned il=0; il<nl; il++) { framed_mesg += string("\n"); }
175 
176  return framed_mesg;
177 }
178 //___________________________________________________________________________
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
string P4AsShortString(const TLorentzVector *p)
Definition: PrintUtils.cxx:45
std::string string
Definition: nybbler.cc:12
string BoolAsYNString(bool b)
Definition: PrintUtils.cxx:108
string P3AsString(const TVector3 *vec)
Definition: PrintUtils.cxx:69
string P4AsString(const TLorentzVector *p)
Definition: PrintUtils.cxx:27
string BoolAsTFString(bool b)
Definition: PrintUtils.cxx:96
string filename
Definition: train.py:213
string BoolAsIOString(bool b)
Definition: PrintUtils.cxx:102
string BoolAsString(bool b)
Definition: PrintUtils.cxx:91
static constexpr double m2
Definition: Units.h:72
p
Definition: test.py:223
void PrintBanner(void)
Definition: PrintUtils.cxx:114
static bool * b
Definition: config.cpp:1043
string PrintFramedMesg(string mesg, unsigned int nl=1, const char f='*')
Definition: PrintUtils.cxx:164
string X4AsString(const TLorentzVector *x)
Definition: PrintUtils.cxx:57
std::string nl(std::size_t i=1)
string Vec3AsString(const TVector3 *vec)
Definition: PrintUtils.cxx:80
QTextStream & endl(QTextStream &s)