PetaVision  Alpha
LayerProbe.cpp
1 /*
2  * LayerProbe.cpp
3  *
4  * Created on: Mar 7, 2009
5  * Author: rasmussn
6  */
7 
8 #include "LayerProbe.hpp"
9 #include "../layers/HyPerLayer.hpp"
10 
11 namespace PV {
12 
13 LayerProbe::LayerProbe() {
14  initialize_base();
15  // Derived classes of LayerProbe should call LayerProbe::initialize
16  // themselves.
17 }
18 
22 LayerProbe::LayerProbe(const char *name, HyPerCol *hc) {
23  initialize_base();
24  initialize(name, hc);
25 }
26 
27 LayerProbe::~LayerProbe() {}
28 
29 int LayerProbe::initialize_base() {
30  targetLayer = NULL;
31  return PV_SUCCESS;
32 }
33 
38 int LayerProbe::initialize(const char *name, HyPerCol *hc) {
39  int status = BaseProbe::initialize(name, hc);
40  return status;
41 }
42 
43 void LayerProbe::ioParam_targetName(enum ParamsIOFlag ioFlag) {
44  // targetLayer is a legacy parameter, so here, it's not required
45  parent->parameters()->ioParamString(
46  ioFlag, name, "targetLayer", &targetName, NULL /*default*/, false /*warnIfAbsent*/);
47  // But if it isn't defined, targetName must be, which BaseProbe checks for
48  if (targetName == NULL) {
50  }
51 }
52 
53 Response::Status
54 LayerProbe::communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) {
55  auto status = BaseProbe::communicateInitInfo(message);
56  if (!Response::completed(status)) {
57  return status;
58  }
59  // Set target layer
60  targetLayer = message->lookup<HyPerLayer>(std::string(targetName));
61  if (targetLayer == NULL) {
62  if (parent->columnId() == 0) {
63  ErrorLog().printf(
64  "%s: targetLayer \"%s\" is not a layer in the column.\n",
65  getDescription_c(),
66  targetName);
67  }
68  MPI_Barrier(parent->getCommunicator()->communicator());
69  exit(EXIT_FAILURE);
70  }
71 
72  // Add to layer
73  targetLayer->insertProbe(this);
74  return Response::SUCCESS;
75 }
76 
77 bool LayerProbe::needRecalc(double timevalue) {
78  return this->getLastUpdateTime() < targetLayer->getLastUpdateTime();
79 }
80 
81 double LayerProbe::referenceUpdateTime() const { return targetLayer->getLastUpdateTime(); }
82 
83 } // namespace PV
double getLastUpdateTime()
Definition: BaseProbe.hpp:102
virtual void ioParam_targetName(enum ParamsIOFlag ioFlag) override
targetName: the name of the layer to attach the probe to. In LayerProbes, targetLayer can be used in ...
Definition: LayerProbe.cpp:43
virtual double referenceUpdateTime() const override
Definition: LayerProbe.cpp:81
static bool completed(Status &a)
Definition: Response.hpp:49
int initialize(const char *name, HyPerCol *hc)
Definition: LayerProbe.cpp:38
virtual Response::Status communicateInitInfo(std::shared_ptr< CommunicateInitInfoMessage const > message) override
Definition: LayerProbe.cpp:54
virtual bool needRecalc(double timevalue) override
Definition: LayerProbe.cpp:77
virtual void ioParam_targetName(enum ParamsIOFlag ioFlag)
targetName: the name of the object that the probe attaches to. In LayerProbe, targetName is used to d...
Definition: BaseProbe.cpp:89
int initialize(const char *name, HyPerCol *hc)
Definition: BaseProbe.cpp:64
virtual Response::Status communicateInitInfo(std::shared_ptr< CommunicateInitInfoMessage const > message) override=0
Definition: BaseProbe.cpp:240