1 #ifndef __JRUNCONTROL__JDAQDRIVER__
2 #define __JRUNCONTROL__JDAQDRIVER__
58 const int timeout_s) :
126 if (i->isActive() && i->getBorn() <= i->getDied()) {
132 return CHSM::machine::enter();
135 cerr <<
"Timeout at subscription." << endl;
139 cerr << error << endl;
143 cerr <<
"Message server or logger not properly initialised." << endl;
159 using namespace JLANG;
187 virtual void enterState(
const CHSM::state& state,
const CHSM::event& event)
override
197 JWarningStream(
logger) <<
"Timeout at transition " <<
event.name() <<
" to state " << state.name();
216 using namespace JNET;
222 long long int length = 0;
224 if ( no_wait &&
server->CheckHead(tag, length) <= 0) {
return false; }
225 if (!no_wait &&
server->WaitHead (tag, length) < 0) {
return false; }
227 char*
data=
new char[length];
231 const string buffer(
data, length);
241 }
else if (buffer.find(
getFullName()) != string::npos) {
250 JClientList::iterator i =
clientList.find(buffer);
254 i->update(tag, buffer);
268 istringstream is(buffer);
278 client.update(tag, buffer);
279 client.setMode(JClient::ILLEGAL);
365 void run(std::istream& in)
369 for (
string key; in >> key; ) {
373 in.ignore(numeric_limits<streamsize>::max(),
'\n');
375 }
else if (key ==
"enter") {
380 cerr <<
"State machine not entered; abort." << endl;
384 }
else if (key ==
"exit") {
389 }
else if (key ==
"quit") {
393 }
else if (key ==
"sleep") {
401 }
else if (key ==
"process") {
407 istringstream is(buffer);
413 client.setMode(JClient::ACTIVE);
423 }
else if (key ==
"event" || key ==
"event*") {
428 const char eol =
'\n';
430 if (in >> event >> c && c ==
'{' &&
getline(in, buffer,
'}')) {
438 if (pev->active() || key ==
"event*") {
440 istringstream is(buffer);
442 for (
string tag; is >> tag; ) {
452 server->PutFullString(tag, os.str());
455 if (key !=
"event*") {
475 }
else if (key ==
"message") {
480 if (in >> tag &&
getline(in, buffer,
';'))
481 server->PutFullString(tag, buffer);
485 }
else if (key ==
"print") {
489 << i->getStartCommand() <<
' '
490 << i->getAlive() <<
' '
491 << i->getStatename();
494 }
else if (key ==
"filter") {
501 for (istringstream is(buffer); is >> client; ) {
505 }
else if (key ==
"sync") {
513 in.ignore(numeric_limits<streamsize>::max(),
'\n');
527 const CHSM::parent& parent =
static_cast<const CHSM::parent&
>(
Main.
RunControl);
529 for (CHSM::parent::const_iterator state = parent.begin(); state != parent.end(); ++state) {
531 if (state->active()) {
550 const CHSM::parent& parent =
static_cast<const CHSM::parent&
>(
Main.
RunControl);
552 for (CHSM::parent::const_iterator state = parent.begin(); state != parent.end(); ++state) {
554 if (state->active()) {
562 if (i->getMode() == JClient::ACTIVE) {
564 if (!i->getAlive()) {
574 if (buffer.find(i->getHostname()) == string::npos) {
575 JErrorStream(
logger) << i->getFullName() <<
" running on " << buffer <<
" but not alive.";
584 if (i->getAlive() && i->getStatename() != state->name()) {
615 const CHSM::parent& parent =
static_cast<const CHSM::parent&
>(
Main.
RunControl);
617 for (CHSM::parent::const_iterator state = parent.begin(); state != parent.end(); ++state) {
619 if (state->active()) {
623 if (
target ==
"" || i->getName().find(
target) != std::string::npos) {
625 if (!i->getAlive() || i->getStatename() != state->name()) {
629 i->setMode(JClient::SLEEP);
653 static void copy(std::istream& in, std::ostream& out,
const char eol =
'\n')
662 if (
getline(in, buffer, eol)) {
664 for (string::size_type pos = 0; pos < buffer.length(); ) {
669 if (lpos != string::npos &&
670 rpos != string::npos) {
672 out << buffer.substr(pos, lpos);
677 ifstream file(buffer.substr(pos, rpos - lpos).c_str());
679 copy(file, out,
'\0');
686 out << buffer.substr(pos);
688 pos += buffer.substr(pos).length();
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
JDAQStateMachine::state_Main::state_RunControl RunControl
JDAQStateMachine::ev_check_event ev_check
JDAQStateMachine::state_Main Main
Exception for ControlHost.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
Auxiliary class to specify white space character(s) in currect locale.
Interface for logging messages.
bool is_valid() const
Check validity of logger object.
List of ControlHost client managers.
ControlHost client manager.
static int WhereIs(const std::string &host_name, const std::string &nick_name, std::string &answer)
Locate ControlHost client(s).
Control unit client base class.
JDAQEvent_t * findEvent(const JTag &tag, const std::string &event_name)
Find event in event table.
JSharedPointer< JControlHost > server
message server
virtual bool filter(const JTag &tag, int length, const char *buffer)
Filter message.
virtual bool exit() override
Exit the state machine.
JMessageLogger logger
message logger
Simple driver for run control clients.
virtual bool enter() override
Enter the state machine.
virtual void actionStart(int, const char *) override
virtual bool filter(const JTag &tag, int length, const char *buffer)
Filter message.
void run(std::istream &in)
Run driver.
JDAQDriver(const std::string &name, const std::string &server, JLogger *logger, const int level, const int timeout_s)
Constructor.
virtual void actionStop(int, const char *) override
virtual void enterState(const CHSM::state &state, const CHSM::event &event) override
Action when entering state.
int timeout_us
timeout of state transitions [us]
void run()
Run driver with user input.
void update()
Update client list with incoming ControlHost messages until the client list is synchronised with the ...
void filter(const std::string &target="")
Filter client list by putting failing clients to sleep.
void synchronise()
Synchronise clients.
virtual void actionExit() override
Exit the state machine.
static void copy(std::istream &in, std::ostream &out, const char eol='\n')
Copy data from input to output stream.
bool update(const bool no_wait)
Update client list with incoming ControlHost message.
static const int SLEEP_TIME_US
Auxiliary classes and methods for language specific functionality.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
static const JTag DISPTAG_Born("Born")
static const JTag DISPTAG_Died("Died")
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
static const std::string FILENAME_PREFIX
static const JNET::JTag RC_REPLY
static const std::string RUN_CONTROL_CLIENT
static const std::string TOKEN_DELIMETER
JTag getUniqueTag(const std::string &hostname, const std::string &name)
Get unique tag of run control client.
static const JNET::JTag RC_CMD
static const JNET::JTag RC_LOG
char getTokenDelimeter()
Get the token delimeter for command messages.
static const std::string FILENAME_POSTFIX
Level specific message streamers.
Auxiliary class for all subscription.
const std::string & getFullName() const
Get full name of this run control client.
Auxiliary class for handling event name and optional static information.
const std::string & getName() const
Get event name.