Skip to content

Commit

Permalink
observables: make ids of ID based observable readonly.
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSzuttor committed Apr 6, 2021
1 parent f1f6b69 commit 921e209
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 19 deletions.
2 changes: 0 additions & 2 deletions src/core/observables/PidObservable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class PidObservable : virtual public Observable {
public:
explicit PidObservable(std::vector<int> ids) : m_ids(std::move(ids)) {}
std::vector<double> operator()() const final;

std::vector<int> &ids() { return m_ids; }
std::vector<int> const &ids() const { return m_ids; }
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ class CylindricalPidProfileObservable
using Base::Base;
CylindricalPidProfileObservable() {
this->add_parameters({
{"ids",
[this](const Variant &v) {
cylindrical_pid_profile_observable()->ids() =
get_value<std::vector<int>>(v);
},
{"ids", AutoParameter::read_only,
[this]() { return cylindrical_pid_profile_observable()->ids(); }},
{"transform_params", m_transform_params},
{"n_r_bins",
Expand Down
6 changes: 1 addition & 5 deletions src/script_interface/observables/PidObservable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ class PidObservable
std::is_base_of<::Observables::PidObservable, CorePidObs>::value, "");

PidObservable() {
this->add_parameters({{"ids",
[this](Variant const &v) {
m_observable->ids() =
get_value<std::vector<int>>(v);
},
this->add_parameters({{"ids", AutoParameter::read_only,
[this]() { return m_observable->ids(); }}});
}

Expand Down
5 changes: 1 addition & 4 deletions src/script_interface/observables/PidProfileObservable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ class PidProfileObservable
using Base::Base;
PidProfileObservable() {
this->add_parameters(
{{"ids",
[this](const Variant &v) {
pid_profile_observable()->ids() = get_value<std::vector<int>>(v);
},
{{"ids", AutoParameter::read_only,
[this]() { return pid_profile_observable()->ids(); }},
{"n_x_bins",
[this](const Variant &v) {
Expand Down
5 changes: 2 additions & 3 deletions testsuite/python/observables.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ def func(self):

# Test setters and getters
self.assertEqual(observable.ids, id_list)
new_pids = [id_list[0]]
observable.ids = new_pids
self.assertEqual(observable.ids, new_pids)
with self.assertRaises(RuntimeError):
observable.ids = [observable.ids[0]]

return func

Expand Down

0 comments on commit 921e209

Please sign in to comment.