| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

SequencerTimerTool.cpp
Go to the documentation of this file.
1 // Include files
2
3 // From ROOT
4 #include "TH1D.h"
5
6 // from Gaudi
7 #include "GaudiKernel/RndmGenerators.h"
8 #include "GaudiKernel/IRndmGenSvc.h"
9 #include "GaudiUtils/Aida2ROOT.h"
10
11 // local
12 #include "SequencerTimerTool.h"
13
14 //-----------------------------------------------------------------------------
15 // Implementation file for class : SequencerTimerTool
16 //
17 // 2004-05-19 : Olivier Callot
18 //-----------------------------------------------------------------------------
19
20 // Declaration of the Tool Factory
21 DECLARE_COMPONENT(SequencerTimerTool)
22
23 //=============================================================================
24 // Standard constructor, initializes variables
25 //=============================================================================
26 SequencerTimerTool::SequencerTimerTool( const std::string& type,
27 const std::string& name,
28 const IInterface* parent )
29 : GaudiHistoTool ( type, name , parent )
30 {
31 declareInterface<ISequencerTimerTool>(this);
32
33 // Histograms are disabled by default in this tool.
34 setProperty("HistoProduce", false).ignore();
35 }
36 //=========================================================================
37 //
38 //=========================================================================
39 StatusCode SequencerTimerTool::initialize ( )
40 {
41 const StatusCode sc = GaudiHistoTool::initialize();
42 if ( sc.isFailure() ) return sc;
43 double sum = 0;
44 TimerForSequencer norm( "normalize", m_headerSize, m_normFactor );
45 norm.start();
46 IRndmGenSvc* rsvc = svc<IRndmGenSvc>( "RndmGenSvc", true );
47 { // Use dummy loop suggested by Vanya Belyaev:
48 Rndm::Numbers gauss;
49 gauss.initialize( rsvc , Rndm::Gauss(0.,1.0) ).ignore();
50 unsigned int shots = m_shots;
51 while( 0 < --shots ) { sum += gauss() * sum ; }
52 }
53 norm.stop();
54 double time = norm.lastCpu();
55 m_speedRatio = 1./time;
56 info() << "This machine has a speed about "
57 << format( "%6.2f", 1000.*m_speedRatio)
58 << " times the speed of a 2.8 GHz Xeon." << endmsg ;
59 if ( m_normalised ) m_normFactor = m_speedRatio;
60 return sc;
61 }
62
63 //=========================================================================
64 // Finalize : Report timers
65 //=========================================================================
66 StatusCode SequencerTimerTool::finalize ( )
67 {
68
69 std::string line(m_headerSize + 68, '-');
70 info() << line << endmsg
71 << "This machine has a speed about "
72 << format( "%6.2f", 1000.*m_speedRatio)
73 << " times the speed of a 2.8 GHz Xeon.";
74 if ( m_normalised ) info() <<" *** All times are renormalized ***";
75 info() << endmsg << TimerForSequencer::header( m_headerSize ) << endmsg
76 << line << endmsg;
77
78 std::string lastName;
79 for ( const auto& timr : m_timerList)
80 {
81 if ( lastName == timr.name() ) continue; // suppress duplicate
82 lastName = timr.name();
83 info() << timr << endmsg;
84 }
85 info() << line << endmsg;
86
87 return GaudiHistoTool::finalize();
88 }
89
90 //=========================================================================
91 // Return the index of a specified name. Trailing and leading spaces ignored
92 //=========================================================================
93 int SequencerTimerTool::indexByName ( const std::string& name )
94 {
95 auto beg = name.find_first_not_of(" \t");
96 auto end = name.find_last_not_of(" \t");
97 auto temp = name.substr( beg, end-beg+1 );
98 auto i = std::find_if( std::begin(m_timerList), std::end(m_timerList),
99 [&](const TimerForSequencer& timer) {
100 beg = timer.name().find_first_not_of(" \t");
101 end = timer.name().find_last_not_of(" \t");
102 return timer.name().compare(beg,end-beg+1,temp) == 0;
103 });
104 return i!=std::end(m_timerList) ? std::distance(std::begin(m_timerList),i) : -1;
105 }
106
107 //=========================================================================
108 // Build and save the histograms
109 //=========================================================================
110 void SequencerTimerTool::saveHistograms()
111 {
112 if ( produceHistos() )
113 {
114 info() << "Saving Timing histograms" << endmsg;
115 const size_t bins = m_timerList.size();
116 AIDA::IHistogram1D* histoTime = book("ElapsedTime", 0, bins, bins);
117 AIDA::IHistogram1D* histoCPU = book("CPUTime", 0, bins, bins);
118 AIDA::IHistogram1D* histoCount = book("Count", 0, bins, bins);
119 TH1D* tHtime = Gaudi::Utils::Aida2ROOT::aida2root(histoTime);
120 TH1D* tHCPU = Gaudi::Utils::Aida2ROOT::aida2root(histoCPU);
121 TH1D* tHCount = Gaudi::Utils::Aida2ROOT::aida2root(histoCount);
122 for (const auto& tfsq : m_timerList ) {
123 tHtime->Fill(tfsq.name().c_str(), tfsq.elapsedTotal());
124 tHCPU->Fill(tfsq.name().c_str(), tfsq.cpuTotal());
125 tHCount->Fill(tfsq.name().c_str(), tfsq.count());
126 }
127 }
128 }
129
130 //=============================================================================
131 // Add a timer
132 //=============================================================================
133 int SequencerTimerTool::addTimer( const std::string& name )
134 {
135 std::string myName( 2*m_indent, ' ' );
136 myName += name;
137 if ( myName.size() < m_headerSize ) {
138 myName += std::string( m_headerSize - myName.size(), ' ' );
139 }
140 m_timerList.emplace_back( std::move(myName), m_headerSize, m_normFactor );
141 return m_timerList.size() - 1;
142 }
143
144 //=============================================================================
SequencerTimerTool::initialize
StatusCode initialize() override
initialize method, to compute the normalization factor
Definition: SequencerTimerTool.cpp:39
Gaudi::Utils::setProperty
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
Definition: Property.h:1138
TimerForSequencer
Auxiliary class.
Definition: TimerForSequencer.h:20
TimerForSequencer::header
static std::string header(std::string::size_type size)
header matching the previous format
Definition: TimerForSequencer.cpp:63
std::distance
T distance(T...args)
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
std::string::find_first_not_of
T find_first_not_of(T...args)
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:123
SequencerTimerTool::m_normalised
Gaudi::Property< bool > m_normalised
Definition: SequencerTimerTool.h:77
GaudiHistos< GaudiTool >::finalize
StatusCode finalize() override
standard finalization method
sum
double sum(double x, double y, double z)
Definition: 3DoubleFuncTest.cpp:25
TimerForSequencer::stop
uint64_t stop()
Stop time measurement and return the last elapsed time.
Definition: TimerForSequencer.cpp:10
plotSpeedupsPyRoot.time
time
Definition: plotSpeedupsPyRoot.py:146
std
STL namespace.
std::end
T end(T...args)
TimerForSequencer::lastCpu
double lastCpu() const
returns the last measured time
Definition: TimerForSequencer.h:54
Rndm::Gauss
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:21
TimerForSequencer::start
void start()
Start a time measurement.
Definition: TimerForSequencer.h:36
SequencerTimerTool::indexByName
int indexByName(const std::string &name) override
returns the index of the counter with that name, or -1
Definition: SequencerTimerTool.cpp:93
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:84
GaudiHistoTool
Simple class to extend the functionality of class GaudiTool.
Definition: GaudiHistoTool.h:39
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
std::string
STL class.
SequencerTimerTool::m_shots
Gaudi::Property< int > m_shots
Definition: SequencerTimerTool.h:76
SequencerTimerTool::saveHistograms
void saveHistograms() override
prepares and saves the timing histograms
Definition: SequencerTimerTool.cpp:110
Aida2ROOT.h
Rndm::Numbers
Random number accessor This small class encapsulates the use of the random number generator...
Definition: RndmGenerators.h:370
IRndmGenSvc
Random Generator service interface definition Definition of a interface for a service to access rando...
Definition: IRndmGenSvc.h:35
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IInterface
Definition of the basic interface.
Definition: IInterface.h:234
gaudirun.type
type
Definition: gaudirun.py:125
SequencerTimerTool.h
end
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:50
Gaudi::Utils::Aida2ROOT::aida2root
static TH1D * aida2root(AIDA::IHistogram1D *aida)
get the underlying pointer for 1D-histogram
Definition: Aida2ROOT.cpp:72
GaudiHistos< GaudiTool >::book
AIDA::IHistogram1D * book(const std::string &title, const double low=0, const double high=100, const unsigned long bins=100) const
book the 1D histogram
Definition: GaudiHistos.h:1865
SequencerTimerTool::addTimer
int addTimer(const std::string &name) override
add a timer entry with the specified name
Definition: SequencerTimerTool.cpp:133
std::move
T move(T...args)
RndmGenerators.h
std::string::find_last_not_of
T find_last_not_of(T...args)
SequencerTimerTool::m_indent
int m_indent
Amount of indentation.
Definition: SequencerTimerTool.h:82
std::find_if
T find_if(T...args)
std::vector::size
T size(T...args)
IRndmGenSvc.h
std::begin
T begin(T...args)
Gaudi::Units::gauss
constexpr double gauss
Definition: SystemOfUnits.h:232
GaudiHistos< GaudiTool >::initialize
StatusCode initialize() override
standard initialization method
GaudiHistos< GaudiTool >::produceHistos
bool produceHistos() const
get the flag for histogram production (property "HistoProduce")
Definition: GaudiHistos.h:2396
SequencerTimerTool
Implements the time measurement inside a sequencer.
Definition: SequencerTimerTool.h:25
TimerForSequencer::name
const std::string & name() const
returns the name
Definition: TimerForSequencer.h:48
SequencerTimerTool::m_timerList
std::vector< TimerForSequencer > m_timerList
Definition: SequencerTimerTool.h:83
std::string::substr
T substr(T...args)
Rndm::Numbers::initialize
virtual StatusCode initialize(const SmartIF< IRndmGenSvc > &svc, const IRndmGen::Param &par)
Initialization.
Definition: RndmGenerators.cpp:27
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:106
SequencerTimerTool::m_headerSize
Gaudi::Property< std::string::size_type > m_headerSize
Definition: SequencerTimerTool.h:79
SequencerTimerTool::m_speedRatio
double m_speedRatio
Definition: SequencerTimerTool.h:85
SequencerTimerTool::finalize
StatusCode finalize() override
finalize method, to print the time summary table
Definition: SequencerTimerTool.cpp:66
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
plotSpeedupsPyRoot.line
line
Definition: plotSpeedupsPyRoot.py:164
std::string::compare
T compare(T...args)
SequencerTimerTool::m_normFactor
double m_normFactor
Factor to convert to standard CPU (1 GHz PIII)
Definition: SequencerTimerTool.h:84
std::vector::emplace_back
T emplace_back(T...args)