From 519081ca4374d6206337587716bfb35b0833f553 Mon Sep 17 00:00:00 2001 From: hrocho Date: Wed, 15 May 2019 16:32:45 +0200 Subject: [PATCH] storage info bug --- pymodule/pycatima.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pymodule/pycatima.cpp b/pymodule/pycatima.cpp index 4c48839..8f6132e 100644 --- a/pymodule/pycatima.cpp +++ b/pymodule/pycatima.cpp @@ -7,6 +7,7 @@ #include "catima/srim.h" #include "catima/nucdata.h" #include +#include namespace py = pybind11; using namespace catima; @@ -128,7 +129,17 @@ PYBIND11_MODULE(pycatima,m){ .def("thickness",py::overload_cast(&Material::thickness), "set thickness") .def("thickness_cm",&Material::thickness_cm,"set thickness in cm unit") .def("I",py::overload_cast<>(&Material::I, py::const_), "get I") - .def("I",py::overload_cast(&Material::I), "set I"); + .def("I",py::overload_cast(&Material::I), "set I") + .def("__str__",[](const Material &r){ + std::string s; + auto n = r.ncomponents(); + for(int i = 0; i < n; i++){ + auto el = r.get_element(i); + s += "#"+std::to_string(i); + s += ": A = "+std::to_string(el.A) + ", Z = "+std::to_string(el.A)+ ", stn = "+std::to_string(el.stn)+"\n"; + } + return s; + }); py::class_(m,"Layers") .def(py::init<>(),"constructor") @@ -265,7 +276,14 @@ PYBIND11_MODULE(pycatima,m){ d["calculation"] = r.calculation; d["skip"] = r.skip; return d; - }); + }) + .def("__str__",[](const Config &r){ + std::string s; + s = "z_effective = "+std::to_string(r.z_effective); + s += ", corrections = "+std::to_string(r.corrections); + s += ", calculation = "+std::to_string(r.calculation); + return s; + }); m.def("srim_dedx_e",&srim_dedx_e); m.def("sezi_dedx_e",&sezi_dedx_e, "sezi_dedx_e", py::arg("projectile"), py::arg("material"), py::arg("config")=default_config);