Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends | List of all members
NdmcClient Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-05-06/NovaDAQMonitorClient/cxx/include/NdmcClient.h"

Inheritance diagram for NdmcClient:
novadaq::Runnable

Public Member Functions

 NdmcClient (int32_t partition=-1, std::string appName="", std::string groupName="", uint32_t sendTimeInterval=15)
 
virtual ~NdmcClient ()
 
void run ()
 
uint32_t getNumMetric ()
 
int32_t getPartition () const
 
std::string getApplicationName () const
 
std::string getGroupName () const
 
uint32_t getSendTimeInterval () const
 
template<class T >
int32_t createMetric (std::string metricName, std::string units, MetricType_t metricType=VALUE, std::string title="", std::string description="")
 
template<class T >
int32_t createMetric (std::string metricName, std::string units, MetricType_t metricType, NdmcMetric< T > *&metricPtr, std::string title="", std::string description="")
 
int32_t send ()
 
void destroyMetric (int32_t metricID)
 
void destroyMetrics ()
 
bool setPartition (int32_t partition)
 
void setApplicationName (std::string appName)
 
void setGroupName (std::string groupName)
 
void setSendTimeInterval (uint32_t sendTimeInterval)
 
template<class T >
bool setValue (int32_t metricId, T value, double weight=1., int npar=0, double *par=0)
 
template<class T >
bool setValue (NdmcMetric< T > *metric, T value, double weight=1., int npar=0, double *par=0)
 
template<class T >
bool getLastValueSent (int32_t metricId, T &lastValueSent)
 
template<class T >
bool getLastValueSent (NdmcMetric< T > *metric, T &lastValueSent)
 
virtual void stop ()
 
virtual bool isRunning () const
 
virtual bool isDone () const
 
virtual void watchfulSleep (int microseconds, int numberOfIntervals=10)
 

Protected Attributes

bool _running
 
bool _stopRequested
 
bool _hasCompleted
 

Private Member Functions

bool _timeToSend ()
 
int32_t _adoptMetric (NdmcMetricABC *metric)
 
NdmcMetricABC_getMetric (int32_t metricId) const
 
void _updateGroupName ()
 

Private Attributes

int32_t _partition
 
std::string _applicationName
 
std::string _groupName
 
std::string _userGroupName
 
uint32_t _sendTimeInterval
 
std::map< int32_t, NdmcMetricABC * > _metricMap
 
clock_t _lastSendTime
 
boost::mutex _mutex
 
boost::thread * _clientThread
 

Friends

class ::NdmcClientTest
 

Detailed Description

NdmcClient

This class implements a NdmcClient client interface for a single process to the daq monitor.

Author
Susan Kasahara
schubert@physics.umn.edu
Date
May 6 2010

Definition at line 33 of file NdmcClient.h.

Constructor & Destructor Documentation

NdmcClient::NdmcClient ( int32_t  partition = -1,
std::string  appName = "",
std::string  groupName = "",
uint32_t  sendTimeInterval = 15 
)

Constructor

Definition at line 16 of file NdmcClient.cpp.

References _clientThread, _updateGroupName(), allTimeWatchdog::endl, getApplicationName(), getGroupName(), getPartition(), getSendTimeInterval(), LOG_DEBUG, and novadaq::Runnable::run().

17  :
19  _userGroupName(groupName), _sendTimeInterval(sendTimeInterval), _lastSendTime(0),
20  _clientThread(NULL) {
21 
23 
24  LOG_DEBUG("NdmcClient") << "NdmcClient::ctor @" << this << " w/ partition " << getPartition()
25  << ", app name " << getApplicationName() << ", group name "
26  << getGroupName() << ", send time interval "
27  << getSendTimeInterval() << "(s)." << std::endl;
28 
29  _clientThread = new boost::thread(boost::bind(&novadaq::Runnable::run,this));
30 
31 }
uint32_t _sendTimeInterval
Definition: NdmcClient.h:88
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::string _applicationName
Definition: NdmcClient.h:85
virtual void run()=0
clock_t _lastSendTime
Definition: NdmcClient.h:90
void _updateGroupName()
Definition: NdmcClient.cpp:99
std::string _userGroupName
Definition: NdmcClient.h:87
uint32_t getSendTimeInterval() const
Definition: NdmcClient.h:51
std::string _groupName
Definition: NdmcClient.h:86
int32_t getPartition() const
Definition: NdmcClient.h:48
std::string getApplicationName() const
Definition: NdmcClient.h:49
std::string getGroupName() const
Definition: NdmcClient.h:50
int32_t _partition
Definition: NdmcClient.h:84
boost::thread * _clientThread
Definition: NdmcClient.h:92
NdmcClient::~NdmcClient ( )
virtual

