PetaVision  Alpha
FeedbackConnectionData.cpp
1 /*
2  * FeedbackConnectionData.cpp
3  *
4  * Created on: Jan 9, 2017
5  * Author: pschultz
6  */
7 
8 #include "FeedbackConnectionData.hpp"
9 #include "columns/HyPerCol.hpp"
10 #include "columns/ObjectMapComponent.hpp"
11 #include "components/OriginalConnNameParam.hpp"
12 #include "connections/HyPerConn.hpp"
13 #include "utils/MapLookupByType.hpp"
14 
15 namespace PV {
16 
17 FeedbackConnectionData::FeedbackConnectionData(char const *name, HyPerCol *hc) {
18  initialize(name, hc);
19 }
20 
21 FeedbackConnectionData::FeedbackConnectionData() {}
22 
23 FeedbackConnectionData::~FeedbackConnectionData() {}
24 
25 int FeedbackConnectionData::initialize(char const *name, HyPerCol *hc) {
26  return ConnectionData::initialize(name, hc);
27 }
28 
29 void FeedbackConnectionData::setObjectType() { mObjectType = "FeedbackConnectionData"; }
30 
31 int FeedbackConnectionData::ioParamsFillGroup(enum ParamsIOFlag ioFlag) {
32  return ConnectionData::ioParamsFillGroup(ioFlag);
33 }
34 
35 // FeedbackConn doesn't use preLayerName or postLayerName
36 // If they're present, errors are handled byy setPreAndPostLayerNames
37 void FeedbackConnectionData::ioParam_preLayerName(enum ParamsIOFlag ioFlag) {}
38 void FeedbackConnectionData::ioParam_postLayerName(enum ParamsIOFlag ioFlag) {}
39 
40 Response::Status FeedbackConnectionData::communicateInitInfo(
41  std::shared_ptr<CommunicateInitInfoMessage const> message) {
42  auto hierarchy = message->mHierarchy;
43  auto *originalConnNameParam =
44  mapLookupByType<OriginalConnNameParam>(hierarchy, getDescription());
45  FatalIf(
46  originalConnNameParam == nullptr,
47  "%s requires an OriginalConnNameParam component.\n",
48  getDescription_c());
49  if (!originalConnNameParam->getInitInfoCommunicatedFlag()) {
50  return Response::POSTPONE;
51  }
52  char const *originalConnName = originalConnNameParam->getOriginalConnName();
53  pvAssert(originalConnName != nullptr);
54 
55  ObjectMapComponent *objectMapComponent =
56  mapLookupByType<ObjectMapComponent>(hierarchy, getDescription());
57  pvAssert(objectMapComponent);
58  HyPerConn *originalConn = objectMapComponent->lookup<HyPerConn>(std::string(originalConnName));
59  if (originalConn == nullptr) {
60  if (parent->getCommunicator()->globalCommRank() == 0) {
61  ErrorLog().printf(
62  "%s: originalConnName \"%s\" does not correspond to a HyPerConn in the column.\n",
63  getDescription_c(),
64  originalConnName);
65  }
66  MPI_Barrier(parent->getCommunicator()->globalCommunicator());
67  exit(PV_FAILURE);
68  }
69  auto *originalConnectionData = originalConn->getComponentByType<ConnectionData>();
70  FatalIf(
71  originalConnectionData == nullptr,
72  "%s has original connection \"%s\", which does not have a ConnectionData component.\n",
73  getDescription_c(),
74  originalConn->getName());
75  if (!originalConnectionData->getInitInfoCommunicatedFlag()) {
76  return Response::POSTPONE;
77  }
78  free(mPreLayerName);
79  mPreLayerName = strdup(originalConnectionData->getPostLayerName());
80  free(mPostLayerName);
81  mPostLayerName = strdup(originalConnectionData->getPreLayerName());
82 
83  return ConnectionData::communicateInitInfo(message);
84 }
85 
86 } // namespace PV
virtual void ioParam_postLayerName(enum ParamsIOFlag ioFlag) override
preLayerName: FeedbackConnectionData does not read the preLayerName parameter, but takes the pre and ...
virtual void ioParam_preLayerName(enum ParamsIOFlag ioFlag) override
preLayerName: FeedbackConnectionData does not read the preLayerName parameter, but takes the pre and ...
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override