PrintUtils.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2019, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Author: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
8  University of Liverpool & STFC Rutherford Appleton Lab - May 06, 2004
9 
10  For documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13  @ Jul 14, 2009 - RH
14  Tweak PrintBanner() to fix problem with random garbage trailing the banner.
15 */
16 //____________________________________________________________________________
17 
18 #include <iostream>
19 #include <fstream>
20 #include <sstream>
21 
22 #include <TSystem.h>
23 
26 
27 using std::ostringstream;
28 using std::cout;
29 using std::endl;
30 using std::ios;
31 using std::ifstream;
32 
33 //____________________________________________________________________________
34 string genie::utils::print::P4AsString(const TLorentzVector * p)
35 {
36  ostringstream fmt;
37 
38  fmt << "(E = " << p->Energy()
39  << ", px = " << p->Px()
40  << ", py = " << p->Py()
41  << ", pz = " << p->Pz() << ")";
42 
43  double m2 = p->Mag2();
44  if(m2>0.) fmt << " / M = " << TMath::Sqrt(m2);
45  else fmt << " / M^2 = " << m2;
46 
47  fmt << " / P = " << p->P();
48 
49  return fmt.str();
50 }
51 //____________________________________________________________________________
52 string genie::utils::print::P4AsShortString(const TLorentzVector * p)
53 {
54  ostringstream fmt;
55 
56  fmt << "(E = " << p->Energy()
57  << ", px = " << p->Px()
58  << ", py = " << p->Py()
59  << ", pz = " << p->Pz() << ")";
60 
61  return fmt.str();
62 }
63 //____________________________________________________________________________
64 string genie::utils::print::X4AsString(const TLorentzVector * vec4)
65 {
66  ostringstream fmt;
67 
68  fmt << "(t = " << vec4->T()
69  << ", x = " << vec4->X()
70  << ", y = " << vec4->Y()
71  << ", z = " << vec4->Z() << ")";
72 
73  return fmt.str();
74 }
75 //____________________________________________________________________________
76 string genie::utils::print::P3AsString(const TVector3 * vec)
77 {
78  ostringstream fmt;
79 
80  fmt << "(px = " << vec->X()
81  << ", py = " << vec->Y()
82  << ", pz = " << vec->Z() << ")";
83 
84  return fmt.str();
85 }
86 //____________________________________________________________________________
87 string genie::utils::print::Vec3AsString(const TVector3 * vec)
88 {
89  ostringstream fmt;
90 
91  fmt << "(x = " << vec->X()
92  << ", y = " << vec->Y()
93  << ", z = " << vec->Z() << ")";
94 
95  return fmt.str();
96 }
97 //____________________________________________________________________________
99 {
100  return BoolAsTFString(b);
101 }
102 //____________________________________________________________________________
104 {
105  if(b) return "true";
106  else return "false";
107 }
108 //____________________________________________________________________________
110 {
111  if(b) return "ON";
112  else return "OFF";
113 }
114 //____________________________________________________________________________
116 {
117  if(b) return "YES";
118  else return "NO";
119 }
120 //____________________________________________________________________________
122 {
123 // loads & prints the GENIE banner
124 
125  string base_dir = string(gSystem->Getenv("GENIE"));
126 
127 #ifdef __GENIE_DEVEL_VERSION__
128  string warn_dev_banner =
129  base_dir +
130  string("/data/logo/warning_development_version.txt");
131  PrintBanner(warn_dev_banner, 0);
132 #endif
133 
134 #ifdef __GENIE_RELEASE_CANDIDATE__
135  string warn_rc_banner =
136  base_dir +
137  string("/data/logo/warning_release_candidate.txt");
138  PrintBanner(warn_rc_banner, 0);
139 #endif
140 
141  string main_banner =
142  base_dir +
143  string("/data/logo/genie_banner_long.txt");
144  PrintBanner(main_banner, 0);
145 }
146 //___________________________________________________________________________
147 void genie::utils::print::PrintBanner(string filename, UInt_t wait_msec)
148 {
149  ifstream banner(filename.c_str(), ios::in);
150 
151  if( banner.is_open() ) {
152  banner.seekg(0, ios::end);
153 
154  int length = banner.tellg();
155  char * buffer = new char[length];
156 
157  banner.seekg(0, ios::beg);
158  banner.read(buffer, length);
159 
160  //cout << "\n\n" << buffer << "\n" << endl;
161  cout << "\n\n";
162  cout.write(buffer,length);
163  cout << "\n" << endl;
164 
165  delete [] buffer;
166 
167  gSystem->Sleep(wait_msec); // watch the banner for a while
168  }
169 }
170 //___________________________________________________________________________
172  string mesg, unsigned int nl, const char f)
173 {
174  string frame(4+mesg.size(),f);
175 
176  string framed_mesg = string("\n") +
177  frame + string("\n") +
178  string(" ") + mesg + string(" ") + string("\n") +
179  frame;
180 
181  for(unsigned il=0; il<nl; il++) { framed_mesg += string("\n"); }
182 
183  return framed_mesg;
184 }
185 //___________________________________________________________________________
string P4AsShortString(const TLorentzVector *p)
Definition: PrintUtils.cxx:52
string BoolAsYNString(bool b)
Definition: PrintUtils.cxx:115
const char * p
Definition: xmltok.h:285
string P3AsString(const TVector3 *vec)
Definition: PrintUtils.cxx:76
string P4AsString(const TLorentzVector *p)
Definition: PrintUtils.cxx:34
string filename
Definition: shutoffs.py:106
string BoolAsTFString(bool b)
Definition: PrintUtils.cxx:103
::xsd::cxx::tree::buffer< char > buffer
Definition: Database.h:179
string BoolAsIOString(bool b)
Definition: PrintUtils.cxx:109
length
Definition: demo0.py:21
string BoolAsString(bool b)
Definition: PrintUtils.cxx:98
Eigen::VectorXd vec
OStream cout
Definition: OStream.cxx:6
static constexpr Double_t m2
Definition: Munits.h:145
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
ifstream in
Definition: comparison.C:7
void PrintBanner(void)
Definition: PrintUtils.cxx:121
Var Sqrt(const Var &v)
Use to take sqrt of a var.
Definition: Var.cxx:326
const hit & b
Definition: hits.cxx:21
string PrintFramedMesg(string mesg, unsigned int nl=1, const char f='*')
Definition: PrintUtils.cxx:171
string X4AsString(const TLorentzVector *x)
Definition: PrintUtils.cxx:64
std::string nl(std::size_t i=1)
string Vec3AsString(const TVector3 *vec)
Definition: PrintUtils.cxx:87