Destructor

Definition at line 36 of file NdmcClient.cpp.

References _clientThread, _metricMap, allTimeWatchdog::endl, LOG_DEBUG, moon_position_table_new3::second, and novadaq::Runnable::stop().

36  {
37 
38  LOG_DEBUG("NdmcClient") << "NdmcClient::dtor @" << this << "." << std::endl;
39 
40  stop();
41 
42  if ( _clientThread != NULL ) {
43  _clientThread -> join();
44  delete _clientThread;
45  }
46 
47  // All adopted metrics are owned
48  std::map<int32_t,NdmcMetricABC*>::iterator itr;
49  for ( itr = _metricMap.begin(); itr != _metricMap.end(); itr++ ) {
50  if ( itr -> second != NULL ) delete (itr -> second);
51  }
52  _metricMap.clear();
53 
54 }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::map< int32_t, NdmcMetricABC * > _metricMap
Definition: NdmcClient.h:89
virtual void stop()
Definition: Runnable.h:61
boost::thread * _clientThread
Definition: NdmcClient.h:92

Member Function Documentation

int32_t NdmcClient::_adoptMetric ( NdmcMetricABC metric)
private

Adopt a metric to own

Parameters
metric- pointer to user created NdmcMetric
Returns
-1 if already metric of this name, else metricId indexing metric in list

Definition at line 167 of file NdmcClient.cpp.

References _metricMap, allTimeWatchdog::endl, LOG_DEBUG, LogWarning, productionTest::metric, moon_position_table_new3::second, and string.

Referenced by createMetric(), NdmcClientTest::testAdoptMetric(), and NdmcClientTest::testGetMetric().

167  {
168 
169  int32_t metricID = -1;
170  std::string metricName = metric -> getName();
171  std::map<int32_t, NdmcMetricABC*>::const_iterator citr;
172  for ( citr = _metricMap.begin(); citr != _metricMap.end(); citr++ ) {
173  if ( metric -> getName() == (citr -> second) -> getName() ) {
174  ::mf::LogWarning("NdmcClient") << "NdmcClient::_adoptMetric - invoked for metric w/name "
175  << metricName << " failed. Duplicate name with existing entry." << std::endl;
176  return -1;
177  }
178  if ( citr -> first > metricID ) metricID = citr -> first;
179  }
180 
181  metricID += 1;
182  LOG_DEBUG("NdmcClient") << "NdmcClient::_adoptMetric - adopting metric with name "
183  << metricName << ", assigned metric ID " << metricID << "."
184  << std::endl;
185  _metricMap[metricID] = metric;
186  return metricID;
187 
188 }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::map< int32_t, NdmcMetricABC * > _metricMap
Definition: NdmcClient.h:89
enum BeamMode string
NdmcMetricABC * NdmcClient::_getMetric ( int32_t  metricID) const
private

Get a metric by metric ID

Parameters
metricIDindexing metric of interest
Returns
pointer to metric or NULL if doesn't exist

Definition at line 232 of file NdmcClient.cpp.

References _metricMap, and moon_position_table_new3::second.

Referenced by createMetric(), getLastValueSent(), setValue(), NdmcClientTest::testDestroyMetric(), NdmcClientTest::testGetLastValueSent(), and NdmcClientTest::testGetMetric().

232  {
233 
234  std::map<int32_t, NdmcMetricABC*>::const_iterator citr = _metricMap.find(metricID);
235  if ( citr == _metricMap.end() ) return NULL;
236  return citr -> second;
237 
238 }
std::map< int32_t, NdmcMetricABC * > _metricMap
Definition: NdmcClient.h:89
bool NdmcClient::_timeToSend ( )
private

