CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Private Attributes

stor::StatisticsReporter Class Reference

#include <StatisticsReporter.h>

List of all members.

Public Member Functions

virtual void actionPerformed (xdata::Event &)
const DataSenderMonitorCollectiongetDataSenderMonitorCollection () const
DataSenderMonitorCollectiongetDataSenderMonitorCollection ()
const
DQMConsumerMonitorCollection
getDQMConsumerMonitorCollection () const
DQMConsumerMonitorCollectiongetDQMConsumerMonitorCollection ()
const DQMEventMonitorCollectiongetDQMEventMonitorCollection () const
DQMEventMonitorCollectiongetDQMEventMonitorCollection ()
EventConsumerMonitorCollectiongetEventConsumerMonitorCollection ()
const
EventConsumerMonitorCollection
getEventConsumerMonitorCollection () const
const FilesMonitorCollectiongetFilesMonitorCollection () const
FilesMonitorCollectiongetFilesMonitorCollection ()
const FragmentMonitorCollectiongetFragmentMonitorCollection () const
FragmentMonitorCollectiongetFragmentMonitorCollection ()
ResourceMonitorCollectiongetResourceMonitorCollection ()
const ResourceMonitorCollectiongetResourceMonitorCollection () const
const RunMonitorCollectiongetRunMonitorCollection () const
RunMonitorCollectiongetRunMonitorCollection ()
const
StateMachineMonitorCollection
getStateMachineMonitorCollection () const
StateMachineMonitorCollectiongetStateMachineMonitorCollection ()
StreamsMonitorCollectiongetStreamsMonitorCollection ()
const StreamsMonitorCollectiongetStreamsMonitorCollection () const
const ThroughputMonitorCollectiongetThroughputMonitorCollection () const
ThroughputMonitorCollectiongetThroughputMonitorCollection ()
void reset ()
void startWorkLoop (std::string workloopName)
 StatisticsReporter (xdaq::Application *, SharedResourcesPtr)
virtual ~StatisticsReporter ()

Private Types

typedef std::list< std::string > InfoSpaceItemNames

Private Member Functions

void addRunInfoQuantitiesToApplicationInfoSpace ()
void calculateStatistics ()
void collectInfoSpaceItems ()
void createMonitoringInfoSpace ()
bool monitorAction (toolbox::task::WorkLoop *)
StatisticsReporteroperator= (StatisticsReporter const &)
void putItemsIntoInfoSpace (MonitorCollection::InfoSpaceItems &)
 StatisticsReporter (StatisticsReporter const &)
void updateInfoSpace ()

Private Attributes

xdaq::Application * app_
xdata::UnsignedInteger32 closedFiles_
DataSenderMonitorCollection dataSenderMonCollection_
bool doMonitoring_
DQMConsumerMonitorCollection dqmConsumerMonCollection_
DQMEventMonitorCollection dqmEventMonCollection_
EventConsumerMonitorCollection eventConsumerMonCollection_
FilesMonitorCollection filesMonCollection_
FragmentMonitorCollection fragMonCollection_
xdata::InfoSpace * infoSpace_
InfoSpaceItemNames infoSpaceItemNames_
utils::TimePoint_t lastMonitorAction_
utils::Duration_t monitoringSleepSec_
toolbox::task::WorkLoop * monitorWL_
ResourceMonitorCollection resourceMonCollection_
RunMonitorCollection runMonCollection_
StateMachineMonitorCollection stateMachineMonCollection_
xdata::String stateName_
xdata::UnsignedInteger32 storedEvents_
StreamsMonitorCollection streamsMonCollection_
ThroughputMonitorCollection throughputMonCollection_

Detailed Description

Singleton to keep track of all monitoring and statistics issues

This class also starts the monitoring workloop to update the statistics for all MonitorCollections.

Author:
mommsen
Revision:
1.15
Date:
2011/11/08 10:48:40

Definition at line 50 of file StatisticsReporter.h.


Member Typedef Documentation

typedef std::list<std::string> stor::StatisticsReporter::InfoSpaceItemNames [private]

Definition at line 157 of file StatisticsReporter.h.


Constructor & Destructor Documentation

stor::StatisticsReporter::StatisticsReporter ( xdaq::Application *  app,
SharedResourcesPtr  sr 
) [explicit]
stor::StatisticsReporter::~StatisticsReporter ( ) [virtual]

Definition at line 86 of file StatisticsReporter.cc.

References doMonitoring_, and monitorWL_.

  {
    // Stop the monitoring activity
    doMonitoring_ = false;
    
    // Cancel the workloop (will wait until the action has finished)
    if ( monitorWL_ && monitorWL_->isActive() ) monitorWL_->cancel();
  }
