lcls2
C++ API: public headers of xtcdata, psalg, psdaq and psana
Loading...
Searching...
No Matches
Pds_Epics::EpicsPVA Class Reference

Client of one EPICS PV over pvAccess or Channel Access. More...

#include <EpicsPVA.hh>

Inherits pvac::ClientChannel::ConnectCallback, pvac::ClientChannel::GetCallback, and pvac::ClientChannel::MonitorCallback.

Inherited by Pds_Epics::PVBase, Pds_Epics::PVCached, Pds_Epics::PVMonitor, and Pds_Epics::PvServer.

Public Member Functions

 EpicsPVA (const char *channelName, const int maxElements=0)
 Connect to channelName through pva without a monitor callback; maxElements is not used.
 
 EpicsPVA (const char *channelName, PVMonitorCb *, const int maxElements=0)
 Connect to channelName through pva; monitor, if not null, receives updated() calls.
 
 EpicsPVA (const char *provider, const char *channelName, PVMonitorCb *, const int maxElements=0, bool nType=false)
 Connect to channelName through ca if provider is ca, otherwise pva.
 
virtual ~EpicsPVA ()
 Remove the connect listener and cancel the pending get.
 
std::string name () const
 Return the channel name.
 
bool connected () const
 Return the state from the last connect event; the flag is not initialized before the first event.
 
long sec ()
 Return secondsPastEpoch of the PV time stamp, or -1 if no value arrives within 30 s (getComplete()).
 
int nsec ()
 Return the nanoseconds of the PV time stamp, or -1 if no value arrives within 30 s.
 
size_t nelem ()
 Return the length of the value array, or the largest size_t value (from -1) if no value arrives within 30 s.
 
template<typename T >
T getScalarAs (const char *field="value") const
 Return field (default value) of the latest structure converted to T, or 0 if no value has been received.
 
template<typename T >
void getVectorAs (pvd::shared_vector< const T > &vec, const char *field="value") const
 Copy array field (default value) of the latest structure into vec as T; does nothing if no value has been received.
 
template<typename T >
T getVectorElemAt (size_t i, const char *field="value") const
 Return element i of array field converted to T, converting the whole array first (per the code comment); i is not range-checked.
 
template<typename T >
void putFrom (T val)
 Put val to the value field and wait for the put to end; timeouts and runtime errors are caught and printed.
 
template<typename T >
void putFromVector (const pvd::shared_vector< const T > &val)
 Put array val to the value field and wait for the put to end; timeouts are caught and printed.
 
void putFromStructure (const void *val, const unsigned *sizes, bool ldebug=false)
 Put the packed buffer val to the top-level fields of the PV (see StructurePutTracker) and wait for the put to end; timeouts are caught and printed.
 
virtual void getDone (const pvac::GetEvent &evt)
 Get callback: on success, fulfil the value promise and, if a monitor callback was given, start monitoring (only timeStamp and value if nType is set).
 
virtual void connectEvent (const pvac::ConnectEvent &evt)
 Connect callback: store the connection state and, if connected, start a get of the PV.
 
virtual void monitorEvent (const pvac::MonitorEvent &evt)
 Monitor callback: for data, store each queued update as the latest structure and call the monitor callback's updated().
 

Static Public Member Functions

static void setProvider (const char *)
 Declared but not defined in EpicsPVA.cc.
 

Protected Member Functions

virtual void onConnect ()
 
bool getComplete (unsigned tmo)
 
bool getComplete ()
 

Protected Attributes

pvac::ClientChannel _channel
 
pvac::Operation _op
 
pvac::Monitor _pvmon
 
std::promise< pvd::PVStructure::const_shared_pointer > _promise
 
pvd::PVStructure::const_shared_pointer _strct
 
PVMonitorCb * _monitorCB
 
bool _nType
 
bool _connected
 

Detailed Description

Client of one EPICS PV over pvAccess or Channel Access.

It connects asynchronously, gets the value once connected and, if a PVMonitorCb is given, then monitors the PV and calls its updated() for each update. getScalarAs() and related methods read the latest value; the put methods block until the put ends.

Constructor & Destructor Documentation

◆ EpicsPVA() [1/3]

Pds_Epics::EpicsPVA::EpicsPVA ( const char *  channelName,
const int  maxElements = 0 
)

Connect to channelName through pva without a monitor callback; maxElements is not used.

◆ EpicsPVA() [2/3]

Pds_Epics::EpicsPVA::EpicsPVA ( const char *  channelName,
PVMonitorCb *  ,
const int  maxElements = 0 
)

Connect to channelName through pva; monitor, if not null, receives updated() calls.

maxElements is not used.

◆ EpicsPVA() [3/3]

Pds_Epics::EpicsPVA::EpicsPVA ( const char *  provider,
const char *  channelName,
PVMonitorCb *  ,
const int  maxElements = 0,
bool  nType = false 
)

