otsdaq  v1_01_02
 All Classes Namespaces Functions
CoreSupervisorBase.cc
1 #include "otsdaq-core/CoreSupervisors/CoreSupervisorBase.h"
2 #include "otsdaq-core/XmlUtilities/HttpXmlDocument.h"
3 #include "otsdaq-core/SOAPUtilities/SOAPUtilities.h"
4 #include "otsdaq-core/SOAPUtilities/SOAPCommand.h"
5 #include "otsdaq-core/CgiDataUtilities/CgiDataUtilities.h"
6 //#include "otsdaq-core/Singleton/Singleton.h"
7 //#include "otsdaq-core/WorkLoopManager/WorkLoopManager.h"
8 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationGroupKey.h"
9 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
10 #include "otsdaq-core/ConfigurationInterface/ConfigurationTree.h"
11 #include "otsdaq-core/ConfigurationPluginDataFormats/XDAQContextConfiguration.h"
12 #include "otsdaq-core/MessageFacility/MessageFacility.h"
13 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
14 #include "otsdaq-core/FiniteStateMachine/VStateMachine.h"
15 #include "otsdaq-core/FECore/FEVInterfacesManager.h"
16 
17 
18 #include <toolbox/fsm/FailedEvent.h>
19 
20 #include <xdaq/NamespaceURI.h>
21 #include <xoap/Method.h>
22 
23 #include <iostream>
24 
25 using namespace ots;
26 
27 //XDAQ_INSTANTIATOR_IMPL(CoreSupervisorBase)
28 
29 //========================================================================================================================
30 CoreSupervisorBase::CoreSupervisorBase(xdaq::ApplicationStub * s)
31 throw (xdaq::exception::Exception)
32 : xdaq::Application (s)
33 , SOAPMessenger (this)
34 , stateMachineWorkLoopManager_ (toolbox::task::bind(this, &CoreSupervisorBase::stateMachineThread, "StateMachine"))
35 , stateMachineSemaphore_ (toolbox::BSem::FULL)
36 , theConfigurationManager_ (new ConfigurationManager)//(Singleton<ConfigurationManager>::getInstance()) //I always load the full config but if I want to load a partial configuration (new ConfigurationManager)
37 , XDAQContextConfigurationName_ (theConfigurationManager_->__GET_CONFIG__(XDAQContextConfiguration)->getConfigurationName())
38 , supervisorConfigurationPath_ ("INITIALIZED INSIDE THE CONTRUCTOR BECAUSE IT NEEDS supervisorContextUID_ and supervisorApplicationUID_")
39 , supervisorContextUID_ ("INITIALIZED INSIDE THE CONTRUCTOR TO LAUNCH AN EXCEPTION")
40 , supervisorApplicationUID_ ("INITIALIZED INSIDE THE CONTRUCTOR TO LAUNCH AN EXCEPTION")
41 , supervisorClass_ (getApplicationDescriptor()->getClassName())
42 , supervisorClassNoNamespace_ (supervisorClass_.substr(supervisorClass_.find_last_of(":")+1, supervisorClass_.length()-supervisorClass_.find_last_of(":")))
43 {
44  __MOUT__ << "Begin!" << std::endl;
45  __MOUT__ << "Begin!" << std::endl;
46  __MOUT__ << "Begin!" << std::endl;
47  __MOUT__ << "Begin!" << std::endl;
48  __MOUT__ << "Begin!" << std::endl;
49  xgi::bind (this, &CoreSupervisorBase::Default, "Default" );
50  xgi::bind (this, &CoreSupervisorBase::stateMachineXgiHandler, "StateMachineXgiHandler");
51  xgi::bind (this, &CoreSupervisorBase::request, "Request");
52 
53  xoap::bind(this, &CoreSupervisorBase::stateMachineStateRequest, "StateMachineStateRequest", XDAQ_NS_URI );
54  xoap::bind(this, &CoreSupervisorBase::macroMakerSupervisorRequest, "MacroMakerSupervisorRequest", XDAQ_NS_URI );
55 
56  try
57  {
58  supervisorContextUID_ = theConfigurationManager_->__GET_CONFIG__(XDAQContextConfiguration)->getContextUID(getApplicationContext()->getContextDescriptor()->getURL());
59  }
60  catch(...)
61  {
62  __MOUT_ERR__ << "XDAQ Supervisor could not access it's configuration through the Configuration Context Group." <<
63  " The XDAQContextConfigurationName = " << XDAQContextConfigurationName_ <<
64  ". The supervisorApplicationUID = " << supervisorApplicationUID_ << std::endl;
65  throw;
66  }
67  try
68  {
69  supervisorApplicationUID_ = theConfigurationManager_->__GET_CONFIG__(XDAQContextConfiguration)->getApplicationUID
70  (
71  getApplicationContext()->getContextDescriptor()->getURL(),
72  getApplicationDescriptor()->getLocalId()
73  );
74  }
75  catch(...)
76  {
77  __MOUT_ERR__ << "XDAQ Supervisor could not access it's configuration through the Configuration Application Group."
78  << " The supervisorApplicationUID = " << supervisorApplicationUID_ << std::endl;
79  throw;
80  }
81  supervisorConfigurationPath_ = "/" + supervisorContextUID_ + "/LinkToApplicationConfiguration/" + supervisorApplicationUID_ + "/LinkToSupervisorConfiguration";
82 
83  setStateMachineName(supervisorApplicationUID_);
84  __MOUT__ << "Done!" << std::endl;
85  __MOUT__ << "Done!" << std::endl;
86  __MOUT__ << "Done!" << std::endl;
87  __MOUT__ << "Done!" << std::endl;
88 
89  init();
90 }
91 
92 //========================================================================================================================
93 CoreSupervisorBase::~CoreSupervisorBase(void)
94 {
95  destroy();
96 }
97 //========================================================================================================================
98 void CoreSupervisorBase::init(void)
99 {
100  //This can be done in the constructor because when you start xdaq it loads the configuration that can't be changed while running!
101  __MOUT__ << "CONTEXT!" << std::endl;
102  __MOUT__ << "CONTEXT!" << std::endl;
103  __MOUT__ << "CONTEXT!" << std::endl;
104  supervisorDescriptorInfo_.init(getApplicationContext());
105  __MOUT__ << "Done!" << std::endl;
106  __MOUT__ << "Done!" << std::endl;
107  __MOUT__ << "Done!" << std::endl;
108  //RunControlStateMachine::reset();
109 }
110 
111 //========================================================================================================================
112 void CoreSupervisorBase::destroy(void)
113 {
114  for(auto& it: theStateMachineImplementation_)
115  delete it;
116  theStateMachineImplementation_.clear();
117 }
118 
119 //========================================================================================================================
120 void CoreSupervisorBase::Default(xgi::Input * in, xgi::Output * out )
121 throw (xgi::exception::Exception)
122 {
123 
124 
125  __MOUT__<< "Supervisor class " << supervisorClass_ << std::endl;
126 
127  *out << "<!DOCTYPE HTML><html lang='en'><frameset col='100%' row='100%'><frame src='/WebPath/html/" << supervisorClassNoNamespace_ << "Supervisor.html?urn=" <<
128  this->getApplicationDescriptor()->getLocalId() << //getenv((theSupervisorClassNoNamespace_ + "_SUPERVISOR_ID").c_str()) <<
129  "'></frameset></html>";
130 }
131 
132 //========================================================================================================================
133 void CoreSupervisorBase::request(xgi::Input * in, xgi::Output * out )
134 throw (xgi::exception::Exception)
135 {
136 
137 
138  cgicc::Cgicc cgi(in);
139  std::string write = CgiDataUtilities::getOrPostData(cgi,"write");
140  std::string addr = CgiDataUtilities::getOrPostData(cgi,"addr");
141  std::string data = CgiDataUtilities::getOrPostData(cgi,"data");
142 
143  __MOUT__<< "write " << write << " addr: " << addr << " data: " << data << std::endl;
144 
145  unsigned long long int addr64,data64;
146  sscanf(addr.c_str(),"%llu",&addr64);
147  sscanf(data.c_str(),"%llu",&data64);
148  __MOUT__<< "write " << write << " addr: " << addr64 << " data: " << data64 << std::endl;
149 
150  *out << "done";
151 }
152 
153 //========================================================================================================================
154 void CoreSupervisorBase::stateMachineXgiHandler(xgi::Input * in, xgi::Output * out )
155 throw (xgi::exception::Exception)
156 {}
157 
158 //========================================================================================================================
159 void CoreSupervisorBase::stateMachineResultXgiHandler(xgi::Input* in, xgi::Output* out )
160 throw (xgi::exception::Exception)
161 {}
162 
163 //========================================================================================================================
164 xoap::MessageReference CoreSupervisorBase::stateMachineXoapHandler(xoap::MessageReference message )
165 throw (xoap::exception::Exception)
166 {
167  __MOUT__<< "Soap Handler!" << std::endl;
168  stateMachineWorkLoopManager_.removeProcessedRequests();
169  stateMachineWorkLoopManager_.processRequest(message);
170  __MOUT__<< "Done - Soap Handler!" << std::endl;
171  return message;
172 }
173 
174 //========================================================================================================================
175 xoap::MessageReference CoreSupervisorBase::stateMachineResultXoapHandler(xoap::MessageReference message )
176 throw (xoap::exception::Exception)
177 {
178  __MOUT__<< "Soap Handler!" << std::endl;
179  //stateMachineWorkLoopManager_.removeProcessedRequests();
180  //stateMachineWorkLoopManager_.processRequest(message);
181  __MOUT__<< "Done - Soap Handler!" << std::endl;
182  return message;
183 }
184 
185 //========================================================================================================================
186 bool CoreSupervisorBase::stateMachineThread(toolbox::task::WorkLoop* workLoop)
187 {
188  stateMachineSemaphore_.take();
189  __MOUT__<< "Re-sending message..." << SOAPUtilities::translate(stateMachineWorkLoopManager_.getMessage(workLoop)).getCommand() << std::endl;
190  std::string reply = send(this->getApplicationDescriptor(),stateMachineWorkLoopManager_.getMessage(workLoop));
191  stateMachineWorkLoopManager_.report(workLoop, reply, 100, true);
192  __MOUT__<< "Done with message" << std::endl;
193  stateMachineSemaphore_.give();
194  return false;//execute once and automatically remove the workloop so in WorkLoopManager the try workLoop->remove(job_) could be commented out
195  //return true;//go on and then you must do the workLoop->remove(job_) in WorkLoopManager
196 }
197 
198 //========================================================================================================================
199 xoap::MessageReference CoreSupervisorBase::stateMachineStateRequest(xoap::MessageReference message)
200 throw (xoap::exception::Exception)
201 {
202  __MOUT__<< theStateMachine_.getCurrentStateName() << std::endl;
203  return SOAPUtilities::makeSOAPMessageReference(theStateMachine_.getCurrentStateName());
204 }
205 
206 //========================================================================================================================
207 // macroMakerSupervisorRequest
208 // Handles all MacroMaker Requests:
209 // - GetInterfaces (returns interface type and id)
210 //
211 // Note: this code assumes a CoreSupervisorBase has only one
212 // FEVInterfacesManager in its vector of state machines
213 xoap::MessageReference CoreSupervisorBase::macroMakerSupervisorRequest(
214  xoap::MessageReference message)
215 throw (xoap::exception::Exception)
216 {
217  __MOUT__<< "$$$$$$$$$$$$$$$$$" << std::endl;
218 
219  //locate theFEInterfacesManager in state machines vector
220  FEVInterfacesManager* theFEInterfacesManager = 0;
221  for(unsigned int i = 0; i<theStateMachineImplementation_.size();++i)
222  {
223  try
224  {
225  theFEInterfacesManager =
226  dynamic_cast<FEVInterfacesManager*>(theStateMachineImplementation_[i]);
227  if(!theFEInterfacesManager) throw std::runtime_error(""); //dynamic_cast returns null pointer on failure
228  __MOUT__ << "State Machine " << i << " WAS of type FEVInterfacesManager" << std::endl;
229 
230  break;
231  }
232  catch(...)
233  {
234  __MOUT__ << "State Machine " << i << " was NOT of type FEVInterfacesManager" << std::endl;
235  }
236  }
237 
238 
239  __MOUT__ << "theFEInterfacesManager pointer = " << theFEInterfacesManager << std::endl;
240 
241  //receive request parameters
242  SOAPParameters parameters;
243  parameters.addParameter("Request");
244  parameters.addParameter("InterfaceID");
245 
246  //params for universal commands
247  parameters.addParameter("Address");
248  parameters.addParameter("Data");
249 
250  //params for running macros
251  parameters.addParameter("feMacroName");
252  parameters.addParameter("inputArgs");
253  parameters.addParameter("outputArgs");
254 
255  SOAPMessenger::receive(message, parameters);
256  std::string request = parameters.getValue("Request");
257  std::string addressStr = parameters.getValue("Address");
258  std::string dataStr = parameters.getValue("Data");
259  std::string InterfaceID = parameters.getValue("InterfaceID");
260 
261  __MOUT__<< "request: " << request << std::endl;
262 
263  __MOUT__<< "Address: " << addressStr << " Data: "
264  << dataStr << " InterfaceID: " << InterfaceID << std::endl;
265 
266  SOAPParameters retParameters;
267 
268  if(request == "GetInterfaces")
269  {
270  if(theFEInterfacesManager)
271  retParameters.addParameter("FEList",theFEInterfacesManager->getFEListString(
272  std::to_string(getApplicationDescriptor()->getLocalId())));
273  else
274  retParameters.addParameter("FEList","");
275 
276  return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "Response",
277  retParameters);
278  }
279  else if(request == "UniversalWrite")
280  {
281  if(!theFEInterfacesManager)
282  {
283  __MOUT_INFO__ << "No FE Interface Manager! (So no write occurred)" << std::endl;
284  return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "DataWritten",retParameters);
285  }
286 
287  // parameters interface index!
288  //unsigned int index = stoi(indexStr); // As long as the supervisor has only one interface, this index will remain 0?
289 
290 
291 
292  __MOUT__<< "theFEInterfacesManager->getInterfaceUniversalAddressSize(index) " <<
293  theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID) << std::endl;
294  __MOUT__<< "theFEInterfacesManager->getInterfaceUniversalDataSize(index) " <<
295  theFEInterfacesManager->getInterfaceUniversalDataSize(InterfaceID) << std::endl;
296 
297  //Converting std::string to char*
298  //char address
299 
300  char tmpHex[3]; //for use converting hex to binary
301  tmpHex[2] = '\0';
302 
303 
304  __MOUT__<< "Translating address: ";
305 
306  char address[theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID)];
307 
308  if(addressStr.size()%2) //if odd, make even
309  addressStr = "0" + addressStr;
310  unsigned int i=0;
311  for(;i<addressStr.size() &&
312  i/2 < theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID) ; i+=2)
313  {
314  tmpHex[0] = addressStr[addressStr.size()-1-i-1];
315  tmpHex[1] = addressStr[addressStr.size()-1-i];
316  sscanf(tmpHex,"%hhX",(unsigned char*)&address[i/2]);
317  printf("%2.2X",(unsigned char)address[i/2]);
318  }
319  //finish and fill with 0s
320  for(;i/2 < theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID) ; i+=2)
321  {
322  address[i/2] = 0;
323  printf("%2.2X",(unsigned char)address[i/2]);
324  }
325 
326  std::cout << std::endl;
327 
328  __MOUT__<< "Translating data: ";
329 
330  char data[theFEInterfacesManager->getInterfaceUniversalDataSize(InterfaceID)];
331 
332  if(dataStr.size()%2) //if odd, make even
333  dataStr = "0" + dataStr;
334 
335  i=0;
336  for(;i<dataStr.size() &&
337  i/2 < theFEInterfacesManager->getInterfaceUniversalDataSize(InterfaceID) ; i+=2)
338  {
339  tmpHex[0] = dataStr[dataStr.size()-1-i-1];
340  tmpHex[1] = dataStr[dataStr.size()-1-i];
341  sscanf(tmpHex,"%hhX",(unsigned char*)&data[i/2]);
342  printf("%2.2X",(unsigned char)data[i/2]);
343  }
344  //finish and fill with 0s
345  for(;i/2 < theFEInterfacesManager->getInterfaceUniversalDataSize(InterfaceID) ; i+=2)
346  {
347  data[i/2] = 0;
348  printf("%2.2X",(unsigned char)data[i/2]);
349  }
350 
351  std::cout << std::endl;
352 
353  //char* address = new char[addressStr.size() + 1];
354  //std::copy(addressStr.begin(), addressStr.end(), address);
355  // address[addressStr.size()] = '\0';
356  // char* data = new char[dataStr.size() + 1];
357  // std::copy(dataStr.begin(), dataStr.end(), data);
358  // data[dataStr.size()] = '\0';
359 
360  theFEInterfacesManager->universalWrite(InterfaceID,address,data);
361 
362  //delete[] address;
363  //delete[] data;
364 
365  return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "DataWritten",retParameters);
366  }
367  else if(request == "UniversalRead")
368  {
369  if(!theFEInterfacesManager)
370  {
371  __MOUT_INFO__ << "No FE Interface Manager! (So no read occurred)" << std::endl;
372  return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "aa",retParameters);
373  }
374 
375  // parameters interface index!
376  // parameter address and data
377  //unsigned int index = stoi(indexStr); // As long as the supervisor has only one interface, this index will remain 0?
378 
379  __MOUT__<< "theFEInterfacesManager->getInterfaceUniversalAddressSize(index) "
380  << theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID) << std::endl;
381  __MOUT__<< "theFEInterfacesManager->getInterfaceUniversalDataSize(index) "
382  <<theFEInterfacesManager->getInterfaceUniversalDataSize(InterfaceID) << std::endl;
383 
384  char tmpHex[3]; //for use converting hex to binary
385  tmpHex[2] = '\0';
386 
387 
388  __MOUT__<< "Translating address: ";
389 
390  char address[theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID)];
391 
392  if(addressStr.size()%2) //if odd, make even
393  addressStr = "0" + addressStr;
394 
395  unsigned int i=0;
396  for(;i<addressStr.size() &&
397  i/2 < theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID) ; i+=2)
398  {
399  tmpHex[0] = addressStr[addressStr.size()-1-i-1];
400  tmpHex[1] = addressStr[addressStr.size()-1-i];
401  sscanf(tmpHex,"%hhX",(unsigned char*)&address[i/2]);
402  printf("%2.2X",(unsigned char)address[i/2]);
403  }
404  //finish and fill with 0s
405  for(;i/2 < theFEInterfacesManager->getInterfaceUniversalAddressSize(InterfaceID) ; i+=2)
406  {
407  address[i/2] = 0;
408  printf("%2.2X",(unsigned char)address[i/2]);
409  }
410 
411  std::cout << std::endl;
412 
413  unsigned int dataSz = theFEInterfacesManager->getInterfaceUniversalDataSize(InterfaceID);
414  char data[dataSz];
415 
416 
417  // std::string result = theFEInterfacesManager->universalRead(index,address,data);
418  // __MOUT__<< result << std::endl << std::endl;
419 
420  if(theFEInterfacesManager->universalRead(InterfaceID, address, data) < 0)
421  {
422  retParameters.addParameter("dataResult","Time Out Error");
423  return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "aa",retParameters);
424  }
425 
426  //if dataSz is less than 8 show what the unsigned number would be
427  if(dataSz <= 8)
428  {
429  std::string str8(data);
430  str8.resize(8);
431  __MOUT__<< "decResult[" << dataSz << " bytes]: " <<
432  *((unsigned long long *)(&str8[0])) << std::endl;
433 
434  }
435 
436  char hexResult[dataSz*2+1];
437  //go through each byte and convert it to hex value (i.e. 2 0-F chars)
438  //go backwards through source data since should be provided in host order
439  // (i.e. a cast to unsigned long long should acquire expected value)
440  for(unsigned int i=0;i<dataSz;++i)
441  {
442  sprintf(&hexResult[i*2],"%2.2X", (unsigned char)data[dataSz-1-i]);
443  }
444 
445  __MOUT__<< "hexResult[" << strlen(hexResult) << " nibbles]: " << std::string(hexResult) << std::endl;
446 
447 
448 
449  retParameters.addParameter("dataResult",hexResult);
450  return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "aa",retParameters);
451 
452  }
453  else if(request == "GetInterfaceMacros")
454  {
455  if(theFEInterfacesManager)
456  retParameters.addParameter("FEMacros",theFEInterfacesManager->getFEMacrosString(
457  std::to_string(getApplicationDescriptor()->getLocalId())));
458  else
459  retParameters.addParameter("FEMacros","");
460 
461  return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "Response",
462  retParameters);
463  }
464  else if(request == "RunInterfaceMacro")
465  {
466  if(!theFEInterfacesManager)
467  {
468  retParameters.addParameter("success","0");
469  retParameters.addParameter("outputArgs","");
470  return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "Response",
471  retParameters);
472  }
473 
474  std::string feMacroName = parameters.getValue("feMacroName");
475  std::string inputArgs = parameters.getValue("inputArgs");
476  std::string outputArgs = parameters.getValue("outputArgs");
477 
478  //outputArgs must be filled with the proper argument names
479  // and then the response output values will be returned in the string.
480  bool success = true;
481  try
482  {
483  theFEInterfacesManager->runFEMacro(InterfaceID,feMacroName,inputArgs,outputArgs);
484  }
485  catch(std::runtime_error &e)
486  {
487  __SS__ << "In Supervisor with LID=" << getApplicationDescriptor()->getLocalId()
488  << " the FE Macro named '" << feMacroName << "' with tartget FE '"
489  << InterfaceID << "' failed. Here is the error:\n\n" << e.what() << std::endl;
490  __MOUT_ERR__ << "\n" << ss.str();
491  success = false;
492  outputArgs = ss.str();
493  }
494 
495 
496  retParameters.addParameter("success",success?"1":"0");
497  retParameters.addParameter("outputArgs",outputArgs);
498 
499  return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "Response",
500  retParameters);
501  }
502  else
503  {
504  __MOUT_WARN__ << "Unrecognized request received! '" << request << "'" << std::endl;
505  }
506 
507 
508  return SOAPUtilities::makeSOAPMessageReference(supervisorClassNoNamespace_ + "FailRequest",retParameters);
509 }
510 
511 //========================================================================================================================
512 void CoreSupervisorBase::stateInitial(toolbox::fsm::FiniteStateMachine& fsm)
513 throw (toolbox::fsm::exception::Exception)
514 {
515  __MOUT__ << "CoreSupervisorBase::stateInitial" << std::endl;
516 }
517 
518 //========================================================================================================================
519 void CoreSupervisorBase::stateHalted(toolbox::fsm::FiniteStateMachine& fsm)
520 throw (toolbox::fsm::exception::Exception)
521 {
522  __MOUT__ << "CoreSupervisorBase::stateHalted" << std::endl;
523 }
524 
525 //========================================================================================================================
526 void CoreSupervisorBase::stateRunning(toolbox::fsm::FiniteStateMachine& fsm)
527 throw (toolbox::fsm::exception::Exception)
528 {
529  __MOUT__ << "CoreSupervisorBase::stateRunning" << std::endl;
530 }
531 
532 //========================================================================================================================
533 void CoreSupervisorBase::stateConfigured(toolbox::fsm::FiniteStateMachine& fsm)
534 throw (toolbox::fsm::exception::Exception)
535 {
536  __MOUT__ << "CoreSupervisorBase::stateConfigured" << std::endl;
537 }
538 
539 //========================================================================================================================
540 void CoreSupervisorBase::statePaused(toolbox::fsm::FiniteStateMachine& fsm)
541 throw (toolbox::fsm::exception::Exception)
542 {
543  __MOUT__ << "CoreSupervisorBase::statePaused" << std::endl;
544 }
545 
546 //========================================================================================================================
547 void CoreSupervisorBase::inError (toolbox::fsm::FiniteStateMachine & fsm)
548 throw (toolbox::fsm::exception::Exception)
549 {
550  __MOUT__<< "Fsm current state: " << theStateMachine_.getCurrentStateName()<< std::endl;
551  //rcmsStateNotifier_.stateChanged("Error", "");
552 }
553 
554 //========================================================================================================================
555 void CoreSupervisorBase::enteringError (toolbox::Event::Reference e)
556 throw (toolbox::fsm::exception::Exception)
557 {
558  __MOUT__<< "Fsm current state: " << theStateMachine_.getCurrentStateName()<< std::endl;
559  toolbox::fsm::FailedEvent& failedEvent = dynamic_cast<toolbox::fsm::FailedEvent&>(*e);
560  std::ostringstream error;
561  error << "Failure performing transition from "
562  << failedEvent.getFromState()
563  << " to "
564  << failedEvent.getToState()
565  << " exception: " << failedEvent.getException().what();
566  __MOUT__<< error.str() << std::endl;
567  //diagService_->reportError(errstr.str(),DIAGERROR);
568 
569 }
570 
571 //========================================================================================================================
572 void CoreSupervisorBase::transitionConfiguring(toolbox::Event::Reference e)
573 throw (toolbox::fsm::exception::Exception)
574 {
575 
576  std::pair<std::string /*group name*/, ConfigurationGroupKey> theGroup(
577  SOAPUtilities::translate(theStateMachine_.getCurrentMessage()).
578  getParameters().getValue("ConfigurationGroupName"),
579  ConfigurationGroupKey(SOAPUtilities::translate(theStateMachine_.getCurrentMessage()).
580  getParameters().getValue("ConfigurationGroupKey")));
581 
582  __MOUT__ << "Configuration group name: " << theGroup.first << " key: " <<
583  theGroup.second << std::endl;
584 
585  theConfigurationManager_->loadConfigurationGroup(
586  theGroup.first,
587  theGroup.second, true);
588 
589 
590  //Now that the configuration manager has all the necessary configurations I can create all objects dependent of the configuration
591  for(auto& it: theStateMachineImplementation_)
592  it->configure();
593 
594 }
595 
596 //========================================================================================================================
597 void CoreSupervisorBase::transitionHalting(toolbox::Event::Reference e)
598 throw (toolbox::fsm::exception::Exception)
599 {
600 
601  for(auto& it: theStateMachineImplementation_)
602  it->halt();
603 }
604 
605 //========================================================================================================================
606 void CoreSupervisorBase::transitionInitializing(toolbox::Event::Reference e)
607 throw (toolbox::fsm::exception::Exception)
608 {
609 
610  // for(auto& it: theStateMachineImplementation_)
611  //it->initialize();
612 }
613 
614 //========================================================================================================================
615 void CoreSupervisorBase::transitionPausing(toolbox::Event::Reference e)
616 throw (toolbox::fsm::exception::Exception)
617 {
618 
619  for(auto& it: theStateMachineImplementation_)
620  it->pause();
621 }
622 
623 //========================================================================================================================
624 void CoreSupervisorBase::transitionResuming(toolbox::Event::Reference e)
625 throw (toolbox::fsm::exception::Exception)
626 {
627 
628  //I want to first start the data manager first if this is a FEDataManagerSupervisor
629  for(auto it = theStateMachineImplementation_.rbegin(); it != theStateMachineImplementation_.rend(); it++)
630  (*it)->resume();
631 }
632 
633 //========================================================================================================================
634 void CoreSupervisorBase::transitionStarting(toolbox::Event::Reference e)
635 throw (toolbox::fsm::exception::Exception)
636 {
637 
638  //I want to first start the data manager first if this is a FEDataManagerSupervisor
639  for(auto it = theStateMachineImplementation_.rbegin(); it != theStateMachineImplementation_.rend(); it++)
640  (*it)->start(SOAPUtilities::translate(theStateMachine_.getCurrentMessage()).getParameters().getValue("RunNumber"));
641 }
642 
643 //========================================================================================================================
644 void CoreSupervisorBase::transitionStopping(toolbox::Event::Reference e)
645 throw (toolbox::fsm::exception::Exception)
646 {
647 
648  for(auto& it: theStateMachineImplementation_)
649  it->stop();
650 }