stor::StatisticsReporter::StatisticsReporter ( StatisticsReporter const &  ) [private]

Member Function Documentation

void stor::StatisticsReporter::actionPerformed ( xdata::Event &  ispaceEvent) [virtual]

Update the variables put into the application info space

Definition at line 336 of file StatisticsReporter.cc.

References closedFiles_, alignCSCRings::e, Exception, filesMonCollection_, infoSpace_, stateMachineMonCollection_, stateName_, storedEvents_, streamsMonCollection_, AlCaHLTBitMon_QueryRunRegistry::string, and stor::MonitorCollection::updateInfoSpaceItems().

  {
    if (ispaceEvent.type() == "ItemRetrieveEvent")
    {
      std::string item =
        dynamic_cast<xdata::ItemRetrieveEvent&>(ispaceEvent).itemName();
      if (item == "closedFiles")
      {
        filesMonCollection_.updateInfoSpaceItems();
        try
        {
          closedFiles_.setValue( *(infoSpace_->find("closedFiles")) );
        }
        catch(xdata::exception::Exception& e)
        {
          closedFiles_ = 0;
        }
      }
      else if (item == "storedEvents")
      {
        streamsMonCollection_.updateInfoSpaceItems();
        try
        {
          storedEvents_.setValue( *(infoSpace_->find("storedEvents")) );
        }
        catch(xdata::exception::Exception& e)
        {
          storedEvents_ = 0;
        }
      } 
      else if (item == "stateName")
      {
        stateMachineMonCollection_.updateInfoSpaceItems();
        try
        {
          stateName_.setValue( *(infoSpace_->find("stateName")) );
        }
        catch(xdata::exception::Exception& e)
        {
          stateName_ = "unknown";
        }
      } 
    }
  }
void stor::StatisticsReporter::addRunInfoQuantitiesToApplicationInfoSpace ( ) [private]

Definition at line 181 of file StatisticsReporter.cc.

References app_, closedFiles_, stateName_, and storedEvents_.

  {
    xdata::InfoSpace *infoSpace = app_->getApplicationInfoSpace();
    
    // bind the local xdata variables to the infospace
    infoSpace->fireItemAvailable("stateName", &stateName_);
    infoSpace->fireItemAvailable("storedEvents", &storedEvents_);
    infoSpace->fireItemAvailable("closedFiles", &closedFiles_);
    
    // spacial handling for the monitoring values requested by the HLTSFM
    // we want to assure that the values are current when they are queried
    infoSpace->addItemRetrieveListener("stateName", this);
    infoSpace->addItemRetrieveListener("storedEvents", this);
    infoSpace->addItemRetrieveListener("closedFiles", this);
  }
void stor::StatisticsReporter::calculateStatistics ( ) [private]
void stor::StatisticsReporter::collectInfoSpaceItems ( ) [private]

Definition at line 131 of file StatisticsReporter.cc.

References stor::MonitorCollection::appendInfoSpaceItems(), dataSenderMonCollection_, dqmConsumerMonCollection_, dqmEventMonCollection_, eventConsumerMonCollection_, filesMonCollection_, fragMonCollection_, infoSpaceItemNames_, putItemsIntoInfoSpace(), resourceMonCollection_, runMonCollection_, stateMachineMonCollection_, streamsMonCollection_, and throughputMonCollection_.

  {
    MonitorCollection::InfoSpaceItems infoSpaceItems;
    infoSpaceItemNames_.clear();
    
    runMonCollection_.appendInfoSpaceItems(infoSpaceItems);
    fragMonCollection_.appendInfoSpaceItems(infoSpaceItems);
    filesMonCollection_.appendInfoSpaceItems(infoSpaceItems);
    streamsMonCollection_.appendInfoSpaceItems(infoSpaceItems);
    dataSenderMonCollection_.appendInfoSpaceItems(infoSpaceItems);
    dqmEventMonCollection_.appendInfoSpaceItems(infoSpaceItems);
    resourceMonCollection_.appendInfoSpaceItems(infoSpaceItems);
    stateMachineMonCollection_.appendInfoSpaceItems(infoSpaceItems);
    eventConsumerMonCollection_.appendInfoSpaceItems(infoSpaceItems);
    dqmConsumerMonCollection_.appendInfoSpaceItems(infoSpaceItems);
    throughputMonCollection_.appendInfoSpaceItems(infoSpaceItems);
    
    putItemsIntoInfoSpace(infoSpaceItems);
  }
void stor::StatisticsReporter::createMonitoringInfoSpace ( ) [private]

Definition at line 96 of file StatisticsReporter.cc.

