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