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];
229 server->GetFullData(data, length);
231 const string buffer(data, length);
241 }
else if (buffer.find(
getFullName()) != string::npos) {
254 i->update(tag, buffer);
268 istringstream
is(buffer);
278 client.update(tag, buffer);
279 client.setMode(JClient::ILLEGAL);
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) {
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());
686 out << buffer.substr(pos);
688 pos += buffer.substr(pos).length();
static const std::string FILENAME_PREFIX
const std::string & getName() const
Get event name.
static const JTag DISPTAG_Died("Died")
JDAQEvent_t * findEvent(const JTag &tag, const std::string &event_name)
Find event in event table.
static const std::string FILENAME_POSTFIX
then usage $script[< detector identifier >< run range >]< QA/QCfile > nExample script to produce data quality plots nWhen a detector identifier and run range are data are downloaded from the database nand subsequently stored in the given QA QC file
ControlHost client manager.
JDAQStateMachine::state_Main Main
JTag getUniqueTag(const std::string &hostname, const std::string &name)
Get unique tag of run control client.
List of ControlHost client managers.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
virtual void actionStart(int, const char *) override
Interface for logging messages.
static void copy(std::istream &in, std::ostream &out, const char eol= '\n')
Copy data from input to output stream.
virtual bool exit() override
Exit the state machine.
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Simple data structure to support I/O of equations (see class JLANG::JEquation).
JSharedPointer< JControlHost > server
message server
static const std::string TOKEN_DELIMETER
Simple driver for run control clients.
virtual bool filter(const JTag &tag, int length, const char *buffer)
Filter message.
void synchronise()
Synchronise clients.
void run()
Run driver with user input.
static const int SLEEP_TIME_US
static const std::string RUN_CONTROL_CLIENT
static const JNET::JTag RC_LOG
virtual void actionExit() override
Exit the state machine.
static const JNET::JTag RC_REPLY
then echo Test string reversed by client(hit< return > to continue)." $DIR/JProcess -c "$DIR/JEcho-r" -C fi if (( 1 ))
bool update(const bool no_wait)
Update client list with incoming ControlHost message.
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Auxiliary class for handling event name and optional static information.
Level specific message streamers.
Exception for ControlHost.
char getTokenDelimeter()
Get the token delimeter for command messages.
Auxiliary class for all subscription.
void run(std::istream &in)
Run driver.
virtual void actionStop(int, const char *) override
virtual void enterState(const CHSM::state &state, const CHSM::event &event) override
Action when entering state.
JDAQStateMachine::ev_check_event ev_check
static const JTag DISPTAG_Born("Born")
$WORKDIR ev_configure_dqsimulator txt echo process $DQ_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DQ_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
JDAQDriver(const std::string &name, const std::string &server, JLogger *logger, const int level, const int timeout_s)
Constructor.
int timeout_us
timeout of state transitions [us]
bool is_valid() const
Check validity of logger object.
Auxiliary class to specify white space character(s) in currect locale.
const std::string & getFullName() const
Get full name of this run control client.
Control unit client base class.
then fatal The output file must have the wildcard in the e g root fi 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
void filter(const std::string &target="")
Filter client list by putting failing clients to sleep.
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::state_Main::state_RunControl RunControl
void update()
Update client list with incoming ControlHost messages until the client list is synchronised with the ...
virtual bool enter() override
Enter the state machine.