diff --git a/src/pflib/python/bindings.cxx b/src/pflib/python/bindings.cxx index cebf30e3..b7562673 100644 --- a/src/pflib/python/bindings.cxx +++ b/src/pflib/python/bindings.cxx @@ -7,6 +7,8 @@ #include "logging.h" #include "packing.h" +#include "pflib/Bias.h" +#include "pflib/HcalBackplane.h" #include "pflib/Target.h" #include "version.h" @@ -27,14 +29,11 @@ * here in order to ease passage of configuration between rogue and us. */ class PyTarget { + protected: /// our handle to the pflib::Target std::shared_ptr tgt_; - public: - /// construct a PyTarget given some arbitrary Python dict of parameters - PyTarget(bp::dict config) { - // where we std::make_shared a dervied type of pflib::Target - // depending on the setup + void parse_config(bp::dict config) { std::cout << "creating { "; for (auto it = bp::stl_input_iterator(config.items()); it != bp::stl_input_iterator(); it++) { @@ -44,38 +43,62 @@ class PyTarget { std::cout << key << ": " << val << ", "; } std::cout << "}" << std::endl; - - tgt_.reset( - pflib::makeTargetHcalBackplaneZCU(0 /*ilink*/, 0xf /*boardmask*/)); } + + public: + /// construct a PyTarget given some arbitrary Python dict of parameters + // virtual PyTarget(bp::dict config) { + PyTarget(bp::dict config) { parse_config(config); }; void configure() { // apply configuration stuff std::cout << "configure" << std::endl; } - void trigger_align() { std::cout << "trigger_align" << std::endl; } - void ror_latency() { std::cout << "ror_latency" << std::endl; } void pre_start() { // prepare to collect data std::cout << "start_run" << std::endl; tgt_->setup_run(1 /*run*/, pflib::Target::DaqFormat::ECOND_SW_HEADERS, 42 /* contrib_id */); } - void go() { std::cout << "go" << std::endl; } - void stop() { std::cout << "stop" << std::endl; } - void reset() { std::cout << "reset" << std::endl; } + + virtual void trigger_align() { + std::cout << "PyTarget trigger_align()" << std::endl; + } + virtual void ror_latency() { + std::cout << "PyTarget ror_latency()" << std::endl; + } + virtual void go() { std::cout << "PyTarget go()" << std::endl; } + virtual void stop() { std::cout << "PyTarget stop()" << std::endl; } + virtual void reset() { std::cout << "PyTarget reset()" << std::endl; } + /// should not use in actual DAQ std::vector grab_pedestals() { tgt_->fc().sendL1A(); usleep(100); return tgt_->read_event(); } + // Dumps the configs of all active ROCs to file + void dump_rocs(bp::str fname_prefix) { + std::string sfname_prefix = bp::extract(fname_prefix); + std::vector roc_ids{tgt_->roc_ids()}; + for (int iroc : roc_ids) { + std::string sfname = + sfname_prefix + "_iroc_" + std::to_string(iroc) + ".yaml"; + // Refactor + auto roc = tgt_->roc(iroc); + roc.dumpSettings(sfname, false); + } + } + void load_roc(int iroc, bp::str fname) { + std::string sfname = bp::extract(fname); + // Refactor + auto roc = tgt_->roc(iroc); + roc.loadRegisters(sfname); + } }; static const char* PyTarget__doc__ = R"DOC(Hold a pflib::Target -This class holds a C++ pflib::Target that we can then do -run commands on. The main configuration parameters are passed -into the object via a Python dict. +Parent class to PyTargetHCal and PyTargetECal. )DOC"; static const char* PyTarget__init____doc__ = R"DOC(construct a pflib::Target @@ -93,6 +116,97 @@ Hopefully, we will remember to remove it as the software progresses, but if its still around it should not be present in any Rogue Run Control code. )DOC"; +static const char* PyTarget_dump_rocs__doc__ = + R"DOC( + +Dumps ROC registers to file from all atcive ROCs +)DOC"; + +static const char* PyTarget_load_roc__doc__ = + R"DOC( + +Loads ROC registers from .yaml file +)DOC"; + +class PyTargetHCal : public PyTarget { + protected: + void makeTarget() { + tgt_.reset( + // TODO Change to Bittware target + pflib::makeTargetFiberless()); + } + + public: + PyTargetHCal(bp::dict config) : PyTarget(config) { makeTarget(); } + + /* + * HCal specific state transitions if needed + */ + // void trigger_align() { std::cout << "PyTargetHCal trigger_align()" << + // std::endl; } void ror_latency() { std::cout << "PyTargeHCal ror_latency()" + // << std::endl; } void go() { std::cout << "PyTargetHCal go()" << std::endl; + // } void stop() { std::cout << "PyTargetHCal stop()" << std::endl; } void + // reset() { std::cout << "PyTargetHCal reset()" << std::endl; } + + int read_sipm_bias(int iroc, int ch) { + pflib::Bias bias = + std::dynamic_pointer_cast(tgt_)->bias(iroc); + return bias.readSiPM(ch); + } + void set_sipm_bias(int iroc, int ch, int dac) { + pflib::Bias bias = + std::dynamic_pointer_cast(tgt_)->bias(iroc); + bias.setSiPM(ch, dac); + } +}; + +static const char* PyTargetHCal__doc__ = + R"DOC( + +This class holds a C++ pflib::Target that we can then do +run commands on. The main configuration parameters are passed +into the object via a Python dict. +)DOC"; + +static const char* PyTargetHCal_read_sipm_bias__doc__ = + R"DOC( + +Reads SiPM bias +)DOC"; + +static const char* PyTargetHCal_set_sipm_bias__doc__ = + R"DOC( + +Sets SiPM bias +)DOC"; + +class PyTargetECal : public PyTarget { + protected: + void makeTarget() { + // tgt_.reset( + // pflib::makeTargetECal()); + } + + public: + PyTargetECal(bp::dict config) : PyTarget(config) { makeTarget(); } + /* + * ECal specific state transitions if needed + */ + // void trigger_align() { std::cout << "PyTargetECal trigger_align()" << + // std::endl; } void ror_latency() { std::cout << "PyTargeECal ror_latency()" + // << std::endl; } void go() { std::cout << "PyTargetECal go()" << std::endl; + // } void stop() { std::cout << "PyTargetECal stop()" << std::endl; } void + // reset() { std::cout << "PyTargetECal reset()" << std::endl; } +}; + +static const char* PyTargetECal__doc__ = + R"DOC( + +This class holds a C++ pflib::Target that we can then do +run commands on. The main configuration parameters are passed +into the object via a Python dict. +)DOC"; + BOOST_PYTHON_MODULE(pypflib) { setup_version(); setup_logging(); @@ -109,5 +223,19 @@ BOOST_PYTHON_MODULE(pypflib) { .def("stop", &PyTarget::stop) .def("reset", &PyTarget::reset) .def("grab_pedestals", &PyTarget::grab_pedestals, - PyTarget_grab_pedestals__doc__); + PyTarget_grab_pedestals__doc__) + .def("dump_rocs", &PyTarget::dump_rocs, PyTarget_dump_rocs__doc__) + .def("load_roc", &PyTarget::load_roc, PyTarget_load_roc__doc__); + + bp::class_>( + "PyTargetHCal", PyTargetHCal__doc__, + bp::init(PyTarget__init____doc__, + (bp::arg("config") = bp::dict()))) + .def("read_sipm_bias", &PyTargetHCal::read_sipm_bias) + .def("set_sipm_bias", &PyTargetHCal::set_sipm_bias); + + bp::class_>( + "PyTargetECal", PyTargetECal__doc__, + bp::init(PyTarget__init____doc__, + (bp::arg("config") = bp::dict()))); }