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
10 #include "ThroughputService.h"
11 
12 // local headers
13 #include "processor_model.h"
14 
15 // describe the module's configuration
18  desc.addUntracked<double>("timeRange", 60000.0);
19  desc.addUntracked<double>("timeResolution", 10.0);
20  desc.addUntracked<std::string>("dqmPath", "HLT/Throughput");
21  desc.addUntracked<bool>("dqmPathByProcesses", false);
22  descriptions.add("ThroughputService", desc);
23 }
24 
26  : // startup time
27  m_startup(std::chrono::steady_clock::now()),
28  // configuration
29  m_time_range(config.getUntrackedParameter<double>("timeRange")),
30  m_time_resolution(config.getUntrackedParameter<double>("timeResolution")),
31  m_dqm_path(config.getUntrackedParameter<std::string>("dqmPath")),
32  m_dqm_bynproc(config.getUntrackedParameter<bool>("dqmPathByProcesses")) {
36 }
37 
39 
41  auto concurrent_streams = bounds.maxNumberOfStreams();
42  auto concurrent_threads = bounds.maxNumberOfThreads();
43 
44  if (m_dqm_bynproc)
45  m_dqm_path += (boost::format("/Running on %s with %d streams on %d threads") % processor_model %
46  concurrent_streams % concurrent_threads)
47  .str();
48 }
49 
51  // if the DQMStore is available, book the DQM histograms
52  if (edm::Service<DQMStore>().isAvailable()) {
53  std::string y_axis_title = (boost::format("events / %g s") % m_time_resolution).str();
54  unsigned int bins = std::round(m_time_range / m_time_resolution);
55  double range = bins * m_time_resolution;
56 
57  // define a callback that can book the histograms
58  auto bookTransactionCallback = [&, this](DQMStore::IBooker& booker) {
59  booker.setCurrentFolder(m_dqm_path);
60  m_sourced_events = booker.book1D("throughput_sourced", "Throughput (sourced events)", bins, 0., range);
61  m_sourced_events->setXTitle("time [s]");
62  m_sourced_events->setYTitle(y_axis_title);
63  m_retired_events = booker.book1D("throughput_retired", "Throughput (retired events)", bins, 0., range);
64  m_retired_events->setXTitle("time [s]");
65  m_retired_events->setYTitle(y_axis_title);
66  };
67 
68  // book MonitorElement's for this run
69  edm::Service<DQMStore>()->bookConcurrentTransaction(bookTransactionCallback, gc.luminosityBlockID().run());
70  } else {
71  std::cerr << "No DQMStore service, aborting." << std::endl;
72  abort();
73  }
74 }
75 
78  m_sourced_events->Fill(std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count());
79 }
80 
83  m_retired_events->Fill(std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count());
84 }
85 
86 // declare ThroughputService as a framework Service
void preallocate(edm::service::SystemBounds const &bounds)
unsigned int maxNumberOfThreads() const
Definition: SystemBounds.h:38
dqm::reco::MonitorElement * m_sourced_events
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:55
dqm::reco::MonitorElement * m_retired_events
void postEvent(edm::StreamContext const &sc)
Definition: config.py:1
void preGlobalBeginRun(edm::GlobalContext const &gc)
void Fill(long long x)
unsigned int maxNumberOfStreams() const
Definition: SystemBounds.h:35
std::chrono::steady_clock::time_point m_startup
virtual void setXTitle(std::string const &title)
std::string m_dqm_path
RunNumber_t run() const
#define DEFINE_FWK_SERVICE(type)
Definition: ServiceMaker.h:105
void watchPreGlobalBeginRun(PreGlobalBeginRun::slot_type const &iSlot)
const std::string processor_model
virtual void setYTitle(std::string const &title)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ThroughputService(const edm::ParameterSet &, edm::ActivityRegistry &)
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
#define str(s)