#ifndef __JOSCPROB__JOSCPARAMETERSINTERFACE__ #define __JOSCPROB__JOSCPARAMETERSINTERFACE__ #include #include #include #include "Jeep/JComment.hh" #include "Jeep/JProperties.hh" #include "JSystem/JStat.hh" #include "JIO/JSerialisable.hh" #include "JLang/JEquals.hh" #include "JLang/JClonable.hh" #include "JLang/JParameter.hh" #include "JLang/JStringStream.hh" #include "JLang/JEquationParameters.hh" #include "JTools/JGrid.hh" #include "JOscProb/JOscParameter.hh" /** * \author bjung, mdejong */ namespace JOSCPROB {} namespace JPP { using namespace JOSCPROB; } namespace JOSCPROB { using JIO::JReader; using JIO::JWriter; using JIO::JSerialisable; using JLANG::JEquals; using JLANG::JClonable; using JLANG::JEquationParameters; /** * Interface class for sets of oscillation parameters. */ template class JOscParametersInterface : public JClonable >, public JEquals >, public JSerialisable { public: typedef JOscParametersInterface JOscParametersInterface_t; typedef JOscParameter JOscParameter_t; typedef typename JOscParameter_t::JParameter_t JParameter_t; typedef typename JParameter_t::argument_type argument_type; typedef typename JParameter_t::value_type value_type; /** * Default constructor. */ JOscParametersInterface() {} /** * Virtual destructor. */ ~JOscParametersInterface() {} /** * Get properties of this class. * * \param equation equation parameters * \return properties of this class */ virtual JProperties getProperties(const JEquationParameters& equation = JOscParametersInterface_t::getEquationParameters()) = 0; /** * Get properties of this class. * * \param equation equation parameters * \return properties of this class */ virtual JProperties getProperties(const JEquationParameters& equation = JOscParametersInterface_t::getEquationParameters()) const = 0; /** * Get oscillation parameters. * * \return reference to oscillation parameters */ JOscParametersInterface_t& getParameters() { return static_cast(*this); } /** * Get oscillation parameter. * * \param name parameter name * \return parameter */ JOscParameter_t& get(const std::string& name) const { using namespace std; using namespace JPP; JProperties properties = this->getProperties(); JOscParameter_t& parameter = properties.getValue(name); return parameter; } /** * Set value for a given oscillation parameter. * * \param name parameter name * \param value parameter value */ void set(const std::string& name, const value_type& value) { using namespace std; using namespace JPP; JProperties properties = this->getProperties(); JOscParameter_t& parameter = properties.getValue(name); parameter.setValue(value); } /** * Set value for given list of oscillation parameters. * * \param name parameter name * \param value parameter value * \param args remaining pairs of parameter names and values */ template void set(const std::string& name, const value_type& value, const Args& ...args) { set(name, value); set(args...); } /** * Set oscillation parameters. * * \param parameters oscillation parameters */ void set(const JOscParametersInterface& parameters) { using namespace std; using namespace JPP; JProperties properties = parameters.getProperties(); for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) { const JOscParameter_t& parameter = i->second.getValue(); this->set(i->first, parameter.getValue()); } } /** * Check validity of oscillation parameters. * * \return true if all oscillation parameters are valid; else false */ bool is_valid() const { bool valid = true; const JProperties properties = this->getProperties(); for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend() && valid; ++i) { const JOscParameter_t& parameter = i->second.getValue(); valid = parameter.is_valid(); } return valid; } /** * Check whether these oscillation parameters are equal to given oscillation parameters. * * \return true if equal; else false */ bool equals(const JOscParametersInterface& parameters) const { using namespace std; using namespace JPP; bool equal = true; JProperties properties = parameters.getProperties(); for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend() && equal; ++i) { const JOscParameter_t& parameter = i->second.getValue(); equal = (parameter == this->get(i->first)); } return equal; } /** * Get equation parameters. * * \return equation parameters */ static inline JEquationParameters& getEquationParameters() { static JEquationParameters equation("=", "\n\r;,", "./", "#"); return equation; } /** * Set equation parameters. * * \param equation equation parameters */ static inline void setEquationParameters(const JEquationParameters& equation) { getEquationParameters() = equation; } /** * Binary stream input of oscillation parameters. * * \param in input stream * \return input stream */ JReader& read(JReader& in) override { JProperties properties = this->getProperties(); for (JProperties::iterator i = properties.begin(); i != properties.end(); ++i) { bool is_defined; value_type value; if ((in >> is_defined >> value) && is_defined) { JOscParameter_t& parameter = i->second.getValue(); parameter.setValue(value); } } return in; } /** * Binary stream output of oscillation parameters. * * \param out output stream * \return output stream */ JWriter& write(JWriter& out) const override { const JProperties properties = this->getProperties(); for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) { const JOscParameter_t& parameter = i->second.getValue(); out << parameter.isDefined() << parameter.getValue(); } return out; } /** * Stream input of oscillation parameters. * * \param in input stream * \param parameters oscillation parameters * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JOscParametersInterface_t& parameters) { using namespace std; using namespace JPP; JStringStream is(in); if (getFileStatus(is.str().c_str())) { is.load(); } JProperties properties = parameters.getProperties(); is >> properties; return in; } /** * Stream output of oscillation parameters. * * \param out output stream * \param parameters oscillation parameters * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JOscParametersInterface_t& parameters) { return out << parameters.getProperties(); } }; /** * Get size of given oscillation parameters set. * * \param parameters oscillation parameters set * \return size (= number of defined parameters) */ template inline size_t getSize(const JOscParametersInterface& parameters) { size_t n = 0; const JProperties properties = parameters.getProperties(); for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) { const JOscParameter& parameter = i->second.getValue >(); n += (size_t) parameter.isDefined(); } return n; } /** * Get size of given oscillation parameters grid. * * \param parameters oscillation parameters grid * \return size (= number of defined parameters) */ inline size_t getSize(const JOscParametersInterface >& parameters) { size_t n = 1; const JProperties properties = parameters.getProperties(); for (JProperties::const_iterator i = properties.cbegin(); i != properties.cend(); ++i) { const JOscParameter >& parameter = i->second.getValue > >(); if (parameter.isDefined()) { n *= getSize(parameter); } } return n; } } #endif