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"
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_ =
"";
57 theConfigurationManager.getAllTableInfo(
true);
59 IteratorWorkLoopStruct theIteratorStruct(iterator, &theConfigurationManager);
63 std::vector<IterateTable::Command> commands;
85 if(iterator->theSupervisor_->VERBOSE_MUTEX)
86 __COUT__ <<
"Waiting for iterator access" << __E__;
87 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
88 if(iterator->theSupervisor_->VERBOSE_MUTEX)
89 __COUT__ <<
"Have iterator access" << __E__;
91 if(iterator->commandPlay_)
93 iterator->commandPlay_ =
false;
95 if(!iterator->activePlanIsRunning_)
99 iterator->activePlanIsRunning_ =
true;
100 iterator->iteratorBusy_ =
true;
102 if(theIteratorStruct.activePlan_ != iterator->activePlanName_)
104 __COUT__ <<
"New plan name encountered old=" << theIteratorStruct.activePlan_ <<
" vs new=" << iterator->activePlanName_ << __E__;
105 theIteratorStruct.commandIndex_ = -1;
108 theIteratorStruct.activePlan_ = iterator->activePlanName_;
109 iterator->lastStartedPlanName_ = iterator->activePlanName_;
111 if(theIteratorStruct.commandIndex_ == (
unsigned int)-1)
113 __COUT__ <<
"Starting plan '" << theIteratorStruct.activePlan_ <<
".'" << __E__;
114 __MOUT__ <<
"Starting plan '" << theIteratorStruct.activePlan_ <<
".'" << __E__;
118 theIteratorStruct.doResumeAction_ =
true;
119 __COUT__ <<
"Continuing plan '" << theIteratorStruct.activePlan_ <<
"' at command index " << theIteratorStruct.commandIndex_ <<
". "
121 __MOUT__ <<
"Continuing plan '" << theIteratorStruct.activePlan_ <<
"' at command index " << theIteratorStruct.commandIndex_ <<
". "
126 else if(iterator->commandPause_ && !theIteratorStruct.doPauseAction_)
128 theIteratorStruct.doPauseAction_ =
true;
129 iterator->commandPause_ =
false;
131 else if(iterator->commandHalt_ && !theIteratorStruct.doHaltAction_)
133 theIteratorStruct.doHaltAction_ =
true;
134 iterator->commandHalt_ =
false;
137 theIteratorStruct.running_ = iterator->activePlanIsRunning_;
139 if(iterator->activeCommandIndex_ !=
140 theIteratorStruct.commandIndex_)
142 iterator->activeCommandIndex_ = theIteratorStruct.commandIndex_;
143 iterator->activeCommandStartTime_ = time(0);
145 if(theIteratorStruct.commandIndex_ < theIteratorStruct.commandIterations_.size())
146 iterator->activeCommandIteration_ = theIteratorStruct.commandIterations_[theIteratorStruct.commandIndex_];
148 iterator->activeCommandIteration_ = -1;
150 iterator->depthIterationStack_.clear();
151 for(
const auto& depthIteration : theIteratorStruct.stepIndexStack_)
152 iterator->depthIterationStack_.push_back(depthIteration);
165 if(theIteratorStruct.doPauseAction_)
172 __COUT__ <<
"Waiting to pause..." << __E__;
173 while(!iterator->checkCommand(&theIteratorStruct))
174 __COUT__ <<
"Waiting to pause..." << __E__;
176 __COUT__ <<
"Completing pause..." << __E__;
178 theIteratorStruct.doPauseAction_ =
false;
182 if(iterator->theSupervisor_->VERBOSE_MUTEX)
183 __COUT__ <<
"Waiting for iterator access" << __E__;
184 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
185 if(iterator->theSupervisor_->VERBOSE_MUTEX)
186 __COUT__ <<
"Have iterator access" << __E__;
188 iterator->activePlanIsRunning_ =
false;
190 __COUT__ <<
"Paused plan '" << theIteratorStruct.activePlan_ <<
"' at command index " << theIteratorStruct.commandIndex_ <<
". " << __E__;
191 __MOUT__ <<
"Paused plan '" << theIteratorStruct.activePlan_ <<
"' at command index " << theIteratorStruct.commandIndex_ <<
". " << __E__;
195 else if(theIteratorStruct.doHaltAction_)
202 __COUT__ <<
"Waiting to halt..." << __E__;
203 while(!iterator->checkCommand(&theIteratorStruct))
204 __COUT__ <<
"Waiting to halt..." << __E__;
206 __COUT__ <<
"Completing halt..." << __E__;
208 theIteratorStruct.doHaltAction_ =
false;
210 iterator->haltIterator(iterator, &theIteratorStruct);
248 if(theIteratorStruct.running_ && theIteratorStruct.activePlan_ !=
"")
250 if(theIteratorStruct.commandIndex_ == (
unsigned int)-1)
254 __COUT__ <<
"Get commands" << __E__;
256 theIteratorStruct.commandIndex_ = 0;
258 theIteratorStruct.cfgMgr_->init();
259 itConfig = theIteratorStruct.cfgMgr_->__GET_CONFIG__(
IterateTable);
261 theIteratorStruct.commands_ = itConfig->getPlanCommands(theIteratorStruct.cfgMgr_, theIteratorStruct.activePlan_);
264 theIteratorStruct.commandIterations_.clear();
265 for(
auto& command : theIteratorStruct.commands_)
267 theIteratorStruct.commandIterations_.push_back(0);
268 __COUT__ <<
"command " << command.type_ << __E__;
269 __COUT__ <<
"table " << IterateTable::commandToTableMap_.at(command.type_) << __E__;
270 __COUT__ <<
"param count = " << command.params_.size() << __E__;
272 for(
auto& param : command.params_)
274 __COUT__ <<
"\t param " << param.first <<
" : " << param.second << __E__;
278 theIteratorStruct.originalTrackChanges_ = ConfigurationInterface::isVersionTrackingEnabled();
279 theIteratorStruct.originalConfigGroup_ = theIteratorStruct.cfgMgr_->getActiveGroupName();
280 theIteratorStruct.originalConfigKey_ = theIteratorStruct.cfgMgr_->getActiveGroupKey();
282 __COUT__ <<
"originalTrackChanges " << theIteratorStruct.originalTrackChanges_ << __E__;
283 __COUT__ <<
"originalConfigGroup " << theIteratorStruct.originalConfigGroup_ << __E__;
284 __COUT__ <<
"originalConfigKey " << theIteratorStruct.originalConfigKey_ << __E__;
288 if(!theIteratorStruct.commandBusy_)
290 if(theIteratorStruct.commandIndex_ < theIteratorStruct.commands_.size())
293 theIteratorStruct.commandBusy_ =
true;
295 __COUT__ <<
"Iterator starting command " << theIteratorStruct.commandIndex_ + 1 <<
": "
296 << theIteratorStruct.commands_[theIteratorStruct.commandIndex_].type_ << __E__;
297 __MOUT__ <<
"Iterator starting command " << theIteratorStruct.commandIndex_ + 1 <<
": "
298 << theIteratorStruct.commands_[theIteratorStruct.commandIndex_].type_ << __E__;
300 iterator->startCommand(&theIteratorStruct);
302 else if(theIteratorStruct.commandIndex_ == theIteratorStruct.commands_.size())
304 __COUT__ <<
"Finished Iteration Plan '" << theIteratorStruct.activePlan_ << __E__;
305 __MOUT__ <<
"Finished Iteration Plan '" << theIteratorStruct.activePlan_ << __E__;
307 __COUT__ <<
"Reverting track changes." << __E__;
308 ConfigurationInterface::setVersionTrackingEnabled(theIteratorStruct.originalTrackChanges_);
310 __COUT__ <<
"Activating original group..." << __E__;
313 theIteratorStruct.cfgMgr_->activateTableGroup(theIteratorStruct.originalConfigGroup_, theIteratorStruct.originalConfigKey_);
317 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
321 __COUT__ <<
"Completing halt..." << __E__;
323 iterator->haltIterator(iterator, &theIteratorStruct);
354 else if(theIteratorStruct.commandBusy_)
357 if(iterator->checkCommand(&theIteratorStruct))
359 theIteratorStruct.commandBusy_ =
false;
361 ++theIteratorStruct.commandIndex_;
363 __COUT__ <<
"Ready for next command. Done with " << theIteratorStruct.commandIndex_ <<
" of " << theIteratorStruct.commands_.size()
365 __MOUT__ <<
"Iterator ready for next command. Done with " << theIteratorStruct.commandIndex_ <<
" of " << theIteratorStruct.commands_.size()
370 if(theIteratorStruct.doResumeAction_)
371 theIteratorStruct.doResumeAction_ =
false;
386 iterator->workloopRunning_ =
false;
388 catch(
const std::runtime_error& e)
390 __SS__ <<
"Encountered error in Iterator thread:\n" << e.what() << __E__;
391 __COUT_ERR__ << ss.str();
395 if(iterator->theSupervisor_->VERBOSE_MUTEX)
396 __COUT__ <<
"Waiting for iterator access" << __E__;
397 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
398 if(iterator->theSupervisor_->VERBOSE_MUTEX)
399 __COUT__ <<
"Have iterator access" << __E__;
401 iterator->workloopRunning_ =
false;
402 iterator->errorMessage_ = ss.str();
406 __SS__ <<
"Encountered unknown error in Iterator thread." << __E__;
407 __COUT_ERR__ << ss.str();
411 if(iterator->theSupervisor_->VERBOSE_MUTEX)
412 __COUT__ <<
"Waiting for iterator access" << __E__;
413 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
414 if(iterator->theSupervisor_->VERBOSE_MUTEX)
415 __COUT__ <<
"Have iterator access" << __E__;
417 iterator->workloopRunning_ =
false;
418 iterator->errorMessage_ = ss.str();
422 void Iterator::startCommand(IteratorWorkLoopStruct* iteratorStruct)
try
426 for(
const auto& depthIteration : iteratorStruct->stepIndexStack_)
428 __COUT__ << i++ <<
":" << depthIteration << __E__;
435 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
436 __COUT__ <<
"Waiting for FSM access" << __E__;
437 std::lock_guard<std::mutex> lock(iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
438 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
439 __COUT__ <<
"Have FSM access" << __E__;
442 if(iteratorStruct->commandIndex_ >= iteratorStruct->commands_.size())
444 __SS__ <<
"Out of range commandIndex = " << iteratorStruct->commandIndex_ <<
" in size = " << iteratorStruct->commands_.size() << __E__;
449 ++iteratorStruct->commandIterations_[iteratorStruct->commandIndex_];
451 std::string type = iteratorStruct->commands_[iteratorStruct->commandIndex_].type_;
452 if(type == IterateTable::COMMAND_BEGIN_LABEL)
454 return startCommandBeginLabel(iteratorStruct);
456 else if(type == IterateTable::COMMAND_CHOOSE_FSM)
458 return startCommandChooseFSM(iteratorStruct,
459 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandChooseFSMParams_.NameOfFSM_]);
461 else if(type == IterateTable::COMMAND_CONFIGURE_ACTIVE_GROUP)
463 return startCommandConfigureActive(iteratorStruct);
465 else if(type == IterateTable::COMMAND_CONFIGURE_ALIAS)
467 return startCommandConfigureAlias(
468 iteratorStruct, iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandConfigureAliasParams_.SystemAlias_]);
470 else if(type == IterateTable::COMMAND_CONFIGURE_GROUP)
472 return startCommandConfigureGroup(iteratorStruct);
474 else if(type == IterateTable::COMMAND_EXECUTE_FE_MACRO)
476 return startCommandMacro(iteratorStruct,
true );
478 else if(type == IterateTable::COMMAND_EXECUTE_MACRO)
480 return startCommandMacro(iteratorStruct,
false );
482 else if(type == IterateTable::COMMAND_MODIFY_ACTIVE_GROUP)
484 return startCommandModifyActive(iteratorStruct);
486 else if(type == IterateTable::COMMAND_REPEAT_LABEL)
488 return startCommandRepeatLabel(iteratorStruct);
490 else if(type == IterateTable::COMMAND_RUN)
492 return startCommandRun(iteratorStruct);
496 __SS__ <<
"Failed attempt to start unrecognized command type = " << type << __E__;
497 __COUT_ERR__ << ss.str();
503 __COUT__ <<
"Error caught. Reverting track changes." << __E__;
504 ConfigurationInterface::setVersionTrackingEnabled(iteratorStruct->originalTrackChanges_);
506 __COUT__ <<
"Activating original group..." << __E__;
509 iteratorStruct->cfgMgr_->activateTableGroup(iteratorStruct->originalConfigGroup_, iteratorStruct->originalConfigKey_);
513 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
522 bool Iterator::checkCommand(IteratorWorkLoopStruct* iteratorStruct)
try
525 if(iteratorStruct->commandIndex_ >= iteratorStruct->commands_.size())
527 __COUT__ <<
"Out of range commandIndex = " << iteratorStruct->commandIndex_ <<
" in size = " << iteratorStruct->commands_.size() << __E__;
531 std::string type = iteratorStruct->commands_[iteratorStruct->commandIndex_].type_;
532 if(type == IterateTable::COMMAND_BEGIN_LABEL)
537 else if(type == IterateTable::COMMAND_CHOOSE_FSM)
542 else if(type == IterateTable::COMMAND_CONFIGURE_ALIAS || type == IterateTable::COMMAND_CONFIGURE_ACTIVE_GROUP ||
543 type == IterateTable::COMMAND_CONFIGURE_GROUP)
545 return checkCommandConfigure(iteratorStruct);
547 else if(type == IterateTable::COMMAND_EXECUTE_FE_MACRO)
549 return checkCommandMacro(iteratorStruct,
true );
551 else if(type == IterateTable::COMMAND_EXECUTE_MACRO)
553 return checkCommandMacro(iteratorStruct,
false );
555 else if(type == IterateTable::COMMAND_MODIFY_ACTIVE_GROUP)
560 else if(type == IterateTable::COMMAND_REPEAT_LABEL)
565 else if(type == IterateTable::COMMAND_RUN)
567 return checkCommandRun(iteratorStruct);
571 __SS__ <<
"Attempt to check unrecognized command type = " << type << __E__;
572 __COUT_ERR__ << ss.str();
578 __COUT__ <<
"Error caught. Reverting track changes." << __E__;
579 ConfigurationInterface::setVersionTrackingEnabled(iteratorStruct->originalTrackChanges_);
581 __COUT__ <<
"Activating original group..." << __E__;
584 iteratorStruct->cfgMgr_->activateTableGroup(iteratorStruct->originalConfigGroup_, iteratorStruct->originalConfigKey_);
588 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
595 void Iterator::startCommandChooseFSM(IteratorWorkLoopStruct* iteratorStruct,
const std::string& fsmName)
597 __COUT__ <<
"fsmName " << fsmName << __E__;
599 iteratorStruct->fsmName_ = fsmName;
600 iteratorStruct->theIterator_->lastFsmName_ = fsmName;
609 iteratorStruct->fsmRunAlias_ =
"Run";
612 ConfigurationTree configLinkNode = iteratorStruct->cfgMgr_->getSupervisorTableNode(iteratorStruct->theIterator_->theSupervisor_->getContextUID(),
613 iteratorStruct->theIterator_->theSupervisor_->getSupervisorUID());
615 if(!configLinkNode.isDisconnected())
619 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineTable");
620 if(!fsmLinkNode.isDisconnected())
621 iteratorStruct->fsmRunAlias_ = fsmLinkNode.getNode(fsmName +
"/RunDisplayAlias").getValue<std::string>();
623 __COUT_INFO__ <<
"FSM Link disconnected." << __E__;
625 catch(std::runtime_error& e)
628 __COUT_INFO__ <<
"No state machine Run alias. Ignoring and assuming alias of '" << iteratorStruct->fsmRunAlias_ <<
".'" << __E__;
632 __COUT_ERR__ <<
"Unknown error. Should never happen." << __E__;
634 __COUT_INFO__ <<
"No state machine Run alias. Ignoring and assuming alias of '" << iteratorStruct->fsmRunAlias_ <<
".'" << __E__;
638 __COUT_INFO__ <<
"FSM Link disconnected." << __E__;
640 __COUT__ <<
"fsmRunAlias_ = " << iteratorStruct->fsmRunAlias_ << __E__;
644 iteratorStruct->fsmNextRunNumber_ = iteratorStruct->theIterator_->theSupervisor_->getNextRunNumber(iteratorStruct->fsmName_);
646 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getCurrentStateName() ==
"Running" ||
647 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getCurrentStateName() ==
"Paused")
648 --iteratorStruct->fsmNextRunNumber_;
650 __COUT__ <<
"fsmNextRunNumber_ = " << iteratorStruct->fsmNextRunNumber_ << __E__;
655 bool Iterator::haltIterator(
Iterator* iterator, IteratorWorkLoopStruct* iteratorStruct)
659 const std::string& fsmName = iterator->lastFsmName_;
661 std::vector<std::string> fsmCommandParameters;
662 std::string errorStr =
"";
663 std::string currentState = theSupervisor->theStateMachine_.getCurrentStateName();
665 bool haltAttempted =
true;
666 if(currentState ==
"Initialized" || currentState ==
"Halted")
668 __COUT__ <<
"Do nothing. Already halted." << __E__;
669 haltAttempted =
false;
671 else if(currentState ==
"Running")
672 errorStr = theSupervisor->attemptStateMachineTransition(
673 0, 0,
"Abort", fsmName, WebUsers::DEFAULT_ITERATOR_USERNAME , WebUsers::DEFAULT_ITERATOR_USERNAME, fsmCommandParameters);
675 errorStr = theSupervisor->attemptStateMachineTransition(
676 0, 0,
"Halt", fsmName, WebUsers::DEFAULT_ITERATOR_USERNAME , WebUsers::DEFAULT_ITERATOR_USERNAME, fsmCommandParameters);
682 __SS__ <<
"Iterator failed to halt because of the following error: " << errorStr;
687 __COUT__ <<
"FSM in transition = " << theSupervisor->theStateMachine_.isInTransition() << __E__;
688 __COUT__ <<
"halting state machine launched." << __E__;
692 __COUT__ <<
"Conducting Iterator halt." << __E__;
696 __COUT__ <<
"Reverting track changes." << __E__;
697 ConfigurationInterface::setVersionTrackingEnabled(iteratorStruct->originalTrackChanges_);
699 __COUT__ <<
"Activating original group..." << __E__;
702 iteratorStruct->cfgMgr_->activateTableGroup(iteratorStruct->originalConfigGroup_, iteratorStruct->originalConfigKey_);
706 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
712 if(iterator->theSupervisor_->VERBOSE_MUTEX)
713 __COUT__ <<
"Waiting for iterator access" << __E__;
714 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
715 if(iterator->theSupervisor_->VERBOSE_MUTEX)
716 __COUT__ <<
"Have iterator access" << __E__;
718 iterator->activePlanIsRunning_ =
false;
719 iterator->iteratorBusy_ =
false;
722 iterator->activePlanName_ =
"";
723 iterator->activeCommandIndex_ = -1;
727 __COUT__ <<
"Halted plan '" << iteratorStruct->activePlan_ <<
"' at command index " << iteratorStruct->commandIndex_ <<
". " << __E__;
728 __MOUT__ <<
"Halted plan '" << iteratorStruct->activePlan_ <<
"' at command index " << iteratorStruct->commandIndex_ <<
". " << __E__;
730 iterator->lastStartedPlanName_ = iteratorStruct->activePlan_;
731 iteratorStruct->activePlan_ =
"";
732 iteratorStruct->commandIndex_ = -1;
735 return haltAttempted;
739 void Iterator::startCommandBeginLabel(IteratorWorkLoopStruct* iteratorStruct)
741 __COUT__ <<
"Entering label '" << iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandBeginLabelParams_.Label_] <<
"'..."
745 iteratorStruct->stepIndexStack_.push_back(0);
749 void Iterator::startCommandRepeatLabel(IteratorWorkLoopStruct* iteratorStruct)
753 int numOfRepetitions;
754 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandRepeatLabelParams_.NumberOfRepetitions_].c_str(),
757 __COUT__ <<
"numOfRepetitions remaining = " << numOfRepetitions << __E__;
761 if(numOfRepetitions <= 0)
764 sprintf(repStr,
"%d", iteratorStruct->stepIndexStack_.back());
765 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandRepeatLabelParams_.NumberOfRepetitions_] =
769 iteratorStruct->stepIndexStack_.pop_back();
777 ++(iteratorStruct->stepIndexStack_.back());
780 for(i = iteratorStruct->commandIndex_; i > 0; --i)
781 if(iteratorStruct->commands_[i].type_ == IterateTable::COMMAND_BEGIN_LABEL &&
782 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandRepeatLabelParams_.Label_] ==
783 iteratorStruct->commands_[i].params_[IterateTable::commandBeginLabelParams_.Label_])
786 sprintf(repStr,
"%d", numOfRepetitions);
787 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandRepeatLabelParams_.NumberOfRepetitions_] =
790 iteratorStruct->commandIndex_ = i;
791 __COUT__ <<
"Jumping back to commandIndex " << iteratorStruct->commandIndex_ << __E__;
795 void Iterator::startCommandRun(IteratorWorkLoopStruct* iteratorStruct)
797 iteratorStruct->runIsDone_ =
false;
798 iteratorStruct->fsmCommandParameters_.clear();
800 std::string errorStr =
"";
801 std::string currentState = iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getCurrentStateName();
805 if(currentState ==
"Configured")
806 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(0,
809 iteratorStruct->fsmName_,
810 WebUsers::DEFAULT_ITERATOR_USERNAME ,
811 WebUsers::DEFAULT_ITERATOR_USERNAME,
812 iteratorStruct->fsmCommandParameters_);
814 errorStr =
"Can only Run from the Configured state. The current state is " + currentState;
818 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
823 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandRunParams_.DurationInSeconds_].c_str(),
825 &iteratorStruct->originalDurationInSeconds_);
826 __COUTV__(iteratorStruct->originalDurationInSeconds_);
829 __COUT__ <<
"FSM in transition = " << iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition() << __E__;
830 __COUT__ <<
"startCommandRun success." << __E__;
834 void Iterator::startCommandConfigureActive(IteratorWorkLoopStruct* iteratorStruct)
836 __COUT__ <<
"startCommandConfigureActive " << __E__;
842 std::string group = iteratorStruct->cfgMgr_->getActiveGroupName();
843 TableGroupKey key = iteratorStruct->cfgMgr_->getActiveGroupKey();
845 __COUT__ <<
"group " << group << __E__;
846 __COUT__ <<
"key " << key << __E__;
850 std::stringstream systemAlias;
851 systemAlias <<
"GROUP:" << group <<
":" << key;
852 startCommandConfigureAlias(iteratorStruct, systemAlias.str());
856 void Iterator::startCommandConfigureGroup(IteratorWorkLoopStruct* iteratorStruct)
858 __COUT__ <<
"startCommandConfigureGroup " << __E__;
863 std::string group = iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandConfigureGroupParams_.GroupName_];
864 TableGroupKey key =
TableGroupKey(iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandConfigureGroupParams_.GroupKey_]);
866 __COUT__ <<
"group " << group << __E__;
867 __COUT__ <<
"key " << key << __E__;
871 std::stringstream systemAlias;
872 systemAlias <<
"GROUP:" << group <<
":" << key;
873 startCommandConfigureAlias(iteratorStruct, systemAlias.str());
877 void Iterator::startCommandConfigureAlias(IteratorWorkLoopStruct* iteratorStruct,
const std::string& systemAlias)
879 __COUT__ <<
"systemAlias " << systemAlias << __E__;
881 iteratorStruct->fsmCommandParameters_.clear();
882 iteratorStruct->fsmCommandParameters_.push_back(systemAlias);
884 std::string errorStr =
"";
885 std::string currentState = iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getCurrentStateName();
889 if(currentState ==
"Initial")
890 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(0,
893 iteratorStruct->fsmName_,
894 WebUsers::DEFAULT_ITERATOR_USERNAME ,
895 WebUsers::DEFAULT_ITERATOR_USERNAME,
896 iteratorStruct->fsmCommandParameters_);
897 else if(currentState ==
"Halted")
898 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(0,
901 iteratorStruct->fsmName_,
902 WebUsers::DEFAULT_ITERATOR_USERNAME ,
903 WebUsers::DEFAULT_ITERATOR_USERNAME,
904 iteratorStruct->fsmCommandParameters_);
905 else if(currentState ==
"Configured")
906 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(0,
909 iteratorStruct->fsmName_,
910 WebUsers::DEFAULT_ITERATOR_USERNAME ,
911 WebUsers::DEFAULT_ITERATOR_USERNAME,
912 iteratorStruct->fsmCommandParameters_);
914 errorStr =
"Can only Configure from the Initial or Halted state. The current state is " + currentState;
918 __SS__ <<
"Iterator failed to configure with system alias '"
919 << (iteratorStruct->fsmCommandParameters_.size() ? iteratorStruct->fsmCommandParameters_[0] :
"UNKNOWN")
920 <<
"' because of the following error: " << errorStr;
925 __COUT__ <<
"FSM in transition = " << iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition() << __E__;
926 __COUT__ <<
"startCommandConfigureAlias success." << __E__;
930 void Iterator::startCommandMacro(IteratorWorkLoopStruct* iteratorStruct,
bool isFrontEndMacro)
938 const std::string& macroName = iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandExecuteMacroParams_.MacroName_];
939 const std::string& enableSavingOutput =
940 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandExecuteMacroParams_.EnableSavingOutput_];
941 const std::string& outputFilePath =
942 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandExecuteMacroParams_.OutputFilePath_];
943 const std::string& outputFileRadix =
944 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandExecuteMacroParams_.OutputFileRadix_];
945 const std::string& inputArgs =
946 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandExecuteMacroParams_.MacroArgumentString_];
948 __COUTV__(macroName);
949 __COUTV__(enableSavingOutput);
950 __COUTV__(outputFilePath);
951 __COUTV__(outputFileRadix);
952 __COUTV__(inputArgs);
960 iteratorStruct->targetsDone_.clear();
962 __COUTV__(iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_.size());
963 for(
const auto& target : iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_)
965 __COUT__ <<
"target " << target.table_ <<
":" << target.UID_ << __E__;
968 iteratorStruct->targetsDone_.push_back(
false);
970 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(
"FECommunication");
973 std::string type = isFrontEndMacro ?
"feMacroMultiDimensionalStart" :
"macroMultiDimensionalStart";
974 parameters.addParameter(
"type", type);
975 parameters.addParameter(
"requester", WebUsers::DEFAULT_ITERATOR_USERNAME);
976 parameters.addParameter(
"targetInterfaceID", target.UID_);
977 parameters.addParameter(isFrontEndMacro ?
"feMacroName" :
"macroName", macroName);
978 parameters.addParameter(
"enableSavingOutput", enableSavingOutput);
979 parameters.addParameter(
"outputFilePath", outputFilePath);
980 parameters.addParameter(
"outputFileRadix", outputFileRadix);
981 parameters.addParameter(
"inputArgs", inputArgs);
982 SOAPUtilities::addParameters(message, parameters);
984 __COUT__ <<
"Sending FE communication: " << SOAPUtilities::translate(message) << __E__;
986 xoap::MessageReference replyMessage = iteratorStruct->theIterator_->theSupervisor_->SOAPMessenger::sendWithSOAPReply(
987 iteratorStruct->theIterator_->theSupervisor_->allSupervisorInfo_.getAllMacroMakerTypeSupervisorInfo().begin()->second.getDescriptor(), message);
989 __COUT__ <<
"Response received: " << SOAPUtilities::translate(replyMessage) << __E__;
992 rxParameters.addParameter(
"Error");
993 std::string response = SOAPUtilities::receive(replyMessage, rxParameters);
995 std::string error = rxParameters.getValue(
"Error");
997 if(response != type +
"Done" || error !=
"")
1000 __SS__ <<
"Error transmitting request to target interface '" << target.UID_ <<
"' from '" << WebUsers::DEFAULT_ITERATOR_USERNAME <<
".' Response '"
1001 << response <<
"' with error: " << error << __E__;
1009 bool Iterator::checkCommandMacro(IteratorWorkLoopStruct* iteratorStruct,
bool isFrontEndMacro)
1019 const std::string& macroName = iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandExecuteMacroParams_.MacroName_];
1021 __COUTV__(macroName);
1026 for(
unsigned int i = 0; i < iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_.size(); ++i)
1030 __COUT__ <<
"target " << target.table_ <<
":" << target.UID_ << __E__;
1032 xoap::MessageReference message = SOAPUtilities::makeSOAPMessageReference(
"FECommunication");
1035 std::string type = isFrontEndMacro ?
"feMacroMultiDimensionalCheck" :
"macroMultiDimensionalCheck";
1036 parameters.addParameter(
"type", type);
1037 parameters.addParameter(
"requester", WebUsers::DEFAULT_ITERATOR_USERNAME);
1038 parameters.addParameter(
"targetInterfaceID", target.UID_);
1039 parameters.addParameter(isFrontEndMacro ?
"feMacroName" :
"macroName", macroName);
1040 SOAPUtilities::addParameters(message, parameters);
1042 __COUT__ <<
"Sending FE communication: " << SOAPUtilities::translate(message) << __E__;
1044 xoap::MessageReference replyMessage = iteratorStruct->theIterator_->theSupervisor_->SOAPMessenger::sendWithSOAPReply(
1045 iteratorStruct->theIterator_->theSupervisor_->allSupervisorInfo_.getAllMacroMakerTypeSupervisorInfo().begin()->second.getDescriptor(), message);
1047 __COUT__ <<
"Response received: " << SOAPUtilities::translate(replyMessage) << __E__;
1050 rxParameters.addParameter(
"Error");
1051 rxParameters.addParameter(
"Done");
1052 std::string response = SOAPUtilities::receive(replyMessage, rxParameters);
1054 std::string error = rxParameters.getValue(
"Error");
1055 bool done = rxParameters.getValue(
"Done") ==
"1";
1057 if(response != type +
"Done" || error !=
"")
1060 __SS__ <<
"Error transmitting request to target interface '" << target.UID_ <<
"' from '" << WebUsers::DEFAULT_ITERATOR_USERNAME <<
".' Response '"
1061 << response <<
"' with error: " << error << __E__;
1069 iteratorStruct->targetsDone_[i] =
true;
1081 void Iterator::startCommandModifyActive(IteratorWorkLoopStruct* iteratorStruct)
1102 bool doTrackGroupChanges =
false;
1103 if(
"True" == iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandModifyActiveParams_.DoTrackGroupChanges_])
1104 doTrackGroupChanges =
true;
1106 const std::string& startValueStr =
1107 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandModifyActiveParams_.FieldStartValue_];
1108 const std::string& stepSizeStr =
1109 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandModifyActiveParams_.FieldIterationStepSize_];
1111 const unsigned int stepIndex = iteratorStruct->stepIndexStack_.back();
1113 __COUT__ <<
"doTrackGroupChanges " << (doTrackGroupChanges ?
"yes" :
"no") << std::endl;
1114 __COUT__ <<
"stepIndex " << stepIndex << std::endl;
1116 ConfigurationInterface::setVersionTrackingEnabled(doTrackGroupChanges);
1120 if(startValueStr.size() && (startValueStr[startValueStr.size() - 1] ==
'f' || startValueStr.find(
'.') != std::string::npos))
1123 double startValue = strtod(startValueStr.c_str(), 0);
1124 double stepSize = strtod(stepSizeStr.c_str(), 0);
1126 __COUT__ <<
"startValue " << startValue << std::endl;
1127 __COUT__ <<
"stepSize " << stepSize << std::endl;
1128 __COUT__ <<
"currentValue " << startValue + stepSize * stepIndex << std::endl;
1130 helpCommandModifyActive(iteratorStruct, startValue + stepSize * stepIndex, doTrackGroupChanges);
1134 long int startValue;
1137 StringMacros::getNumber(startValueStr, startValue);
1138 StringMacros::getNumber(startValueStr, stepSize);
1159 __COUT__ <<
"startValue " << startValue << std::endl;
1160 __COUT__ <<
"stepSize " << stepSize << std::endl;
1161 __COUT__ <<
"currentValue " << startValue + stepSize * stepIndex << std::endl;
1163 helpCommandModifyActive(iteratorStruct, startValue + stepSize * stepIndex, doTrackGroupChanges);
1177 bool Iterator::checkCommandRun(IteratorWorkLoopStruct* iteratorStruct)
1186 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1187 __COUT__ <<
"Waiting for FSM access" << __E__;
1188 std::lock_guard<std::mutex> lock(iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
1189 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1190 __COUT__ <<
"Have FSM access" << __E__;
1192 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition())
1195 iteratorStruct->fsmCommandParameters_.clear();
1197 std::string errorStr =
"";
1198 std::string currentState = iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getCurrentStateName();
1202 if(iteratorStruct->doPauseAction_)
1205 __COUT__ <<
"Transitioning FSM to Paused..." << __E__;
1207 if(currentState ==
"Paused")
1210 __COUT__ <<
"Transition to Paused complete." << __E__;
1213 else if(currentState ==
"Running")
1214 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(0,
1217 iteratorStruct->fsmName_,
1218 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1219 WebUsers::DEFAULT_ITERATOR_USERNAME,
1220 iteratorStruct->fsmCommandParameters_);
1221 else if(currentState ==
"Configured")
1224 __COUT__ <<
"In Configured state. No need to transition to Paused." << __E__;
1228 errorStr =
"Expected to be in Paused. Unexpectedly, the current state is " + currentState +
1229 ". Last State Machine error message was as follows: " + iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getErrorMessage();
1233 __SS__ <<
"Iterator failed to pause because of the following error: " << errorStr;
1238 else if(iteratorStruct->doHaltAction_)
1241 __COUT__ <<
"Transitioning FSM to Halted..." << __E__;
1243 if(currentState ==
"Halted")
1246 __COUT__ <<
"Transition to Halted complete." << __E__;
1249 else if(currentState ==
"Running" ||
1250 currentState ==
"Paused")
1251 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(0,
1254 iteratorStruct->fsmName_,
1255 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1256 WebUsers::DEFAULT_ITERATOR_USERNAME,
1257 iteratorStruct->fsmCommandParameters_);
1258 else if(currentState ==
"Configured")
1259 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(0,
1262 iteratorStruct->fsmName_,
1263 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1264 WebUsers::DEFAULT_ITERATOR_USERNAME,
1265 iteratorStruct->fsmCommandParameters_);
1267 errorStr =
"Expected to be in Halted. Unexpectedly, the current state is " + currentState +
1268 ". Last State Machine error message was as follows: " + iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getErrorMessage();
1272 __SS__ <<
"Iterator failed to halt because of the following error: " << errorStr;
1277 else if(iteratorStruct->doResumeAction_)
1282 __COUT__ <<
"Transitioning FSM to Running..." << __E__;
1284 if(currentState ==
"Paused")
1285 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(0,
1288 iteratorStruct->fsmName_,
1289 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1290 WebUsers::DEFAULT_ITERATOR_USERNAME,
1291 iteratorStruct->fsmCommandParameters_);
1295 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
1304 if(currentState !=
"Running")
1306 if(iteratorStruct->runIsDone_ && currentState ==
"Configured")
1309 __COUT__ <<
"Reached end of run " << iteratorStruct->fsmNextRunNumber_ << __E__;
1313 errorStr =
"Expected to be in Running. Unexpectedly, the current state is " + currentState +
1314 ". Last State Machine error message was as follows: " + iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getErrorMessage();
1318 bool waitOnRunningThreads =
false;
1319 if(
"True" == iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandRunParams_.WaitOnRunningThreads_])
1320 waitOnRunningThreads =
true;
1322 time_t remainingDurationInSeconds;
1323 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandRunParams_.DurationInSeconds_].c_str(),
1325 &remainingDurationInSeconds);
1327 __COUT__ <<
"waitOnRunningThreads " << waitOnRunningThreads << __E__;
1328 __COUT__ <<
"remainingDurationInSeconds " << remainingDurationInSeconds << __E__;
1332 if(waitOnRunningThreads)
1335 GatewaySupervisor* theSupervisor = iteratorStruct->theIterator_->theSupervisor_;
1337 bool allFrontEndsAreDone =
true;
1338 for(
auto& it : theSupervisor->allSupervisorInfo_.getAllFETypeSupervisorInfo())
1342 std::string status = theSupervisor->send(it.second.getDescriptor(),
"WorkLoopStatusRequest");
1344 __COUT__ <<
"FESupervisor instance " << it.first <<
" has status = " << status << std::endl;
1346 if(status != CoreSupervisorBase::WORK_LOOP_DONE)
1348 allFrontEndsAreDone =
false;
1352 catch(xdaq::exception::Exception& e)
1354 __SS__ <<
"Could not retrieve status from FESupervisor instance " << it.first <<
"." << std::endl;
1355 __COUT_WARN__ << ss.str();
1356 errorStr = ss.str();
1360 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
1366 if(allFrontEndsAreDone)
1369 __COUT__ <<
"FE workloops all complete! Stopping run..." << __E__;
1371 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(0,
1374 iteratorStruct->fsmName_,
1375 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1376 WebUsers::DEFAULT_ITERATOR_USERNAME,
1377 iteratorStruct->fsmCommandParameters_);
1381 __SS__ <<
"Iterator failed to stop run because of the following error: " << errorStr;
1386 iteratorStruct->runIsDone_ =
true;
1394 if(remainingDurationInSeconds > 1)
1396 --remainingDurationInSeconds;
1400 sprintf(str,
"%ld", remainingDurationInSeconds);
1401 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandRunParams_.DurationInSeconds_] = str;
1403 else if(remainingDurationInSeconds == 1)
1406 __COUT__ <<
"Time duration reached! Stopping run..." << __E__;
1408 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(0,
1411 iteratorStruct->fsmName_,
1412 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1413 WebUsers::DEFAULT_ITERATOR_USERNAME,
1414 iteratorStruct->fsmCommandParameters_);
1418 __SS__ <<
"Iterator failed to stop run because of the following error: " << errorStr;
1423 iteratorStruct->runIsDone_ =
true;
1427 sprintf(str,
"%ld", iteratorStruct->originalDurationInSeconds_);
1428 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateTable::commandRunParams_.DurationInSeconds_] = str;
1435 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
1443 bool Iterator::checkCommandConfigure(IteratorWorkLoopStruct* iteratorStruct)
1452 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1453 __COUT__ <<
"Waiting for FSM access" << __E__;
1454 std::lock_guard<std::mutex> lock(iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
1455 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1456 __COUT__ <<
"Have FSM access" << __E__;
1458 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition())
1461 std::string errorStr =
"";
1462 std::string currentState = iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getCurrentStateName();
1464 if(currentState ==
"Halted")
1465 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(0,
1468 iteratorStruct->fsmName_,
1469 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1470 WebUsers::DEFAULT_ITERATOR_USERNAME,
1471 iteratorStruct->fsmCommandParameters_);
1472 else if(currentState !=
"Configured")
1473 errorStr =
"Expected to be in Configure. Unexpectedly, the current state is " + currentState +
"." +
1474 ". Last State Machine error message was as follows: " + iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getErrorMessage();
1477 __COUT__ <<
"checkCommandConfigureAlias complete." << __E__;
1480 std::pair<std::string, TableGroupKey> newActiveGroup = iteratorStruct->cfgMgr_->getTableGroupFromAlias(iteratorStruct->fsmCommandParameters_[0]);
1481 iteratorStruct->cfgMgr_->loadTableGroup(newActiveGroup.first, newActiveGroup.second,
true );
1483 __COUT__ <<
"originalTrackChanges " << iteratorStruct->originalTrackChanges_ << __E__;
1484 __COUT__ <<
"originalConfigGroup " << iteratorStruct->originalConfigGroup_ << __E__;
1485 __COUT__ <<
"originalConfigKey " << iteratorStruct->originalConfigKey_ << __E__;
1487 __COUT__ <<
"currentTrackChanges " << ConfigurationInterface::isVersionTrackingEnabled() << __E__;
1488 __COUT__ <<
"originalConfigGroup " << iteratorStruct->cfgMgr_->getActiveGroupName() << __E__;
1489 __COUT__ <<
"originalConfigKey " << iteratorStruct->cfgMgr_->getActiveGroupKey() << __E__;
1496 __SS__ <<
"Iterator failed to configure with system alias '"
1497 << (iteratorStruct->fsmCommandParameters_.size() ? iteratorStruct->fsmCommandParameters_[0] :
"UNKNOWN")
1498 <<
"' because of the following error: " << errorStr;
1505 bool Iterator::handleCommandRequest(
HttpXmlDocument& xmldoc,
const std::string& command,
const std::string& parameter)
1508 if(command ==
"iteratePlay")
1510 playIterationPlan(xmldoc, parameter);
1513 else if(command ==
"iteratePause")
1515 pauseIterationPlan(xmldoc);
1518 else if(command ==
"iterateHalt")
1520 haltIterationPlan(xmldoc);
1523 else if(command ==
"getIterationPlanStatus")
1525 getIterationPlanStatus(xmldoc);
1532 if(theSupervisor_->VERBOSE_MUTEX)
1533 __COUT__ <<
"Waiting for iterator access" << __E__;
1534 std::lock_guard<std::mutex> lock(accessMutex_);
1535 if(theSupervisor_->VERBOSE_MUTEX)
1536 __COUT__ <<
"Have iterator access" << __E__;
1540 __SS__ <<
"Error - Can not accept request because the Iterator "
1542 <<
"in control of State Machine progress. ";
1543 __COUT_ERR__ <<
"\n" << ss.str();
1544 __MOUT_ERR__ <<
"\n" << ss.str();
1546 xmldoc.addTextElementToData(
"state_tranisition_attempted",
1548 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
1558 void Iterator::playIterationPlan(
HttpXmlDocument& xmldoc,
const std::string& planName)
1560 __MOUT__ <<
"Attempting to play iteration plan '" << planName <<
".'" << __E__;
1561 __COUT__ <<
"Attempting to play iteration plan '" << planName <<
".'" << __E__;
1567 if(theSupervisor_->VERBOSE_MUTEX)
1568 __COUT__ <<
"Waiting for iterator access" << __E__;
1569 std::lock_guard<std::mutex> lock(accessMutex_);
1570 if(theSupervisor_->VERBOSE_MUTEX)
1571 __COUT__ <<
"Have iterator access" << __E__;
1573 if(!activePlanIsRunning_ && !commandPlay_)
1575 if(!workloopRunning_)
1579 workloopRunning_ =
true;
1582 std::thread([](
Iterator* iterator) { Iterator::IteratorWorkLoop(iterator); },
this).detach();
1585 activePlanName_ = planName;
1586 commandPlay_ =
true;
1590 __SS__ <<
"Invalid play command attempted. Can only play when the Iterator is "
1591 "inactive or paused."
1592 <<
" If you would like to restart an iteration plan, first try halting." << __E__;
1593 __MOUT__ << ss.str();
1595 xmldoc.addTextElementToData(
"error_message", ss.str());
1597 __COUT__ <<
"Invalid play command attempted. " << commandPlay_ <<
" " << activePlanName_ << __E__;
1604 __MOUT__ <<
"Attempting to pause iteration plan '" << activePlanName_ <<
".'" << __E__;
1605 __COUT__ <<
"Attempting to pause iteration plan '" << activePlanName_ <<
".'" << __E__;
1611 if(theSupervisor_->VERBOSE_MUTEX)
1612 __COUT__ <<
"Waiting for iterator access" << __E__;
1613 std::lock_guard<std::mutex> lock(accessMutex_);
1614 if(theSupervisor_->VERBOSE_MUTEX)
1615 __COUT__ <<
"Have iterator access" << __E__;
1617 if(workloopRunning_ && activePlanIsRunning_ && !commandPause_)
1619 commandPause_ =
true;
1623 __SS__ <<
"Invalid pause command attempted. Can only pause when running." << __E__;
1624 __MOUT__ << ss.str();
1626 xmldoc.addTextElementToData(
"error_message", ss.str());
1628 __COUT__ <<
"Invalid pause command attempted. " << workloopRunning_ <<
" " << activePlanIsRunning_ <<
" " << commandPause_ <<
" " << activePlanName_
1636 __MOUT__ <<
"Attempting to halt iteration plan '" << activePlanName_ <<
".'" << __E__;
1637 __COUT__ <<
"Attempting to halt iteration plan '" << activePlanName_ <<
".'" << __E__;
1641 if(workloopRunning_)
1645 if(theSupervisor_->VERBOSE_MUTEX)
1646 __COUT__ <<
"Waiting for iterator access" << __E__;
1647 std::lock_guard<std::mutex> lock(accessMutex_);
1648 if(theSupervisor_->VERBOSE_MUTEX)
1649 __COUT__ <<
"Have iterator access" << __E__;
1651 __COUT__ <<
"activePlanIsRunning_: " << activePlanIsRunning_ << __E__;
1652 __COUT__ <<
"Passing halt command to iterator thread." << __E__;
1653 commandHalt_ =
true;
1656 activePlanName_ =
"";
1657 activeCommandIndex_ = -1;
1661 __COUT__ <<
"No thread, so conducting halt." << __E__;
1662 Iterator::haltIterator(
this);
1701 xmldoc.addTextElementToData(
"current_state",
1702 theSupervisor_->theStateMachine_.isInTransition()
1703 ? theSupervisor_->theStateMachine_.getCurrentTransitionName(theSupervisor_->stateMachineLastCommandInput_)
1704 : theSupervisor_->theStateMachine_.getCurrentStateName());
1708 if(theSupervisor_->theStateMachine_.isInTransition())
1709 xmldoc.addTextElementToData(
"transition_progress", theSupervisor_->theProgressBar_.readPercentageString());
1711 xmldoc.addTextElementToData(
"transition_progress",
"100");
1714 sprintf(tmp,
"%lu", theSupervisor_->theStateMachine_.getTimeInState());
1715 xmldoc.addTextElementToData(
"time_in_state", tmp);
1719 if(theSupervisor_->VERBOSE_MUTEX)
1720 __COUT__ <<
"Waiting for iterator access" << __E__;
1721 std::lock_guard<std::mutex> lock(accessMutex_);
1722 if(theSupervisor_->VERBOSE_MUTEX)
1723 __COUT__ <<
"Have iterator access" << __E__;
1725 xmldoc.addTextElementToData(
"active_plan", activePlanName_);
1726 xmldoc.addTextElementToData(
"last_started_plan", lastStartedPlanName_);
1727 xmldoc.addTextElementToData(
"last_finished_plan", lastFinishedPlanName_);
1729 sprintf(tmp,
"%u", activeCommandIndex_);
1730 xmldoc.addTextElementToData(
"current_command_index", tmp);
1731 sprintf(tmp,
"%ld", time(0) - activeCommandStartTime_);
1732 xmldoc.addTextElementToData(
"current_command_duration", tmp);
1733 sprintf(tmp,
"%u", activeCommandIteration_);
1734 xmldoc.addTextElementToData(
"current_command_iteration", tmp);
1736 for(
const auto& depthIteration : depthIterationStack_)
1738 sprintf(tmp,
"%u", depthIteration);
1739 xmldoc.addTextElementToData(
"depth_iteration", tmp);
1742 if(activePlanIsRunning_ && iteratorBusy_)
1744 if(workloopRunning_)
1745 xmldoc.addTextElementToData(
"active_plan_status",
"Running");
1747 xmldoc.addTextElementToData(
"active_plan_status",
"Error");
1749 else if(!activePlanIsRunning_ && iteratorBusy_)
1750 xmldoc.addTextElementToData(
"active_plan_status",
"Paused");
1752 xmldoc.addTextElementToData(
"active_plan_status",
"Inactive");
1754 xmldoc.addTextElementToData(
"error_message", errorMessage_);