Connect to channelName through ca if provider is ca, otherwise pva.

If nType is true, monitoring requests only the timeStamp and value fields; maxElements is not used.

◆ ~EpicsPVA()

virtual Pds_Epics::EpicsPVA::~EpicsPVA ( )
virtual

Remove the connect listener and cancel the pending get.

Member Function Documentation

◆ connected()

bool Pds_Epics::EpicsPVA::connected ( ) const
inline

Return the state from the last connect event; the flag is not initialized before the first event.

◆ connectEvent()

virtual void Pds_Epics::EpicsPVA::connectEvent ( const pvac::ConnectEvent &  evt)
virtual

Connect callback: store the connection state and, if connected, start a get of the PV.

◆ getComplete() [1/2]

bool Pds_Epics::EpicsPVA::getComplete ( )
inlineprotected

◆ getComplete() [2/2]

bool Pds_Epics::EpicsPVA::getComplete ( unsigned  tmo)
protected

◆ getDone()

virtual void Pds_Epics::EpicsPVA::getDone ( const pvac::GetEvent &  evt)
virtual

Get callback: on success, fulfil the value promise and, if a monitor callback was given, start monitoring (only timeStamp and value if nType is set).

Failures and cancellations are printed.

◆ getScalarAs()

template<typename T >
T Pds_Epics::EpicsPVA::getScalarAs ( const char *  field = "value") const
inline

Return field (default value) of the latest structure converted to T, or 0 if no value has been received.

◆ getVectorAs()

template<typename T >
void Pds_Epics::EpicsPVA::getVectorAs ( pvd::shared_vector< const T > &  vec,
const char *  field = "value" 
) const
inline

Copy array field (default value) of the latest structure into vec as T; does nothing if no value has been received.

◆ getVectorElemAt()

template<typename T >
T Pds_Epics::EpicsPVA::getVectorElemAt ( size_t  i,
const char *  field = "value" 
) const
inline

Return element i of array field converted to T, converting the whole array first (per the code comment); i is not range-checked.

Returns 0 if no value has been received.

◆ monitorEvent()

virtual void Pds_Epics::EpicsPVA::monitorEvent ( const pvac::MonitorEvent &  evt)
virtual

Monitor callback: for data, store each queued update as the latest structure and call the monitor callback's updated().

Failures, cancels and disconnects are only printed.

◆ name()

std::string Pds_Epics::EpicsPVA::name ( ) const
inline

Return the channel name.

◆ nelem()

size_t Pds_Epics::EpicsPVA::nelem ( )

Return the length of the value array, or the largest size_t value (from -1) if no value arrives within 30 s.

◆ nsec()

int Pds_Epics::EpicsPVA::nsec ( )

Return the nanoseconds of the PV time stamp, or -1 if no value arrives within 30 s.

◆ onConnect()

virtual void Pds_Epics::EpicsPVA::onConnect ( )
protectedvirtual

◆ putFrom()

template<typename T >
void Pds_Epics::EpicsPVA::putFrom ( T  val)
inline

Put val to the value field and wait for the put to end; timeouts and runtime errors are caught and printed.

◆ putFromStructure()

void Pds_Epics::EpicsPVA::putFromStructure ( const void *  val,
const unsigned *  sizes,
bool  ldebug = false 
)
inline

Put the packed buffer val to the top-level fields of the PV (see StructurePutTracker) and wait for the put to end; timeouts are caught and printed.

◆ putFromVector()

template<typename T >
void Pds_Epics::EpicsPVA::putFromVector ( const pvd::shared_vector< const T > &  val)
inline

Put array val to the value field and wait for the put to end; timeouts are caught and printed.

◆ sec()

long Pds_Epics::EpicsPVA::sec ( )

Return secondsPastEpoch of the PV time stamp, or -1 if no value arrives within 30 s (getComplete()).

◆ setProvider()

static void Pds_Epics::EpicsPVA::setProvider ( const char *  )
static

Declared but not defined in EpicsPVA.cc.

Member Data Documentation

◆ _channel

pvac::ClientChannel Pds_Epics::EpicsPVA::_channel
protected

◆ _connected

bool Pds_Epics::EpicsPVA::_connected
protected

◆ _monitorCB

PVMonitorCb* Pds_Epics::EpicsPVA::_monitorCB
protected

◆ _nType

bool Pds_Epics::EpicsPVA::_nType
protected

◆ _op

pvac::Operation Pds_Epics::EpicsPVA::_op
protected

◆ _promise

std::promise<pvd::PVStructure::const_shared_pointer> Pds_Epics::EpicsPVA::_promise
protected

◆ _pvmon

pvac::Monitor Pds_Epics::EpicsPVA::_pvmon
protected

◆ _strct

pvd::PVStructure::const_shared_pointer Pds_Epics::EpicsPVA::_strct
protected

The documentation for this class was generated from the following file: