Skip to content

Commit

Permalink
Pickle weighter
Browse files Browse the repository at this point in the history
  • Loading branch information
austinschneider committed Oct 22, 2024
1 parent 52e9558 commit df90ce5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions projects/injection/private/pybindings/injection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ PYBIND11_MODULE(injection,m) {
.def("EventWeight",&Weighter::EventWeight)
.def("SaveWeighter",&Weighter::SaveWeighter)
.def("LoadWeighter",&Weighter::LoadWeighter)
.def(pybind11::pickle(
&(siren::serialization::pickle_save<Weighter>),
&(siren::serialization::pickle_load<Weighter>)
))
;
}

7 changes: 6 additions & 1 deletion projects/injection/public/SIREN/injection/Weighter.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,17 @@ class Weighter {
}

template<typename Archive>
void load(Archive & archive, std::uint32_t const version) const {
static void load_and_construct(Archive & archive, cereal::construct<Weighter> & construct, std::uint32_t const version) {
if(version == 0) {
std::vector<std::shared_ptr<Injector>> injectors;
std::shared_ptr<siren::detector::DetectorModel> detector_model;
std::shared_ptr<siren::injection::PhysicalProcess> primary_physical_process;
std::vector<std::shared_ptr<siren::injection::PhysicalProcess>> secondary_physical_processes;
archive(::cereal::make_nvp("Injectors", injectors));
archive(::cereal::make_nvp("DetectorModel", detector_model));
archive(::cereal::make_nvp("PrimaryPhysicalProcess", primary_physical_process));
archive(::cereal::make_nvp("SecondaryPhysicalProcesses", secondary_physical_processes));
construct(injectors, detector_model, primary_physical_process, secondary_physical_processes);
} else {
throw std::runtime_error("Weighter only supports version <= 0!");
}
Expand Down

0 comments on commit df90ce5

Please sign in to comment.