Private method to determine if its time to send the next batch of metrics

Definition at line 274 of file NdmcClient.cpp.

References _lastSendTime, _sendTimeInterval, and plot_timing_data::times.

Referenced by run().

274  {
275 
276  struct tms ctime;
277  clock_t wall = times(&ctime);
278  if ( _lastSendTime == 0 ) {
279  _lastSendTime = wall;
280  return false;
281  }
282  double deltaw = ((double)(wall-_lastSendTime))*10000./CLOCKS_PER_SEC;
283 
284  if ( deltaw >= _sendTimeInterval ) {
285  _lastSendTime = wall;
286  return true;
287  }
288 
289  return false;
290 
291 }
uint32_t _sendTimeInterval
Definition: NdmcClient.h:88
clock_t _lastSendTime
Definition: NdmcClient.h:90
void NdmcClient::_updateGroupName ( )
private

Update group name to <appname>+P<partition> if groupname hasn't been set, or <groupname>+P<partition> if it has been set. Update managed metrics with current partition, appname, and groupname.

Definition at line 99 of file NdmcClient.cpp.

References _groupName, _metricMap, _userGroupName, allTimeWatchdog::endl, getApplicationName(), getGroupName(), getPartition(), LogInfo, moon_position_table_new3::second, setApplicationName(), setGroupName(), and setPartition().

Referenced by NdmcClient(), setApplicationName(), setGroupName(), and setPartition().

99  {
100 
101  std::ostringstream oss;
102  if ( !_userGroupName.empty() ) oss << _userGroupName;
103  else if ( !getApplicationName().empty() ) oss << getApplicationName();
104  if ( getPartition() >= 0 ) {
105  if ( oss.str().empty() ) oss << "P" << getPartition();
106  else oss << " P" << getPartition();
107  }
108  _groupName = oss.str();
109 
110  if ( _metricMap.size() == 0 ) return;
111 
112  std::ostringstream oss2;
113  std::map<int32_t, NdmcMetricABC*>::iterator itr;
114  int im = 0;
115  for ( itr = _metricMap.begin(); itr != _metricMap.end(); itr++, im++ ) {
116  (itr -> second) -> setPartition(getPartition());
118  (itr -> second) -> setGroupName(getGroupName());
119  if ( im > 0 ) oss2 << ", ";
120  if ( im % 5 == 0 ) oss2 << "\n";
121  oss2 << (itr -> second) -> getName();
122  }
123 
124  ::mf::LogInfo("NdmcClient") << "NdmcClient::_updataGroupName - Partition " << getPartition()
125  << ", AppName \"" << getApplicationName() << "\", GroupName \""
126  << getGroupName() << "\" applied to metric(s): " << oss2.str()
127  << "." << std::endl;
128 
129 }
void setGroupName(std::string groupName)
Definition: NdmcClient.cpp:85
std::map< int32_t, NdmcMetricABC * > _metricMap
Definition: NdmcClient.h:89
std::string _userGroupName
Definition: NdmcClient.h:87
std::string _groupName
Definition: NdmcClient.h:86
void setApplicationName(std::string appName)
Definition: NdmcClient.cpp:73
bool setPartition(int32_t partition)
Definition: NdmcClient.cpp:60
int32_t getPartition() const
Definition: NdmcClient.h:48
std::string getApplicationName() const
Definition: NdmcClient.h:49
std::string getGroupName() const
Definition: NdmcClient.h:50
template<class T >
int32_t NdmcClient::createMetric ( std::string  metricName,
std::string  units,
MetricType_t  metricType = VALUE,
std::string  title = "",
std::string  description = "" 
)

Create new metric of name metricName.

Parameters
metricName- name of this metric.
units- units to be displayed on axis of plot, e.g. "Bytes", "Hz"
metricType- VALUE,COUNTER,RATE,AVERAGE,MAXIMUM,MINIMUM,STDEV,HEARTBEAT
Returns
-1 if error, id number of this metric.

Definition at line 110 of file NdmcClient.h.

References _adoptMetric(), _mutex, _sendTimeInterval, makeFirstAnaHTMLDatasetPages::description, getApplicationName(), getGroupName(), getPartition(), productionTest::metric, and plotROC::title.

