Version: SMASH-2.0
smash::Configuration::Value Class Reference

#include <configuration.h>

Return type of Configuration::take that automatically determines the target type.

This class is an implementation detail of Configuration and can be ignored by users of Configuration.

Definition at line 496 of file configuration.h.

Collaboration diagram for smash::Configuration::Value:
[legend]

Public Member Functions

 Value (const Value &)=delete
 If you want to copy this you're doing it wrong. More...
 
Valueoperator= (const Value &)=delete
 If you want to copy this you're doing it wrong. More...
 
template<typename T >
convert_for (const T &) const
 Convert the value to the type of the supplied argument. More...
 
template<typename T >
 operator T () const
 This function determines the type it is assigned to and calls YAML::Node::as<T>() with this type. More...
 
template<typename T >
 operator std::vector< T > () const
 Check conversion exceptions. More...
 
template<typename T , size_t N>
 operator std::array< T, N > () const
 Cast array of keys to a std::array of length N. More...
 
 operator ReactionsBitSet () const
 Set ReactionBitSet from configuration values. More...
 
 operator MultiParticleReactionsBitSet () const
 Set MultiParticleReactionsBitSet from configuration values. More...
 
 operator std::set< ThermodynamicQuantity > () const
 Set thermodynamic quantity from configuration values. More...
 
 operator CalculationFrame () const
 Set calculation frame from configuration values. More...
 
 operator FermiMotion () const
 (De-)Activate Fermi motion from configuration values. More...
 
 operator DensityType () const
 Set density type from configuration values. More...
 
 operator ExpansionMode () const
 Set expansion mode from configuration values. More...
 
 operator TimeStepMode () const
 Set time step mode from configuration values. More...
 
 operator BoxInitialCondition () const
 Set initial condition for box setup from configuration values. More...
 
 operator SphereInitialCondition () const
 Set initial condition for sphere setup from configuration values. More...
 
 operator NNbarTreatment () const
 Set treatment of N-Nbar reactions from configuration values. More...
 
 operator Sampling () const
 Set cross-section sampling method from configuration values. More...
 
 operator ThermalizationAlgorithm () const
 Set algorithm for forced thermalization from configuration values. More...
 
 operator CollisionCriterion () const
 Set collision criterion from configuration values. More...
 
 operator OutputOnlyFinal () const
 Set OutputOnlyFinal for particles output from configuration values. More...
 

Private Member Functions

 Value (const YAML::Node &n, const char *key)
 Constructs the Value wrapper from a YAML::Node. More...
 

Private Attributes

const YAML::Node node_
 a YAML leaf node More...
 
const char *const key_
 The key to be interpreted. More...
 

Friends

class Configuration
 

Constructor & Destructor Documentation

◆ Value() [1/2]

smash::Configuration::Value::Value ( const YAML::Node &  n,
const char *  key 
)
inlineprivate

Constructs the Value wrapper from a YAML::Node.

Note
This constructor must be implicit, otherwise it's impossible to return an rvalue Value object - because the copy constructor is deleted.

Definition at line 510 of file configuration.h.

510  : node_(n), key_(key) {
511  if (!(n.IsScalar() || n.IsSequence() || n.IsMap())) {
512  std::stringstream err;
513  err << "Configuration value for \"" << key
514  << "\" is missing or invalid";
515  throw std::runtime_error(err.str());
516  }
517  }

◆ Value() [2/2]

smash::Configuration::Value::Value ( const Value )
delete

If you want to copy this you're doing it wrong.

Member Function Documentation

◆ operator=()

Value& smash::Configuration::Value::operator= ( const Value )
delete

If you want to copy this you're doing it wrong.

◆ convert_for()

template<typename T >
T smash::Configuration::Value::convert_for ( const T &  ) const
inline

Convert the value to the type of the supplied argument.

The argument itself is not used other than to determine its type. This function is necessary because in some situations the overload resolution rules lead to the correct conversion becoming hidden. Then you'll see a compiler error with a list of ambiguous constructor calls as candidates. Use this function as a workaround. Example:

