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 
24  // configuration
25  m_time_range( config.getUntrackedParameter<double>("timeRange") ),
26  m_time_resolution( config.getUntrackedParameter<double>("timeResolution") ),
27  m_dqm_path( config.getUntrackedParameter<std::string>("dqmPath" ) )
28 {
34  registry.watchPostEvent( this, & ThroughputService::postEvent );
35 }
36 
38 
39 void
41 {
43 
44  m_stream_histograms.resize( bounds.maxNumberOfStreams() );
45 
46  // assign a pseudo module id to the ThroughputService
48 }
49 
50 void
52 {
53  // if the DQMStore is available, book the DQM histograms
54  if (edm::Service<DQMStore>().isAvailable()) {
55  unsigned int sid = sc.streamID().value();
56  auto & stream = m_stream_histograms[sid];
57 
58  std::string y_axis_title = (boost::format("events / %g s") % m_time_resolution).str();
59  unsigned int bins = std::round( m_time_range / m_time_resolution );
60  double range = bins * m_time_resolution;
61 
62  // define a callback that can book the histograms
63  auto bookTransactionCallback = [&, this] (DQMStore::IBooker & booker) {
64  booker.setCurrentFolder(m_dqm_path);
65  stream.sourced_events = booker.book1D("throughput_sourced", "Throughput (sourced events)", bins, 0., range)->getTH1F();
66  stream.sourced_events ->SetXTitle("time [s]");
67  stream.sourced_events ->SetYTitle(y_axis_title.c_str());
68  stream.retired_events = booker.book1D("throughput_retired", "Throughput (retired events)", bins, 0., range)->getTH1F();
69  stream.retired_events ->SetXTitle("time [s]");
70  stream.retired_events ->SetYTitle(y_axis_title.c_str());
71  };
72 
73  // book MonitorElement's for this stream
74  edm::Service<DQMStore>()->bookTransaction(bookTransactionCallback, sc.eventID().run(), sid, m_module_id);
75  }
76 }
77 
78 void
80 {
81  if (edm::Service<DQMStore>().isAvailable())
82  edm::Service<DQMStore>()->mergeAndResetMEsLuminositySummaryCache(sc.eventID().run(), sc.eventID().luminosityBlock(), sc.streamID().value(), m_module_id);
83 }
84 
85 void
87 {
88  if (edm::Service<DQMStore>().isAvailable())
89  edm::Service<DQMStore>()->mergeAndResetMEsRunSummaryCache(sc.eventID().run(), sc.streamID().value(), m_module_id);
90 }
91 
92 void
94 {
96  m_stream_histograms[sid].sourced_events->Fill( std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count() );
97 }
98 
99 void
101 {
102  unsigned int sid = sc.streamID().value();
104  m_stream_histograms[sid].retired_events->Fill( std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count() );
105 }
106 
107 
108 // declare ThroughputService as a framework Service
RunNumber_t run() const
Definition: EventID.h:39
void preallocate(edm::service::SystemBounds const &bounds)
void watchPreallocate(Preallocate::slot_type const &iSlot)
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
void preSourceEvent(edm::StreamID sid)
void watchPostEvent(PostEvent::slot_type const &iSlot)
void watchPostStreamEndLumi(PostStreamEndLumi::slot_type const &iSlot)
void postStreamEndLumi(edm::StreamContext const &sc)
void postEvent(edm::StreamContext const &sc)
Definition: config.py:1
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
static unsigned int getUniqueID()
Returns a unique id each time called. Intended to be passed to ModuleDescription&#39;s constructor&#39;s modI...
unsigned int maxNumberOfStreams() const
Definition: SystemBounds.h:43
std::chrono::steady_clock::time_point m_startup
std::string m_dqm_path
void preStreamBeginRun(edm::StreamContext const &sc)
format
Some error handling for the usage.
void watchPostStreamEndRun(PostStreamEndRun::slot_type const &iSlot)
StreamID const & streamID() const
Definition: StreamContext.h:57
std::vector< stream_histograms > m_stream_histograms
#define DEFINE_FWK_SERVICE(type)
Definition: ServiceMaker.h:113
unsigned int value() const
Definition: StreamID.h:46
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ThroughputService(const edm::ParameterSet &, edm::ActivityRegistry &)
void watchPreStreamBeginRun(PreStreamBeginRun::slot_type const &iSlot)
void postStreamEndRun(edm::StreamContext const &sc)
EventID const & eventID() const
Definition: StreamContext.h:59
unsigned int m_module_id
void watchPreSourceEvent(PreSourceEvent::slot_type const &iSlot)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
static Interceptor::Registry registry("Interceptor")