Referenced by getSendTimeInterval(), NdmcClientTest::testCreateMetric(), NdmcClientTest::testDestroyMetric(), and NdmcClientTest::testGetLastValueSent().

112  {
113 
114  boost::mutex::scoped_lock lock(_mutex);
115 
116  // tmax is the max time in seconds expected between metric sends (appears to be ignored)
117  int32_t tmax = _sendTimeInterval;
118  // dmax is the lifetime in seconds of this metric before it expires in ganglia plots
119  int32_t dmax = _sendTimeInterval*2;
120  NdmcMetric<T>* metric = new NdmcMetric<T>(metricName, units, metricType,
121  tmax, dmax, GANGLIA_SLOPE_BOTH,
123  title, description);
124 
125  int32_t metricID = _adoptMetric(metric);
126 
127  if ( metricID < 0 ) {
128  delete metric; metric = 0; // adoptMetric failed
129  }
130 
131  return metricID;
132 
133 }
uint32_t _sendTimeInterval
Definition: NdmcClient.h:88
int32_t _adoptMetric(NdmcMetricABC *metric)
Definition: NdmcClient.cpp:167
boost::mutex _mutex
Definition: NdmcClient.h:91
int32_t getPartition() const
Definition: NdmcClient.h:48
std::string getApplicationName() const
Definition: NdmcClient.h:49
std::string getGroupName() const
Definition: NdmcClient.h:50
template<class T >
int32_t NdmcClient::createMetric ( std::string  metricName,
std::string  units,
MetricType_t  metricType,
NdmcMetric< T > *&  metricPtr,
std::string  title = "",
std::string  description = "" 
)

Create new metric of name metricName.

Parameters
metricName- name of this metric.
units- units to be displayed on axis of plot, e.g. "Bytes", "Hz"
metricType- VALUE,COUNTER,RATE,AVERAGE,MAXIMUM,MINIMUM,STDEV,HEARTBEAT
Returns
-1 if error, id number of this metric.

Definition at line 143 of file NdmcClient.h.

References _getMetric(), makeFirstAnaHTMLDatasetPages::description, and plotROC::title.

145  {
146 
147  int32_t metricID = createMetric<T>(metricName,units,metricType,title,description);
148  metricPtr = NULL;
149  if ( metricID >= 0 ) metricPtr = dynamic_cast<NdmcMetric<T>*>(_getMetric(metricID));
150 
151  return metricID;
152 
153 }
NdmcMetricABC * _getMetric(int32_t metricId) const
Definition: NdmcClient.cpp:232
void NdmcClient::destroyMetric ( int32_t  metricID)

Destroy metric by ID.

Definition at line 193 of file NdmcClient.cpp.

References _metricMap, _mutex, allTimeWatchdog::endl, and LOG_DEBUG.

Referenced by getSendTimeInterval(), and NdmcClientTest::testDestroyMetric().

193  {
194 
195  LOG_DEBUG("NdmcClient") << "NdmcClient::destroyMetric - Metric ID " << metricID << "."
196  << std::endl;
197 
198  boost::mutex::scoped_lock lock(_mutex);
199 
200  std::map<int32_t, NdmcMetricABC*>::iterator itr = _metricMap.find(metricID);
201  if ( itr != _metricMap.end() ) {
202  if ( itr->second != NULL ) delete (itr->second);
203  _metricMap.erase(itr);
204  }
205 
206 }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::map< int32_t, NdmcMetricABC * > _metricMap
Definition: NdmcClient.h:89
boost::mutex _mutex
Definition: NdmcClient.h:91
void NdmcClient::destroyMetrics ( )

Destroy all managed metrics and remove from map

Definition at line 211 of file NdmcClient.cpp.

References _metricMap, _mutex, allTimeWatchdog::endl, LOG_DEBUG, and moon_position_table_new3::second.

Referenced by getSendTimeInterval().

