PetaVision  Alpha
PlasticCloneConn.cpp
1 /* PlasticCloneConn.cpp
2  *
3  * Created on: May 23, 2011
4  * Author: peteschultz
5  */
6 
7 #include "PlasticCloneConn.hpp"
8 #include "columns/HyPerCol.hpp"
9 #include "components/OriginalConnNameParam.hpp"
10 #include "weightupdaters/HebbianUpdater.hpp"
11 
12 namespace PV {
13 
14 PlasticCloneConn::PlasticCloneConn() {}
15 
16 PlasticCloneConn::PlasticCloneConn(const char *name, HyPerCol *hc) { initialize(name, hc); }
17 
18 PlasticCloneConn::~PlasticCloneConn() {}
19 
20 int PlasticCloneConn::initialize(const char *name, HyPerCol *hc) {
21  int status = CloneConn::initialize(name, hc);
22  return status;
23 }
24 
25 Response::Status
26 PlasticCloneConn::communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) {
27  auto status = CloneConn::communicateInitInfo(message);
28  if (!Response::completed(status)) {
29  return status;
30  }
31  auto *originalConnNameParam = getComponentByType<OriginalConnNameParam>();
32  FatalIf(
33  originalConnNameParam == nullptr,
34  "%s requires an OriginalConnNameParam component.\n",
35  getDescription_c());
36  auto *originalConnName = originalConnNameParam->getOriginalConnName();
37  auto *originalConn = message->lookup<HyPerConn>(std::string(originalConnName));
38  pvAssert(originalConn); // CloneConn::communicateInitInfo should have failed if this fails.
39  auto *originalUpdater = originalConn->getComponentByType<HebbianUpdater>();
40  FatalIf(
41  originalUpdater == nullptr,
42  "%s specifies %s as its original connection, but this connection does not have a "
43  "Hebbian updater.\n",
44  getDescription_c(),
45  originalConn->getDescription_c());
46  // Do we need to handle PlasticClones of PlasticClones? Right now, this won't handle that case.
47  auto *connectionData = getComponentByType<ConnectionData>();
48  pvAssert(connectionData); // BaseConnection creates this component
49  pvAssert(connectionData->getInitInfoCommunicatedFlag()); // Set while CloneConn communicates
50  // CloneConn creates this component, and
51  // CloneConn::CommunicateInitInfo shouldn't return until its components have communicated.
52  originalUpdater->addClone(connectionData);
53 
54  return Response::SUCCESS;
55 }
56 
57 } // end namespace PV
static bool completed(Status &a)
Definition: Response.hpp:49