CMS 3D CMS Logo

ThroughputService.cc
Go to the documentation of this file.
1 // C++ headers
2 #include <algorithm>
3 #include <chrono>
4 
5 // boost headers
6 #include <boost/format.hpp>
7 
8 // CMSSW headers
11 #include "ThroughputService.h"
12 
13 // describe the module's configuration
16  desc.addUntracked<double>( "timeRange", 60000.0 );
17  desc.addUntracked<double>( "timeResolution", 10.0 );
18  desc.addUntracked<std::string>( "dqmPath", "HLT/Throughput" );
19  descriptions.add("ThroughputService", desc);
20 }
21 
23  // startup time
24  m_startup(std::chrono::steady_clock::now()),
25  // configuration
26  m_time_range( config.getUntrackedParameter<double>("timeRange") ),
27  m_time_resolution( config.getUntrackedParameter<double>("timeResolution") ),
28  m_dqm_path( config.getUntrackedParameter<std::string>("dqmPath" ) )
29 {
32  registry.watchPostEvent( this, & ThroughputService::postEvent );
33 }
34 
36 
37 void
39 {
40  // if the DQMStore is available, book the DQM histograms
41  if (edm::Service<DQMStore>().isAvailable()) {
42  std::string y_axis_title = (boost::format("events / %g s") % m_time_resolution).str();
43  unsigned int bins = std::round( m_time_range / m_time_resolution );
44  double range = bins * m_time_resolution;
45 
46  // define a callback that can book the histograms
47  auto bookTransactionCallback = [&, this] (DQMStore::ConcurrentBooker & booker) {
48  booker.setCurrentFolder(m_dqm_path);
49  m_sourced_events = booker.book1D("throughput_sourced", "Throughput (sourced events)", bins, 0., range);
50  m_sourced_events.setXTitle("time [s]");
51  m_sourced_events.setYTitle(y_axis_title.c_str());
52  m_retired_events = booker.book1D("throughput_retired", "Throughput (retired events)", bins, 0., range);
53  m_retired_events.setXTitle("time [s]");
54  m_retired_events.setYTitle(y_axis_title.c_str());
55  };
56 
57  // book MonitorElement's for this run
58  edm::Service<DQMStore>()->bookConcurrentTransaction(bookTransactionCallback, gc.luminosityBlockID().run());
59  } else {
60  std::cerr << "No DQMStore service, aborting." << std::endl;
61  abort();
62  }
63 }
64 
65 void
67 {
69  m_sourced_events.fill( std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count() );
70 }
71 
72 void
74 {
76  m_retired_events.fill( std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count() );
77 }
78 
79 
80 // declare ThroughputService as a framework Service
const std::string m_dqm_path
void setYTitle(std::string const &title)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void preSourceEvent(edm::StreamID sid)
void watchPostEvent(PostEvent::slot_type const &iSlot)
LuminosityBlockID const & luminosityBlockID() const
Definition: GlobalContext.h:57
void postEvent(edm::StreamContext const &sc)
Definition: config.py:1
void preGlobalBeginRun(edm::GlobalContext const &)
ConcurrentMonitorElement m_sourced_events
std::chrono::steady_clock::time_point m_startup
RunNumber_t run() const
format
Some error handling for the usage.
void watchPreGlobalBeginRun(PreGlobalBeginRun::slot_type const &iSlot)
#define DEFINE_FWK_SERVICE(type)
Definition: ServiceMaker.h:113
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ThroughputService(const edm::ParameterSet &, edm::ActivityRegistry &)
void fill(Args &&...args) const
ConcurrentMonitorElement m_retired_events
const double m_time_resolution
const double m_time_range
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static Interceptor::Registry registry("Interceptor")
void setXTitle(std::string const &title)