test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  m_stream_histograms(),
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 }
40 
41 void
43 {
45 
46  m_stream_histograms.resize( bounds.maxNumberOfStreams() );
47 
48  // assign a pseudo module id to the FastTimerService
50 }
51 
52 void
54 {
55  // if the DQMStore is available, book the DQM histograms
56  if (edm::Service<DQMStore>().isAvailable()) {
57  unsigned int sid = sc.streamID().value();
58  auto & stream = m_stream_histograms[sid];
59 
60  std::string y_axis_title = (boost::format("events / %g s") % m_time_resolution).str();
61  unsigned int bins = std::round( m_time_range / m_time_resolution );
62  double range = bins * m_time_resolution;
63 
64  // define a callback that can book the histograms
65  auto bookTransactionCallback = [&, this] (DQMStore::IBooker & booker) {
66  booker.setCurrentFolder(m_dqm_path);
67  stream.sourced_events = booker.book1D("throughput_sourced", "Throughput (sourced events)", bins, 0., range)->getTH1F();
68  stream.sourced_events ->SetXTitle("time [s]");
69  stream.sourced_events ->SetYTitle(y_axis_title.c_str());
70  stream.retired_events = booker.book1D("throughput_retired", "Throughput (retired events)", bins, 0., range)->getTH1F();
71  stream.retired_events ->SetXTitle("time [s]");
72  stream.retired_events ->SetYTitle(y_axis_title.c_str());
73  };
74 
75  // book MonitorElement's for this stream
76  edm::Service<DQMStore>()->bookTransaction(bookTransactionCallback, sc.eventID().run(), sid, m_module_id);
77  }
78 }
79 
80 void
82 {
83  if (edm::Service<DQMStore>().isAvailable())
84  edm::Service<DQMStore>()->mergeAndResetMEsLuminositySummaryCache(sc.eventID().run(), sc.eventID().luminosityBlock(), sc.streamID().value(), m_module_id);
85 }
86 
87 void
89 {
90  if (edm::Service<DQMStore>().isAvailable())
91  edm::Service<DQMStore>()->mergeAndResetMEsRunSummaryCache(sc.eventID().run(), sc.streamID().value(), m_module_id);
92 }
93 
94 void
96 {
98  m_stream_histograms[sid].sourced_events->Fill( std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count() );
99 }
100 
101 void
103 {
104  unsigned int sid = sc.streamID().value();
106  m_stream_histograms[sid].retired_events->Fill( std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count() );
107 }
108 
109 
110 // 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)
string format
Some error handling for the usage.
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)
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")