References app_, alignCSCRings::e, Exception, infoSpace_, and AlCaHLTBitMon_QueryRunRegistry::string.

  {
    // Create an infospace which can be monitored.
    // The naming follows the old SM scheme.
    // In future, the instance number should be included.
    
    std::ostringstream oss;
    oss << "urn:xdaq-monitorable-" << app_->getApplicationDescriptor()->getClassName();
    
    std::string errorMsg =
      "Failed to create monitoring info space " + oss.str();
    
    try
    {
      toolbox::net::URN urn = app_->createQualifiedInfoSpace(oss.str());
      xdata::getInfoSpaceFactory()->lock();
      infoSpace_ = xdata::getInfoSpaceFactory()->get(urn.toString());
      xdata::getInfoSpaceFactory()->unlock();
    }
    catch(xdata::exception::Exception &e)
    {
      xdata::getInfoSpaceFactory()->unlock();
      
      XCEPT_RETHROW(stor::exception::Infospace, errorMsg, e);
    }
    catch (...)
    {
      xdata::getInfoSpaceFactory()->unlock();
      
      errorMsg += " : unknown exception";
      XCEPT_RAISE(stor::exception::Infospace, errorMsg);
    }
  }
DataSenderMonitorCollection& stor::StatisticsReporter::getDataSenderMonitorCollection ( ) [inline]

Definition at line 93 of file StatisticsReporter.h.

References dataSenderMonCollection_.

const DataSenderMonitorCollection& stor::StatisticsReporter::getDataSenderMonitorCollection ( ) const [inline]

Definition at line 90 of file StatisticsReporter.h.

References dataSenderMonCollection_.

const DQMConsumerMonitorCollection& stor::StatisticsReporter::getDQMConsumerMonitorCollection ( ) const [inline]

Definition at line 125 of file StatisticsReporter.h.

References dqmConsumerMonCollection_.

DQMConsumerMonitorCollection& stor::StatisticsReporter::getDQMConsumerMonitorCollection ( ) [inline]

Definition at line 128 of file StatisticsReporter.h.

References dqmConsumerMonCollection_.

const DQMEventMonitorCollection& stor::StatisticsReporter::getDQMEventMonitorCollection ( ) const [inline]

Definition at line 97 of file StatisticsReporter.h.

References dqmEventMonCollection_.

DQMEventMonitorCollection& stor::StatisticsReporter::getDQMEventMonitorCollection ( ) [inline]

Definition at line 100 of file StatisticsReporter.h.

References dqmEventMonCollection_.

const EventConsumerMonitorCollection& stor::StatisticsReporter::getEventConsumerMonitorCollection ( ) const [inline]

Definition at line 118 of file StatisticsReporter.h.

References eventConsumerMonCollection_.

EventConsumerMonitorCollection& stor::StatisticsReporter::getEventConsumerMonitorCollection ( ) [inline]

Definition at line 121 of file StatisticsReporter.h.

References eventConsumerMonCollection_.

const FilesMonitorCollection& stor::StatisticsReporter::getFilesMonitorCollection ( ) const [inline]

Definition at line 76 of file StatisticsReporter.h.

References filesMonCollection_.

    { return filesMonCollection_; }
FilesMonitorCollection& stor::StatisticsReporter::getFilesMonitorCollection ( ) [inline]

Definition at line 79 of file StatisticsReporter.h.

References filesMonCollection_.

    { return filesMonCollection_; }
const FragmentMonitorCollection& stor::StatisticsReporter::getFragmentMonitorCollection ( ) const [inline]

Definition at line 69 of file StatisticsReporter.h.

References fragMonCollection_.

    { return fragMonCollection_; }
FragmentMonitorCollection& stor::StatisticsReporter::getFragmentMonitorCollection ( ) [inline]

Definition at line 72 of file StatisticsReporter.h.

References fragMonCollection_.

    { return fragMonCollection_; }
const ResourceMonitorCollection& stor::StatisticsReporter::getResourceMonitorCollection ( ) const [inline]

Definition at line 104 of file StatisticsReporter.h.

References resourceMonCollection_.

ResourceMonitorCollection& stor::StatisticsReporter::getResourceMonitorCollection ( ) [inline]

Definition at line 107 of file StatisticsReporter.h.

References resourceMonCollection_.

RunMonitorCollection& stor::StatisticsReporter::getRunMonitorCollection ( ) [inline]

Definition at line 65 of file StatisticsReporter.h.

References runMonCollection_.

    { return runMonCollection_; }
const RunMonitorCollection& stor::StatisticsReporter::getRunMonitorCollection ( ) const [inline]

