JHUGen MELA  JHUGen v7.5.6, MELA v2.4.2
Matrix element calculations as used in JHUGen.
MELAOutputStreamer.h
Go to the documentation of this file.
1 #ifndef MELAOUTPUTSTREAMER_H
2 #define MELAOUTPUTSTREAMER_H
3 
4 #include <ios>
5 #include <iostream>
6 #include <istream>
7 #include <ostream>
8 #include <fstream>
9 #include <streambuf>
10 #include <sstream>
11 #include <iomanip>
12 #include <string>
13 #include <vector>
14 #include <utility>
15 #include "TString.h"
16 #include "TLorentzVector.h"
18 #include "MELACandidate.h"
19 
20 
22 protected:
23  std::ofstream theFile;
24  std::ostream* stdout_ptr;
25 
26 public:
27  MELAOutputStreamer(const char* fname, std::ios_base::openmode fmode = std::ios_base::out, bool printError=false);
29 
30  template<typename T> MELAOutputStreamer& operator<<(T const& val);
31  template<typename T, typename U> MELAOutputStreamer& operator<<(std::pair<T, U> const& val);
32  template<typename T> MELAOutputStreamer& operator<<(std::vector<T> const& val);
33  MELAOutputStreamer& operator<<(std::ostream& (*fcn)(std::ostream&));
34  MELAOutputStreamer& operator<<(std::ios& (*fcn)(std::ios&));
35  MELAOutputStreamer& operator<<(std::ios_base& (*fcn)(std::ios_base&));
36 
37  std::streamsize width() const;
38  std::streamsize width(std::streamsize wide);
39 
40  char fill() const;
41  char fill(char fillch);
42 
43  void open(const char* fname, std::ios_base::openmode fmode = std::ios_base::out);
44  void close();
45 
46  template<typename T> void writeCentered(const T& val, char fillch=' ', std::streamsize gapsize=0);
47 
48 };
49 
50 template<typename T> MELAOutputStreamer& MELAOutputStreamer::operator<<(T const& val){
51  theFile << val;
52  if (stdout_ptr) *stdout_ptr << val;
53  return *this;
54 }
55 template MELAOutputStreamer& MELAOutputStreamer::operator<< <bool>(bool const& val);
56 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned short>(unsigned short const& val);
57 template MELAOutputStreamer& MELAOutputStreamer::operator<< <short>(short const& val);
58 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned int>(unsigned int const& val);
59 template MELAOutputStreamer& MELAOutputStreamer::operator<< <int>(int const& val);
60 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned long>(unsigned long const& val);
61 template MELAOutputStreamer& MELAOutputStreamer::operator<< <long>(long const& val);
62 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned long long>(unsigned long long const& val);
63 template MELAOutputStreamer& MELAOutputStreamer::operator<< <long long>(long long const& val);
64 template MELAOutputStreamer& MELAOutputStreamer::operator<< <float>(float const& val);
65 template MELAOutputStreamer& MELAOutputStreamer::operator<< <double>(double const& val);
66 template MELAOutputStreamer& MELAOutputStreamer::operator<< <long double>(long double const& val);
67 
68 template MELAOutputStreamer& MELAOutputStreamer::operator<< <char*>(char* const& val);
69 template MELAOutputStreamer& MELAOutputStreamer::operator<< <char const*>(char const* const& val);
70 template MELAOutputStreamer& MELAOutputStreamer::operator<< <char>(char const& val);
71 template MELAOutputStreamer& MELAOutputStreamer::operator<< <signed char*>(signed char* const& val);
72 template MELAOutputStreamer& MELAOutputStreamer::operator<< <signed char const*>(signed char const* const& val);
73 template MELAOutputStreamer& MELAOutputStreamer::operator<< <signed char>(signed char const& val);
74 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned char*>(unsigned char* const& val);
75 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned char const*>(unsigned char const* const& val);
76 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned char>(unsigned char const& val);
77 
78 template<> MELAOutputStreamer& MELAOutputStreamer::operator<< <TLorentzVector>(TLorentzVector const& val);
79 
80 template MELAOutputStreamer& MELAOutputStreamer::operator<< <std::string>(std::string const& val);
81 template MELAOutputStreamer& MELAOutputStreamer::operator<< <TString>(TString const& val);
82 template MELAOutputStreamer& MELAOutputStreamer::operator<< <std::streambuf*>(std::streambuf* const& val);
83 template MELAOutputStreamer& MELAOutputStreamer::operator<< <void*>(void* const& val);
84 
85 template<> MELAOutputStreamer& MELAOutputStreamer::operator<< <MELAParticle>(MELAParticle const& val);
86 template<> MELAOutputStreamer& MELAOutputStreamer::operator<< <MELAThreeBodyDecayCandidate>(MELAThreeBodyDecayCandidate const& val);
87 template<> MELAOutputStreamer& MELAOutputStreamer::operator<< <MELACandidate>(MELACandidate const& val);
88 
89 
90 template<typename T, typename U> MELAOutputStreamer& MELAOutputStreamer::operator<<(std::pair<T, U> const& val){
91  *this << "(" << val.first << ", " << val.second << ")";
92  return *this;
93 }
94 template<> MELAOutputStreamer& MELAOutputStreamer::operator<< <int, TLorentzVector>(SimpleParticle_t const& val);
95 
96 
97 template<typename T> MELAOutputStreamer& MELAOutputStreamer::operator<<(std::vector<T> const& val){
98  for (typename std::vector<T>::const_iterator it=val.cbegin(); it!=val.cend(); it++){
99  *this << *it;
100  if (it!=val.cend()-1) *this << ", ";
101  }
102  return *this;
103 }
104 template MELAOutputStreamer& MELAOutputStreamer::operator<< <bool>(std::vector<bool> const& val);
105 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned short>(std::vector<unsigned short> const& val);
106 template MELAOutputStreamer& MELAOutputStreamer::operator<< <short>(std::vector<short> const& val);
107 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned int>(std::vector<unsigned int> const& val);
108 template MELAOutputStreamer& MELAOutputStreamer::operator<< <int>(std::vector<int> const& val);
109 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned long>(std::vector<unsigned long> const& val);
110 template MELAOutputStreamer& MELAOutputStreamer::operator<< <long>(std::vector<long> const& val);
111 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned long long>(std::vector<unsigned long long> const& val);
112 template MELAOutputStreamer& MELAOutputStreamer::operator<< <long long>(std::vector<long long> const& val);
113 template MELAOutputStreamer& MELAOutputStreamer::operator<< <float>(std::vector<float> const& val);
114 template MELAOutputStreamer& MELAOutputStreamer::operator<< <double>(std::vector<double> const& val);
115 template MELAOutputStreamer& MELAOutputStreamer::operator<< <long double>(std::vector<long double> const& val);
116 
117 template MELAOutputStreamer& MELAOutputStreamer::operator<< <char*>(std::vector<char*> const& val);
118 template MELAOutputStreamer& MELAOutputStreamer::operator<< <char const*>(std::vector<char const*> const& val);
119 template MELAOutputStreamer& MELAOutputStreamer::operator<< <char>(std::vector<char> const& val);
120 template MELAOutputStreamer& MELAOutputStreamer::operator<< <signed char*>(std::vector<signed char*> const& val);
121 template MELAOutputStreamer& MELAOutputStreamer::operator<< <signed char const*>(std::vector<signed char const*> const& val);
122 template MELAOutputStreamer& MELAOutputStreamer::operator<< <signed char>(std::vector<signed char> const& val);
123 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned char*>(std::vector<unsigned char*> const& val);
124 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned char const*>(std::vector<unsigned char const*> const& val);
125 template MELAOutputStreamer& MELAOutputStreamer::operator<< <unsigned char>(std::vector<unsigned char> const& val);
126 
127 template MELAOutputStreamer& MELAOutputStreamer::operator<< <std::string>(std::vector<std::string> const& val);
128 template MELAOutputStreamer& MELAOutputStreamer::operator<< <TString>(std::vector<TString> const& val);
129 
130 
131 template<typename T> void MELAOutputStreamer::writeCentered(const T& val, char fillch, std::streamsize gapsize){
132  char deffillch = this->fill(fillch);
133 
134  std::stringstream tmpss;
135  tmpss << val;
136  std::string tmpstr = tmpss.str();
137  std::streamsize strlength = (std::streamsize) tmpstr.length();
138 
139  if (strlength>gapsize) *this << std::setw(gapsize) << "";
140  else{
141  std::streamsize leftgap = (gapsize+strlength)/2;
142  std::streamsize rightgap = gapsize-leftgap;
143  *this << std::setw(leftgap) << tmpstr << std::setw(rightgap) << "";
144  }
145 
146  this->fill(deffillch);
147 }
148 template void MELAOutputStreamer::writeCentered<bool>(const bool& val, char fillch, std::streamsize gapsize);
149 template void MELAOutputStreamer::writeCentered<unsigned short>(const unsigned short& val, char fillch, std::streamsize gapsize);
150 template void MELAOutputStreamer::writeCentered<short>(const short& val, char fillch, std::streamsize gapsize);
151 template void MELAOutputStreamer::writeCentered<unsigned int>(const unsigned int& val, char fillch, std::streamsize gapsize);
152 template void MELAOutputStreamer::writeCentered<int>(const int& val, char fillch, std::streamsize gapsize);
153 template void MELAOutputStreamer::writeCentered<unsigned long>(const unsigned long& val, char fillch, std::streamsize gapsize);
154 template void MELAOutputStreamer::writeCentered<long>(const long& val, char fillch, std::streamsize gapsize);
155 template void MELAOutputStreamer::writeCentered<unsigned long long>(const unsigned long long& val, char fillch, std::streamsize gapsize);
156 template void MELAOutputStreamer::writeCentered<long long>(const long long& val, char fillch, std::streamsize gapsize);
157 template void MELAOutputStreamer::writeCentered<float>(const float& val, char fillch, std::streamsize gapsize);
158 template void MELAOutputStreamer::writeCentered<double>(const double& val, char fillch, std::streamsize gapsize);
159 template void MELAOutputStreamer::writeCentered<long double>(const long double& val, char fillch, std::streamsize gapsize);
160 
161 template void MELAOutputStreamer::writeCentered<char*>(char* const& val, char fillch, std::streamsize gapsize);
162 template void MELAOutputStreamer::writeCentered<char const*>(char const* const& val, char fillch, std::streamsize gapsize);
163 template void MELAOutputStreamer::writeCentered<char>(char const& val, char fillch, std::streamsize gapsize);
164 template void MELAOutputStreamer::writeCentered<signed char*>(signed char* const& val, char fillch, std::streamsize gapsize);
165 template void MELAOutputStreamer::writeCentered<signed char const*>(signed char const* const& val, char fillch, std::streamsize gapsize);
166 template void MELAOutputStreamer::writeCentered<signed char>(signed char const& val, char fillch, std::streamsize gapsize);
167 template void MELAOutputStreamer::writeCentered<unsigned char*>(unsigned char* const& val, char fillch, std::streamsize gapsize);
168 template void MELAOutputStreamer::writeCentered<unsigned char const*>(unsigned char const* const& val, char fillch, std::streamsize gapsize);
169 template void MELAOutputStreamer::writeCentered<unsigned char>(unsigned char const& val, char fillch, std::streamsize gapsize);
170 
171 template void MELAOutputStreamer::writeCentered<std::string>(std::string const& val, char fillch, std::streamsize gapsize);
172 template void MELAOutputStreamer::writeCentered<TString>(TString const& val, char fillch, std::streamsize gapsize);
173 
174 
175 
176 #endif
SimpleParticle_t
std::pair< int, TLorentzVector > SimpleParticle_t
Definition: TVar.hh:24
MELAOutputStreamer::width
std::streamsize width() const
Definition: MELAOutputStreamer.cc:133
MELAOutputStreamer::MELAOutputStreamer
MELAOutputStreamer(const char *fname, std::ios_base::openmode fmode=std::ios_base::out, bool printError=false)
Definition: MELAOutputStreamer.cc:7
MELAOutputStreamer::fill
char fill() const
Definition: MELAOutputStreamer.cc:139
MELAOutputStreamer::close
void close()
Definition: MELAOutputStreamer.cc:145
MELAOutputStreamer::operator<<
MELAOutputStreamer & operator<<(T const &val)
Definition: MELAOutputStreamer.h:50
MELAThreeBodyDecayCandidate.h
MELAParticle
Definition: MELAParticle.h:13
MELAOutputStreamer::theFile
std::ofstream theFile
Definition: MELAOutputStreamer.h:23
MELAOutputStreamer::open
void open(const char *fname, std::ios_base::openmode fmode=std::ios_base::out)
Definition: MELAOutputStreamer.cc:148
MELAOutputStreamer::stdout_ptr
std::ostream * stdout_ptr
Definition: MELAOutputStreamer.h:24
MELAOutputStreamer::~MELAOutputStreamer
~MELAOutputStreamer()
Definition: MELAOutputStreamer.cc:13
MELAOutputStreamer::writeCentered
void writeCentered(const T &val, char fillch=' ', std::streamsize gapsize=0)
Definition: MELAOutputStreamer.h:131
MELAOutputStreamer
Definition: MELAOutputStreamer.h:21
MELACandidate.h
MELACandidate
Definition: MELACandidate.h:7
MELAThreeBodyDecayCandidate
Definition: MELAThreeBodyDecayCandidate.h:7