// this doesn't compile:
const PdgCode code0(config.take({"key"}));
// this compiles (because PdgCode::operator= is not overloaded), but note
// that it cannot be used in constructor initializer lists:
const PdgCode code1 = config.take({"key"});
// Thus, for class member variables use the following pattern:
class X {
public:
X() : code_(config.take({"key"}).convert_for(code_)) {}
private:
const PdgCode code_;
};

Definition at line 552 of file configuration.h.

552  {
553  return *this;
554  }

◆ operator T()

template<typename T >
smash::Configuration::Value::operator T ( ) const
inline

This function determines the type it is assigned to and calls YAML::Node::as<T>() with this type.

This makes reading values more convenient than calling as<type>() explicitly.

Exceptions
IncorrectTypeInAssignment

Definition at line 565 of file configuration.h.

565  {
566  try {
567  return node_.as<T>();
568  } catch (YAML::TypedBadConversion<T> &e) {
569  throw IncorrectTypeInAssignment(
570  "The value for key \"" + std::string(key_) +
571  "\" cannot be converted to the requested type.");
572  }
573  }

◆ operator std::vector< T >()

template<typename T >
smash::Configuration::Value::operator std::vector< T > ( ) const
inline

Check conversion exceptions.

Exceptions
IncorrectTypeInAssignmentin case type conversion failed.

Definition at line 581 of file configuration.h.

581  {
582  try {
583  return node_.as<std::vector<T>>();
584  } catch (YAML::TypedBadConversion<T> &e) {
585  throw IncorrectTypeInAssignment(
586  "One of the values in the sequence for key \"" + std::string(key_) +
587  "\" failed to convert to the requested type. E.g. [1 2] is a "
588  "sequence of one string \"1 2\" and [1, 2] is a sequence of two "
589  "integers. Often there is just a comma missing in the config "
590  "file.");
591  } catch (YAML::TypedBadConversion<std::vector<T>> &e) {
592  throw IncorrectTypeInAssignment(
593  "The value for key \"" + std::string(key_) +
594  "\" cannot be converted to the requested type. A sequence was "
595  "expected but apparently not found.");
596  }
597  }

◆ operator std::array< T, N >()

template<typename T , size_t N>
smash::Configuration::Value::operator std::array< T, N > ( ) const
inline

Cast array of keys to a std::array of length N.

Returns
Array of std::array type.
Exceptions
IncorrectTypeInAssignmentin case the number of keys does not match the length of the newly generated array.

Definition at line 607 of file configuration.h.

607  {
608  const std::vector<T> vec = operator std::vector<T>();
609  const size_t n_read = vec.size();
610  // Alert if size does not match
611  if (n_read != N) {
612  throw IncorrectTypeInAssignment("Wrong number of values in array \"" +
613  std::string(key_) + "\". Expected " +
614  std::to_string(N) +
615  " values,"
616  " found " +
617  std::to_string(n_read) + ".");
618  }
619  std::array<T, N> arr;
620  std::copy_n(vec.begin(), N, arr.begin());
621  return arr;
622  }

◆ operator ReactionsBitSet()

smash::Configuration::Value::operator ReactionsBitSet ( ) const
inline

Set ReactionBitSet from configuration values.

Returns
ReactionBitSet with all included reaction types.
Exceptions
IncorrectTypeInAssignmentin case a reaction type that is not available is provided as a configuration value.

Definition at line 631 of file configuration.h.

631  {
632  const std::vector<std::string> v = operator std::vector<std::string>();
633  ReactionsBitSet s;
634  for (const auto &x : v) {
635  if (x == "All") {
636  s.set();
637  break;
638  } else if (x == "Elastic") {
640  } else if (x == "NN_to_NR") {
642  } else if (x == "NN_to_DR") {
644  } else if (x == "KN_to_KN") {
646  } else if (x == "KN_to_KDelta") {
648  } else if (x == "Strangeness_exchange") {
650  } else if (x == "NNbar") {
652  } else if (x == "PiDeuteron_to_NN") {
654  } else if (x == "PiDeuteron_to_pidprime") {
656  } else if (x == "NDeuteron_to_Ndprime") {
658  } else {
659  throw IncorrectTypeInAssignment(
660  "The value for key \"" + std::string(key_) +
661  "\" should be \"All\", \"Elastic\", \"NN_to_NR\", \"NN_to_DR\","
662  "\"KN_to_KN\", \"KN_to_KDelta\", \"PiDeuteron_to_NN\", "
663  "\"PiDeuteron_to_pidprime\", \"NDeuteron_to_Ndprime\", "
664  "\"Strangeness_exchange\" or "
665  "\"NNbar\", or any combination of these.");
666  }
667  }
668  return s;
669  }

