1 #ifndef __JRUNCONTROL__JDAQCLIENT__
2 #define __JRUNCONTROL__JDAQCLIENT__
43 using namespace JLOGGER;
63 static const int TIMEOUT_S = 1;
82 eventTable.insert(*tag, chsm->
ev_init);
84 eventTable.insert(*tag, chsm->
ev_start);
85 eventTable.insert(*tag, chsm->
ev_pause);
87 eventTable.insert(*tag, chsm->
ev_stop);
88 eventTable.insert(*tag, chsm->
ev_reset);
89 eventTable.insert(*tag, chsm->
ev_quit);
90 eventTable.insert(*tag, chsm->
ev_off);
92 eventTable.insert(*tag, chsm->
ev_check);
93 eventTable.insert(*tag, chsm->
ev_input);
100 setClockInterval(TIMEOUT_S * 1000000LL);
144 return clock.getDelay();
156 return clock.getInterval();
167 clock.setInterval(interval_us);
198 this->event_info = info;
337 JErrorStream(this->logger) <<
"Process with nick name \"" <<
getFullName() <<
"\" already running on host(s) " << buffer;
400 parser[
'H'] =
make_field(server) =
"localhost";
401 parser[
'M'] =
make_field(logger) =
"localhost";
405 if (parser.read(args) != 0) {
409 catch(
const exception &error) {
410 cerr << error.what() << endl;
430 cerr << error << endl;
449 if (server.is_valid() && logger.is_valid()) {
455 server->Subscribe(buffer);
456 server->SendMeAlways();
461 return CHSM::machine::enter();
468 cerr <<
"Message server or logger not properly initialised." << endl;
485 if (server.is_valid()) { server.reset(NULL); }
491 if (logger.is_valid()) { logger.reset(NULL); }
507 return Main.RunControl.Operational.Running.active();
522 eventTable.replace(oldTag, newTag, event);
535 JEventTable::const_iterator
i = eventTable.find(tag, event_name);
537 if (i != eventTable.end())
551 this->subscription.add(subscription);
578 parser[option] =
make_field(parameter) = value;
589 setSelect(select.getReaderMask());
591 select.setReaderMask(*server);
638 int level = this->logger.getLevel();
640 properties[
"debug"] = level;
642 properties.
read(
string(buffer, length));
644 this->logger.setLevel(level);
659 virtual bool filter(
const JTag& tag,
int length,
const char* buffer)
697 if (select(
JTimeval(TIMEOUT_S,0)) > 0) {
699 if (select.hasReaderMask(*server)) {
703 actionSelect(select.getReaderMask());
711 if (isRunning() && clock.getInterval() != 0LL) {
713 long long int numberOfCalls = 0;
723 if (clock.wait(select.getReaderMask())) {
725 if (select.hasReaderMask(*server)) {
729 actionSelect(select.getReaderMask());
736 catch(
const exception& error) {
737 logger.error(error.what());
741 }
while (isRunning());
743 if (numberOfCalls != 0) {
744 JNoticeStream(logger) <<
"Delay per call " << clock.getDelay() / numberOfCalls / 1000 <<
" ms";
748 catch(
const exception& error) {
749 JErrorStream(logger) <<
"method run(): " << error.what();
781 const int length = prefix.
getSize();
783 char* buffer =
new char[length];
819 while (in >> tag && in >> skipws &&
getline(in, buffer,
';')) {
820 update(tag, buffer.length(), buffer.data());
838 server->WaitHead(prefix);
840 const int length = prefix.
getSize();
842 char* buffer =
new char[length];
844 server->GetFullData(buffer, length);
846 update(prefix.
getTag(), length, buffer);
864 if (filter(tag, length, buffer)) {
871 actionTagged(tag, length, buffer);
877 string::size_type pos = 0;
879 while (pos != (string::size_type) length &&
TOKEN_DELIMETER.find(*(buffer + pos)) == string::npos) {
885 if (event.hasInfo()) {
886 setEventInfo(event.getInfo());
889 while (pos != (string::size_type) length &&
TOKEN_DELIMETER.find(*(buffer + pos)) != string::npos) {
894 JEventTable::const_iterator
i = eventTable.find(tag, event.getName());
896 if (
i != eventTable.end()) {
898 const CHSM::state*
const s0 = getState();
900 if (!
i->second->active()) {
902 JWarningStream(logger) <<
"Event " <<
i->second->name() <<
" not active (" << (s0 != NULL ? s0->name() :
"") <<
")";
904 if (server.
is_valid() && s0 != NULL) {
905 server->PutFullString(
RC_FAIL, getMessage(*s0, *
i->second));
923 (*(
i->second))(length - pos, buffer + pos);
927 const CHSM::state*
const s1 = getState();
930 << (s0 != NULL ? s0->name() :
"")
931 <<
"->(" <<
i->second->name() <<
")->"
932 << (s1 != NULL ? s1->name() :
"");
935 JErrorStream(logger) <<
"Unknown key <" << tag <<
"," <<
event.getName() <<
">";
958 std::ostringstream os;
962 << (getEventInfo() !=
"" ?
963 JEvent_t(event.name(), getEventInfo()) :
979 virtual void enterState(
const CHSM::state& state,
const CHSM::event& event)
982 server->PutFullString(
RC_REPLY, getMessage(state, event));
995 if (
Main.RunControl.Error.active()) {
1001 for (CHSM::parent::iterator state =
Main.RunControl.Operational.begin(); state !=
Main.RunControl.Operational.end(); ++state) {
1003 if (state->active()) {
1020 void execute(action __action,
const CHSM::event& __event)
1026 (this->*__action)(event->length, event->buffer);
1028 catch(
const std::exception& error) {
1029 JErrorStream(logger) <<
"Error at event " << __event.name() <<
" \"" << error.what() <<
"\"; trigger ev_error.";
1042 for (CHSM::parent::const_iterator state =
Main.RunControl.Operational.begin(); state !=
Main.RunControl.Operational.end(); ++state) {
1043 if (state->active()) {
1048 if (
Main.RunControl.Error.active()) {
1049 return &
Main.RunControl.Error;
set Main(RunControl, Responder) is
JParser parser
parser method enter()
Utility class to parse command line options.
long long int getClockDelay() const
Get total delay time.
bool read(const JEquation &equation)
Read equation.
JDAQStateMachine::ev_start_event ev_start
JDAQEvent_t * findEvent(const JTag &tag, const std::string &event_name)
Find event in event table.
JDAQStateMachine::ev_configure_event ev_configure
JTimekeeper clock
central clock
void resetClock()
Reset clock.
JDAQStateMachine::ev_pause_event ev_pause
Message logging based on std::ostream.
JDAQStateMachine::ev_continue_event ev_continue
virtual void setSelect(JFileDescriptorMask &mask) const
Set the file descriptor mask for the select call.
int Connected()
Send version.
JTag getUniqueTag(const std::string &hostname, const std::string &name)
Get unique tag of run control client.
JDAQStateMachine::ev_reset_event ev_reset
JSelectReader select
select call
Message reporting compatible with STL output stream operations.
long long int getClockInterval() const
Get interval time.
void setEventInfo(const std::string &info)
Set last event information.
Auxiliary data structure for DAQ client data.
std::string toString() const
Convert subscription list to string.
Interface for logging messages.
Message logging based on ControlHost.
then echo Enter input within $TIMEOUT_S seconds echo n User name
Utility class to parse parameter values.
void setClockInterval(const long long int interval_us)
Set interval time.
JDAQClient(const std::string &name)
Constructor.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
then usage $script< detector file >< detectorfile > nIf the range of floors is the first detector file is aligned to the second before the comparison nIn this
Jpp environment information.
const std::string & getEventInfo() const
Get last event information.
virtual void enterState(const CHSM::state &state, const CHSM::event &event)
Action when entering state.
void configure()
Configure client.
JSharedPointer< JControlHost > server
message server
void replaceEvent(const JTag &oldTag, const JTag &newTag, JDAQEvent_t &event)
Replace tag of given event in event table.
static const std::string TOKEN_DELIMETER
void execute(action __action, const CHSM::event &__event)
The method to execute the action.
void run()
Run as run control client following command messages via JNET::JControlHost.
std::string event_info
event information
JDAQStateMachine::ev_init_event ev_init
virtual bool filter(const JTag &tag, int length, const char *buffer)
Filter message.
bool is_valid() const
Check validity of pointer.
int getSize() const
Get size.
Utility class to parse parameter values.
JDAQClient_t(JDAQStateMachine *chsm)
Constructor.
static JEvent_t toValue(const std::string &buffer)
Convert string to event.
Auxiliary class for time values.
void run(const int port)
Run for ever.
JDAQStateMachine::ev_stop_event ev_stop
std::string getStateName(const std::string &name)
Get name of state.
const CHSM::state * getState() const
Get current state.
Scheduling of actions via fixed latency intervals.
std::string getGITVersion(const std::string &tag)
Get GIT version for given GIT tag.
The template JSharedPointer class can be used to share a pointer to an object.
This class can be used to temporarily redirect one output (input) stream to another output (input) st...
static const JNET::JTag RC_REPLY
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
virtual bool enter()
Enter the state machine.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
virtual void actionRunning()
This method is repeatedly called when this client machine is in state Running and the clock interval ...
Auxiliary class for method select.
Wrapper class for select call.
Auxiliary class for any subscription.
virtual void actionTagged(const JTag &tag, int length, const char *buffer)
This method is called when a custom tag is encountered.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
static const JTag DISPTAG_UNDEFINED(0)
Auxiliary class for handling event name and optional static information.
Level specific message streamers.
Exception for ControlHost.
virtual bool exit()
Exit the state machine.
Data structure to store command line arguments.
char getTokenDelimeter()
Get the token delimeter for command messages.
bool isRunning() const
Check if this client is in runnig state.
Auxiliary class for all subscription.
void update(const JTag &tag, int length, const char *buffer)
Update state machine.
JSubscriptionList subscription
custom subscription
JControlHost * AcceptClient(JTimeval timeout=JTimeval::max())
Accept new client.
const std::string & getHostname() const
Get hostname.
const JTag & getTag() const
Get tag.
std::string getHostname()
Get host name.
void update()
Update state machine.
JDAQStateMachine::ev_check_event ev_check
int WaitHead(JPrefix &prefix)
Wait for header.
void addParameter(const char option, T ¶meter, const T &value)
Add parameter to parser used in method enter().
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.
std::string toString() const
Convert tag to string.
General purpose message reporting.
JEventTable eventTable
event table
JDAQStateMachine::ev_quit_event ev_quit
int GetFullData(void *buffer, long long int length)
Receive data.
const std::string & getFullName() const
Get full name of this run control client.
JDAQStateMachine::ev_input_event ev_input
Control unit client base class.
Utility class to parse command line options.
void run(std::istream &in)
Run client with commands from input stream (e.g. for debugging).
ControlHost subscription.
std::string getMessage(const CHSM::state &state, const CHSM::event &event) const
Get event message.
JSubscriptionList getSubscription(const JEventTable &event_table)
Convert event table to ControlHost subscription.
virtual bool enter(const JArgs &args)
Enter the state machine.
const JTag & getUniqueTag() const
Get unique tag of this run control client.
JDAQClient(const std::string &name, const std::string &server, JLogger *logger, const int level)
Constructor.
const char * getName()
Get ROOT name of given data type.
JMessageLogger logger
message logger
static const JNET::JTag RC_CMD
static int WhereIs(const std::string &host_name, const std::string &nick_name, std::string &answer)
Locate ControlHost client(s).
JDAQStateMachine::ev_off_event ev_off
const std::string & getName() const
Get name of state machine.
std::string getFullName(const std::string &hostname, const std::string &name)
Get full name of run control client.
static JNullStream null
Null I/O stream.
void setSelect()
Set the file descriptor mask for the select call.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
static const JNET::JTag RC_FAIL
int PutFullData(const JTag &tag, const void *buffer, const long long int length)
Send data.
Hostname and IP address functions.
virtual void actionSelect(const JFileDescriptorMask &mask)
Action method following last select call.
void addSubscription(const JSubscription &subscription)
Add custom subscription.
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...
static void Throw(const bool option)
Enable/disable throw option.
Light-weight wrapper class around server socket.
JDAQStateMachine::ev_recover_event ev_recover
JDAQClient(const std::string &name, JLogger *logger, const int level)
Constructor.