211  {
212 
213  LOG_DEBUG("NdmcClient") << "NdmcClient::destroyMetrics." << std::endl;
214 
215  boost::mutex::scoped_lock lock(_mutex);
216 
217  // All adopted metrics are owned
218  std::map<int32_t,NdmcMetricABC*>::iterator itr;
219  for ( itr = _metricMap.begin(); itr != _metricMap.end(); itr++ ) {
220  if ( itr -> second != NULL ) delete (itr -> second);
221  }
222  _metricMap.clear();
223 
224 }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
std::map< int32_t, NdmcMetricABC * > _metricMap
Definition: NdmcClient.h:89
boost::mutex _mutex
Definition: NdmcClient.h:91
std::string NdmcClient::getApplicationName ( ) const
inline
std::string NdmcClient::getGroupName ( ) const
inline

Definition at line 50 of file NdmcClient.h.

References _groupName.

Referenced by _updateGroupName(), createMetric(), NdmcClient(), NdmcClientTest::testCtor(), and NdmcClientTest::testSetGroupName().

50 { return _groupName; }
std::string _groupName
Definition: NdmcClient.h:86
template<class T >
bool NdmcClient::getLastValueSent ( int32_t  metricID,
T lastValueSent 
)

Get last metric value sent, by metricID

Parameters
metricID- ID number of this metric
lastValueSent- reference of type T to return value
Returns
true if successful, else false. Will fail if metric of ID of type T has not been created.

Definition at line 214 of file NdmcClient.h.

References _getMetric(), _mutex, allTimeWatchdog::endl, LogWarning, productionTest::metric, and T.

Referenced by getLastValueSent(), getSendTimeInterval(), and NdmcClientTest::testGetLastValueSent().

214  {
215 
216  boost::mutex::scoped_lock lock(_mutex);
217 
218  NdmcMetric<T>* metric = dynamic_cast<NdmcMetric<T>*>(_getMetric(metricID));
219  if ( !metric ) {
220  ::mf::LogWarning("NdmcClient") << "NdmcClient::getLastValueSent - failed. No metric of id "
221  << metricID << " of type " << typeid(T).name() << "."
222  << std::endl;
223  return false;
224  }
225 
226  return metric -> getLastValueSent(lastValueSent);
227 
228 }
NdmcMetricABC * _getMetric(int32_t metricId) const
Definition: NdmcClient.cpp:232
const XML_Char * name
Definition: expat.h:151
boost::mutex _mutex
Definition: NdmcClient.h:91
bool getLastValueSent(int32_t metricId, T &lastValueSent)
Definition: NdmcClient.h:214
double T
Definition: Xdiff_gwt.C:5
template<class T >
bool NdmcClient::getLastValueSent ( NdmcMetric< T > *  metric,
T lastValueSent 
)

Get last metric value sent, by metric ptr. Recommend the user use getLastValueSent, by metric id unless performance is an issue.

Parameters
metric- ptr of type NdmcMetric<T>* previously created by NdmcClient::createMetric
lastValueSent- reference of type T to return value
Returns
true if successful, else false.

Definition at line 239 of file NdmcClient.h.

References _mutex, allTimeWatchdog::endl, getLastValueSent(), LogWarning, and NDMC_NAMESPACE_END.

239  {
240 
241  boost::mutex::scoped_lock lock(_mutex);
242 
243  if ( !metric ) {
244  ::mf::LogWarning("NdmcClient") << "NdmcClient::getLastValueSent - failed."
245  << " Passed NULL metric ptr." << std::endl;
246  return false;
247  }
248 
249  return metric -> getLastValueSent(lastValueSent);
250 
251 }
boost::mutex _mutex
Definition: NdmcClient.h:91
bool getLastValueSent(int32_t metricId, T &lastValueSent)
Definition: NdmcClient.h:214
uint32_t NdmcClient::getNumMetric ( )

Return number of metrics

Returns
number of metrics

Definition at line 245 of file NdmcClient.cpp.

References _metricMap, and _mutex.

Referenced by NdmcClientTest::testAdoptMetric(), NdmcClientTest::testCreateMetric(), NdmcClientTest::testCtor(), NdmcClientTest::testDestroyMetric(), NdmcClientTest::testGetLastValueSent(), and NdmcClientTest::testGetMetric().

