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 
4 // boost headers
5 #include <boost/format.hpp>
6 
7 // CMSSW headers
10 #include "ThroughputService.h"
11 
12 // describe the module's configuration
15  desc.addUntracked<double>( "timeRange", 60000.0 );
16  desc.addUntracked<double>( "timeResolution", 10.0 );
17  desc.addUntracked<std::string>( "dqmPath", "HLT/Throughput" );
18  descriptions.add("ThroughputService", desc);
19 }
20 
22  m_stream_histograms(),
23  // configuration
24  m_time_range( config.getUntrackedParameter<double>("timeRange") ),
25  m_time_resolution( config.getUntrackedParameter<double>("timeResolution") ),
26  m_dqm_path( config.getUntrackedParameter<std::string>("dqmPath" ) )
27 {
33  registry.watchPostEvent( this, & ThroughputService::postEvent );
34 }
35 
37 {
38 }
39 
40 void
42 {
44 
45  m_stream_histograms.resize( bounds.maxNumberOfStreams() );
46 
47  // assign a pseudo module id to the FastTimerService
49 }
50 
51 void
53 {
54  // if the DQMStore is available, book the DQM histograms
55  if (edm::Service<DQMStore>().isAvailable()) {
56  unsigned int sid = sc.streamID().value();
57  auto & stream = m_stream_histograms[sid];
58 
59  std::string y_axis_title = (boost::format("events / %g s") % m_time_resolution).str();
60  unsigned int bins = std::round( m_time_range / m_time_resolution );
61  double range = bins * m_time_resolution;
62 
63  // define a callback that can book the histograms
64  auto bookTransactionCallback = [&, this] (DQMStore::IBooker & booker) {
65  booker.setCurrentFolder(m_dqm_path);
66  stream.sourced_events = booker.book1D("throughput_sourced", "Throughput (sourced events)", bins, 0., range)->getTH1F();
67  stream.sourced_events ->SetXTitle("time [s]");
68  stream.sourced_events ->SetYTitle(y_axis_title.c_str());
69  stream.retired_events = booker.book1D("throughput_retired", "Throughput (retired events)", bins, 0., range)->getTH1F();
70  stream.retired_events ->SetXTitle("time [s]");
71  stream.retired_events ->SetYTitle(y_axis_title.c_str());
72  };
73 
74  // book MonitorElement's for this stream
75  edm::Service<DQMStore>()->bookTransaction(bookTransactionCallback, sc.eventID().run(), sid, m_module_id);
76  }
77 }
78 
79 void
81 {
82  if (edm::Service<DQMStore>().isAvailable())
83  edm::Service<DQMStore>()->mergeAndResetMEsLuminositySummaryCache(sc.eventID().run(), sc.eventID().luminosityBlock(), sc.streamID().value(), m_module_id);
84 }
85 
86 void
88 {
89  if (edm::Service<DQMStore>().isAvailable())
90  edm::Service<DQMStore>()->mergeAndResetMEsRunSummaryCache(sc.eventID().run(), sc.streamID().value(), m_module_id);
91 }
92 
93 void
95 {
97  m_stream_histograms[sid].sourced_events->Fill( std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count() );
98 }
99 
100 void
102 {
103  unsigned int sid = sc.streamID().value();
105  m_stream_histograms[sid].retired_events->Fill( std::chrono::duration_cast<std::chrono::duration<double>>(timestamp - m_startup).count() );
106 }
107 
108 
109 // 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)
clock_gettime_monotonic::time_point m_startup
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)
static time_point now()
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::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")