8 #include "BaseConnection.hpp" 9 #include "columns/HyPerCol.hpp" 10 #include "columns/ObjectMapComponent.hpp" 11 #include "utils/MapLookupByType.hpp" 15 BaseConnection::BaseConnection(
char const *name, HyPerCol *hc) { initialize(name, hc); }
17 BaseConnection::BaseConnection() {}
19 BaseConnection::~BaseConnection() {
24 int BaseConnection::initialize(
char const *name, HyPerCol *hc) {
25 int status = BaseObject::initialize(name, hc);
27 if (status == PV_SUCCESS) {
35 mComponentTable.addObject(observer->getDescription(), observer);
38 void BaseConnection::defineComponents() {
39 mConnectionData = createConnectionData();
40 if (mConnectionData) {
43 mDeliveryObject = createDeliveryObject();
44 if (mDeliveryObject) {
54 for (
auto &c : mComponentTable.getObjectVector()) {
61 Response::Status BaseConnection::respond(std::shared_ptr<BaseMessage const> message) {
62 Response::Status status = BaseObject::respond(message);
68 std::dynamic_pointer_cast<ConnectionWriteParamsMessage const>(message)) {
69 return respondConnectionWriteParams(castMessage);
73 std::dynamic_pointer_cast<ConnectionFinalizeUpdateMessage const>(message)) {
74 return respondConnectionFinalizeUpdate(castMessage);
76 else if (
auto castMessage = std::dynamic_pointer_cast<ConnectionOutputMessage const>(message)) {
77 return respondConnectionOutput(castMessage);
84 Response::Status BaseConnection::respondConnectionWriteParams(
85 std::shared_ptr<ConnectionWriteParamsMessage const> message) {
87 return Response::SUCCESS;
90 Response::Status BaseConnection::respondConnectionFinalizeUpdate(
91 std::shared_ptr<ConnectionFinalizeUpdateMessage const> message) {
93 mComponentTable, message, parent->getCommunicator()->globalCommRank() == 0 );
98 BaseConnection::respondConnectionOutput(std::shared_ptr<ConnectionOutputMessage const> message) {
101 mComponentTable, message, parent->getCommunicator()->globalCommRank() == 0 );
107 BaseConnection::communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) {
111 auto componentTable = mComponentTable;
113 objectMapComponent.setObjectMap(message->mHierarchy);
114 componentTable.addObject(objectMapComponent.getDescription(), &objectMapComponent);
115 auto communicateMessage =
116 std::make_shared<CommunicateInitInfoMessage>(componentTable.getObjectMap());
118 Response::Status status =
notify(
121 parent->getCommunicator()->globalCommRank() == 0 );
124 auto *deliveryObject = getComponentByType<BaseDelivery>();
125 pvAssert(deliveryObject);
126 HyPerLayer *postLayer = deliveryObject->getPostLayer();
127 if (postLayer !=
nullptr) {
131 for (
auto &c : componentTable.getObjectVector()) {
132 auto *baseObject =
dynamic_cast<BaseObject *
>(c);
134 mUsingGPUFlag |= baseObject->isUsingGPU();
137 #endif // PV_USE_CUDA 138 status = Response::SUCCESS;
146 BaseConnection::setCudaDevice(std::shared_ptr<SetCudaDeviceMessage const> message) {
147 auto status = BaseObject::setCudaDevice(message);
148 if (status != Response::SUCCESS) {
152 mComponentTable, message, parent->getCommunicator()->globalCommunicator() );
155 #endif // PV_USE_CUDA 157 Response::Status BaseConnection::allocateDataStructures() {
158 Response::Status status =
notify(
160 std::make_shared<AllocateDataMessage>(),
161 parent->getCommunicator()->globalCommRank() == 0 );
165 Response::Status BaseConnection::registerData(
Checkpointer *checkpointer) {
169 parent->getCommunicator()->globalCommRank() == 0 );
170 mIOTimer =
new Timer(getName(),
"conn",
"io");
171 checkpointer->registerTimer(mIOTimer);
175 void BaseConnection::deleteComponents() {
176 mComponentTable.clear(
true);
static bool completed(Status &a)
int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
Response::Status notify(ObserverTable const &table, std::vector< std::shared_ptr< BaseMessage const >> messages, bool printFlag)
virtual void addObserver(Observer *observer) override
void addRecvConn(BaseConnection *conn)
void ioParams(enum ParamsIOFlag ioFlag, bool printHeader, bool printFooter)