245  {
246 
247  boost::mutex::scoped_lock lock(_mutex);
248  return _metricMap.size();
249 
250 }
std::map< int32_t, NdmcMetricABC * > _metricMap
Definition: NdmcClient.h:89
boost::mutex _mutex
Definition: NdmcClient.h:91
int32_t NdmcClient::getPartition ( ) const
inline

Definition at line 48 of file NdmcClient.h.

References _partition.

Referenced by _updateGroupName(), createMetric(), NdmcClient(), NdmcClientTest::testCtor(), and NdmcClientTest::testSetPartition().

48 { return _partition; }
int32_t _partition
Definition: NdmcClient.h:84
uint32_t NdmcClient::getSendTimeInterval ( ) const
inline
virtual bool novadaq::Runnable::isDone ( ) const
inlinevirtualinherited

Tests if the Runnable object has completed its running.

Returns
true if the object is done, false otherwise.

Definition at line 80 of file Runnable.h.

References novadaq::Runnable::_hasCompleted.

Referenced by novadaq::BackgroundProcess::timedWaitForDone().

80  {
81  return _hasCompleted;
82  }
virtual bool novadaq::Runnable::isRunning ( ) const
inlinevirtualinherited

Tests if the Runnable object is running.

Returns
true if the object is running, false otherwise.

Definition at line 71 of file Runnable.h.

References novadaq::Runnable::_running.

71  {
72  return _running;
73  }
void NdmcClient::run ( )
virtual

Main process loop. run() will run continuously until _stopRequested is set with a stop request.

Implements novadaq::Runnable.

Definition at line 134 of file NdmcClient.cpp.

References novadaq::Runnable::_running, novadaq::Runnable::_stopRequested, _timeToSend(), allTimeWatchdog::endl, LOG_DEBUG, and send().

134  {
135 
136  LOG_DEBUG("NdmcClient") << "NdmcClient::run." << std::endl;
137 
138  _running = true; // base class Runnable data member. Allows isRunning() to be used.
139  while ( !_stopRequested ) { // stop requested by invoking stop method
140  sleep(1);
141  if ( _timeToSend() ) {
142  send(); // send the metrics
143  }
144  }
145 
146  _running = false;
147 
148  LOG_DEBUG("NdmcClient") << "NdmcClient::run - done." << std::endl;
149 
150 }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
bool _timeToSend()
Definition: NdmcClient.cpp:274
int32_t send()
Definition: NdmcClient.cpp:257
int32_t NdmcClient::send ( )

Send all metrics. Return number of metrics successfully sent. Compare to NdmcClient::getNumMetric().

Returns
number of metrics successfully sent

Definition at line 257 of file NdmcClient.cpp.

References _metricMap, and _mutex.

Referenced by getSendTimeInterval(), and run().

257  {
258 
259  boost::mutex::scoped_lock lock(_mutex);
260 
261  int32_t nokay = 0;
262 
263  std::map<int32_t, NdmcMetricABC*>::iterator itr;
264  for ( itr = _metricMap.begin(); itr != _metricMap.end(); itr++ ) {
265  if ( (itr->second) -> send() ) nokay++;
266  }
267  return nokay;
268 
269 }
std::map< int32_t, NdmcMetricABC * > _metricMap
Definition: NdmcClient.h:89
boost::mutex _mutex
Definition: NdmcClient.h:91
int32_t send()
Definition: NdmcClient.cpp:257
void NdmcClient::setApplicationName ( std::string  appName)

Set application name

Definition at line 73 of file NdmcClient.cpp.

References _applicationName, _mutex, and _updateGroupName().

Referenced by _updateGroupName(), getSendTimeInterval(), NdmcClientTest::testSetApplicationName(), and NdmcClientTest::testSetGroupName().

73  {
74 
75  boost::mutex::scoped_lock lock(_mutex);
76 
77  _applicationName = appName;
79 
80 }
std::string _applicationName
Definition: NdmcClient.h:85
void _updateGroupName()
Definition: NdmcClient.cpp:99
boost::mutex _mutex
Definition: NdmcClient.h:91
void NdmcClient::setGroupName ( std::string  groupName)

Set group name

Definition at line 85 of file NdmcClient.cpp.

References _mutex, _updateGroupName(), and _userGroupName.

Referenced by _updateGroupName(), getSendTimeInterval(), and NdmcClientTest::testSetGroupName().