◆ operator MultiParticleReactionsBitSet()

smash::Configuration::Value::operator MultiParticleReactionsBitSet ( ) const
inline

Set MultiParticleReactionsBitSet from configuration values.

Returns
MultiParticleReactionsBitSet with all included reaction types.
Exceptions
IncorrectTypeInAssignmentin case a reaction type that is not available is provided as a configuration value.

Definition at line 678 of file configuration.h.

678  {
679  const std::vector<std::string> v = operator std::vector<std::string>();
681  for (const auto &x : v) {
682  if (x == "All") {
683  s.set();
684  break;
685  } else if (x == "Meson_3to1") {
687  } else if (x == "Deuteron_3to2") {
689  } else {
690  throw IncorrectTypeInAssignment(
691  "The value for key \"" + std::string(key_) +
692  "\" should be \"All\", \"Meson_3to1\" or "
693  "\"Deuteron_3to2\", or any combination of these.");
694  }
695  }
696  return s;
697  }

◆ operator std::set< ThermodynamicQuantity >()

smash::Configuration::Value::operator std::set< ThermodynamicQuantity > ( ) const
inline

Set thermodynamic quantity from configuration values.

Returns
Set of thermodynamic quantity.
Exceptions
IncorrectTypeInAssignmentin case a thermodynamic quantity that is not available is provided as a configuration value.

Definition at line 706 of file configuration.h.

706  {
707  const std::vector<std::string> v = operator std::vector<std::string>();
708  std::set<ThermodynamicQuantity> s;
709  for (const auto &x : v) {
710  if (x == "rho_eckart") {
712  } else if (x == "tmn") {
713  s.insert(ThermodynamicQuantity::Tmn);
714  } else if (x == "tmn_landau") {
716  } else if (x == "landau_velocity") {
718  } else if (x == "j_QBS") {
720  } else {
721  throw IncorrectTypeInAssignment(
722  "The value for key \"" + std::string(key_) +
723  "\" should be \"rho_eckart\", \"tmn\""
724  ", \"tmn_landau\", \"landau_velocity\" or \"j_QBS\".");
725  }
726  }
727  return s;
728  }

◆ operator CalculationFrame()

smash::Configuration::Value::operator CalculationFrame ( ) const
inline

Set calculation frame from configuration values.

Returns
string of calculation frame.
Exceptions
IncorrectTypeInAssignmentin case a calculation frame that is not available is provided as a configuration value.

Definition at line 737 of file configuration.h.

737  {
738  const std::string s = operator std::string();
739  if (s == "center of velocity") {
741  }
742  if (s == "center of mass") {
744  }
745  if (s == "fixed target") {
747  }
748  throw IncorrectTypeInAssignment(
749  "The value for key \"" + std::string(key_) +
750  "\" should be \"center of velocity\" or \"center of mass\" "
751  "or \"fixed target\".");
752  }

◆ operator FermiMotion()

smash::Configuration::Value::operator FermiMotion ( ) const
inline

(De-)Activate Fermi motion from configuration values.

Returns
Fermi motion setup.
Exceptions
IncorrectTypeInAssignmentin case a Fermi motion value that is not available is provided as a configuration value.

Definition at line 761 of file configuration.h.

761  {
762  const std::string s = operator std::string();
763  if (s == "off") {
764  return FermiMotion::Off;
765  }
766  if (s == "on") {
767  return FermiMotion::On;
768  }
769  if (s == "frozen") {
770  return FermiMotion::Frozen;
771  }
772  throw IncorrectTypeInAssignment(
773  "The value for key \"" + std::string(key_) +
774  "\" should be \"off\" or \"on\" or \"frozen\".");
775  }

◆ operator DensityType()

smash::Configuration::Value::operator DensityType ( ) const
inline

Set density type from configuration values.

Returns
Density type.
Exceptions
IncorrectTypeInAssignmentin case a density type that is not available is provided as a configuration value.

