Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Public Attributes | Static Public Attributes | Static Protected Member Functions | Protected Attributes | List of all members
KM3NETDAQ::JDAQDriver Class Reference

Simple driver for run control clients. More...

#include <JDAQDriver.hh>

Inheritance diagram for KM3NETDAQ::JDAQDriver:
KM3NETDAQ::JDAQClient

Public Member Functions

 JDAQDriver (const std::string &name, const std::string &server, JLogger *logger, const int level, const int timeout_s)
 Constructor. More...
 
virtual bool enter ()
 Enter the state machine. More...
 
void actionExit ()
 Exit the state machine. More...
 
void enterState (const CHSM::state &state, const CHSM::event &event)
 Action when entering state. More...
 
bool update (const bool no_wait)
 Update client list with incoming ControlHost message. More...
 
virtual void actionStart (int, const char *)
 
virtual void actionStop (int, const char *)
 
void run ()
 Run driver with user input. More...
 
void run (std::istream &in)
 Run driver. More...
 
void update ()
 Update client list with incoming ControlHost messages until the client list is synchronised with the current state or until the timeout. More...
 
void synchronise ()
 Synchronise clients. More...
 
void filter (const std::string &target="")
 Filter client list by putting failing clients to sleep. More...
 
virtual bool enter (const JArgs &args)
 Enter the state machine. More...
 
virtual bool exit ()
 Exit the state machine. More...
 
const std::string & getFullName () const
 Get full name of this run control client. More...
 
const JNET::JTaggetUniqueTag () const
 Get unique tag of this run control client. More...
 
int getEventNumber () const
 Get last event number. More...
 
bool isRunning () const
 Check if this client is in runnig state. More...
 
void replaceEvent (const JNET::JTag &oldTag, const JNET::JTag &newTag, JDAQEvent_t &event)
 Replace tag of given event in event table. More...
 
JDAQEvent_tfindEvent (const JNET::JTag &tag, const std::string &event_name)
 Find event in event table. More...
 
template<class T >
void addParameter (const char option, T &parameter)
 Add parameter to parser used in method enter(). More...
 
template<class T >
void addParameter (const char option, T &parameter, const T &value)
 Add parameter to parser used in method enter(). More...
 
long long int getClockDelay () const
 Get total delay time. More...
 
const std::string & getHostname () const
 Get hostname. More...
 
long long int getClockInterval () const
 Get interval time. More...
 
void setClockInterval (const long long int interval_us)
 Set interval time. More...
 
void resetClock ()
 Reset clock. More...
 
void setSelect ()
 Set the file descriptor mask for the select call. More...
 
virtual void setSelect (JFileDescriptorMask &mask) const
 Set the file descriptor mask for the select call. More...
 
virtual void actionSelect (const JFileDescriptorMask &mask)
 Action method following last select call. More...
 
virtual void actionRunning ()
 This method is repeatedly called when this client machine is in state Running and the clock interval time is non-zero. More...
 
virtual void actionInput (int length, const char *buffer)
 This method is called at ev_input. More...
 
virtual bool filter (const std::string &tag, int length, const char *buffer)
 Filter message. More...
 
void run (const int port)
 Run for ever. More...
 

Public Attributes

int timeout_s
 timeout of state transitions [s] More...
 

Static Public Attributes

static const int TIMEOUT_S = 1
 time out of update [s] More...
 

Static Protected Member Functions

static void copy (std::istream &in, std::ostream &out, const char eol= '\n')
 Copy data from input to output stream. More...
 

Protected Attributes

JClientList clientList
 
bool is_alive
 
std::string rc_log
 
JSharedPointer< JControlHostserver
 message server More...
 
JMessageLogger logger
 message logger More...
 

Detailed Description

Simple driver for run control clients.

This class can be used to start a set of run control clients, trigger events and eventually stop the clients.

Definition at line 35 of file JDAQDriver.hh.

Constructor & Destructor Documentation

KM3NETDAQ::JDAQDriver::JDAQDriver ( const std::string &  name,
const std::string &  server,
JLogger logger,
const int  level,
const int  timeout_s 
)
inline

Constructor.

Parameters
namename of driver
servername of command message server
loggerlogger
leveldebug level
timeout_stimeout_s [s]

Definition at line 48 of file JDAQDriver.hh.

52  :
53  JDAQClient(name, server, logger, level),
55  is_alive (false)
56  {}
int timeout_s
timeout of state transitions [s]
Definition: JDAQDriver.hh:614
JDAQClient(const std::string &name)
Constructor.
Definition: JDAQClient.hh:97
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636

Member Function Documentation

virtual bool KM3NETDAQ::JDAQDriver::enter ( )
inlinevirtual

Enter the state machine.

The driver will subscribe to the ControlHost tags corresponding to born, died and reply messages of the clients instead of the standard tags for run control commands. The clients are started after the driver is ready to receive ControlHost messages. In case of an error, a message is printed on the terminal and the state machine is not entered.

Reimplemented from KM3NETDAQ::JDAQClient.

Definition at line 67 of file JDAQDriver.hh.

