Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SequencerTimerTool.cpp
Go to the documentation of this file.
1 // $Id: SequencerTimerTool.cpp,v 1.12 2007/01/10 16:33:32 hmd Exp $
2 // Include files
3 
4 // From ROOT
5 #include "TH1D.h"
6 
7 // from Gaudi
11 #include "GaudiUtils/Aida2ROOT.h"
12 
13 // local
14 #include "SequencerTimerTool.h"
15 
16 //-----------------------------------------------------------------------------
17 // Implementation file for class : SequencerTimerTool
18 //
19 // 2004-05-19 : Olivier Callot
20 //-----------------------------------------------------------------------------
21 
22 // Declaration of the Tool Factory
24 
25 //=============================================================================
26 // Standard constructor, initializes variables
27 //=============================================================================
29  const std::string& name,
30  const IInterface* parent )
31  : GaudiHistoTool ( type, name , parent )
32  , m_indent( 0 )
33  , m_normFactor( 0.001 )
34  , m_speedRatio(0)
35 {
37 
38  m_shots = 3500000 ; // 1s on 2.8GHz Xeon, gcc 3.2, -o2
39  declareProperty( "shots" , m_shots );
40  declareProperty( "Normalised" , m_normalised = false );
41  declareProperty( "GlobalTiming" , m_globalTiming = false );
42  declareProperty( "NameSize" , m_headerSize = 30, "Number of characters to be used in algorithm name column" );
43  // Histograms are disabled by default in this tool.
44  setProperty("HistoProduce", false).ignore();
45 }
46 //=============================================================================
47 // Destructor
48 //=============================================================================
50 
51 
52 //=========================================================================
53 //
54 //=========================================================================
57  double sum = 0;
58  TimerForSequencer norm( "normalize", m_normFactor );
59  norm.start();
60  IRndmGenSvc* rsvc = svc<IRndmGenSvc>( "RndmGenSvc", true );
61  { // Use dummy loop suggested by Vanya Belyaev:
63  gauss.initialize( rsvc , Rndm::Gauss(0.,1.0) ).ignore();
64  unsigned int shots = m_shots;
65  while( 0 < --shots ) { sum += gauss() * sum ; }
66  }
67  norm.stop();
68  double time = norm.lastCpu();
69  m_speedRatio = 1./time;
70  info() << "This machine has a speed about "
71  << format( "%6.2f", 1000.*m_speedRatio)
72  << " times the speed of a 2.8 GHz Xeon." << endmsg ;
73  if ( m_normalised ) {
75  }
76  return StatusCode::SUCCESS;
77 }
78 //=========================================================================
79 // Finalize : Report timers
80 //=========================================================================
82 
83  std::string line(m_headerSize + 68, '-');
84  info() << line << endmsg
85  << "This machine has a speed about "
86  << format( "%6.2f", 1000.*m_speedRatio)
87  << " times the speed of a 2.8 GHz Xeon.";
88  if ( m_normalised ) info() <<" *** All times are renormalized ***";
90  << line << endmsg;
91 
92  std::string lastName = "";
93  for ( unsigned int kk=0 ; m_timerList.size() > kk ; kk++ ) {
94  if ( lastName == m_timerList[kk].name() ) continue; // suppress duplicate
95  lastName = m_timerList[kk].name();
96  info() << m_timerList[kk] << endmsg;
97  }
98  info() << line << endmsg;
99 
100  return GaudiHistoTool::finalize();
101 }
102 
103 //=========================================================================
104 // Return the index of a specified name. Trailing and leading spaces ignored
105 //=========================================================================
107  std::string::size_type beg = name.find_first_not_of(" \t");
108  std::string::size_type end = name.find_last_not_of(" \t");
109  std::string temp = name.substr( beg, end-beg+1 );
110  for ( unsigned int kk=0 ; m_timerList.size() > kk ; kk++ ) {
111  beg = m_timerList[kk].name().find_first_not_of(" \t");
112  end = m_timerList[kk].name().find_last_not_of(" \t");
113  if ( m_timerList[kk].name().substr(beg,end-beg+1) == temp ) return kk;
114  }
115  return -1;
116 }
117 //=========================================================================
118 // Build and save the histograms
119 //=========================================================================
121 {
122  if(produceHistos()){
123  info() << "Saving Timing histograms" << endmsg;
124  const size_t bins = m_timerList.size();
125  AIDA::IHistogram1D* histoTime = book("ElapsedTime", 0, bins, bins);
126  AIDA::IHistogram1D* histoCPU = book("CPUTime", 0, bins, bins);
127  AIDA::IHistogram1D* histoCount = book("Count", 0, bins, bins);
128  TH1D* tHtime = Gaudi::Utils::Aida2ROOT::aida2root(histoTime);
129  TH1D* tHCPU = Gaudi::Utils::Aida2ROOT::aida2root(histoCPU);
130  TH1D* tHCount = Gaudi::Utils::Aida2ROOT::aida2root(histoCount);
131  for ( size_t kk = 0 ; bins > kk ; kk++ ) {
132  TimerForSequencer &tfsq = m_timerList[kk];
133  tHtime->Fill(tfsq.name().c_str(), tfsq.elapsedTotal());
134  tHCPU->Fill(tfsq.name().c_str(), tfsq.cpuTotal());
135  tHCount->Fill(tfsq.name().c_str(), tfsq.count());
136  }
137  }
138 }
139 //=============================================================================
140 
141 
142 

Generated at Wed Nov 28 2012 12:17:10 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004