1 #include "otsdaq-core/GatewaySupervisor/Iterator.h"
2 #include "otsdaq-core/CoreSupervisors/CoreSupervisorBase.h"
3 #include "otsdaq-core/GatewaySupervisor/GatewaySupervisor.h"
4 #include "otsdaq-core/Macros/CoutMacros.h"
5 #include "otsdaq-core/MessageFacility/MessageFacility.h"
6 #include "otsdaq-core/WebUsersUtilities/WebUsers.h"
12 #define __MF_SUBJECT__ "Iterator"
18 : workloopRunning_(false)
19 , activePlanIsRunning_(false)
20 , iteratorBusy_(false)
22 , commandPause_(false)
25 , activeCommandIndex_(-1)
26 , activeCommandStartTime_(0)
27 , theSupervisor_(supervisor)
29 __MOUT__ <<
"Iterator constructed." << __E__;
30 __COUT__ <<
"Iterator constructed." << __E__;
34 Iterator::~Iterator(
void) {}
37 void Iterator::IteratorWorkLoop(
Iterator* iterator)
try
39 __MOUT__ <<
"Iterator work loop starting..." << __E__;
40 __COUT__ <<
"Iterator work loop starting..." << __E__;
46 if(iterator->theSupervisor_->VERBOSE_MUTEX)
47 __COUT__ <<
"Waiting for iterator access" << __E__;
48 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
49 if(iterator->theSupervisor_->VERBOSE_MUTEX)
50 __COUT__ <<
"Have iterator access" << __E__;
52 iterator->errorMessage_ =
"";
56 WebUsers::DEFAULT_ITERATOR_USERNAME);
58 theConfigurationManager.getAllTableInfo(
true);
60 IteratorWorkLoopStruct theIteratorStruct(iterator, &theConfigurationManager);
64 std::vector<IterateTable::Command> commands;
86 if(iterator->theSupervisor_->VERBOSE_MUTEX)
87 __COUT__ <<
"Waiting for iterator access" << __E__;
88 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
89 if(iterator->theSupervisor_->VERBOSE_MUTEX)
90 __COUT__ <<
"Have iterator access" << __E__;
92 if(iterator->commandPlay_)
94 iterator->commandPlay_ =
false;
96 if(!iterator->activePlanIsRunning_)
100 iterator->activePlanIsRunning_ =
true;
101 iterator->iteratorBusy_ =
true;
103 if(theIteratorStruct.activePlan_ != iterator->activePlanName_)
105 __COUT__ <<
"New plan name encountered old="
106 << theIteratorStruct.activePlan_
107 <<
" vs new=" << iterator->activePlanName_ << __E__;
108 theIteratorStruct.commandIndex_ = -1;
111 theIteratorStruct.activePlan_ = iterator->activePlanName_;
112 iterator->lastStartedPlanName_ = iterator->activePlanName_;
114 if(theIteratorStruct.commandIndex_ == (
unsigned int)-1)
116 __COUT__ <<
"Starting plan '" << theIteratorStruct.activePlan_
118 __MOUT__ <<
"Starting plan '" << theIteratorStruct.activePlan_
123 theIteratorStruct.doResumeAction_ =
true;
124 __COUT__ <<
"Continuing plan '" << theIteratorStruct.activePlan_
125 <<
"' at command index "
126 << theIteratorStruct.commandIndex_ <<
". " << __E__;
127 __MOUT__ <<
"Continuing plan '" << theIteratorStruct.activePlan_
128 <<
"' at command index "
129 << theIteratorStruct.commandIndex_ <<
". " << __E__;
133 else if(iterator->commandPause_ && !theIteratorStruct.doPauseAction_)
135 theIteratorStruct.doPauseAction_ =
true;
136 iterator->commandPause_ =
false;
138 else if(iterator->commandHalt_ && !theIteratorStruct.doHaltAction_)
140 theIteratorStruct.doHaltAction_ =
true;
141 iterator->commandHalt_ =
false;
144 theIteratorStruct.running_ = iterator->activePlanIsRunning_;
147 ->activeCommandIndex_ !=
148 theIteratorStruct.commandIndex_)
150 iterator->activeCommandIndex_ = theIteratorStruct.commandIndex_;
151 iterator->activeCommandStartTime_ = time(0);
153 if(theIteratorStruct.commandIndex_ <
154 theIteratorStruct.commandIterations_.size())
155 iterator->activeCommandIteration_ =
157 .commandIterations_[theIteratorStruct.commandIndex_];
159 iterator->activeCommandIteration_ = -1;
161 iterator->depthIterationStack_.clear();
162 for(
const auto& depthIteration : theIteratorStruct.stepIndexStack_)
163 iterator->depthIterationStack_.push_back(depthIteration);
176 if(theIteratorStruct.doPauseAction_)
183 __COUT__ <<
"Waiting to pause..." << __E__;
184 while(!iterator->checkCommand(&theIteratorStruct))
185 __COUT__ <<
"Waiting to pause..." << __E__;
187 __COUT__ <<
"Completing pause..." << __E__;
189 theIteratorStruct.doPauseAction_ =
false;
193 if(iterator->theSupervisor_->VERBOSE_MUTEX)
194 __COUT__ <<
"Waiting for iterator access" << __E__;
195 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
196 if(iterator->theSupervisor_->VERBOSE_MUTEX)
197 __COUT__ <<
"Have iterator access" << __E__;
199 iterator->activePlanIsRunning_ =
false;
201 __COUT__ <<
"Paused plan '" << theIteratorStruct.activePlan_
202 <<
"' at command index " << theIteratorStruct.commandIndex_ <<
". "
204 __MOUT__ <<
"Paused plan '" << theIteratorStruct.activePlan_
205 <<
"' at command index " << theIteratorStruct.commandIndex_ <<
". "
210 else if(theIteratorStruct.doHaltAction_)
217 __COUT__ <<
"Waiting to halt..." << __E__;
218 while(!iterator->checkCommand(&theIteratorStruct))
219 __COUT__ <<
"Waiting to halt..." << __E__;
221 __COUT__ <<
"Completing halt..." << __E__;
223 theIteratorStruct.doHaltAction_ =
false;
225 iterator->haltIterator(iterator, &theIteratorStruct);
263 if(theIteratorStruct.running_ &&
264 theIteratorStruct.activePlan_ !=
267 if(theIteratorStruct.commandIndex_ == (
unsigned int)-1)
271 __COUT__ <<
"Get commands" << __E__;
273 theIteratorStruct.commandIndex_ = 0;
275 theIteratorStruct.cfgMgr_
277 itConfig = theIteratorStruct.cfgMgr_->__GET_CONFIG__(
IterateTable);
279 theIteratorStruct.commands_ = itConfig->getPlanCommands(
280 theIteratorStruct.cfgMgr_, theIteratorStruct.activePlan_);
283 theIteratorStruct.commandIterations_.clear();
284 for(
auto& command : theIteratorStruct.commands_)
286 theIteratorStruct.commandIterations_.push_back(0);
287 __COUT__ <<
"command " << command.type_ << __E__;
289 << IterateTable::commandToTableMap_.at(command.type_)
291 __COUT__ <<
"param count = " << command.params_.size() << __E__;
293 for(
auto& param : command.params_)
295 __COUT__ <<
"\t param " << param.first <<
" : " << param.second
300 theIteratorStruct.originalTrackChanges_ =
301 ConfigurationInterface::isVersionTrackingEnabled();
302 theIteratorStruct.originalConfigGroup_ =
303 theIteratorStruct.cfgMgr_->getActiveGroupName();
304 theIteratorStruct.originalConfigKey_ =
305 theIteratorStruct.cfgMgr_->getActiveGroupKey();
307 __COUT__ <<
"originalTrackChanges "
308 << theIteratorStruct.originalTrackChanges_ << __E__;
309 __COUT__ <<
"originalConfigGroup "
310 << theIteratorStruct.originalConfigGroup_ << __E__;
311 __COUT__ <<
"originalConfigKey " << theIteratorStruct.originalConfigKey_
316 if(!theIteratorStruct.commandBusy_)
318 if(theIteratorStruct.commandIndex_ < theIteratorStruct.commands_.size())
321 theIteratorStruct.commandBusy_ =
true;
323 __COUT__ <<
"Iterator starting command "
324 << theIteratorStruct.commandIndex_ + 1 <<
": "
326 .commands_[theIteratorStruct.commandIndex_]
329 __MOUT__ <<
"Iterator starting command "
330 << theIteratorStruct.commandIndex_ + 1 <<
": "
332 .commands_[theIteratorStruct.commandIndex_]
336 iterator->startCommand(&theIteratorStruct);
338 else if(theIteratorStruct.commandIndex_ ==
339 theIteratorStruct.commands_.size())
341 __COUT__ <<
"Finished Iteration Plan '"
342 << theIteratorStruct.activePlan_ << __E__;
343 __MOUT__ <<
"Finished Iteration Plan '"
344 << theIteratorStruct.activePlan_ << __E__;
346 __COUT__ <<
"Reverting track changes." << __E__;
347 ConfigurationInterface::setVersionTrackingEnabled(
348 theIteratorStruct.originalTrackChanges_);
350 __COUT__ <<
"Activating original group..." << __E__;
353 theIteratorStruct.cfgMgr_->activateTableGroup(
354 theIteratorStruct.originalConfigGroup_,
355 theIteratorStruct.originalConfigKey_);
359 __COUT_WARN__ <<
"Original group could not be activated."
364 __COUT__ <<
"Completing halt..." << __E__;
366 iterator->haltIterator(iterator, &theIteratorStruct);
397 else if(theIteratorStruct.commandBusy_)
400 if(iterator->checkCommand(&theIteratorStruct))
402 theIteratorStruct.commandBusy_ =
false;
404 ++theIteratorStruct.commandIndex_;
406 __COUT__ <<
"Ready for next command. Done with "
407 << theIteratorStruct.commandIndex_ <<
" of "
408 << theIteratorStruct.commands_.size() << __E__;
409 __MOUT__ <<
"Iterator ready for next command. Done with "
410 << theIteratorStruct.commandIndex_ <<
" of "
411 << theIteratorStruct.commands_.size() << __E__;
415 if(theIteratorStruct.doResumeAction_)
416 theIteratorStruct.doResumeAction_ =
false;
431 iterator->workloopRunning_ =
false;
433 catch(
const std::runtime_error& e)
435 __SS__ <<
"Encountered error in Iterator thread:\n" << e.what() << __E__;
436 __COUT_ERR__ << ss.str();
440 if(iterator->theSupervisor_->VERBOSE_MUTEX)
441 __COUT__ <<
"Waiting for iterator access" << __E__;
442 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
443 if(iterator->theSupervisor_->VERBOSE_MUTEX)
444 __COUT__ <<
"Have iterator access" << __E__;
446 iterator->workloopRunning_ =
false;
447 iterator->errorMessage_ = ss.str();
451 __SS__ <<
"Encountered unknown error in Iterator thread." << __E__;
452 __COUT_ERR__ << ss.str();
456 if(iterator->theSupervisor_->VERBOSE_MUTEX)
457 __COUT__ <<
"Waiting for iterator access" << __E__;
458 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
459 if(iterator->theSupervisor_->VERBOSE_MUTEX)
460 __COUT__ <<
"Have iterator access" << __E__;
462 iterator->workloopRunning_ =
false;
463 iterator->errorMessage_ = ss.str();
467 void Iterator::startCommand(IteratorWorkLoopStruct* iteratorStruct)
try
471 for(
const auto& depthIteration : iteratorStruct->stepIndexStack_)
473 __COUT__ << i++ <<
":" << depthIteration << __E__;
480 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
481 __COUT__ <<
"Waiting for FSM access" << __E__;
482 std::lock_guard<std::mutex> lock(
483 iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
484 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
485 __COUT__ <<
"Have FSM access" << __E__;
488 if(iteratorStruct->commandIndex_ >= iteratorStruct->commands_.size())
490 __SS__ <<
"Out of range commandIndex = " << iteratorStruct->commandIndex_
491 <<
" in size = " << iteratorStruct->commands_.size() << __E__;
496 ++iteratorStruct->commandIterations_[iteratorStruct->commandIndex_];
498 std::string type = iteratorStruct->commands_[iteratorStruct->commandIndex_].type_;
499 if(type == IterateTable::COMMAND_BEGIN_LABEL)
501 return startCommandBeginLabel(iteratorStruct);
503 else if(type == IterateTable::COMMAND_CHOOSE_FSM)
505 return startCommandChooseFSM(
507 iteratorStruct->commands_[iteratorStruct->commandIndex_]
508 .params_[IterateTable::commandChooseFSMParams_.NameOfFSM_]);
510 else if(type == IterateTable::COMMAND_CONFIGURE_ACTIVE_GROUP)
512 return startCommandConfigureActive(iteratorStruct);
514 else if(type == IterateTable::COMMAND_CONFIGURE_ALIAS)
516 return startCommandConfigureAlias(
518 iteratorStruct->commands_[iteratorStruct->commandIndex_]
519 .params_[IterateTable::commandConfigureAliasParams_.SystemAlias_]);
521 else if(type == IterateTable::COMMAND_CONFIGURE_GROUP)
523 return startCommandConfigureGroup(iteratorStruct);
525 else if(type == IterateTable::COMMAND_EXECUTE_FE_MACRO)
527 return startCommandMacro(iteratorStruct,
true );
529 else if(type == IterateTable::COMMAND_EXECUTE_MACRO)
531 return startCommandMacro(iteratorStruct,
false );
533 else if(type == IterateTable::COMMAND_MODIFY_ACTIVE_GROUP)
535 return startCommandModifyActive(iteratorStruct);
537 else if(type == IterateTable::COMMAND_REPEAT_LABEL)
539 return startCommandRepeatLabel(iteratorStruct);
541 else if(type == IterateTable::COMMAND_RUN)
543 return startCommandRun(iteratorStruct);
547 __SS__ <<
"Failed attempt to start unrecognized command type = " << type << __E__;
548 __COUT_ERR__ << ss.str();
554 __COUT__ <<
"Error caught. Reverting track changes." << __E__;
555 ConfigurationInterface::setVersionTrackingEnabled(
556 iteratorStruct->originalTrackChanges_);
558 __COUT__ <<
"Activating original group..." << __E__;
561 iteratorStruct->cfgMgr_->activateTableGroup(iteratorStruct->originalConfigGroup_,
562 iteratorStruct->originalConfigKey_);
566 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
575 bool Iterator::checkCommand(IteratorWorkLoopStruct* iteratorStruct)
try
578 if(iteratorStruct->commandIndex_ >= iteratorStruct->commands_.size())
580 __COUT__ <<
"Out of range commandIndex = " << iteratorStruct->commandIndex_
581 <<
" in size = " << iteratorStruct->commands_.size() << __E__;
585 std::string type = iteratorStruct->commands_[iteratorStruct->commandIndex_].type_;
586 if(type == IterateTable::COMMAND_BEGIN_LABEL)
591 else if(type == IterateTable::COMMAND_CHOOSE_FSM)
596 else if(type == IterateTable::COMMAND_CONFIGURE_ALIAS ||
597 type == IterateTable::COMMAND_CONFIGURE_ACTIVE_GROUP ||
598 type == IterateTable::COMMAND_CONFIGURE_GROUP)
600 return checkCommandConfigure(iteratorStruct);
602 else if(type == IterateTable::COMMAND_EXECUTE_FE_MACRO)
604 return checkCommandMacro(iteratorStruct,
true );
606 else if(type == IterateTable::COMMAND_EXECUTE_MACRO)
608 return checkCommandMacro(iteratorStruct,
false );
610 else if(type == IterateTable::COMMAND_MODIFY_ACTIVE_GROUP)
615 else if(type == IterateTable::COMMAND_REPEAT_LABEL)
620 else if(type == IterateTable::COMMAND_RUN)
622 return checkCommandRun(iteratorStruct);
626 __SS__ <<
"Attempt to check unrecognized command type = " << type << __E__;
627 __COUT_ERR__ << ss.str();
633 __COUT__ <<
"Error caught. Reverting track changes." << __E__;
634 ConfigurationInterface::setVersionTrackingEnabled(
635 iteratorStruct->originalTrackChanges_);
637 __COUT__ <<
"Activating original group..." << __E__;
640 iteratorStruct->cfgMgr_->activateTableGroup(iteratorStruct->originalConfigGroup_,
641 iteratorStruct->originalConfigKey_);
645 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
652 void Iterator::startCommandChooseFSM(IteratorWorkLoopStruct* iteratorStruct,
653 const std::string& fsmName)
655 __COUT__ <<
"fsmName " << fsmName << __E__;
657 iteratorStruct->fsmName_ = fsmName;
658 iteratorStruct->theIterator_->lastFsmName_ = fsmName;
667 iteratorStruct->fsmRunAlias_ =
"Run";
670 ConfigurationTree configLinkNode = iteratorStruct->cfgMgr_->getSupervisorTableNode(
671 iteratorStruct->theIterator_->theSupervisor_->getContextUID(),
672 iteratorStruct->theIterator_->theSupervisor_->getSupervisorUID());
674 if(!configLinkNode.isDisconnected())
679 configLinkNode.getNode(
"LinkToStateMachineTable");
680 if(!fsmLinkNode.isDisconnected())
681 iteratorStruct->fsmRunAlias_ =
682 fsmLinkNode.getNode(fsmName +
"/RunDisplayAlias")
683 .getValue<std::string>();
685 __COUT_INFO__ <<
"FSM Link disconnected." << __E__;
687 catch(std::runtime_error& e)
691 <<
"No state machine Run alias. Ignoring and assuming alias of '"
692 << iteratorStruct->fsmRunAlias_ <<
".'" << __E__;
696 __COUT_ERR__ <<
"Unknown error. Should never happen." << __E__;
699 <<
"No state machine Run alias. Ignoring and assuming alias of '"
700 << iteratorStruct->fsmRunAlias_ <<
".'" << __E__;
704 __COUT_INFO__ <<
"FSM Link disconnected." << __E__;
706 __COUT__ <<
"fsmRunAlias_ = " << iteratorStruct->fsmRunAlias_ << __E__;
710 iteratorStruct->fsmNextRunNumber_ =
711 iteratorStruct->theIterator_->theSupervisor_->getNextRunNumber(
712 iteratorStruct->fsmName_);
714 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
715 .getCurrentStateName() ==
"Running" ||
716 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
717 .getCurrentStateName() ==
"Paused")
718 --iteratorStruct->fsmNextRunNumber_;
720 __COUT__ <<
"fsmNextRunNumber_ = " << iteratorStruct->fsmNextRunNumber_ << __E__;
725 bool Iterator::haltIterator(
Iterator* iterator, IteratorWorkLoopStruct* iteratorStruct)
729 const std::string& fsmName = iterator->lastFsmName_;
731 std::vector<std::string> fsmCommandParameters;
732 std::string errorStr =
"";
733 std::string currentState = theSupervisor->theStateMachine_.getCurrentStateName();
735 bool haltAttempted =
true;
736 if(currentState ==
"Initialized" || currentState ==
"Halted")
738 __COUT__ <<
"Do nothing. Already halted." << __E__;
739 haltAttempted =
false;
741 else if(currentState ==
"Running")
742 errorStr = theSupervisor->attemptStateMachineTransition(
747 WebUsers::DEFAULT_ITERATOR_USERNAME ,
748 WebUsers::DEFAULT_ITERATOR_USERNAME,
749 fsmCommandParameters);
751 errorStr = theSupervisor->attemptStateMachineTransition(
756 WebUsers::DEFAULT_ITERATOR_USERNAME ,
757 WebUsers::DEFAULT_ITERATOR_USERNAME,
758 fsmCommandParameters);
764 __SS__ <<
"Iterator failed to halt because of the following error: "
770 __COUT__ <<
"FSM in transition = "
771 << theSupervisor->theStateMachine_.isInTransition() << __E__;
772 __COUT__ <<
"halting state machine launched." << __E__;
776 __COUT__ <<
"Conducting Iterator halt." << __E__;
780 __COUT__ <<
"Reverting track changes." << __E__;
781 ConfigurationInterface::setVersionTrackingEnabled(
782 iteratorStruct->originalTrackChanges_);
784 __COUT__ <<
"Activating original group..." << __E__;
787 iteratorStruct->cfgMgr_->activateTableGroup(
788 iteratorStruct->originalConfigGroup_, iteratorStruct->originalConfigKey_);
792 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
798 if(iterator->theSupervisor_->VERBOSE_MUTEX)
799 __COUT__ <<
"Waiting for iterator access" << __E__;
800 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
801 if(iterator->theSupervisor_->VERBOSE_MUTEX)
802 __COUT__ <<
"Have iterator access" << __E__;
804 iterator->activePlanIsRunning_ =
false;
805 iterator->iteratorBusy_ =
false;
808 iterator->activePlanName_ =
"";
809 iterator->activeCommandIndex_ = -1;
813 __COUT__ <<
"Halted plan '" << iteratorStruct->activePlan_
814 <<
"' at command index " << iteratorStruct->commandIndex_ <<
". "
816 __MOUT__ <<
"Halted plan '" << iteratorStruct->activePlan_
817 <<
"' at command index " << iteratorStruct->commandIndex_ <<
". "
820 iterator->lastStartedPlanName_ = iteratorStruct->activePlan_;
821 iteratorStruct->activePlan_ =
"";
822 iteratorStruct->commandIndex_ = -1;
825 return haltAttempted;
829 void Iterator::startCommandBeginLabel(IteratorWorkLoopStruct* iteratorStruct)
831 __COUT__ <<
"Entering label '"
832 << iteratorStruct->commands_[iteratorStruct->commandIndex_]
833 .params_[IterateTable::commandBeginLabelParams_.Label_]
834 <<
"'..." << std::endl;
837 iteratorStruct->stepIndexStack_.push_back(0);
841 void Iterator::startCommandRepeatLabel(IteratorWorkLoopStruct* iteratorStruct)
845 int numOfRepetitions;
846 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_]
847 .params_[IterateTable::commandRepeatLabelParams_.NumberOfRepetitions_]
851 __COUT__ <<
"numOfRepetitions remaining = " << numOfRepetitions << __E__;
855 if(numOfRepetitions <= 0)
858 sprintf(repStr,
"%d", iteratorStruct->stepIndexStack_.back());
859 iteratorStruct->commands_[iteratorStruct->commandIndex_]
860 .params_[IterateTable::commandRepeatLabelParams_.NumberOfRepetitions_] =
864 iteratorStruct->stepIndexStack_.pop_back();
872 ++(iteratorStruct->stepIndexStack_.back());
875 for(i = iteratorStruct->commandIndex_; i > 0;
877 if(iteratorStruct->commands_[i].type_ == IterateTable::COMMAND_BEGIN_LABEL &&
878 iteratorStruct->commands_[iteratorStruct->commandIndex_]
879 .params_[IterateTable::commandRepeatLabelParams_.Label_] ==
880 iteratorStruct->commands_[i]
881 .params_[IterateTable::commandBeginLabelParams_.Label_])
884 sprintf(repStr,
"%d", numOfRepetitions);
885 iteratorStruct->commands_[iteratorStruct->commandIndex_]
886 .params_[IterateTable::commandRepeatLabelParams_.NumberOfRepetitions_] =
889 iteratorStruct->commandIndex_ = i;
890 __COUT__ <<
"Jumping back to commandIndex " << iteratorStruct->commandIndex_ << __E__;
894 void Iterator::startCommandRun(IteratorWorkLoopStruct* iteratorStruct)
896 iteratorStruct->runIsDone_ =
false;
897 iteratorStruct->fsmCommandParameters_.clear();
899 std::string errorStr =
"";
900 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
901 ->theStateMachine_.getCurrentStateName();
905 if(currentState ==
"Configured")
907 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
911 iteratorStruct->fsmName_,
912 WebUsers::DEFAULT_ITERATOR_USERNAME ,
913 WebUsers::DEFAULT_ITERATOR_USERNAME,
914 iteratorStruct->fsmCommandParameters_);
916 errorStr =
"Can only Run from the Configured state. The current state is " +
921 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
927 <<
"FSM in transition = "
928 << iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition()
930 __COUT__ <<
"startCommandRun success." << __E__;
934 void Iterator::startCommandConfigureActive(IteratorWorkLoopStruct* iteratorStruct)
936 __COUT__ <<
"startCommandConfigureActive " << __E__;
942 std::string group = iteratorStruct->cfgMgr_->getActiveGroupName();
943 TableGroupKey key = iteratorStruct->cfgMgr_->getActiveGroupKey();
945 __COUT__ <<
"group " << group << __E__;
946 __COUT__ <<
"key " << key << __E__;
950 std::stringstream systemAlias;
951 systemAlias <<
"GROUP:" << group <<
":" << key;
952 startCommandConfigureAlias(iteratorStruct, systemAlias.str());
956 void Iterator::startCommandConfigureGroup(IteratorWorkLoopStruct* iteratorStruct)
958 __COUT__ <<
"startCommandConfigureGroup " << __E__;
964 iteratorStruct->commands_[iteratorStruct->commandIndex_]
965 .params_[IterateTable::commandConfigureGroupParams_.GroupName_];
967 TableGroupKey(iteratorStruct->commands_[iteratorStruct->commandIndex_]
968 .params_[IterateTable::commandConfigureGroupParams_.GroupKey_]);
970 __COUT__ <<
"group " << group << __E__;
971 __COUT__ <<
"key " << key << __E__;
975 std::stringstream systemAlias;
976 systemAlias <<
"GROUP:" << group <<
":" << key;
977 startCommandConfigureAlias(iteratorStruct, systemAlias.str());
981 void Iterator::startCommandConfigureAlias(IteratorWorkLoopStruct* iteratorStruct,
982 const std::string& systemAlias)
984 __COUT__ <<
"systemAlias " << systemAlias << __E__;
986 iteratorStruct->fsmCommandParameters_.clear();
987 iteratorStruct->fsmCommandParameters_.push_back(systemAlias);
989 std::string errorStr =
"";
990 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
991 ->theStateMachine_.getCurrentStateName();
995 if(currentState ==
"Initial")
997 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1001 iteratorStruct->fsmName_,
1002 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1003 WebUsers::DEFAULT_ITERATOR_USERNAME,
1004 iteratorStruct->fsmCommandParameters_);
1005 else if(currentState ==
"Halted")
1007 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1011 iteratorStruct->fsmName_,
1012 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1013 WebUsers::DEFAULT_ITERATOR_USERNAME,
1014 iteratorStruct->fsmCommandParameters_);
1015 else if(currentState ==
"Configured")
1017 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1021 iteratorStruct->fsmName_,
1022 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1023 WebUsers::DEFAULT_ITERATOR_USERNAME,
1024 iteratorStruct->fsmCommandParameters_);
1027 "Can only Configure from the Initial or Halted state. The current state is " +
1032 __SS__ <<
"Iterator failed to configure with system alias '"
1033 << (iteratorStruct->fsmCommandParameters_.size()
1034 ? iteratorStruct->fsmCommandParameters_[0]
1036 <<
"' because of the following error: " << errorStr;
1042 <<
"FSM in transition = "
1043 << iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition()
1045 __COUT__ <<
"startCommandConfigureAlias success." << __E__;
1049 void Iterator::startCommandMacro(IteratorWorkLoopStruct* iteratorStruct,
1050 bool isFrontEndMacro)
1058 const std::string& macroName =
1059 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1060 .params_[IterateTable::commandExecuteMacroParams_.MacroName_];
1061 const std::string& enableSavingOutput =
1062 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1063 .params_[IterateTable::commandExecuteMacroParams_.EnableSavingOutput_];
1064 const std::string& outputFilePath =
1065 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1066 .params_[IterateTable::commandExecuteMacroParams_.OutputFilePath_];
1067 const std::string& outputFileRadix =
1068 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1069 .params_[IterateTable::commandExecuteMacroParams_.OutputFileRadix_];
1070 const std::string& inputArgs =
1071 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1072 .params_[IterateTable::commandExecuteMacroParams_.MacroArgumentString_];
1074 __COUTV__(macroName);
1075 __COUTV__(enableSavingOutput);
1076 __COUTV__(outputFilePath);
1077 __COUTV__(outputFileRadix);
1078 __COUTV__(inputArgs);
1086 iteratorStruct->targetsDone_.clear();
1088 __COUTV__(iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_.size());
1089 for(
const auto& target :
1090 iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_)
1092 __COUT__ <<
"target " << target.table_ <<
":" << target.UID_ << __E__;
1095 iteratorStruct->targetsDone_.push_back(
false);
1097 xoap::MessageReference message =
1098 SOAPUtilities::makeSOAPMessageReference(
"FECommunication");
1101 std::string type = isFrontEndMacro ?
"feMacroMultiDimensionalStart"
1102 :
"macroMultiDimensionalStart";
1103 parameters.addParameter(
"type", type);
1104 parameters.addParameter(
"requester", WebUsers::DEFAULT_ITERATOR_USERNAME);
1105 parameters.addParameter(
"targetInterfaceID", target.UID_);
1106 parameters.addParameter(isFrontEndMacro ?
"feMacroName" :
"macroName", macroName);
1107 parameters.addParameter(
"enableSavingOutput", enableSavingOutput);
1108 parameters.addParameter(
"outputFilePath", outputFilePath);
1109 parameters.addParameter(
"outputFileRadix", outputFileRadix);
1110 parameters.addParameter(
"inputArgs", inputArgs);
1111 SOAPUtilities::addParameters(message, parameters);
1113 __COUT__ <<
"Sending FE communication: " << SOAPUtilities::translate(message)
1116 xoap::MessageReference replyMessage =
1117 iteratorStruct->theIterator_->theSupervisor_
1118 ->SOAPMessenger::sendWithSOAPReply(
1119 iteratorStruct->theIterator_->theSupervisor_->allSupervisorInfo_
1120 .getAllMacroMakerTypeSupervisorInfo()
1122 ->second.getDescriptor(),
1125 __COUT__ <<
"Response received: " << SOAPUtilities::translate(replyMessage)
1129 rxParameters.addParameter(
"Error");
1130 std::string response = SOAPUtilities::receive(replyMessage, rxParameters);
1132 std::string error = rxParameters.getValue(
"Error");
1134 if(response != type +
"Done" || error !=
"")
1137 __SS__ <<
"Error transmitting request to target interface '" << target.UID_
1138 <<
"' from '" << WebUsers::DEFAULT_ITERATOR_USERNAME <<
".' Response '"
1139 << response <<
"' with error: " << error << __E__;
1147 bool Iterator::checkCommandMacro(IteratorWorkLoopStruct* iteratorStruct,
1148 bool isFrontEndMacro)
1158 const std::string& macroName =
1159 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1160 .params_[IterateTable::commandExecuteMacroParams_.MacroName_];
1162 __COUTV__(macroName);
1167 for(
unsigned int i = 0;
1168 i < iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_.size();
1172 iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_[i];
1174 __COUT__ <<
"target " << target.table_ <<
":" << target.UID_ << __E__;
1176 xoap::MessageReference message =
1177 SOAPUtilities::makeSOAPMessageReference(
"FECommunication");
1180 std::string type = isFrontEndMacro ?
"feMacroMultiDimensionalCheck"
1181 :
"macroMultiDimensionalCheck";
1182 parameters.addParameter(
"type", type);
1183 parameters.addParameter(
"requester", WebUsers::DEFAULT_ITERATOR_USERNAME);
1184 parameters.addParameter(
"targetInterfaceID", target.UID_);
1185 parameters.addParameter(isFrontEndMacro ?
"feMacroName" :
"macroName", macroName);
1186 SOAPUtilities::addParameters(message, parameters);
1188 __COUT__ <<
"Sending FE communication: " << SOAPUtilities::translate(message)
1191 xoap::MessageReference replyMessage =
1192 iteratorStruct->theIterator_->theSupervisor_
1193 ->SOAPMessenger::sendWithSOAPReply(
1194 iteratorStruct->theIterator_->theSupervisor_->allSupervisorInfo_
1195 .getAllMacroMakerTypeSupervisorInfo()
1197 ->second.getDescriptor(),
1200 __COUT__ <<
"Response received: " << SOAPUtilities::translate(replyMessage)
1204 rxParameters.addParameter(
"Error");
1205 rxParameters.addParameter(
"Done");
1206 std::string response = SOAPUtilities::receive(replyMessage, rxParameters);
1208 std::string error = rxParameters.getValue(
"Error");
1209 bool done = rxParameters.getValue(
"Done") ==
"1";
1211 if(response != type +
"Done" || error !=
"")
1214 __SS__ <<
"Error transmitting request to target interface '" << target.UID_
1215 <<
"' from '" << WebUsers::DEFAULT_ITERATOR_USERNAME <<
".' Response '"
1216 << response <<
"' with error: " << error << __E__;
1224 iteratorStruct->targetsDone_[i] =
true;
1236 void Iterator::startCommandModifyActive(IteratorWorkLoopStruct* iteratorStruct)
1257 bool doTrackGroupChanges =
false;
1259 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1260 .params_[IterateTable::commandModifyActiveParams_.DoTrackGroupChanges_])
1261 doTrackGroupChanges =
true;
1263 const std::string& startValueStr =
1264 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1265 .params_[IterateTable::commandModifyActiveParams_.FieldStartValue_];
1266 const std::string& stepSizeStr =
1267 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1268 .params_[IterateTable::commandModifyActiveParams_.FieldIterationStepSize_];
1270 const unsigned int stepIndex = iteratorStruct->stepIndexStack_.back();
1272 __COUT__ <<
"doTrackGroupChanges " << (doTrackGroupChanges ?
"yes" :
"no")
1274 __COUT__ <<
"stepIndex " << stepIndex << std::endl;
1276 ConfigurationInterface::setVersionTrackingEnabled(doTrackGroupChanges);
1280 if(startValueStr.size() && (startValueStr[startValueStr.size() - 1] ==
'f' ||
1281 startValueStr.find(
'.') != std::string::npos))
1284 double startValue = strtod(startValueStr.c_str(), 0);
1285 double stepSize = strtod(stepSizeStr.c_str(), 0);
1287 __COUT__ <<
"startValue " << startValue << std::endl;
1288 __COUT__ <<
"stepSize " << stepSize << std::endl;
1289 __COUT__ <<
"currentValue " << startValue + stepSize * stepIndex << std::endl;
1291 helpCommandModifyActive(
1292 iteratorStruct, startValue + stepSize * stepIndex, doTrackGroupChanges);
1296 long int startValue;
1299 StringMacros::getNumber(startValueStr, startValue);
1300 StringMacros::getNumber(startValueStr, stepSize);
1321 __COUT__ <<
"startValue " << startValue << std::endl;
1322 __COUT__ <<
"stepSize " << stepSize << std::endl;
1323 __COUT__ <<
"currentValue " << startValue + stepSize * stepIndex << std::endl;
1325 helpCommandModifyActive(
1326 iteratorStruct, startValue + stepSize * stepIndex, doTrackGroupChanges);
1340 bool Iterator::checkCommandRun(IteratorWorkLoopStruct* iteratorStruct)
1349 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1350 __COUT__ <<
"Waiting for FSM access" << __E__;
1351 std::lock_guard<std::mutex> lock(
1352 iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
1353 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1354 __COUT__ <<
"Have FSM access" << __E__;
1356 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition())
1359 iteratorStruct->fsmCommandParameters_.clear();
1361 std::string errorStr =
"";
1362 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
1363 ->theStateMachine_.getCurrentStateName();
1367 if(iteratorStruct->doPauseAction_)
1370 __COUT__ <<
"Transitioning FSM to Paused..." << __E__;
1372 if(currentState ==
"Paused")
1375 __COUT__ <<
"Transition to Paused complete." << __E__;
1378 else if(currentState ==
"Running")
1379 errorStr = iteratorStruct->theIterator_->theSupervisor_
1380 ->attemptStateMachineTransition(
1384 iteratorStruct->fsmName_,
1385 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1386 WebUsers::DEFAULT_ITERATOR_USERNAME,
1387 iteratorStruct->fsmCommandParameters_);
1388 else if(currentState ==
"Configured")
1391 __COUT__ <<
"In Configured state. No need to transition to Paused." << __E__;
1395 errorStr =
"Expected to be in Paused. Unexpectedly, the current state is " +
1397 ". Last State Machine error message was as follows: " +
1398 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
1403 __SS__ <<
"Iterator failed to pause because of the following error: "
1409 else if(iteratorStruct->doHaltAction_)
1412 __COUT__ <<
"Transitioning FSM to Halted..." << __E__;
1414 if(currentState ==
"Halted")
1417 __COUT__ <<
"Transition to Halted complete." << __E__;
1420 else if(currentState ==
"Running" ||
1421 currentState ==
"Paused")
1422 errorStr = iteratorStruct->theIterator_->theSupervisor_
1423 ->attemptStateMachineTransition(
1427 iteratorStruct->fsmName_,
1428 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1429 WebUsers::DEFAULT_ITERATOR_USERNAME,
1430 iteratorStruct->fsmCommandParameters_);
1431 else if(currentState ==
"Configured")
1432 errorStr = iteratorStruct->theIterator_->theSupervisor_
1433 ->attemptStateMachineTransition(
1437 iteratorStruct->fsmName_,
1438 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1439 WebUsers::DEFAULT_ITERATOR_USERNAME,
1440 iteratorStruct->fsmCommandParameters_);
1442 errorStr =
"Expected to be in Halted. Unexpectedly, the current state is " +
1444 ". Last State Machine error message was as follows: " +
1445 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
1450 __SS__ <<
"Iterator failed to halt because of the following error: "
1456 else if(iteratorStruct->doResumeAction_)
1461 __COUT__ <<
"Transitioning FSM to Running..." << __E__;
1463 if(currentState ==
"Paused")
1464 errorStr = iteratorStruct->theIterator_->theSupervisor_
1465 ->attemptStateMachineTransition(
1469 iteratorStruct->fsmName_,
1470 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1471 WebUsers::DEFAULT_ITERATOR_USERNAME,
1472 iteratorStruct->fsmCommandParameters_);
1476 __SS__ <<
"Iterator failed to run because of the following error: "
1486 if(currentState !=
"Running")
1488 if(iteratorStruct->runIsDone_ && currentState ==
"Configured")
1491 __COUT__ <<
"Reached end of run " << iteratorStruct->fsmNextRunNumber_
1496 errorStr =
"Expected to be in Running. Unexpectedly, the current state is " +
1497 currentState +
". Last State Machine error message was as follows: " +
1498 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
1503 bool waitOnRunningThreads =
false;
1504 if(
"True" == iteratorStruct->commands_[iteratorStruct->commandIndex_]
1505 .params_[IterateTable::commandRunParams_.WaitOnRunningThreads_])
1506 waitOnRunningThreads =
true;
1508 time_t remainingDurationInSeconds;
1510 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_]
1511 .params_[IterateTable::commandRunParams_.DurationInSeconds_]
1514 &remainingDurationInSeconds);
1516 __COUT__ <<
"waitOnRunningThreads " << waitOnRunningThreads << __E__;
1517 __COUT__ <<
"remainingDurationInSeconds " << remainingDurationInSeconds << __E__;
1521 if(waitOnRunningThreads)
1525 iteratorStruct->theIterator_->theSupervisor_;
1527 bool allFrontEndsAreDone =
true;
1528 for(
auto& it : theSupervisor->allSupervisorInfo_.getAllFETypeSupervisorInfo())
1532 std::string status = theSupervisor->send(it.second.getDescriptor(),
1533 "WorkLoopStatusRequest");
1535 __COUT__ <<
"FESupervisor instance " << it.first
1536 <<
" has status = " << status << std::endl;
1538 if(status != CoreSupervisorBase::WORK_LOOP_DONE)
1540 allFrontEndsAreDone =
false;
1544 catch(xdaq::exception::Exception& e)
1546 __SS__ <<
"Could not retrieve status from FESupervisor instance "
1547 << it.first <<
"." << std::endl;
1548 __COUT_WARN__ << ss.str();
1549 errorStr = ss.str();
1554 <<
"Iterator failed to run because of the following error: "
1561 if(allFrontEndsAreDone)
1564 __COUT__ <<
"FE workloops all complete! Stopping run..." << __E__;
1566 errorStr = iteratorStruct->theIterator_->theSupervisor_
1567 ->attemptStateMachineTransition(
1571 iteratorStruct->fsmName_,
1572 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1573 WebUsers::DEFAULT_ITERATOR_USERNAME,
1574 iteratorStruct->fsmCommandParameters_);
1579 <<
"Iterator failed to stop run because of the following error: "
1585 iteratorStruct->runIsDone_ =
true;
1593 if(remainingDurationInSeconds > 1)
1595 --remainingDurationInSeconds;
1599 sprintf(str,
"%ld", remainingDurationInSeconds);
1600 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1601 .params_[IterateTable::commandRunParams_.DurationInSeconds_] =
1604 else if(remainingDurationInSeconds == 1)
1607 __COUT__ <<
"Time duration reached! Stopping run..." << __E__;
1609 errorStr = iteratorStruct->theIterator_->theSupervisor_
1610 ->attemptStateMachineTransition(
1614 iteratorStruct->fsmName_,
1615 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1616 WebUsers::DEFAULT_ITERATOR_USERNAME,
1617 iteratorStruct->fsmCommandParameters_);
1621 __SS__ <<
"Iterator failed to stop run because of the following error: "
1627 iteratorStruct->runIsDone_ =
true;
1635 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
1643 bool Iterator::checkCommandConfigure(IteratorWorkLoopStruct* iteratorStruct)
1652 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1653 __COUT__ <<
"Waiting for FSM access" << __E__;
1654 std::lock_guard<std::mutex> lock(
1655 iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
1656 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1657 __COUT__ <<
"Have FSM access" << __E__;
1659 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition())
1662 std::string errorStr =
"";
1663 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
1664 ->theStateMachine_.getCurrentStateName();
1666 if(currentState ==
"Halted")
1668 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1672 iteratorStruct->fsmName_,
1673 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1674 WebUsers::DEFAULT_ITERATOR_USERNAME,
1675 iteratorStruct->fsmCommandParameters_);
1676 else if(currentState !=
"Configured")
1677 errorStr =
"Expected to be in Configure. Unexpectedly, the current state is " +
1678 currentState +
"." +
1679 ". Last State Machine error message was as follows: " +
1680 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
1684 __COUT__ <<
"checkCommandConfigureAlias complete." << __E__;
1687 std::pair<std::string, TableGroupKey> newActiveGroup =
1688 iteratorStruct->cfgMgr_->getTableGroupFromAlias(
1689 iteratorStruct->fsmCommandParameters_[0]);
1690 iteratorStruct->cfgMgr_->loadTableGroup(
1691 newActiveGroup.first, newActiveGroup.second,
true );
1693 __COUT__ <<
"originalTrackChanges " << iteratorStruct->originalTrackChanges_
1695 __COUT__ <<
"originalConfigGroup " << iteratorStruct->originalConfigGroup_
1697 __COUT__ <<
"originalConfigKey " << iteratorStruct->originalConfigKey_ << __E__;
1699 __COUT__ <<
"currentTrackChanges "
1700 << ConfigurationInterface::isVersionTrackingEnabled() << __E__;
1701 __COUT__ <<
"originalConfigGroup "
1702 << iteratorStruct->cfgMgr_->getActiveGroupName() << __E__;
1703 __COUT__ <<
"originalConfigKey " << iteratorStruct->cfgMgr_->getActiveGroupKey()
1711 __SS__ <<
"Iterator failed to configure with system alias '"
1712 << (iteratorStruct->fsmCommandParameters_.size()
1713 ? iteratorStruct->fsmCommandParameters_[0]
1715 <<
"' because of the following error: " << errorStr;
1723 const std::string& command,
1724 const std::string& parameter)
1727 if(command ==
"iteratePlay")
1729 playIterationPlan(xmldoc, parameter);
1732 else if(command ==
"iteratePause")
1734 pauseIterationPlan(xmldoc);
1737 else if(command ==
"iterateHalt")
1739 haltIterationPlan(xmldoc);
1742 else if(command ==
"getIterationPlanStatus")
1744 getIterationPlanStatus(xmldoc);
1751 if(theSupervisor_->VERBOSE_MUTEX)
1752 __COUT__ <<
"Waiting for iterator access" << __E__;
1753 std::lock_guard<std::mutex> lock(accessMutex_);
1754 if(theSupervisor_->VERBOSE_MUTEX)
1755 __COUT__ <<
"Have iterator access" << __E__;
1759 __SS__ <<
"Error - Can not accept request because the Iterator "
1761 <<
"in control of State Machine progress. ";
1762 __COUT_ERR__ <<
"\n" << ss.str();
1763 __MOUT_ERR__ <<
"\n" << ss.str();
1765 xmldoc.addTextElementToData(
"state_tranisition_attempted",
1767 xmldoc.addTextElementToData(
1768 "state_tranisition_attempted_err",
1778 void Iterator::playIterationPlan(
HttpXmlDocument& xmldoc,
const std::string& planName)
1780 __MOUT__ <<
"Attempting to play iteration plan '" << planName <<
".'" << __E__;
1781 __COUT__ <<
"Attempting to play iteration plan '" << planName <<
".'" << __E__;
1787 if(theSupervisor_->VERBOSE_MUTEX)
1788 __COUT__ <<
"Waiting for iterator access" << __E__;
1789 std::lock_guard<std::mutex> lock(accessMutex_);
1790 if(theSupervisor_->VERBOSE_MUTEX)
1791 __COUT__ <<
"Have iterator access" << __E__;
1793 if(!activePlanIsRunning_ && !commandPlay_)
1795 if(!workloopRunning_)
1799 workloopRunning_ =
true;
1802 std::thread([](
Iterator* iterator) { Iterator::IteratorWorkLoop(iterator); },
1807 activePlanName_ = planName;
1808 commandPlay_ =
true;
1812 __SS__ <<
"Invalid play command attempted. Can only play when the Iterator is "
1813 "inactive or paused."
1814 <<
" If you would like to restart an iteration plan, first try halting."
1816 __MOUT__ << ss.str();
1818 xmldoc.addTextElementToData(
"error_message", ss.str());
1820 __COUT__ <<
"Invalid play command attempted. " << commandPlay_ <<
" "
1821 << activePlanName_ << __E__;
1828 __MOUT__ <<
"Attempting to pause iteration plan '" << activePlanName_ <<
".'"
1830 __COUT__ <<
"Attempting to pause iteration plan '" << activePlanName_ <<
".'"
1837 if(theSupervisor_->VERBOSE_MUTEX)
1838 __COUT__ <<
"Waiting for iterator access" << __E__;
1839 std::lock_guard<std::mutex> lock(accessMutex_);
1840 if(theSupervisor_->VERBOSE_MUTEX)
1841 __COUT__ <<
"Have iterator access" << __E__;
1843 if(workloopRunning_ && activePlanIsRunning_ && !commandPause_)
1845 commandPause_ =
true;
1849 __SS__ <<
"Invalid pause command attempted. Can only pause when running."
1851 __MOUT__ << ss.str();
1853 xmldoc.addTextElementToData(
"error_message", ss.str());
1855 __COUT__ <<
"Invalid pause command attempted. " << workloopRunning_ <<
" "
1856 << activePlanIsRunning_ <<
" " << commandPause_ <<
" " << activePlanName_
1864 __MOUT__ <<
"Attempting to halt iteration plan '" << activePlanName_ <<
".'" << __E__;
1865 __COUT__ <<
"Attempting to halt iteration plan '" << activePlanName_ <<
".'" << __E__;
1869 if(workloopRunning_)
1873 if(theSupervisor_->VERBOSE_MUTEX)
1874 __COUT__ <<
"Waiting for iterator access" << __E__;
1875 std::lock_guard<std::mutex> lock(accessMutex_);
1876 if(theSupervisor_->VERBOSE_MUTEX)
1877 __COUT__ <<
"Have iterator access" << __E__;
1879 __COUT__ <<
"activePlanIsRunning_: " << activePlanIsRunning_ << __E__;
1880 __COUT__ <<
"Passing halt command to iterator thread." << __E__;
1881 commandHalt_ =
true;
1884 activePlanName_ =
"";
1885 activeCommandIndex_ = -1;
1889 __COUT__ <<
"No thread, so conducting halt." << __E__;
1890 Iterator::haltIterator(
this);
1929 xmldoc.addTextElementToData(
1931 theSupervisor_->theStateMachine_.isInTransition()
1932 ? theSupervisor_->theStateMachine_.getCurrentTransitionName(
1933 theSupervisor_->stateMachineLastCommandInput_)
1934 : theSupervisor_->theStateMachine_.getCurrentStateName());
1938 if(theSupervisor_->theStateMachine_.isInTransition())
1939 xmldoc.addTextElementToData(
1940 "transition_progress",
1941 theSupervisor_->theProgressBar_.readPercentageString());
1943 xmldoc.addTextElementToData(
"transition_progress",
"100");
1946 sprintf(tmp,
"%lu", theSupervisor_->theStateMachine_.getTimeInState());
1947 xmldoc.addTextElementToData(
"time_in_state", tmp);
1951 if(theSupervisor_->VERBOSE_MUTEX)
1952 __COUT__ <<
"Waiting for iterator access" << __E__;
1953 std::lock_guard<std::mutex> lock(accessMutex_);
1954 if(theSupervisor_->VERBOSE_MUTEX)
1955 __COUT__ <<
"Have iterator access" << __E__;
1957 xmldoc.addTextElementToData(
"active_plan", activePlanName_);
1958 xmldoc.addTextElementToData(
"last_started_plan", lastStartedPlanName_);
1959 xmldoc.addTextElementToData(
"last_finished_plan", lastFinishedPlanName_);
1961 sprintf(tmp,
"%u", activeCommandIndex_);
1962 xmldoc.addTextElementToData(
"current_command_index", tmp);
1963 sprintf(tmp,
"%ld", time(0) - activeCommandStartTime_);
1964 xmldoc.addTextElementToData(
"current_command_duration", tmp);
1965 sprintf(tmp,
"%u", activeCommandIteration_);
1966 xmldoc.addTextElementToData(
"current_command_iteration", tmp);
1968 for(
const auto& depthIteration : depthIterationStack_)
1970 sprintf(tmp,
"%u", depthIteration);
1971 xmldoc.addTextElementToData(
"depth_iteration", tmp);
1974 if(activePlanIsRunning_ && iteratorBusy_)
1976 if(workloopRunning_)
1977 xmldoc.addTextElementToData(
"active_plan_status",
"Running");
1979 xmldoc.addTextElementToData(
"active_plan_status",
"Error");
1981 else if(!activePlanIsRunning_ && iteratorBusy_)
1982 xmldoc.addTextElementToData(
"active_plan_status",
"Paused");
1984 xmldoc.addTextElementToData(
"active_plan_status",
"Inactive");
1986 xmldoc.addTextElementToData(
"error_message", errorMessage_);