1 #include "otsdaq/GatewaySupervisor/Iterator.h"
2 #include "otsdaq/CoreSupervisors/CoreSupervisorBase.h"
3 #include "otsdaq/GatewaySupervisor/GatewaySupervisor.h"
4 #include "otsdaq/Macros/CoutMacros.h"
5 #include "otsdaq/MessageFacility/MessageFacility.h"
6 #include "otsdaq/WebUsersUtilities/WebUsers.h"
12 #define __MF_SUBJECT__ "Iterator"
16 #define ITERATOR_PLAN_HISTORY_FILENAME \
17 ((getenv("SERVICE_DATA_PATH") == NULL) \
18 ? (std::string(__ENV__("USER_DATA")) + "/ServiceData") \
19 : (std::string(__ENV__("SERVICE_DATA_PATH")))) + \
20 "/IteratorPlanHistory.hist"
22 const std::string Iterator::RESERVED_GEN_PLAN_NAME =
"---GENERATED_PLAN---";
26 : workloopRunning_(false)
27 , activePlanIsRunning_(false)
28 , iteratorBusy_(false)
30 , commandPause_(false)
33 , activeCommandIndex_(-1)
34 , activeCommandStartTime_(0)
35 , theSupervisor_(supervisor)
37 __COUT__ <<
"Iterator constructed." << __E__;
40 __COUT__ <<
"Filename for iterator history: " << ITERATOR_PLAN_HISTORY_FILENAME
42 FILE* fp = fopen((ITERATOR_PLAN_HISTORY_FILENAME).c_str(),
"r");
47 while(fgets(line, 100, fp))
51 line[strlen(line) - 1] =
'\0';
54 lastStartedPlanName_ = line;
57 lastFinishedPlanName_ = line;
63 __COUTV__(lastStartedPlanName_);
64 __COUTV__(lastFinishedPlanName_);
69 Iterator::~Iterator(
void) {}
72 void Iterator::IteratorWorkLoop(
Iterator* iterator)
75 __COUT__ <<
"Iterator work loop starting..." << __E__;
81 if(iterator->theSupervisor_->VERBOSE_MUTEX)
82 __COUT__ <<
"Waiting for iterator access" << __E__;
83 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
84 if(iterator->theSupervisor_->VERBOSE_MUTEX)
85 __COUT__ <<
"Have iterator access" << __E__;
87 iterator->errorMessage_ =
"";
91 WebUsers::DEFAULT_ITERATOR_USERNAME);
93 theConfigurationManager.getAllTableInfo(
true ,
100 __COUT__ <<
"Iterator work loop starting..." << __E__;
101 IteratorWorkLoopStruct theIteratorStruct(iterator, &theConfigurationManager);
102 __COUT__ <<
"Iterator work loop starting..." << __E__;
106 std::vector<IterateTable::Command> commands;
130 if(iterator->theSupervisor_->VERBOSE_MUTEX)
131 __COUT__ <<
"Waiting for iterator access" << __E__;
132 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
133 if(iterator->theSupervisor_->VERBOSE_MUTEX)
134 __COUT__ <<
"Have iterator access" << __E__;
136 if(iterator->commandPlay_)
138 iterator->commandPlay_ =
false;
140 if(!iterator->activePlanIsRunning_)
144 iterator->activePlanIsRunning_ =
true;
145 iterator->iteratorBusy_ =
true;
147 if(theIteratorStruct.activePlan_ != iterator->activePlanName_)
149 __COUT__ <<
"New plan name encountered old="
150 << theIteratorStruct.activePlan_
151 <<
" vs new=" << iterator->activePlanName_ << __E__;
152 theIteratorStruct.commandIndex_ = -1;
155 theIteratorStruct.activePlan_ = iterator->activePlanName_;
156 iterator->lastStartedPlanName_ = iterator->activePlanName_;
157 FILE* fp = fopen((ITERATOR_PLAN_HISTORY_FILENAME).c_str(),
"w");
160 fprintf(fp,
"%s\n", iterator->lastStartedPlanName_.c_str());
161 fprintf(fp,
"%s\n", iterator->lastFinishedPlanName_.c_str());
165 __COUT_WARN__ <<
"Could not open Iterator history file: "
166 << ITERATOR_PLAN_HISTORY_FILENAME << __E__;
168 if(theIteratorStruct.commandIndex_ == (
unsigned int)-1)
170 __COUT__ <<
"Starting plan '" << theIteratorStruct.activePlan_
172 __COUT__ <<
"Starting plan '" << theIteratorStruct.activePlan_
177 theIteratorStruct.doResumeAction_ =
true;
178 __COUT__ <<
"Continuing plan '"
179 << theIteratorStruct.activePlan_
180 <<
"' at command index "
181 << theIteratorStruct.commandIndex_ <<
". " << __E__;
182 __COUT__ <<
"Continuing plan '"
183 << theIteratorStruct.activePlan_
184 <<
"' at command index "
185 << theIteratorStruct.commandIndex_ <<
". " << __E__;
189 else if(iterator->commandPause_ && !theIteratorStruct.doPauseAction_)
191 theIteratorStruct.doPauseAction_ =
true;
192 iterator->commandPause_ =
false;
194 else if(iterator->commandHalt_ && !theIteratorStruct.doHaltAction_)
196 theIteratorStruct.doHaltAction_ =
true;
197 iterator->commandHalt_ =
false;
200 theIteratorStruct.running_ = iterator->activePlanIsRunning_;
203 ->activeCommandIndex_ !=
204 theIteratorStruct.commandIndex_)
206 iterator->activeCommandIndex_ = theIteratorStruct.commandIndex_;
207 if(theIteratorStruct.commandIndex_ <
208 theIteratorStruct.commands_.size())
209 iterator->activeCommandType_ =
210 theIteratorStruct.commands_[theIteratorStruct.commandIndex_]
213 iterator->activeCommandType_ =
"";
214 iterator->activeCommandStartTime_ = time(0);
216 if(theIteratorStruct.commandIndex_ <
217 theIteratorStruct.commandIterations_.size())
218 iterator->activeCommandIteration_ =
220 .commandIterations_[theIteratorStruct.commandIndex_];
222 iterator->activeCommandIteration_ = -1;
224 iterator->depthIterationStack_.clear();
225 for(
const auto& depthIteration : theIteratorStruct.stepIndexStack_)
226 iterator->depthIterationStack_.push_back(depthIteration);
232 iterator->activeNumberOfCommands_ =
233 theIteratorStruct.commands_.size();
242 if(theIteratorStruct.doPauseAction_)
249 __COUT__ <<
"Waiting to pause..." << __E__;
250 while(!iterator->checkCommand(&theIteratorStruct))
251 __COUT__ <<
"Waiting to pause..." << __E__;
253 __COUT__ <<
"Completing pause..." << __E__;
255 theIteratorStruct.doPauseAction_ =
false;
259 if(iterator->theSupervisor_->VERBOSE_MUTEX)
260 __COUT__ <<
"Waiting for iterator access" << __E__;
261 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
262 if(iterator->theSupervisor_->VERBOSE_MUTEX)
263 __COUT__ <<
"Have iterator access" << __E__;
265 iterator->activePlanIsRunning_ =
false;
267 __COUT__ <<
"Paused plan '" << theIteratorStruct.activePlan_
268 <<
"' at command index " << theIteratorStruct.commandIndex_
270 __COUT__ <<
"Paused plan '" << theIteratorStruct.activePlan_
271 <<
"' at command index " << theIteratorStruct.commandIndex_
276 else if(theIteratorStruct.doHaltAction_)
283 __COUT__ <<
"Waiting to halt..." << __E__;
284 while(!iterator->checkCommand(&theIteratorStruct))
285 __COUT__ <<
"Waiting to halt..." << __E__;
287 __COUT__ <<
"Completing halt..." << __E__;
289 theIteratorStruct.doHaltAction_ =
false;
291 iterator->haltIterator(iterator, &theIteratorStruct);
329 if(theIteratorStruct.running_ &&
330 theIteratorStruct.activePlan_ !=
333 if(theIteratorStruct.commandIndex_ == (
unsigned int)-1)
337 __COUT__ <<
"Get commands" << __E__;
339 theIteratorStruct.commandIndex_ = 0;
341 theIteratorStruct.cfgMgr_
344 if(theIteratorStruct.activePlan_ == Iterator::RESERVED_GEN_PLAN_NAME)
346 __COUT__ <<
"Using generated plan..." << __E__;
347 theIteratorStruct.onlyConfigIfNotConfigured_ =
348 iterator->genKeepConfiguration_;
349 theIteratorStruct.commands_ =
350 generateIterationPlan(iterator->genFsmName_,
351 iterator->genConfigAlias_,
352 iterator->genPlanDurationSeconds_,
353 iterator->genPlanNumberOfRuns_);
357 __COUT__ <<
"Getting iterator table..." << __E__;
359 theIteratorStruct.cfgMgr_->__GET_CONFIG__(
IterateTable);
360 theIteratorStruct.onlyConfigIfNotConfigured_ =
false;
361 theIteratorStruct.commands_ = itConfig->getPlanCommands(
362 theIteratorStruct.cfgMgr_, theIteratorStruct.activePlan_);
366 theIteratorStruct.commandIterations_.clear();
367 for(
auto& command : theIteratorStruct.commands_)
369 theIteratorStruct.commandIterations_.push_back(0);
370 __COUT__ <<
"command " << command.type_ << __E__;
372 << IterateTable::commandToTableMap_.at(command.type_)
374 __COUT__ <<
"param count = " << command.params_.size() << __E__;
376 for(
auto& param : command.params_)
378 __COUT__ <<
"\t param " << param.first <<
" : "
379 << param.second << __E__;
383 theIteratorStruct.originalTrackChanges_ =
384 ConfigurationInterface::isVersionTrackingEnabled();
385 theIteratorStruct.originalConfigGroup_ =
386 theIteratorStruct.cfgMgr_->getActiveGroupName();
387 theIteratorStruct.originalConfigKey_ =
388 theIteratorStruct.cfgMgr_->getActiveGroupKey();
390 __COUT__ <<
"originalTrackChanges "
391 << theIteratorStruct.originalTrackChanges_ << __E__;
392 __COUT__ <<
"originalConfigGroup "
393 << theIteratorStruct.originalConfigGroup_ << __E__;
394 __COUT__ <<
"originalConfigKey "
395 << theIteratorStruct.originalConfigKey_ << __E__;
399 if(!theIteratorStruct.commandBusy_)
401 if(theIteratorStruct.commandIndex_ <
402 theIteratorStruct.commands_.size())
405 theIteratorStruct.commandBusy_ =
true;
407 __COUT__ <<
"Iterator starting command "
408 << theIteratorStruct.commandIndex_ + 1 <<
": "
410 .commands_[theIteratorStruct.commandIndex_]
413 __COUT__ <<
"Iterator starting command "
414 << theIteratorStruct.commandIndex_ + 1 <<
": "
416 .commands_[theIteratorStruct.commandIndex_]
420 iterator->startCommand(&theIteratorStruct);
422 else if(theIteratorStruct.commandIndex_ ==
423 theIteratorStruct.commands_.size())
425 __COUT__ <<
"Finished Iteration Plan '"
426 << theIteratorStruct.activePlan_ << __E__;
427 __COUT__ <<
"Finished Iteration Plan '"
428 << theIteratorStruct.activePlan_ << __E__;
430 __COUT__ <<
"Reverting track changes." << __E__;
431 ConfigurationInterface::setVersionTrackingEnabled(
432 theIteratorStruct.originalTrackChanges_);
435 __COUT__ <<
"Activating original group..." << __E__;
438 theIteratorStruct.cfgMgr_->activateTableGroup(
439 theIteratorStruct.originalConfigGroup_,
440 theIteratorStruct.originalConfigKey_);
444 __COUT_WARN__ <<
"Original group could not be activated."
449 __COUT__ <<
"Completing Iteration Plan and cleaning up..."
452 iterator->haltIterator(
453 iterator, &theIteratorStruct,
true );
456 else if(theIteratorStruct.commandBusy_)
459 if(iterator->checkCommand(&theIteratorStruct))
461 theIteratorStruct.commandBusy_ =
false;
463 ++theIteratorStruct.commandIndex_;
465 __COUT__ <<
"Ready for next command. Done with "
466 << theIteratorStruct.commandIndex_ <<
" of "
467 << theIteratorStruct.commands_.size() << __E__;
468 __COUT__ <<
"Iterator ready for next command. Done with "
469 << theIteratorStruct.commandIndex_ <<
" of "
470 << theIteratorStruct.commands_.size() << __E__;
474 if(theIteratorStruct.doResumeAction_)
475 theIteratorStruct.doResumeAction_ =
false;
490 catch(
const std::runtime_error& e)
492 if(theIteratorStruct.activePlan_ !=
"")
494 __SS__ <<
"The active Iterator plan name is '"
495 << theIteratorStruct.activePlan_
496 <<
"'... Here was the error: " << e.what() << __E__;
503 iterator->workloopRunning_ =
false;
505 catch(
const std::runtime_error& e)
507 __SS__ <<
"Encountered error in Iterator thread. Here is the error:\n"
508 << e.what() << __E__;
509 __COUT_ERR__ << ss.str();
513 if(iterator->theSupervisor_->VERBOSE_MUTEX)
514 __COUT__ <<
"Waiting for iterator access" << __E__;
515 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
516 if(iterator->theSupervisor_->VERBOSE_MUTEX)
517 __COUT__ <<
"Have iterator access" << __E__;
519 iterator->workloopRunning_ =
false;
520 iterator->errorMessage_ = ss.str();
524 __SS__ <<
"Encountered unknown error in Iterator thread." << __E__;
529 catch(
const std::exception& e)
531 ss <<
"Exception message: " << e.what();
536 __COUT_ERR__ << ss.str();
540 if(iterator->theSupervisor_->VERBOSE_MUTEX)
541 __COUT__ <<
"Waiting for iterator access" << __E__;
542 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
543 if(iterator->theSupervisor_->VERBOSE_MUTEX)
544 __COUT__ <<
"Have iterator access" << __E__;
546 iterator->workloopRunning_ =
false;
547 iterator->errorMessage_ = ss.str();
551 void Iterator::startCommand(IteratorWorkLoopStruct* iteratorStruct)
556 for(
const auto& depthIteration : iteratorStruct->stepIndexStack_)
558 __COUT__ << i++ <<
":" << depthIteration << __E__;
565 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
566 __COUT__ <<
"Waiting for FSM access" << __E__;
567 std::lock_guard<std::mutex> lock(
568 iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
569 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
570 __COUT__ <<
"Have FSM access" << __E__;
573 if(iteratorStruct->commandIndex_ >= iteratorStruct->commands_.size())
575 __SS__ <<
"Out of range commandIndex = " << iteratorStruct->commandIndex_
576 <<
" in size = " << iteratorStruct->commands_.size() << __E__;
581 ++iteratorStruct->commandIterations_[iteratorStruct->commandIndex_];
583 std::string type = iteratorStruct->commands_[iteratorStruct->commandIndex_].type_;
586 return startCommandBeginLabel(iteratorStruct);
588 else if(type == IterateTable::COMMAND_CHOOSE_FSM)
590 return startCommandChooseFSM(
592 iteratorStruct->commands_[iteratorStruct->commandIndex_]
593 .params_[IterateTable::commandChooseFSMParams_.NameOfFSM_]);
595 else if(type == IterateTable::COMMAND_CONFIGURE_ACTIVE_GROUP)
597 return startCommandConfigureActive(iteratorStruct);
599 else if(type == IterateTable::COMMAND_CONFIGURE_ALIAS)
601 return startCommandConfigureAlias(
603 iteratorStruct->commands_[iteratorStruct->commandIndex_]
604 .params_[IterateTable::commandConfigureAliasParams_.SystemAlias_]);
606 else if(type == IterateTable::COMMAND_CONFIGURE_GROUP)
608 return startCommandConfigureGroup(iteratorStruct);
610 else if(type == IterateTable::COMMAND_ACTIVATE_ALIAS)
613 std::pair<std::string, TableGroupKey> newActiveGroup =
615 iteratorStruct->commands_[iteratorStruct->commandIndex_]
616 .params_[IterateTable::commandActivateAliasParams_.SystemAlias_]);
618 newActiveGroup.first, newActiveGroup.second,
true );
620 else if(type == IterateTable::COMMAND_ACTIVATE_GROUP)
624 iteratorStruct->commands_[iteratorStruct->commandIndex_]
625 .params_[IterateTable::commandActivateGroupParams_.GroupName_],
627 iteratorStruct->commands_[iteratorStruct->commandIndex_]
628 .params_[IterateTable::commandActivateGroupParams_.GroupKey_]),
631 else if(type == IterateTable::COMMAND_EXECUTE_FE_MACRO)
633 return startCommandMacro(iteratorStruct,
true );
635 else if(type == IterateTable::COMMAND_EXECUTE_MACRO)
637 return startCommandMacro(iteratorStruct,
false );
639 else if(type == IterateTable::COMMAND_MODIFY_ACTIVE_GROUP)
641 return startCommandModifyActive(iteratorStruct);
643 else if(type == IterateTable::COMMAND_REPEAT_LABEL)
645 return startCommandRepeatLabel(iteratorStruct);
647 else if(type == IterateTable::COMMAND_RUN)
649 return startCommandRun(iteratorStruct);
651 else if(type == IterateTable::COMMAND_WAIT)
653 return startCommandWait(iteratorStruct);
655 else if(type == IterateTable::COMMAND_START)
657 return startCommandFSMTransition(iteratorStruct,
658 RunControlStateMachine::START_TRANSITION_NAME);
660 else if(type == IterateTable::COMMAND_STOP)
662 return startCommandFSMTransition(iteratorStruct,
663 RunControlStateMachine::STOP_TRANSITION_NAME);
665 else if(type == IterateTable::COMMAND_PAUSE)
667 return startCommandFSMTransition(iteratorStruct,
668 RunControlStateMachine::PAUSE_TRANSITION_NAME);
670 else if(type == IterateTable::COMMAND_RESUME)
672 return startCommandFSMTransition(iteratorStruct,
673 RunControlStateMachine::RESUME_TRANSITION_NAME);
675 else if(type == IterateTable::COMMAND_HALT)
677 return startCommandFSMTransition(iteratorStruct,
678 RunControlStateMachine::HALT_TRANSITION_NAME);
682 __SS__ <<
"Failed attempt to start unrecognized command type = " << type << __E__;
683 __COUT_ERR__ << ss.str();
689 __COUT__ <<
"Error caught. Reverting track changes." << __E__;
690 ConfigurationInterface::setVersionTrackingEnabled(
691 iteratorStruct->originalTrackChanges_);
693 __COUT__ <<
"Activating original group..." << __E__;
696 iteratorStruct->cfgMgr_->activateTableGroup(iteratorStruct->originalConfigGroup_,
697 iteratorStruct->originalConfigKey_);
701 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
710 bool Iterator::checkCommand(IteratorWorkLoopStruct* iteratorStruct)
714 if(iteratorStruct->commandIndex_ >= iteratorStruct->commands_.size())
716 __COUT__ <<
"Out of range commandIndex = " << iteratorStruct->commandIndex_
717 <<
" in size = " << iteratorStruct->commands_.size() << __E__;
721 std::string type = iteratorStruct->commands_[iteratorStruct->commandIndex_].type_;
727 else if(type == IterateTable::COMMAND_CHOOSE_FSM)
732 else if(type == IterateTable::COMMAND_CONFIGURE_ALIAS ||
733 type == IterateTable::COMMAND_CONFIGURE_ACTIVE_GROUP ||
734 type == IterateTable::COMMAND_CONFIGURE_GROUP)
736 return checkCommandConfigure(iteratorStruct);
738 else if(type == IterateTable::COMMAND_ACTIVATE_ALIAS ||
739 type == IterateTable::COMMAND_ACTIVATE_GROUP)
744 else if(type == IterateTable::COMMAND_EXECUTE_FE_MACRO)
746 return checkCommandMacro(iteratorStruct,
true );
748 else if(type == IterateTable::COMMAND_EXECUTE_MACRO)
750 return checkCommandMacro(iteratorStruct,
false );
752 else if(type == IterateTable::COMMAND_MODIFY_ACTIVE_GROUP)
757 else if(type == IterateTable::COMMAND_REPEAT_LABEL)
762 else if(type == IterateTable::COMMAND_RUN)
764 return checkCommandRun(iteratorStruct);
766 else if(type == IterateTable::COMMAND_WAIT)
768 return checkCommandWait(iteratorStruct);
770 else if(type == IterateTable::COMMAND_START)
772 return checkCommandFSMTransition(iteratorStruct,
"Running");
774 else if(type == IterateTable::COMMAND_STOP)
776 return checkCommandFSMTransition(iteratorStruct,
"Configured");
778 else if(type == IterateTable::COMMAND_PAUSE)
780 return checkCommandFSMTransition(iteratorStruct,
"Paused");
782 else if(type == IterateTable::COMMAND_RESUME)
784 return checkCommandFSMTransition(iteratorStruct,
"Running");
786 else if(type == IterateTable::COMMAND_HALT)
788 return checkCommandFSMTransition(iteratorStruct,
789 RunControlStateMachine::HALTED_STATE_NAME);
793 __SS__ <<
"Attempt to check unrecognized command type = " << type << __E__;
794 __COUT_ERR__ << ss.str();
800 __COUT__ <<
"Error caught. Reverting track changes." << __E__;
801 ConfigurationInterface::setVersionTrackingEnabled(
802 iteratorStruct->originalTrackChanges_);
804 __COUT__ <<
"Activating original group..." << __E__;
807 iteratorStruct->cfgMgr_->activateTableGroup(iteratorStruct->originalConfigGroup_,
808 iteratorStruct->originalConfigKey_);
812 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
819 void Iterator::startCommandChooseFSM(IteratorWorkLoopStruct* iteratorStruct,
820 const std::string& fsmName)
822 __COUT__ <<
"fsmName " << fsmName << __E__;
824 iteratorStruct->fsmName_ = fsmName;
825 iteratorStruct->theIterator_->lastFsmName_ = fsmName;
834 iteratorStruct->fsmRunAlias_ =
"Run";
837 ConfigurationTree configLinkNode = iteratorStruct->cfgMgr_->getSupervisorTableNode(
838 iteratorStruct->theIterator_->theSupervisor_->getContextUID(),
839 iteratorStruct->theIterator_->theSupervisor_->getSupervisorUID());
846 configLinkNode.
getNode(
"LinkToStateMachineTable");
848 iteratorStruct->fsmRunAlias_ =
849 fsmLinkNode.
getNode(fsmName +
"/RunDisplayAlias")
852 __COUT_INFO__ <<
"FSM Link disconnected." << __E__;
854 catch(std::runtime_error& e)
858 <<
"No state machine Run alias. Ignoring and assuming alias of '"
859 << iteratorStruct->fsmRunAlias_ <<
".'" << __E__;
863 __COUT_ERR__ <<
"Unknown error. Should never happen." << __E__;
866 <<
"No state machine Run alias. Ignoring and assuming alias of '"
867 << iteratorStruct->fsmRunAlias_ <<
".'" << __E__;
871 __COUT_INFO__ <<
"FSM Link disconnected." << __E__;
873 __COUT__ <<
"fsmRunAlias_ = " << iteratorStruct->fsmRunAlias_ << __E__;
877 iteratorStruct->fsmNextRunNumber_ =
878 iteratorStruct->theIterator_->theSupervisor_->getNextRunNumber(
879 iteratorStruct->fsmName_);
881 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
882 .getCurrentStateName() ==
"Running" ||
883 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
884 .getCurrentStateName() ==
"Paused")
885 --iteratorStruct->fsmNextRunNumber_;
887 __COUT__ <<
"fsmNextRunNumber_ = " << iteratorStruct->fsmNextRunNumber_ << __E__;
892 bool Iterator::haltIterator(
Iterator* iterator,
893 IteratorWorkLoopStruct* iteratorStruct ,
898 const std::string& fsmName = iterator->lastFsmName_;
900 std::vector<std::string> fsmCommandParameters;
901 std::string errorStr =
"";
902 std::string currentState = theSupervisor->theStateMachine_.getCurrentStateName();
904 __COUTV__(currentState);
906 bool haltAttempted =
true;
909 __COUT_INFO__ <<
"Iterator is leaving FSM in current state: " << currentState
910 <<
". If this is undesireable, add a Halt command, for example, to "
911 "the end of your Iteration plan."
913 haltAttempted =
false;
915 else if(currentState == RunControlStateMachine::INITIAL_STATE_NAME ||
916 currentState == RunControlStateMachine::HALTED_STATE_NAME)
918 __COUT__ <<
"Do nothing. Already halted." << __E__;
919 haltAttempted =
false;
921 else if(currentState ==
"Running")
922 errorStr = theSupervisor->attemptStateMachineTransition(
925 RunControlStateMachine::ABORT_TRANSITION_NAME,
927 WebUsers::DEFAULT_ITERATOR_USERNAME ,
928 WebUsers::DEFAULT_ITERATOR_USERNAME,
929 fsmCommandParameters);
931 errorStr = theSupervisor->attemptStateMachineTransition(
934 RunControlStateMachine::HALT_TRANSITION_NAME,
936 WebUsers::DEFAULT_ITERATOR_USERNAME ,
937 WebUsers::DEFAULT_ITERATOR_USERNAME,
938 fsmCommandParameters);
944 __SS__ <<
"Iterator failed to halt because of the following error: "
950 __COUT__ <<
"FSM in transition = "
951 << theSupervisor->theStateMachine_.isInTransition() << __E__;
952 __COUT__ <<
"halting state machine launched." << __E__;
956 __COUT__ <<
"Conducting Iterator cleanup." << __E__;
960 __COUT__ <<
"Reverting track changes." << __E__;
961 ConfigurationInterface::setVersionTrackingEnabled(
962 iteratorStruct->originalTrackChanges_);
966 __COUT__ <<
"Activating original group..." << __E__;
969 iteratorStruct->cfgMgr_->activateTableGroup(
970 iteratorStruct->originalConfigGroup_,
971 iteratorStruct->originalConfigKey_);
975 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
982 if(iterator->theSupervisor_->VERBOSE_MUTEX)
983 __COUT__ <<
"Waiting for iterator access" << __E__;
984 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
985 if(iterator->theSupervisor_->VERBOSE_MUTEX)
986 __COUT__ <<
"Have iterator access" << __E__;
988 iterator->activePlanIsRunning_ =
false;
989 iterator->iteratorBusy_ =
false;
992 iterator->activePlanName_ =
"";
993 iterator->activeCommandIndex_ = -1;
997 __COUT__ <<
"Iterator cleanup complete of plan '" << iteratorStruct->activePlan_
998 <<
"' at command index " << iteratorStruct->commandIndex_ <<
". "
1001 iterator->lastFinishedPlanName_ = iteratorStruct->activePlan_;
1002 FILE* fp = fopen((ITERATOR_PLAN_HISTORY_FILENAME).c_str(),
"w");
1005 fprintf(fp,
"%s\n", iterator->lastStartedPlanName_.c_str());
1006 fprintf(fp,
"%s\n", iterator->lastFinishedPlanName_.c_str());
1010 __COUT_WARN__ <<
"Could not open Iterator history file: "
1011 << ITERATOR_PLAN_HISTORY_FILENAME << __E__;
1013 iteratorStruct->activePlan_ =
"";
1014 iteratorStruct->commandIndex_ = -1;
1017 return haltAttempted;
1021 void Iterator::startCommandBeginLabel(IteratorWorkLoopStruct* iteratorStruct)
1023 __COUT__ <<
"Entering label '"
1024 << iteratorStruct->commands_[iteratorStruct->commandIndex_]
1025 .params_[IterateTable::commandBeginLabelParams_.Label_]
1026 <<
"'..." << std::endl;
1029 iteratorStruct->stepIndexStack_.push_back(0);
1033 void Iterator::startCommandRepeatLabel(IteratorWorkLoopStruct* iteratorStruct)
1037 int numOfRepetitions;
1038 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_]
1039 .params_[IterateTable::commandRepeatLabelParams_.NumberOfRepetitions_]
1043 __COUT__ <<
"numOfRepetitions remaining = " << numOfRepetitions << __E__;
1047 if(numOfRepetitions <= 0)
1050 sprintf(repStr,
"%d", iteratorStruct->stepIndexStack_.back());
1051 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1052 .params_[IterateTable::commandRepeatLabelParams_.NumberOfRepetitions_] =
1056 iteratorStruct->stepIndexStack_.pop_back();
1064 ++(iteratorStruct->stepIndexStack_.back());
1067 for(i = iteratorStruct->commandIndex_; i > 0;
1070 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1071 .params_[IterateTable::commandRepeatLabelParams_.Label_] ==
1072 iteratorStruct->commands_[i]
1073 .params_[IterateTable::commandBeginLabelParams_.Label_])
1076 sprintf(repStr,
"%d", numOfRepetitions);
1077 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1078 .params_[IterateTable::commandRepeatLabelParams_.NumberOfRepetitions_] =
1081 iteratorStruct->commandIndex_ = i;
1082 __COUT__ <<
"Jumping back to commandIndex " << iteratorStruct->commandIndex_ << __E__;
1086 void Iterator::startCommandRun(IteratorWorkLoopStruct* iteratorStruct)
1088 __COUT__ <<
"startCommandRun " << __E__;
1090 iteratorStruct->runIsDone_ =
false;
1091 iteratorStruct->fsmCommandParameters_.clear();
1093 std::string errorStr =
"";
1094 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
1095 ->theStateMachine_.getCurrentStateName();
1099 __COUTTV__(iteratorStruct->theIterator_->genLogEntry_);
1101 if(currentState == RunControlStateMachine::CONFIGURED_STATE_NAME)
1103 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1106 RunControlStateMachine::START_TRANSITION_NAME,
1107 iteratorStruct->fsmName_,
1108 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1109 WebUsers::DEFAULT_ITERATOR_USERNAME,
1110 iteratorStruct->fsmCommandParameters_,
1111 iteratorStruct->activePlan_ == Iterator::RESERVED_GEN_PLAN_NAME
1112 ? iteratorStruct->theIterator_->genLogEntry_
1115 errorStr =
"Can only Run from the Configured state. The current state is " +
1120 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
1125 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_]
1126 .params_[IterateTable::commandRunParams_.DurationInSeconds_]
1129 &iteratorStruct->originalDurationInSeconds_);
1130 __COUTV__(iteratorStruct->originalDurationInSeconds_);
1134 <<
"FSM in transition = "
1135 << iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition()
1137 __COUT__ <<
"startCommandRun success." << __E__;
1141 void Iterator::startCommandWait(IteratorWorkLoopStruct* iteratorStruct)
1143 __COUT__ <<
"startCommandWait " << __E__;
1145 iteratorStruct->waitIsDone_ =
false;
1148 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_]
1149 .params_[IterateTable::commandWaitParams_.DurationInSeconds_]
1152 &iteratorStruct->originalDurationInSeconds_);
1153 __COUTV__(iteratorStruct->originalDurationInSeconds_);
1155 __COUT__ <<
"startCommandWait success." << __E__;
1159 void Iterator::startCommandConfigureActive(IteratorWorkLoopStruct* iteratorStruct)
1161 __COUT__ <<
"startCommandConfigureActive " << __E__;
1167 std::string group = iteratorStruct->cfgMgr_->getActiveGroupName();
1168 TableGroupKey key = iteratorStruct->cfgMgr_->getActiveGroupKey();
1170 __COUT__ <<
"group " << group << __E__;
1171 __COUT__ <<
"key " << key << __E__;
1175 std::stringstream systemAlias;
1176 systemAlias <<
"GROUP:" << group <<
":" << key;
1177 startCommandConfigureAlias(iteratorStruct, systemAlias.str());
1181 void Iterator::startCommandConfigureGroup(IteratorWorkLoopStruct* iteratorStruct)
1183 __COUT__ <<
"startCommandConfigureGroup " << __E__;
1189 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1190 .params_[IterateTable::commandConfigureGroupParams_.GroupName_];
1192 TableGroupKey(iteratorStruct->commands_[iteratorStruct->commandIndex_]
1193 .params_[IterateTable::commandConfigureGroupParams_.GroupKey_]);
1195 __COUT__ <<
"group " << group << __E__;
1196 __COUT__ <<
"key " << key << __E__;
1200 std::stringstream systemAlias;
1201 systemAlias <<
"GROUP:" << group <<
":" << key;
1202 startCommandConfigureAlias(iteratorStruct, systemAlias.str());
1206 void Iterator::startCommandConfigureAlias(IteratorWorkLoopStruct* iteratorStruct,
1207 const std::string& systemAlias)
1209 __COUT__ <<
"systemAlias " << systemAlias << __E__;
1211 iteratorStruct->fsmCommandParameters_.clear();
1212 iteratorStruct->fsmCommandParameters_.push_back(systemAlias);
1214 std::string errorStr =
"";
1215 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
1216 ->theStateMachine_.getCurrentStateName();
1220 if(currentState == RunControlStateMachine::INITIAL_STATE_NAME)
1222 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1225 RunControlStateMachine::INIT_TRANSITION_NAME,
1226 iteratorStruct->fsmName_,
1227 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1228 WebUsers::DEFAULT_ITERATOR_USERNAME,
1229 iteratorStruct->fsmCommandParameters_);
1230 else if(currentState == RunControlStateMachine::HALTED_STATE_NAME)
1232 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1235 RunControlStateMachine::CONFIGURE_TRANSITION_NAME,
1236 iteratorStruct->fsmName_,
1237 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1238 WebUsers::DEFAULT_ITERATOR_USERNAME,
1239 iteratorStruct->fsmCommandParameters_);
1240 else if(currentState == RunControlStateMachine::CONFIGURED_STATE_NAME ||
1241 currentState == RunControlStateMachine::FAILED_STATE_NAME)
1243 if(iteratorStruct->onlyConfigIfNotConfigured_ &&
1244 currentState != RunControlStateMachine::FAILED_STATE_NAME)
1245 __COUT__ <<
"Already configured, so do nothing!" << __E__;
1247 errorStr = iteratorStruct->theIterator_->theSupervisor_
1248 ->attemptStateMachineTransition(
1251 RunControlStateMachine::HALT_TRANSITION_NAME,
1252 iteratorStruct->fsmName_,
1253 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1254 WebUsers::DEFAULT_ITERATOR_USERNAME,
1255 iteratorStruct->fsmCommandParameters_);
1259 "Can only Configure from the Initial or Halted state. The current state is " +
1264 __SS__ <<
"Iterator failed to configure with system alias '"
1265 << (iteratorStruct->fsmCommandParameters_.size()
1266 ? iteratorStruct->fsmCommandParameters_[0]
1268 <<
"' because of the following error: " << errorStr;
1274 <<
"FSM in transition = "
1275 << iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition()
1277 __COUT__ <<
"startCommandConfigureAlias success." << __E__;
1281 void Iterator::startCommandFSMTransition(IteratorWorkLoopStruct* iteratorStruct,
1282 const std::string& transitionCommand)
1284 __COUTV__(transitionCommand);
1286 iteratorStruct->fsmCommandParameters_.clear();
1288 std::string errorStr =
"";
1289 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
1290 ->theStateMachine_.getCurrentStateName();
1294 __COUTV__(currentState);
1297 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1301 iteratorStruct->fsmName_,
1302 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1303 WebUsers::DEFAULT_ITERATOR_USERNAME,
1304 iteratorStruct->fsmCommandParameters_,
1305 (transitionCommand == RunControlStateMachine::START_TRANSITION_NAME &&
1306 iteratorStruct->activePlan_ == Iterator::RESERVED_GEN_PLAN_NAME)
1307 ? iteratorStruct->theIterator_->genLogEntry_
1312 __SS__ <<
"Iterator failed to " << transitionCommand <<
" with ";
1313 if(iteratorStruct->fsmCommandParameters_.size() == 0)
1314 ss <<
"no parameters ";
1316 ss <<
"parameters '"
1319 ss <<
"' because of the following error: " << errorStr;
1325 <<
"FSM in transition = "
1326 << iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition()
1328 __COUT__ <<
"startCommandFSMTransition success." << __E__;
1332 void Iterator::startCommandMacro(IteratorWorkLoopStruct* iteratorStruct,
1333 bool isFrontEndMacro)
1341 const std::string& macroName =
1342 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1343 .params_[IterateTable::commandExecuteMacroParams_.MacroName_];
1344 const std::string& enableSavingOutput =
1345 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1346 .params_[IterateTable::commandExecuteMacroParams_.EnableSavingOutput_];
1347 const std::string& outputFilePath =
1348 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1349 .params_[IterateTable::commandExecuteMacroParams_.OutputFilePath_];
1350 const std::string& outputFileRadix =
1351 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1352 .params_[IterateTable::commandExecuteMacroParams_.OutputFileRadix_];
1353 const std::string& inputArgs =
1354 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1355 .params_[IterateTable::commandExecuteMacroParams_.MacroArgumentString_];
1357 __COUTV__(macroName);
1358 __COUTV__(enableSavingOutput);
1359 __COUTV__(outputFilePath);
1360 __COUTV__(outputFileRadix);
1361 __COUTV__(inputArgs);
1369 iteratorStruct->targetsDone_.clear();
1371 __COUTV__(iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_.size());
1372 for(
const auto& target :
1373 iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_)
1375 __COUT__ <<
"target " << target.table_ <<
":" << target.UID_ << __E__;
1378 iteratorStruct->targetsDone_.push_back(
false);
1380 xoap::MessageReference message =
1381 SOAPUtilities::makeSOAPMessageReference(
"FECommunication");
1384 std::string type = isFrontEndMacro ?
"feMacroMultiDimensionalStart"
1385 :
"macroMultiDimensionalStart";
1386 parameters.addParameter(
"type", type);
1387 parameters.addParameter(
"requester", WebUsers::DEFAULT_ITERATOR_USERNAME);
1388 parameters.addParameter(
"targetInterfaceID", target.UID_);
1389 parameters.addParameter(isFrontEndMacro ?
"feMacroName" :
"macroName", macroName);
1390 parameters.addParameter(
"enableSavingOutput", enableSavingOutput);
1391 parameters.addParameter(
"outputFilePath", outputFilePath);
1392 parameters.addParameter(
"outputFileRadix", outputFileRadix);
1393 parameters.addParameter(
"inputArgs", inputArgs);
1394 SOAPUtilities::addParameters(message, parameters);
1396 __COUT__ <<
"Sending FE communication: " << SOAPUtilities::translate(message)
1399 xoap::MessageReference replyMessage =
1400 iteratorStruct->theIterator_->theSupervisor_
1401 ->SOAPMessenger::sendWithSOAPReply(
1402 iteratorStruct->theIterator_->theSupervisor_->allSupervisorInfo_
1403 .getAllMacroMakerTypeSupervisorInfo()
1405 ->second.getDescriptor(),
1408 __COUT__ <<
"Response received: " << SOAPUtilities::translate(replyMessage)
1412 rxParameters.addParameter(
"Error");
1413 std::string response = SOAPUtilities::receive(replyMessage, rxParameters);
1415 std::string error = rxParameters.getValue(
"Error");
1417 if(response != type +
"Done" || error !=
"")
1420 __SS__ <<
"Error transmitting request to target interface '" << target.UID_
1421 <<
"' from '" << WebUsers::DEFAULT_ITERATOR_USERNAME <<
".' Response '"
1422 << response <<
"' with error: " << error << __E__;
1430 bool Iterator::checkCommandMacro(IteratorWorkLoopStruct* iteratorStruct,
1431 bool isFrontEndMacro)
1441 const std::string& macroName =
1442 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1443 .params_[IterateTable::commandExecuteMacroParams_.MacroName_];
1445 __COUTV__(macroName);
1450 for(
unsigned int i = 0;
1451 i < iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_.size();
1455 iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_[i];
1457 __COUT__ <<
"target " << target.table_ <<
":" << target.UID_ << __E__;
1459 xoap::MessageReference message =
1460 SOAPUtilities::makeSOAPMessageReference(
"FECommunication");
1463 std::string type = isFrontEndMacro ?
"feMacroMultiDimensionalCheck"
1464 :
"macroMultiDimensionalCheck";
1465 parameters.addParameter(
"type", type);
1466 parameters.addParameter(
"requester", WebUsers::DEFAULT_ITERATOR_USERNAME);
1467 parameters.addParameter(
"targetInterfaceID", target.UID_);
1468 parameters.addParameter(isFrontEndMacro ?
"feMacroName" :
"macroName", macroName);
1469 SOAPUtilities::addParameters(message, parameters);
1471 __COUT__ <<
"Sending FE communication: " << SOAPUtilities::translate(message)
1474 xoap::MessageReference replyMessage =
1475 iteratorStruct->theIterator_->theSupervisor_
1476 ->SOAPMessenger::sendWithSOAPReply(
1477 iteratorStruct->theIterator_->theSupervisor_->allSupervisorInfo_
1478 .getAllMacroMakerTypeSupervisorInfo()
1480 ->second.getDescriptor(),
1483 __COUT__ <<
"Response received: " << SOAPUtilities::translate(replyMessage)
1487 rxParameters.addParameter(
"Error");
1488 rxParameters.addParameter(
"Done");
1489 std::string response = SOAPUtilities::receive(replyMessage, rxParameters);
1491 std::string error = rxParameters.getValue(
"Error");
1492 bool done = rxParameters.getValue(
"Done") ==
"1";
1494 if(response != type +
"Done" || error !=
"")
1497 __SS__ <<
"Error transmitting request to target interface '" << target.UID_
1498 <<
"' from '" << WebUsers::DEFAULT_ITERATOR_USERNAME <<
".' Response '"
1499 << response <<
"' with error: " << error << __E__;
1507 iteratorStruct->targetsDone_[i] =
true;
1519 void Iterator::startCommandModifyActive(IteratorWorkLoopStruct* iteratorStruct)
1540 bool doTrackGroupChanges =
false;
1542 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1543 .params_[IterateTable::commandModifyActiveParams_.DoTrackGroupChanges_])
1544 doTrackGroupChanges =
true;
1546 const std::string& startValueStr =
1547 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1548 .params_[IterateTable::commandModifyActiveParams_.FieldStartValue_];
1549 const std::string& stepSizeStr =
1550 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1551 .params_[IterateTable::commandModifyActiveParams_.FieldIterationStepSize_];
1553 const unsigned int stepIndex = iteratorStruct->stepIndexStack_.back();
1555 __COUT__ <<
"doTrackGroupChanges " << (doTrackGroupChanges ?
"yes" :
"no")
1557 __COUTV__(startValueStr);
1558 __COUTV__(stepSizeStr);
1559 __COUTV__(stepIndex);
1561 ConfigurationInterface::setVersionTrackingEnabled(doTrackGroupChanges);
1566 if(((stepSizeStr.size() && stepSizeStr[0] ==
'0') || !stepSizeStr.size()) &&
1570 __COUT__ <<
"Treating start value as string: " << startValueStr << __E__;
1571 helpCommandModifyActive(iteratorStruct, startValueStr, doTrackGroupChanges);
1573 else if(startValueStr.size() && (startValueStr[startValueStr.size() - 1] ==
'f' ||
1574 startValueStr.find(
'.') != std::string::npos))
1577 double startValue = strtod(startValueStr.c_str(), 0);
1578 double stepSize = strtod(stepSizeStr.c_str(), 0);
1580 __COUT__ <<
"startValue " << startValue << std::endl;
1581 __COUT__ <<
"stepSize " << stepSize << std::endl;
1582 __COUT__ <<
"currentValue " << startValue + stepSize * stepIndex << std::endl;
1584 helpCommandModifyActive(
1585 iteratorStruct, startValue + stepSize * stepIndex, doTrackGroupChanges);
1589 long int startValue;
1595 __COUT__ <<
"startValue " << startValue << std::endl;
1596 __COUT__ <<
"stepSize " << stepSize << std::endl;
1597 __COUT__ <<
"currentValue " << startValue + stepSize * stepIndex << std::endl;
1599 helpCommandModifyActive(
1600 iteratorStruct, startValue + stepSize * stepIndex, doTrackGroupChanges);
1614 bool Iterator::checkCommandRun(IteratorWorkLoopStruct* iteratorStruct)
1623 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1624 __COUT__ <<
"Waiting for FSM access" << __E__;
1625 std::lock_guard<std::mutex> lock(
1626 iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
1627 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1628 __COUT__ <<
"Have FSM access" << __E__;
1630 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition())
1633 iteratorStruct->fsmCommandParameters_.clear();
1635 std::string errorStr =
"";
1636 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
1637 ->theStateMachine_.getCurrentStateName();
1641 if(iteratorStruct->doPauseAction_)
1644 __COUT__ <<
"Transitioning FSM to Paused..." << __E__;
1646 if(currentState ==
"Paused")
1649 __COUT__ <<
"Transition to Paused complete." << __E__;
1652 else if(currentState ==
"Running")
1653 errorStr = iteratorStruct->theIterator_->theSupervisor_
1654 ->attemptStateMachineTransition(
1658 iteratorStruct->fsmName_,
1659 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1660 WebUsers::DEFAULT_ITERATOR_USERNAME,
1661 iteratorStruct->fsmCommandParameters_);
1662 else if(currentState ==
"Configured")
1665 __COUT__ <<
"In Configured state. No need to transition to Paused." << __E__;
1669 errorStr =
"Expected to be in Paused. Unexpectedly, the current state is " +
1671 ". Last State Machine error message was as follows: " +
1672 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
1677 __SS__ <<
"Iterator failed to pause because of the following error: "
1683 else if(iteratorStruct->doHaltAction_)
1686 __COUT__ <<
"Transitioning FSM to Halted..." << __E__;
1688 if(currentState == RunControlStateMachine::HALTED_STATE_NAME)
1691 __COUT__ <<
"Transition to Halted complete." << __E__;
1695 RUNNING_STATE_NAME ||
1696 currentState == RunControlStateMachine::PAUSED_STATE_NAME)
1697 errorStr = iteratorStruct->theIterator_->theSupervisor_
1698 ->attemptStateMachineTransition(
1701 RunControlStateMachine::ABORT_TRANSITION_NAME,
1702 iteratorStruct->fsmName_,
1703 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1704 WebUsers::DEFAULT_ITERATOR_USERNAME,
1705 iteratorStruct->fsmCommandParameters_);
1707 CONFIGURED_STATE_NAME)
1708 errorStr = iteratorStruct->theIterator_->theSupervisor_
1709 ->attemptStateMachineTransition(
1712 RunControlStateMachine::HALT_TRANSITION_NAME,
1713 iteratorStruct->fsmName_,
1714 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1715 WebUsers::DEFAULT_ITERATOR_USERNAME,
1716 iteratorStruct->fsmCommandParameters_);
1718 errorStr =
"Expected to be in Halted. Unexpectedly, the current state is " +
1720 ". Last State Machine error message was as follows: " +
1721 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
1726 __SS__ <<
"Iterator failed to halt because of the following error: "
1732 else if(iteratorStruct->doResumeAction_)
1737 __COUT__ <<
"Transitioning FSM to Running..." << __E__;
1739 if(currentState ==
"Paused")
1740 errorStr = iteratorStruct->theIterator_->theSupervisor_
1741 ->attemptStateMachineTransition(
1744 RunControlStateMachine::RESUME_TRANSITION_NAME,
1745 iteratorStruct->fsmName_,
1746 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1747 WebUsers::DEFAULT_ITERATOR_USERNAME,
1748 iteratorStruct->fsmCommandParameters_);
1752 __SS__ <<
"Iterator failed to run because of the following error: "
1762 if(currentState !=
"Running")
1764 if(iteratorStruct->runIsDone_ && currentState ==
"Configured")
1767 __COUT__ <<
"Reached end of run " << iteratorStruct->fsmNextRunNumber_
1772 errorStr =
"Expected to be in Running. Unexpectedly, the current state is " +
1773 currentState +
". Last State Machine error message was as follows: " +
1774 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
1779 bool waitOnRunningThreads =
false;
1780 if(
"True" == iteratorStruct->commands_[iteratorStruct->commandIndex_]
1781 .params_[IterateTable::commandRunParams_.WaitOnRunningThreads_])
1782 waitOnRunningThreads =
true;
1784 time_t remainingDurationInSeconds;
1785 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_]
1786 .params_[IterateTable::commandRunParams_.DurationInSeconds_]
1789 &remainingDurationInSeconds);
1791 __COUT__ <<
"waitOnRunningThreads " << waitOnRunningThreads << __E__;
1792 __COUT__ <<
"remainingDurationInSeconds " << remainingDurationInSeconds << __E__;
1796 if(waitOnRunningThreads)
1800 iteratorStruct->theIterator_->theSupervisor_;
1802 bool allFrontEndsAreDone =
true;
1803 for(
auto& it : theSupervisor->allSupervisorInfo_.getAllFETypeSupervisorInfo())
1807 std::string status = theSupervisor->
send(it.second.getDescriptor(),
1808 "WorkLoopStatusRequest");
1810 __COUT__ <<
"FESupervisor instance " << it.first
1811 <<
" has status = " << status << std::endl;
1813 if(status != CoreSupervisorBase::WORK_LOOP_DONE)
1815 allFrontEndsAreDone =
false;
1819 catch(xdaq::exception::Exception& e)
1821 __SS__ <<
"Could not retrieve status from FESupervisor instance "
1822 << it.first <<
"." << std::endl;
1823 __COUT_WARN__ << ss.str();
1824 errorStr = ss.str();
1829 <<
"Iterator failed to run because of the following error: "
1836 if(allFrontEndsAreDone)
1839 __COUT__ <<
"FE workloops all complete! Stopping run..." << __E__;
1841 errorStr = iteratorStruct->theIterator_->theSupervisor_
1842 ->attemptStateMachineTransition(
1846 iteratorStruct->fsmName_,
1847 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1848 WebUsers::DEFAULT_ITERATOR_USERNAME,
1849 iteratorStruct->fsmCommandParameters_);
1854 <<
"Iterator failed to stop run because of the following error: "
1860 iteratorStruct->runIsDone_ =
true;
1868 if(remainingDurationInSeconds > 1)
1871 if(remainingDurationInSeconds == iteratorStruct->originalDurationInSeconds_)
1873 iteratorStruct->theIterator_->activeCommandStartTime_ =
1875 __COUT__ <<
"Starting run duration of " << remainingDurationInSeconds
1876 <<
" [s] at time = "
1877 << iteratorStruct->theIterator_->activeCommandStartTime_ <<
" "
1879 iteratorStruct->theIterator_->activeCommandStartTime_)
1883 --remainingDurationInSeconds;
1887 sprintf(str,
"%ld", remainingDurationInSeconds);
1888 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1889 .params_[IterateTable::commandRunParams_.DurationInSeconds_] =
1892 else if(remainingDurationInSeconds == 1)
1895 __COUT__ <<
"Time duration reached! Stopping run..." << __E__;
1897 errorStr = iteratorStruct->theIterator_->theSupervisor_
1898 ->attemptStateMachineTransition(
1902 iteratorStruct->fsmName_,
1903 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1904 WebUsers::DEFAULT_ITERATOR_USERNAME,
1905 iteratorStruct->fsmCommandParameters_);
1909 __SS__ <<
"Iterator failed to stop run because of the following error: "
1915 iteratorStruct->runIsDone_ =
true;
1919 sprintf(str,
"%ld", iteratorStruct->originalDurationInSeconds_);
1920 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1921 .params_[IterateTable::commandRunParams_.DurationInSeconds_] =
1929 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
1936 bool Iterator::checkCommandWait(IteratorWorkLoopStruct* iteratorStruct)
1941 long remainingDurationInSeconds;
1942 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_]
1943 .params_[IterateTable::commandWaitParams_.DurationInSeconds_]
1946 &remainingDurationInSeconds);
1948 __COUT__ <<
"Wait remaining time: " << remainingDurationInSeconds <<
" seconds."
1952 if(remainingDurationInSeconds == iteratorStruct->originalDurationInSeconds_)
1954 iteratorStruct->theIterator_->activeCommandStartTime_ = time(0);
1955 __COUT__ <<
"Starting wait duration of " << remainingDurationInSeconds
1956 <<
" [s] at time = "
1957 << iteratorStruct->theIterator_->activeCommandStartTime_ <<
" "
1959 iteratorStruct->theIterator_->activeCommandStartTime_)
1964 if(iteratorStruct->doPauseAction_ || iteratorStruct->doHaltAction_)
1968 sprintf(str,
"%ld", iteratorStruct->originalDurationInSeconds_);
1969 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1970 .params_[IterateTable::commandWaitParams_.DurationInSeconds_] = str;
1976 if(remainingDurationInSeconds <= 1)
1978 __COUT__ <<
"Wait duration complete!" << __E__;
1982 sprintf(str,
"%ld", iteratorStruct->originalDurationInSeconds_);
1983 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1984 .params_[IterateTable::commandWaitParams_.DurationInSeconds_] = str;
1986 iteratorStruct->waitIsDone_ =
true;
1992 --remainingDurationInSeconds;
1996 sprintf(str,
"%ld", remainingDurationInSeconds);
1997 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1998 .params_[IterateTable::commandWaitParams_.DurationInSeconds_] = str;
2006 bool Iterator::checkCommandConfigure(IteratorWorkLoopStruct* iteratorStruct)
2015 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
2016 __COUT__ <<
"Waiting for FSM access" << __E__;
2017 std::lock_guard<std::mutex> lock(
2018 iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
2019 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
2020 __COUT__ <<
"Have FSM access" << __E__;
2022 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition())
2025 std::string errorStr =
"";
2026 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
2027 ->theStateMachine_.getCurrentStateName();
2029 if(currentState == RunControlStateMachine::HALTED_STATE_NAME)
2031 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
2035 iteratorStruct->fsmName_,
2036 WebUsers::DEFAULT_ITERATOR_USERNAME ,
2037 WebUsers::DEFAULT_ITERATOR_USERNAME,
2038 iteratorStruct->fsmCommandParameters_);
2039 else if(currentState != RunControlStateMachine::CONFIGURED_STATE_NAME)
2040 errorStr =
"Expected to be in '" + RunControlStateMachine::CONFIGURED_STATE_NAME +
2041 "' state. Unexpectedly, the current state is " + currentState +
"." +
2042 ". Last State Machine error message was as follows: " +
2043 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
2047 __COUT__ <<
"checkCommandConfigureAlias complete." << __E__;
2050 std::pair<std::string, TableGroupKey> newActiveGroup =
2051 iteratorStruct->cfgMgr_->getTableGroupFromAlias(
2052 iteratorStruct->fsmCommandParameters_[0]);
2053 iteratorStruct->cfgMgr_->loadTableGroup(
2054 newActiveGroup.first, newActiveGroup.second,
true );
2056 __COUT__ <<
"originalTrackChanges " << iteratorStruct->originalTrackChanges_
2058 __COUT__ <<
"originalConfigGroup " << iteratorStruct->originalConfigGroup_
2060 __COUT__ <<
"originalConfigKey " << iteratorStruct->originalConfigKey_ << __E__;
2062 __COUT__ <<
"currentTrackChanges "
2063 << ConfigurationInterface::isVersionTrackingEnabled() << __E__;
2064 __COUT__ <<
"originalConfigGroup "
2065 << iteratorStruct->cfgMgr_->getActiveGroupName() << __E__;
2066 __COUT__ <<
"originalConfigKey " << iteratorStruct->cfgMgr_->getActiveGroupKey()
2074 __SS__ <<
"Iterator failed to configure with system alias '"
2075 << (iteratorStruct->fsmCommandParameters_.size()
2076 ? iteratorStruct->fsmCommandParameters_[0]
2078 <<
"' because of the following error: " << errorStr;
2086 bool Iterator::checkCommandFSMTransition(IteratorWorkLoopStruct* iteratorStruct,
2087 const std::string& finalState)
2089 __COUTV__(finalState);
2098 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
2099 __COUT__ <<
"Waiting for FSM access" << __E__;
2100 std::lock_guard<std::mutex> lock(
2101 iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
2102 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
2103 __COUT__ <<
"Have FSM access" << __E__;
2105 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition())
2108 std::string errorStr =
"";
2109 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
2110 ->theStateMachine_.getCurrentStateName();
2112 if(currentState != finalState)
2113 errorStr =
"Expected to be in " + finalState +
2114 ". Unexpectedly, the current state is " + currentState +
"." +
2115 ". Last State Machine error message was as follows: " +
2116 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
2120 __COUT__ <<
"checkCommandFSMTransition complete." << __E__;
2127 __SS__ <<
"Iterator failed to reach final state '" << finalState
2128 <<
"' because of the following error: " << errorStr;
2136 std::vector<IterateTable::Command> Iterator::generateIterationPlan(
2137 const std::string& fsmName,
2138 const std::string& configAlias,
2139 uint64_t durationSeconds ,
2140 unsigned int numberOfRuns )
2142 std::vector<IterateTable::Command> commands;
2152 if(durationSeconds == (uint64_t)-1)
2154 __COUTV__(durationSeconds);
2155 __COUTV__(numberOfRuns);
2160 commands.back().type_ = IterateTable::COMMAND_CHOOSE_FSM;
2162 commands.back().params_.emplace(
2163 std::pair<std::string /*param name*/, std::string /*param value*/>(
2164 IterateTable::commandChooseFSMParams_.NameOfFSM_, fsmName));
2170 commands.back().type_ = IterateTable::COMMAND_CONFIGURE_ALIAS;
2172 commands.back().params_.emplace(
2173 std::pair<std::string /*param name*/, std::string /*param value*/>(
2174 IterateTable::commandConfigureAliasParams_.SystemAlias_, configAlias));
2177 if(durationSeconds == (uint64_t)-1)
2179 __COUT__ <<
"Open ended run..." << __E__;
2184 commands.back().type_ = IterateTable::COMMAND_START;
2189 __COUT__ <<
"Finite duration run(s)..." << __E__;
2191 if(numberOfRuns > 1)
2193 __COUT__ <<
"Setting up iterator loop for " << numberOfRuns <<
" runs."
2199 commands.back().params_.emplace(
2200 std::pair<std::string /*param name*/, std::string /*param value*/>(
2201 IterateTable::commandBeginLabelParams_.Label_,
"GENERATED_LABEL"));
2207 commands.back().type_ = IterateTable::COMMAND_RUN;
2209 commands.back().params_.emplace(
2210 std::pair<std::string /*param name*/, std::string /*param value*/>(
2211 IterateTable::commandRunParams_.DurationInSeconds_,
2212 std::to_string(durationSeconds)));
2215 if(numberOfRuns > 1)
2218 commands.back().type_ = IterateTable::COMMAND_REPEAT_LABEL;
2220 commands.back().params_.emplace(
2221 std::pair<std::string /*param name*/, std::string /*param value*/>(
2222 IterateTable::commandRepeatLabelParams_.Label_,
"GENERATED_LABEL"));
2223 commands.back().params_.emplace(
2224 std::pair<std::string /*param name*/, std::string /*param value*/>(
2225 IterateTable::commandRepeatLabelParams_.NumberOfRepetitions_,
2226 std::to_string(numberOfRuns -
2232 __COUTV__(commands.size());
2239 const std::string& command,
2240 const std::string& parameter)
2244 if(command ==
"iteratePlay")
2246 playIterationPlan(xmldoc, parameter);
2249 else if(command ==
"iteratePlayGenerated")
2251 playGeneratedIterationPlan(xmldoc, parameter);
2254 else if(command ==
"iteratePause")
2256 pauseIterationPlan(xmldoc);
2259 else if(command ==
"iterateHalt")
2261 haltIterationPlan(xmldoc);
2264 else if(command ==
"getIterationPlanStatus")
2266 if(activePlanName_ ==
"" &&
2270 activePlanName_ = parameter;
2271 __COUTV__(activePlanName_);
2280 if(theSupervisor_->VERBOSE_MUTEX)
2281 __COUT__ <<
"Waiting for iterator access" << __E__;
2282 std::lock_guard<std::mutex> lock(accessMutex_);
2283 if(theSupervisor_->VERBOSE_MUTEX)
2284 __COUT__ <<
"Have iterator access" << __E__;
2288 __SS__ <<
"Error - Can not accept request because the Iterator "
2290 <<
"in control of State Machine progress. ";
2291 __COUT_ERR__ <<
"\n" << ss.str();
2292 __COUT_ERR__ <<
"\n" << ss.str();
2294 xmldoc.addTextElementToData(
"state_tranisition_attempted",
2296 xmldoc.addTextElementToData(
2297 "state_tranisition_attempted_err",
2299 theSupervisor_->theStateMachine_.setErrorMessage(ss.str());
2307 __SS__ <<
"Error caught by Iterator command handling!" << __E__;
2312 catch(
const std::runtime_error& e)
2314 ss <<
"\nHere is the error: " << e.what() << __E__;
2318 ss <<
"Uknown error caught." << __E__;
2321 __COUT_ERR__ <<
"\n" << ss.str();
2323 xmldoc.addTextElementToData(
"state_tranisition_attempted",
2325 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
2327 theSupervisor_->theStateMachine_.setErrorMessage(ss.str());
2332 void Iterator::playIterationPlan(
HttpXmlDocument& xmldoc,
const std::string& planName)
2334 __COUT__ <<
"Attempting to play iteration plan '" << planName <<
".'" << __E__;
2336 if(planName == Iterator::RESERVED_GEN_PLAN_NAME)
2338 __SS__ <<
"Illegal use of reserved iteration plan name '"
2339 << Iterator::RESERVED_GEN_PLAN_NAME <<
"!' Please select a different name."
2344 playIterationPlanPrivate(xmldoc, planName);
2350 const std::string& parametersCSV)
2352 __COUTV__(parametersCSV);
2353 std::vector<std::string> parameters =
2356 if(parameters.size() != 6)
2358 __SS__ <<
"Malformed CSV parameters to playGeneratedIterationPlan(), must be 6 "
2359 "arguments and there were "
2360 << parameters.size() <<
": " << parametersCSV << __E__;
2371 uint64_t durationSeconds;
2372 sscanf(parameters[2].c_str(),
"%lu", &durationSeconds);
2373 unsigned int numberOfRuns;
2374 sscanf(parameters[3].c_str(),
"%u", &numberOfRuns);
2375 unsigned int keepConfiguration;
2376 sscanf(parameters[4].c_str(),
"%u", &keepConfiguration);
2377 playGeneratedIterationPlan(xmldoc,
2390 const std::string& fsmName,
2391 const std::string& configAlias,
2392 uint64_t durationSeconds ,
2393 unsigned int numberOfRuns ,
2394 bool keepConfiguration ,
2395 const std::string& logEntry)
2397 std::string planName = Iterator::RESERVED_GEN_PLAN_NAME;
2398 __COUT__ <<
"Attempting to play iteration plan '" << planName <<
".'" << __E__;
2400 genFsmName_ = fsmName;
2401 genConfigAlias_ = configAlias;
2402 genPlanDurationSeconds_ = durationSeconds;
2403 genPlanNumberOfRuns_ = numberOfRuns;
2404 genKeepConfiguration_ = keepConfiguration;
2405 genLogEntry_ = logEntry;
2407 __COUTV__(genFsmName_);
2408 __COUTV__(genConfigAlias_);
2409 __COUTV__(genPlanDurationSeconds_);
2410 __COUTV__(genPlanNumberOfRuns_);
2411 __COUTV__(genKeepConfiguration_);
2412 __COUTV__(genLogEntry_);
2414 playIterationPlanPrivate(xmldoc, planName);
2421 const std::string& planName)
2427 if(theSupervisor_->VERBOSE_MUTEX)
2428 __COUT__ <<
"Waiting for iterator access" << __E__;
2429 std::lock_guard<std::mutex> lock(accessMutex_);
2430 if(theSupervisor_->VERBOSE_MUTEX)
2431 __COUT__ <<
"Have iterator access" << __E__;
2433 if(!activePlanIsRunning_ && !commandPlay_)
2435 if(!workloopRunning_)
2439 workloopRunning_ =
true;
2442 std::thread([](
Iterator* iterator) { Iterator::IteratorWorkLoop(iterator); },
2447 activePlanName_ = planName;
2448 commandPlay_ =
true;
2452 __SS__ <<
"Invalid play command attempted. Can only play when the Iterator is "
2453 "inactive or paused."
2454 <<
" If you would like to restart an iteration plan, first try halting "
2457 __COUT__ << ss.str();
2459 xmldoc.addTextElementToData(
"error_message", ss.str());
2461 __COUT__ <<
"Invalid play command attempted. " << activePlanIsRunning_ <<
" "
2462 << commandPlay_ <<
" " << activePlanName_ << __E__;
2469 __COUT__ <<
"Attempting to pause iteration plan '" << activePlanName_ <<
".'"
2471 __COUT__ <<
"Attempting to pause iteration plan '" << activePlanName_ <<
".'"
2478 if(theSupervisor_->VERBOSE_MUTEX)
2479 __COUT__ <<
"Waiting for iterator access" << __E__;
2480 std::lock_guard<std::mutex> lock(accessMutex_);
2481 if(theSupervisor_->VERBOSE_MUTEX)
2482 __COUT__ <<
"Have iterator access" << __E__;
2484 if(workloopRunning_ && activePlanIsRunning_ && !commandPause_)
2486 commandPause_ =
true;
2490 __SS__ <<
"Invalid pause command attempted. Can only pause when running."
2492 __COUT__ << ss.str();
2494 xmldoc.addTextElementToData(
"error_message", ss.str());
2496 __COUT__ <<
"Invalid pause command attempted. " << workloopRunning_ <<
" "
2497 << activePlanIsRunning_ <<
" " << commandPause_ <<
" " << activePlanName_
2505 __COUT__ <<
"Attempting to halt iteration plan '" << activePlanName_ <<
".'" << __E__;
2506 __COUT__ <<
"Attempting to halt iteration plan '" << activePlanName_ <<
".'" << __E__;
2510 if(workloopRunning_)
2514 if(theSupervisor_->VERBOSE_MUTEX)
2515 __COUT__ <<
"Waiting for iterator access" << __E__;
2516 std::lock_guard<std::mutex> lock(accessMutex_);
2517 if(theSupervisor_->VERBOSE_MUTEX)
2518 __COUT__ <<
"Have iterator access" << __E__;
2520 __COUT__ <<
"activePlanIsRunning_: " << activePlanIsRunning_ << __E__;
2521 __COUT__ <<
"Passing halt command to iterator thread." << __E__;
2522 commandHalt_ =
true;
2525 activePlanName_ =
"";
2526 activeCommandIndex_ = -1;
2530 __COUT__ <<
"No thread, so conducting halt." << __E__;
2531 Iterator::haltIterator(
this);
2539 xmldoc.addTextElementToData(
2541 theSupervisor_->theStateMachine_.isInTransition()
2542 ? theSupervisor_->theStateMachine_.getCurrentTransitionName(
2543 theSupervisor_->stateMachineLastCommandInput_)
2544 : theSupervisor_->theStateMachine_.getCurrentStateName());
2548 if(theSupervisor_->theStateMachine_.isInTransition())
2549 xmldoc.addTextElementToData(
2550 "transition_progress",
2553 xmldoc.addTextElementToData(
"transition_progress",
"100");
2555 xmldoc.addNumberElementToData(
"time_in_state",
2560 if(theSupervisor_->VERBOSE_MUTEX)
2561 __COUT__ <<
"Waiting for iterator access" << __E__;
2562 std::lock_guard<std::mutex> lock(accessMutex_);
2563 if(theSupervisor_->VERBOSE_MUTEX)
2564 __COUT__ <<
"Have iterator access" << __E__;
2566 xmldoc.addTextElementToData(
"active_plan", activePlanName_);
2567 xmldoc.addTextElementToData(
"last_started_plan", lastStartedPlanName_);
2568 xmldoc.addTextElementToData(
"last_finished_plan", lastFinishedPlanName_);
2570 xmldoc.addNumberElementToData(
"current_command_index", activeCommandIndex_);
2571 xmldoc.addNumberElementToData(
"current_number_of_commands", activeNumberOfCommands_);
2572 xmldoc.addTextElementToData(
"current_command_type", activeCommandType_);
2573 xmldoc.addNumberElementToData(
"current_command_duration",
2574 time(0) - activeCommandStartTime_);
2575 xmldoc.addNumberElementToData(
"current_command_iteration", activeCommandIteration_);
2576 for(
const auto& depthIteration : depthIterationStack_)
2577 xmldoc.addNumberElementToData(
"depth_iteration", depthIteration);
2579 if(activePlanName_ == Iterator::RESERVED_GEN_PLAN_NAME)
2581 xmldoc.addNumberElementToData(
"generated_number_of_runs", genPlanNumberOfRuns_);
2582 xmldoc.addNumberElementToData(
"generated_duration_of_runs",
2583 genPlanDurationSeconds_);
2586 if(activePlanIsRunning_ && iteratorBusy_)
2588 if(workloopRunning_)
2589 xmldoc.addTextElementToData(
"active_plan_status",
"Running");
2591 xmldoc.addTextElementToData(
"active_plan_status",
"Error");
2593 else if(!activePlanIsRunning_ && iteratorBusy_)
2594 xmldoc.addTextElementToData(
"active_plan_status",
"Paused");
2596 xmldoc.addTextElementToData(
"active_plan_status",
"Inactive");
2598 xmldoc.addTextElementToData(
"error_message", errorMessage_);
void loadTableGroup(const std::string &tableGroupName, const TableGroupKey &tableGroupKey, bool doActivate=false, std::map< std::string, TableVersion > *groupMembers=0, ProgressBar *progressBar=0, std::string *accumulateWarnings=0, std::string *groupComment=0, std::string *groupAuthor=0, std::string *groupCreateTime=0, bool doNotLoadMember=false, std::string *groupTypeString=0, std::map< std::string, std::string > *groupAliases=0, ConfigurationManager::LoadGroupType groupTypeToLoad=ConfigurationManager::LoadGroupType::ALL_TYPES, bool ignoreVersionTracking=false)
std::pair< std::string, TableGroupKey > getTableGroupFromAlias(std::string systemAlias, ProgressBar *progressBar=0)
Getters.
bool isDisconnected(void) const
ConfigurationTree getNode(const std::string &nodeName, bool doNotThrowOnBrokenUIDLinks=false) const
navigating between nodes
void getValue(T &value) const
time_t getTimeInState(void) const
static const std::string COMMAND_BEGIN_LABEL
void getIterationPlanStatus(HttpXmlDocument &xmldoc)
return state machine and iterator status
std::string readPercentageString()
return percentage complete as std::string
std::string send(XDAQ_CONST_CALL xdaq::ApplicationDescriptor *d, xoap::MessageReference message)
static std::string getTimestampString(const std::string &linuxTimeInSeconds)
static void getVectorFromString(const std::string &inputString, std::vector< std::string > &listToReturn, const std::set< char > &delimiter={',', '|', '&'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'}, std::vector< char > *listOfDelimiters=0, bool decodeURIComponents=false)
static std::string vectorToString(const std::vector< T > &setToReturn, const std::string &delimeter=", ")
vectorToString ~
static bool isNumber(const std::string &stringToCheck)
Note: before call consider use of stringToCheck = StringMacros::convertEnvironmentVariables(stringToC...
static std::string decodeURIComponent(const std::string &data)
static bool getNumber(const std::string &s, T &retValue)