The interfaces in this group are used for debug and informational console output.
SMASH uses the einhard logging library for debug and info/warn/error output to stdout. This library builds upon the C++ ostream classes and thus uses stream operators for converting objects into a text representation.
The einhard library supports named output streams (which simply means they automatically add the name to the prefix string). We use this feature to define log areas in SMASH that can be configured independently. The einhard::Logger class supports two options: colorization and verbosity. For colorization we stay with the default of auto-detecting a color-terminal. For verbosity we use a Configuration object to set the verbosity of each area independently. This way we have control over the amount of debug output at runtime and without the need to touch the code/recompile.
To output something from your code do the following:
logg[LAreaName].debug(
"particle",
p);
logg[LAreaName].warn(
"Something happened.");
Note that LAreaName
needs to be declared within the smash namespace of the respective file in a form of (using PauliBlocking as an example area):
The einhard::Logger class supports two ways of writing to an output stream: Use stream operators or pass the list of objects for output as parameters. Thus
log.debug(
"particle: ",
p);
and
log.debug() <<
"particle: " <<
p;
are equivalent (except for a small optimization opportunity in the former variant, that could make it slightly more efficient). You can see, though, that the former variant is more concise and often much easier to type than the stream operators.
|
#define | DECLARE_LOGAREA(id__, name__) |
| Declares the necessary interface to identify a new log area. More...
|
|
#define | source_location __FILE__ ":" + std::to_string(__LINE__) + " (" + __func__ + ')' |
| Hackery that is required to output the location in the source code where the log statement occurs. More...
|
|
|
using | smash::LogArea::AreaTuple = std::tuple< Main, Experiment, Box, Collider, Sphere, Action, InputParser, ParticleType, FindScatter, Clock, DecayModes, Resonances, ScatterAction, Distributions, Propagation, Grid, List, Nucleus, Density, PauliBlocking, Tmn, Fpe, Lattice, Sampling, Pythia, GrandcanThermalizer, CrossSections, Output, HadronGasEos, HyperSurfaceCrossing, InitialConditions > |
| This type collects all existing log areas so they will be created with the correct log level automatically. More...
|
|
|
virtual void | smash::Action::format_debug_output (std::ostream &out) const =0 |
|
std::ostream & | smash::operator<< (std::ostream &out, const ActionPtr &action) |
|
std::ostream & | smash::operator<< (std::ostream &out, const ActionList &actions) |
|
std::ostream & | smash::operator<< (std::ostream &out, const Angles &a) |
|
void | smash::DecayAction::format_debug_output (std::ostream &out) const override |
|
std::ostream & | smash::operator<< (std::ostream &, const EnergyMomentumTensor &) |
|
std::ostream & | smash::operator<< (std::ostream &os, const FourVector &vec) |
|
template<int w = 9, int p = w - 3, typename CharT , typename Traits > |
std::basic_ostream< CharT, Traits > & | smash::field (std::basic_ostream< CharT, Traits > &s) |
|
void | smash::create_all_loggers (Configuration config) |
| Called from main() right after the Configuration object is fully set up to create all logger objects (as defined by LogArea::AreaTuple) with the correct area names and log levels. More...
|
|
einhard::LogLevel | smash::default_loglevel () |
|
void | smash::set_default_loglevel (einhard::LogLevel level) |
| Set the default log level (what will be returned from subsequent default_loglevel calls). More...
|
|
template<typename T > |
FormattingHelper< T > | smash::format (const T &value, const char *unit, int width=-1, int precision=-1) |
| Acts as a stream modifier for std::ostream to output an object with an optional suffix string and with a given field width and precision. More...
|
|
static Node | YAML::convert< einhard::LogLevel >::encode (const einhard::LogLevel &x) |
| Convert from einhard::LogLevel to YAML::Node. More...
|
|
static bool | YAML::convert< einhard::LogLevel >::decode (const Node &node, einhard::LogLevel &x) |
| Convert from YAML::Node to einhard::LogLevel. More...
|
|
std::ostream & | smash::operator<< (std::ostream &s, const ParticleData &p) |
|
std::ostream & | smash::operator<< (std::ostream &out, const ParticleList &particle_list) |
|
PrintParticleListDetailed | smash::detailed (const ParticleList &list) |
|
std::ostream & | smash::operator<< (std::ostream &out, const PrintParticleListDetailed &particle_list) |
|
std::ostream & | smash::operator<< (std::ostream &is, const PdgCode &code) |
|
std::ostream & | smash::operator<< (std::ostream &os, ProcessType process_type) |
|
std::ostream & | smash::operator<< (std::ostream &os, const CollisionBranch &cbranch) |
|
void | smash::ScatterAction::format_debug_output (std::ostream &out) const override |
|
std::ostream & | smash::operator<< (std::ostream &, const ThreeVector &) |
|
|
std::ostream & | smash::Action::operator<< (std::ostream &out, const Action &action) |
|
std::ostream & | smash::BoxModus::operator<< (std::ostream &out, const BoxModus &m) |
|
std::ostream & | smash::ColliderModus::operator<< (std::ostream &, const ColliderModus &) |
|
std::ostream & | smash::Experiment< Modus >::operator<< (std::ostream &out, const Experiment &e) |
| Creates a verbose textual description of the setup of the Experiment. More...
|
|
std::ostream & | smash::ListModus::operator<< (std::ostream &, const ListModus &) |
|
std::ostream & | smash::FormattingHelper< T >::operator<< (std::ostream &out, const FormattingHelper &h) |
| Nicely formatted output. More...
|
|
std::ostream & | smash::Nucleus::operator<< (std::ostream &, const Nucleus &) |
|
std::ostream & | smash::Particles::operator<< (std::ostream &out, const Particles &particles) |
|
std::ostream & | smash::ParticleType::operator<< (std::ostream &out, const ParticleType &type) |
|
std::ostream & | smash::SphereModus::operator<< (std::ostream &, const SphereModus &) |
|
◆ DECLARE_LOGAREA
#define DECLARE_LOGAREA |
( |
|
id__, |
|
|
|
name__ |
|
) |
| |
Value:struct name__ { \
static constexpr int id = id__; \
static constexpr const char *textual() { return #name__; } \
static constexpr int textual_length() { return sizeof(#name__) - 1; } \
}
Declares the necessary interface to identify a new log area.
Definition at line 166 of file logging.h.
◆ source_location
#define source_location __FILE__ ":" + std::to_string(__LINE__) + " (" + __func__ + ')' |
Hackery that is required to output the location in the source code where the log statement occurs.
Definition at line 240 of file logging.h.
◆ AreaTuple
using smash::LogArea::AreaTuple = typedef std::tuple<Main, Experiment, Box, Collider, Sphere, Action, InputParser, ParticleType, FindScatter, Clock, DecayModes, Resonances, ScatterAction, Distributions, Propagation, Grid, List, Nucleus, Density, PauliBlocking, Tmn, Fpe, Lattice, Sampling, Pythia, GrandcanThermalizer, CrossSections, Output, HadronGasEos, HyperSurfaceCrossing, InitialConditions> |
This type collects all existing log areas so they will be created with the correct log level automatically.
Definition at line 223 of file logging.h.
◆ format_debug_output() [1/3]
virtual void smash::Action::format_debug_output |
( |
std::ostream & |
out | ) |
const |
|
protectedpure virtual |
◆ operator<<() [1/12]
std::ostream& smash::operator<< |
( |
std::ostream & |
out, |
|
|
const ActionPtr & |
action |
|
) |
| |
|
inline |
Convenience: dereferences the ActionPtr to Action.
Definition at line 463 of file action.h.
464 return out << *action;
◆ operator<<() [2/12]
std::ostream & smash::operator<< |
( |
std::ostream & |
out, |
|
|
const ActionList & |
actions |
|
) |
| |
Writes multiple actions to the out
stream.
Definition at line 276 of file action.cc.
277 out <<
"ActionList {\n";
278 for (
const auto &a : actions) {
279 out <<
"- " << a <<
'\n';
◆ operator<<() [3/12]
std::ostream& smash::operator<< |
( |
std::ostream & |
out, |
|
|
const Angles & |
a |
|
) |
| |
|
inline |
Creates output for an Angles object in the form "φ: 0.1294, cos ϑ: 0.423".
Definition at line 184 of file angles.h.
185 return out <<
"φ:" <<
field << a.phi() <<
", cos ϑ:" <<
field << a.costheta();
◆ format_debug_output() [2/3]
void smash::DecayAction::format_debug_output |
( |
std::ostream & |
out | ) |
const |
|
overrideprotectedvirtual |
◆ operator<<() [4/12]
Prints out 4x4 tensor to the output stream.
- Parameters
-
[in] | out | Location of output |
[in] | Tmn | Energy-momentum tensor |
Definition at line 144 of file energymomentumtensor.cc.
146 for (
size_t mu = 0; mu < 4; mu++) {
147 for (
size_t nu = 0; nu < 4; nu++) {
148 out << std::setprecision(3) << std::setw(12) << std::fixed
149 <<
Tmn[EnergyMomentumTensor::tmn_index(mu, nu)];
◆ operator<<() [5/12]
std::ostream & smash::operator<< |
( |
std::ostream & |
os, |
|
|
const FourVector & |
vec |
|
) |
| |
Writes the four components of the vector to the output stream.
- Parameters
-
[in] | os | The ostream into which to output |
[in] | vec | The FourVector to write into os |
Definition at line 36 of file fourvector.cc.
◆ field()
template<int w = 9, int p = w - 3, typename CharT , typename Traits >
std::basic_ostream<CharT, Traits>& smash::field |
( |
std::basic_ostream< CharT, Traits > & |
s | ) |
|
|
inline |
Stream modifier to align the next object to a specific width w
.
- Template Parameters
-
w | The number of characters the field should have in the output. |
p | The floating precision. |
CharT | Character type of the output stream. |
Traits | Traits of the output stream. |
- Parameters
-
[in,out] | s | The output stream. |
- Returns
- The output stream.
Definition at line 30 of file iomanipulators.h.
33 s.setf(std::ios_base::fixed, std::ios_base::floatfield);
◆ create_all_loggers()
Called from main() right after the Configuration object is fully set up to create all logger objects (as defined by LogArea::AreaTuple) with the correct area names and log levels.
- Parameters
-
config | A configuration object with the log area names as toplevel keys. |
Definition at line 118 of file logging.cc.
119 create_all_loggers_impl<std::tuple_size<LogArea::AreaTuple>::value>(config);
◆ default_loglevel()
- Returns
- The default log level to use if no specific level is configured.
Definition at line 22 of file logging.cc.
◆ set_default_loglevel()
Set the default log level (what will be returned from subsequent default_loglevel calls).
- Parameters
-
Definition at line 24 of file logging.cc.
◆ format()
template<typename T >
FormattingHelper<T> smash::format |
( |
const T & |
value, |
|
|
const char * |
unit, |
|
|
int |
width = -1 , |
|
|
int |
precision = -1 |
|
) |
| |
Acts as a stream modifier for std::ostream to output an object with an optional suffix string and with a given field width and precision.
- Template Parameters
-
T | Value that is being formatted. |
- Parameters
-
value | The object to be written to the stream. |
unit | An optional suffix string, typically used for a unit. May be nullptr. |
width | The field width to use for value . |
precision | The precision to use for value . |
Definition at line 304 of file logging.h.
306 return {value, width, precision, unit};
◆ encode()
◆ decode()
Convert from YAML::Node to einhard::LogLevel.
- Parameters
-
[in] | node | YAML node. |
[out] | x | Where the corresponding log level will be stored if the conversion was successful. |
- Returns
- Whether the conversion was successful.
Definition at line 342 of file logging.h.
343 if (!node.IsScalar()) {
◆ operator<<() [6/12]
std::ostream & smash::operator<< |
( |
std::ostream & |
s, |
|
|
const ParticleData & |
p |
|
) |
| |
Writes the state of the particle to the output stream.
Definition at line 110 of file particledata.cc.
112 return out <<
p.type().name() <<
" (" << std::setw(5) <<
p.type().pdgcode()
113 <<
")" << std::right <<
"{id:" << field<6> <<
p.id()
114 <<
", process:" << field<4> <<
p.id_process()
115 <<
", pos [fm]:" <<
p.position() <<
", mom [GeV]:" <<
p.momentum()
116 <<
", formation time [fm]:" <<
p.formation_time()
117 <<
", cross section scaling factor:" <<
p.xsec_scaling_factor()
◆ operator<<() [7/12]
std::ostream & smash::operator<< |
( |
std::ostream & |
out, |
|
|
const ParticleList & |
particle_list |
|
) |
| |
Writes a compact overview over the particles in the particle_list
argument to the stream.
Definition at line 121 of file particledata.cc.
122 auto column = out.tellp();
124 for (
const auto &
p : particle_list) {
125 if (out.tellp() - column >= 201) {
127 column = out.tellp();
130 out << std::setw(5) << std::setprecision(3) <<
p.momentum().abs3()
◆ detailed()
Request the ParticleList to be printed in full detail (i.e. one full ParticleData printout per line).
Definition at line 476 of file particledata.h.
◆ operator<<() [8/12]
Writes a detailed overview over the particles in the particle_list
argument to the stream. This overload is selected via the function detailed.
Definition at line 136 of file particledata.cc.
140 for (
const auto &
p : particle_list.list) {
◆ operator<<() [9/12]
std::ostream & smash::operator<< |
( |
std::ostream & |
is, |
|
|
const PdgCode & |
code |
|
) |
| |
Writes the textual representation of the PDG code to the output stream.
Definition at line 88 of file pdgcode.cc.
89 return s << code.string();
◆ operator<<() [10/12]
std::ostream & smash::operator<< |
( |
std::ostream & |
os, |
|
|
ProcessType |
process_type |
|
) |
| |
Writes the textual representation of the process_type
to the output stream os
.
Definition at line 85 of file processbranch.cc.
86 switch (process_type) {
87 case ProcessType::None:
93 case ProcessType::TwoToOne:
96 case ProcessType::TwoToTwo:
99 case ProcessType::StringSoftSingleDiffractiveAX:
100 case ProcessType::StringSoftSingleDiffractiveXB:
101 case ProcessType::StringSoftDoubleDiffractive:
102 case ProcessType::StringSoftAnnihilation:
103 case ProcessType::StringSoftNonDiffractive:
104 os <<
"Soft String Excitation";
106 case ProcessType::StringHard:
107 os <<
"Hard String via Pythia";
109 case ProcessType::Decay:
112 case ProcessType::Wall:
116 os <<
"Hypersurface crossing";
119 os.setstate(std::ios_base::failbit);
◆ operator<<() [11/12]
std::ostream & smash::operator<< |
( |
std::ostream & |
os, |
|
|
const CollisionBranch & |
cbranch |
|
) |
| |
Writes the textual representation of the Collision Branch cbranch
to the output stream os
.
Definition at line 55 of file processbranch.cc.
57 if (ptype == ProcessType::StringSoftSingleDiffractiveAX ||
58 ptype == ProcessType::StringSoftSingleDiffractiveXB) {
60 }
else if (ptype == ProcessType::StringSoftDoubleDiffractive) {
62 }
else if (ptype == ProcessType::StringSoftAnnihilation) {
64 }
else if (ptype == ProcessType::StringSoftNonDiffractive) {
66 }
else if (ptype == ProcessType::StringHard) {
68 }
else if (ptype == ProcessType::TwoToOne || ptype == ProcessType::TwoToTwo ||
70 ParticleTypePtrList ptype_list = cbranch.particle_types();
75 std::sort(ptype_list.begin(), ptype_list.end());
76 for (
const auto& type : ptype_list) {
◆ format_debug_output() [3/3]
void smash::ScatterAction::format_debug_output |
( |
std::ostream & |
out | ) |
const |
|
overrideprotectedvirtual |
Writes information about this scatter action to the out
stream.
Implements smash::Action.
Definition at line 560 of file scatteraction.cc.
563 out <<
" (not performed)";
◆ operator<<() [12/12]
std::ostream & smash::operator<< |
( |
std::ostream & |
out, |
|
|
const ThreeVector & |
v |
|
) |
| |
Writes the three components of the vector to the output stream.
Definition at line 16 of file threevector.cc.
◆ value
Value that is being formatted.
Definition at line 264 of file logging.h.
◆ width
◆ precision
Precision that value is being formatted with.
Definition at line 268 of file logging.h.
◆ unit
Unit that is attached at the end of value.
Definition at line 270 of file logging.h.
◆ logg
An array that stores all pre-configured Logger objects.
The objects can be accessed via the logger function.
To access its elements use logg[LAreaName]
where AreaName is the respective areas name declared in loggin.h
. Note that LAreaName
needs to be declared within the smash namespace of the respective file in a form of (using PauliBlocking as an example area):
For further documentation see logging.h
.
Definition at line 39 of file logging.cc.
◆ operator<< [1/10]
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const Action & |
action |
|
) |
| |
|
friend |
◆ operator<< [2/10]
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const BoxModus & |
m |
|
) |
| |
|
friend |
Console output on startup of box specific parameters; writes the initial state for the box to the output stream.
- Parameters
-
[in] | out | The ostream into which to output |
[in] | m | The BoxModus object to write into out |
Definition at line 38 of file boxmodus.cc.
39 out <<
"-- Box Modus:\nSize of the box: (" << m.length_ <<
" fm)³\n";
41 out <<
"Thermal multiplicities "
42 <<
"(T = " << m.temperature_ <<
" GeV, muB = " << m.mub_
43 <<
" GeV, muS = " << m.mus_ <<
" GeV)\n";
45 for (
const auto &
p : m.init_multipl_) {
47 out << ptype->name() <<
" initial multiplicity " <<
p.second <<
'\n';
51 out <<
"All initial momenta = 3T = " << 3 * m.temperature_ <<
" GeV\n";
53 out <<
"Boltzmann momentum distribution with T = " << m.temperature_
58 out <<
"Adding a " << ptype->name() <<
" as a jet in the middle "
59 <<
"of the box with " << m.jet_mom_ <<
" GeV initial momentum.\n";
◆ operator<< [3/10]
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const ColliderModus & |
m |
|
) |
| |
|
friend |
Writes the initial state for the ColliderModus to the output stream.
- Parameters
-
[in] | out | The ostream into which to output |
[in] | m | The ColliderModus object to write into out |
Definition at line 441 of file collidermodus.cc.
442 return out <<
"-- Collider Modus:\n"
443 <<
"sqrt(S) (nucleus-nucleus) = "
444 <<
format(std::sqrt(m.total_s_),
"GeV\n")
445 <<
"sqrt(S) (nucleon-nucleon) = " <<
format(m.sqrt_s_NN_,
"GeV\n")
447 << *m.projectile_ <<
"\nTarget:\n"
◆ operator<< [4/10]
template<typename Modus>
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const Experiment< Modus > & |
e |
|
) |
| |
|
friend |
Creates a verbose textual description of the setup of the Experiment.
Writes the initial state for the Experiment to the output stream. It automatically appends the output of the current Modus.
Definition at line 569 of file experiment.h.
570 out <<
"End time: " << e.end_time_ <<
" fm/c\n";
◆ operator<< [5/10]
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const ListModus & |
m |
|
) |
| |
|
friend |
Writes the initial state for the List to the output stream.
- Parameters
-
[in] | out | The ostream into which to output |
[in] | m | The ListModus object to write into out |
Definition at line 135 of file listmodus.cc.
136 out <<
"-- List Modus\nInput directory for external particle lists:\n"
137 << m.particle_list_file_directory_ <<
"\n";
◆ operator<< [6/10]
template<typename T >
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const FormattingHelper< T > & |
h |
|
) |
| |
|
friend |
Nicely formatted output.
- Parameters
-
Definition at line 276 of file logging.h.
279 out << std::setfill(
' ') << std::setw(h.width);
281 if (h.precision >= 0) {
282 out << std::setprecision(h.precision);
286 out <<
' ' << h.unit;
◆ operator<< [7/10]
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const Nucleus & |
n |
|
) |
| |
|
friend |
Writes the state of the Nucleus object to the output stream.
Definition at line 513 of file nucleus.cc.
514 return out <<
" #particles #testparticles mass [GeV] "
515 "radius [fm] diffusiveness [fm]\n"
516 <<
format(
n.number_of_particles(),
nullptr, 12)
518 <<
format(
n.get_nuclear_radius(),
nullptr, 14)
519 <<
format(
n.get_diffusiveness(),
nullptr, 20);
◆ operator<< [8/10]
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const Particles & |
particles |
|
) |
| |
|
friend |
Print effective mass and type name for all particles to the stream.
- Parameters
-
[in] | out | The ostream into which to output |
[in] | particles | The Particles object to write into out |
Definition at line 148 of file particles.cc.
149 out << particles.size() <<
" Particles:\n";
150 for (
unsigned i = 0; i < particles.data_size_; ++i) {
151 const auto &
p = particles.data_[i];
155 out << std::setw(5) << std::setprecision(3) <<
p.momentum().abs3()
◆ operator<< [9/10]
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const ParticleType & |
type |
|
) |
| |
|
friend |
Writes all information about the particle type to the output stream.
- Parameters
-
[out] | out | The ostream into which to output |
[in] | type | The ParticleType object to write into out |
Definition at line 768 of file particletype.cc.
769 const PdgCode &pdg = type.pdgcode();
770 return out << type.name() << std::setfill(
' ') << std::right
771 <<
"[ mass:" << field<6> << type.mass()
772 <<
", width:" << field<6> << type.width_at_pole()
773 <<
", PDG:" << field<6> << pdg
774 <<
", charge:" << field<3> << pdg.charge()
775 <<
", spin:" << field<2> << pdg.spin() <<
"/2 ]";
◆ operator<< [10/10]
std::ostream& operator<< |
( |
std::ostream & |
out, |
|
|
const SphereModus & |
m |
|
) |
| |
|
friend |
Writes the initial state for the Sphere to the output stream.
- Parameters
-
[in] | out | The ostream into which to output |
[in] | m | The SphereModus object to write into out |
Definition at line 189 of file spheremodus.cc.
190 out <<
"-- Sphere Modus:\nRadius of the sphere: " << m.radius_ <<
" fm\n";
191 if (m.use_thermal_) {
192 out <<
"Thermal multiplicities (T = " << m.sphere_temperature_
193 <<
" GeV, muB = " << m.mub_ <<
" GeV, muS = " << m.mus_ <<
" GeV)\n";
195 for (
const auto &
p : m.init_multipl_) {
197 out << ptype->name() <<
" initial multiplicity " <<
p.second <<
'\n';
200 out <<
"Boltzmann momentum distribution with T = " << m.sphere_temperature_
204 out <<
"Adding a " << ptype->name() <<
" as a jet in the middle "
205 <<
"of the sphere with " << m.jet_mom_ <<
" GeV initial momentum.\n";