Go to the documentation of this file.00001
00002
00003
00004
00005 #include "TH1D.h"
00006
00007
00008 #include "GaudiKernel/ToolFactory.h"
00009 #include "GaudiKernel/RndmGenerators.h"
00010 #include "GaudiKernel/IRndmGenSvc.h"
00011 #include "GaudiUtils/Aida2ROOT.h"
00012
00013
00014 #include "SequencerTimerTool.h"
00015
00016
00017
00018
00019
00020
00021
00022
00023 DECLARE_TOOL_FACTORY(SequencerTimerTool)
00024
00025
00026
00027
00028 SequencerTimerTool::SequencerTimerTool( const std::string& type,
00029 const std::string& name,
00030 const IInterface* parent )
00031 : GaudiHistoTool ( type, name , parent )
00032 , m_indent( 0 )
00033 , m_normFactor( 0.001 )
00034 , m_speedRatio(0)
00035 {
00036 declareInterface<ISequencerTimerTool>(this);
00037
00038 m_shots = 3500000 ;
00039 declareProperty( "shots" , m_shots );
00040 declareProperty( "Normalised" , m_normalised = false );
00041 declareProperty( "GlobalTiming" , m_globalTiming = false );
00042 declareProperty( "NameSize" , m_headerSize = 30, "Number of characters to be used in algorithm name column" );
00043
00044 setProperty("HistoProduce", false).ignore();
00045 }
00046
00047
00048
00049 SequencerTimerTool::~SequencerTimerTool() {}
00050
00051
00052
00053
00054
00055 StatusCode SequencerTimerTool::initialize ( ) {
00056 GaudiHistoTool::initialize();
00057 double sum = 0;
00058 TimerForSequencer norm( "normalize", m_normFactor );
00059 norm.start();
00060 IRndmGenSvc* rsvc = svc<IRndmGenSvc>( "RndmGenSvc", true );
00061 {
00062 Rndm::Numbers gauss;
00063 gauss.initialize( rsvc , Rndm::Gauss(0.,1.0) ).ignore();
00064 unsigned int shots = m_shots;
00065 while( 0 < --shots ) { sum += gauss() * sum ; }
00066 }
00067 norm.stop();
00068 double time = norm.lastCpu();
00069 m_speedRatio = 1./time;
00070 info() << "This machine has a speed about "
00071 << format( "%6.2f", 1000.*m_speedRatio)
00072 << " times the speed of a 2.8 GHz Xeon." << endmsg ;
00073 if ( m_normalised ) {
00074 m_normFactor = m_speedRatio;
00075 }
00076 return StatusCode::SUCCESS;
00077 }
00078
00079
00080
00081 StatusCode SequencerTimerTool::finalize ( ) {
00082
00083 std::string line(m_headerSize + 68, '-');
00084 info() << line << endmsg
00085 << "This machine has a speed about "
00086 << format( "%6.2f", 1000.*m_speedRatio)
00087 << " times the speed of a 2.8 GHz Xeon.";
00088 if ( m_normalised ) info() <<" *** All times are renormalized ***";
00089 info() << endmsg << TimerForSequencer::header( m_headerSize ) << endmsg
00090 << line << endmsg;
00091
00092 std::string lastName = "";
00093 for ( unsigned int kk=0 ; m_timerList.size() > kk ; kk++ ) {
00094 if ( lastName == m_timerList[kk].name() ) continue;
00095 lastName = m_timerList[kk].name();
00096 info() << m_timerList[kk] << endmsg;
00097 }
00098 info() << line << endmsg;
00099
00100 return GaudiHistoTool::finalize();
00101 }
00102
00103
00104
00105
00106 int SequencerTimerTool::indexByName ( std::string name ) {
00107 std::string::size_type beg = name.find_first_not_of(" \t");
00108 std::string::size_type end = name.find_last_not_of(" \t");
00109 std::string temp = name.substr( beg, end-beg+1 );
00110 for ( unsigned int kk=0 ; m_timerList.size() > kk ; kk++ ) {
00111 beg = m_timerList[kk].name().find_first_not_of(" \t");
00112 end = m_timerList[kk].name().find_last_not_of(" \t");
00113 if ( m_timerList[kk].name().substr(beg,end-beg+1) == temp ) return kk;
00114 }
00115 return -1;
00116 }
00117
00118
00119
00120 void SequencerTimerTool::saveHistograms()
00121 {
00122 if(produceHistos()){
00123 info() << "Saving Timing histograms" << endmsg;
00124 const size_t bins = m_timerList.size();
00125 AIDA::IHistogram1D* histoTime = book("ElapsedTime", 0, bins, bins);
00126 AIDA::IHistogram1D* histoCPU = book("CPUTime", 0, bins, bins);
00127 AIDA::IHistogram1D* histoCount = book("Count", 0, bins, bins);
00128 TH1D* tHtime = Gaudi::Utils::Aida2ROOT::aida2root(histoTime);
00129 TH1D* tHCPU = Gaudi::Utils::Aida2ROOT::aida2root(histoCPU);
00130 TH1D* tHCount = Gaudi::Utils::Aida2ROOT::aida2root(histoCount);
00131 for ( size_t kk = 0 ; bins > kk ; kk++ ) {
00132 TimerForSequencer &tfsq = m_timerList[kk];
00133 tHtime->Fill(tfsq.name().c_str(), tfsq.elapsedTotal());
00134 tHCPU->Fill(tfsq.name().c_str(), tfsq.cpuTotal());
00135 tHCount->Fill(tfsq.name().c_str(), tfsq.count());
00136 }
00137 }
00138 }
00139
00140
00141
00142