Definition at line 784 of file configuration.h.

784  {
785  const std::string s = operator std::string();
786  if (s == "hadron") {
787  return DensityType::Hadron;
788  }
789  if (s == "baryon") {
790  return DensityType::Baryon;
791  }
792  if (s == "baryonic isospin") {
794  }
795  if (s == "pion") {
796  return DensityType::Pion;
797  }
798  if (s == "total isospin") {
800  }
801  if (s == "none") {
802  return DensityType::None;
803  }
804  throw IncorrectTypeInAssignment("The value for key \"" +
805  std::string(key_) +
806  "\" should be \"hadron\" or \"baryon\" "
807  "or \"baryonic isospin\" or \"pion\" "
808  "or \"none\".");
809  }

◆ operator ExpansionMode()

smash::Configuration::Value::operator ExpansionMode ( ) const
inline

Set expansion mode from configuration values.

Returns
Expansion mode.
Exceptions
IncorrectTypeInAssignmentin case an expansion mode that is not available is provided as a configuration value.

Definition at line 818 of file configuration.h.

818  {
819  const std::string s = operator std::string();
820  if (s == "NoExpansion") {
822  }
823  if (s == "MasslessFRW") {
825  }
826  if (s == "MassiveFRW") {
828  }
829  if (s == "Exponential") {
831  }
832  throw IncorrectTypeInAssignment(
833  "The value for key \"" + std::string(key_) +
834  "\" should be \"NoExpansion\", \"MasslessFRW\"," +
835  "\"MassiveFRW\" or \"Exponential\".");
836  }

◆ operator TimeStepMode()

smash::Configuration::Value::operator TimeStepMode ( ) const
inline

Set time step mode from configuration values.

Returns
time step mode.
Exceptions
IncorrectTypeInAssignmentin case a time step mode that is not available is provided as a configuration value.

Definition at line 845 of file configuration.h.

845  {
846  const std::string s = operator std::string();
847  if (s == "None") {
848  return TimeStepMode::None;
849  }
850  if (s == "Fixed") {
851  return TimeStepMode::Fixed;
852  }
853  throw IncorrectTypeInAssignment("The value for key \"" +
854  std::string(key_) +
855  "\" should be \"None\" or \"Fixed\".");
856  }

◆ operator BoxInitialCondition()

smash::Configuration::Value::operator BoxInitialCondition ( ) const
inline

Set initial condition for box setup from configuration values.

Returns
Initial condition for box setup.
Exceptions
IncorrectTypeInAssignmentin case an initial conditions that is not available is provided as a configuration value.

Definition at line 865 of file configuration.h.

865  {
866  const std::string s = operator std::string();
867  if (s == "thermal momenta") {
869  }
870  if (s == "thermal momenta quantum") {
872  }
873  if (s == "peaked momenta") {
875  }
876  throw IncorrectTypeInAssignment(
877  "The value for key \"" + std::string(key_) +
878  "\" should be \"thermal momenta\", \"thermal momenta quantum\", " +
879  "or \"peaked momenta\".");
880  }

◆ operator SphereInitialCondition()

smash::Configuration::Value::operator SphereInitialCondition ( ) const
inline

Set initial condition for sphere setup from configuration values.

Returns
Initial condition for sphere setup.
Exceptions
IncorrectTypeInAssignmentin case an initial conditions that is not available is provided as a configuration value.

Definition at line 889 of file configuration.h.

889  {
890  const std::string s = operator std::string();
891  if (s == "thermal momenta") {
893  }
894  if (s == "thermal momenta quantum") {
896  }
897  if (s == "IC_ES") {
899  }
900  if (s == "IC_1M") {
902  }
903  if (s == "IC_2M") {
905  }
906  if (s == "IC_Massive") {
908  }
909  throw IncorrectTypeInAssignment(
910  "The value for key \"" + std::string(key_) +
911  "\" should be \"thermal momenta\", \"thermal momenta quantum\", " +
912  "\"IC_ES\", \"IC_1M\", \"IC_2M\" or" + "\"IC_Massive\".");
913  }

◆ operator NNbarTreatment()

smash::Configuration::Value::operator NNbarTreatment ( ) const
inline

Set treatment of N-Nbar reactions from configuration values.