Definition at line 62 of file StatisticsReporter.h.

References runMonCollection_.

    { return runMonCollection_; }
StateMachineMonitorCollection& stor::StatisticsReporter::getStateMachineMonitorCollection ( ) [inline]

Definition at line 114 of file StatisticsReporter.h.

References stateMachineMonCollection_.

const StateMachineMonitorCollection& stor::StatisticsReporter::getStateMachineMonitorCollection ( ) const [inline]

Definition at line 111 of file StatisticsReporter.h.

References stateMachineMonCollection_.

StreamsMonitorCollection& stor::StatisticsReporter::getStreamsMonitorCollection ( ) [inline]

Definition at line 86 of file StatisticsReporter.h.

References streamsMonCollection_.

    { return streamsMonCollection_; }
const StreamsMonitorCollection& stor::StatisticsReporter::getStreamsMonitorCollection ( ) const [inline]

Definition at line 83 of file StatisticsReporter.h.

References streamsMonCollection_.

    { return streamsMonCollection_; }
ThroughputMonitorCollection& stor::StatisticsReporter::getThroughputMonitorCollection ( ) [inline]

Definition at line 135 of file StatisticsReporter.h.

References throughputMonCollection_.

const ThroughputMonitorCollection& stor::StatisticsReporter::getThroughputMonitorCollection ( ) const [inline]

Definition at line 132 of file StatisticsReporter.h.

References throughputMonCollection_.

bool stor::StatisticsReporter::monitorAction ( toolbox::task::WorkLoop *  wl) [private]

Definition at line 198 of file StatisticsReporter.cc.

References app_, calculateStatistics(), doMonitoring_, alignCSCRings::e, exception, Exception, stor::utils::getCurrentTime(), lastMonitorAction_, monitoringSleepSec_, stor::utils::sleepUntil(), AlCaHLTBitMon_QueryRunRegistry::string, and updateInfoSpace().

Referenced by startWorkLoop().

  {
    utils::sleepUntil(lastMonitorAction_ + monitoringSleepSec_);
    lastMonitorAction_ = utils::getCurrentTime();
    
    std::string errorMsg = "Failed to update the monitoring information";
    
    try
    {
      calculateStatistics();
      updateInfoSpace();
    }
    catch(xcept::Exception &e)
    {
      LOG4CPLUS_ERROR(app_->getApplicationLogger(),
        errorMsg << xcept::stdformat_exception_history(e));
      
      XCEPT_DECLARE_NESTED(stor::exception::Monitoring,
        sentinelException, errorMsg, e);
      app_->notifyQualified("error", sentinelException);
    }
    catch(std::exception &e)
    {
      errorMsg += ": ";
      errorMsg += e.what();
      
      LOG4CPLUS_ERROR(app_->getApplicationLogger(),
        errorMsg);
      
      XCEPT_DECLARE(stor::exception::Monitoring,
        sentinelException, errorMsg);
      app_->notifyQualified("error", sentinelException);
    }
    catch(...)
    {
      errorMsg += ": Unknown exception";
      
      LOG4CPLUS_ERROR(app_->getApplicationLogger(),
        errorMsg);
      
      XCEPT_DECLARE(stor::exception::Monitoring,
        sentinelException, errorMsg);
      app_->notifyQualified("error", sentinelException);
    }
    
    return doMonitoring_;
  }
StatisticsReporter& stor::StatisticsReporter::operator= ( StatisticsReporter const &  ) [private]
void stor::StatisticsReporter::putItemsIntoInfoSpace ( MonitorCollection::InfoSpaceItems items) [private]

Definition at line 152 of file StatisticsReporter.cc.

References alignCSCRings::e, Exception, infoSpace_, and infoSpaceItemNames_.

Referenced by collectInfoSpaceItems().

  {
    
    for ( MonitorCollection::InfoSpaceItems::const_iterator it = items.begin(),
            itEnd = items.end();
          it != itEnd;
          ++it )
    {
      try
      {
        // fireItemAvailable locks the infospace internally
        infoSpace_->fireItemAvailable(it->first, it->second);
      }
      catch(xdata::exception::Exception &e)
      {
        std::stringstream oss;
        
        oss << "Failed to put " << it->first;
        oss << " into info space " << infoSpace_->name();
        
        XCEPT_RETHROW(stor::exception::Monitoring, oss.str(), e);
      }
      
      // keep a list of info space names for the fireItemGroupChanged
      infoSpaceItemNames_.push_back(it->first);
    }
  }
void stor::StatisticsReporter::reset ( void  )
void stor::StatisticsReporter::startWorkLoop ( std::string  workloopName)