68  {
69  using namespace std;
70  using namespace JLANG;
71  using namespace JNET;
72 
73  if (server.is_valid() && logger.is_valid()) {
74 
75  try {
76 
77  server->Subscribe(JSubscriptionAll(RC_REPLY) +
81  server->SendMeAlways();
82  server->MyId(getFullName());
83 
84  // check alive of this driver
85 
86  for (int i = 0; i != timeout_s && !is_alive; ) {
87  if (!update(true)) {
88  sleep(1);
89  ++i;
90  }
91  }
92 
93  if (is_alive) {
94 
95  {
96  // redirect standard output to message logger
97 
98  //JDebugStream out(logger);
99  //JRedirectStream redirect(cout, out);
100 
101  clientList.start();
102 
103  for (int i = 0; i != timeout_s; ++i) {
104 
105  while (update(true)) {}
106 
107  if (clientList.count() >= clientList.count(JClient::ACTIVE))
108  break;
109  else
110  sleep(1);
111  }
112  }
113 
114  if (clientList.count() != clientList.count(JClient::ACTIVE)) {
115  for (JClientList::const_iterator i = clientList.begin(); i != clientList.end(); ++i) {
116  if (i->isActive() && i->getBorn() <= i->getDied()) {
117  JWarningStream(logger) << "client " << i->getFullName() << " did not start.";
118  }
119  }
120  }
121 
122  return CHSM::machine::enter();
123 
124  } else {
125  cerr << "Timeout at subscription." << endl;
126  }
127  }
128  catch(const JControlHostException& error) {
129  cerr << error << endl;
130  }
131 
132  } else {
133  cerr << "Message server or logger not properly initialised." << endl;
134  }
135 
136  return false;
137  }
int timeout_s
timeout of state transitions [s]
Definition: JDAQDriver.hh:614
static const JTag DISPTAG_Died("Died")
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
static const JNET::JTag RC_LOG
Definition: JDAQTags.hh:49
static const JNET::JTag RC_REPLY
Definition: JDAQTags.hh:45
Exception for ControlHost.
Definition: JException.hh:432
Auxiliary class for all subscription.
Definition: JControlHost.hh:95
JClientList clientList
Definition: JDAQDriver.hh:618
static const JTag DISPTAG_Born("Born")
bool is_valid() const
Check validity of logger object.
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
const std::string & getFullName() const
Get full name of this run control client.
Definition: JDAQClient.hh:248
void update()
Update client list with incoming ControlHost messages until the client list is synchronised with the ...
Definition: JDAQDriver.hh:500
void KM3NETDAQ::JDAQDriver::actionExit ( )
inline

Exit the state machine.

This method waits for the clients to terminate using the died message generated by ControlHost. In case of a timeout, the process is terminated by calling the method stop() of the corresponding client.

Definition at line 146 of file JDAQDriver.hh.

147  {
148  using namespace std;
149  using namespace JLANG;
150 
151  for (int i = 0; i != timeout_s; ++i) {
152 
153  while (update(true)) {}
154 
155  if (clientList.count() == 0)
156  break;
157  else
158  sleep(1);
159  }
160 
161  if (clientList.count() != 0) {
162  JWarningStream(logger) << "Timeout at transition " << "exit(); forced stop.";
163  }
164 
165  // redirect standard output to message logger
166 
167  //JDebugStream out(logger);
168  //JRedirectStream redirect(cout, out);
169 
170  clientList.stop();
171  }
int timeout_s
timeout of state transitions [s]
Definition: JDAQDriver.hh:614
JClientList clientList
Definition: JDAQDriver.hh:618
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
void update()
Update client list with incoming ControlHost messages until the client list is synchronised with the ...
Definition: JDAQDriver.hh:500
void KM3NETDAQ::JDAQDriver::enterState ( const CHSM::state &  state,
const CHSM::event &  event 
)
inline

Action when entering state.

This method waits for all clients to produce the enter state message. In case of a timeout, no specific action is taken but an error message is logged.

Parameters
stateentered state
eventevent that triggered transition

Definition at line 182 of file JDAQDriver.hh.

183  {
184  for (int i = 0; i != timeout_s && clientList.count(state) < clientList.count(JClient::ACTIVE); ) {
185  if (!update(true)) {
186  sleep(1);
187  ++i;
188  }
189  }
190 
191  if (clientList.count(state) < clientList.count(JClient::ACTIVE)) {
192  JWarningStream(logger) << "Timeout at transition " << event.name() << " to state " << state.name();
193  }
194  }
int timeout_s
timeout of state transitions [s]
Definition: JDAQDriver.hh:614
JClientList clientList
Definition: JDAQDriver.hh:618
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
void update()
Update client list with incoming ControlHost messages until the client list is synchronised with the ...
Definition: JDAQDriver.hh:500
bool KM3NETDAQ::JDAQDriver::update ( const bool  no_wait)
inline

Update client list with incoming ControlHost message.

This method receives and processes a message. The client list is updated accordingly. If the no-wait option is set to true, it returns in the absence of a pending message immediately. The return value is then false. If the no-wait option is set to false, it waits until the next message is received.

Parameters
no_waitwait option
Returns
true if message received; else false

Definition at line 208 of file JDAQDriver.hh.

209  {
210  using namespace std;
211  using namespace JNET;
213 
214  try {
215 
216  string tag;
217  int length = 0;
218 
219  if ( no_wait && server->CheckHead(tag, length) <= 0) { return false; }
220  if (!no_wait && server->WaitHead (tag, length) < 0) { return false; }
221 
222  char* data= new char[length];
223 
224  server->GetFullData(data, length);
225 
226  const string buffer(data, length);
227 
228  delete [] data;
229 
230  JDebugStream(logger) << "Got message " << tag << ' ' << buffer;
231 
232  if (tag == RC_LOG) {
233 
234  rc_log = buffer;
235 
236  } else if (buffer.find(getFullName()) != string::npos) {
237 
238  if (tag == DISPTAG_Born)
239  is_alive = true;
240  else if (tag == DISPTAG_Died)
241  is_alive = false;
242 
243  } else {
244 
245  JClientList::iterator i = clientList.find(buffer);
246 
247  if (i != clientList.end()) {
248 
249  i->update(tag, buffer);
250 
251  } else {
252 
253  JErrorStream(logger) << "Message fom illegal client " << buffer;
254 
255  try {
256 
257  if (tag == DISPTAG_Born ||
258  tag == DISPTAG_Died ||
259  tag == RC_REPLY) {
260 
261  string key, hostname, name;
262 
263  istringstream is(buffer);
264 
265  const locale loc(is.getloc(), new JWhiteSpacesFacet(is.getloc(), TOKEN_DELIMETER));
266 
267  is.imbue(loc);
268 
269  if (is >> key >> hostname >> name && key == RUN_CONTROL_CLIENT) {
270 
271  JClient client(name, hostname);
272 
273  client.update(tag, buffer);
274  client.setMode(JClient::ILLEGAL);
275 
276  clientList.insert(client);
277 
278  JWarningStream(logger) << "Added illegal client " << client.getFullName();
279 
280  } else {
281  throw JIOException("JClient: Error reading " + buffer);
282  }
283  }
284  }
285  catch(const JException& error) {
286  JErrorStream(logger) << error;
287  }
288  }
289  }
290 
291  return true;
292  }
293  catch(const JControlHostException& error) {
294  JErrorStream(logger) << error;
295  }
296 
297  return false;
298  }
General exception.
Definition: JException.hh:40
static const JTag DISPTAG_Died("Died")
ControlHost client manager.
Definition: JLigier.cc:241
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
static const std::string TOKEN_DELIMETER
Definition: JDAQTags.hh:36
static const std::string RUN_CONTROL_CLIENT
Definition: JDAQTags.hh:22
static const JNET::JTag RC_LOG
Definition: JDAQTags.hh:49
static const JNET::JTag RC_REPLY
Definition: JDAQTags.hh:45
Exception for ControlHost.
Definition: JException.hh:432
JClientList clientList
Definition: JDAQDriver.hh:618
static const JTag DISPTAG_Born("Born")
Auxiliary class to specify white space character(s) in currect locale.
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
const std::string & getFullName() const
Get full name of this run control client.
Definition: JDAQClient.hh:248
std::string hostname
Definition: JDAQClient.hh:829
Exception for I/O.
Definition: JException.hh:306
virtual void KM3NETDAQ::JDAQDriver::actionStart ( int  ,
const char *   
)
inlinevirtual

Definition at line 300 of file JDAQDriver.hh.

301  {
302  rc_log = "";
303  }
virtual void KM3NETDAQ::JDAQDriver::actionStop ( int  ,
const char *   
)
inlinevirtual

Definition at line 305 of file JDAQDriver.hh.

306  {
307  if (rc_log != "")
308  JNoticeStream(logger) << rc_log;
309  else
310  JErrorStream (logger) << "Missing message from JDataWriter with tag " << RC_LOG;
311  }
static const JNET::JTag RC_LOG
Definition: JDAQTags.hh:49
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
void KM3NETDAQ::JDAQDriver::run ( )
inline

Run driver with user input.

Definition at line 316 of file JDAQDriver.hh.

317  {
318  run(std::cin);
319  }
void run()
Run driver with user input.
Definition: JDAQDriver.hh:316
void KM3NETDAQ::JDAQDriver::run ( std::istream &  in)
inline

Run driver.

Example input format:

# comment line.
process <process name> <host name> [<start command>];
# The following tokens in <start command> will be substituted: 
#   $HOST$    by  <host name>;
#   $NAME$    by  <process name>;
#   $SERVER$  by  JClient::SERVER;
#   $LOGGER$  by  JClient::LOGGER;
#   $ARGS$    by  part following '/' in <process name>;
# enter state machine.
enter
# trigger event
# data can be provided online and mixed with data from a separate file (optional).
# multiple tags should be separated by a new line.
event <event name> {
  [<tag 1> [data]]
  [<tag 2> [data][%<file name>%][data]]
}
# optionally quit before end of input
[quit]
# optionally kill processes that did not properly terminate.
[exit]
Parameters
ininput stream

Definition at line 360 of file JDAQDriver.hh.

361  {
362  using namespace std;
363 
364  for (string key; in >> key; ) {
365 
366  if (key[0] == '#') {
367 
368  in.ignore(numeric_limits<streamsize>::max(), '\n');
369 
370  } else if (key == "enter") {
371 
372  enter();
373 
374  if (!active()) {
375  cerr << "State machine not entered; abort." << endl;
376  return;
377  }
378 
379  } else if (key == "exit") {
380 
381  timeout_s = 0;
382  exit();
383 
384  } else if (key == "quit") {
385 
386  break;
387 
388  } else if (key == "sleep") {
389 
390  int sec;
391 
392  if (in >> sec) {
393  sleep(sec);
394  }
395 
396  } else if (key == "process") {
397 
398  string buffer;
399 
400  getline(in, buffer, ';');
401 
402  istringstream is(buffer);
403 
404  JClient client;
405 
406  if (is >> client) {
407 
408  client.setMode(JClient::ACTIVE);
409 
410  if (!clientList.insert(client).second) {
411  JWarningStream(logger) << "Process already exists " << client;
412  }
413 
414  } else {
415  JErrorStream(logger) << "Error reading key word process.";
416  }
417 
418  } else if (key == "event" || key == "event*") {
419 
420  JEvent_t event;
421  char c;
422  string buffer;
423  const char eol = '\n';
424 
425  if (in >> event >> c && c == '{' && getline(in, buffer, '}')) {
426 
427  JDAQEvent_t* pev = findEvent(RC_CMD, event.getName());
428 
429  if (pev != NULL) {
430 
431  if (pev->active() || key == "event*") {
432 
433  istringstream is(buffer);
434 
435  for (string tag; is >> tag; ) {
436 
437  ostringstream os;
438 
439  os << event << getTokenDelimeter();
440 
441  copy(is, os, eol);
442 
443  server->PutFullString(tag, os.str());
444  }
445 
446  if (key != "event*") {
447  (*pev)(0, NULL); // trigger driver
448  }
449 
450  } else {
451  JErrorStream(logger) << "Inactive event " << event;
452  }
453 
454  } else {
455  JErrorStream(logger) << "Unknown event " << event;
456  }
457 
458  } else {
459  JErrorStream(logger) << "Error reading key word event.";
460  }
461 
462  } else if (key == "print") {
463 
464  for (JClientList::const_iterator i = clientList.begin(); i != clientList.end(); ++i) {
465  JNoticeStream(logger) << i->getFullName() << ' '
466  << i->getStartCommand() << ' '
467  << i->getAlive() << ' '
468  << i->getStatename();
469  }
470 
471  } else if (key == "filter") {
472 
473  string client;
474  string buffer;
475 
476  getline(in, buffer, ';');
477 
478  for (istringstream is(buffer); is >> client; ) {
479  filter(client);
480  }
481 
482  } else if (key == "sync") {
483 
484  synchronise();
485 
486  } else {
487 
488  JErrorStream(logger) << "Unknown key: " << key;
489 
490  in.ignore(numeric_limits<streamsize>::max(), '\n');
491  }
492  }
493  }
int timeout_s
timeout of state transitions [s]
Definition: JDAQDriver.hh:614
ControlHost client manager.
Definition: JLigier.cc:241
virtual bool enter()
Enter the state machine.
Definition: JDAQDriver.hh:67
static void copy(std::istream &in, std::ostream &out, const char eol= '\n')
Copy data from input to output stream.
Definition: JDAQDriver.hh:630
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
void synchronise()
Synchronise clients.
Definition: JDAQDriver.hh:523
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468
virtual bool exit()
Exit the state machine.
Definition: JDAQClient.hh:225
char getTokenDelimeter()
Get the token delimeter for command messages.
JClientList clientList
Definition: JDAQDriver.hh:618
void filter(const std::string &target="")
Filter client list by putting failing clients to sleep.
Definition: JDAQDriver.hh:590
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
static const JNET::JTag RC_CMD
Definition: JDAQTags.hh:44
JDAQStateMachine::ev_daq_event JDAQEvent_t
Type definition of a DAQ event.
Definition: JEventTable.hh:22
JDAQEvent_t * findEvent(const JNET::JTag &tag, const std::string &event_name)
Find event in event table.
Definition: JDAQClient.hh:309
void KM3NETDAQ::JDAQDriver::update ( )
inline

Update client list with incoming ControlHost messages until the client list is synchronised with the current state or until the timeout.

Definition at line 500 of file JDAQDriver.hh.

501  {
502  using namespace std;
503 
504  const CHSM::parent& parent = static_cast<const CHSM::parent&>(Main.RunControl);
505 
506  for (CHSM::parent::const_iterator state = parent.begin(); state != parent.end(); ++state) {
507 
508  if (state->active()) {
509  for (int i = 0; i != timeout_s && clientList.count(*state) < clientList.count(JClient::ACTIVE); ) {
510  if (!update(true)) {
511  sleep(1);
512  ++i;
513  }
514  }
515  }
516  }
517  }
int timeout_s
timeout of state transitions [s]
Definition: JDAQDriver.hh:614
JClientList clientList
Definition: JDAQDriver.hh:618
void update()
Update client list with incoming ControlHost messages until the client list is synchronised with the ...
Definition: JDAQDriver.hh:500
void KM3NETDAQ::JDAQDriver::synchronise ( )
inline

Synchronise clients.

Definition at line 523 of file JDAQDriver.hh.

524  {
525  using namespace std;
526 
527  const CHSM::parent& parent = static_cast<const CHSM::parent&>(Main.RunControl);
528 
529  for (CHSM::parent::const_iterator state = parent.begin(); state != parent.end(); ++state) {
530 
531  if (state->active()) {
532 
533  if (clientList.count(*state) < clientList.count(JClient::ACTIVE)) {
534 
535  JDebugStream(logger) << "Synchronising " << state->name();
536 
537  for (JClientList::iterator i = clientList.begin(); i != clientList.end(); ++i) {
538 
539  if (i->getMode() == JClient::ACTIVE) {
540 
541  if (!i->getAlive()) {
542 
543  try {
544 
545  string buffer;
546 
547  if (JControlHost::WhereIs(JClient::SERVER, i->getFullName(), buffer) > 0) {
548 
549  i->setAlive(true);
550 
551  if (buffer.find(i->getHostname()) == string::npos) {
552  JErrorStream(logger) << i->getFullName() << " running on " << buffer << " but not alive.";
553  }
554  }
555  }
556  catch(const JControlHostException& error) {
557  JErrorStream(logger) << error;
558  }
559  }
560 
561  if (i->getAlive() && i->getStatename() != state->name()) {
562  server->PutFullString(KM3NETDAQ::getUniqueTag(i->getHostname(), i->getName()), ev_check.name());
563  }
564  }
565  }
566 
567 
568  for (int i = 0; i != timeout_s && clientList.count(*state) < clientList.count(JClient::ACTIVE); ) {
569  if (!update(true)) {
570  sleep(1);
571  ++i;
572  }
573  }
574 
575  if (clientList.count(*state) < clientList.count(JClient::ACTIVE)) {
576  JWarningStream(logger) << "Timeout at synchronisation.";
577  }
578  }
579  }
580  }
581  }
int timeout_s
timeout of state transitions [s]
Definition: JDAQDriver.hh:614
JTag getUniqueTag(const std::string &hostname, const std::string &name)
Get unique tag of run control client.
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
Exception for ControlHost.
Definition: JException.hh:432
JClientList clientList
Definition: JDAQDriver.hh:618
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
static int WhereIs(const std::string &host_name, const std::string &nick_name, std::string &answer)
Locate ControlHost client(s).
void update()
Update client list with incoming ControlHost messages until the client list is synchronised with the ...
Definition: JDAQDriver.hh:500
void KM3NETDAQ::JDAQDriver::filter ( const std::string &  target = "")
inline

Filter client list by putting failing clients to sleep.

In this, only clients with names that contain the given character sequence are considered.

Parameters
targettarget name of client(s)

Definition at line 590 of file JDAQDriver.hh.

591  {
592  const CHSM::parent& parent = static_cast<const CHSM::parent&>(Main.RunControl);
593 
594  for (CHSM::parent::const_iterator state = parent.begin(); state != parent.end(); ++state) {
595 
596  if (state->active()) {
597 
598  for (JClientList::iterator i = clientList.begin(); i != clientList.end(); ++i) {
599 
600  if (target == "" || i->getName().find(target) != std::string::npos) {
601 
602  if (!i->getAlive() || i->getStatename() != state->name()) {
603 
604  JNoticeStream(logger) << "Put to sleep " << i->getFullName();
605 
606  i->setMode(JClient::SLEEP);
607  }
608  }
609  }
610  }
611  }
612  }
JClientList clientList
Definition: JDAQDriver.hh:618
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
static void KM3NETDAQ::JDAQDriver::copy ( std::istream &  in,
std::ostream &  out,
const char  eol = '\n' 
)
inlinestaticprotected

Copy data from input to output stream.

Tagged file names are recursively expanded.

Parameters
ininput stream
outoutput stream
eolend of line

Definition at line 630 of file JDAQDriver.hh.

631  {
632  using namespace std;
633 
634  string buffer;
635 
636  if (getline(in, buffer, eol)) {
637 
638  for (string::size_type pos = 0; pos < buffer.length(); ) {
639 
640  string::size_type lpos = buffer.substr(pos).find(FILENAME_PREFIX);
641  string::size_type rpos = buffer.substr(pos).find(FILENAME_POSTFIX);
642 
643  if (lpos != string::npos &&
644  rpos != string::npos) {
645 
646  out << buffer.substr(pos, lpos);
647 
648  lpos += FILENAME_PREFIX.length();
649  pos += lpos;
650 
651  ifstream file(buffer.substr(pos, rpos - lpos).c_str());
652 
653  copy(file, out, '\0');
654 
655  rpos += FILENAME_POSTFIX.length();
656  pos += rpos - lpos;
657 
658  } else {
659 
660  out << buffer.substr(pos);
661 
662  pos += buffer.substr(pos).length();
663  }
664  }
665  }
666  }
static const std::string FILENAME_PREFIX
Definition: JDAQTags.hh:38
static const std::string FILENAME_POSTFIX
Definition: JDAQTags.hh:39
static void copy(std::istream &in, std::ostream &out, const char eol= '\n')
Copy data from input to output stream.
Definition: JDAQDriver.hh:630
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468
virtual bool KM3NETDAQ::JDAQClient::enter ( const JArgs args)
inlinevirtualinherited

Enter the state machine.

This overloaded method enter reproduces the constructor. All necessary input is parsed from the list of arguments. In case of an error, the state machine is not entered.

Parameters
argsarray of command line arguments

Definition at line 143 of file JDAQClient.hh.

144  {
145  using namespace std;
146 
147  string server;
148  string logger;
149  int level;
150  bool use_cout;
151 
152  try {
153 
154  parser['H'] = make_field(server) = "localhost";
155  parser['M'] = make_field(logger) = "localhost";
156  parser['d'] = make_field(level) = 0;
157  parser['c'] = make_field(use_cout);
158 
159  if (parser.read(args) != 0) {
160  return false;
161  }
162  }
163  catch(const exception &error) {
164  cerr << error.what() << endl;
165  return false;
166  }
167 
168  try {
169 
170  JLogger* out = NULL;
171 
172  if (use_cout)
173  out = new JStreamLogger(cout);
174  else
175  out = new JControlHostLogger(logger);
176 
177  this->logger = JMessageLogger(out, getName(), level);
178 
179  this->server.reset(new JControlHost(server));
180 
181  return enter();
182  }
183  catch(const JControlHostException& error) {
184  cerr << error << endl;
185  return false;
186  }
187  }
JParser parser
parser method enter()
Definition: JDAQClient.hh:834
ControlHost class.
Message logging based on std::ostream.
Interface for logging messages.
Definition: JLogger.hh:22
Message logging based on ControlHost.
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
virtual bool enter()
Enter the state machine.
Definition: JDAQClient.hh:195
Exception for ControlHost.
Definition: JException.hh:432
int read(const int argc, const char *const argv[])
Parse the program&#39;s command line options.
Definition: JParser.hh:1673
const char * getName()
Get ROOT name of given data type.
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
virtual bool KM3NETDAQ::JDAQClient::exit ( )
inlinevirtualinherited

Exit the state machine.

This method releases the various resources.

Definition at line 225 of file JDAQClient.hh.

226  {
227  try {
228  if (server.is_valid()) server.reset(NULL);
229  }
230  catch(const JControlHostException& error) {
231  }
232 
233  try {
234  if (logger.is_valid()) logger.reset(NULL);
235  }
236  catch(const JControlHostException& error) {
237  }
238 
239  return CHSM::machine::exit();
240  }
void reset(JLogger *__logger=NULL)
Reset logger.
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
Exception for ControlHost.
Definition: JException.hh:432
bool is_valid() const
Check validity of logger object.
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
const std::string& KM3NETDAQ::JDAQClient::getFullName ( ) const
inlineinherited

Get full name of this run control client.

Returns
full name

Definition at line 248 of file JDAQClient.hh.

249  {
250  return full_name;
251  }
std::string full_name
Definition: JDAQClient.hh:830
const JNET::JTag& KM3NETDAQ::JDAQClient::getUniqueTag ( ) const
inlineinherited

Get unique tag of this run control client.

Returns
unique tag

Definition at line 259 of file JDAQClient.hh.

260  {
261  return unique_tag;
262  }
int KM3NETDAQ::JDAQClient::getEventNumber ( ) const
inlineinherited

Get last event number.

Returns
event number

Definition at line 270 of file JDAQClient.hh.

271  {
272  return event_number;
273  }
int event_number
number of last event
Definition: JDAQClient.hh:835
bool KM3NETDAQ::JDAQClient::isRunning ( ) const
inlineinherited

Check if this client is in runnig state.

Returns
true if running; else false

Definition at line 281 of file JDAQClient.hh.

282  {
283  return Main.RunControl.Operational.Running.active();
284  }
void KM3NETDAQ::JDAQClient::replaceEvent ( const JNET::JTag oldTag,
const JNET::JTag newTag,
JDAQEvent_t event 
)
inlineinherited

Replace tag of given event in event table.

Parameters
oldTagold tag
newTagnew tag
eventevent

Definition at line 294 of file JDAQClient.hh.

297  {
298  eventTable.replace(oldTag, newTag, event);
299  }
Structure to store the ToT mean and standard deviation of the hits produced by a nanobeacon in a sour...
JEventTable eventTable
event table
Definition: JDAQClient.hh:828
void replace(const JNET::JTag &oldTag, const JNET::JTag &newTag, JDAQEvent_t &event)
Replace entry in table.
Definition: JEventTable.hh:93
JDAQEvent_t* KM3NETDAQ::JDAQClient::findEvent ( const JNET::JTag tag,
const std::string &  event_name 
)
inlineinherited

Find event in event table.

Parameters
tagtag
event_nameevent name
Returns
pointer to event or NULL

Definition at line 309 of file JDAQClient.hh.

310  {
311  JEventTable::const_iterator i = eventTable.find(tag, event_name);
312 
313  if (i != eventTable.end())
314  return i->second;
315  else
316  return NULL;
317  }
const_iterator find(const JNET::JTag &tag, const std::string &event_name) const
Find entry.
Definition: JEventTable.hh:112
JEventTable eventTable
event table
Definition: JDAQClient.hh:828
template<class T >
void KM3NETDAQ::JDAQClient::addParameter ( const char  option,
T &  parameter 
)
inlineinherited

Add parameter to parser used in method enter().

Parameters
optionoption
parameterparameter

Definition at line 327 of file JDAQClient.hh.

328  {
329  parser[option] = make_field(parameter);
330  }
JParser parser
parser method enter()
Definition: JDAQClient.hh:834
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
template<class T >
void KM3NETDAQ::JDAQClient::addParameter ( const char  option,
T &  parameter,
const T &  value 
)
inlineinherited

Add parameter to parser used in method enter().

Parameters
optionoption
parameterparameter
valuedefault value

Definition at line 341 of file JDAQClient.hh.

342  {
343  parser[option] = make_field(parameter) = value;
344  }
JParser parser
parser method enter()
Definition: JDAQClient.hh:834
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
long long int KM3NETDAQ::JDAQClient::getClockDelay ( ) const
inlineinherited

Get total delay time.

Returns
delay time [us]

Definition at line 352 of file JDAQClient.hh.

353  {
354  return clock.getDelay();
355  }
long long int getDelay() const
Get total delay time.
Definition: JTimekeeper.hh:78
JTimekeeper clock
central clock
Definition: JDAQClient.hh:832
const std::string& KM3NETDAQ::JDAQClient::getHostname ( ) const
inlineinherited

Get hostname.

Returns
host name

Definition at line 363 of file JDAQClient.hh.

364  {
365  return hostname;
366  }
std::string hostname
Definition: JDAQClient.hh:829
long long int KM3NETDAQ::JDAQClient::getClockInterval ( ) const
inlineinherited

Get interval time.

Returns
interval time [us]

Definition at line 374 of file JDAQClient.hh.

375  {
376  return clock.getInterval();
377  }
JTimekeeper clock
central clock
Definition: JDAQClient.hh:832
long long int getInterval() const
Get interval time.
Definition: JTimekeeper.hh:67
void KM3NETDAQ::JDAQClient::setClockInterval ( const long long int  interval_us)
inlineinherited

Set interval time.

Parameters
interval_usinterval time [us]

Definition at line 385 of file JDAQClient.hh.

386  {
387  clock.setInterval(interval_us);
388  }
JTimekeeper clock
central clock
Definition: JDAQClient.hh:832
void setInterval(const long long int interval_us)
Set interval time.
Definition: JTimekeeper.hh:89
void KM3NETDAQ::JDAQClient::resetClock ( )
inlineinherited

Reset clock.

Definition at line 394 of file JDAQClient.hh.

395  {
396  clock.reset();
397  }
void reset(const long long int t0)
Reset time.
Definition: JTimekeeper.hh:100
JTimekeeper clock
central clock
Definition: JDAQClient.hh:832
void KM3NETDAQ::JDAQClient::setSelect ( )
inlineinherited

Set the file descriptor mask for the select call.

Definition at line 403 of file JDAQClient.hh.

404  {
405  select.reset();
406 
408 
410  }
JSelectReader select
select call
Definition: JDAQClient.hh:833
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
JFileDescriptorMask & getReaderMask()
Get reader mask.
void setReaderMask(const JAbstractFile &file)
Set reader mask.
void reset()
Reset.
void setSelect()
Set the file descriptor mask for the select call.
Definition: JDAQClient.hh:403
virtual void KM3NETDAQ::JDAQClient::setSelect ( JFileDescriptorMask mask) const
inlinevirtualinherited

Set the file descriptor mask for the select call.

This implementation does nothing but may be redefined by the derived class.

Parameters
maskfile descriptor mask

Reimplemented in KM3NETDAQ::JDataWriter, and KM3NETDAQ::MonitorRouter.

Definition at line 419 of file JDAQClient.hh.

420  {}
virtual void KM3NETDAQ::JDAQClient::actionSelect ( const JFileDescriptorMask mask)
inlinevirtualinherited

Action method following last select call.

This implementation does nothing but may be redefined by the derived class.

Parameters
maskfile descriptor mask

Reimplemented in KM3NETDAQ::DataQueue, KM3NETDAQ::JDataWriter, and KM3NETDAQ::MonitorRouter.

Definition at line 429 of file JDAQClient.hh.

430  {}
virtual void KM3NETDAQ::JDAQClient::actionRunning ( )
inlinevirtualinherited

This method is repeatedly called when this client machine is in state Running and the clock interval time is non-zero.

This implementation does nothing but may be redefined by the derived class. Care has to be taken so that the time needed to execute this method should be less than the specified clock interval time (see method setClockInterval()).

Reimplemented in JDataFilter, KM3NETDAQ::JDataWriter, KM3NETDAQ::JDOMSimulator, KM3NETDAQ::DataQueue, KM3NETDAQ::JEventGenerator, KM3NETDAQ::MonitorRouter, and AcousticDataFilter.

Definition at line 440 of file JDAQClient.hh.

441  {}
virtual void KM3NETDAQ::JDAQClient::actionInput ( int  length,
const char *  buffer 
)
inlinevirtualinherited

This method is called at ev_input.

Parameters
lengthlength of data
bufferpointer to data

Reimplemented in AcousticDataFilter.

Definition at line 450 of file JDAQClient.hh.

451  {
452  using namespace std;
453 
454  JProperties properties(JEquationParameters("=", ";", "", ""), 1);
455 
456  int level = this->logger.getLevel();
457 
458  properties["debug"] = level;
459 
460  properties.read(string(buffer, length));
461 
462  this->logger.setLevel(level);
463  }
Utility class to parse parameter values.
Definition: JProperties.hh:484
Simple data structure to support I/O of equations (see class JLANG::JEquation).
JMessageLogger logger
message logger
Definition: JDAQClient.hh:636
void setLevel(const int __level)
Set debug level.
JLevel_t getLevel()
Get debug level.
virtual bool KM3NETDAQ::JDAQClient::filter ( const std::string &  tag,
int  length,
const char *  buffer 
)
inlinevirtualinherited

Filter message.

The filter method can be overloaded so that a specific action is made before the corresponding message is processed by the state machine. The message is ignored if true is returned, else it is normally processed.

Parameters
tagtag
lengthnumber of characters
buffermessage
Returns
skip message or not

Definition at line 477 of file JDAQClient.hh.

478  {
479  return false;
480  }
void KM3NETDAQ::JDAQClient::run ( const int  port)
inlineinherited

Run for ever.

This method can be used when the run control client is started before the run control (e.g. at boot time of the host processor). This method should be called before the state machine is entered. It launches a server which accepts a JNET::JControlHost connection from a designated application e.g. the JDAQClientStarter.cc program. The state machine is entered using the available data in the JNET::JControlHost message. After the state machine is exited, it accepts a new a JNET::JControlHost connection.

Parameters
portport number

Definition at line 573 of file JDAQClient.hh.

574  {
576 
577  for ( ; ; ) {
578 
579  JControlHost* ps = server.AcceptClient();
580 
581  ps->Connected();
582 
583  JNET::JPrefix prefix;
584 
585  ps->WaitHead(prefix);
586 
587  const int length = prefix.getSize();
588 
589  char* buffer = new char[length];
590 
591  ps->GetFullData(buffer, length);
592  ps->PutFullData(prefix.toString(), buffer, length);
593 
594  delete ps;
595 
596  enter(JArgs(std::string(buffer, length)));
597 
598  delete [] buffer;
599 
600  run();
601 
602  exit();
603  }
604  }
ControlHost prefix.
Definition: JPrefix.hh:31
ControlHost class.
int Connected()
Send version.
JSharedPointer< JControlHost > server
message server
Definition: JDAQClient.hh:635
void run()
Run as run control client following command messages via JNET::JControlHost.
Definition: JDAQClient.hh:493
int getSize() const
Get size.
Definition: JPrefix.hh:63
virtual bool enter()
Enter the state machine.
Definition: JDAQClient.hh:195
virtual bool exit()
Exit the state machine.
Definition: JDAQClient.hh:225
int WaitHead(JPrefix &prefix)
Wait for header.
std::string toString() const
Convert tag to string.
Definition: JTag.hh:167
int GetFullData(void *buffer, int length)
Receive data.
Light-weight wrapper class around server socket.
int PutFullData(const JTag &tag, const void *buffer, const int length)
Send data.

Member Data Documentation

int KM3NETDAQ::JDAQDriver::timeout_s

timeout of state transitions [s]

Definition at line 614 of file JDAQDriver.hh.

JClientList KM3NETDAQ::JDAQDriver::clientList
protected

Definition at line 618 of file JDAQDriver.hh.

bool KM3NETDAQ::JDAQDriver::is_alive
protected

Definition at line 619 of file JDAQDriver.hh.

std::string KM3NETDAQ::JDAQDriver::rc_log
protected

Definition at line 620 of file JDAQDriver.hh.

const int KM3NETDAQ::JDAQClient::TIMEOUT_S = 1
staticinherited

time out of update [s]

Definition at line 631 of file JDAQClient.hh.

JSharedPointer<JControlHost> KM3NETDAQ::JDAQClient::server
protectedinherited

message server

Definition at line 635 of file JDAQClient.hh.

JMessageLogger KM3NETDAQ::JDAQClient::logger
protectedinherited

message logger

Definition at line 636 of file JDAQClient.hh.


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