10 #ifndef _PARAMETERLIST_HPP_ 11 #define _PARAMETERLIST_HPP_ 20 #include <boost/serialization/shared_ptr.hpp> 21 #include <boost/serialization/vector.hpp> 32 namespace FunctionTree {
52 virtual std::size_t numParameters()
const;
54 std::shared_ptr<FitParameter>
55 addUniqueParameter(std::shared_ptr<FitParameter> par);
57 virtual void addParameter(std::shared_ptr<Parameter> par);
59 virtual void addParameter(std::shared_ptr<FitParameter> par);
61 virtual void addParameters(std::vector<std::shared_ptr<Parameter>> pars);
63 virtual std::size_t numValues()
const;
65 virtual void addValue(std::shared_ptr<Parameter> value);
67 virtual void addValues(std::vector<std::shared_ptr<Parameter>> values);
71 return FitParameters.at(i);
78 virtual const std::vector<std::shared_ptr<FitParameter>> &
85 virtual std::shared_ptr<Value<int>>
intValue(
size_t i) {
86 return IntValues.at(i);
89 virtual std::vector<std::shared_ptr<Value<int>>> &
intValues() {
93 virtual const std::vector<std::shared_ptr<Value<int>>> &
intValues()
const {
97 virtual std::shared_ptr<Value<double>>
doubleValue(
size_t i)
const {
98 return DoubleValues.at(i);
105 virtual const std::vector<std::shared_ptr<Value<double>>> &
110 virtual std::shared_ptr<Value<std::complex<double>>>
112 return ComplexValues.at(i);
115 virtual std::vector<std::shared_ptr<Value<std::complex<double>>>> &
117 return ComplexValues;
120 virtual const std::vector<std::shared_ptr<Value<std::complex<double>>>> &
122 return ComplexValues;
125 virtual std::shared_ptr<Value<std::vector<int>>>
mIntValue(
size_t i)
const {
126 return MultiIntValues.at(i);
129 virtual std::vector<std::shared_ptr<Value<std::vector<int>>>> &
mIntValues() {
130 return MultiIntValues;
133 virtual const std::vector<std::shared_ptr<Value<std::vector<int>>>> &
135 return MultiIntValues;
138 virtual std::shared_ptr<Value<std::vector<double>>>
140 return MultiDoubleValues.at(i);
143 virtual std::vector<std::shared_ptr<Value<std::vector<double>>>> &
145 return MultiDoubleValues;
148 virtual const std::vector<std::shared_ptr<Value<std::vector<double>>>> &
150 return MultiDoubleValues;
153 virtual std::shared_ptr<Value<std::vector<std::complex<double>>>>
155 return MultiComplexValues.at(i);
158 virtual std::vector<std::shared_ptr<Value<std::vector<std::complex<double>>>>>
160 return MultiComplexValues;
163 virtual const std::vector<
164 std::shared_ptr<Value<std::vector<std::complex<double>>>>> &
166 return MultiComplexValues;
174 virtual std::string to_str()
const;
187 std::vector<std::shared_ptr<Value<std::vector<std::complex<double>>>>>
193 friend class boost::serialization::access;
194 template <
class archive>
195 void serialize(archive &ar,
const unsigned int version) {
198 ar &make_nvp(
"FitParameters", FitParameters);
209 [name](
const std::shared_ptr<FitParameter> &s) {
210 return s->name() == name;
213 throw BadParameter(
"FindParameter() | Parameter not in list!");
220 inline std::shared_ptr<FitParameter>
221 FindParameter(std::string name, std::vector<std::shared_ptr<FitParameter>> &v) {
222 auto it = std::find_if(v.begin(), v.end(),
223 [name](
const std::shared_ptr<FitParameter> &s) {
224 return s->name() == name;
227 throw BadParameter(
"FindParameter() | Parameter not in list!");
231 inline std::shared_ptr<Value<std::vector<double>>>
233 auto it = std::find_if(
235 [name](
const std::shared_ptr<Value<std::vector<double>>> &s) {
236 return s->name() == name;
239 throw BadParameter(
"FindParameter() | Parameter not in list!");
249 #include <boost/version.hpp> 250 #if (BOOST_VERSION < 105600) 251 #include <boost/serialization/split_free.hpp> 252 #include <boost/unordered_map.hpp> 257 namespace serialization {
259 template <
class Archive,
class Type>
260 void save(Archive &archive,
const std::shared_ptr<Type> &value,
261 const unsigned int version) {
262 Type *data = value.get();
263 archive << make_nvp(
"shared_ptr", data);
266 template <
class Archive,
class Type>
267 void load(Archive &archive, std::shared_ptr<Type> &value,
268 const unsigned int version) {
270 archive >> make_nvp(
"shared_ptr", data);
273 typedef std::weak_ptr<Type> WeakPtr;
274 static boost::unordered_map<void *, WeakPtr> hash;
276 if (hash[data].expired()) {
277 value = std::shared_ptr<Type>(data);
280 value = hash[data].lock();
283 template <
class Archive,
class Type>
284 inline void serialize(Archive &archive, std::shared_ptr<Type> &value,
285 const unsigned int version) {
286 split_free(archive, value, version);
291 #endif // END serialization work-a-round std::vector< std::shared_ptr< Value< std::vector< double > > > > MultiDoubleValues
virtual std::shared_ptr< Value< int > > intValue(size_t i)
void serialize(archive &ar, const unsigned int version)
Support for serialization of std::shared_ptr (and other types) is added in boost 1.56 .
virtual const std::vector< std::shared_ptr< Value< std::complex< double > > > > & complexValues() const
Implementations of Parameter for various data types.
Template implementation of Parameter for simple values.
virtual const std::vector< std::shared_ptr< Value< std::vector< int > > > > & mIntValues() const
std::shared_ptr< Value< std::vector< double > > > findMDoubleValue(const std::string &name, const ParameterList &list)
std::vector< std::shared_ptr< Value< std::vector< std::complex< double > > > > > MultiComplexValues
virtual const std::vector< std::shared_ptr< Value< std::vector< double > > > > & mDoubleValues() const
std::vector< std::shared_ptr< Value< double > > > DoubleValues
virtual std::vector< std::shared_ptr< Value< std::vector< int > > > > & mIntValues()
std::vector< std::shared_ptr< Value< int > > > IntValues
virtual std::shared_ptr< Value< std::vector< std::complex< double > > > > mComplexValue(size_t i) const
virtual std::vector< std::shared_ptr< Value< std::vector< double > > > > & mDoubleValues()
virtual const std::vector< std::shared_ptr< Value< std::vector< std::complex< double > > > > > & mComplexValues() const
virtual std::vector< std::shared_ptr< Value< std::complex< double > > > > & complexValues()
virtual const std::vector< std::shared_ptr< FitParameter > > & doubleParameters() const
virtual std::string to_str() const
A public function returning a string with parameter information.
virtual const std::vector< std::shared_ptr< Value< int > > > & intValues() const
virtual const std::vector< std::shared_ptr< Value< double > > > & doubleValues() const
friend std::ostream & operator<<(std::ostream &out, const ParameterList &b)
virtual std::shared_ptr< FitParameter > doubleParameter(size_t i) const
virtual std::vector< std::shared_ptr< Value< std::vector< std::complex< double > > > > > & mComplexValues()
virtual std::vector< std::shared_ptr< Value< double > > > & doubleValues()
FitResult load(std::string filename)
virtual std::vector< std::shared_ptr< FitParameter > > & doubleParameters()
virtual std::vector< std::shared_ptr< Value< int > > > & intValues()
std::vector< std::shared_ptr< Value< std::complex< double > > > > ComplexValues
std::vector< std::shared_ptr< Value< std::vector< int > > > > MultiIntValues
virtual std::shared_ptr< Value< std::vector< int > > > mIntValue(size_t i) const
virtual std::shared_ptr< Value< std::complex< double > > > complexValue(size_t i) const
std::shared_ptr< FitParameter > FindParameter(std::string name, std::vector< std::shared_ptr< FitParameter >> &v)
Search list for a FitParameter with name.
std::vector< std::shared_ptr< FitParameter > > FitParameters
This class provides a list of parameters and values of different types.
virtual std::shared_ptr< Value< std::vector< double > > > mDoubleValue(size_t i) const
virtual std::shared_ptr< Value< double > > doubleValue(size_t i) const