CMS 3D CMS Logo

Public Member Functions | Private Attributes

smproxy::StateMachine Class Reference

#include <StateMachine.h>

List of all members.

Public Member Functions

void clearConsumerRegistrations ()
void clearInitMsgCollection ()
void clearQueues ()
void disableConsumerRegistration ()
void enableConsumerRegistration ()
void failEvent (const Fail &)
xdaq::ApplicationDescriptor * getApplicationDescriptor () const
ConfigurationPtr getConfiguration () const
DataManagerPtr getDataManager () const
stor::DQMEventQueueCollectionPtr getDQMEventQueueCollection () const
EventQueueCollectionPtr getEventQueueCollection () const
std::string getExternallyVisibleStateName ()
stor::InitMsgCollectionPtr getInitMsgCollection () const
std::string getReasonForFailed ()
stor::RegistrationCollectionPtr getRegistrationCollection () const
stor::RegistrationQueuePtr getRegistrationQueue () const
std::string getStateName ()
StatisticsReporterPtr getStatisticsReporter () const
void moveToFailedState (xcept::Exception &e)
std::string processEvent (const boost::statechart::event_base &)
void resetStatistics ()
void setAlarms ()
void setExternallyVisibleStateName (const std::string &stateName)
void setQueueSizes ()
 StateMachine (xdaq::Application *)
void unconsumed_event (const boost::statechart::event_base &)
void updateConfiguration ()

Private Attributes

xdaq::Application * app_
std::string appNameAndInstance_
ConfigurationPtr configuration_
DataManagerPtr dataManager_
stor::DQMEventQueueCollectionPtr dqmEventQueueCollection_
boost::mutex eventMutex_
EventQueueCollectionPtr eventQueueCollection_
stor::InitMsgCollectionPtr initMsgCollection_
xdaq2rc::RcmsStateNotifier rcmsStateNotifier_
std::string reasonForFailed_
stor::RegistrationCollectionPtr registrationCollection_
stor::RegistrationQueuePtr registrationQueue_
xdata::String stateName_
StatisticsReporterPtr statisticsReporter_

Detailed Description

Definition at line 68 of file StateMachine.h.


Constructor & Destructor Documentation

smproxy::StateMachine::StateMachine ( xdaq::Application *  app)

Definition at line 20 of file StateMachine.cc.

References edm::errors::Configuration.

   :
  app_(app),
  rcmsStateNotifier_
  (
    app->getApplicationLogger(),
    app->getApplicationDescriptor(),
    app->getApplicationContext()
  ),
  reasonForFailed_(""),
  stateName_("Halted")
  {
    std::ostringstream oss;
    oss << app->getApplicationDescriptor()->getClassName()
      << app->getApplicationDescriptor()->getInstance();
    appNameAndInstance_ = oss.str();

    xdata::InfoSpace *is = app->getApplicationInfoSpace();
    is->fireItemAvailable("rcmsStateListener",
      rcmsStateNotifier_.getRcmsStateListenerParameter() );
    is->fireItemAvailable("foundRcmsStateListener",
      rcmsStateNotifier_.getFoundRcmsStateListenerParameter() );
    rcmsStateNotifier_.findRcmsStateListener();
    rcmsStateNotifier_.subscribeToChangesInRcmsStateListener(is);
  
    is->fireItemAvailable("stateName", &stateName_);

    initiate();

    configuration_.reset(new Configuration(
        app->getApplicationInfoSpace(), app->getApplicationDescriptor()->getInstance()
      ));

    registrationCollection_.reset( new stor::RegistrationCollection() );
    
    registrationQueue_.reset(new stor::RegistrationQueue(
        configuration_->getQueueConfigurationParams().registrationQueueSize_
      ));
    
    initMsgCollection_.reset(new stor::InitMsgCollection());

    statisticsReporter_.reset(new StatisticsReporter(app,
        configuration_->getQueueConfigurationParams()));

    eventQueueCollection_.reset(new EventQueueCollection(
        statisticsReporter_->getEventConsumerMonitorCollection()));
    
    dqmEventQueueCollection_.reset(new stor::DQMEventQueueCollection(
        statisticsReporter_->getDQMConsumerMonitorCollection()));
    
    dataManager_.reset(new DataManager(this));
  }

Member Function Documentation

void smproxy::StateMachine::clearConsumerRegistrations ( )

Definition at line 178 of file StateMachine.cc.

