PetaVision  Alpha
DependentArborList.cpp
1 /*
2  * DependentArborList.cpp
3  *
4  * Created on: Jan 5, 2018
5  * Author: pschultz
6  */
7 
8 #include "DependentArborList.hpp"
9 #include "columns/HyPerCol.hpp"
10 #include "columns/ObjectMapComponent.hpp"
11 #include "components/OriginalConnNameParam.hpp"
12 #include "connections/BaseConnection.hpp"
13 #include "utils/MapLookupByType.hpp"
14 
15 namespace PV {
16 
17 DependentArborList::DependentArborList(char const *name, HyPerCol *hc) { initialize(name, hc); }
18 
19 DependentArborList::DependentArborList() {}
20 
21 DependentArborList::~DependentArborList() {}
22 
23 int DependentArborList::initialize(char const *name, HyPerCol *hc) {
24  return ArborList::initialize(name, hc);
25 }
26 
27 void DependentArborList::setObjectType() { mObjectType = "DependentArborList"; }
28 
29 int DependentArborList::ioParamsFillGroup(enum ParamsIOFlag ioFlag) {
30  return ArborList::ioParamsFillGroup(ioFlag);
31 }
32 
33 void DependentArborList::ioParam_numAxonalArbors(enum ParamsIOFlag ioFlag) {
34  if (ioFlag == PARAMS_IO_READ) {
35  parent->parameters()->handleUnnecessaryParameter(name, "numAxonalArbors");
36  }
37  // During the communication phase, numAxonalArbors will be copied from originalConn
38 }
39 
40 Response::Status
41 DependentArborList::communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) {
42  auto hierarchy = message->mHierarchy;
43 
44  char const *originalConnName = getOriginalConnName(hierarchy);
45  pvAssert(originalConnName);
46 
47  auto *originalArborList = getOriginalArborList(hierarchy, originalConnName);
48  pvAssert(originalArborList);
49 
50  if (!originalArborList->getInitInfoCommunicatedFlag()) {
51  if (parent->getCommunicator()->globalCommRank() == 0) {
52  InfoLog().printf(
53  "%s must wait until original connection \"%s\" has finished its communicateInitInfo "
54  "stage.\n",
55  getDescription_c(),
56  originalConnName);
57  }
58  return Response::POSTPONE;
59  }
60  mNumAxonalArbors = originalArborList->getNumAxonalArbors();
61  parent->parameters()->handleUnnecessaryParameter(name, "numAxonalArbors", mNumAxonalArbors);
62 
63  auto status = ArborList::communicateInitInfo(message);
64  if (!Response::completed(status)) {
65  return status;
66  }
67  return Response::SUCCESS;
68 }
69 
70 char const *
71 DependentArborList::getOriginalConnName(std::map<std::string, Observer *> const hierarchy) const {
72  OriginalConnNameParam *originalConnNameParam =
73  mapLookupByType<OriginalConnNameParam>(hierarchy, getDescription());
74  FatalIf(
75  originalConnNameParam == nullptr,
76  "%s requires an OriginalConnNameParam component.\n",
77  getDescription_c());
78  char const *originalConnName = originalConnNameParam->getOriginalConnName();
79  return originalConnName;
80 }
81 
82 ArborList *DependentArborList::getOriginalArborList(
83  std::map<std::string, Observer *> const hierarchy,
84  char const *originalConnName) const {
85  ObjectMapComponent *objectMapComponent =
86  mapLookupByType<ObjectMapComponent>(hierarchy, getDescription());
87  pvAssert(objectMapComponent);
88  BaseConnection *originalConn =
89  objectMapComponent->lookup<BaseConnection>(std::string(originalConnName));
90  if (originalConn == nullptr) {
91  if (parent->getCommunicator()->globalCommRank() == 0) {
92  ErrorLog().printf(
93  "%s: originalConnName \"%s\" does not correspond to a BaseConnection in the "
94  "column.\n",
95  getDescription_c(),
96  originalConnName);
97  }
98  MPI_Barrier(parent->getCommunicator()->globalCommunicator());
99  exit(PV_FAILURE);
100  }
101 
102  auto *originalArborList = originalConn->getComponentByType<ArborList>();
103  FatalIf(
104  originalArborList == nullptr,
105  "%s original connection \"%s\" does not have an ArborList.\n",
106  getDescription_c(),
107  originalConnName);
108  return originalArborList;
109 }
110 
111 } // namespace PV
virtual void ioParam_numAxonalArbors(enum ParamsIOFlag ioFlag) override
numAxonalArbors: DependentArborList does not use the numAxonalArbors parameter, but gets the number o...
static bool completed(Status &a)
Definition: Response.hpp:49
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
Definition: ArborList.cpp:28
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override