85  {
86 
87  boost::mutex::scoped_lock lock(_mutex);
88 
89  _userGroupName = groupName;
91 
92 }
void _updateGroupName()
Definition: NdmcClient.cpp:99
std::string _userGroupName
Definition: NdmcClient.h:87
boost::mutex _mutex
Definition: NdmcClient.h:91
bool NdmcClient::setPartition ( int32_t  partition)

Set partition

Definition at line 60 of file NdmcClient.cpp.

References _mutex, _partition, _updateGroupName(), and parsePQSLOutput::partition.

Referenced by _updateGroupName(), getSendTimeInterval(), NdmcClientTest::testSetGroupName(), and NdmcClientTest::testSetPartition().

60  {
61 
62  boost::mutex::scoped_lock lock(_mutex);
63 
66  return true;
67 
68 }
void _updateGroupName()
Definition: NdmcClient.cpp:99
boost::mutex _mutex
Definition: NdmcClient.h:91
int32_t _partition
Definition: NdmcClient.h:84
void NdmcClient::setSendTimeInterval ( uint32_t  sendTimeInterval)

Set metric send time interval.

Definition at line 155 of file NdmcClient.cpp.

References _mutex, and _sendTimeInterval.

Referenced by getSendTimeInterval(), and NdmcClientTest::testSetSendTimeInterval().

155  {
156 
157  boost::mutex::scoped_lock lock(_mutex);
158  _sendTimeInterval = sendTimeInterval;
159 
160 }
uint32_t _sendTimeInterval
Definition: NdmcClient.h:88
boost::mutex _mutex
Definition: NdmcClient.h:91
template<class T >
bool NdmcClient::setValue ( int32_t  metricID,
T  value,
double  weight = 1.,
int  npar = 0,
double *  par = 0 
)

Set metric value by metricID

Parameters
metricID- ID number of this metric
value- value to set of type T
weight- optional value (def = 1) only used with metrics of type AVERAGE
Returns
true if successful, else false. Will fail if metric of ID of type T has not been created.

Definition at line 164 of file NdmcClient.h.

References _getMetric(), _mutex, allTimeWatchdog::endl, LogWarning, productionTest::metric, and T.

Referenced by getSendTimeInterval(), and setValue().

164  {
165 
166  boost::mutex::scoped_lock lock(_mutex);
167 
168  NdmcMetric<T>* metric = dynamic_cast<NdmcMetric<T>*>(_getMetric(metricID));
169  if ( !metric ) {
170  ::mf::LogWarning("NdmcClient") << "NdmcClient::setValue - failed. No metric of id "
171  << metricID << " of type " << typeid(T).name() << "."
172  << std::endl;
173  return false;
174  }
175 
176  metric -> setValue(value, weight);
177 
178  return true;
179 
180 }
NdmcMetricABC * _getMetric(int32_t metricId) const
Definition: NdmcClient.cpp:232
const XML_Char * name
Definition: expat.h:151
const Var weight
bool setValue(int32_t metricId, T value, double weight=1., int npar=0, double *par=0)
Definition: NdmcClient.h:164
const XML_Char int const XML_Char * value
Definition: expat.h:331
boost::mutex _mutex
Definition: NdmcClient.h:91
double T
Definition: Xdiff_gwt.C:5
template<class T >
bool NdmcClient::setValue ( NdmcMetric< T > *  metric,
T  value,
double  weight = 1.,
int  npar = 0,
double *  par = 0 
)

Set metric value by metric ptr. Recommend the user use setValue by metric id unless performance is an issue.

Parameters
metric- ptr of type NdmcMetric<T>* previously created by NdmcClient::createMetric
value- value to set of type T
weight- optional value (def = 1) only used with metrics of type AVERAGE
Returns
true if successful, else false.

Definition at line 192 of file NdmcClient.h.

References _mutex, allTimeWatchdog::endl, LogWarning, and setValue().

