CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/EventFilter/ResourceBroker/src/Running.cc

Go to the documentation of this file.
00001 
00006 #include "EventFilter/ResourceBroker/interface/RBStateMachine.h"
00007 #include "EventFilter/ResourceBroker/interface/SharedResources.h"
00008 
00009 #include "interface/evb/i2oEVBMsgs.h"
00010 
00011 #include <iostream>
00012 
00013 using std::string;
00014 using std::cout;
00015 using std::endl;
00016 using namespace evf::rb_statemachine;
00017 
00018 // entry action, state notification, state action
00019 //______________________________________________________________________________
00020 void Running::do_entryActionWork() {
00021 }
00022 
00023 void Running::do_stateNotify() {
00024         SharedResourcesPtr_t res = outermost_context().getSharedResources();
00025         LOG4CPLUS_INFO(res->log_, "--> ResourceBroker: NEW STATE: " << stateName());
00026         outermost_context().setExternallyVisibleState("Enabled");
00027         outermost_context().setInternalStateName(stateName());
00028         // notify RCMS of the new state
00029         outermost_context().rcmsStateChangeNotify();
00030 }
00031 
00032 /*
00033  * Supported I2O operations
00034  */
00035 bool Running::take(toolbox::mem::Reference* bufRef) const {
00036         SharedResourcesPtr_t res = outermost_context().getSharedResources();
00037         bool eventComplete = false;
00038         try {
00039                 eventComplete = res->resourceStructure_->buildResource(bufRef);
00040         } catch (evf::Exception& e) {
00041                 moveToFailedState(e);
00042         }
00043 
00044         if (eventComplete && res->doDropEvents_) {
00045                 cout << "dropping event" << endl;
00046                 try {
00047                         res->resourceStructure_->dropEvent();
00048                 } catch (evf::Exception& e) {
00049                         moveToFailedState(e);
00050                 }
00051         }
00052         return true;
00053 }
00054 bool Running::evmLumisection(toolbox::mem::Reference* bufRef) const {
00055         SharedResourcesPtr_t res = outermost_context().getSharedResources();
00056         I2O_EVM_END_OF_LUMISECTION_MESSAGE_FRAME
00057                         *msg =
00058                                         (I2O_EVM_END_OF_LUMISECTION_MESSAGE_FRAME *) bufRef->getDataLocation();
00059         if (msg->lumiSection == 0) {
00060                 LOG4CPLUS_ERROR(res->log_, "EOL message received for ls=0!!! ");
00061                 EventPtr fail(new Fail());
00062                 res->commands_.enqEvent(fail);
00063                 return false;
00064         }
00065         res->nbReceivedEol_++;
00066         if (res->highestEolReceived_.value_ + 100 < msg->lumiSection) {
00067                 LOG4CPLUS_ERROR(
00068                                 res->log_,
00069                                 "EOL message not in sequence, expected "
00070                                                 << res->highestEolReceived_.value_ + 1 << " received "
00071                                                 << msg->lumiSection);
00072                 EventPtr fail(new Fail());
00073                 res->commands_.enqEvent(fail);
00074                 return false;
00075         }
00076         if (res->highestEolReceived_.value_ + 1 != msg->lumiSection)
00077                 LOG4CPLUS_WARN(
00078                                 res->log_,
00079                                 "EOL message not in sequence, expected "
00080                                                 << res->highestEolReceived_.value_ + 1 << " received "
00081                                                 << msg->lumiSection);
00082 
00083         if (res->highestEolReceived_.value_ < msg->lumiSection)
00084                 res->highestEolReceived_.value_ = msg->lumiSection;
00085 
00086         try {
00087                 res->resourceStructure_->postEndOfLumiSection(bufRef);
00088         } catch (evf::Exception& e) {
00089                 moveToFailedState(e);
00090         }
00091         return true;
00092 }
00093 
00094 bool Running::discardDataEvent(MemRef_t* bufRef) const {
00095         SharedResourcesPtr_t res = outermost_context().getSharedResources();
00096         bool returnValue = false;
00097         try {
00098                 returnValue = res->resourceStructure_->discardDataEvent(bufRef);
00099         } catch (evf::Exception& e) {
00100                 moveToFailedState(e);
00101         }
00102         return returnValue;
00103 }
00104 bool Running::discardDqmEvent(MemRef_t* bufRef) const {
00105         SharedResourcesPtr_t res = outermost_context().getSharedResources();
00106         bool returnValue = false;
00107         try {
00108                 returnValue = res->resourceStructure_->discardDqmEvent(bufRef);
00109         } catch (evf::Exception& e) {
00110                 moveToFailedState(e);
00111         }
00112         return returnValue;
00113 }
00114 
00115 // construction / destruction
00116 //______________________________________________________________________________
00117 Running::Running(my_context c) :
00118         my_base(c) {
00119         safeEntryAction();
00120 }
00121 
00122 Running::~Running() {
00123         safeExitAction();
00124 }
00125 
00126 // exit action, state name, move to failed state
00127 //______________________________________________________________________________
00128 void Running::do_exitActionWork() {
00129 }
00130 
00131 string Running::do_stateName() const {
00132         return string("Running");
00133 }
00134 
00135 void Running::do_moveToFailedState(xcept::Exception& exception) const {
00136         SharedResourcesPtr_t res = outermost_context().getSharedResources();
00137         res->reasonForFailed_ = exception.what();
00138         LOG4CPLUS_ERROR(res->log_,
00139                         "Moving to FAILED state! Reason: " << exception.what());
00140         EventPtr fail(new Fail());
00141         res->commands_.enqEvent(fail);
00142 
00143 }