Returns
N-Nbar treatment.
Exceptions
IncorrectTypeInAssignmentin case an N-Nbar treatment that is not available is provided as a configuration value.

Definition at line 922 of file configuration.h.

922  {
923  const std::string s = operator std::string();
924  if (s == "no annihilation") {
926  }
927  if (s == "resonances") {
929  }
930  if (s == "strings") {
932  }
933  throw IncorrectTypeInAssignment(
934  "The value for key \"" + std::string(key_) + "\" should be " +
935  "\"no annihilation\", \"detailed balance\", or \"strings\".");
936  }

◆ operator Sampling()

smash::Configuration::Value::operator Sampling ( ) const
inline

Set cross-section sampling method from configuration values.

Returns
Sampling method of cross-section.
Exceptions
IncorrectTypeInAssignmentin case a sampling method that is not available is provided as a configuration value.

Definition at line 945 of file configuration.h.

945  {
946  const std::string s = operator std::string();
947  if (s == "quadratic") {
948  return Sampling::Quadratic;
949  }
950  if (s == "custom") {
951  return Sampling::Custom;
952  }
953  if (s == "uniform") {
954  return Sampling::Uniform;
955  }
956  throw IncorrectTypeInAssignment(
957  "The value for key \"" + std::string(key_) +
958  "\" should be \"quadratic\", \"uniform\" or \"custom\".");
959  }

◆ operator ThermalizationAlgorithm()

smash::Configuration::Value::operator ThermalizationAlgorithm ( ) const
inline

Set algorithm for forced thermalization from configuration values.

Returns
Algorithm for forced thermalization.
Exceptions
IncorrectTypeInAssignmentin case a thermalization algorithm that is not available is provided as a configuration value.

Definition at line 968 of file configuration.h.

968  {
969  const std::string s = operator std::string();
970  if (s == "mode sampling") {
972  }
973  if (s == "biased BF") {
975  }
976  if (s == "unbiased BF") {
978  }
979  throw IncorrectTypeInAssignment(
980  "The value for key \"" + std::string(key_) +
981  "\" should be \"mode sampling\", \"biased BF\" or \"unbiased BF\".");
982  }

◆ operator CollisionCriterion()

smash::Configuration::Value::operator CollisionCriterion ( ) const
inline

Set collision criterion from configuration values.

Returns
CollisionCriterion.
Exceptions
IncorrectTypeInAssignmentin case an collision criterion that is not available is provided as a configuration value.

Definition at line 991 of file configuration.h.

991  {
992  const std::string s = operator std::string();
993  if (s == "Geometric") {
995  }
996  if (s == "Stochastic") {
998  }
999  if (s == "Covariant") {
1001  }
1002  throw IncorrectTypeInAssignment(
1003  "The value for key \"" + std::string(key_) + "\" should be " +
1004  "\"Geometric\", \"Stochastic\" " + "or \"Covariant\".");
1005  }

◆ operator OutputOnlyFinal()

smash::Configuration::Value::operator OutputOnlyFinal ( ) const
inline

Set OutputOnlyFinal for particles output from configuration values.

Returns
OutputOnlyFinal.
Exceptions
IncorrectTypeInAssignmentin case only_final value that is not available is provided as a configuration value.

Definition at line 1014 of file configuration.h.

1014  {
1015  const std::string s = operator std::string();
1016  if (s == "Yes") {
1017  return OutputOnlyFinal::Yes;
1018  }
1019  if (s == "No") {
1020  return OutputOnlyFinal::No;
1021  }
1022  if (s == "IfNotEmpty") {
1024  }
1025  throw IncorrectTypeInAssignment("The value for key \"" +
1026  std::string(key_) + "\" should be " +
1027  "\"Yes\", \"No\" or \"IfNotEmpty\".");
1028  }

Friends And Related Function Documentation

◆ Configuration

friend class Configuration
friend

Definition at line 497 of file configuration.h.

Member Data Documentation

◆ node_

const YAML::Node smash::Configuration::Value::node_
private

a YAML leaf node

Todo:
(steinberg) What is that?

Definition at line 500 of file configuration.h.

◆ key_

const char* const smash::Configuration::Value::key_
private

The key to be interpreted.