192  {
193 
194  boost::mutex::scoped_lock lock(_mutex);
195 
196  if ( !metric) {
197  ::mf::LogWarning("NdmcClient") << "NdmcClient::setValue - failed. Passed NULL metric ptr."
198  << std::endl;
199  return false;
200  }
201 
202  return metric -> setValue(value, weight, npar, par);
203 
204 }
const Var weight
Int_t par
Definition: SimpleIterate.C:24
bool setValue(int32_t metricId, T value, double weight=1., int npar=0, double *par=0)
Definition: NdmcClient.h:164
static const unsigned int npar
const XML_Char int const XML_Char * value
Definition: expat.h:331
boost::mutex _mutex
Definition: NdmcClient.h:91
virtual void novadaq::Runnable::stop ( )
inlinevirtualinherited

Stops the execution of the Runnable object.

Reimplemented in gov::fnal::cd::rms::ClientListenerLoop, and novadaq::BackgroundProcess.

Definition at line 61 of file Runnable.h.

References novadaq::Runnable::_hasCompleted, and novadaq::Runnable::_stopRequested.

Referenced by ~NdmcClient().

61  {
62  if (_hasCompleted) {return;}
63  _stopRequested = true;
64  }
virtual void novadaq::Runnable::watchfulSleep ( int  microseconds,
int  numberOfIntervals = 10 
)
inlinevirtualinherited

Sleeps for the specified amount of time, but periodically checks if a stop has been requested, and returns if so.

Definition at line 88 of file Runnable.h.

References novadaq::Runnable::_stopRequested, and compare_h5_caf::idx.

89  {
90  if (numberOfIntervals < 1) {numberOfIntervals = 1;}
91  int intervalTime = microseconds / numberOfIntervals;
92  if (intervalTime < 1) {intervalTime = 1;}
93  for (int idx = 0; idx < numberOfIntervals; ++idx) {
94  if (_stopRequested) {break;}
95  usleep(intervalTime);
96  }
97  }

Friends And Related Function Documentation

friend class ::NdmcClientTest
friend

Definition at line 35 of file NdmcClient.h.

Member Data Documentation

std::string NdmcClient::_applicationName
private

application name, e.g. dcmapp

Definition at line 85 of file NdmcClient.h.

Referenced by getApplicationName(), and setApplicationName().

boost::thread* NdmcClient::_clientThread
private

thread for this client

Definition at line 92 of file NdmcClient.h.

Referenced by NdmcClient(), and ~NdmcClient().

std::string NdmcClient::_groupName
private

group name, defaults to "appName + Ppartition"

Definition at line 86 of file NdmcClient.h.

Referenced by _updateGroupName(), and getGroupName().

bool novadaq::Runnable::_hasCompleted
protectedinherited
clock_t NdmcClient::_lastSendTime
private

last send time

Definition at line 90 of file NdmcClient.h.

Referenced by _timeToSend().

std::map<int32_t, NdmcMetricABC*> NdmcClient::_metricMap
private

map by ID/Metric

Definition at line 89 of file NdmcClient.h.

Referenced by _adoptMetric(), _getMetric(), _updateGroupName(), destroyMetric(), destroyMetrics(), getNumMetric(), send(), and ~NdmcClient().

boost::mutex NdmcClient::_mutex
private
int32_t NdmcClient::_partition
private

partition number (0,1,2, or 3)

Definition at line 84 of file NdmcClient.h.

Referenced by getPartition(), and setPartition().

bool novadaq::Runnable::_running
protectedinherited

Tracks whether the Runnable object is running or not (this can be before it has started or after it has finished)

Definition at line 105 of file Runnable.h.

Referenced by novadaq::Runnable::isRunning(), novadaq::BackgroundProcess::run(), gov::fnal::cd::rms::ClientListenerLoop::run(), run(), novadaq::Runnable::Runnable(), and gov::fnal::cd::rms::ClientListenerLoop::~ClientListenerLoop().

uint32_t NdmcClient::_sendTimeInterval
private

time interval at which to send custom metrics

Definition at line 88 of file NdmcClient.h.

Referenced by _timeToSend(), createMetric(), getSendTimeInterval(), and setSendTimeInterval().

bool novadaq::Runnable::_stopRequested
protectedinherited
std::string NdmcClient::_userGroupName
private

user-specified group name

Definition at line 87 of file NdmcClient.h.

Referenced by _updateGroupName(), and setGroupName().


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