1 #include "otsdaq-core/Supervisor/Supervisor.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
4 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
5 #include "otsdaq-core/CgiDataUtilities/CgiDataUtilities.h"
6 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
7 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h"
9 #include "otsdaq-core/WorkLoopManager/WorkLoopManager.h"
10 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
11 #include "otsdaq-core/ConfigurationInterface/ConfigurationManagerRW.h"
12 #include "otsdaq-core/ConfigurationPluginDataFormats/XDAQContextConfiguration.h"
13 #include <cgicc/HTMLClasses.h>
14 #include <cgicc/HTTPCookie.h>
15 #include <cgicc/HTMLDoctype.h>
16 #include <cgicc/HTTPHeader.h>
17 #include <xgi/Utils.h>
19 #include <xoap/Method.h>
20 #include <xdaq/NamespaceURI.h>
21 #include <toolbox/task/WorkLoopFactory.h>
22 #include <toolbox/fsm/FailedEvent.h>
32 #define ICON_FILE_NAME std::string(getenv("SERVICE_DATA_PATH")) + "/OtsWizardData/iconList.dat"
33 #define RUN_NUMBER_PATH std::string(getenv("SERVICE_DATA_PATH")) + "/RunNumber/"
34 #define RUN_NUMBER_FILE_NAME "NextRunNumber.txt"
35 #define FSM_LAST_GROUP_ALIAS_PATH std::string(getenv("SERVICE_DATA_PATH")) + "/RunControlData/"
36 #define FSM_LAST_GROUP_ALIAS_FILE_START std::string("FSMLastGroupAlias-")
37 #define FSM_USERS_PREFERENCES_FILETYPE "pref"
41 #define __MF_SUBJECT__ "OmniSuper"
49 :xdaq::Application (s)
55 ,stateMachineWorkLoopManager_(toolbox::task::bind(this, &Supervisor::stateMachineThread,"StateMachine"))
56 ,stateMachineSemaphore_ (toolbox::BSem::FULL)
57 ,infoRequestWorkLoopManager_ (toolbox::task::bind(this, &Supervisor::infoRequestThread, "InfoRequest"))
58 ,infoRequestSemaphore_ (toolbox::BSem::FULL)
59 , activeStateMachineName_ ("")
62 INIT_MF(
"Supervisor");
63 __MOUT__ << std::endl;
66 mkdir((FSM_LAST_GROUP_ALIAS_PATH).c_str(), 0755);
67 mkdir((RUN_NUMBER_PATH).c_str(), 0755);
69 securityType_ = theWebUsers_.getSecurity();
71 __MOUT__ <<
"Security: " << securityType_ << std::endl;
73 xgi::bind(
this, &Supervisor::Default,
"Default");
74 xgi::bind(
this, &Supervisor::loginRequest,
"LoginRequest");
75 xgi::bind(
this, &Supervisor::request,
"Request");
76 xgi::bind(
this, &Supervisor::stateMachineXgiHandler,
"StateMachineXgiHandler");
77 xgi::bind(
this, &Supervisor::infoRequestHandler,
"InfoRequestHandler");
78 xgi::bind(
this, &Supervisor::infoRequestResultHandler,
"InfoRequestResultHandler");
79 xgi::bind(
this, &Supervisor::tooltipRequest,
"TooltipRequest");
81 xoap::bind(
this, &Supervisor::supervisorCookieCheck,
"SupervisorCookieCheck", XDAQ_NS_URI);
82 xoap::bind(
this, &Supervisor::supervisorGetActiveUsers,
"SupervisorGetActiveUsers", XDAQ_NS_URI);
83 xoap::bind(
this, &Supervisor::supervisorSystemMessage,
"SupervisorSystemMessage", XDAQ_NS_URI);
84 xoap::bind(
this, &Supervisor::supervisorGetUserInfo,
"SupervisorGetUserInfo", XDAQ_NS_URI);
85 xoap::bind(
this, &Supervisor::supervisorSystemLogbookEntry,
"SupervisorSystemLogbookEntry", XDAQ_NS_URI);
86 xoap::bind(
this, &Supervisor::supervisorLastConfigGroupRequest,
"SupervisorLastConfigGroupRequest", XDAQ_NS_URI);
102 Supervisor::~Supervisor(
void)
104 delete theConfigurationManager_;
105 makeSystemLogbookEntry(
"ots halted.");
109 void Supervisor::init(
void)
112 theSupervisorDescriptorInfo_.init(getApplicationContext());
113 theSupervisorsInfo_.init(theSupervisorDescriptorInfo_);
115 supervisorGuiHasBeenLoaded_ =
false;
119 supervisorContextUID_ = contextConfiguration->getContextUID(
120 getApplicationContext()->getContextDescriptor()->getURL()
122 __MOUT__ <<
"Context UID:" << supervisorContextUID_ << std::endl;
124 supervisorApplicationUID_ = contextConfiguration->getApplicationUID(
125 getApplicationContext()->getContextDescriptor()->getURL(),
126 getApplicationDescriptor()->getLocalId()
129 __MOUT__ <<
"Application UID:" << supervisorApplicationUID_ << std::endl;
131 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
132 supervisorContextUID_, supervisorApplicationUID_);
137 std::string supervisorUID;
138 if(!configLinkNode.isDisconnected())
139 supervisorUID = configLinkNode.getValue();
141 supervisorUID = ViewColumnInfo::DATATYPE_LINK_DEFAULT;
143 __MOUT__ <<
"Supervisor UID:" << supervisorUID << std::endl;
147 void Supervisor::URLDisplayThread(Supervisor *supervisorPtr)
149 INIT_MF(
"Supervisor");
155 std::this_thread::sleep_for (std::chrono::seconds(2));
156 std:: cout << __COUT_HDR_FL__ <<
"\n*********************************************************************" << std::endl;
157 std:: cout << __COUT_HDR_FL__ <<
"\n\n"
158 << supervisorPtr->getApplicationContext()->getContextDescriptor()->getURL()
160 <<
"/urn:xdaq-application:lid="
161 << supervisorPtr->getApplicationDescriptor()->getLocalId() <<
"/"
162 <<
"\n" << std::endl;
163 std:: cout << __COUT_HDR_FL__ <<
"\n*********************************************************************" << std::endl;
172 void Supervisor::makeSystemLogbookEntry(std::string entryText)
174 __MOUT__ <<
"Making System Logbook Entry: " << entryText << std::endl;
177 if(!theSupervisorDescriptorInfo_.getLogbookDescriptor())
179 __MOUT__ <<
"Just kidding... Logbook Descriptor not found." << std:: endl;
185 std::string replace[] =
186 {
"\"",
"'",
"&",
"<",
">",
"\n",
" "};
188 {
"%22",
"%27",
"%26",
"%3C",
"%3E",
"%0A%0D",
"%20%20"};
193 for(
int i=0;i<numOfKeys;++i)
195 while((f=entryText.find(replace[i])) != std::string::npos)
197 entryText = entryText.substr(0,f) + with[i] + entryText.substr(f+replace[i].length());
208 xoap::MessageReference retMsg = SOAPMessenger::sendWithSOAPReply(theSupervisorDescriptorInfo_.getLogbookDescriptor(),
"MakeSystemLogbookEntry",parameters);
213 receive(retMsg, retParameters);
215 __MOUT__ <<
"Returned Status: " << retParameters.getValue(
"Status") << std::endl;
220 void Supervisor::Default(xgi::Input* in, xgi::Output* out)
221 throw (xgi::exception::Exception)
224 if (!supervisorGuiHasBeenLoaded_ && (supervisorGuiHasBeenLoaded_ =
true))
225 makeSystemLogbookEntry(
"ots started.");
228 "<!DOCTYPE HTML><html lang='en'><head><title>ots</title></head>" <<
229 "<frameset col='100%' row='100%'>" <<
230 "<frame src='/WebPath/html/Supervisor.html?urn=" <<
231 this->getApplicationDescriptor()->getLocalId() <<
"=securityType=" <<
232 securityType_ <<
"'></frameset></html>";
238 void Supervisor::stateMachineXgiHandler(xgi::Input* in, xgi::Output* out)
239 throw (xgi::exception::Exception)
241 cgicc::Cgicc cgi(in);
243 uint8_t userPermissions;
245 std::string userWithLock;
246 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
247 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions,
248 &uid,
"0", 1, &userWithLock))
255 std::string username =
"";
256 username = theWebUsers_.getUsersUsername(uid);
257 if (userWithLock !=
"" && userWithLock != username)
259 *out << WebUsers::REQ_USER_LOCKOUT_RESPONSE;
260 __MOUT__ <<
"User " << username <<
" is locked out. " << userWithLock <<
" has lock." << std::endl;
266 std::string command = CgiDataUtilities::getData(cgi,
"StateMachine");
267 std::string fsmName = CgiDataUtilities::getData(cgi,
"fsmName");
268 std::string fsmWindowName = CgiDataUtilities::getData(cgi,
"fsmWindowName");
269 fsmWindowName = CgiDataUtilities::decodeURIComponent(fsmWindowName);
270 std::string currentState = theStateMachine_.getCurrentStateName();
272 __MOUT__ <<
"fsmName = " << fsmName << std::endl;
273 __MOUT__ <<
"fsmWindowName = " << fsmWindowName << std::endl;
274 __MOUT__ <<
"activeStateMachineName_ = " << activeStateMachineName_ << std::endl;
277 if (theStateMachine_.isInTransition())
279 __SS__ <<
"Error - Can not accept request since State Machine is already in transition!" << std::endl;
280 __MOUT_ERR__ <<
"\n" << ss.str();
282 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"0");
283 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
285 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
295 if(activeStateMachineName_ !=
"" &&
296 activeStateMachineName_ != fsmName)
298 __MOUT__ <<
"currentState = " <<
299 currentState << std::endl;
300 if(currentState !=
"Halted" &&
301 currentState !=
"Initial")
305 __SS__ <<
"Error - Can not accept request since State Machine " <<
306 "with window name '" <<
307 activeStateMachineWindowName_ <<
"' (UID: " <<
308 activeStateMachineName_ <<
") "
310 "in control of State Machine progress. ";
311 ss <<
"\n\nIn order for this State Machine with window name '" <<
312 fsmWindowName <<
"' (UID: " << fsmName <<
") "
313 "to control progress, please transition to Halted using the active " <<
314 "State Machine '" << activeStateMachineWindowName_ <<
".'" << std::endl;
315 __MOUT_ERR__ <<
"\n" << ss.str();
317 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"0");
318 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
320 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
325 activeStateMachineName_ =
"";
326 activeStateMachineWindowName_ =
"";
334 if (command ==
"Configure")
336 if(currentState !=
"Halted")
338 __SS__ <<
"Error - Can only transition to Configured if the current " <<
339 "state is Halted. Perhaps your state machine is out of sync." <<
341 __MOUT_ERR__ <<
"\n" << ss.str();
343 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"0");
344 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
346 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
352 parameters.addParameter(
"ConfigurationAlias",
353 CgiDataUtilities::postData(cgi,
"ConfigurationAlias"));
355 std::string configurationAlias = parameters.getValue(
"ConfigurationAlias");
356 __MOUT__ <<
"Configure --> Name: ConfigurationAlias Value: " <<
357 configurationAlias << std::endl;
360 std::string fn = FSM_LAST_GROUP_ALIAS_PATH + FSM_LAST_GROUP_ALIAS_FILE_START +
361 username +
"." + FSM_USERS_PREFERENCES_FILETYPE;
363 __MOUT__ <<
"Save FSM preferences: " << fn << std::endl;
364 FILE *fp = fopen(fn.c_str(),
"w");
366 throw std::runtime_error(
"Could not open file: " + fn);
367 fprintf(fp,
"FSM_last_configuration_alias %s",configurationAlias.c_str());
370 activeStateMachineName_ = fsmName;
371 activeStateMachineWindowName_ = fsmWindowName;
373 else if (command ==
"Start")
375 if(currentState !=
"Configured")
377 __SS__ <<
"Error - Can only transition to Configured if the current " <<
378 "state is Halted. Perhaps your state machine is out of sync. " <<
379 "(Likely the server was restarted or another user changed the state)" <<
381 __MOUT_ERR__ <<
"\n" << ss.str();
383 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"0");
384 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
386 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
390 unsigned int runNumber = getNextRunNumber();
391 parameters.addParameter(
"RunNumber", runNumber);
392 setNextRunNumber(++runNumber);
395 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(
396 command, parameters);
398 xoap::MessageReference reply = stateMachineXoapHandler(message);
402 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"1");
403 xmldoc.outputXmlDocument((std::ostringstream*) out,
false);
404 __MOUT__ <<
"Done - Xgi Request!" << std::endl;
408 void Supervisor::stateMachineResultXgiHandler(xgi::Input* in, xgi::Output* out)
409 throw (xgi::exception::Exception)
411 cgicc::Cgicc cgi(in);
412 __MOUT__ <<
"Xgi Request!" << std::endl;
414 uint8_t userPermissions;
415 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
416 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode,
425 std::string command = CgiDataUtilities::getData(cgi,
"StateMachine");
446 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(
447 CgiDataUtilities::getData(cgi,
"StateMachine"), parameters);
449 xoap::MessageReference reply = stateMachineResultXoapHandler(message);
453 __MOUT__ <<
"Done - Xgi Request!" << std::endl;
457 xoap::MessageReference Supervisor::stateMachineXoapHandler(xoap::MessageReference message)
458 throw (xoap::exception::Exception)
460 __MOUT__ <<
"Soap Handler!" << std::endl;
461 stateMachineWorkLoopManager_.removeProcessedRequests();
462 stateMachineWorkLoopManager_.processRequest(message);
463 __MOUT__ <<
"Done - Soap Handler!" << std::endl;
468 xoap::MessageReference Supervisor::stateMachineResultXoapHandler(
469 xoap::MessageReference message)
470 throw (xoap::exception::Exception)
472 __MOUT__ <<
"Soap Handler!" << std::endl;
475 __MOUT__ <<
"Done - Soap Handler!" << std::endl;
480 bool Supervisor::stateMachineThread(toolbox::task::WorkLoop* workLoop)
482 stateMachineSemaphore_.take();
483 __MOUT__ <<
"Re-sending message..." << SOAPUtilities::translate( stateMachineWorkLoopManager_.getMessage(workLoop)).getCommand() << std::endl;
484 std::string reply = send(
485 theSupervisorDescriptorInfo_.getSupervisorDescriptor(),
486 stateMachineWorkLoopManager_.getMessage(workLoop));
487 stateMachineWorkLoopManager_.report(workLoop, reply, 100,
true);
489 __MOUT__ <<
"Done with message" << std::endl;
490 stateMachineSemaphore_.give();
500 void Supervisor::infoRequestHandler(xgi::Input* in, xgi::Output* out)
501 throw (xgi::exception::Exception)
503 __MOUT__ <<
"Starting to Request!" << std::endl;
504 cgicc::Cgicc cgi(in);
509 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
510 uint8_t userPermissions;
511 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions))
524 HttpXmlDocument tmpDoc = infoRequestWorkLoopManager_.processRequest(cgi);
526 xmldoc.copyDataChildren(tmpDoc);
528 xmldoc.outputXmlDocument((std::ostringstream*) out,
false);
532 void Supervisor::infoRequestResultHandler(xgi::Input* in, xgi::Output* out)
533 throw (xgi::exception::Exception)
535 __MOUT__ <<
"Starting ask!" << std::endl;
536 cgicc::Cgicc cgi(in);
541 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
542 uint8_t userPermissions;
543 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions))
552 infoRequestWorkLoopManager_.getRequestResult(cgi, xmldoc);
555 xmldoc.outputXmlDocument((std::ostringstream*) out,
false);
557 __MOUT__ <<
"Done asking!" << std::endl;
561 bool Supervisor::infoRequestThread(toolbox::task::WorkLoop* workLoop)
566 infoRequestSemaphore_.take();
570 for (
unsigned long long i = 0; i < 100000000; i++)
573 vectorTest_.push_back(counterTest_);
576 infoRequestWorkLoopManager_.report(workLoop,
577 "RESULT: This is the best result ever", 50,
false);
578 std::string workLoopName = workLoop->getName();
579 __MOUT__ << workLoopName <<
" test: " << counterTest_
580 <<
" vector size: " << vectorTest_.size() << std::endl;
581 wait(400,
"InfoRequestThread ----- locked");
582 infoRequestSemaphore_.give();
584 wait(200,
"InfoRequestThread");
586 infoRequestSemaphore_.take();
590 for (
unsigned long long i = 0; i < 100000000; i++)
593 vectorTest_.push_back(counterTest_);
596 wait(400,
"InfoRequestThread ----- locked");
597 __MOUT__ << workLoopName <<
" test: " << counterTest_ <<
" vector size: " << vectorTest_.size() << std::endl;
598 infoRequestSemaphore_.give();
601 infoRequestWorkLoopManager_.report(workLoop,
602 theStateMachine_.getCurrentStateName(), 100,
true);
609 void Supervisor::stateInitial(toolbox::fsm::FiniteStateMachine & fsm)
610 throw (toolbox::fsm::exception::Exception)
612 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
618 void Supervisor::statePaused(toolbox::fsm::FiniteStateMachine & fsm)
619 throw (toolbox::fsm::exception::Exception)
621 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
637 void Supervisor::stateRunning(toolbox::fsm::FiniteStateMachine & fsm)
638 throw (toolbox::fsm::exception::Exception)
641 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
657 void Supervisor::stateHalted(toolbox::fsm::FiniteStateMachine& fsm)
658 throw (toolbox::fsm::exception::Exception)
660 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
661 __MOUT__ <<
"Fsm is in transition?" << theStateMachine_.isInTransition() << std::endl;
687 void Supervisor::stateConfigured(toolbox::fsm::FiniteStateMachine & fsm)
688 throw (toolbox::fsm::exception::Exception)
756 void Supervisor::inError(toolbox::fsm::FiniteStateMachine & fsm)
757 throw (toolbox::fsm::exception::Exception)
759 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
764 void Supervisor::enteringError(toolbox::Event::Reference e)
765 throw (toolbox::fsm::exception::Exception)
767 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
770 toolbox::fsm::FailedEvent& failedEvent =
dynamic_cast<toolbox::fsm::FailedEvent&
> (*e);
771 __SS__ <<
"\nFailure performing transition from " << failedEvent.getFromState() <<
"-" <<
772 theStateMachine_.getStateName(failedEvent.getFromState()) <<
773 " to " << failedEvent.getToState() <<
"-" <<
774 theStateMachine_.getStateName(failedEvent.getToState()) <<
775 ".\n\nException:\n" << failedEvent.getException().what();
776 __MOUT_ERR__ <<
"\n" << ss.str();
778 theStateMachine_.setErrorMessage(ss.str());
791 void Supervisor::getSupervisorsStatus(
void)
792 throw (toolbox::fsm::exception::Exception)
794 theSupervisorsInfo_.getSupervisorInfo().setStatus(
795 theStateMachine_.getCurrentStateName());
799 SupervisorDescriptors::const_iterator it =
800 theSupervisorDescriptorInfo_.getFEDescriptors().begin();
801 for (; it != theSupervisorDescriptorInfo_.getFEDescriptors().end();
806 std::string state = send(it->second,
807 "StateMachineStateRequest");
809 theSupervisorsInfo_.getFESupervisorInfo(it->first).setStatus(
812 __MOUT__ <<
"PixelFESupervisor instance " << it->first <<
" is in FSM state " << state << std::endl;
813 __MOUT__ <<
"Look! Here's a FEW! @@@" << std::endl;
815 catch (xdaq::exception::Exception& e)
838 for (
auto& it : theSupervisorDescriptorInfo_.getARTDAQFEDataManagerDescriptors())
842 std::string state = send(it.second,
843 "StateMachineStateRequest");
844 theSupervisorsInfo_.getARTDAQFEDataManagerSupervisorInfo(it.first).setStatus(
846 __MOUT__ <<
"PixelFERSupervisor instance " << it.first <<
" is in FSM state " << state << std::endl;
847 __MOUT__ <<
"Look! Here's a FER! @@@" << std::endl;
849 catch (xdaq::exception::Exception& e)
854 for (
auto& it : theSupervisorDescriptorInfo_.getARTDAQDataManagerDescriptors())
858 std::string state = send(it.second,
859 "StateMachineStateRequest");
860 theSupervisorsInfo_.getARTDAQDataManagerSupervisorInfo(it.first).setStatus(
862 __MOUT__ <<
"PixelFERSupervisor instance " << it.first <<
" is in FSM state " << state << std::endl;
863 __MOUT__ <<
"Look! Here's a FER! @@@" << std::endl;
865 catch (xdaq::exception::Exception& e)
871 catch (xdaq::exception::Exception& e)
874 <<
"No PixelFESupervisor found in the \"daq\" group in the Configuration XML file."
882 void Supervisor::transitionConfiguring(toolbox::Event::Reference e)
883 throw (toolbox::fsm::exception::Exception)
887 theProgressBar_.step();
889 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
891 std::string systemAlias = SOAPUtilities::translate(
892 theStateMachine_.getCurrentMessage()).getParameters().getValue(
"ConfigurationAlias");
894 __MOUT__ <<
"Transition parameter: " << systemAlias << std::endl;
896 theProgressBar_.step();
901 theConfigurationManager_->init();
905 __SS__ <<
"\nTransition to Configuring interrupted! " <<
906 "The Configuration Manager could not be initialized." << std::endl;
908 __MOUT_ERR__ <<
"\n" << ss.str();
909 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
913 theProgressBar_.step();
918 theConfigurationGroup_ = theConfigurationManager_->getConfigurationGroupFromAlias(systemAlias);
922 __MOUT_INFO__ <<
"Exception occurred" << std::endl;
925 theProgressBar_.step();
927 if(theConfigurationGroup_.second.isInvalid())
929 __SS__ <<
"\nTransition to Configuring interrupted! System Alias " <<
930 systemAlias <<
" could not be translated to a group name and key." << std::endl;
932 __MOUT_ERR__ <<
"\n" << ss.str();
933 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
937 theProgressBar_.step();
939 __MOUT__ <<
"Configuration group name: " << theConfigurationGroup_.first <<
" key: " <<
940 theConfigurationGroup_.second << std::endl;
944 std::stringstream ss;
945 ss <<
"Configuring '" << systemAlias <<
"' which translates to " <<
946 theConfigurationGroup_.first <<
" (" << theConfigurationGroup_.second <<
").";
947 makeSystemLogbookEntry(ss.str());
950 theProgressBar_.step();
955 theConfigurationManager_->loadConfigurationGroup(theConfigurationGroup_.first, theConfigurationGroup_.second,
true);
959 tmpCfgMgr.activateConfigurationGroup(theConfigurationGroup_.first, theConfigurationGroup_.second);
963 __SS__ <<
"\nTransition to Configuring interrupted! System Alias " <<
964 systemAlias <<
" was translated to " << theConfigurationGroup_.first <<
965 " (" << theConfigurationGroup_.second <<
") but could not be loaded and initialized." << std::endl;
966 ss <<
"\n\nTo debug this problem, try activating this group in the Configuration GUI " <<
967 " and detailed errors will be shown." << std::endl;
968 __MOUT_ERR__ <<
"\n" << ss.str();
969 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
975 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
976 supervisorContextUID_, supervisorApplicationUID_);
977 if(!configLinkNode.isDisconnected())
981 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration");
982 if(!fsmLinkNode.isDisconnected() &&
983 fsmLinkNode.getNode(activeStateMachineName_ +
984 "/EnableConfigurationDumpOnConfigureTransition").getValue<
bool>())
987 theConfigurationManager_->dumpActiveConfiguration(
988 fsmLinkNode.getNode(activeStateMachineName_ +
989 "/ConfigurationDumpOnConfigureFilePath").getValue<std::string>() +
990 fsmLinkNode.getNode(activeStateMachineName_ +
991 "/ConfigurationDumpOnConfigureFileRadix").getValue<std::string>() +
993 std::to_string(time(0)) +
995 fsmLinkNode.getNode(activeStateMachineName_ +
996 "/ConfigurationDumpOnConfigureFormat").getValue<std::string>()
1000 __MOUT_INFO__ <<
"FSM Link disconnected." << std::endl;
1002 catch(std::runtime_error &e) {
1003 __SS__ <<
"\nTransition to Configuring interrupted! There was an error identified " <<
1004 "during the configuration dump attempt:\n\n " <<
1005 e.what() << std::endl;
1006 __MOUT_ERR__ <<
"\n" << ss.str();
1007 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1011 __SS__ <<
"\nTransition to Configuring interrupted! There was an error identified " <<
1012 "during the configuration dump attempt.\n\n " <<
1014 __MOUT_ERR__ <<
"\n" << ss.str();
1015 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1022 theProgressBar_.step();
1024 parameters.addParameter(
"ConfigurationGroupName", theConfigurationGroup_.first);
1025 parameters.addParameter(
"ConfigurationGroupKey", theConfigurationGroup_.second.toString());
1028 xoap::MessageReference message = theStateMachine_.getCurrentMessage();
1029 SOAPUtilities::addParameters(message,parameters);
1030 broadcastMessage(message);
1031 theProgressBar_.step();
1036 saveGroupNameAndKey(theConfigurationGroup_,FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE);
1038 __MOUT__ <<
"Done" << std::endl;
1039 theProgressBar_.complete();
1043 void Supervisor::transitionHalting(toolbox::Event::Reference e)
1044 throw (toolbox::fsm::exception::Exception)
1046 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1048 makeSystemLogbookEntry(
"Run halting.");
1050 broadcastMessage(theStateMachine_.getCurrentMessage());
1054 void Supervisor::transitionInitializing(toolbox::Event::Reference e)
1055 throw (toolbox::fsm::exception::Exception)
1057 __MOUT__ << theStateMachine_.getCurrentStateName() << std::endl;
1060 getSupervisorsStatus();
1062 if(!broadcastMessage(theStateMachine_.getCurrentMessage()))
1064 __MOUT__ <<
"I can't Initialize the supervisors!" << std::endl;
1067 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1068 __MOUT__ <<
"Fsm current transition: " << theStateMachine_.getCurrentTransitionName(e->type()) << std::endl;
1069 __MOUT__ <<
"Fsm final state: " << theStateMachine_.getTransitionFinalStateName(e->type()) << std::endl;
1073 void Supervisor::transitionPausing(toolbox::Event::Reference e)
1074 throw (toolbox::fsm::exception::Exception)
1076 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1078 makeSystemLogbookEntry(
"Run pausing.");
1080 broadcastMessage(theStateMachine_.getCurrentMessage());
1084 void Supervisor::transitionResuming(toolbox::Event::Reference e)
1085 throw (toolbox::fsm::exception::Exception)
1087 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1089 makeSystemLogbookEntry(
"Run resuming.");
1091 broadcastMessage(theStateMachine_.getCurrentMessage());
1095 void Supervisor::transitionStarting(toolbox::Event::Reference e)
1096 throw (toolbox::fsm::exception::Exception)
1098 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1101 receive(theStateMachine_.getCurrentMessage(), parameters);
1103 std::string runNumber = parameters.getValue(
"RunNumber");
1104 __MOUT__ << runNumber << std::endl;
1108 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
1109 supervisorContextUID_, supervisorApplicationUID_);
1110 if(!configLinkNode.isDisconnected())
1114 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration");
1115 if(!fsmLinkNode.isDisconnected() &&
1116 fsmLinkNode.getNode(activeStateMachineName_ +
1117 "/EnableConfigurationDumpOnRunTransition").getValue<
bool>())
1120 theConfigurationManager_->dumpActiveConfiguration(
1121 fsmLinkNode.getNode(activeStateMachineName_ +
1122 "/ConfigurationDumpOnRunFilePath").getValue<std::string>() +
1123 fsmLinkNode.getNode(activeStateMachineName_ +
1124 "/ConfigurationDumpOnRunFileRadix").getValue<std::string>() +
1128 fsmLinkNode.getNode(activeStateMachineName_ +
1129 "/ConfigurationDumpOnRunFormat").getValue<std::string>()
1133 __MOUT_INFO__ <<
"FSM Link disconnected." << std::endl;
1135 catch(std::runtime_error &e) {
1136 __SS__ <<
"\nTransition to Configuring interrupted! There was an error identified " <<
1137 "during the configuration dump attempt:\n\n " <<
1138 e.what() << std::endl;
1139 __MOUT_ERR__ <<
"\n" << ss.str();
1140 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1144 __SS__ <<
"\nTransition to Configuring interrupted! There was an error identified " <<
1145 "during the configuration dump attempt.\n\n " <<
1147 __MOUT_ERR__ <<
"\n" << ss.str();
1148 XCEPT_RAISE (toolbox::fsm::exception::Exception, ss.str());
1156 makeSystemLogbookEntry(
"Run " + runNumber +
" starting.");
1158 broadcastMessage(theStateMachine_.getCurrentMessage());
1161 saveGroupNameAndKey(theConfigurationGroup_,FSM_LAST_STARTED_GROUP_ALIAS_FILE);
1165 void Supervisor::transitionStopping(toolbox::Event::Reference e)
1166 throw (toolbox::fsm::exception::Exception)
1168 __MOUT__ <<
"Fsm current state: " << theStateMachine_.getCurrentStateName() << std::endl;
1170 makeSystemLogbookEntry(
"Run stopping.");
1172 broadcastMessage(theStateMachine_.getCurrentMessage());
1180 bool Supervisor::broadcastMessage(xoap::MessageReference message)
1182 std::string command = SOAPUtilities::translate(message).getCommand();
1183 bool proceed =
true;
1185 for(
auto& it: theSupervisorDescriptorInfo_.getFEDescriptors())
1187 RunControlStateMachine::theProgressBar_.step();
1188 __MOUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1189 __MOUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1190 __MOUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1191 __MOUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1192 __MOUT__ <<
"Sending message to FESupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1193 std::string reply = send(it.second, message);
1194 if (reply != command +
"Done")
1197 std::stringstream error;
1198 error <<
"Can't " << command <<
" FESupervisor, instance = " << it.first;
1199 XCEPT_RAISE(xdaq::exception::Exception, error.str());
1200 __MOUT__ << error.str() << std::endl;
1205 __MOUT__ <<
"FESupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1209 for(
auto& it: theSupervisorDescriptorInfo_.getDataManagerDescriptors())
1211 RunControlStateMachine::theProgressBar_.step();
1212 __MOUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1213 __MOUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1214 __MOUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1215 __MOUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1216 __MOUT__ <<
"Sending message to DataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1217 std::string reply = send(it.second, message);
1218 if (reply != command +
"Done")
1221 std::stringstream error;
1222 error <<
"Can't " << command <<
" DataManagerSupervisor, instance = " << it.first;
1223 XCEPT_RAISE(xdaq::exception::Exception, error.str());
1224 __MOUT__ << error.str() << std::endl;
1228 __MOUT__ <<
"DataManagerSupervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1232 for (
auto& it: theSupervisorDescriptorInfo_.getFEDataManagerDescriptors())
1234 RunControlStateMachine::theProgressBar_.step();
1235 __MOUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1236 __MOUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1237 __MOUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1238 __MOUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1239 __MOUT__ <<
"Sending message to FEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1240 std::string reply = send(it.second, message);
1241 if (reply != command +
"Done")
1244 std::stringstream error;
1245 error <<
"Can't " << command <<
" FEDataManagerSupervisor, instance = " << it.first;
1246 XCEPT_RAISE(xdaq::exception::Exception, error.str());
1247 __MOUT__ << error.str() << std::endl;
1251 __MOUT__ <<
"FEDataManagerSupervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1255 for(
auto& it: theSupervisorDescriptorInfo_.getVisualDescriptors())
1257 RunControlStateMachine::theProgressBar_.step();
1258 __MOUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1259 __MOUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1260 __MOUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1261 __MOUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1262 __MOUT__ <<
"Sending message to VisualSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1263 std::string reply = send(it.second, message);
1264 if (reply != command +
"Done")
1267 std::stringstream error;
1268 error <<
"Can't " << command
1269 <<
" VisualSupervisor, instance = " << it.first;
1270 XCEPT_RAISE(xdaq::exception::Exception, error.str());
1271 __MOUT__ << error.str() << std::endl;
1275 __MOUT__ <<
"VisualSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1280 bool artdaqRestarted =
false;
1281 bool artdaqWasRestarted =
false;
1283 RunControlStateMachine::theProgressBar_.step();
1284 if(command ==
"Halt" || command ==
"Initialize")
1291 FILE *fp = fopen((std::string(getenv(
"SERVICE_DATA_PATH")) +
1292 "/StartOTS_action.cmd").c_str(),
"w");
1295 fprintf(fp,
"RESET_MPI");
1300 artdaqRestarted =
true;
1303 message = SOAPUtilities::makeSOAPMessageReference(
1304 "Initialize", parameters);
1305 command = SOAPUtilities::translate(message).getCommand();
1306 __MOUT__ <<
"command now is " << command << std::endl;
1308 RunControlStateMachine::theProgressBar_.step();
1311 int MAX_ARTDAQ_RESTARTS = 10;
1312 int ARTDAQ_RESTART_DELAY = 2;
1313 int artdaqRestartCount = 0;
1314 bool preArtdaqProceed = proceed;
1317 if(artdaqWasRestarted)
1319 ++artdaqRestartCount;
1320 proceed = preArtdaqProceed;
1321 if(artdaqRestartCount < MAX_ARTDAQ_RESTARTS)
1322 artdaqWasRestarted =
false;
1323 for(
int i=0;i<ARTDAQ_RESTART_DELAY;++i)
1326 __MOUT__ <<
"Waiting on artdaq reboot... " << i <<
" for " << artdaqRestartCount <<
"x" << std::endl;
1330 for(
auto& it: theSupervisorDescriptorInfo_.getARTDAQFEDataManagerDescriptors())
1332 RunControlStateMachine::theProgressBar_.step();
1333 __MOUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1334 __MOUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1335 __MOUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1336 __MOUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1337 __MOUT__ <<
"Sending message to ARTDAQFEDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1341 std::string reply = send(it.second, message);
1342 if (reply != command +
"Done")
1345 std::stringstream error;
1346 error <<
"Can't " << command <<
" ARTDAQFEDataManagerSupervisor, instance = " << it.first;
1347 XCEPT_RAISE(xdaq::exception::Exception, error.str());
1348 __MOUT__ << error.str() << std::endl;
1353 __MOUT__ <<
"ARTDAQFEDataManagerSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1356 catch(xdaq::exception::Exception &e)
1358 if(artdaqRestarted && !artdaqWasRestarted)
1360 artdaqWasRestarted =
true;
1405 for(
auto& it: theSupervisorDescriptorInfo_.getARTDAQDataManagerDescriptors())
1407 RunControlStateMachine::theProgressBar_.step();
1408 __MOUT__ <<
"Sending message to ARTDAQDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1409 __MOUT__ <<
"Sending message to ARTDAQDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1410 __MOUT__ <<
"Sending message to ARTDAQDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1411 __MOUT__ <<
"Sending message to ARTDAQDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1412 __MOUT__ <<
"Sending message to ARTDAQDataManagerSupervisors: " << it.second->getLocalId() <<
" : " << command << std::endl;
1415 std::string reply = send(it.second, message);
1416 if (reply != command +
"Done")
1419 std::stringstream error;
1420 error <<
"Can't " << command <<
" ARTDAQDataManagerSupervisors, instance = " << it.first;
1421 XCEPT_RAISE(xdaq::exception::Exception, error.str());
1422 __MOUT__ << error.str() << std::endl;
1427 __MOUT__ <<
"ARTDAQDataManagerSupervisors supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1430 catch(xdaq::exception::Exception &e)
1432 if(artdaqRestarted && !artdaqWasRestarted)
1434 artdaqWasRestarted =
true;
1441 for(
auto& it: theSupervisorDescriptorInfo_.getARTDAQBuilderDescriptors())
1443 RunControlStateMachine::theProgressBar_.step();
1444 __MOUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1445 __MOUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1446 __MOUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1447 __MOUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1448 __MOUT__ <<
"Sending message to ARTDAQBuilderSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1452 std::string reply = send(it.second, message);
1453 if (reply != command +
"Done")
1456 std::stringstream error;
1457 error <<
"Can't " << command <<
" ARTDAQBuilderSupervisor, instance = " << it.first;
1458 XCEPT_RAISE(xdaq::exception::Exception, error.str());
1459 __MOUT__ << error.str() << std::endl;
1464 __MOUT__ <<
"ARTDAQBuilderSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1467 catch(xdaq::exception::Exception &e)
1469 if(artdaqRestarted && !artdaqWasRestarted)
1471 artdaqWasRestarted =
true;
1479 for(
auto& it: theSupervisorDescriptorInfo_.getARTDAQAggregatorDescriptors())
1481 RunControlStateMachine::theProgressBar_.step();
1482 __MOUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1483 __MOUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1484 __MOUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1485 __MOUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1486 __MOUT__ <<
"Sending message to ARTDAQAggregatorSupervisor: " << it.second->getLocalId() <<
" : " << command << std::endl;
1490 std::string reply = send(it.second, message);
1491 if (reply != command +
"Done")
1494 std::stringstream error;
1495 error <<
"Can't " << command <<
" ARTDAQAggregatorSupervisor, instance = " << it.first;
1496 XCEPT_RAISE(xdaq::exception::Exception, error.str());
1497 __MOUT__ << error.str() << std::endl;
1502 __MOUT__ <<
"ARTDAQAggregatorSupervisor supervisor " << (it.first) <<
" was " << command <<
"'d correctly!" << std::endl;
1505 catch(xdaq::exception::Exception &e)
1507 if(artdaqRestarted && !artdaqWasRestarted)
1509 artdaqWasRestarted =
true;
1547 void Supervisor::wait(
int milliseconds, std::string who)
const
1549 for (
int s = 1; s <= milliseconds; s++)
1554 __MOUT__ << s <<
" msecs " << who << std::endl;
1563 void Supervisor::loginRequest(xgi::Input * in, xgi::Output * out)
1564 throw (xgi::exception::Exception)
1566 cgicc::Cgicc cgi(in);
1567 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
1569 __MOUT__ << Command << std::endl;
1578 std::vector<std::string> loggedOutUsernames;
1579 theWebUsers_.cleanupExpiredEntries(&loggedOutUsernames);
1580 for (
unsigned int i = 0; i < loggedOutUsernames.size(); ++i)
1581 makeSystemLogbookEntry(loggedOutUsernames[i] +
" login timed out.");
1583 if (Command ==
"sessionId")
1590 std::string uuid = CgiDataUtilities::postData(cgi,
"uuid");
1592 std::string sid = theWebUsers_.createNewLoginSession(uuid);
1594 __MOUT__ <<
"uuid = " << uuid << std::endl;
1595 __MOUT__ <<
"SessionId = " << sid.substr(0, 10) << std::endl;
1598 else if (Command ==
"checkCookie")
1602 std::string jumbledUser;
1603 std::string cookieCode;
1613 uuid = CgiDataUtilities::postData(cgi,
"uuid");
1614 jumbledUser = CgiDataUtilities::postData(cgi,
"ju");
1615 cookieCode = CgiDataUtilities::postData(cgi,
"cc");
1617 __MOUT__ <<
"Cookie Code = " << cookieCode.substr(0, 10) << std::endl;
1618 __MOUT__ <<
"jumbledUser = " << jumbledUser.substr(0, 10) << std::endl;
1619 __MOUT__ <<
"uuid = " << uuid << std::endl;
1622 uid = theWebUsers_.isCookieCodeActiveForLogin(uuid, cookieCode,
1625 if (uid == theWebUsers_.NOT_FOUND_IN_DATABASE)
1627 __MOUT__ <<
"cookieCode invalid" << std::endl;
1635 theWebUsers_.insertSettingsForUser(uid, &xmldoc);
1637 xmldoc.outputXmlDocument((std::ostringstream*) out);
1640 else if (Command ==
"login")
1651 std::string uuid = CgiDataUtilities::postData(cgi,
"uuid");
1652 std::string newAccountCode = CgiDataUtilities::postData(cgi,
"nac");
1653 std::string jumbledUser = CgiDataUtilities::postData(cgi,
"ju");
1654 std::string jumbledPw = CgiDataUtilities::postData(cgi,
"jp");
1656 __MOUT__ <<
"jumbledUser = " << jumbledUser.substr(0, 10) << std::endl;
1657 __MOUT__ <<
"jumbledPw = " << jumbledPw.substr(0, 10) << std::endl;
1658 __MOUT__ <<
"uuid = " << uuid << std::endl;
1659 __MOUT__ <<
"nac =-" << newAccountCode <<
"-" << std::endl;
1661 uint64_t uid = theWebUsers_.attemptActiveSession(uuid, jumbledUser,
1662 jumbledPw, newAccountCode);
1665 if (uid == theWebUsers_.NOT_FOUND_IN_DATABASE)
1667 __MOUT__ <<
"cookieCode invalid" << std::endl;
1669 if (newAccountCode !=
"1")
1670 newAccountCode =
"0";
1673 __MOUT__ <<
"new cookieCode = " << newAccountCode.substr(0, 10) << std::endl;
1677 theWebUsers_.insertSettingsForUser(uid, &xmldoc);
1681 if (uid != theWebUsers_.NOT_FOUND_IN_DATABASE)
1683 uint64_t asCnt = theWebUsers_.getActiveSessionCountForUser(uid) - 1;
1685 sprintf(asStr,
"%lu", asCnt);
1686 xmldoc.addTextElementToData(
"user_active_session_count", asStr);
1689 xmldoc.outputXmlDocument((std::ostringstream*) out);
1692 makeSystemLogbookEntry(
1693 theWebUsers_.getUsersUsername(uid) +
" logged in.");
1695 else if (Command ==
"logout")
1697 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
1698 std::string logoutOthers = CgiDataUtilities::postData(cgi,
1701 __MOUT__ <<
"Cookie Code = " << cookieCode.substr(0, 10) << std::endl;
1702 __MOUT__ <<
"logoutOthers = " << logoutOthers << std::endl;
1705 if (theWebUsers_.cookieCodeLogout(cookieCode, logoutOthers ==
"1", &uid)
1706 != theWebUsers_.NOT_FOUND_IN_DATABASE)
1710 if (!theWebUsers_.isUserIdActive(uid))
1711 makeSystemLogbookEntry(
1712 theWebUsers_.getUsersUsername(uid) +
" logged out.");
1717 __MOUT__ << __LINE__ <<
"\tInvalid Command" << std::endl;
1723 void Supervisor::tooltipRequest(xgi::Input * in, xgi::Output * out)
1724 throw (xgi::exception::Exception)
1726 cgicc::Cgicc cgi(in);
1728 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
1729 __MOUT__ << Command << std::endl;
1735 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
1736 uint8_t userPermissions;
1739 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions,
1750 if(Command ==
"check")
1752 WebUsers::tooltipCheckForUsername(
1753 theWebUsers_.getUsersUsername(uid),
1755 CgiDataUtilities::getData(cgi,
"srcFile"),
1756 CgiDataUtilities::getData(cgi,
"srcFunc"),
1757 CgiDataUtilities::getData(cgi,
"srcId"));
1759 else if(Command ==
"setNeverShow")
1761 WebUsers::tooltipSetNeverShowForUsername(
1762 theWebUsers_.getUsersUsername(uid),
1764 CgiDataUtilities::getData(cgi,
"srcFile"),
1765 CgiDataUtilities::getData(cgi,
"srcFunc"),
1766 CgiDataUtilities::getData(cgi,
"srcId"),
1767 CgiDataUtilities::getData(cgi,
"doNeverShow") ==
"1"?
true:
false,
1768 CgiDataUtilities::getData(cgi,
"temporarySilence") ==
"1"?
true:
false);
1772 __MOUT__ <<
"Command Request, " << Command <<
", not recognized." << std::endl;
1774 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
1778 void Supervisor::request(xgi::Input * in, xgi::Output * out)
1779 throw (xgi::exception::Exception)
1781 cgicc::Cgicc cgi(in);
1783 std::string Command = CgiDataUtilities::getData(cgi,
"RequestType");
1790 std::string cookieCode = CgiDataUtilities::postData(cgi,
"CookieCode");
1791 uint8_t userPermissions;
1793 std::string userWithLock;
1795 if (!theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions,
1796 &uid,
"0", Command !=
"getSystemMessages", &userWithLock))
1823 if (Command ==
"getSettings")
1825 std::string accounts = CgiDataUtilities::getData(cgi,
"accounts");
1827 __MOUT__ <<
"Get Settings Request" << std::endl;
1828 __MOUT__ <<
"accounts = " << accounts << std::endl;
1829 theWebUsers_.insertSettingsForUser(uid, &xmldoc, accounts ==
"1");
1831 else if (Command ==
"setSettings")
1833 std::string bgcolor = CgiDataUtilities::postData(cgi,
"bgcolor");
1834 std::string dbcolor = CgiDataUtilities::postData(cgi,
"dbcolor");
1835 std::string wincolor = CgiDataUtilities::postData(cgi,
"wincolor");
1836 std::string layout = CgiDataUtilities::postData(cgi,
"layout");
1837 std::string syslayout = CgiDataUtilities::postData(cgi,
"syslayout");
1839 __MOUT__ <<
"Set Settings Request" << std::endl;
1840 __MOUT__ <<
"bgcolor = " << bgcolor << std::endl;
1841 __MOUT__ <<
"dbcolor = " << dbcolor << std::endl;
1842 __MOUT__ <<
"wincolor = " << wincolor << std::endl;
1843 __MOUT__ <<
"layout = " << layout << std::endl;
1844 __MOUT__ <<
"syslayout = " << syslayout << std::endl;
1845 theWebUsers_.changeSettingsForUser(uid, bgcolor, dbcolor, wincolor,
1847 theWebUsers_.insertSettingsForUser(uid, &xmldoc,
true);
1849 else if (Command ==
"accountSettings")
1851 std::string type = CgiDataUtilities::postData(cgi,
"type");
1854 if (type ==
"updateAccount")
1856 else if (type ==
"createAccount")
1858 else if (type ==
"deleteAccount")
1861 std::string username = CgiDataUtilities::postData(cgi,
"username");
1862 std::string displayname = CgiDataUtilities::postData(cgi,
1864 std::string permissions = CgiDataUtilities::postData(cgi,
1866 std::string accounts = CgiDataUtilities::getData(cgi,
"accounts");
1868 __MOUT__ <<
"accountSettings Request" << std::endl;
1869 __MOUT__ <<
"type = " << type <<
" - " << type_int << std::endl;
1870 __MOUT__ <<
"username = " << username << std::endl;
1871 __MOUT__ <<
"displayname = " << displayname << std::endl;
1872 __MOUT__ <<
"permissions = " << permissions << std::endl;
1874 theWebUsers_.modifyAccountSettings(uid, type_int, username, displayname,
1877 __MOUT__ <<
"accounts = " << accounts << std::endl;
1879 theWebUsers_.insertSettingsForUser(uid, &xmldoc, accounts ==
"1");
1881 else if(Command ==
"stateMatchinePreferences")
1883 std::string set = CgiDataUtilities::getData(cgi,
"set");
1884 const std::string DEFAULT_FSM_VIEW =
"Default_FSM_View";
1886 theWebUsers_.setGenericPreference(uid, DEFAULT_FSM_VIEW,
1887 CgiDataUtilities::getData(cgi, DEFAULT_FSM_VIEW));
1889 theWebUsers_.getGenericPreference(uid, DEFAULT_FSM_VIEW, &xmldoc);
1891 else if(Command ==
"getAliasList")
1893 std::string username = theWebUsers_.getUsersUsername(uid);
1894 std::string fsmName = CgiDataUtilities::getData(cgi,
"fsmName");
1895 __MOUT__ <<
"fsmName = " << fsmName << std::endl;
1897 std::string stateMachineAliasFilter =
"*";
1899 std::map<std::string ,
1901 theConfigurationManager_->getGroupAliasesConfiguration();
1905 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
1906 supervisorContextUID_, supervisorApplicationUID_);
1908 if(!configLinkNode.isDisconnected())
1912 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration");
1913 if(!fsmLinkNode.isDisconnected())
1914 stateMachineAliasFilter =
1915 fsmLinkNode.getNode(fsmName +
"/SystemAliasFilter").getValue<std::string>();
1917 __MOUT_INFO__ <<
"FSM Link disconnected." << std::endl;
1919 catch(std::runtime_error &e) { __MOUT_INFO__ << e.what() << std::endl; }
1920 catch(...) { __MOUT_ERR__ <<
"Unknown error. Should never happen." << std::endl; }
1923 __MOUT_INFO__ <<
"FSM Link disconnected." << std::endl;
1925 __MOUT__ <<
"stateMachineAliasFilter = " << stateMachineAliasFilter << std::endl;
1932 bool invertFilter = stateMachineAliasFilter.size() && stateMachineAliasFilter[0] ==
'!';
1933 std::vector<std::string> filterArr;
1936 if(invertFilter) ++i;
1939 while((f = stateMachineAliasFilter.find(
'*',i)) != std::string::npos)
1941 tmp = stateMachineAliasFilter.substr(i,f-i);
1943 filterArr.push_back(tmp);
1948 if(i <= stateMachineAliasFilter.size())
1950 tmp = stateMachineAliasFilter.substr(i);
1951 filterArr.push_back(tmp);
1959 for(
auto& aliasMapPair : aliasMap)
1965 if(filterArr.size() == 1)
1967 if(filterArr[0] !=
"" &&
1968 filterArr[0] !=
"*" &&
1969 aliasMapPair.first != filterArr[0])
1970 filterMatch =
false;
1975 for(f=0;f<filterArr.size();++f)
1977 if(!filterArr[f].size())
continue;
1981 if((i = aliasMapPair.first.find(filterArr[f])) != 0)
1983 filterMatch =
false;
1987 else if(f == filterArr.size()-1)
1989 if(aliasMapPair.first.rfind(filterArr[f]) !=
1990 aliasMapPair.first.size() - filterArr[f].size())
1992 filterMatch =
false;
1996 else if((i = aliasMapPair.first.find(filterArr[f])) ==
1999 filterMatch =
false;
2005 if(invertFilter) filterMatch = !filterMatch;
2009 if(!filterMatch)
continue;
2011 xmldoc.addTextElementToData(
"config_alias", aliasMapPair.first);
2012 xmldoc.addTextElementToData(
"config_key",
2013 ConfigurationGroupKey::getFullGroupString(aliasMapPair.second.first,
2014 aliasMapPair.second.second).c_str());
2019 std::string fn = FSM_LAST_GROUP_ALIAS_PATH + FSM_LAST_GROUP_ALIAS_FILE_START +
2020 username +
"." + FSM_USERS_PREFERENCES_FILETYPE;
2021 __MOUT__ <<
"Load preferences: " << fn << std::endl;
2022 FILE *fp = fopen(fn.c_str(),
"r");
2025 char tmpLastAlias[500];
2026 fscanf(fp,
"%*s %s",tmpLastAlias);
2027 __MOUT__ <<
"tmpLastAlias: " << tmpLastAlias << std::endl;
2029 xmldoc.addTextElementToData(
"UserLastConfigAlias",tmpLastAlias);
2033 else if (Command ==
"getFecList")
2035 xmldoc.addTextElementToData(
"fec_list",
"");
2037 for (
unsigned int i = 0; i< theSupervisorDescriptorInfo_.getFEDescriptors().size(); ++i)
2039 xmldoc.addTextElementToParent(
"fec_url",
2040 theSupervisorDescriptorInfo_.getFEURL(i),
"fec_list");
2041 xmldoc.addTextElementToParent(
2043 theSupervisorDescriptorInfo_.getFEDescriptor(i)->getURN(),
2047 else if (Command ==
"getSystemMessages")
2049 xmldoc.addTextElementToData(
"systemMessages",
2050 theSysMessenger_.getSysMsg(
2051 theWebUsers_.getUsersDisplayName(uid)));
2053 xmldoc.addTextElementToData(
"username_with_lock",
2054 theWebUsers_.getUserWithLock());
2058 else if (Command ==
"setUserWithLock")
2060 std::string username = CgiDataUtilities::postData(cgi,
"username");
2061 std::string lock = CgiDataUtilities::postData(cgi,
"lock");
2062 std::string accounts = CgiDataUtilities::getData(cgi,
"accounts");
2064 __MOUT__ << Command << std::endl;
2065 __MOUT__ <<
"username " << username << std::endl;
2066 __MOUT__ <<
"lock " << lock << std::endl;
2067 __MOUT__ <<
"accounts " << accounts << std::endl;
2068 __MOUT__ <<
"uid " << uid << std::endl;
2070 std::string tmpUserWithLock = theWebUsers_.getUserWithLock();
2071 if(!theWebUsers_.setUserWithLock(uid, lock ==
"1", username))
2072 xmldoc.addTextElementToData(
"server_alert",
2073 std::string(
"Set user lock action failed. You must have valid permissions and ") +
2074 "locking user must be currently logged in.");
2076 theWebUsers_.insertSettingsForUser(uid, &xmldoc, accounts ==
"1");
2078 if (tmpUserWithLock != theWebUsers_.getUserWithLock())
2079 theSysMessenger_.addSysMsg(
"*", theWebUsers_.getUserWithLock()
2080 ==
"" ? tmpUserWithLock +
" has unlocked ots."
2081 : theWebUsers_.getUserWithLock()
2082 +
" has locked ots.");
2084 else if (Command ==
"getStateMachine")
2087 std::vector<toolbox::fsm::State> states;
2088 states = theStateMachine_.getStates();
2091 std::string transName;
2092 std::string transParameter;
2093 for (
unsigned int i = 0; i < states.size(); ++i)
2095 stateStr[0] = states[i];
2096 DOMElement* stateParent = xmldoc.addTextElementToData(
"state", stateStr);
2098 xmldoc.addTextElementToParent(
"state_name", theStateMachine_.getStateName(states[i]), stateParent);
2103 std::map<std::string, toolbox::fsm::State, std::less<std::string> >
2104 trans = theStateMachine_.getTransitions(states[i]);
2105 std::set<std::string> actionNames = theStateMachine_.getInputs(states[i]);
2107 std::map<std::string, toolbox::fsm::State, std::less<std::string> >::iterator
2109 std::set<std::string>::iterator ait = actionNames.begin();
2110 for (; it != trans.end() && ait != actionNames.end(); ++it, ++ait)
2114 stateStr[0] = it->second;
2115 xmldoc.addTextElementToParent(
"state_transition", stateStr, stateParent);
2119 xmldoc.addTextElementToParent(
"state_transition_action", *ait, stateParent);
2121 transName = theStateMachine_.getTransitionName(states[i], *ait);
2124 xmldoc.addTextElementToParent(
"state_transition_name",
2125 transName, stateParent);
2126 transParameter = theStateMachine_.getTransitionParameter(states[i], *ait);
2129 xmldoc.addTextElementToParent(
"state_transition_parameter", transParameter, stateParent);
2134 else if (Command ==
"getCurrentState")
2136 xmldoc.addTextElementToData(
"current_state", theStateMachine_.getCurrentStateName());
2137 xmldoc.addTextElementToData(
"in_transition", theStateMachine_.isInTransition() ?
"1" :
"0");
2138 if (theStateMachine_.isInTransition())
2139 xmldoc.addTextElementToData(
"transition_progress", theProgressBar_.readPercentageString());
2141 xmldoc.addTextElementToData(
"transition_progress",
"100");
2145 sprintf(tmp,
"%lu",theStateMachine_.getTimeInState());
2146 xmldoc.addTextElementToData(
"time_in_state", tmp);
2154 std::string fsmName = CgiDataUtilities::getData(cgi,
"fsmName");
2162 if(!theStateMachine_.isInTransition())
2164 std::string stateMachineRunAlias =
"Run";
2167 ConfigurationTree configLinkNode = theConfigurationManager_->getSupervisorConfigurationNode(
2168 supervisorContextUID_, supervisorApplicationUID_);
2170 if(!configLinkNode.isDisconnected())
2174 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration");
2175 if(!fsmLinkNode.isDisconnected())
2176 stateMachineRunAlias =
2177 fsmLinkNode.getNode(fsmName +
"/RunDisplayAlias").getValue<std::string>();
2181 catch(std::runtime_error &e) { __MOUT_INFO__ << e.what() << std::endl; }
2182 catch(...) { __MOUT_ERR__ <<
"Unknown error. Should never happen." << std::endl; }
2189 xmldoc.addTextElementToData(
"stateMachineRunAlias", stateMachineRunAlias);
2194 if(theStateMachine_.getCurrentStateName() ==
"Running" ||
2195 theStateMachine_.getCurrentStateName() ==
"Paused")
2196 sprintf(tmp,
"Current %s Number: %u",stateMachineRunAlias.c_str(),getNextRunNumber(activeStateMachineName_)-1);
2198 sprintf(tmp,
"Next %s Number: %u",stateMachineRunAlias.c_str(),getNextRunNumber(fsmName));
2199 xmldoc.addTextElementToData(
"run_number", tmp);
2202 else if(Command ==
"getErrorInStateMatchine")
2204 xmldoc.addTextElementToData(
"FSM_Error", theStateMachine_.getErrorMessage());
2206 else if(Command ==
"getDesktopIcons")
2209 std::string iconFileName = ICON_FILE_NAME;
2210 std::ifstream iconFile;
2211 std::string iconList =
"";
2213 iconFile.open(iconFileName.c_str());
2217 __MOUT__ <<
"Error opening file: "<< iconFileName << std::endl;
2221 if(iconFile.is_open())
2223 __MOUT__ <<
"Opened File: " << iconFileName << std::endl;
2224 while(std::getline(iconFile, line))
2228 __MOUT__ << iconList << std::endl;
2233 xmldoc.addTextElementToData(
"iconList", iconList);
2236 else if(Command ==
"launchConfig")
2238 if(userPermissions != 255)
2240 __MOUT__ <<
"Insufficient Permissions" << std::endl;
2244 __MOUT__ <<
"Self-destruct." << std::endl;
2249 else if(Command ==
"resetUserTooltips")
2251 WebUsers::resetAllUserTooltips(theWebUsers_.getUsersUsername(uid));
2254 __MOUT__ <<
"Command Request, " << Command <<
", not recognized." << std::endl;
2259 xmldoc.outputXmlDocument((std::ostringstream*) out,
false,
true);
2267 xoap::MessageReference Supervisor::supervisorGetUserInfo(
2268 xoap::MessageReference message)
2269 throw (xoap::exception::Exception)
2272 parameters.addParameter(
"CookieCode");
2273 receive(message, parameters);
2274 std::string cookieCode = parameters.getValue(
"CookieCode");
2276 std::string username, displayName;
2277 uint64_t activeSessionIndex;
2279 theWebUsers_.getUserInfoForCookie(cookieCode, &username, &displayName,
2280 &activeSessionIndex);
2287 retParameters.addParameter(
"Username", username);
2288 retParameters.addParameter(
"DisplayName", displayName);
2290 sprintf(tmpStr,
"%lu", activeSessionIndex);
2291 retParameters.addParameter(
"ActiveSessionIndex", tmpStr);
2293 return SOAPUtilities::makeSOAPMessageReference(
"UserInfoResponse",
2300 xoap::MessageReference Supervisor::supervisorCookieCheck(xoap::MessageReference message)
2301 throw (xoap::exception::Exception)
2307 parameters.addParameter(
"CookieCode");
2308 parameters.addParameter(
"RefreshOption");
2309 receive(message, parameters);
2310 std::string cookieCode = parameters.getValue(
"CookieCode");
2311 std::string refreshOption = parameters.getValue(
"RefreshOption");
2315 uint8_t userPermissions = 0;
2316 std::string userWithLock =
"";
2317 theWebUsers_.cookieCodeIsActiveForRequest(cookieCode, &userPermissions, 0,
2318 "0", refreshOption ==
"1", &userWithLock);
2324 retParameters.addParameter(
"CookieCode", cookieCode);
2326 sprintf(tmp,
"%d", userPermissions);
2327 retParameters.addParameter(
"Permissions", tmp);
2328 retParameters.addParameter(
"UserWithLock", userWithLock);
2332 return SOAPUtilities::makeSOAPMessageReference(
"CookieResponse",
2339 xoap::MessageReference Supervisor::supervisorGetActiveUsers(
2340 xoap::MessageReference message)
2341 throw (xoap::exception::Exception)
2343 __MOUT__ << std::endl;
2346 parameters(
"UserList", theWebUsers_.getActiveUsersString());
2347 return SOAPUtilities::makeSOAPMessageReference(
"ActiveUserResponse",
2355 xoap::MessageReference Supervisor::supervisorSystemMessage(
2356 xoap::MessageReference message)
2357 throw (xoap::exception::Exception)
2360 parameters.addParameter(
"ToUser");
2361 parameters.addParameter(
"Message");
2362 receive(message, parameters);
2364 __MOUT__ <<
"toUser: " << parameters.getValue(
"ToUser").substr(
2365 0, 10) <<
", message: " << parameters.getValue(
"Message").substr(0,
2368 theSysMessenger_.addSysMsg(parameters.getValue(
"ToUser"),
2369 parameters.getValue(
"Message"));
2370 return SOAPUtilities::makeSOAPMessageReference(
"SystemMessageResponse");
2377 xoap::MessageReference Supervisor::supervisorSystemLogbookEntry(
2378 xoap::MessageReference message)
2379 throw (xoap::exception::Exception)
2382 parameters.addParameter(
"EntryText");
2383 receive(message, parameters);
2385 __MOUT__ <<
"EntryText: " << parameters.getValue(
"EntryText").substr(
2386 0, 10) << std::endl;
2388 makeSystemLogbookEntry(parameters.getValue(
"EntryText"));
2390 return SOAPUtilities::makeSOAPMessageReference(
"SystemLogbookResponse");
2398 xoap::MessageReference Supervisor::supervisorLastConfigGroupRequest(
2399 xoap::MessageReference message)
2400 throw (xoap::exception::Exception)
2403 parameters.addParameter(
"ActionOfLastGroup");
2404 receive(message, parameters);
2406 return Supervisor::lastConfigGroupRequestHandler(parameters);
2415 xoap::MessageReference Supervisor::lastConfigGroupRequestHandler(
2418 std::string action = parameters.getValue(
"ActionOfLastGroup");
2419 __MOUT__ <<
"ActionOfLastGroup: " << action.substr(
2420 0, 10) << std::endl;
2422 std::string fileName =
"";
2423 if(action ==
"Configured")
2424 fileName = FSM_LAST_CONFIGURED_GROUP_ALIAS_FILE;
2425 else if(action ==
"Started")
2426 fileName = FSM_LAST_STARTED_GROUP_ALIAS_FILE;
2429 __MOUT_ERR__ <<
"Invalid last group action requested." << std::endl;
2430 return SOAPUtilities::makeSOAPMessageReference(
"LastConfigGroupResponseFailure");
2432 std::string timeString;
2434 loadGroupNameAndKey(fileName,timeString);
2438 retParameters.addParameter(
"GroupName", theGroup.first);
2439 retParameters.addParameter(
"GroupKey", theGroup.second.toString());
2440 retParameters.addParameter(
"GroupAction", action);
2441 retParameters.addParameter(
"GroupActionTime", timeString);
2444 return SOAPUtilities::makeSOAPMessageReference(
"LastConfigGroupResponse",
2455 unsigned int Supervisor::getNextRunNumber(
const std::string &fsmNameIn)
2457 std::string runNumberFileName = RUN_NUMBER_PATH +
"/";
2458 std::string fsmName = fsmNameIn ==
""?activeStateMachineName_:fsmNameIn;
2460 for(
unsigned int i=0;i<fsmName.size();++i)
2461 if( (fsmName[i] >=
'a' && fsmName[i] <=
'z') ||
2462 (fsmName[i] >=
'A' && fsmName[i] <=
'Z') ||
2463 (fsmName[i] >=
'0' && fsmName[i] <=
'9'))
2464 runNumberFileName += fsmName[i];
2465 runNumberFileName += RUN_NUMBER_FILE_NAME;
2468 std::ifstream runNumberFile(runNumberFileName.c_str());
2469 if (!runNumberFile.is_open())
2471 __MOUT__ <<
"Can't open file: " << runNumberFileName << std::endl;
2473 __MOUT__ <<
"Creating file and setting Run Number to 1: " << runNumberFileName << std::endl;
2474 FILE *fp = fopen(runNumberFileName.c_str(),
"w");
2478 runNumberFile.open(runNumberFileName.c_str());
2479 if(!runNumberFile.is_open())
2481 __MOUT__ <<
"Can't create file: " << runNumberFileName << std::endl;
2482 throw std::runtime_error(
"Error.");
2485 std::string runNumberString;
2486 runNumberFile >> runNumberString;
2487 runNumberFile.close();
2488 return atoi(runNumberString.c_str());
2492 bool Supervisor::setNextRunNumber(
unsigned int runNumber,
const std::string &fsmNameIn)
2494 std::string runNumberFileName = RUN_NUMBER_PATH +
"/";
2495 std::string fsmName = fsmNameIn ==
""?activeStateMachineName_:fsmNameIn;
2497 for(
unsigned int i=0;i<fsmName.size();++i)
2498 if( (fsmName[i] >=
'a' && fsmName[i] <=
'z') ||
2499 (fsmName[i] >=
'A' && fsmName[i] <=
'Z') ||
2500 (fsmName[i] >=
'0' && fsmName[i] <=
'9'))
2501 runNumberFileName += fsmName[i];
2502 runNumberFileName += RUN_NUMBER_FILE_NAME;
2503 __MOUT__ <<
"runNumberFileName: " << runNumberFileName << std::endl;
2505 std::ofstream runNumberFile(runNumberFileName.c_str());
2506 if (!runNumberFile.is_open())
2508 __MOUT__ <<
"Can't open file: " << runNumberFileName << std::endl;
2509 throw std::runtime_error(
"Error.");
2511 std::stringstream runNumberStream;
2512 runNumberStream << runNumber;
2513 runNumberFile << runNumberStream.str().c_str();
2514 runNumberFile.close();
2524 std::pair<std::string ,
2526 std::string &returnedTimeString)
2528 std::string fullPath = FSM_LAST_GROUP_ALIAS_PATH +
"/" + fileName;
2530 FILE *groupFile = fopen(fullPath.c_str(),
"r");
2533 __MOUT__ <<
"Can't open file: " << fullPath << std::endl;
2535 __MOUT__ <<
"Returning empty groupName and key -1" << std::endl;
2537 return std::pair<std::string ,
2543 std::pair<std::string ,
2546 fgets(line,500,groupFile);
2547 theGroup.first = line;
2549 fgets(line,500,groupFile);
2551 sscanf(line,
"%d",&key);
2552 theGroup.second = key;
2554 fgets(line,500,groupFile);
2556 sscanf(line,
"%ld",×tamp);
2558 ::localtime_r(×tamp, &tmstruct);
2559 ::strftime(line, 30,
"%c %Z", &tmstruct);
2560 returnedTimeString = line;
2564 __MOUT__ <<
"theGroup.first= " << theGroup.first <<
2565 " theGroup.second= " << theGroup.second << std::endl;
2571 void Supervisor::saveGroupNameAndKey(
const std::pair<std::string ,
2573 const std::string &fileName)
2575 std::string fullPath = FSM_LAST_GROUP_ALIAS_PATH +
"/" + fileName;
2577 std::ofstream groupFile(fullPath.c_str());
2578 if (!groupFile.is_open())
2580 __SS__ <<
"Can't open file: " << fullPath << std::endl;
2581 __MOUT_ERR__ <<
"\n" << ss.str();
2582 throw std::runtime_error(
"Error.\n" + ss.str());
2584 std::stringstream outss;
2585 outss << theGroup.first <<
"\n" << theGroup.second <<
"\n" << time(0);
2586 groupFile << outss.str().c_str();