References dqmEventQueueCollection_, eventQueueCollection_, and registrationCollection_.

  {
    registrationCollection_->clearRegistrations();
    eventQueueCollection_->removeQueues();
    dqmEventQueueCollection_->removeQueues();
  }
void smproxy::StateMachine::clearInitMsgCollection ( )

Definition at line 166 of file StateMachine.cc.

References initMsgCollection_.

  {
    initMsgCollection_->clear();
  }
void smproxy::StateMachine::clearQueues ( )

Definition at line 200 of file StateMachine.cc.

References dqmEventQueueCollection_, eventQueueCollection_, and registrationQueue_.

  {
    registrationQueue_->clear();
    eventQueueCollection_->clearQueues();
    dqmEventQueueCollection_->clearQueues();
  }
void smproxy::StateMachine::disableConsumerRegistration ( )

Definition at line 193 of file StateMachine.cc.

References dataManager_, and registrationCollection_.

  {
    registrationCollection_->disableConsumerRegistration();
    dataManager_->stop();
  }
void smproxy::StateMachine::enableConsumerRegistration ( )

Definition at line 186 of file StateMachine.cc.

References configuration_, dataManager_, and registrationCollection_.

  {
    registrationCollection_->enableConsumerRegistration();
    dataManager_->start(configuration_->getDataRetrieverParams());
  }
void smproxy::StateMachine::failEvent ( const Fail evt)

Definition at line 92 of file StateMachine.cc.

References app_, smproxy::Fail::getException(), smproxy::Fail::getReason(), smproxy::Fail::getTraceback(), rcmsStateNotifier_, reasonForFailed_, and stateName_.

  {
    stateName_ = "Failed";
    reasonForFailed_ = evt.getTraceback();
    
    LOG4CPLUS_FATAL(app_->getApplicationLogger(),
      "Failed: " << evt.getReason() << ". " << reasonForFailed_);
    
    rcmsStateNotifier_.stateChanged(stateName_, evt.getReason());
    
    app_->notifyQualified("fatal", evt.getException());
  }
xdaq::ApplicationDescriptor* smproxy::StateMachine::getApplicationDescriptor ( ) const [inline]

Definition at line 109 of file StateMachine.h.

References app_.

    { return app_->getApplicationDescriptor(); }
ConfigurationPtr smproxy::StateMachine::getConfiguration ( ) const [inline]

Definition at line 93 of file StateMachine.h.

References configuration_.

Referenced by smproxy::DQMArchiver::createRegistration().

    { return configuration_; }
DataManagerPtr smproxy::StateMachine::getDataManager ( ) const [inline]

Definition at line 95 of file StateMachine.h.

References dataManager_.

    { return dataManager_; }
stor::DQMEventQueueCollectionPtr smproxy::StateMachine::getDQMEventQueueCollection ( ) const [inline]
EventQueueCollectionPtr smproxy::StateMachine::getEventQueueCollection ( ) const [inline]

Definition at line 103 of file StateMachine.h.

References eventQueueCollection_.

Referenced by smproxy::DataManager::checkForStaleConsumers().

    { return eventQueueCollection_; }
std::string smproxy::StateMachine::getExternallyVisibleStateName ( ) [inline]

Definition at line 90 of file StateMachine.h.

References stateName_.

    { return stateName_.toString(); }
stor::InitMsgCollectionPtr smproxy::StateMachine::getInitMsgCollection ( ) const [inline]

Definition at line 101 of file StateMachine.h.

References initMsgCollection_.

    { return initMsgCollection_; }
std::string smproxy::StateMachine::getReasonForFailed ( ) [inline]

Definition at line 86 of file StateMachine.h.

References reasonForFailed_.

    { return reasonForFailed_; }
stor::RegistrationCollectionPtr smproxy::StateMachine::getRegistrationCollection ( ) const [inline]
stor::RegistrationQueuePtr smproxy::StateMachine::getRegistrationQueue ( ) const [inline]

Definition at line 99 of file StateMachine.h.

References registrationQueue_.

    { return registrationQueue_; }
std::string smproxy::StateMachine::getStateName ( ) [inline]

Definition at line 88 of file StateMachine.h.

    { return state_cast<const StateName&>().stateName(); }
StatisticsReporterPtr smproxy::StateMachine::getStatisticsReporter ( ) const [inline]

Definition at line 107 of file StateMachine.h.

