Go to the documentation of this file. 1 #ifndef __JRUNCONTROL__JDAQCLIENT__
2 #define __JRUNCONTROL__JDAQCLIENT__
61 static const int TIMEOUT_S = 1;
81 eventTable.insert(*tag, chsm->
ev_init);
83 eventTable.insert(*tag, chsm->
ev_start);
84 eventTable.insert(*tag, chsm->
ev_pause);
86 eventTable.insert(*tag, chsm->
ev_stop);
87 eventTable.insert(*tag, chsm->
ev_reset);
88 eventTable.insert(*tag, chsm->
ev_quit);
89 eventTable.insert(*tag, chsm->
ev_off);
91 eventTable.insert(*tag, chsm->
ev_check);
92 eventTable.insert(*tag, chsm->
ev_input);
99 setClockInterval(TIMEOUT_S * 1000000LL);
143 return clock.getDelay();
155 return clock.getInterval();
166 clock.setInterval(interval_us);
197 this->event_number = event_number;
291 const std::string& server,
311 JErrorStream(this->logger) <<
"Process with nick name \"" <<
getFullName() <<
"\" already running on host(s) " << buffer;
374 parser[
'H'] =
make_field(server) =
"localhost";
375 parser[
'M'] =
make_field(logger) =
"localhost";
379 if (parser.read(args) != 0) {
383 catch(
const exception &error) {
384 cerr << error.what() << endl;
404 cerr << error << endl;
423 if (server.is_valid() && logger.is_valid()) {
429 server->Subscribe(buffer);
430 server->SendMeAlways();
435 return CHSM::machine::enter();
442 cerr <<
"Message server or logger not properly initialised." << endl;
459 if (server.is_valid()) { server.reset(NULL); }
465 if (logger.is_valid()) { logger.reset(NULL); }
470 return CHSM::machine::exit();
481 return Main.RunControl.Operational.Running.active();
496 eventTable.replace(oldTag, newTag, event);
509 JEventTable::const_iterator i = eventTable.find(tag, event_name);
511 if (i != eventTable.end())
525 this->subscription.add(subscription);
552 parser[option] =
make_field(parameter) = value;
563 setSelect(select.getReaderMask());
565 select.setReaderMask(*server);
612 int level = this->logger.getLevel();
614 properties[
"debug"] = level;
616 properties.
read(
string(buffer, length));
618 this->logger.setLevel(level);
633 virtual bool filter(
const JTag& tag,
int length,
const char* buffer)
671 if (select(
JTimeval(TIMEOUT_S,0)) > 0) {
673 if (select.hasReaderMask(*server)) {
677 actionSelect(select.getReaderMask());
685 if (isRunning() && clock.getInterval() != 0LL) {
687 long long int numberOfCalls = 0;
697 if (clock.wait(select.getReaderMask())) {
699 if (select.hasReaderMask(*server)) {
703 actionSelect(select.getReaderMask());
710 catch(
const exception& error) {
711 logger.error(error.what());
715 }
while (isRunning());
717 if (numberOfCalls != 0) {
718 JNoticeStream(logger) <<
"Delay per call " << clock.getDelay() / numberOfCalls / 1000 <<
" ms";
722 catch(
const exception& error) {
723 JErrorStream(logger) <<
"method run(): " << error.what();
755 const int length = prefix.
getSize();
757 char* buffer =
new char[length];
764 enter(
JArgs(std::string(buffer, length)));
786 void run(std::istream& in)
793 while (in >> tag && in >> skipws &&
getline(in, buffer,
';')) {
794 update(tag, buffer.length(), buffer.data());
812 server->WaitHead(prefix);
814 const int length = prefix.
getSize();
816 char* buffer =
new char[length];
818 server->GetFullData(buffer, length);
820 update(prefix.
getTag(), length, buffer);
838 if (filter(tag, length, buffer)) {
845 actionTagged(tag, length, buffer);
851 string::size_type pos = 0;
853 while (pos != (string::size_type) length &&
TOKEN_DELIMETER.find(*(buffer + pos)) == string::npos) {
859 setEventNumber(event.getNumber());
861 while (pos != (string::size_type) length &&
TOKEN_DELIMETER.find(*(buffer + pos)) != string::npos) {
866 JEventTable::const_iterator i = eventTable.find(tag, event.getName());
868 if (i != eventTable.end()) {
870 const CHSM::state*
const s0 = getState();
872 if (!i->second->active()) {
874 JWarningStream(logger) <<
"Event " << i->second->name() <<
" not active (" << (s0 != NULL ? s0->name() :
"") <<
")";
876 if (server.
is_valid() && s0 != NULL) {
877 server->PutFullString(
RC_FAIL, getMessage(*s0, *i->second));
895 (*(i->second))(length - pos, buffer + pos);
899 const CHSM::state*
const s1 = getState();
902 << (s0 != NULL ? s0->name() :
"")
903 <<
"->(" << i->second->name() <<
")->"
904 << (s1 != NULL ? s1->name() :
"");
907 JErrorStream(logger) <<
"Unknown key <" << tag <<
"," <<
event.getName() <<
">";
928 std::string
getMessage(
const CHSM::state& state,
const CHSM::event& event)
const
930 std::ostringstream os;
934 <<
JEvent_t(event.name(), event_number)
949 virtual void enterState(
const CHSM::state& state,
const CHSM::event& event)
952 server->PutFullString(
RC_REPLY, getMessage(state, event));
965 if (Main.RunControl.Error.active()) {
967 enterState(Main.RunControl.Error, ev_check);
971 for (CHSM::parent::iterator state = Main.RunControl.Operational.begin(); state != Main.RunControl.Operational.end(); ++state) {
973 if (state->active()) {
977 enterState(*state, ev_check);
990 void execute(action __action,
const CHSM::event& __event)
996 (this->*__action)(event->length, event->buffer);
998 catch(
const std::exception& error) {
999 JErrorStream(logger) <<
"Error at event " << __event.name() <<
" \"" << error.what() <<
"\"; trigger ev_error.";
1012 for (CHSM::parent::const_iterator state = Main.RunControl.Operational.begin(); state != Main.RunControl.Operational.end(); ++state) {
1013 if (state->active()) {
1018 if (Main.RunControl.Error.active()) {
1019 return &Main.RunControl.Error;
Level specific message streamers.
Interface for logging messages.
Auxiliary class for time values.
JDAQStateMachine::ev_stop_event ev_stop
static const JNET::JTag RC_FAIL
static const std::string TOKEN_DELIMETER
void setSelect()
Set the file descriptor mask for the select call.
const CHSM::state * getState() const
Get current state.
JDAQClient(const std::string &name)
Constructor.
Data structure to store command line arguments.
JDAQStateMachine::ev_input_event ev_input
virtual void enterState(const CHSM::state &state, const CHSM::event &event)
Action when entering state.
Auxiliary data structure for DAQ client data.
JParser parser
parser method enter()
Exception for ControlHost.
JDAQStateMachine::ev_quit_event ev_quit
Auxiliary class for any subscription.
JDAQStateMachine::ev_check_event ev_check
void configure()
Configure client.
virtual void setSelect(JFileDescriptorMask &mask) const
Set the file descriptor mask for the select call.
void execute(action __action, const CHSM::event &__event)
The method to execute the action.
JDAQEvent_t * findEvent(const JTag &tag, const std::string &event_name)
Find event in event table.
JTag getUniqueTag(const std::string &hostname, const std::string &name)
Get unique tag of run control client.
void run()
Run as run control client following command messages via JNET::JControlHost.
static const JNET::JTag RC_REPLY
long long int getClockDelay() const
Get total delay time.
const JTag & getTag() const
Get tag.
int Connected()
Send version.
const std::string & getName() const
Get name of state machine.
int GetFullData(void *buffer, long long int length)
Receive data.
static JNullStream null
Null I/O stream.
Utility class to parse command line options.
JEventTable eventTable
event table
bool read(const JEquation &equation)
Read equation.
JSharedPointer< JControlHost > server
message server
JDAQStateMachine::ev_off_event ev_off
virtual bool filter(const JTag &tag, int length, const char *buffer)
Filter message.
JSelectReader select
select call
virtual void actionRunning()
This method is repeatedly called when this client machine is in state Running and the clock interval ...
Wrapper class for select call.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static int WhereIs(const std::string &host_name, const std::string &nick_name, std::string &answer)
Locate ControlHost client(s).
static JEvent_t toValue(const std::string &buffer)
Convert string to event.
Light-weight wrapper class around server socket.
void run(const int port)
Run for ever.
void replaceEvent(const JTag &oldTag, const JTag &newTag, JDAQEvent_t &event)
Replace tag of given event in event table.
JDAQStateMachine::ev_start_event ev_start
std::string getFullName(const std::string &hostname, const std::string &name)
Get full name of run control client.
JDAQClient_t(JDAQStateMachine *chsm)
Constructor.
virtual void actionTagged(const JTag &tag, int length, const char *buffer)
This method is called when a custom tag is encountered.
ControlHost subscription.
Message logging based on std::ostream.
virtual bool exit()
Exit the state machine.
Auxiliary class for method select.
JDAQStateMachine::ev_recover_event ev_recover
void update(const JTag &tag, int length, const char *buffer)
Update state machine.
virtual bool enter()
Enter the state machine.
int WaitHead(JPrefix &prefix)
Wait for header.
JControlHost * AcceptClient(JTimeval timeout=JTimeval::max())
Accept new client.
bool isRunning() const
Check if this client is in runnig state.
void update()
Update state machine.
void run(std::istream &in)
Run client with commands from input stream (e.g.
Control unit client base class.
Message logging based on ControlHost.
void addParameter(const char option, T ¶meter)
Add parameter to parser used in method enter().
virtual void actionInput(int length, const char *buffer)
This method is called at ev_input.
static void Throw(const bool option)
Enable/disable throw option.
const JTag & getUniqueTag() const
Get unique tag of this run control client.
int PutFullData(const JTag &tag, const void *buffer, const long long int length)
Send data.
JDAQStateMachine::ev_reset_event ev_reset
JDAQStateMachine::ev_init_event ev_init
int getEventNumber() const
Get last event number.
JSubscriptionList subscription
custom subscription
JMessageLogger logger
message logger
std::string getHostname()
Get host name.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
const std::string & getFullName() const
Get full name of this run control client.
Utility class to parse parameter values.
JDAQStateMachine::ev_configure_event ev_configure
Auxiliary class for handling event name and optional number.
std::string getStateName(const std::string &name)
Get name of state.
const char * getName()
Get ROOT name of given data type.
void resetClock()
Reset clock.
static const JTag DISPTAG_UNDEFINED(0)
const std::string & getHostname() const
Get hostname.
This class can be used to temporarily redirect one output (input) stream to another output (input) st...
JSubscriptionList getSubscription(const JEventTable &event_table)
Convert event table to ControlHost subscription.
KM3NeT DAQ data structures and auxiliaries.
std::string getMessage(const CHSM::state &state, const CHSM::event &event) const
Get event message.
static const JNET::JTag RC_CMD
virtual void actionCheck(int length, const char *buffer)
This method is called at ev_check and reports a system check by mimicing an enter state action.
JDAQStateMachine::ev_pause_event ev_pause
JDAQStateMachine::ev_continue_event ev_continue
void setClockInterval(const long long int interval_us)
Set interval time.
int event_number
number of last event
void addParameter(const char option, T ¶meter, const T &value)
Add parameter to parser used in method enter().
char getTokenDelimeter()
Get the token delimeter for command messages.
std::string toString() const
Convert tag to string.
JDAQClient(const std::string &name, const std::string &server, JLogger *logger, const int level)
Constructor.
int getSize() const
Get size.
long long int getClockInterval() const
Get interval time.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
JDAQClient(const std::string &name, JLogger *logger, const int level)
Constructor.
virtual bool enter(const JArgs &args)
Enter the state machine.
JTimekeeper clock
central clock
std::string toString() const
Convert subscription list to string.
virtual void actionSelect(const JFileDescriptorMask &mask)
Action method following last select call.
The template JSharedPointer class can be used to share a pointer to an object.
Auxiliary class for all subscription.
bool is_valid() const
Check validity of pointer.
void setEventNumber(const int event_number)
Set last event number.
void addSubscription(const JSubscription &subscription)
Add custom subscription.