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 // local headers
14 #include "processor_model.h"
15 
16 // describe the module's configuration
19  desc.addUntracked<double>( "timeRange", 60000.0 );
20  desc.addUntracked<double>( "timeResolution", 10.0 );
21  desc.addUntracked<std::string>( "dqmPath", "HLT/Throughput" );
22  desc.addUntracked<bool>( "dqmPathByProcesses", false );
23  descriptions.add("ThroughputService", desc);
24 }
25 
27  // startup time
28  m_startup(std::chrono::steady_clock::now()),
29  // configuration
30  m_time_range( config.getUntrackedParameter<double>("timeRange") ),
31  m_time_resolution( config.getUntrackedParameter<double>("timeResolution") ),
32  m_dqm_path( config.getUntrackedParameter<std::string>("dqmPath") ),
33  m_dqm_bynproc( config.getUntrackedParameter<bool>("dqmPathByProcesses") )
34 {
37  registry.watchPostEvent( this, & ThroughputService::postEvent );
38 }
39 
41 
42 void
44 {
45  auto concurrent_streams = bounds.maxNumberOfStreams();
46  auto concurrent_threads = bounds.maxNumberOfThreads();
47 
48  if (m_dqm_bynproc)
49  m_dqm_path += (boost::format("/Running on %s with %d streams on %d threads") % processor_model % concurrent_streams % concurrent_threads).str();
50 }
51 
52 void
54 {
55  // if the DQMStore is available, book the DQM histograms
56  if (edm::Service<DQMStore>().isAvailable()) {
57  std::string y_axis_title = (boost::format("events / %g s") % m_time_resolution).str();
58  unsigned int bins = std::round( m_time_range / m_time_resolution );
59  double range = bins * m_time_resolution;
60 
61  // define a callback that can book the histograms
62  auto bookTransactionCallback = [&, this] (DQMStore::ConcurrentBooker & booker) {
63  booker.setCurrentFolder(m_dqm_path);
64  m_sourced_events = booker.book1D("throughput_sourced", "Throughput (sourced events)", bins, 0., range);
65  m_sourced_events.setXTitle("time [s]");
66  m_sourced_events.setYTitle(y_axis_title.c_str());
67  m_retired_events = booker.book1D("throughput_retired", "Throughput (retired events)", bins, 0., range);
68  m_retired_events.setXTitle("time [s]");
69  m_retired_events.setYTitle(y_axis_title.c_str());
70  };
71 
72  // book MonitorElement's for this run
73  edm::Service<DQMStore>()->bookConcurrentTransaction(bookTransactionCallback, gc.luminosityBlockID().run());
74  } else {
75  std::cerr << "No DQMStore service, aborting." << std::endl;
76  abort();
77  }
78 }
79 
80 void
82 {
84  m_sourced_events.fill( std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count() );
85 }
86 
87 void
89 {
91  m_retired_events.fill( std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count() );
92 }
93 
94 
95 // declare ThroughputService as a framework Service
void preallocate(edm::service::SystemBounds const &bounds)
unsigned int maxNumberOfThreads() const
Definition: SystemBounds.h:46
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 &gc)
unsigned int maxNumberOfStreams() const
Definition: SystemBounds.h:43
ConcurrentMonitorElement m_sourced_events
std::chrono::steady_clock::time_point m_startup
std::string m_dqm_path
RunNumber_t run() const
format
Some error handling for the usage.
void watchPreGlobalBeginRun(PreGlobalBeginRun::slot_type const &iSlot)
const std::string processor_model
#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)
const bool m_dqm_bynproc
static Interceptor::Registry registry("Interceptor")
#define str(s)
void setXTitle(std::string const &title)