References statisticsReporter_.

    { return statisticsReporter_; }
void smproxy::StateMachine::moveToFailedState ( xcept::Exception e) [inline]
std::string smproxy::StateMachine::processEvent ( const boost::statechart::event_base &  event)

Definition at line 75 of file StateMachine.cc.

References eventMutex_.

Referenced by moveToFailedState().

  {
    boost::mutex::scoped_lock sl(eventMutex_);
    process_event(event);
    return state_cast<const StateName&>().stateName();
  }
void smproxy::StateMachine::resetStatistics ( )

Definition at line 172 of file StateMachine.cc.

References statisticsReporter_.

  {
    statisticsReporter_->reset();
  }
void smproxy::StateMachine::setAlarms ( )

Definition at line 157 of file StateMachine.cc.

References configuration_, and statisticsReporter_.

  {
    AlarmParams alarmParams =
      configuration_->getAlarmParams();
    statisticsReporter_->getDataRetrieverMonitorCollection().
      configureAlarms(alarmParams);
  }
void smproxy::StateMachine::setExternallyVisibleStateName ( const std::string &  stateName)

Definition at line 83 of file StateMachine.cc.

References appNameAndInstance_, rcmsStateNotifier_, and stateName_.

  {
    stateName_ = stateName;
    rcmsStateNotifier_.stateChanged(stateName,
      appNameAndInstance_ + " has reached target state " +
      stateName);
  }
void smproxy::StateMachine::setQueueSizes ( )

Definition at line 148 of file StateMachine.cc.

References configuration_, registrationQueue_, and smproxy::QueueConfigurationParams::registrationQueueSize_.

  {
    QueueConfigurationParams queueParams =
      configuration_->getQueueConfigurationParams();
    registrationQueue_->
      setCapacity(queueParams.registrationQueueSize_);
  }
void smproxy::StateMachine::unconsumed_event ( const boost::statechart::event_base &  evt)

Definition at line 106 of file StateMachine.cc.

References app_, mergeVDriftHistosByStation::name, and stateName_.

  {
    LOG4CPLUS_ERROR(app_->getApplicationLogger(),
      "The " << typeid(evt).name()
      << " event is not supported from the "
      << stateName_.toString() << " state!");
  }
void smproxy::StateMachine::updateConfiguration ( )

Definition at line 115 of file StateMachine.cc.

References edm::errors::Configuration, configuration_, exception, Exception, and moveToFailedState().

  {
    std::string errorMsg = "Failed to update configuration parameters";
    try
    {
      configuration_->updateAllParams();
    }
    catch(xcept::Exception &e)
    {
      XCEPT_DECLARE_NESTED(exception::Configuration,
        sentinelException, errorMsg, e);
      moveToFailedState(sentinelException);
    }
    catch( std::exception &e )
    {
      errorMsg.append(": ");
      errorMsg.append( e.what() );
      
      XCEPT_DECLARE(exception::Configuration,
        sentinelException, errorMsg);
      moveToFailedState(sentinelException);
    }
    catch(...)
    {
      errorMsg.append(": unknown exception");
      
      XCEPT_DECLARE(exception::Configuration,
        sentinelException, errorMsg);
      moveToFailedState(sentinelException);
    }
  }

Member Data Documentation

xdaq::Application* smproxy::StateMachine::app_ [private]

Definition at line 125 of file StateMachine.h.

Referenced by failEvent(), getApplicationDescriptor(), and unconsumed_event().

Definition at line 138 of file StateMachine.h.

Referenced by setExternallyVisibleStateName().

Definition at line 136 of file StateMachine.h.

Referenced by processEvent().

Definition at line 131 of file StateMachine.h.

Referenced by clearInitMsgCollection(), and getInitMsgCollection().

xdaq2rc::RcmsStateNotifier smproxy::StateMachine::rcmsStateNotifier_ [private]

Definition at line 126 of file StateMachine.h.

Referenced by failEvent(), and setExternallyVisibleStateName().

Definition at line 139 of file StateMachine.h.

Referenced by failEvent(), and getReasonForFailed().

Definition at line 130 of file StateMachine.h.

Referenced by clearQueues(), getRegistrationQueue(), and setQueueSizes().

xdata::String smproxy::StateMachine::stateName_ [private]

Definition at line 132 of file StateMachine.h.

Referenced by getStatisticsReporter(), resetStatistics(), and setAlarms().