Create and start the monitoring workloop

Definition at line 54 of file StatisticsReporter.cc.

References app_, doMonitoring_, alignCSCRings::e, Exception, stor::utils::getCurrentTime(), stor::utils::getIdentifier(), lastMonitorAction_, monitorAction(), monitorWL_, lumiQueryAPI::msg, and AlCaHLTBitMon_QueryRunRegistry::string.

  {
    if ( !doMonitoring_ ) return;
    
    try
    {
      std::string identifier = utils::getIdentifier(app_->getApplicationDescriptor());
      
      monitorWL_=
        toolbox::task::getWorkLoopFactory()->getWorkLoop(
          identifier + workloopName, "waiting");
      
      if ( ! monitorWL_->isActive() )
      {
        toolbox::task::ActionSignature* monitorAction = 
          toolbox::task::bind(this, &StatisticsReporter::monitorAction, 
            identifier + "MonitorAction");
        monitorWL_->submit(monitorAction);
        
        lastMonitorAction_ = utils::getCurrentTime();
        monitorWL_->activate();
      }
    }
    catch (xcept::Exception& e)
    {
      const std::string msg =
        "Failed to start workloop 'StatisticsReporter' with 'MonitorAction'.";
      XCEPT_RETHROW(stor::exception::Monitoring, msg, e);
    }
  }
void stor::StatisticsReporter::updateInfoSpace ( ) [private]

Definition at line 265 of file StatisticsReporter.cc.

References dataSenderMonCollection_, dqmConsumerMonCollection_, dqmEventMonCollection_, alignCSCRings::e, eventConsumerMonCollection_, exception, Exception, filesMonCollection_, fragMonCollection_, infoSpace_, infoSpaceItemNames_, resourceMonCollection_, runMonCollection_, stateMachineMonCollection_, streamsMonCollection_, AlCaHLTBitMon_QueryRunRegistry::string, throughputMonCollection_, and stor::MonitorCollection::updateInfoSpaceItems().

Referenced by monitorAction().

  {
    std::string errorMsg =
      "Failed to update values of items in info space " + infoSpace_->name();
    
    // Lock the infospace to assure that all items are consistent
    try
    {
      infoSpace_->lock();
      
      runMonCollection_.updateInfoSpaceItems();
      fragMonCollection_.updateInfoSpaceItems();
      filesMonCollection_.updateInfoSpaceItems();
      streamsMonCollection_.updateInfoSpaceItems();
      dataSenderMonCollection_.updateInfoSpaceItems();
      dqmEventMonCollection_.updateInfoSpaceItems();
      resourceMonCollection_.updateInfoSpaceItems();
      stateMachineMonCollection_.updateInfoSpaceItems();
      eventConsumerMonCollection_.updateInfoSpaceItems();
      dqmConsumerMonCollection_.updateInfoSpaceItems();
      throughputMonCollection_.updateInfoSpaceItems();
      
      infoSpace_->unlock();
    }
    catch(std::exception &e)
    {
      infoSpace_->unlock();
      
      errorMsg += ": ";
      errorMsg += e.what();
      XCEPT_RAISE(stor::exception::Monitoring, errorMsg);
    }
    catch (...)
    {
      infoSpace_->unlock();
      
      errorMsg += " : unknown exception";
      XCEPT_RAISE(stor::exception::Monitoring, errorMsg);
    }
    
    try
    {
      // The fireItemGroupChanged locks the infospace
      infoSpace_->fireItemGroupChanged(infoSpaceItemNames_, this);
    }
    catch (xdata::exception::Exception &e)
    {
      XCEPT_RETHROW(stor::exception::Monitoring, errorMsg, e);
    }
  }

Member Data Documentation

xdaq::Application* stor::StatisticsReporter::app_ [private]
xdata::UnsignedInteger32 stor::StatisticsReporter::closedFiles_ [private]

Definition at line 187 of file StatisticsReporter.h.

Referenced by monitorAction(), startWorkLoop(), and ~StatisticsReporter().

xdata::InfoSpace* stor::StatisticsReporter::infoSpace_ [private]

Definition at line 173 of file StatisticsReporter.h.

Referenced by monitorAction(), and startWorkLoop().

Definition at line 172 of file StatisticsReporter.h.

Referenced by monitorAction().

toolbox::task::WorkLoop* stor::StatisticsReporter::monitorWL_ [private]

Definition at line 186 of file StatisticsReporter.h.

Referenced by startWorkLoop(), and ~StatisticsReporter().

xdata::String stor::StatisticsReporter::stateName_ [private]
xdata::UnsignedInteger32 stor::StatisticsReporter::storedEvents_ [private]