NRP Core  1.4.1
output_dummy.h
Go to the documentation of this file.
1 /* * NRP Core - Backend infrastructure to synchronize simulations
2  *
3  * Copyright 2020-2023 NRP Team
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * This project has received funding from the European Union’s Horizon 2020
18  * Framework Programme for Research and Innovation under the Specific Grant
19  * Agreement No. 945539 (Human Brain Project SGA3).
20  */
21 
22 #ifndef OUTPUT_DUMMY_H
23 #define OUTPUT_DUMMY_H
24 
25 #include <boost/python.hpp>
26 #include <iostream>
27 
30 
34 class OutputDummy : public OutputNode<boost::python::object> {
35 public:
36 
37  OutputDummy(const std::string &id,
38  bool publishFromCache = false,
39  unsigned int computePeriod = 1) :
41  { }
42 
43  size_t call_count = 0;
44  const boost::python::object* lastData = nullptr;
45  bool debugPrint = false;
46 
47 protected:
48 
49  void sendSingleMsg(const std::string& /*id*/, const boost::python::object* data) override
50  {
51  if(debugPrint) {
52  std::string o_s = boost::python::extract<std::string>(boost::python::str(*data));
53  std::stringstream msg;
54  msg << "Dummy output node " << this->id() << " got msg " << o_s;
55  NRPLogger::info(msg.str());
56  }
57 
58  lastData = data;
59  call_count++;
60  }
61 
62  void sendBatchMsg(const std::string& id, const std::vector<const boost::python::object*>& data) override
63  {
64  for (auto d : data) {
65  sendSingleMsg(id, d);
66  lastData = d;
67  }
68  }
69 };
70 
71 
72 class OutputDummyEdge : public SimpleOutputEdge<boost::python::object, OutputDummy> {
73 
74 public:
75 
76  OutputDummyEdge(const std::string &keyword, const std::string &id,
77  bool publishFromCache = false,
78  unsigned int computePeriod = 1) :
79  SimpleOutputEdge<boost::python::object, OutputDummy>(keyword, id, id, publishFromCache, computePeriod)
80  {}
81 
82 protected:
83 
85  { return new OutputDummy(this->_id, this->_publishFromCache, this->_computePeriod); }
86 };
87 
88 #endif //OUTPUT_DUMMY_H
OutputDummy::debugPrint
bool debugPrint
Definition: output_dummy.h:45
OutputDummy::sendSingleMsg
void sendSingleMsg(const std::string &, const boost::python::object *data) override
Sends out a single msg, to be implemented by derived classes.
Definition: output_dummy.h:49
OutputDummyEdge
Definition: output_dummy.h:72
OutputEdge::_computePeriod
unsigned int _computePeriod
Definition: output_edge.h:173
OutputEdge::_publishFromCache
bool _publishFromCache
Definition: output_edge.h:172
OutputEdge::_id
std::string _id
Definition: output_edge.h:170
OutputNodePolicies
Definition: computational_node_policies.h:47
OutputDummy::OutputDummy
OutputDummy(const std::string &id, bool publishFromCache=false, unsigned int computePeriod=1)
Definition: output_dummy.h:37
OutputNode< boost::python::object >::publishFromCache
bool publishFromCache()
Definition: output_node.h:109
OutputDummy
Dummy output node which just stores the last received msgs.
Definition: output_dummy.h:34
output_node.h
ComputationalNode::id
const std::string & id() const
Returns the node 'id'.
Definition: computational_node.h:57
NRPLogger::info
static void info(const FormatString &fmt, const Args &...args)
NRP logging function with message formatting for info level.
Definition: nrp_logger.h:138
OutputEdge
Helper class used to implement Python output edge decorators.
Definition: output_edge.h:36
OutputDummy::sendBatchMsg
void sendBatchMsg(const std::string &id, const std::vector< const boost::python::object * > &data) override
Sends out a vector of msg as a single batch, to be implemented by derived classes.
Definition: output_dummy.h:62
OutputNode
Implementation of an output node in the computation graph.
Definition: output_node.h:38
OutputDummyEdge::OutputDummyEdge
OutputDummyEdge(const std::string &keyword, const std::string &id, bool publishFromCache=false, unsigned int computePeriod=1)
Definition: output_dummy.h:76
python_grpc_engine.str
str
Definition: python_grpc_engine.py:63
OutputDummy::lastData
const boost::python::object * lastData
Definition: output_dummy.h:44
output_edge.h
OutputNodePolicies::SERIES
@ SERIES
Definition: computational_node_policies.h:51
OutputDummyEdge::makeNewNode
OutputDummy * makeNewNode() override
Definition: output_dummy.h:84
OutputDummy::call_count
size_t call_count
Definition: output_dummy.h:43
OutputNodePolicies::PublishFormatPolicy
PublishFormatPolicy
Defines how output nodes send stored msgs.
Definition: computational_node_policies.h:50