Definition at line 502 of file configuration.h.


The documentation for this class was generated from the following file:
SphereInitialCondition::IC_Massive
NN_to_DR
Definition: forwarddeclarations.h:220
ThermodynamicQuantity::TmnLandau
Sampling::Quadratic
Sample from areal / quadratic distribution.
CalculationFrame::CenterOfVelocity
ThermodynamicQuantity::LandauVelocity
smash::Configuration::Value::node_
const YAML::Node node_
a YAML leaf node
Definition: configuration.h:500
SphereInitialCondition::IC_2M
NNbar
Definition: forwarddeclarations.h:224
smash::DensityType::BaryonicIsospin
SphereInitialCondition::ThermalMomentaBoltzmann
ExpansionMode::NoExpansion
PiDeuteron_to_NN
Definition: forwarddeclarations.h:225
ExpansionMode::Exponential
NNbarTreatment::Strings
Use string fragmentation.
FermiMotion::Off
Don't use fermi motion.
Strangeness_exchange
Definition: forwarddeclarations.h:223
FermiMotion::Frozen
Use fermi motion without potentials.
ReactionsBitSet
std::bitset< 10 > ReactionsBitSet
Container for the 2 to 2 reactions in the code.
Definition: forwarddeclarations.h:231
Sampling::Custom
Sample from custom, user-defined distribution.
MultiParticleReactionsBitSet
std::bitset< 2 > MultiParticleReactionsBitSet
Container for the 2 to 2 reactions in the code.
Definition: forwarddeclarations.h:240
ThermalizationAlgorithm::UnbiasedBF
Deuteron_3to2
Definition: forwarddeclarations.h:236
OutputOnlyFinal::IfNotEmpty
Print only final-state particles, and those only if the event is not empty.
CollisionCriterion::Stochastic
Stochastic Criteiron.
CollisionCriterion::Covariant
Covariant Criterion.
SphereInitialCondition::ThermalMomentaQuantum
ThermodynamicQuantity::Tmn
SphereInitialCondition::IC_1M
ExpansionMode::MassiveFRW
BoxInitialCondition::ThermalMomentaQuantum
ExpansionMode::MasslessFRW
smash::DensityType::Pion
NDeuteron_to_Ndprime
Definition: forwarddeclarations.h:227
OutputOnlyFinal::Yes
Print only final-state particles.
CalculationFrame::FixedTarget
ThermodynamicQuantity::EckartDensity
ThermalizationAlgorithm::ModeSampling
SphereInitialCondition::IC_ES
BoxInitialCondition::ThermalMomentaBoltzmann
KN_to_KN
Definition: forwarddeclarations.h:221
KN_to_KDelta
Definition: forwarddeclarations.h:222
ThermalizationAlgorithm::BiasedBF
NNbarTreatment::Resonances
Use intermediate Resonances.
Sampling::Uniform
Sample from uniform distribution.
smash::Configuration::Value::key_
const char *const key_
The key to be interpreted.
Definition: configuration.h:502
FermiMotion::On
Use fermi motion in combination with potentials.
smash::Configuration::Value::convert_for
T convert_for(const T &) const
Convert the value to the type of the supplied argument.
Definition: configuration.h:552
smash::ProcessType::Elastic
elastic scattering: particles remain the same, only momenta change
BoxInitialCondition::PeakedMomenta
smash::Configuration::take
Value take(std::initializer_list< const char * > keys)
The default interface for SMASH to read configuration values.
Definition: configuration.cc:140
smash::DensityType::None
NN_to_NR
Definition: forwarddeclarations.h:219
smash::DensityType::Isospin3_tot
ThermodynamicQuantity::j_QBS
smash::pdg::n
constexpr int n
Neutron.
Definition: pdgcode_constants.h:30
NNbarTreatment::NoAnnihilation
No Annihilation.
CalculationFrame::CenterOfMass
PiDeuteron_to_pidprime
Definition: forwarddeclarations.h:226
smash::DensityType::Hadron
CollisionCriterion::Geometric
(Default) geometric criterion.
smash::DensityType::Baryon
smash::NeedsToWrap::No
TimeStepMode::Fixed
Use fixed time step.
Meson_3to1
Definition: forwarddeclarations.h:235