1 #include "otsdaq-core/GatewaySupervisor/Iterator.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
4 #include "otsdaq-core/GatewaySupervisor/GatewaySupervisor.h"
5 #include "otsdaq-core/CoreSupervisors/CoreSupervisorBase.h"
6 #include "otsdaq-core/WebUsersUtilities/WebUsers.h"
13 #define __MF_SUBJECT__ "Iterator"
19 : workloopRunning_ (false)
20 , activePlanIsRunning_ (false)
21 , iteratorBusy_ (false)
22 , commandPlay_(false), commandPause_(false), commandHalt_(false)
23 , activePlanName_ (
"")
24 , activeCommandIndex_ (-1)
25 , activeCommandStartTime_ (0)
26 , theSupervisor_ (supervisor)
28 __MOUT__ <<
"Iterator constructed." << __E__;
29 __COUT__ <<
"Iterator constructed." << __E__;
34 Iterator::~Iterator(
void)
39 void Iterator::IteratorWorkLoop(
Iterator *iterator)
42 __MOUT__ <<
"Iterator work loop starting..." << __E__;
43 __COUT__ <<
"Iterator work loop starting..." << __E__;
49 if(iterator->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for iterator access" << __E__;
50 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
51 if(iterator->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have iterator access" << __E__;
53 iterator->errorMessage_ =
"";
59 theConfigurationManager.getAllConfigurationInfo(
true);
61 IteratorWorkLoopStruct theIteratorStruct(iterator,
62 &theConfigurationManager);
67 std::vector<IterateConfiguration::Command> commands;
89 if(iterator->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for iterator access" << __E__;
90 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
91 if(iterator->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have iterator access" << __E__;
93 if(iterator->commandPlay_)
95 iterator->commandPlay_ =
false;
97 if(!iterator->activePlanIsRunning_)
101 iterator->activePlanIsRunning_ =
true;
102 iterator->iteratorBusy_ =
true;
104 if(theIteratorStruct.activePlan_ != iterator->activePlanName_)
106 __COUT__ <<
"New plan name encountered old=" << 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_ <<
".'" << __E__;
117 __MOUT__ <<
"Starting plan '" << theIteratorStruct.activePlan_ <<
".'" << __E__;
121 theIteratorStruct.doResumeAction_ =
true;
122 __COUT__ <<
"Continuing plan '" << theIteratorStruct.activePlan_ <<
"' at command index " <<
123 theIteratorStruct.commandIndex_ <<
". " << __E__;
124 __MOUT__ <<
"Continuing plan '" << theIteratorStruct.activePlan_ <<
"' at command index " <<
125 theIteratorStruct.commandIndex_ <<
". " << __E__;
129 else if(iterator->commandPause_ && !theIteratorStruct.doPauseAction_)
131 theIteratorStruct.doPauseAction_ =
true;
132 iterator->commandPause_ =
false;
134 else if(iterator->commandHalt_ && !theIteratorStruct.doHaltAction_)
136 theIteratorStruct.doHaltAction_ =
true;
137 iterator->commandHalt_ =
false;
140 theIteratorStruct.running_ = iterator->activePlanIsRunning_;
142 if(iterator->activeCommandIndex_ !=
143 theIteratorStruct.commandIndex_)
145 iterator->activeCommandIndex_ = theIteratorStruct.commandIndex_;
146 iterator->activeCommandStartTime_ = time(0);
148 if(theIteratorStruct.commandIndex_ < theIteratorStruct.commandIterations_.size())
149 iterator->activeCommandIteration_ = theIteratorStruct.commandIterations_
150 [theIteratorStruct.commandIndex_];
152 iterator->activeCommandIteration_ = -1;
154 iterator->depthIterationStack_.clear();
155 for(
const auto& depthIteration:theIteratorStruct.stepIndexStack_)
156 iterator->depthIterationStack_.push_back(depthIteration);
170 if(theIteratorStruct.doPauseAction_)
177 __COUT__ <<
"Waiting to pause..." << __E__;
178 while(!iterator->checkCommand(&theIteratorStruct))
179 __COUT__ <<
"Waiting to pause..." << __E__;
181 __COUT__ <<
"Completing pause..." << __E__;
183 theIteratorStruct.doPauseAction_ =
false;
187 if(iterator->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for iterator access" << __E__;
188 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
189 if(iterator->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have iterator access" << __E__;
191 iterator->activePlanIsRunning_ =
false;
193 __COUT__ <<
"Paused plan '" << theIteratorStruct.activePlan_ <<
"' at command index " <<
194 theIteratorStruct.commandIndex_ <<
". " << __E__;
195 __MOUT__ <<
"Paused plan '" << theIteratorStruct.activePlan_ <<
"' at command index " <<
196 theIteratorStruct.commandIndex_ <<
". " << __E__;
200 else if(theIteratorStruct.doHaltAction_)
207 __COUT__ <<
"Waiting to halt..." << __E__;
208 while(!iterator->checkCommand(&theIteratorStruct))
209 __COUT__ <<
"Waiting to halt..." << __E__;
211 __COUT__ <<
"Completing halt..." << __E__;
213 theIteratorStruct.doHaltAction_ =
false;
215 iterator->haltIterator(iterator,&theIteratorStruct);
249 if(theIteratorStruct.running_ &&
250 theIteratorStruct.activePlan_ !=
"")
252 if(theIteratorStruct.commandIndex_ == (
unsigned int)-1)
256 __COUT__ <<
"Get commands" << __E__;
258 theIteratorStruct.commandIndex_ = 0;
260 theIteratorStruct.cfgMgr_->init();
263 theIteratorStruct.commands_ = itConfig->getPlanCommands(
264 theIteratorStruct.cfgMgr_,
265 theIteratorStruct.activePlan_);
268 theIteratorStruct.commandIterations_.clear();
269 for(
auto& command:theIteratorStruct.commands_)
271 theIteratorStruct.commandIterations_.push_back(0);
272 __COUT__ <<
"command " <<
273 command.type_ << __E__;
274 __COUT__ <<
"table " <<
275 IterateConfiguration::commandToTableMap_.at(command.type_) << __E__;
276 __COUT__ <<
"param count = " << command.params_.size() << __E__;
278 for(
auto& param:command.params_)
280 __COUT__ <<
"\t param " <<
281 param.first <<
" : " <<
282 param.second << __E__;
287 theIteratorStruct.originalTrackChanges_ =
288 ConfigurationInterface::isVersionTrackingEnabled();
289 theIteratorStruct.originalConfigGroup_ =
290 theIteratorStruct.cfgMgr_->getActiveGroupName();
291 theIteratorStruct.originalConfigKey_ =
292 theIteratorStruct.cfgMgr_->getActiveGroupKey();
294 __COUT__ <<
"originalTrackChanges " <<
295 theIteratorStruct.originalTrackChanges_ << __E__;
296 __COUT__ <<
"originalConfigGroup " <<
297 theIteratorStruct.originalConfigGroup_ << __E__;
298 __COUT__ <<
"originalConfigKey " <<
299 theIteratorStruct.originalConfigKey_ << __E__;
304 if(!theIteratorStruct.commandBusy_)
306 if(theIteratorStruct.commandIndex_ < theIteratorStruct.commands_.size())
309 theIteratorStruct.commandBusy_ =
true;
311 __COUT__ <<
"Iterator starting command " << theIteratorStruct.commandIndex_+1 <<
": " <<
312 theIteratorStruct.commands_[theIteratorStruct.commandIndex_].type_ << __E__;
313 __MOUT__ <<
"Iterator starting command " << theIteratorStruct.commandIndex_+1 <<
": " <<
314 theIteratorStruct.commands_[theIteratorStruct.commandIndex_].type_ << __E__;
316 iterator->startCommand(&theIteratorStruct);
318 else if(theIteratorStruct.commandIndex_ ==
319 theIteratorStruct.commands_.size())
321 __COUT__ <<
"Finished Iteration Plan '" << theIteratorStruct.activePlan_ << __E__;
322 __MOUT__ <<
"Finished Iteration Plan '" << theIteratorStruct.activePlan_ << __E__;
324 __COUT__ <<
"Reverting track changes." << __E__;
325 ConfigurationInterface::setVersionTrackingEnabled(theIteratorStruct.originalTrackChanges_);
327 __COUT__ <<
"Activating original group..." << __E__;
330 theIteratorStruct.cfgMgr_->activateConfigurationGroup(
331 theIteratorStruct.originalConfigGroup_,theIteratorStruct.originalConfigKey_);
335 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
339 __COUT__ <<
"Completing halt..." << __E__;
341 iterator->haltIterator(iterator,&theIteratorStruct);
364 else if(theIteratorStruct.commandBusy_)
367 if(iterator->checkCommand(&theIteratorStruct))
369 theIteratorStruct.commandBusy_ =
false;
371 ++theIteratorStruct.commandIndex_;
373 __COUT__ <<
"Ready for next command. Done with " << theIteratorStruct.commandIndex_ <<
" of " <<
374 theIteratorStruct.commands_.size() << __E__;
375 __MOUT__ <<
"Iterator ready for next command. Done with " << theIteratorStruct.commandIndex_ <<
" of " <<
376 theIteratorStruct.commands_.size() << __E__;
380 if(theIteratorStruct.doResumeAction_)
381 theIteratorStruct.doResumeAction_ =
false;
399 iterator->workloopRunning_ =
false;
401 catch(
const std::runtime_error &e)
403 __SS__ <<
"Encountered error in Iterator thread:\n" << e.what() << __E__;
404 __COUT_ERR__ << ss.str();
408 if(iterator->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for iterator access" << __E__;
409 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
410 if(iterator->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have iterator access" << __E__;
412 iterator->workloopRunning_ =
false;
413 iterator->errorMessage_ = ss.str();
418 __SS__ <<
"Encountered unknown error in Iterator thread." << __E__;
419 __COUT_ERR__ << ss.str();
423 if(iterator->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for iterator access" << __E__;
424 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
425 if(iterator->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have iterator access" << __E__;
427 iterator->workloopRunning_ =
false;
428 iterator->errorMessage_ = ss.str();
432 void Iterator::startCommand(IteratorWorkLoopStruct *iteratorStruct)
438 for(
const auto& depthIteration:iteratorStruct->stepIndexStack_)
440 __COUT__ << i++ <<
":" << depthIteration << __E__;
449 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for FSM access" << __E__;
450 std::lock_guard<std::mutex> lock(iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
451 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have FSM access" << __E__;
455 if(iteratorStruct->commandIndex_ >= iteratorStruct->commands_.size())
457 __SS__ <<
"Out of range commandIndex = " << iteratorStruct->commandIndex_ <<
458 " in size = " << iteratorStruct->commands_.size() << __E__;
459 throw std::runtime_error(ss.str());
463 ++iteratorStruct->commandIterations_[iteratorStruct->commandIndex_];
466 std::string type = iteratorStruct->commands_[iteratorStruct->commandIndex_].type_;
467 if(type == IterateConfiguration::COMMAND_BEGIN_LABEL)
469 return startCommandBeginLabel(iteratorStruct);
471 else if(type == IterateConfiguration::COMMAND_CHOOSE_FSM)
473 return startCommandChooseFSM(
475 iteratorStruct->commands_
476 [iteratorStruct->commandIndex_].params_
477 [IterateConfiguration::commandChooseFSMParams_.NameOfFSM_]);
479 else if(type == IterateConfiguration::COMMAND_CONFIGURE_ACTIVE_GROUP)
481 return startCommandConfigureActive(iteratorStruct);
483 else if(type == IterateConfiguration::COMMAND_CONFIGURE_ALIAS)
485 return startCommandConfigureAlias(
487 iteratorStruct->commands_
488 [iteratorStruct->commandIndex_].params_
489 [IterateConfiguration::commandConfigureAliasParams_.SystemAlias_]);
491 else if(type == IterateConfiguration::COMMAND_CONFIGURE_GROUP)
493 return startCommandConfigureGroup(iteratorStruct);
495 else if(type == IterateConfiguration::COMMAND_EXECUTE_FE_MACRO)
500 else if(type == IterateConfiguration::COMMAND_EXECUTE_MACRO)
505 else if(type == IterateConfiguration::COMMAND_MODIFY_ACTIVE_GROUP)
507 return startCommandModifyActive(iteratorStruct);
509 else if(type == IterateConfiguration::COMMAND_REPEAT_LABEL)
511 return startCommandRepeatLabel(iteratorStruct);
513 else if(type == IterateConfiguration::COMMAND_RUN)
515 return startCommandRun(iteratorStruct);
519 __SS__ <<
"Attempt to start unrecognized command type = " << type << __E__;
520 __COUT_ERR__ << ss.str();
521 throw std::runtime_error(ss.str());
526 __COUT__ <<
"Error caught. Reverting track changes." << __E__;
527 ConfigurationInterface::setVersionTrackingEnabled(iteratorStruct->originalTrackChanges_);
529 __COUT__ <<
"Activating original group..." << __E__;
532 iteratorStruct->cfgMgr_->activateConfigurationGroup(
533 iteratorStruct->originalConfigGroup_,iteratorStruct->originalConfigKey_);
537 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
547 bool Iterator::checkCommand(IteratorWorkLoopStruct *iteratorStruct)
551 if(iteratorStruct->commandIndex_ >= iteratorStruct->commands_.size())
553 __COUT__ <<
"Out of range commandIndex = " << iteratorStruct->commandIndex_ <<
554 " in size = " << iteratorStruct->commands_.size() << __E__;
558 std::string type = iteratorStruct->commands_[iteratorStruct->commandIndex_].type_;
559 if(type == IterateConfiguration::COMMAND_BEGIN_LABEL)
564 else if(type == IterateConfiguration::COMMAND_CHOOSE_FSM)
569 else if(type == IterateConfiguration::COMMAND_CONFIGURE_ALIAS ||
570 type == IterateConfiguration::COMMAND_CONFIGURE_ACTIVE_GROUP ||
571 type == IterateConfiguration::COMMAND_CONFIGURE_GROUP)
573 return checkCommandConfigure(iteratorStruct);
575 else if(type == IterateConfiguration::COMMAND_EXECUTE_FE_MACRO)
580 else if(type == IterateConfiguration::COMMAND_EXECUTE_MACRO)
585 else if(type == IterateConfiguration::COMMAND_MODIFY_ACTIVE_GROUP)
590 else if(type == IterateConfiguration::COMMAND_REPEAT_LABEL)
595 else if(type == IterateConfiguration::COMMAND_RUN)
597 return checkCommandRun(iteratorStruct);
601 __SS__ <<
"Attempt to check unrecognized command type = " << type << __E__;
602 __COUT_ERR__ << ss.str();
603 throw std::runtime_error(ss.str());
608 __COUT__ <<
"Error caught. Reverting track changes." << __E__;
609 ConfigurationInterface::setVersionTrackingEnabled(iteratorStruct->originalTrackChanges_);
611 __COUT__ <<
"Activating original group..." << __E__;
614 iteratorStruct->cfgMgr_->activateConfigurationGroup(
615 iteratorStruct->originalConfigGroup_,iteratorStruct->originalConfigKey_);
619 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
626 void Iterator::startCommandChooseFSM(IteratorWorkLoopStruct *iteratorStruct,
627 const std::string& fsmName)
629 __COUT__ <<
"fsmName " << fsmName << __E__;
632 iteratorStruct->fsmName_ = fsmName;
633 iteratorStruct->theIterator_->lastFsmName_ = fsmName;
644 iteratorStruct->fsmRunAlias_ =
"Run";
647 ConfigurationTree configLinkNode = iteratorStruct->cfgMgr_->getSupervisorConfigurationNode(
648 iteratorStruct->theIterator_->theSupervisor_->supervisorContextUID_,
649 iteratorStruct->theIterator_->theSupervisor_->supervisorApplicationUID_);
651 if(!configLinkNode.isDisconnected())
655 ConfigurationTree fsmLinkNode = configLinkNode.getNode(
"LinkToStateMachineConfiguration");
656 if(!fsmLinkNode.isDisconnected())
657 iteratorStruct->fsmRunAlias_ =
658 fsmLinkNode.getNode(fsmName +
"/RunDisplayAlias").getValue<std::string>();
660 __COUT_INFO__ <<
"FSM Link disconnected." << __E__;
662 catch(std::runtime_error &e)
665 __COUT_INFO__ <<
"No state machine Run alias. Ignoring and assuming alias of '" <<
666 iteratorStruct->fsmRunAlias_ <<
".'" << __E__;
670 __COUT_ERR__ <<
"Unknown error. Should never happen." << __E__;
672 __COUT_INFO__ <<
"No state machine Run alias. Ignoring and assuming alias of '" <<
673 iteratorStruct->fsmRunAlias_ <<
".'" << __E__;
677 __COUT_INFO__ <<
"FSM Link disconnected." << __E__;
679 __COUT__ <<
"fsmRunAlias_ = " << iteratorStruct->fsmRunAlias_ << __E__;
686 iteratorStruct->fsmNextRunNumber_ = iteratorStruct->theIterator_->theSupervisor_->getNextRunNumber(
687 iteratorStruct->fsmName_);
689 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getCurrentStateName() ==
"Running" ||
690 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getCurrentStateName() ==
"Paused")
691 --iteratorStruct->fsmNextRunNumber_;
693 __COUT__ <<
"fsmNextRunNumber_ = " << iteratorStruct->fsmNextRunNumber_ << __E__;
698 bool Iterator::haltIterator(
Iterator *iterator,
699 IteratorWorkLoopStruct *iteratorStruct)
703 const std::string& fsmName = iterator->lastFsmName_;
705 std::vector<std::string> fsmCommandParameters;
706 std::string errorStr =
"";
707 std::string currentState = theSupervisor->theStateMachine_.getCurrentStateName();
709 bool haltAttempted =
true;
710 if(currentState ==
"Initialized" ||
711 currentState ==
"Halted")
713 __COUT__ <<
"Do nothing. Already halted." << __E__;
714 haltAttempted =
false;
716 else if(currentState ==
"Running")
717 errorStr = theSupervisor->attemptStateMachineTransition(
720 WebUsers::DEFAULT_ITERATOR_USERNAME ,
721 WebUsers::DEFAULT_ITERATOR_USERNAME,
722 fsmCommandParameters);
724 errorStr = theSupervisor->attemptStateMachineTransition(
727 WebUsers::DEFAULT_ITERATOR_USERNAME ,
728 WebUsers::DEFAULT_ITERATOR_USERNAME,
729 fsmCommandParameters);
736 __SS__ <<
"Iterator failed to halt because of the following error: " << errorStr;
737 throw std::runtime_error(ss.str());
741 __COUT__ <<
"FSM in transition = " << theSupervisor->theStateMachine_.isInTransition() << __E__;
742 __COUT__ <<
"halting state machine launched." << __E__;
748 __COUT__ <<
"Conducting Iterator halt." << __E__;
753 __COUT__ <<
"Reverting track changes." << __E__;
754 ConfigurationInterface::setVersionTrackingEnabled(iteratorStruct->originalTrackChanges_);
756 __COUT__ <<
"Activating original group..." << __E__;
759 iteratorStruct->cfgMgr_->activateConfigurationGroup(
760 iteratorStruct->originalConfigGroup_,iteratorStruct->originalConfigKey_);
764 __COUT_WARN__ <<
"Original group could not be activated." << __E__;
771 if(iterator->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for iterator access" << __E__;
772 std::lock_guard<std::mutex> lock(iterator->accessMutex_);
773 if(iterator->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have iterator access" << __E__;
777 iterator->activePlanIsRunning_ =
false;
778 iterator->iteratorBusy_ =
false;
781 iterator->activePlanName_ =
"";
782 iterator->activeCommandIndex_ = -1;
787 __COUT__ <<
"Halted plan '" << iteratorStruct->activePlan_ <<
"' at command index " <<
788 iteratorStruct->commandIndex_ <<
". " << __E__;
789 __MOUT__ <<
"Halted plan '" << iteratorStruct->activePlan_ <<
"' at command index " <<
790 iteratorStruct->commandIndex_ <<
". " << __E__;
792 iterator->lastStartedPlanName_ = iteratorStruct->activePlan_;
793 iteratorStruct->activePlan_ =
"";
794 iteratorStruct->commandIndex_ = -1;
797 return haltAttempted;
801 void Iterator::startCommandBeginLabel(IteratorWorkLoopStruct *iteratorStruct)
803 __COUT__ <<
"Entering label '" <<
804 iteratorStruct->commands_
805 [iteratorStruct->commandIndex_].params_
806 [IterateConfiguration::commandBeginLabelParams_.Label_]
807 <<
"'..." << std::endl;
810 iteratorStruct->stepIndexStack_.push_back(0);
815 void Iterator::startCommandRepeatLabel(IteratorWorkLoopStruct *iteratorStruct)
819 int numOfRepetitions;
820 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_].params_
821 [IterateConfiguration::commandRepeatLabelParams_.NumberOfRepetitions_].c_str(),
822 "%d",&numOfRepetitions);
823 __COUT__ <<
"numOfRepetitions remaining = " << numOfRepetitions << __E__;
827 if(numOfRepetitions <= 0)
830 sprintf(repStr,
"%d",iteratorStruct->stepIndexStack_.back());
831 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_
832 [IterateConfiguration::commandRepeatLabelParams_.NumberOfRepetitions_] =
836 iteratorStruct->stepIndexStack_.pop_back();
845 ++(iteratorStruct->stepIndexStack_.back());
848 for(i=iteratorStruct->commandIndex_;i>0;--i)
849 if(iteratorStruct->commands_[i].type_ == IterateConfiguration::COMMAND_BEGIN_LABEL &&
850 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_[IterateConfiguration::commandRepeatLabelParams_.Label_] ==
851 iteratorStruct->commands_[i].params_[IterateConfiguration::commandBeginLabelParams_.Label_])
break;
853 sprintf(repStr,
"%d",numOfRepetitions);
854 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_
855 [IterateConfiguration::commandRepeatLabelParams_.NumberOfRepetitions_] =
858 iteratorStruct->commandIndex_ = i;
859 __COUT__ <<
"Jumping back to commandIndex " << iteratorStruct->commandIndex_ << __E__;
863 void Iterator::startCommandRun(IteratorWorkLoopStruct *iteratorStruct)
865 iteratorStruct->runIsDone_ =
false;
866 iteratorStruct->fsmCommandParameters_.clear();
868 std::string errorStr =
"";
869 std::string currentState = iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getCurrentStateName();
873 if(currentState ==
"Configured")
874 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
876 "Start",iteratorStruct->fsmName_,
877 WebUsers::DEFAULT_ITERATOR_USERNAME ,
878 WebUsers::DEFAULT_ITERATOR_USERNAME,
879 iteratorStruct->fsmCommandParameters_);
881 errorStr =
"Can only Run from the Configured state. The current state is " +
887 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
888 throw std::runtime_error(ss.str());
892 __COUT__ <<
"FSM in transition = " << iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition() << __E__;
893 __COUT__ <<
"startCommandRun success." << __E__;
897 void Iterator::startCommandConfigureActive(IteratorWorkLoopStruct *iteratorStruct)
899 __COUT__ <<
"startCommandConfigureActive " << __E__;
905 std::string group = iteratorStruct->cfgMgr_->getActiveGroupName();
908 __COUT__ <<
"group " << group << __E__;
909 __COUT__ <<
"key " << key << __E__;
913 std::stringstream systemAlias;
914 systemAlias <<
"GROUP:" << group <<
":" << key;
915 startCommandConfigureAlias(iteratorStruct,systemAlias.str());
919 void Iterator::startCommandConfigureGroup(IteratorWorkLoopStruct *iteratorStruct)
921 __COUT__ <<
"startCommandConfigureGroup " << __E__;
927 iteratorStruct->commands_
928 [iteratorStruct->commandIndex_].params_
929 [IterateConfiguration::commandConfigureGroupParams_.GroupName_];
931 iteratorStruct->commands_
932 [iteratorStruct->commandIndex_].params_
933 [IterateConfiguration::commandConfigureGroupParams_.GroupKey_])
936 __COUT__ <<
"group " << group << __E__;
937 __COUT__ <<
"key " << key << __E__;
941 std::stringstream systemAlias;
942 systemAlias <<
"GROUP:" << group <<
":" << key;
943 startCommandConfigureAlias(iteratorStruct,systemAlias.str());
947 void Iterator::startCommandConfigureAlias(IteratorWorkLoopStruct *iteratorStruct,
948 const std::string& systemAlias)
950 __COUT__ <<
"systemAlias " << systemAlias << __E__;
952 iteratorStruct->fsmCommandParameters_.clear();
953 iteratorStruct->fsmCommandParameters_.push_back(systemAlias);
955 std::string errorStr =
"";
956 std::string currentState = iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getCurrentStateName();
960 if(currentState ==
"Initial")
961 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
963 "Initialize",iteratorStruct->fsmName_,
964 WebUsers::DEFAULT_ITERATOR_USERNAME ,
965 WebUsers::DEFAULT_ITERATOR_USERNAME,
966 iteratorStruct->fsmCommandParameters_);
967 else if(currentState ==
"Halted")
968 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
970 "Configure",iteratorStruct->fsmName_,
971 WebUsers::DEFAULT_ITERATOR_USERNAME ,
972 WebUsers::DEFAULT_ITERATOR_USERNAME,
973 iteratorStruct->fsmCommandParameters_);
974 else if(currentState ==
"Configured")
975 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
977 "Halt",iteratorStruct->fsmName_,
978 WebUsers::DEFAULT_ITERATOR_USERNAME ,
979 WebUsers::DEFAULT_ITERATOR_USERNAME,
980 iteratorStruct->fsmCommandParameters_);
982 errorStr =
"Can only Configure from the Initial or Halted state. The current state is " +
989 __SS__ <<
"Iterator failed to configure with system alias '" <<
990 (iteratorStruct->fsmCommandParameters_.size()?
991 iteratorStruct->fsmCommandParameters_[0]:
"UNKNOWN") <<
992 "' because of the following error: " << errorStr;
993 throw std::runtime_error(ss.str());
997 __COUT__ <<
"FSM in transition = " << iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition() << __E__;
998 __COUT__ <<
"startCommandConfigureAlias success." << __E__;
1002 void Iterator::startCommandModifyActive(IteratorWorkLoopStruct *iteratorStruct)
1023 bool doTrackGroupChanges =
false;
1024 if(
"True" == iteratorStruct->commands_[iteratorStruct->commandIndex_].params_
1025 [IterateConfiguration::commandModifyActiveParams_.DoTrackGroupChanges_])
1026 doTrackGroupChanges =
true;
1028 const std::string& startValueStr =
1029 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_
1030 [IterateConfiguration::commandModifyActiveParams_.FieldStartValue_];
1031 const std::string& stepSizeStr =
1032 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_
1033 [IterateConfiguration::commandModifyActiveParams_.FieldIterationStepSize_];
1035 const unsigned int stepIndex = iteratorStruct->stepIndexStack_.back();
1038 __COUT__ <<
"doTrackGroupChanges " << (doTrackGroupChanges?
"yes":
"no") << std::endl;
1039 __COUT__ <<
"stepIndex " << stepIndex << std::endl;
1041 ConfigurationInterface::setVersionTrackingEnabled(doTrackGroupChanges);
1045 if(startValueStr.size() &&
1046 (startValueStr[startValueStr.size()-1] ==
'f' ||
1047 startValueStr.find(
'.') != std::string::npos))
1050 double startValue = strtod(startValueStr.c_str(),0);
1051 double stepSize = strtod(stepSizeStr.c_str(),0);
1053 __COUT__ <<
"startValue " << startValue << std::endl;
1054 __COUT__ <<
"stepSize " << stepSize << std::endl;
1055 __COUT__ <<
"currentValue " << startValue + stepSize*stepIndex << std::endl;
1057 helpCommandModifyActive(
1059 startValue + stepSize*stepIndex,
1060 doTrackGroupChanges);
1064 long int startValue;
1066 if(startValueStr.size() > 2 && startValueStr[1] ==
'x')
1067 startValue = strtol(startValueStr.c_str(),0,16);
1068 else if(startValueStr.size() > 1 && startValueStr[0] ==
'b')
1069 startValue = strtol(startValueStr.substr(1).c_str(),0,2);
1071 startValue = strtol(startValueStr.c_str(),0,10);
1075 if(stepSizeStr.size() > 2 && stepSizeStr[1] ==
'x')
1076 stepSize = strtol(stepSizeStr.c_str(),0,16);
1077 else if(stepSizeStr.size() > 1 && stepSizeStr[0] ==
'b')
1078 stepSize = strtol(stepSizeStr.substr(1).c_str(),0,2);
1080 stepSize = strtol(stepSizeStr.c_str(),0,10);
1082 __COUT__ <<
"startValue " << startValue << std::endl;
1083 __COUT__ <<
"stepSize " << stepSize << std::endl;
1084 __COUT__ <<
"currentValue " << startValue + stepSize*stepIndex << std::endl;
1086 helpCommandModifyActive(
1088 startValue + stepSize*stepIndex,
1089 doTrackGroupChanges);
1104 bool Iterator::checkCommandRun(IteratorWorkLoopStruct *iteratorStruct)
1112 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for FSM access" << __E__;
1113 std::lock_guard<std::mutex> lock(iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
1114 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have FSM access" << __E__;
1116 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition())
1119 iteratorStruct->fsmCommandParameters_.clear();
1121 std::string errorStr =
"";
1122 std::string currentState = iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getCurrentStateName();
1127 if(iteratorStruct->doPauseAction_)
1130 __COUT__ <<
"Transitioning FSM to Paused..." << __E__;
1132 if(currentState ==
"Paused")
1135 __COUT__ <<
"Transition to Paused complete." << __E__;
1138 else if(currentState ==
"Running")
1139 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1141 "Pause",iteratorStruct->fsmName_,
1142 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1143 WebUsers::DEFAULT_ITERATOR_USERNAME,
1144 iteratorStruct->fsmCommandParameters_);
1145 else if(currentState ==
"Configured")
1148 __COUT__ <<
"In Configured state. No need to transition to Paused." << __E__;
1152 errorStr =
"Expected to be in Paused. Unexpectedly, the current state is " +
1153 currentState +
". Last State Machine error message was as follows: " +
1154 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getErrorMessage();
1158 __SS__ <<
"Iterator failed to pause because of the following error: " << errorStr;
1159 throw std::runtime_error(ss.str());
1163 else if(iteratorStruct->doHaltAction_)
1166 __COUT__ <<
"Transitioning FSM to Halted..." << __E__;
1168 if(currentState ==
"Halted")
1171 __COUT__ <<
"Transition to Halted complete." << __E__;
1174 else if(currentState ==
"Running" ||
1175 currentState ==
"Paused")
1176 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1178 "Abort",iteratorStruct->fsmName_,
1179 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1180 WebUsers::DEFAULT_ITERATOR_USERNAME,
1181 iteratorStruct->fsmCommandParameters_);
1182 else if(currentState ==
"Configured")
1183 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1185 "Halt",iteratorStruct->fsmName_,
1186 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1187 WebUsers::DEFAULT_ITERATOR_USERNAME,
1188 iteratorStruct->fsmCommandParameters_);
1190 errorStr =
"Expected to be in Halted. Unexpectedly, the current state is " +
1191 currentState +
". Last State Machine error message was as follows: " +
1192 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getErrorMessage();
1196 __SS__ <<
"Iterator failed to halt because of the following error: " << errorStr;
1197 throw std::runtime_error(ss.str());
1201 else if(iteratorStruct->doResumeAction_)
1206 __COUT__ <<
"Transitioning FSM to Running..." << __E__;
1208 if(currentState ==
"Paused")
1209 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1211 "Resume",iteratorStruct->fsmName_,
1212 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1213 WebUsers::DEFAULT_ITERATOR_USERNAME,
1214 iteratorStruct->fsmCommandParameters_);
1218 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
1219 throw std::runtime_error(ss.str());
1229 if(currentState !=
"Running")
1231 if(iteratorStruct->runIsDone_ &&
1232 currentState ==
"Configured")
1235 __COUT__ <<
"Reached end of run " <<
1236 iteratorStruct->fsmNextRunNumber_ << __E__;
1240 errorStr =
"Expected to be in Running. Unexpectedly, the current state is " +
1241 currentState +
". Last State Machine error message was as follows: " +
1242 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getErrorMessage();
1246 bool waitOnRunningThreads =
false;
1247 if(
"True" == iteratorStruct->commands_[iteratorStruct->commandIndex_].params_
1248 [IterateConfiguration::commandRunParams_.WaitOnRunningThreads_])
1249 waitOnRunningThreads =
true;
1251 time_t remainingDurationInSeconds;
1252 sscanf(iteratorStruct->commands_[iteratorStruct->commandIndex_].params_
1253 [IterateConfiguration::commandRunParams_.DurationInSeconds_].c_str(),
1254 "%ld",&remainingDurationInSeconds);
1257 __COUT__ <<
"waitOnRunningThreads " << waitOnRunningThreads << __E__;
1258 __COUT__ <<
"remainingDurationInSeconds " << remainingDurationInSeconds << __E__;
1262 if(waitOnRunningThreads)
1266 iteratorStruct->theIterator_->theSupervisor_;
1268 bool allFrontEndsAreDone =
true;
1270 theSupervisor->allSupervisorInfo_.getAllFETypeSupervisorInfo())
1274 std::string status = theSupervisor->send(it.second.getDescriptor(),
1275 "WorkLoopStatusRequest");
1277 __COUT__ <<
"FESupervisor instance " << it.first <<
1278 " has status = " << status << std::endl;
1280 if(status != CoreSupervisorBase::WORK_LOOP_DONE)
1282 allFrontEndsAreDone =
false;
1286 catch (xdaq::exception::Exception& e)
1288 __SS__ <<
"Could not retrieve status from FESupervisor instance " <<
1289 it.first <<
"." << std::endl;
1290 __COUT_WARN__ << ss.str();
1291 errorStr = ss.str();
1295 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
1296 throw std::runtime_error(ss.str());
1301 if(allFrontEndsAreDone)
1304 __COUT__ <<
"FE workloops all complete! Stopping run..." << __E__;
1306 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1308 "Stop",iteratorStruct->fsmName_,
1309 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1310 WebUsers::DEFAULT_ITERATOR_USERNAME,
1311 iteratorStruct->fsmCommandParameters_);
1315 __SS__ <<
"Iterator failed to stop run because of the following error: " << errorStr;
1316 throw std::runtime_error(ss.str());
1320 iteratorStruct->runIsDone_ =
true;
1329 if(remainingDurationInSeconds > 1)
1331 --remainingDurationInSeconds;
1335 sprintf(str,
"%ld",remainingDurationInSeconds);
1336 iteratorStruct->commands_[iteratorStruct->commandIndex_].params_
1337 [IterateConfiguration::commandRunParams_.DurationInSeconds_] =
1340 else if(remainingDurationInSeconds == 1)
1343 __COUT__ <<
"Time duration reached! Stopping run..." << __E__;
1345 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1347 "Stop",iteratorStruct->fsmName_,
1348 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1349 WebUsers::DEFAULT_ITERATOR_USERNAME,
1350 iteratorStruct->fsmCommandParameters_);
1354 __SS__ <<
"Iterator failed to stop run because of the following error: " << errorStr;
1355 throw std::runtime_error(ss.str());
1359 iteratorStruct->runIsDone_ =
true;
1367 __SS__ <<
"Iterator failed to run because of the following error: " << errorStr;
1368 throw std::runtime_error(ss.str());
1375 bool Iterator::checkCommandConfigure(IteratorWorkLoopStruct *iteratorStruct)
1383 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for FSM access" << __E__;
1384 std::lock_guard<std::mutex> lock(iteratorStruct->theIterator_->theSupervisor_->stateMachineAccessMutex_);
1385 if(iteratorStruct->theIterator_->theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have FSM access" << __E__;
1387 if(iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.isInTransition())
1390 std::string errorStr =
"";
1391 std::string currentState = iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getCurrentStateName();
1393 if(currentState ==
"Halted")
1394 errorStr = iteratorStruct->theIterator_->theSupervisor_->attemptStateMachineTransition(
1396 "Configure",iteratorStruct->fsmName_,
1397 WebUsers::DEFAULT_ITERATOR_USERNAME ,
1398 WebUsers::DEFAULT_ITERATOR_USERNAME,
1399 iteratorStruct->fsmCommandParameters_);
1400 else if(currentState !=
"Configured")
1401 errorStr =
"Expected to be in Configure. Unexpectedly, the current state is " +
1402 currentState +
"." +
". Last State Machine error message was as follows: " +
1403 iteratorStruct->theIterator_->theSupervisor_->theStateMachine_.getErrorMessage();
1406 __COUT__ <<
"checkCommandConfigureAlias complete." << __E__;
1409 std::pair<std::string, ConfigurationGroupKey> newActiveGroup =
1410 iteratorStruct->cfgMgr_->getConfigurationGroupFromAlias(iteratorStruct->fsmCommandParameters_[0]);
1411 iteratorStruct->cfgMgr_->loadConfigurationGroup(newActiveGroup.first,newActiveGroup.second,
true );
1414 __COUT__ <<
"originalTrackChanges " <<
1415 iteratorStruct->originalTrackChanges_ << __E__;
1416 __COUT__ <<
"originalConfigGroup " <<
1417 iteratorStruct->originalConfigGroup_ << __E__;
1418 __COUT__ <<
"originalConfigKey " <<
1419 iteratorStruct->originalConfigKey_ << __E__;
1421 __COUT__ <<
"currentTrackChanges " <<
1422 ConfigurationInterface::isVersionTrackingEnabled() << __E__;
1423 __COUT__ <<
"originalConfigGroup " <<
1424 iteratorStruct->cfgMgr_->getActiveGroupName() << __E__;
1425 __COUT__ <<
"originalConfigKey " <<
1426 iteratorStruct->cfgMgr_->getActiveGroupKey() << __E__;
1433 __SS__ <<
"Iterator failed to configure with system alias '" <<
1434 (iteratorStruct->fsmCommandParameters_.size()?
1435 iteratorStruct->fsmCommandParameters_[0]:
"UNKNOWN") <<
1436 "' because of the following error: " << errorStr;
1437 throw std::runtime_error(ss.str());
1445 const std::string& command,
const std::string& parameter)
1447 if(command ==
"iteratePlay")
1449 playIterationPlan(xmldoc,parameter);
1452 else if(command ==
"iteratePause")
1454 pauseIterationPlan(xmldoc);
1457 else if(command ==
"iterateHalt")
1459 haltIterationPlan(xmldoc);
1462 else if(command ==
"getIterationPlanStatus")
1464 getIterationPlanStatus(xmldoc);
1471 if(theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for iterator access" << __E__;
1472 std::lock_guard<std::mutex> lock(accessMutex_);
1473 if(theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have iterator access" << __E__;
1477 __SS__ <<
"Error - Can not accept request because the Iterator " <<
1479 "in control of State Machine progress. ";
1480 __COUT_ERR__ <<
"\n" << ss.str();
1481 __MOUT_ERR__ <<
"\n" << ss.str();
1483 xmldoc.addTextElementToData(
"state_tranisition_attempted",
"0");
1484 xmldoc.addTextElementToData(
"state_tranisition_attempted_err",
1494 void Iterator::playIterationPlan(
HttpXmlDocument& xmldoc,
const std::string& planName)
1496 __MOUT__ <<
"Attempting to play iteration plan '" << planName <<
".'" << __E__;
1497 __COUT__ <<
"Attempting to play iteration plan '" << planName <<
".'" << __E__;
1505 if(theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for iterator access" << __E__;
1506 std::lock_guard<std::mutex> lock(accessMutex_);
1507 if(theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have iterator access" << __E__;
1509 if(!activePlanIsRunning_ && !commandPlay_)
1511 if(!workloopRunning_)
1515 workloopRunning_ =
true;
1518 std::thread([](
Iterator *iterator){ Iterator::IteratorWorkLoop(iterator); },
this).detach();
1521 activePlanName_ = planName;
1522 commandPlay_ =
true;
1526 __SS__ <<
"Invalid play command attempted. Can only play when the Iterator is inactive or paused." <<
1527 " If you would like to restart an iteration plan, first try halting." << __E__;
1528 __MOUT__ << ss.str();
1530 xmldoc.addTextElementToData(
"error_message", ss.str());
1532 __COUT__ <<
"Invalid play command attempted. " <<
1533 commandPlay_ <<
" " <<
1534 activePlanName_ << __E__;
1541 __MOUT__ <<
"Attempting to pause iteration plan '" << activePlanName_ <<
".'" << __E__;
1542 __COUT__ <<
"Attempting to pause iteration plan '" << activePlanName_ <<
".'" << __E__;
1548 if(theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for iterator access" << __E__;
1549 std::lock_guard<std::mutex> lock(accessMutex_);
1550 if(theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have iterator access" << __E__;
1552 if(workloopRunning_ && activePlanIsRunning_ && !commandPause_)
1554 commandPause_ =
true;
1558 __SS__ <<
"Invalid pause command attempted. Can only pause when running." << __E__;
1559 __MOUT__ << ss.str();
1561 xmldoc.addTextElementToData(
"error_message", ss.str());
1563 __COUT__ <<
"Invalid pause command attempted. " <<
1564 workloopRunning_ <<
" " <<
1565 activePlanIsRunning_ <<
" " <<
1566 commandPause_ <<
" " <<
1567 activePlanName_ << __E__;
1574 __MOUT__ <<
"Attempting to halt iteration plan '" << activePlanName_ <<
".'" << __E__;
1575 __COUT__ <<
"Attempting to halt iteration plan '" << activePlanName_ <<
".'" << __E__;
1580 if(workloopRunning_)
1584 if(theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for iterator access" << __E__;
1585 std::lock_guard<std::mutex> lock(accessMutex_);
1586 if(theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have iterator access" << __E__;
1588 __COUT__ <<
"activePlanIsRunning_: " << activePlanIsRunning_ << __E__;
1589 __COUT__ <<
"Passing halt command to iterator thread." << __E__;
1590 commandHalt_ =
true;
1593 activePlanName_ =
"";
1594 activeCommandIndex_ = -1;
1598 __COUT__ <<
"No thread, so conducting halt." << __E__;
1599 Iterator::haltIterator(
this);
1639 xmldoc.addTextElementToData(
"current_state",
1640 theSupervisor_->theStateMachine_.isInTransition()?
1641 theSupervisor_->theStateMachine_.getCurrentTransitionName(
1642 theSupervisor_->stateMachineLastCommandInput_):
1643 theSupervisor_->theStateMachine_.getCurrentStateName());
1646 if(theSupervisor_->theStateMachine_.isInTransition())
1647 xmldoc.addTextElementToData(
"transition_progress",
1648 theSupervisor_->theProgressBar_.readPercentageString());
1650 xmldoc.addTextElementToData(
"transition_progress",
"100");
1653 sprintf(tmp,
"%lu",theSupervisor_->theStateMachine_.getTimeInState());
1654 xmldoc.addTextElementToData(
"time_in_state", tmp);
1660 if(theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Waiting for iterator access" << __E__;
1661 std::lock_guard<std::mutex> lock(accessMutex_);
1662 if(theSupervisor_->VERBOSE_MUTEX) __COUT__ <<
"Have iterator access" << __E__;
1664 xmldoc.addTextElementToData(
"active_plan", activePlanName_);
1665 xmldoc.addTextElementToData(
"last_started_plan", lastStartedPlanName_);
1666 xmldoc.addTextElementToData(
"last_finished_plan", lastFinishedPlanName_);
1668 sprintf(tmp,
"%u",activeCommandIndex_);
1669 xmldoc.addTextElementToData(
"current_command_index", tmp);
1670 sprintf(tmp,
"%ld",time(0) - activeCommandStartTime_);
1671 xmldoc.addTextElementToData(
"current_command_duration", tmp);
1672 sprintf(tmp,
"%u",activeCommandIteration_);
1673 xmldoc.addTextElementToData(
"current_command_iteration", tmp);
1675 for(
const auto& depthIteration:depthIterationStack_)
1677 sprintf(tmp,
"%u",depthIteration);
1678 xmldoc.addTextElementToData(
"depth_iteration", tmp);
1681 if(activePlanIsRunning_ && iteratorBusy_)
1683 if(workloopRunning_)
1684 xmldoc.addTextElementToData(
"active_plan_status",
"Running");
1686 xmldoc.addTextElementToData(
"active_plan_status",
"Error");
1688 else if(!activePlanIsRunning_ && iteratorBusy_)
1689 xmldoc.addTextElementToData(
"active_plan_status",
"Paused");
1691 xmldoc.addTextElementToData(
"active_plan_status",
"Inactive");
1693 xmldoc.addTextElementToData(
"error_message", errorMessage_);