PetaVision  Alpha
BaseProbe.hpp
1 /*
2  * BaseProbe.hpp
3  *
4  * Author: slundquist
5  */
6 
7 #ifndef BASEPROBE_HPP_
8 #define BASEPROBE_HPP_
9 
10 #include "columns/BaseObject.hpp"
11 #include "include/pv_common.h"
12 #include "io/FileStream.hpp"
13 #include "io/io.hpp"
14 #include <stdio.h>
15 #include <vector>
16 
17 namespace PV {
18 
19 class HyPerCol;
20 class HyPerLayer;
21 
26 class BaseProbe : public BaseObject {
27 
28  // Methods
29  public:
30  virtual ~BaseProbe();
31 
39  virtual Response::Status
40  communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) override = 0;
41 
48  virtual Response::Status registerData(Checkpointer *checkpointer) override;
49 
61  int getNumValues() { return numValues; }
62 
70  virtual Response::Status outputStateWrapper(double timef, double dt);
71 
75  virtual Response::Status outputState(double timef) = 0;
76  virtual int writeTimer(PrintStream &stream) { return PV_SUCCESS; }
77 
83  const char *getTargetName() { return targetName; }
84 
90  char const *getEnergyProbe() { return energyProbe; }
91 
95  double getCoefficient() { return coefficient; }
96 
102  double getLastUpdateTime() { return lastUpdateTime; }
103 
119  void getValues(double timevalue, double *valuesVector);
127  void getValues(double timevalue, std::vector<double> *valuesVector);
139  double getValue(double timevalue, int index);
140 
141  protected:
142  BaseProbe();
143  int initialize(const char *name, HyPerCol *hc);
144 
145  virtual void setObjectType() override;
146 
147  virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override;
148 
160  virtual void ioParam_targetName(enum ParamsIOFlag ioFlag);
161 
167  virtual void ioParam_message(enum ParamsIOFlag ioFlag);
168 
174  virtual void ioParam_textOutputFlag(enum ParamsIOFlag ioFlag);
175 
182  virtual void ioParam_probeOutputFile(enum ParamsIOFlag ioFlag);
183 
190  virtual void ioParam_triggerFlag(enum ParamsIOFlag ioFlag);
191 
197  virtual void ioParam_triggerLayerName(enum ParamsIOFlag ioFlag);
198 
204  virtual void ioParam_triggerOffset(enum ParamsIOFlag ioFlag);
205 
210  virtual void ioParam_energyProbe(enum ParamsIOFlag ioFlag);
211 
219  virtual void ioParam_coefficient(enum ParamsIOFlag ioFlag);
232  virtual void initOutputStreams(const char *filename, Checkpointer *checkpointer);
233 
246  virtual bool needRecalc(double timevalue) = 0;
247 
260  virtual double referenceUpdateTime() const = 0;
261 
268  virtual void calcValues(double timevalue) = 0;
269 
275  void getValues(double timevalue);
276 
280  const char *getMessage() { return msgstring; }
281 
286  virtual int initMessage(const char *msg);
287 
291  PrintStream &output(int b) { return *mOutputStreams.at(b); }
292 
300  virtual void initNumValues();
301 
309  void setNumValues(int n);
310 
314  char const *getProbeOutputFilename() { return probeOutputFilename; }
315 
319  double *getValuesBuffer() { return probeValues; }
320 
324  inline bool getTextOutputFlag() const { return textOutputFlag; }
325 
330  inline bool isWritingToFile() const { return probeOutputFilename != nullptr; }
331 
342  virtual bool needUpdate(double time, double dt);
343 
344  private:
345  int initialize_base();
346 
347  // Member variables
348  protected:
349  // A vector of PrintStreams, one for each batch element.
350  std::vector<PrintStream *> mOutputStreams;
351 
352  bool triggerFlag;
353  char *triggerLayerName;
354  HyPerLayer *triggerLayer;
355  double triggerOffset;
356  char *targetName;
357  char *energyProbe; // the name of the ColumnEnergyProbe to attach to, if any.
358  double coefficient;
359 
360  private:
361  char *msgparams; // the message parameter in the params
362  char *msgstring; // the string that gets printed by outputState ("" if message
363  // is empty or null;
364  // message + ":" if nonempty
365  char *probeOutputFilename;
366  int numValues;
367  double *probeValues;
368  double lastUpdateTime; // The time of the last time calcValues was called.
369  bool textOutputFlag;
370  bool mInitInfoCommunicatedFlag = false;
371  bool mDataStructuresAllocatedFlag = false;
372 };
373 }
374 
375 #endif /* BASEPROBE_HPP_ */
virtual void ioParam_coefficient(enum ParamsIOFlag ioFlag)
coefficient: If energyProbe is set, the coefficient parameter specifies that ColumnEnergyProbe multip...
Definition: BaseProbe.cpp:106
double getLastUpdateTime()
Definition: BaseProbe.hpp:102
double getValue(double timevalue, int index)
Definition: BaseProbe.cpp:346
virtual void calcValues(double timevalue)=0
const char * getTargetName()
Definition: BaseProbe.hpp:83
void setNumValues(int n)
Definition: BaseProbe.cpp:221
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
Definition: BaseProbe.cpp:76
char const * getProbeOutputFilename()
Definition: BaseProbe.hpp:314
virtual void ioParam_message(enum ParamsIOFlag ioFlag)
message: A string parameter that is typically included in the lines output by the outputState method ...
Definition: BaseProbe.cpp:93
PrintStream & output(int b)
Definition: BaseProbe.hpp:291
virtual double referenceUpdateTime() const =0
virtual Response::Status outputState(double timef)=0
virtual void ioParam_energyProbe(enum ParamsIOFlag ioFlag)
energyProbe: If nonblank, specifies the name of a ColumnEnergyProbe that this probe contributes an en...
Definition: BaseProbe.cpp:101
double getCoefficient()
Definition: BaseProbe.hpp:95
virtual void ioParam_triggerFlag(enum ParamsIOFlag ioFlag)
triggerFlag: If false, the needUpdate method always returns true, so that outputState is called every...
Definition: BaseProbe.cpp:139
virtual void initNumValues()
Definition: BaseProbe.cpp:219
virtual bool needRecalc(double timevalue)=0
double * getValuesBuffer()
Definition: BaseProbe.hpp:319
bool isWritingToFile() const
Definition: BaseProbe.hpp:330
virtual void ioParam_triggerOffset(enum ParamsIOFlag ioFlag)
triggerOffset: If triggerFlag is true, triggerOffset specifies the time interval before the triggerLa...
Definition: BaseProbe.cpp:157
virtual void initOutputStreams(const char *filename, Checkpointer *checkpointer)
Definition: BaseProbe.cpp:174
const char * getMessage()
Definition: BaseProbe.hpp:280
virtual bool needUpdate(double time, double dt)
Definition: BaseProbe.cpp:313
virtual void ioParam_textOutputFlag(enum ParamsIOFlag ioFlag)
textOutputFlag: A boolean parameter that sets whether to generate an output file. Defaults to true...
Definition: BaseProbe.cpp:114
virtual Response::Status registerData(Checkpointer *checkpointer) override
Definition: BaseProbe.cpp:320
char const * getEnergyProbe()
Definition: BaseProbe.hpp:90
virtual Response::Status outputStateWrapper(double timef, double dt)
Definition: BaseProbe.cpp:358
void getValues(double timevalue, double *valuesVector)
Definition: BaseProbe.cpp:336
virtual void ioParam_probeOutputFile(enum ParamsIOFlag ioFlag)
probeOutputFile: If textOutputFlag is true, probeOutputFile specifies the name of the file that the o...
Definition: BaseProbe.cpp:119
virtual void ioParam_triggerLayerName(enum ParamsIOFlag ioFlag)
triggerLayerName: If triggerFlag is true, triggerLayerName specifies the layer to check for triggerin...
Definition: BaseProbe.cpp:127
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 getNumValues()
Definition: BaseProbe.hpp:61
bool getTextOutputFlag() const
Definition: BaseProbe.hpp:324
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
virtual int initMessage(const char *msg)
Definition: BaseProbe.cpp:282