Go to the documentation of this file.00001
00006 #include "EventFilter/ResourceBroker/interface/RBStateMachine.h"
00007 #include "EvffedFillerRB.h"
00008
00009 #include <iostream>
00010
00011 using namespace evf::rb_statemachine;
00012 using namespace evf;
00013 using std::set;
00014 using std::string;
00015
00016
00017
00018 void Configuring::do_entryActionWork() {
00019 }
00020
00021 void Configuring::do_stateNotify() {
00022 SharedResourcesPtr_t res = outermost_context().getSharedResources();
00023 LOG4CPLUS_INFO(res->log_, "--> ResourceBroker: NEW STATE: " << stateName());
00024 outermost_context().setExternallyVisibleState(stateName());
00025 outermost_context().setInternalStateName(stateName());
00026
00027
00028
00029 }
00030
00031 void Configuring::do_stateAction() const {
00032 SharedResourcesPtr_t res = outermost_context().getSharedResources();
00033
00034 try {
00035 LOG4CPLUS_INFO(res->log_, "Start configuring ...");
00036
00037 connectToBUandSM();
00038
00039 res->frb_ = new EvffedFillerRB(
00040 (FUResourceBroker*) outermost_context().getApp());
00041
00042 res->configureResources(outermost_context().getApp());
00043
00044 if (res->shmInconsistent_) {
00045 std::ostringstream ost;
00046 ost
00047 << "configuring FAILED: Inconsistency in ResourceTable - nbRaw="
00048 << res->nbRawCells_.value_ << " but nbResources="
00049 << res->resourceStructure_->nbResources()
00050 << " and nbFreeSlots="
00051 << res->resourceStructure_->nbFreeSlots();
00052 XCEPT_RAISE(evf::Exception, ost.str());
00053 }
00054
00055 LOG4CPLUS_INFO(res->log_, "Finished configuring!");
00056
00057 EventPtr configureDone(new ConfigureDone());
00058 res->commands_.enqEvent(configureDone);
00059
00060 } catch (xcept::Exception &e) {
00061 moveToFailedState(e);
00062 }
00063 }
00064
00065
00066
00067 Configuring::Configuring(my_context c) :
00068 my_base(c) {
00069 safeEntryAction();
00070 }
00071
00072 Configuring::~Configuring() {
00073 safeExitAction();
00074 }
00075
00076
00077
00078 void Configuring::do_exitActionWork() {
00079 }
00080
00081 string Configuring::do_stateName() const {
00082 return string("Configuring");
00083 }
00084
00085 void Configuring::do_moveToFailedState(xcept::Exception& exception) const {
00086 SharedResourcesPtr_t res = outermost_context().getSharedResources();
00087 res->reasonForFailed_ = exception.what();
00088 LOG4CPLUS_FATAL(res->log_,
00089 "Moving to FAILED state! Reason: " << exception.what());
00090 EventPtr fail(new Fail());
00091 res->commands_.enqEvent(fail);
00092 }
00093
00094
00095
00096 void Configuring::connectToBUandSM() const throw (evf::Exception) {
00097
00098 SharedResourcesPtr_t res = outermost_context().getSharedResources();
00099 xdaq::Application* app = outermost_context().getApp();
00100
00101 typedef set<xdaq::ApplicationDescriptor*> AppDescSet_t;
00102 typedef AppDescSet_t::iterator AppDescIter_t;
00103
00104
00105 AppDescSet_t
00106 setOfBUs =
00107 app->getApplicationContext()->getDefaultZone()-> getApplicationDescriptors(
00108 res->buClassName_.toString());
00109
00110 if (0 != res->bu_) {
00111 delete res->bu_;
00112 res->bu_ = 0;
00113 }
00114
00115 for (AppDescIter_t it = setOfBUs.begin(); it != setOfBUs.end(); ++it)
00116
00117 if ((*it)->getInstance() == res->buInstance_)
00118
00119 res->bu_ = new BUProxy(app->getApplicationDescriptor(), *it,
00120 app->getApplicationContext(), res->i2oPool_);
00121
00122 if (0 == res->bu_) {
00123 string msg = res->sourceId_ + " failed to locate input BU!";
00124 XCEPT_RAISE(evf::Exception, msg);
00125 }
00126
00127
00128 AppDescSet_t
00129 setOfSMs =
00130 app->getApplicationContext()->getDefaultZone()-> getApplicationDescriptors(
00131 res->smClassName_.toString());
00132
00133 if (0 != res->sm_) {
00134 delete res->sm_;
00135 res->sm_ = 0;
00136 }
00137
00138 for (AppDescIter_t it = setOfSMs.begin(); it != setOfSMs.end(); ++it)
00139 if ((*it)->getInstance() == res->smInstance_)
00140 res->sm_ = new SMProxy(app->getApplicationDescriptor(), *it,
00141 app->getApplicationContext(), res->i2oPool_);
00142
00143 if (0 == res->sm_)
00144 LOG4CPLUS_WARN(res->log_,
00145 res->sourceId_ << " failed to locate output SM!");
00146 }