From d7a0b66aa4e8b61814b2d0d79593f0808a08e4b2 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 26 Sep 2019 14:38:42 +0200 Subject: [PATCH] Add Matrix keyword into ObservationOperator dict --- AdaoExchangeLayer.cxx | 21 +++++++++++++++++++++ AdaoExchangeLayer.hxx | 3 +++ AdaoModelKeyVal.cxx | 10 ++++++---- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/AdaoExchangeLayer.cxx b/AdaoExchangeLayer.cxx index c5c15b8..8e9e280 100644 --- a/AdaoExchangeLayer.cxx +++ b/AdaoExchangeLayer.cxx @@ -228,6 +228,27 @@ PyObject *AdaoExchangeLayer::getPythonContext() const return _internal->_context; } +std::string AdaoExchangeLayer::printContext() const +{ + AutoGIL agil; + PyObject *obj(this->getPythonContext()); + if(!PyDict_Check(obj)) + throw AdaoExchangeLayerException("printContext : not a dict !"); + PyObject *key(nullptr), *value(nullptr); + Py_ssize_t pos(0); + std::ostringstream oss; + while( PyDict_Next(obj, &pos, &key, &value) ) + { + if(!PyUnicode_Check(key)) + throw AdaoExchangeLayerException("printContext : not a string as key !"); + oss << PyUnicode_AsUTF8(key) << " = "; + PyObjectRAII reprOfValue(PyObjectRAII::FromNew(PyObject_Repr(value))); + oss << PyUnicode_AsUTF8(reprOfValue); + oss << std::endl; + } + return oss.str(); +} + /*! * AdaoExchangeLayer is based on multithreaded paradigm. * Master thread (thread calling this method) and slave thread (thread calling ADAO algo) diff --git a/AdaoExchangeLayer.hxx b/AdaoExchangeLayer.hxx index dbb3dba..988e23c 100644 --- a/AdaoExchangeLayer.hxx +++ b/AdaoExchangeLayer.hxx @@ -22,6 +22,8 @@ #include "Python.h" +#include + class AdaoCallbackSt; namespace AdaoModel @@ -36,6 +38,7 @@ public: AdaoExchangeLayer(); ~AdaoExchangeLayer(); PyObject *getPythonContext() const; + std::string printContext() const; void init(); void loadTemplate(AdaoModel::MainModel *model); void execute(); diff --git a/AdaoModelKeyVal.cxx b/AdaoModelKeyVal.cxx index 0c21832..c22f022 100644 --- a/AdaoModelKeyVal.cxx +++ b/AdaoModelKeyVal.cxx @@ -333,11 +333,13 @@ Observation::Observation():DictKeyVal(KEY) ObservationOperator::ObservationOperator():DictKeyVal(KEY) { std::shared_ptr v0(std::make_shared()); - std::shared_ptr v1(std::make_shared()); - std::shared_ptr v2(std::make_shared()); + std::shared_ptr v1(std::make_shared()); + std::shared_ptr v2(std::make_shared()); + std::shared_ptr v3(std::make_shared()); _pairs.push_back(std::static_pointer_cast(v0)); - _pairs.push_back(std::static_pointer_cast(v1)); - _pairs.push_back(std::static_pointer_cast(v2)); + _pairs.push_back(std::static_pointer_cast(v1)); + _pairs.push_back(std::static_pointer_cast(v2)); + _pairs.push_back(std::static_pointer_cast(v3)); } ObserverEntry::ObserverEntry():DictKeyVal(KEY) -- 2.39.2