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_ =
"";
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;
926 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_]
927 .params_[IterateTable::commandRunParams_.DurationInSeconds_]
930 &iteratorStruct->originalDurationInSeconds_);
931 __COUTV__(iteratorStruct->originalDurationInSeconds_);
935 <<
"FSM in transition = "
936 << iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition()
938 __COUT__ <<
"startCommandRun success." << __E__;
942 void Iterator::startCommandConfigureActive(IteratorWorkLoopStruct* iteratorStruct)
944 __COUT__ <<
"startCommandConfigureActive " << __E__;
950 std::string group = iteratorStruct->cfgMgr_->getActiveGroupName();
951 TableGroupKey key = iteratorStruct->cfgMgr_->getActiveGroupKey();
953 __COUT__ <<
"group " << group << __E__;
954 __COUT__ <<
"key " << key << __E__;
958 std::stringstream systemAlias;
959 systemAlias <<
"GROUP:" << group <<
":" << key;
960 startCommandConfigureAlias(iteratorStruct, systemAlias.str());
964 void Iterator::startCommandConfigureGroup(IteratorWorkLoopStruct* iteratorStruct)
966 __COUT__ <<
"startCommandConfigureGroup " << __E__;
972 iteratorStruct->commands_[iteratorStruct->commandIndex_]
973 .params_[IterateTable::commandConfigureGroupParams_.GroupName_];
975 TableGroupKey(iteratorStruct->commands_[iteratorStruct->commandIndex_]
976 .params_[IterateTable::commandConfigureGroupParams_.GroupKey_]);
978 __COUT__ <<
"group " << group << __E__;
979 __COUT__ <<
"key " << key << __E__;
983 std::stringstream systemAlias;
984 systemAlias <<
"GROUP:" << group <<
":" << key;
985 startCommandConfigureAlias(iteratorStruct, systemAlias.str());
989 void Iterator::startCommandConfigureAlias(IteratorWorkLoopStruct* iteratorStruct,
990 const std::string& systemAlias)
992 __COUT__ <<
"systemAlias " << systemAlias << __E__;
994 iteratorStruct->fsmCommandParameters_.clear();
995 iteratorStruct->fsmCommandParameters_.push_back(systemAlias);
997 std::string errorStr =
"";
998 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
999 ->theStateMachine_.getCurrentStateName();
1003 if(currentState ==
"Initial")
1005 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1009 iteratorStruct->fsmName_,
1010 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1011 WebUsers::DEFAULT_ITERATOR_USERNAME,
1012 iteratorStruct->fsmCommandParameters_);
1013 else if(currentState ==
"Halted")
1015 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1019 iteratorStruct->fsmName_,
1020 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1021 WebUsers::DEFAULT_ITERATOR_USERNAME,
1022 iteratorStruct->fsmCommandParameters_);
1023 else if(currentState ==
"Configured")
1025 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1029 iteratorStruct->fsmName_,
1030 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1031 WebUsers::DEFAULT_ITERATOR_USERNAME,
1032 iteratorStruct->fsmCommandParameters_);
1035 "Can only Configure from the Initial or Halted state. The current state is " +
1040 __SS__ <<
"Iterator failed to configure with system alias '"
1041 << (iteratorStruct->fsmCommandParameters_.size()
1042 ? iteratorStruct->fsmCommandParameters_[0]
1044 <<
"' because of the following error: " << errorStr;
1050 <<
"FSM in transition = "
1051 << iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition()
1053 __COUT__ <<
"startCommandConfigureAlias success." << __E__;
1057 void Iterator::startCommandMacro(IteratorWorkLoopStruct* iteratorStruct,
1058 bool isFrontEndMacro)
1066 const std::string& macroName =
1067 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1068 .params_[IterateTable::commandExecuteMacroParams_.MacroName_];
1069 const std::string& enableSavingOutput =
1070 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1071 .params_[IterateTable::commandExecuteMacroParams_.EnableSavingOutput_];
1072 const std::string& outputFilePath =
1073 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1074 .params_[IterateTable::commandExecuteMacroParams_.OutputFilePath_];
1075 const std::string& outputFileRadix =
1076 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1077 .params_[IterateTable::commandExecuteMacroParams_.OutputFileRadix_];
1078 const std::string& inputArgs =
1079 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1080 .params_[IterateTable::commandExecuteMacroParams_.MacroArgumentString_];
1082 __COUTV__(macroName);
1083 __COUTV__(enableSavingOutput);
1084 __COUTV__(outputFilePath);
1085 __COUTV__(outputFileRadix);
1086 __COUTV__(inputArgs);
1094 iteratorStruct->targetsDone_.clear();
1096 __COUTV__(iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_.size());
1097 for(
const auto& target :
1098 iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_)
1100 __COUT__ <<
"target " << target.table_ <<
":" << target.UID_ << __E__;
1103 iteratorStruct->targetsDone_.push_back(
false);
1105 xoap::MessageReference message =
1106 SOAPUtilities::makeSOAPMessageReference(
"FECommunication");
1109 std::string type = isFrontEndMacro ?
"feMacroMultiDimensionalStart"
1110 :
"macroMultiDimensionalStart";
1111 parameters.addParameter(
"type", type);
1112 parameters.addParameter(
"requester", WebUsers::DEFAULT_ITERATOR_USERNAME);
1113 parameters.addParameter(
"targetInterfaceID", target.UID_);
1114 parameters.addParameter(isFrontEndMacro ?
"feMacroName" :
"macroName", macroName);
1115 parameters.addParameter(
"enableSavingOutput", enableSavingOutput);
1116 parameters.addParameter(
"outputFilePath", outputFilePath);
1117 parameters.addParameter(
"outputFileRadix", outputFileRadix);
1118 parameters.addParameter(
"inputArgs", inputArgs);
1119 SOAPUtilities::addParameters(message, parameters);
1121 __COUT__ <<
"Sending FE communication: " << SOAPUtilities::translate(message)
1124 xoap::MessageReference replyMessage =
1125 iteratorStruct->theIterator_->theSupervisor_
1126 ->SOAPMessenger::sendWithSOAPReply(
1127 iteratorStruct->theIterator_->theSupervisor_->allSupervisorInfo_
1128 .getAllMacroMakerTypeSupervisorInfo()
1130 ->second.getDescriptor(),
1133 __COUT__ <<
"Response received: " << SOAPUtilities::translate(replyMessage)
1137 rxParameters.addParameter(
"Error");
1138 std::string response = SOAPUtilities::receive(replyMessage, rxParameters);
1140 std::string error = rxParameters.getValue(
"Error");
1142 if(response != type +
"Done" || error !=
"")
1145 __SS__ <<
"Error transmitting request to target interface '" << target.UID_
1146 <<
"' from '" << WebUsers::DEFAULT_ITERATOR_USERNAME <<
".' Response '"
1147 << response <<
"' with error: " << error << __E__;
1155 bool Iterator::checkCommandMacro(IteratorWorkLoopStruct* iteratorStruct,
1156 bool isFrontEndMacro)
1166 const std::string& macroName =
1167 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1168 .params_[IterateTable::commandExecuteMacroParams_.MacroName_];
1170 __COUTV__(macroName);
1175 for(
unsigned int i = 0;
1176 i < iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_.size();
1180 iteratorStruct->commands_[iteratorStruct->commandIndex_].targets_[i];
1182 __COUT__ <<
"target " << target.table_ <<
":" << target.UID_ << __E__;
1184 xoap::MessageReference message =
1185 SOAPUtilities::makeSOAPMessageReference(
"FECommunication");
1188 std::string type = isFrontEndMacro ?
"feMacroMultiDimensionalCheck"
1189 :
"macroMultiDimensionalCheck";
1190 parameters.addParameter(
"type", type);
1191 parameters.addParameter(
"requester", WebUsers::DEFAULT_ITERATOR_USERNAME);
1192 parameters.addParameter(
"targetInterfaceID", target.UID_);
1193 parameters.addParameter(isFrontEndMacro ?
"feMacroName" :
"macroName", macroName);
1194 SOAPUtilities::addParameters(message, parameters);
1196 __COUT__ <<
"Sending FE communication: " << SOAPUtilities::translate(message)
1199 xoap::MessageReference replyMessage =
1200 iteratorStruct->theIterator_->theSupervisor_
1201 ->SOAPMessenger::sendWithSOAPReply(
1202 iteratorStruct->theIterator_->theSupervisor_->allSupervisorInfo_
1203 .getAllMacroMakerTypeSupervisorInfo()
1205 ->second.getDescriptor(),
1208 __COUT__ <<
"Response received: " << SOAPUtilities::translate(replyMessage)
1212 rxParameters.addParameter(
"Error");
1213 rxParameters.addParameter(
"Done");
1214 std::string response = SOAPUtilities::receive(replyMessage, rxParameters);
1216 std::string error = rxParameters.getValue(
"Error");
1217 bool done = rxParameters.getValue(
"Done") ==
"1";
1219 if(response != type +
"Done" || error !=
"")
1222 __SS__ <<
"Error transmitting request to target interface '" << target.UID_
1223 <<
"' from '" << WebUsers::DEFAULT_ITERATOR_USERNAME <<
".' Response '"
1224 << response <<
"' with error: " << error << __E__;
1232 iteratorStruct->targetsDone_[i] =
true;
1244 void Iterator::startCommandModifyActive(IteratorWorkLoopStruct* iteratorStruct)
1265 bool doTrackGroupChanges =
false;
1267 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1268 .params_[IterateTable::commandModifyActiveParams_.DoTrackGroupChanges_])
1269 doTrackGroupChanges =
true;
1271 const std::string& startValueStr =
1272 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1273 .params_[IterateTable::commandModifyActiveParams_.FieldStartValue_];
1274 const std::string& stepSizeStr =
1275 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1276 .params_[IterateTable::commandModifyActiveParams_.FieldIterationStepSize_];
1278 const unsigned int stepIndex = iteratorStruct->stepIndexStack_.back();
1280 __COUT__ <<
"doTrackGroupChanges " << (doTrackGroupChanges ?
"yes" :
"no")
1282 __COUT__ <<
"stepIndex " << stepIndex << std::endl;
1284 ConfigurationInterface::setVersionTrackingEnabled(doTrackGroupChanges);
1288 if(startValueStr.size() && (startValueStr[startValueStr.size() - 1] ==
'f' ||
1289 startValueStr.find(
'.') != std::string::npos))
1292 double startValue = strtod(startValueStr.c_str(), 0);
1293 double stepSize = strtod(stepSizeStr.c_str(), 0);
1295 __COUT__ <<
"startValue " << startValue << std::endl;
1296 __COUT__ <<
"stepSize " << stepSize << std::endl;
1297 __COUT__ <<
"currentValue " << startValue + stepSize * stepIndex << std::endl;
1299 helpCommandModifyActive(
1300 iteratorStruct, startValue + stepSize * stepIndex, doTrackGroupChanges);
1304 long int startValue;
1307 StringMacros::getNumber(startValueStr, startValue);
1308 StringMacros::getNumber(startValueStr, stepSize);
1329 __COUT__ <<
"startValue " << startValue << std::endl;
1330 __COUT__ <<
"stepSize " << stepSize << std::endl;
1331 __COUT__ <<
"currentValue " << startValue + stepSize * stepIndex << std::endl;
1333 helpCommandModifyActive(
1334 iteratorStruct, startValue + stepSize * stepIndex, doTrackGroupChanges);
1348 bool Iterator::checkCommandRun(IteratorWorkLoopStruct* iteratorStruct)
1357 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1358 __COUT__ <<
"Waiting for FSM access" << __E__;
1359 std::lock_guard<std::mutex> lock(
1360 iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
1361 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1362 __COUT__ <<
"Have FSM access" << __E__;
1364 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition())
1367 iteratorStruct->fsmCommandParameters_.clear();
1369 std::string errorStr =
"";
1370 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
1371 ->theStateMachine_.getCurrentStateName();
1375 if(iteratorStruct->doPauseAction_)
1378 __COUT__ <<
"Transitioning FSM to Paused..." << __E__;
1380 if(currentState ==
"Paused")
1383 __COUT__ <<
"Transition to Paused complete." << __E__;
1386 else if(currentState ==
"Running")
1387 errorStr = iteratorStruct->theIterator_->theSupervisor_
1388 ->attemptStateMachineTransition(
1392 iteratorStruct->fsmName_,
1393 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1394 WebUsers::DEFAULT_ITERATOR_USERNAME,
1395 iteratorStruct->fsmCommandParameters_);
1396 else if(currentState ==
"Configured")
1399 __COUT__ <<
"In Configured state. No need to transition to Paused." << __E__;
1403 errorStr =
"Expected to be in Paused. Unexpectedly, the current state is " +
1405 ". Last State Machine error message was as follows: " +
1406 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
1411 __SS__ <<
"Iterator failed to pause because of the following error: "
1417 else if(iteratorStruct->doHaltAction_)
1420 __COUT__ <<
"Transitioning FSM to Halted..." << __E__;
1422 if(currentState ==
"Halted")
1425 __COUT__ <<
"Transition to Halted complete." << __E__;
1428 else if(currentState ==
"Running" ||
1429 currentState ==
"Paused")
1430 errorStr = iteratorStruct->theIterator_->theSupervisor_
1431 ->attemptStateMachineTransition(
1435 iteratorStruct->fsmName_,
1436 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1437 WebUsers::DEFAULT_ITERATOR_USERNAME,
1438 iteratorStruct->fsmCommandParameters_);
1439 else if(currentState ==
"Configured")
1440 errorStr = iteratorStruct->theIterator_->theSupervisor_
1441 ->attemptStateMachineTransition(
1445 iteratorStruct->fsmName_,
1446 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1447 WebUsers::DEFAULT_ITERATOR_USERNAME,
1448 iteratorStruct->fsmCommandParameters_);
1450 errorStr =
"Expected to be in Halted. Unexpectedly, the current state is " +
1452 ". Last State Machine error message was as follows: " +
1453 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
1458 __SS__ <<
"Iterator failed to halt because of the following error: "
1464 else if(iteratorStruct->doResumeAction_)
1469 __COUT__ <<
"Transitioning FSM to Running..." << __E__;
1471 if(currentState ==
"Paused")
1472 errorStr = iteratorStruct->theIterator_->theSupervisor_
1473 ->attemptStateMachineTransition(
1477 iteratorStruct->fsmName_,
1478 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1479 WebUsers::DEFAULT_ITERATOR_USERNAME,
1480 iteratorStruct->fsmCommandParameters_);
1484 __SS__ <<
"Iterator failed to run because of the following error: "
1494 if(currentState !=
"Running")
1496 if(iteratorStruct->runIsDone_ && currentState ==
"Configured")
1499 __COUT__ <<
"Reached end of run " << iteratorStruct->fsmNextRunNumber_
1504 errorStr =
"Expected to be in Running. Unexpectedly, the current state is " +
1505 currentState +
". Last State Machine error message was as follows: " +
1506 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
1511 bool waitOnRunningThreads =
false;
1512 if(
"True" == iteratorStruct->commands_[iteratorStruct->commandIndex_]
1513 .params_[IterateTable::commandRunParams_.WaitOnRunningThreads_])
1514 waitOnRunningThreads =
true;
1516 time_t remainingDurationInSeconds;
1517 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_]
1518 .params_[IterateTable::commandRunParams_.DurationInSeconds_]
1521 &remainingDurationInSeconds);
1523 __COUT__ <<
"waitOnRunningThreads " << waitOnRunningThreads << __E__;
1524 __COUT__ <<
"remainingDurationInSeconds " << remainingDurationInSeconds << __E__;
1528 if(waitOnRunningThreads)
1532 iteratorStruct->theIterator_->theSupervisor_;
1534 bool allFrontEndsAreDone =
true;
1535 for(
auto& it : theSupervisor->allSupervisorInfo_.getAllFETypeSupervisorInfo())
1539 std::string status = theSupervisor->send(it.second.getDescriptor(),
1540 "WorkLoopStatusRequest");
1542 __COUT__ <<
"FESupervisor instance " << it.first
1543 <<
" has status = " << status << std::endl;
1545 if(status != CoreSupervisorBase::WORK_LOOP_DONE)
1547 allFrontEndsAreDone =
false;
1551 catch(xdaq::exception::Exception& e)
1553 __SS__ <<
"Could not retrieve status from FESupervisor instance "
1554 << it.first <<
"." << std::endl;
1555 __COUT_WARN__ << ss.str();
1556 errorStr = ss.str();
1561 <<
"Iterator failed to run because of the following error: "
1568 if(allFrontEndsAreDone)
1571 __COUT__ <<
"FE workloops all complete! Stopping run..." << __E__;
1573 errorStr = iteratorStruct->theIterator_->theSupervisor_
1574 ->attemptStateMachineTransition(
1578 iteratorStruct->fsmName_,
1579 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1580 WebUsers::DEFAULT_ITERATOR_USERNAME,
1581 iteratorStruct->fsmCommandParameters_);
1586 <<
"Iterator failed to stop run because of the following error: "
1592 iteratorStruct->runIsDone_ =
true;
1600 if(remainingDurationInSeconds > 1)
1602 --remainingDurationInSeconds;
1606 sprintf(str,
"%ld", remainingDurationInSeconds);
1607 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1608 .params_[IterateTable::commandRunParams_.DurationInSeconds_] =
1611 else if(remainingDurationInSeconds == 1)
1614 __COUT__ <<
"Time duration reached! Stopping run..." << __E__;
1616 errorStr = iteratorStruct->theIterator_->theSupervisor_
1617 ->attemptStateMachineTransition(
1621 iteratorStruct->fsmName_,
1622 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1623 WebUsers::DEFAULT_ITERATOR_USERNAME,
1624 iteratorStruct->fsmCommandParameters_);
1628 __SS__ <<
"Iterator failed to stop run because of the following error: "
1634 iteratorStruct->runIsDone_ =
true;
1638 sprintf(str,
"%ld", iteratorStruct->originalDurationInSeconds_);
1639 iteratorStruct->commands_[iteratorStruct->commandIndex_]
1640 .params_[IterateTable::commandRunParams_.DurationInSeconds_] =
1648 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
1656 bool Iterator::checkCommandConfigure(IteratorWorkLoopStruct* iteratorStruct)
1665 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1666 __COUT__ <<
"Waiting for FSM access" << __E__;
1667 std::lock_guard<std::mutex> lock(
1668 iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
1669 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX)
1670 __COUT__ <<
"Have FSM access" << __E__;
1672 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition())
1675 std::string errorStr =
"";
1676 std::string currentState = iteratorStruct->theIterator_->theSupervisor_
1677 ->theStateMachine_.getCurrentStateName();
1679 if(currentState ==
"Halted")
1681 iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1685 iteratorStruct->fsmName_,
1686 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1687 WebUsers::DEFAULT_ITERATOR_USERNAME,
1688 iteratorStruct->fsmCommandParameters_);
1689 else if(currentState !=
"Configured")
1690 errorStr =
"Expected to be in Configure. Unexpectedly, the current state is " +
1691 currentState +
"." +
1692 ". Last State Machine error message was as follows: " +
1693 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_
1697 __COUT__ <<
"checkCommandConfigureAlias complete." << __E__;
1700 std::pair<std::string, TableGroupKey> newActiveGroup =
1701 iteratorStruct->cfgMgr_->getTableGroupFromAlias(
1702 iteratorStruct->fsmCommandParameters_[0]);
1703 iteratorStruct->cfgMgr_->loadTableGroup(
1704 newActiveGroup.first, newActiveGroup.second,
true );
1706 __COUT__ <<
"originalTrackChanges " << iteratorStruct->originalTrackChanges_
1708 __COUT__ <<
"originalConfigGroup " << iteratorStruct->originalConfigGroup_
1710 __COUT__ <<
"originalConfigKey " << iteratorStruct->originalConfigKey_ << __E__;
1712 __COUT__ <<
"currentTrackChanges "
1713 << ConfigurationInterface::isVersionTrackingEnabled() << __E__;
1714 __COUT__ <<
"originalConfigGroup "
1715 << iteratorStruct->cfgMgr_->getActiveGroupName() << __E__;
1716 __COUT__ <<
"originalConfigKey " << iteratorStruct->cfgMgr_->getActiveGroupKey()
1724 __SS__ <<
"Iterator failed to configure with system alias '"
1725 << (iteratorStruct->fsmCommandParameters_.size()
1726 ? iteratorStruct->fsmCommandParameters_[0]
1728 <<
"' because of the following error: " << errorStr;
1736 const std::string& command,
1737 const std::string& parameter)
1740 if(command ==
"iteratePlay")
1742 playIterationPlan(xmldoc, parameter);
1745 else if(command ==
"iteratePause")
1747 pauseIterationPlan(xmldoc);
1750 else if(command ==
"iterateHalt")
1752 haltIterationPlan(xmldoc);
1755 else if(command ==
"getIterationPlanStatus")
1757 getIterationPlanStatus(xmldoc);
1764 if(theSupervisor_->VERBOSE_MUTEX)
1765 __COUT__ <<
"Waiting for iterator access" << __E__;
1766 std::lock_guard<std::mutex> lock(accessMutex_);
1767 if(theSupervisor_->VERBOSE_MUTEX)
1768 __COUT__ <<
"Have iterator access" << __E__;
1772 __SS__ <<
"Error - Can not accept request because the Iterator "
1774 <<
"in control of State Machine progress. ";
1775 __COUT_ERR__ <<
"\n" << ss.str();
1776 __MOUT_ERR__ <<
"\n" << ss.str();
1778 xmldoc.addTextElementToData(
"state_tranisition_attempted",
1780 xmldoc.addTextElementToData(
1781 "state_tranisition_attempted_err",
1791 void Iterator::playIterationPlan(
HttpXmlDocument& xmldoc,
const std::string& planName)
1793 __MOUT__ <<
"Attempting to play iteration plan '" << planName <<
".'" << __E__;
1794 __COUT__ <<
"Attempting to play iteration plan '" << planName <<
".'" << __E__;
1800 if(theSupervisor_->VERBOSE_MUTEX)
1801 __COUT__ <<
"Waiting for iterator access" << __E__;
1802 std::lock_guard<std::mutex> lock(accessMutex_);
1803 if(theSupervisor_->VERBOSE_MUTEX)
1804 __COUT__ <<
"Have iterator access" << __E__;
1806 if(!activePlanIsRunning_ && !commandPlay_)
1808 if(!workloopRunning_)
1812 workloopRunning_ =
true;
1815 std::thread([](
Iterator* iterator) { Iterator::IteratorWorkLoop(iterator); },
1820 activePlanName_ = planName;
1821 commandPlay_ =
true;
1825 __SS__ <<
"Invalid play command attempted. Can only play when the Iterator is "
1826 "inactive or paused."
1827 <<
" If you would like to restart an iteration plan, first try halting."
1829 __MOUT__ << ss.str();
1831 xmldoc.addTextElementToData(
"error_message", ss.str());
1833 __COUT__ <<
"Invalid play command attempted. " << commandPlay_ <<
" "
1834 << activePlanName_ << __E__;
1841 __MOUT__ <<
"Attempting to pause iteration plan '" << activePlanName_ <<
".'"
1843 __COUT__ <<
"Attempting to pause iteration plan '" << activePlanName_ <<
".'"
1850 if(theSupervisor_->VERBOSE_MUTEX)
1851 __COUT__ <<
"Waiting for iterator access" << __E__;
1852 std::lock_guard<std::mutex> lock(accessMutex_);
1853 if(theSupervisor_->VERBOSE_MUTEX)
1854 __COUT__ <<
"Have iterator access" << __E__;
1856 if(workloopRunning_ && activePlanIsRunning_ && !commandPause_)
1858 commandPause_ =
true;
1862 __SS__ <<
"Invalid pause command attempted. Can only pause when running."
1864 __MOUT__ << ss.str();
1866 xmldoc.addTextElementToData(
"error_message", ss.str());
1868 __COUT__ <<
"Invalid pause command attempted. " << workloopRunning_ <<
" "
1869 << activePlanIsRunning_ <<
" " << commandPause_ <<
" " << activePlanName_
1877 __MOUT__ <<
"Attempting to halt iteration plan '" << activePlanName_ <<
".'" << __E__;
1878 __COUT__ <<
"Attempting to halt iteration plan '" << activePlanName_ <<
".'" << __E__;
1882 if(workloopRunning_)
1886 if(theSupervisor_->VERBOSE_MUTEX)
1887 __COUT__ <<
"Waiting for iterator access" << __E__;
1888 std::lock_guard<std::mutex> lock(accessMutex_);
1889 if(theSupervisor_->VERBOSE_MUTEX)
1890 __COUT__ <<
"Have iterator access" << __E__;
1892 __COUT__ <<
"activePlanIsRunning_: " << activePlanIsRunning_ << __E__;
1893 __COUT__ <<
"Passing halt command to iterator thread." << __E__;
1894 commandHalt_ =
true;
1897 activePlanName_ =
"";
1898 activeCommandIndex_ = -1;
1902 __COUT__ <<
"No thread, so conducting halt." << __E__;
1903 Iterator::haltIterator(
this);
1942 xmldoc.addTextElementToData(
1944 theSupervisor_->theStateMachine_.isInTransition()
1945 ? theSupervisor_->theStateMachine_.getCurrentTransitionName(
1946 theSupervisor_->stateMachineLastCommandInput_)
1947 : theSupervisor_->theStateMachine_.getCurrentStateName());
1951 if(theSupervisor_->theStateMachine_.isInTransition())
1952 xmldoc.addTextElementToData(
1953 "transition_progress",
1954 theSupervisor_->theProgressBar_.readPercentageString());
1956 xmldoc.addTextElementToData(
"transition_progress",
"100");
1959 sprintf(tmp,
"%lu", theSupervisor_->theStateMachine_.getTimeInState());
1960 xmldoc.addTextElementToData(
"time_in_state", tmp);
1964 if(theSupervisor_->VERBOSE_MUTEX)
1965 __COUT__ <<
"Waiting for iterator access" << __E__;
1966 std::lock_guard<std::mutex> lock(accessMutex_);
1967 if(theSupervisor_->VERBOSE_MUTEX)
1968 __COUT__ <<
"Have iterator access" << __E__;
1970 xmldoc.addTextElementToData(
"active_plan", activePlanName_);
1971 xmldoc.addTextElementToData(
"last_started_plan", lastStartedPlanName_);
1972 xmldoc.addTextElementToData(
"last_finished_plan", lastFinishedPlanName_);
1974 sprintf(tmp,
"%u", activeCommandIndex_);
1975 xmldoc.addTextElementToData(
"current_command_index", tmp);
1976 sprintf(tmp,
"%ld", time(0) - activeCommandStartTime_);
1977 xmldoc.addTextElementToData(
"current_command_duration", tmp);
1978 sprintf(tmp,
"%u", activeCommandIteration_);
1979 xmldoc.addTextElementToData(
"current_command_iteration", tmp);
1981 for(
const auto& depthIteration : depthIterationStack_)
1983 sprintf(tmp,
"%u", depthIteration);
1984 xmldoc.addTextElementToData(
"depth_iteration", tmp);
1987 if(activePlanIsRunning_ && iteratorBusy_)
1989 if(workloopRunning_)
1990 xmldoc.addTextElementToData(
"active_plan_status",
"Running");
1992 xmldoc.addTextElementToData(
"active_plan_status",
"Error");
1994 else if(!activePlanIsRunning_ && iteratorBusy_)
1995 xmldoc.addTextElementToData(
"active_plan_status",
"Paused");
1997 xmldoc.addTextElementToData(
"active_plan_status",
"Inactive");
1999 xmldoc.addTextElementToData(
"error_message", errorMessage_);