00001 #include "otsdaq-core/CoreSupervisors/CoreSupervisorBase.h"
00002 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
00003 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
00004 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h"
00005 #include "otsdaq-core/CgiDataUtilities/CgiDataUtilities.h"
00006
00007
00008 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationGroupKey.h"
00009 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
00010 #include "otsdaq-core/ConfigurationInterface/ConfigurationTree.h"
00011 #include "otsdaq-core/ConfigurationPluginDataFormats/XDAQContextConfiguration.h"
00012 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00013 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
00014 #include "otsdaq-core/FiniteStateMachine/VStateMachine.h"
00015 #include "otsdaq-core/FECore/FEVInterfacesManager.h"
00016
00017
00018 #include <toolbox/fsm/FailedEvent.h>
00019
00020 #include <xdaq/NamespaceURI.h>
00021 #include <xoap/Method.h>
00022
00023 #include <iostream>
00024
00025 using namespace ots;
00026
00027
00028
00029
00030 CoreSupervisorBase::CoreSupervisorBase(xdaq::ApplicationStub * s)
00031 throw (xdaq::exception::Exception)
00032 : xdaq::Application (s)
00033 , SOAPMessenger (this)
00034 , stateMachineWorkLoopManager_ (toolbox::task::bind(this, &CoreSupervisorBase::stateMachineThread, "StateMachine"))
00035 , stateMachineSemaphore_ (toolbox::BSem::FULL)
00036 , theConfigurationManager_ (new ConfigurationManager)
00037 , XDAQContextConfigurationName_ (theConfigurationManager_->__GET_CONFIG__(XDAQContextConfiguration)->getConfigurationName())
00038 , supervisorConfigurationPath_ ("INITIALIZED INSIDE THE CONTRUCTOR BECAUSE IT NEEDS supervisorContextUID_ and supervisorApplicationUID_")
00039 , supervisorContextUID_ ("INITIALIZED INSIDE THE CONTRUCTOR TO LAUNCH AN EXCEPTION")
00040 , supervisorApplicationUID_ ("INITIALIZED INSIDE THE CONTRUCTOR TO LAUNCH AN EXCEPTION")
00041 , supervisorClass_ (getApplicationDescriptor()->getClassName())
00042 , supervisorClassNoNamespace_ (supervisorClass_.substr(supervisorClass_.find_last_of(":")+1, supervisorClass_.length()-supervisorClass_.find_last_of(":")))
00043 {
00044 INIT_MF("CoreSupervisorBase");
00045
00046 __COUT__ << "Begin!" << std::endl;
00047
00048 xgi::bind (this, &CoreSupervisorBase::Default, "Default" );
00049 xgi::bind (this, &CoreSupervisorBase::stateMachineXgiHandler, "StateMachineXgiHandler");
00050 xgi::bind (this, &CoreSupervisorBase::request, "Request");
00051
00052 xoap::bind(this, &CoreSupervisorBase::stateMachineStateRequest, "StateMachineStateRequest", XDAQ_NS_URI );
00053 xoap::bind(this, &CoreSupervisorBase::stateMachineErrorMessageRequest, "StateMachineErrorMessageRequest", XDAQ_NS_URI );
00054 xoap::bind(this, &CoreSupervisorBase::macroMakerSupervisorRequest, "MacroMakerSupervisorRequest", XDAQ_NS_URI );
00055 xoap::bind(this, &CoreSupervisorBase::workLoopStatusRequest, "WorkLoopStatusRequest", XDAQ_NS_URI );
00056
00057 try
00058 {
00059 supervisorContextUID_ = theConfigurationManager_->__GET_CONFIG__(XDAQContextConfiguration)->getContextUID(getApplicationContext()->getContextDescriptor()->getURL());
00060 }
00061 catch(...)
00062 {
00063 __COUT_ERR__ << "XDAQ Supervisor could not access it's configuration through the Configuration Context Group." <<
00064 " The XDAQContextConfigurationName = " << XDAQContextConfigurationName_ <<
00065 ". The supervisorApplicationUID = " << supervisorApplicationUID_ << std::endl;
00066 throw;
00067 }
00068 try
00069 {
00070 supervisorApplicationUID_ = theConfigurationManager_->__GET_CONFIG__(XDAQContextConfiguration)->getApplicationUID
00071 (
00072 getApplicationContext()->getContextDescriptor()->getURL(),
00073 getApplicationDescriptor()->getLocalId()
00074 );
00075 }
00076 catch(...)
00077 {
00078 __COUT_ERR__ << "XDAQ Supervisor could not access it's configuration through the Configuration Application Group."
00079 << " The supervisorApplicationUID = " << supervisorApplicationUID_ << std::endl;
00080 throw;
00081 }
00082 supervisorConfigurationPath_ = "/" + supervisorContextUID_ + "/LinkToApplicationConfiguration/" + supervisorApplicationUID_ + "/LinkToSupervisorConfiguration";
00083
00084 setStateMachineName(supervisorApplicationUID_);
00085
00086 __COUT__ << "Done!" << std::endl;
00087
00088 init();
00089 }
00090
00091
00092 CoreSupervisorBase::~CoreSupervisorBase(void)
00093 {
00094 destroy();
00095 }
00096
00097 void CoreSupervisorBase::init(void)
00098 {
00099
00100 __COUT__ << "init CONTEXT!" << std::endl;
00101
00102 supervisorDescriptorInfo_.init(getApplicationContext());
00103
00104 __COUT__ << "Done!" << std::endl;
00105
00106 }
00107
00108
00109 void CoreSupervisorBase::destroy(void)
00110 {
00111 for(auto& it: theStateMachineImplementation_)
00112 delete it;
00113 theStateMachineImplementation_.clear();
00114 }
00115
00116
00117 void CoreSupervisorBase::Default(xgi::Input * in, xgi::Output * out )
00118 throw (xgi::exception::Exception)
00119 {
00120
00121
00122 __COUT__<< "Supervisor class " << supervisorClass_ << std::endl;
00123
00124 *out << "<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame src='/WebPath/html/" << supervisorClassNoNamespace_ << "Supervisor.html?urn=" <<
00125 this->getApplicationDescriptor()->getLocalId() <<
00126 "'></frameset></html>";
00127 }
00128
00129
00130 void CoreSupervisorBase::request(xgi::Input * in, xgi::Output * out )
00131 throw (xgi::exception::Exception)
00132 {
00133
00134
00135 cgicc::Cgicc cgi(in);
00136 std::string write = CgiDataUtilities::getOrPostData(cgi,"write");
00137 std::string addr = CgiDataUtilities::getOrPostData(cgi,"addr");
00138 std::string data = CgiDataUtilities::getOrPostData(cgi,"data");
00139
00140 __COUT__<< "write " << write << " addr: " << addr << " data: " << data << std::endl;
00141
00142 unsigned long long int addr64,data64;
00143 sscanf(addr.c_str(),"%llu",&addr64);
00144 sscanf(data.c_str(),"%llu",&data64);
00145 __COUT__<< "write " << write << " addr: " << addr64 << " data: " << data64 << std::endl;
00146
00147 *out << "done";
00148 }
00149
00150
00151 void CoreSupervisorBase::stateMachineXgiHandler(xgi::Input * in, xgi::Output * out )
00152 throw (xgi::exception::Exception)
00153 {}
00154
00155
00156 void CoreSupervisorBase::stateMachineResultXgiHandler(xgi::Input* in, xgi::Output* out )
00157 throw (xgi::exception::Exception)
00158 {}
00159
00160
00161 xoap::MessageReference CoreSupervisorBase::stateMachineXoapHandler(xoap::MessageReference message )
00162 throw (xoap::exception::Exception)
00163 {
00164 __COUT__<< "Soap Handler!" << std::endl;
00165 stateMachineWorkLoopManager_.removeProcessedRequests();
00166 stateMachineWorkLoopManager_.processRequest(message);
00167 __COUT__<< "Done - Soap Handler!" << std::endl;
00168 return message;
00169 }
00170
00171
00172 xoap::MessageReference CoreSupervisorBase::stateMachineResultXoapHandler(xoap::MessageReference message )
00173 throw (xoap::exception::Exception)
00174 {
00175 __COUT__<< "Soap Handler!" << std::endl;
00176
00177
00178 __COUT__<< "Done - Soap Handler!" << std::endl;
00179 return message;
00180 }
00181
00182
00183 bool CoreSupervisorBase::stateMachineThread(toolbox::task::WorkLoop* workLoop)
00184 {
00185 stateMachineSemaphore_.take();
00186 __COUT__<< "Re-sending message..." << SOAPUtilities::translate(stateMachineWorkLoopManager_.getMessage(workLoop)).getCommand() << std::endl;
00187 std::string reply = send(this->getApplicationDescriptor(),stateMachineWorkLoopManager_.getMessage(workLoop));
00188 stateMachineWorkLoopManager_.report(workLoop, reply, 100, true);
00189 __COUT__<< "Done with message" << std::endl;
00190 stateMachineSemaphore_.give();
00191 return false;
00192
00193 }
00194
00195
00196 xoap::MessageReference CoreSupervisorBase::stateMachineStateRequest(xoap::MessageReference message)
00197 throw (xoap::exception::Exception)
00198 {
00199 __COUT__<< "theStateMachine_.getCurrentStateName() = " << theStateMachine_.getCurrentStateName() << std::endl;
00200 return SOAPUtilities::makeSOAPMessageReference(theStateMachine_.getCurrentStateName());
00201 }
00202
00203
00204 xoap::MessageReference CoreSupervisorBase::stateMachineErrorMessageRequest(xoap::MessageReference message)
00205 throw (xoap::exception::Exception)
00206 {
00207 __COUT__<< "theStateMachine_.getErrorMessage() = " << theStateMachine_.getErrorMessage() << std::endl;
00208
00209 SOAPParameters retParameters;
00210 retParameters.addParameter("ErrorMessage",theStateMachine_.getErrorMessage());
00211 return SOAPUtilities::makeSOAPMessageReference("stateMachineErrorMessageRequestReply",retParameters);
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221 xoap::MessageReference CoreSupervisorBase::macroMakerSupervisorRequest(
00222 xoap::MessageReference message)
00223 throw (xoap::exception::Exception)
00224 {
00225 __COUT__<< "$$$$$$$$$$$$$$$$$" << std::endl;
00226
00227
00228 FEVInterfacesManager* theFEInterfacesManager = extractFEInterfaceManager();
00229
00230
00231 SOAPParameters parameters;
00232 parameters.addParameter("Request");
00233 parameters.addParameter("InterfaceID");
00234
00235
00236 parameters.addParameter("Address");
00237 parameters.addParameter("Data");
00238
00239
00240 parameters.addParameter("feMacroName");
00241 parameters.addParameter("inputArgs");
00242 parameters.addParameter("outputArgs");
00243
00244 SOAPMessenger::receive(message, parameters);
00245 std::string request = parameters.getValue("Request");
00246 std::string addressStr = parameters.getValue("Address");
00247 std::string dataStr = parameters.getValue("Data");
00248 std::string InterfaceID = parameters.getValue("InterfaceID");
00249
00250 __COUT__<< "request: " << request << std::endl;
00251
00252 __COUT__<< "Address: " << addressStr << " Data: "
00253 << dataStr << " InterfaceID: " << InterfaceID << std::endl;
00254
00255 SOAPParameters retParameters;
00256
00257 if(request == "GetInterfaces")
00258 {
00259 if(theFEInterfacesManager)
00260 retParameters.addParameter("FEList",theFEInterfacesManager->getFEListString(
00261 std::to_string(getApplicationDescriptor()->getLocalId())));
00262 else
00263 retParameters.addParameter("FEList","");
00264
00265 return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "Response",
00266 retParameters);
00267 }
00268 else if(request == "UniversalWrite")
00269 {
00270 if(!theFEInterfacesManager)
00271 {
00272 __COUT_INFO__ << "No FE Interface Manager! (So no write occurred)" << std::endl;
00273 return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "DataWritten",retParameters);
00274 }
00275
00276
00277
00278
00279
00280
00281 __COUT__<< "theFEInterfacesManager->getInterfaceUniversalAddressSize(index) " <<
00282 theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID) << std::endl;
00283 __COUT__<< "theFEInterfacesManager->getInterfaceUniversalDataSize(index) " <<
00284 theFEInterfacesManager->getInterfaceUniversalDataSize(InterfaceID) << std::endl;
00285
00286
00287
00288
00289 char tmpHex[3];
00290 tmpHex[2] = '\0';
00291
00292
00293 __COUT__<< "Translating address: ";
00294
00295 char address[theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID)];
00296
00297 if(addressStr.size()%2)
00298 addressStr = "0" + addressStr;
00299 unsigned int i=0;
00300 for(;i<addressStr.size() &&
00301 i/2 < theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID) ; i+=2)
00302 {
00303 tmpHex[0] = addressStr[addressStr.size()-1-i-1];
00304 tmpHex[1] = addressStr[addressStr.size()-1-i];
00305 sscanf(tmpHex,"%hhX",(unsigned char*)&address[i/2]);
00306 printf("%2.2X",(unsigned char)address[i/2]);
00307 }
00308
00309 for(;i/2 < theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID) ; i+=2)
00310 {
00311 address[i/2] = 0;
00312 printf("%2.2X",(unsigned char)address[i/2]);
00313 }
00314
00315 std::cout << std::endl;
00316
00317 __COUT__<< "Translating data: ";
00318
00319 char data[theFEInterfacesManager->getInterfaceUniversalDataSize(InterfaceID)];
00320
00321 if(dataStr.size()%2)
00322 dataStr = "0" + dataStr;
00323
00324 i=0;
00325 for(;i<dataStr.size() &&
00326 i/2 < theFEInterfacesManager->getInterfaceUniversalDataSize(InterfaceID) ; i+=2)
00327 {
00328 tmpHex[0] = dataStr[dataStr.size()-1-i-1];
00329 tmpHex[1] = dataStr[dataStr.size()-1-i];
00330 sscanf(tmpHex,"%hhX",(unsigned char*)&data[i/2]);
00331 printf("%2.2X",(unsigned char)data[i/2]);
00332 }
00333
00334 for(;i/2 < theFEInterfacesManager->getInterfaceUniversalDataSize(InterfaceID) ; i+=2)
00335 {
00336 data[i/2] = 0;
00337 printf("%2.2X",(unsigned char)data[i/2]);
00338 }
00339
00340 std::cout << std::endl;
00341
00342
00343
00344
00345
00346
00347
00348
00349 theFEInterfacesManager->universalWrite(InterfaceID,address,data);
00350
00351
00352
00353
00354 return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "DataWritten",retParameters);
00355 }
00356 else if(request == "UniversalRead")
00357 {
00358 if(!theFEInterfacesManager)
00359 {
00360 __COUT_INFO__ << "No FE Interface Manager! (So no read occurred)" << std::endl;
00361 return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "aa",retParameters);
00362 }
00363
00364
00365
00366
00367
00368 __COUT__<< "theFEInterfacesManager->getInterfaceUniversalAddressSize(index) "
00369 << theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID) << std::endl;
00370 __COUT__<< "theFEInterfacesManager->getInterfaceUniversalDataSize(index) "
00371 <<theFEInterfacesManager->getInterfaceUniversalDataSize(InterfaceID) << std::endl;
00372
00373 char tmpHex[3];
00374 tmpHex[2] = '\0';
00375
00376
00377 __COUT__<< "Translating address: ";
00378
00379 char address[theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID)];
00380
00381 if(addressStr.size()%2)
00382 addressStr = "0" + addressStr;
00383
00384 unsigned int i=0;
00385 for(;i<addressStr.size() &&
00386 i/2 < theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID) ; i+=2)
00387 {
00388 tmpHex[0] = addressStr[addressStr.size()-1-i-1];
00389 tmpHex[1] = addressStr[addressStr.size()-1-i];
00390 sscanf(tmpHex,"%hhX",(unsigned char*)&address[i/2]);
00391 printf("%2.2X",(unsigned char)address[i/2]);
00392 }
00393
00394 for(;i/2 < theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID) ; i+=2)
00395 {
00396 address[i/2] = 0;
00397 printf("%2.2X",(unsigned char)address[i/2]);
00398 }
00399
00400 std::cout << std::endl;
00401
00402 unsigned int dataSz = theFEInterfacesManager->getInterfaceUniversalDataSize(InterfaceID);
00403 char data[dataSz];
00404
00405
00406
00407
00408
00409 try
00410 {
00411 if(theFEInterfacesManager->universalRead(InterfaceID, address, data) < 0)
00412 {
00413 retParameters.addParameter("dataResult","Time Out Error");
00414 return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "aa",retParameters);
00415 }
00416 }
00417 catch(const std::runtime_error& e)
00418 {
00419
00420 __MOUT_ERR__ << "Exception caught during read: " << e.what() << std::endl;
00421 __COUT_ERR__ << "Exception caught during read: " << e.what() << std::endl;
00422 retParameters.addParameter("dataResult","Time Out Error");
00423 return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "aa",retParameters);
00424 }
00425 catch(...)
00426 {
00427
00428 __MOUT_ERR__ << "Exception caught during read." << std::endl;
00429 __COUT_ERR__ << "Exception caught during read." << std::endl;
00430 retParameters.addParameter("dataResult","Time Out Error");
00431 return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "aa",retParameters);
00432 }
00433
00434
00435 if(dataSz <= 8)
00436 {
00437 std::string str8(data);
00438 str8.resize(8);
00439 __COUT__<< "decResult[" << dataSz << " bytes]: " <<
00440 *((unsigned long long *)(&str8[0])) << std::endl;
00441
00442 }
00443
00444 char hexResult[dataSz*2+1];
00445
00446
00447
00448 for(unsigned int i=0;i<dataSz;++i)
00449 {
00450 sprintf(&hexResult[i*2],"%2.2X", (unsigned char)data[dataSz-1-i]);
00451 }
00452
00453 __COUT__<< "hexResult[" << strlen(hexResult) << " nibbles]: " << std::string(hexResult) << std::endl;
00454
00455
00456
00457 retParameters.addParameter("dataResult",hexResult);
00458 return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "aa",retParameters);
00459
00460 }
00461 else if(request == "GetInterfaceMacros")
00462 {
00463 if(theFEInterfacesManager)
00464 retParameters.addParameter("FEMacros",theFEInterfacesManager->getFEMacrosString(
00465 std::to_string(getApplicationDescriptor()->getLocalId())));
00466 else
00467 retParameters.addParameter("FEMacros","");
00468
00469 return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "Response",
00470 retParameters);
00471 }
00472 else if(request == "RunInterfaceMacro")
00473 {
00474 if(!theFEInterfacesManager)
00475 {
00476 retParameters.addParameter("success","0");
00477 retParameters.addParameter("outputArgs","");
00478 return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "Response",
00479 retParameters);
00480 }
00481
00482 std::string feMacroName = parameters.getValue("feMacroName");
00483 std::string inputArgs = parameters.getValue("inputArgs");
00484 std::string outputArgs = parameters.getValue("outputArgs");
00485
00486
00487
00488 bool success = true;
00489 try
00490 {
00491 theFEInterfacesManager->runFEMacro(InterfaceID,feMacroName,inputArgs,outputArgs);
00492 }
00493 catch(std::runtime_error &e)
00494 {
00495 __SS__ << "In Supervisor with LID=" << getApplicationDescriptor()->getLocalId()
00496 << " the FE Macro named '" << feMacroName << "' with tartget FE '"
00497 << InterfaceID << "' failed. Here is the error:\n\n" << e.what() << std::endl;
00498 __COUT_ERR__ << "\n" << ss.str();
00499 success = false;
00500 outputArgs = ss.str();
00501 }
00502
00503
00504 retParameters.addParameter("success",success?"1":"0");
00505 retParameters.addParameter("outputArgs",outputArgs);
00506
00507 return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "Response",
00508 retParameters);
00509 }
00510 else
00511 {
00512 __COUT_WARN__ << "Unrecognized request received! '" << request << "'" << std::endl;
00513 }
00514
00515
00516 return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "FailRequest",retParameters);
00517 }
00518
00519
00520 xoap::MessageReference CoreSupervisorBase::workLoopStatusRequest(xoap::MessageReference message)
00521 throw (xoap::exception::Exception)
00522 {
00523
00524 FEVInterfacesManager* theFEInterfacesManager = extractFEInterfaceManager();
00525
00526 if(!theFEInterfacesManager)
00527 {
00528 __SS__ << "Invalid request for front-end workloop status from Supervisor without a FEVInterfacesManager."
00529 << std::endl;
00530 __COUT_ERR__ << ss.str();
00531 throw std::runtime_error(ss.str());
00532 }
00533
00534 return SOAPUtilities::makeSOAPMessageReference(
00535 (theFEInterfacesManager->allFEWorkloopsAreDone()?"Done":"Working"));
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546 FEVInterfacesManager* CoreSupervisorBase::extractFEInterfaceManager()
00547 {
00548 FEVInterfacesManager* theFEInterfacesManager = 0;
00549
00550 for(unsigned int i = 0; i<theStateMachineImplementation_.size();++i)
00551 {
00552 try
00553 {
00554 theFEInterfacesManager =
00555 dynamic_cast<FEVInterfacesManager*>(theStateMachineImplementation_[i]);
00556 if(!theFEInterfacesManager)
00557 {
00558
00559 __SS__ << "Dynamic cast failure!" << std::endl;
00560 __COUT_ERR__ << ss.str();
00561 throw std::runtime_error(ss.str());
00562 }
00563 __COUT__ << "State Machine " << i << " WAS of type FEVInterfacesManager" << std::endl;
00564
00565 break;
00566 }
00567 catch(...)
00568 {
00569 __COUT__ << "State Machine " << i << " was NOT of type FEVInterfacesManager" << std::endl;
00570 }
00571 }
00572
00573 __COUT__ << "theFEInterfacesManager pointer = " << theFEInterfacesManager << std::endl;
00574
00575 return theFEInterfacesManager;
00576 }
00577
00578
00579 void CoreSupervisorBase::stateInitial(toolbox::fsm::FiniteStateMachine& fsm)
00580 throw (toolbox::fsm::exception::Exception)
00581 {
00582 __COUT__ << "CoreSupervisorBase::stateInitial" << std::endl;
00583 }
00584
00585
00586 void CoreSupervisorBase::stateHalted(toolbox::fsm::FiniteStateMachine& fsm)
00587 throw (toolbox::fsm::exception::Exception)
00588 {
00589 __COUT__ << "CoreSupervisorBase::stateHalted" << std::endl;
00590 }
00591
00592
00593 void CoreSupervisorBase::stateRunning(toolbox::fsm::FiniteStateMachine& fsm)
00594 throw (toolbox::fsm::exception::Exception)
00595 {
00596 __COUT__ << "CoreSupervisorBase::stateRunning" << std::endl;
00597 }
00598
00599
00600 void CoreSupervisorBase::stateConfigured(toolbox::fsm::FiniteStateMachine& fsm)
00601 throw (toolbox::fsm::exception::Exception)
00602 {
00603 __COUT__ << "CoreSupervisorBase::stateConfigured" << std::endl;
00604 }
00605
00606
00607 void CoreSupervisorBase::statePaused(toolbox::fsm::FiniteStateMachine& fsm)
00608 throw (toolbox::fsm::exception::Exception)
00609 {
00610 __COUT__ << "CoreSupervisorBase::statePaused" << std::endl;
00611 }
00612
00613
00614 void CoreSupervisorBase::inError (toolbox::fsm::FiniteStateMachine & fsm)
00615 throw (toolbox::fsm::exception::Exception)
00616 {
00617 __COUT__<< "Fsm current state: " << theStateMachine_.getCurrentStateName()<< std::endl;
00618
00619 }
00620
00621
00622 void CoreSupervisorBase::enteringError (toolbox::Event::Reference e)
00623 throw (toolbox::fsm::exception::Exception)
00624 {
00625 __COUT__<< "Fsm current state: " << theStateMachine_.getCurrentStateName()
00626 << "\n\nError Message: " <<
00627 theStateMachine_.getErrorMessage() << std::endl;
00628 toolbox::fsm::FailedEvent& failedEvent = dynamic_cast<toolbox::fsm::FailedEvent&>(*e);
00629 std::ostringstream error;
00630 error << "Failure performing transition from "
00631 << failedEvent.getFromState()
00632 << " to "
00633 << failedEvent.getToState()
00634 << " exception: " << failedEvent.getException().what();
00635 __COUT_ERR__<< error.str() << std::endl;
00636
00637
00638 }
00639
00640
00641 void CoreSupervisorBase::transitionConfiguring(toolbox::Event::Reference e)
00642 throw (toolbox::fsm::exception::Exception)
00643 {
00644 __COUT__ << "transitionConfiguring" << std::endl;
00645
00646 std::pair<std::string , ConfigurationGroupKey> theGroup(
00647 SOAPUtilities::translate(theStateMachine_.getCurrentMessage()).
00648 getParameters().getValue("ConfigurationGroupName"),
00649 ConfigurationGroupKey(SOAPUtilities::translate(theStateMachine_.getCurrentMessage()).
00650 getParameters().getValue("ConfigurationGroupKey")));
00651
00652 __COUT__ << "Configuration group name: " << theGroup.first << " key: " <<
00653 theGroup.second << std::endl;
00654
00655 theConfigurationManager_->loadConfigurationGroup(
00656 theGroup.first,
00657 theGroup.second, true);
00658
00659
00660
00661
00662 try
00663 {
00664 for(auto& it: theStateMachineImplementation_)
00665 it->configure();
00666 }
00667 catch(const std::runtime_error& e)
00668 {
00669 __SS__ << "Error was caught while configuring: " << e.what() << std::endl;
00670 __COUT_ERR__ << "\n" << ss.str();
00671 theStateMachine_.setErrorMessage(ss.str());
00672 throw toolbox::fsm::exception::Exception(
00673 "Transition Error" ,
00674 ss.str() ,
00675 "CoreSupervisorBase::transitionConfiguring" ,
00676 __LINE__ ,
00677 __FUNCTION__
00678 );
00679 }
00680
00681 }
00682
00683
00684
00685
00686 void CoreSupervisorBase::transitionHalting(toolbox::Event::Reference e)
00687 throw (toolbox::fsm::exception::Exception)
00688 {
00689 __COUT__ << "transitionHalting" << std::endl;
00690
00691 for(auto& it: theStateMachineImplementation_)
00692 {
00693 try
00694 {
00695 it->halt();
00696 }
00697 catch(const std::runtime_error& e)
00698 {
00699
00700 if(theStateMachine_.getProvenanceStateName() ==
00701 RunControlStateMachine::FAILED_STATE_NAME)
00702 {
00703 __COUT_INFO__ << "Error was caught while halting (but ignoring because previous state was '" <<
00704 RunControlStateMachine::FAILED_STATE_NAME << "'): " << e.what() << std::endl;
00705 }
00706 else
00707 {
00708 __SS__ << "Error was caught while halting: " << e.what() << std::endl;
00709 __COUT_ERR__ << "\n" << ss.str();
00710 theStateMachine_.setErrorMessage(ss.str());
00711 throw toolbox::fsm::exception::Exception(
00712 "Transition Error" ,
00713 ss.str() ,
00714 "CoreSupervisorBase::transitionHalting" ,
00715 __LINE__ ,
00716 __FUNCTION__
00717 );
00718 }
00719 }
00720 }
00721 }
00722
00723
00724 void CoreSupervisorBase::transitionInitializing(toolbox::Event::Reference e)
00725 throw (toolbox::fsm::exception::Exception)
00726 {
00727 __COUT__ << "transitionInitializing" << std::endl;
00728
00729
00730
00731 }
00732
00733
00734 void CoreSupervisorBase::transitionPausing(toolbox::Event::Reference e)
00735 throw (toolbox::fsm::exception::Exception)
00736 {
00737 __COUT__ << "transitionPausing" << std::endl;
00738
00739 try
00740 {
00741 for(auto& it: theStateMachineImplementation_)
00742 it->pause();
00743 }
00744 catch(const std::runtime_error& e)
00745 {
00746 __SS__ << "Error was caught while pausing: " << e.what() << std::endl;
00747 __COUT_ERR__ << "\n" << ss.str();
00748 theStateMachine_.setErrorMessage(ss.str());
00749 throw toolbox::fsm::exception::Exception(
00750 "Transition Error" ,
00751 ss.str() ,
00752 "CoreSupervisorBase::transitionPausing" ,
00753 __LINE__ ,
00754 __FUNCTION__
00755 );
00756 }
00757 }
00758
00759
00760 void CoreSupervisorBase::transitionResuming(toolbox::Event::Reference e)
00761 throw (toolbox::fsm::exception::Exception)
00762 {
00763
00764
00765
00766 __COUT__ << "transitionResuming" << std::endl;
00767
00768 try
00769 {
00770 for(auto& it: theStateMachineImplementation_)
00771 it->resume();
00772 }
00773 catch(const std::runtime_error& e)
00774 {
00775 __SS__ << "Error was caught while resuming: " << e.what() << std::endl;
00776 __COUT_ERR__ << "\n" << ss.str();
00777 theStateMachine_.setErrorMessage(ss.str());
00778 throw toolbox::fsm::exception::Exception(
00779 "Transition Error" ,
00780 ss.str() ,
00781 "CoreSupervisorBase::transitionResuming" ,
00782 __LINE__ ,
00783 __FUNCTION__
00784 );
00785 }
00786 }
00787
00788
00789 void CoreSupervisorBase::transitionStarting(toolbox::Event::Reference e)
00790 throw (toolbox::fsm::exception::Exception)
00791 {
00792
00793
00794
00795 __COUT__ << "transitionStarting" << std::endl;
00796
00797 try
00798 {
00799 for(auto& it: theStateMachineImplementation_)
00800 it->start(SOAPUtilities::translate(theStateMachine_.getCurrentMessage()).getParameters().getValue("RunNumber"));
00801 }
00802 catch(const std::runtime_error& e)
00803 {
00804 __SS__ << "Error was caught while starting: " << e.what() << std::endl;
00805 __COUT_ERR__ << "\n" << ss.str();
00806 theStateMachine_.setErrorMessage(ss.str());
00807 throw toolbox::fsm::exception::Exception(
00808 "Transition Error" ,
00809 ss.str() ,
00810 "CoreSupervisorBase::transitionStarting" ,
00811 __LINE__ ,
00812 __FUNCTION__
00813 );
00814 }
00815 }
00816
00817
00818 void CoreSupervisorBase::transitionStopping(toolbox::Event::Reference e)
00819 throw (toolbox::fsm::exception::Exception)
00820 {
00821 __COUT__ << "transitionStopping" << std::endl;
00822
00823 try
00824 {
00825 for(auto& it: theStateMachineImplementation_)
00826 it->stop();
00827 }
00828 catch(const std::runtime_error& e)
00829 {
00830 __SS__ << "Error was caught while pausing: " << e.what() << std::endl;
00831 __COUT_ERR__ << "\n" << ss.str();
00832 theStateMachine_.setErrorMessage(ss.str());
00833 throw toolbox::fsm::exception::Exception(
00834 "Transition Error" ,
00835 ss.str() ,
00836 "CoreSupervisorBase::transitionStopping" ,
00837 __LINE__ ,
00838 __FUNCTION__
00839 );
00840 }
00841 }