1 #ifndef __JRUNCONTROL__JDAQCLIENT__ 
    2 #define __JRUNCONTROL__JDAQCLIENT__ 
   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;
 
  302     using CHSM::machine::enter;
 
  303     using CHSM::machine::exit;
 
  320                const std::string& server,
 
  331       catch(
const std::exception& error) {
 
  340         JErrorStream(this->logger) << 
"Process with nick name \"" << 
getFullName() << 
"\" already running on host(s) " << buffer; 
 
  403         parser[
'H'] = 
make_field(server)    = 
"localhost";
 
  404         parser[
'M'] = 
make_field(logger)    = 
"localhost";
 
  408         if (parser.read(
args) != 0) {
 
  412       catch(
const std::exception &error) {
 
  413         cerr << error.what() << endl;
 
  432       catch(
const std::exception& error) {
 
  433         cerr << error.what() << endl;
 
  452       if (server.is_valid() && logger.is_valid()) {
 
  458           server->Subscribe(buffer);
 
  459           server->SendMeAlways();
 
  464           return CHSM::machine::enter();
 
  466         catch(
const std::exception& error) {
 
  471         cerr << 
"Message server or logger not properly initialised." << endl;
 
  488         if (server.is_valid()) { server.reset(NULL); }
 
  490       catch(
const std::exception& error) {
 
  494         if (logger.is_valid()) { logger.reset(NULL); }
 
  496       catch(
const std::exception& error) {
 
  499       return CHSM::machine::exit();
 
  510       return Main.RunControl.Operational.Running.active();
 
  525       eventTable.replace(oldTag, newTag, event);
 
  538       JEventTable::const_iterator i = eventTable.find(tag, event_name);
 
  540       if (i != eventTable.end())
 
  554       this->subscription.add(subscription);
 
  581       parser[option] = 
make_field(parameter) = value;
 
  592       setSelect(
select.getReaderMask());
 
  594       select.setReaderMask(*server);
 
  641       int level = this->logger.getLevel();
 
  643       properties[
"debug"] = level;
 
  645       properties.
read(
string(buffer, length));
 
  647       this->logger.setLevel(level);
 
  662     virtual bool filter(
const JTag& tag, 
int length, 
const char* buffer)
 
  703             if (
select.hasReaderMask(*server)) {
 
  707             actionSelect(
select.getReaderMask());
 
  715           if (isRunning() && clock.getInterval() != 0LL) {
 
  717             long long int numberOfCalls = 0;
 
  727               if (clock.wait(
select.getReaderMask())) {
 
  729                 if (
select.hasReaderMask(*server)) {
 
  733                 actionSelect(
select.getReaderMask());
 
  740                 catch(
const std::exception& error) {
 
  741                   logger.error(error.what());
 
  745             } 
while (isRunning());
 
  747             if (numberOfCalls != 0) {
 
  748               JNoticeStream(logger) << 
"Delay per call " << clock.getDelay() / numberOfCalls / 1000 << 
" ms";
 
  753           JErrorStream(logger) << 
"method run(): \"" << error.
what() << 
"\" -> trigger ev_error.";
 
  756         catch(
const std::exception& error) {
 
  789         const int length = prefix.
getSize();
 
  791         char* buffer = 
new char[length];
 
  798         enter(
JArgs(std::string(buffer, length)));
 
  820     void run(std::istream& in)
 
  827       while (in >> tag && in >> skipws && 
getline(in, buffer, 
';')) {
 
  828         update(tag, buffer.length(), buffer.data());
 
  846       server->WaitHead(prefix);
 
  848       const int length = prefix.
getSize();
 
  850       char* buffer = 
new char[length];
 
  852       server->GetFullData(buffer, length);
 
  854       update(prefix.
getTag(), length, buffer);
 
  872       if (
filter(tag, length, buffer)) {
 
  879         actionTagged(tag, length, buffer);
 
  885       string::size_type pos = 0;
 
  887       while (pos != (string::size_type) length && 
TOKEN_DELIMETER.find(*(buffer + pos)) == string::npos) {
 
  893       if (event.hasInfo()) {
 
  894         setEventInfo(event.getInfo());
 
  897       while (pos != (string::size_type) length && 
TOKEN_DELIMETER.find(*(buffer + pos)) != string::npos) {
 
  902       JEventTable::const_iterator i = eventTable.find(tag, event.getName());
 
  904       if (i != eventTable.end()) {
 
  906         const CHSM::state* 
const s0 = getState();
 
  908         if (!i->second->active()) {
 
  910           JWarningStream(logger) << 
"Event " << i->second->name() << 
" not active (" << (s0 != NULL ? s0->name() : 
"") << 
")";
 
  912           if (server.
is_valid() && s0 != NULL) {
 
  913             server->PutFullString(
RC_FAIL, getMessage(*s0, *i->second));
 
  931             (*(i->second))(length - pos, buffer + pos);
 
  935         const CHSM::state* 
const s1 = getState();
 
  938                               << (s0 != NULL ? s0->name() : 
"") 
 
  939                               << 
"->(" << i->second->name() << 
")->"  
  940                               << (s1 != NULL ? s1->name() : 
"");
 
  943         JErrorStream(logger) << 
"Unknown key <" << tag << 
"," << 
event.getName() << 
">";
 
  964     std::string 
getMessage(
const CHSM::state& state, 
const CHSM::event& event)
 const 
  966       std::ostringstream os;
 
  970          << (getEventInfo() != 
"" ? 
 
  971              JEvent_t(event.name(), getEventInfo()) : 
 
  987     virtual void enterState(
const CHSM::state& state, 
const CHSM::event& event)
 override 
  990         server->PutFullString(
RC_REPLY, getMessage(state, event));
 
 1003       if (Main.RunControl.Error.active()) {
 
 1005         enterState(Main.RunControl.Error, ev_check);
 
 1009         for (CHSM::parent::iterator state = Main.RunControl.Operational.begin(); state != Main.RunControl.Operational.end(); ++state) {
 
 1011           if (state->active()) {
 
 1015             enterState(*state, ev_check);
 
 1028     void execute(action __action, 
const CHSM::event& __event)
 override 
 1034         (this->*__action)(event->length, event->buffer);
 
 1036       catch(
const std::exception& error) {
 
 1037         JErrorStream(logger) << 
"Error at event " << __event.name() << 
" \"" << error.what() << 
"\"; trigger ev_error.";
 
 1050       for (CHSM::parent::const_iterator state = Main.RunControl.Operational.begin(); state != Main.RunControl.Operational.end(); ++state) {
 
 1051         if (state->active()) {
 
 1056       if (Main.RunControl.Error.active()) {
 
 1057         return &Main.RunControl.Error;
 
General purpose message reporting.
 
Message reporting compatible with STL output stream operations.
 
Hostname and IP address functions.
 
Utility class to parse command line options.
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
 
Utility class to parse parameter values.
 
Scheduling of actions via fixed latency intervals.
 
Jpp environment information.
 
const std::string & getName() const
Get name of state machine.
 
JDAQStateMachine::ev_recover_event ev_recover
 
JDAQStateMachine::ev_continue_event ev_continue
 
JDAQStateMachine::ev_stop_event ev_stop
 
JDAQStateMachine::ev_off_event ev_off
 
JDAQStateMachine::ev_init_event ev_init
 
JDAQStateMachine::ev_start_event ev_start
 
JDAQStateMachine::ev_pause_event ev_pause
 
JDAQStateMachine::ev_check_event ev_check
 
JDAQStateMachine::ev_reset_event ev_reset
 
JDAQStateMachine::ev_configure_event ev_configure
 
JDAQStateMachine::ev_input_event ev_input
 
JDAQStateMachine::ev_quit_event ev_quit
 
Data structure to store command line arguments.
 
Utility class to parse parameter values.
 
bool read(const JEquation &equation)
Read equation.
 
bool is_valid() const
Check validity of pointer.
 
Exception for ControlHost.
 
Simple data structure to support I/O of equations (see class JLANG::JEquation).
 
virtual const char * what() const override
Get error message.
 
Auxiliary class for method select.
 
This class can be used to temporarily redirect one output (input) stream to another output (input) st...
 
The template JSharedPointer class can be used to share a pointer to an object.
 
static void Throw(const bool option)
Enable/disable throw option.
 
Auxiliary class for time values.
 
Message logging based on ControlHost.
 
Interface for logging messages.
 
Message logging based on std::ostream.
 
Light-weight wrapper class around server socket.
 
JControlHost * AcceptClient(JTimeval timeout=JTimeval::max())
Accept new client.
 
static int WhereIs(const std::string &host_name, const std::string &nick_name, std::string &answer)
Locate ControlHost client(s).
 
int WaitHead(JPrefix &prefix)
Wait for header.
 
int GetFullData(void *buffer, long long int length)
Receive data.
 
int PutFullData(const JTag &tag, const void *buffer, const long long int length)
Send data.
 
int Connected()
Send version.
 
int getSize() const
Get size.
 
Wrapper class for select call.
 
std::string toString() const
Convert subscription list to string.
 
ControlHost subscription.
 
std::string toString() const
Convert tag to string.
 
const JTag & getTag() const
Get tag.
 
Utility class to parse command line options.
 
Control unit client base class.
 
JDAQEvent_t * findEvent(const JTag &tag, const std::string &event_name)
Find event in event table.
 
virtual void enterState(const CHSM::state &state, const CHSM::event &event) override
Action when entering state.
 
void update(const JTag &tag, int length, const char *buffer)
Update state machine.
 
JSharedPointer< JControlHost > server
message server
 
virtual void actionInput(int length, const char *buffer) override
This method is called at ev_input.
 
bool isRunning() const
Check if this client is in runnig state.
 
void update()
Update state machine.
 
virtual bool filter(const JTag &tag, int length, const char *buffer)
Filter message.
 
JDAQClient(const std::string &name)
Constructor.
 
JParser parser
parser method enter()
 
virtual void actionTagged(const JTag &tag, int length, const char *buffer)
This method is called when a custom tag is encountered.
 
JDAQClient(const std::string &name, JLogger *logger, const int level)
Constructor.
 
virtual void actionSelect(const JFileDescriptorMask &mask)
Action method following last select call.
 
void replaceEvent(const JTag &oldTag, const JTag &newTag, JDAQEvent_t &event)
Replace tag of given event in event table.
 
void execute(action __action, const CHSM::event &__event) override
The method to execute the action.
 
std::string getMessage(const CHSM::state &state, const CHSM::event &event) const
Get event message.
 
virtual bool exit() override
Exit the state machine.
 
void addParameter(const char option, T ¶meter)
Add parameter to parser used in method enter().
 
void run(std::istream &in)
Run client with commands from input stream (e.g. for debugging).
 
void run(const int port)
Run for ever.
 
void run()
Run as run control client following command messages via JNET::JControlHost.
 
const CHSM::state * getState() const
Get current state.
 
void configure()
Configure client.
 
virtual void setSelect(JFileDescriptorMask &mask) const
Set the file descriptor mask for the select call.
 
JSelectReader select
select call
 
JMessageLogger logger
message logger
 
virtual void actionRunning()
This method is repeatedly called when this client machine is in state Running and the clock interval ...
 
void addParameter(const char option, T ¶meter, const T &value)
Add parameter to parser used in method enter().
 
void setSelect()
Set the file descriptor mask for the select call.
 
virtual bool enter() override
Enter the state machine.
 
JSubscriptionList subscription
custom subscription
 
virtual bool enter(const JArgs &args)
Enter the state machine.
 
JDAQClient(const std::string &name, const std::string &server, JLogger *logger, const int level)
Constructor.
 
virtual void actionCheck(int length, const char *buffer) override
This method is called at ev_check and reports a system check by mimicing an enter state action.
 
void addSubscription(const JSubscription &subscription)
Add custom subscription.
 
bool select(const Trk &trk, const Evt &evt)
Event selection.
 
std::string getGITVersion(const std::string &tag)
Get GIT version for given GIT tag.
 
static JNullStream null
Null I/O stream.
 
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
 
static const JTag DISPTAG_UNDEFINED(0)
 
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
 
bool filter(const JDAQEvent &tev, const JEvt &evt, const Evt *const pE)
Event selection.
 
const char * getName()
Get ROOT name of given data type.
 
std::string getHostname()
Get host name.
 
KM3NeT DAQ data structures and auxiliaries.
 
static const JNET::JTag RC_REPLY
 
std::string getFullName(const std::string &hostname, const std::string &name)
Get full name of run control client.
 
JSubscriptionList getSubscription(const JEventTable &event_table)
Convert event table to ControlHost subscription.
 
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
 
std::string getStateName(const std::string &name)
Get name of state.
 
char getTokenDelimeter()
Get the token delimeter for command messages.
 
static const JNET::JTag RC_FAIL
 
Level specific message streamers.
 
Auxiliary class for all subscription.
 
Auxiliary class for any subscription.
 
Auxiliary data structure for DAQ client data.
 
const std::string & getEventInfo() const
Get last event information.
 
JTimekeeper clock
central clock
 
void setEventInfo(const std::string &info)
Set last event information.
 
void setClockInterval(const long long int interval_us)
Set interval time.
 
long long int getClockDelay() const
Get total delay time.
 
void resetClock()
Reset clock.
 
const std::string & getFullName() const
Get full name of this run control client.
 
JEventTable eventTable
event table
 
const std::string & getHostname() const
Get hostname.
 
JDAQClient_t(JDAQStateMachine *chsm)
Constructor.
 
std::string event_info
event information
 
long long int getClockInterval() const
Get interval time.
 
const JTag & getUniqueTag() const
Get unique tag of this run control client.
 
Auxiliary class for handling event name and optional static information.
 
static JEvent_t toValue(const std::string &buffer)
Convert string to event.