1 #ifndef __JRUNCONTROL__JDAQDRIVER__
2 #define __JRUNCONTROL__JDAQDRIVER__
55 const int timeout_s) :
123 if (i->isActive() && i->getBorn() <= i->getDied()) {
129 return CHSM::machine::enter();
132 cerr <<
"Timeout at subscription." << endl;
136 cerr << error << endl;
140 cerr <<
"Message server or logger not properly initialised." << endl;
156 using namespace JLANG;
184 virtual void enterState(
const CHSM::state& state,
const CHSM::event& event)
override
194 JWarningStream(
logger) <<
"Timeout at transition " <<
event.name() <<
" to state " << state.name();
213 using namespace JNET;
219 long long int length = 0;
221 if ( no_wait &&
server->CheckHead(tag, length) <= 0) {
return false; }
222 if (!no_wait &&
server->WaitHead (tag, length) < 0) {
return false; }
224 char* data=
new char[length];
226 server->GetFullData(data, length);
228 const string buffer(data, length);
238 }
else if (buffer.find(
getFullName()) != string::npos) {
247 JClientList::iterator i =
clientList.find(buffer);
251 i->update(tag, buffer);
265 istringstream
is(buffer);
275 client.update(tag, buffer);
276 client.setMode(JClient::ILLEGAL);
366 for (
string key; in >> key; ) {
370 in.ignore(numeric_limits<streamsize>::max(),
'\n');
372 }
else if (key ==
"enter") {
377 cerr <<
"State machine not entered; abort." << endl;
381 }
else if (key ==
"exit") {
386 }
else if (key ==
"quit") {
390 }
else if (key ==
"sleep") {
398 }
else if (key ==
"process") {
404 istringstream
is(buffer);
410 client.setMode(JClient::ACTIVE);
420 }
else if (key ==
"event" || key ==
"event*") {
425 const char eol =
'\n';
427 if (in >> event >> c && c ==
'{' &&
getline(in, buffer,
'}')) {
435 if (pev->active() || key ==
"event*") {
437 istringstream
is(buffer);
439 for (
string tag; is >> tag; ) {
449 server->PutFullString(tag, os.str());
452 if (key !=
"event*") {
472 }
else if (key ==
"message") {
477 if (in >> tag &&
getline(in, buffer,
';'))
478 server->PutFullString(tag, buffer);
482 }
else if (key ==
"print") {
486 << i->getStartCommand() <<
' '
487 << i->getAlive() <<
' '
488 << i->getStatename();
491 }
else if (key ==
"filter") {
498 for (istringstream
is(buffer);
is >>
client; ) {
502 }
else if (key ==
"sync") {
510 in.ignore(numeric_limits<streamsize>::max(),
'\n');
524 const CHSM::parent& parent =
static_cast<const CHSM::parent&
>(
Main.
RunControl);
526 for (CHSM::parent::const_iterator state = parent.begin(); state != parent.end(); ++state) {
528 if (state->active()) {
547 const CHSM::parent& parent =
static_cast<const CHSM::parent&
>(
Main.
RunControl);
549 for (CHSM::parent::const_iterator state = parent.begin(); state != parent.end(); ++state) {
551 if (state->active()) {
559 if (i->getMode() == JClient::ACTIVE) {
561 if (!i->getAlive()) {
571 if (buffer.find(i->getHostname()) == string::npos) {
572 JErrorStream(
logger) << i->getFullName() <<
" running on " << buffer <<
" but not alive.";
581 if (i->getAlive() && i->getStatename() != state->name()) {
612 const CHSM::parent& parent =
static_cast<const CHSM::parent&
>(
Main.
RunControl);
614 for (CHSM::parent::const_iterator state = parent.begin(); state != parent.end(); ++state) {
616 if (state->active()) {
620 if (
target ==
"" || i->getName().find(
target) != std::string::npos) {
622 if (!i->getAlive() || i->getStatename() != state->name()) {
626 i->setMode(JClient::SLEEP);
650 static void copy(std::istream&
in, std::ostream& out,
const char eol =
'\n')
656 if (
getline(in, buffer, eol)) {
658 for (string::size_type pos = 0; pos < buffer.length(); ) {
663 if (lpos != string::npos &&
664 rpos != string::npos) {
666 out << buffer.substr(pos, lpos);
671 ifstream
file(buffer.substr(pos, rpos - lpos).c_str());
680 out << buffer.substr(pos);
682 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.
JSharedPointer< JControlHost > server
message server
static const std::string TOKEN_DELIMETER
Simple driver for run control clients.
void synchronise()
Synchronise clients.
void run()
Run driver with user input.
static const int SLEEP_TIME_US
static const std::string RUN_CONTROL_CLIENT
void actionExit()
Exit the state machine.
static const JNET::JTag RC_LOG
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 number.
Level specific message streamers.
Exception for ControlHost.
virtual bool exit()
Exit the state machine.
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.
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 ...
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
virtual bool enter() override
Enter the state machine.