CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Timer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Timer
4 // Class: Timer
5 //
14 //
15 // Original Author: Christos Leonidopoulos
16 // Created: Mon Jul 10 14:13:58 CEST 2006
17 //
18 //
19 
20 
23 
24 #include "boost/bind.hpp"
25 #include "boost/mem_fn.hpp"
26 
27 #include <iostream>
28 
29 using edm::ParameterSet;
30 using edm::Service;
32 //
33 using edm::ModuleTime;
34 using edm::EventTime;
35 
36 using std::string;
37 
38 Timer::Timer(const ParameterSet& iConfig)
39 {
40  // produces<EventTime>("Timing");
41  produces<EventTime>();
42 
43  // whether to include timing info about Timer module (default: false)
44  includeSelf = iConfig.getUntrackedParameter<bool>("includeSelf", false);
45 
46  timing.reset();
47 
48  // attach method to Timing service's "new measurement" signal
50  time->newMeasurementSignal.connect(boost::bind(boost::mem_fn(&Timer::newTimingMeasurement), this, _1, _2) );
51 
52  self_module_name = string(iConfig.getParameter<string>("@module_type"));
53 }
54 
56 {
57  using namespace std;
58 
59  if(!includeSelf){
60  string longLine("==========================================================");
61  cout << longLine << endl;
62  cout << " Timer Info:\n";
63  cout << " Timer module was excluded from time measurements\n";
64  cout << " (to include, set 'bool includeSelf = true' in .cfg file)\n";
65  cout << longLine << endl << endl;
66  }
67 
68 }
69 
71  // # Make sure to enable the "TimerService" service at your top-level cfg!
72  // # by including something like the following:
73  // # service = TimerService {
74  // # untracked bool useCPUtime = true // set to false for wall-clock-time
75  // # }
76  // # This EDProducer is the module that stores in the Event the timing info
78  desc.addUntracked<bool>("includeSelf",false);
79  descriptions.add("timer", desc);
80 }
81 
82 // fwk calls this method when new module measurement arrives
83 void Timer::newTimingMeasurement(const ModuleDescription& iMod, double iTime)
84 {
85  // check if module name corresponds to "this" and skip if needed
86  if(!includeSelf && iMod.moduleName() == self_module_name)
87  return;
88 
89  // new measurement; add to private member
90  ModuleTime newModuleTime(iMod.moduleLabel(), iTime);
91  timing.addModuleTime(newModuleTime);
92 }
93 
94 
95 //
96 // member functions
97 //
98 
99 // ------------ method called to produce the data ------------
100 void
102 {
103  std::auto_ptr<EventTime> out(new EventTime(timing));
104  // reset data so that we can start from scratch for next event
105  timing.reset();
106  //
107  iEvent.put(out);
108 }
109 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Timer(const edm::ParameterSet &)
Definition: Timer.cc:38
~Timer()
Definition: Timer.cc:55
std::string const & moduleName() const
std::string const & moduleLabel() const
void addModuleTime(const ModuleTime &m)
Definition: ModuleTiming.h:58
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: Timer.cc:70
std::string self_module_name
Definition: Timer.h:64
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
void newTimingMeasurement(const edm::ModuleDescription &iMod, double iTime)
Definition: Timer.cc:83
edm::EventTime timing
Definition: Timer.h:59
void add(std::string const &label, ParameterSetDescription const &psetDescription)
virtual void produce(edm::Event &, const edm::EventSetup &)
Definition: Timer.cc:101
sigc::signal< void, const edm::ModuleDescription &, double > newMeasurementSignal
Definition: TimerService.h:91
tuple cout
Definition: gather_cfg.py:145
bool includeSelf
Definition: Timer.h:61