BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTimerSvc.cxx
Go to the documentation of this file.
1// this is -*- c++ -*-
2// $Id: BesTimerSvc.cxx,v 1.5 2022/01/12 04:44:15 maqm Exp $
3// $Name: BesTimerSvc-00-01-00 $
4#include "GaudiKernel/IInterface.h"
5#include "GaudiKernel/Kernel.h"
6#include "GaudiKernel/MsgStream.h"
7#include "GaudiKernel/StatusCode.h"
8#include <algorithm>
9#include <string>
10#include <vector>
11// #include "GaudiKernel/ISvcFactory.h"
12#include "BesTimerSvc.h"
13
15
16BesTimerSvc::BesTimerSvc( const std::string& name, ISvcLocator* svcloc )
17 : base_class( name, svcloc ) {}
18
20 std::vector<BesTimer*>::iterator it = m_itemList.begin();
21 for ( ; it != m_itemList.end(); it++ ) { delete ( *it ); }
22}
23
24/*StatusCode BesTimerSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ) {
25
26 if ( IID_IBesTimerSvc.versionMatch(riid) ) {
27 *ppvInterface = static_cast<IBesTimerSvc*> (this);
28 } else {
29 return Service::queryInterface(riid, ppvInterface) ;
30 }
31 return StatusCode::SUCCESS;
32}*/
34 MsgStream log( msgSvc(), name() );
35 log << MSG::INFO << name() << ": Start of run initialisation" << endmsg;
36
37 StatusCode sc = Service::initialize();
38 if ( sc.isFailure() ) return sc;
39 // Set my own properties
40 // setProperties();
41
42 return StatusCode::SUCCESS;
43}
44
46 MsgStream log( msgSvc(), name() );
47 log << MSG::INFO << name() << ": End of Run Statistics" << endmsg;
48 this->print();
49 return StatusCode::SUCCESS;
50}
51
52BesTimer* BesTimerSvc::addItem( const std::string& itemName ) {
53
54 // Create a BesTimer and return a pointer to it
55 // If an item of that name already exists, flag error
56 // by returning NULL
57
58 MsgStream log( msgSvc(), name() );
59 log << MSG::DEBUG << name() << " adding " << itemName << endmsg;
60
61 BesTimer* item = new BesTimer( itemName );
62 m_itemList.push_back( item );
63 return item;
64}
65
67 MsgStream log( msgSvc(), name() );
68
69 log << MSG::INFO
70 << "==============================BesTimerSvc::Print==============================="
71 << endmsg;
72 unsigned int maxname = 0;
73 std::vector<BesTimer*>::iterator it = m_itemList.begin();
74 for ( ; it != m_itemList.end(); it++ )
75 {
76 if ( ( *it )->name().length() > maxname )
77 maxname = static_cast<int>( ( *it )->name().length() );
78 if ( !( *it )->propName().empty() )
79 {
80 if ( ( *it )->propName().length() > maxname )
81 maxname = static_cast<int>( ( *it )->propName().length() );
82 }
83 }
84
85 it = m_itemList.begin();
86 for ( ; it != m_itemList.end(); it++ )
87 {
88 std::string nam = ( *it )->name();
89 for ( unsigned int i = static_cast<int>( nam.length() ); i < maxname; i++ )
90 nam.insert( i, " " );
91 log << MSG::INFO << nam << " mean(t) : " << std::setw( 12 ) << ( *it )->mean()
92 << " ms rms : " << std::setw( 12 ) << ( *it )->rms() << " ms " << endmsg;
93 }
94 log << MSG::INFO
95 << "------------------------------------------------------------------------------"
96 << endmsg;
97 it = m_itemList.begin();
98 for ( ; it != m_itemList.end(); it++ )
99 {
100 if ( !( *it )->propName().empty() )
101 {
102 std::string nam = ( *it )->name();
103 for ( unsigned int i = static_cast<int>( nam.length() ); i < maxname; i++ )
104 nam.insert( i, " " );
105 log << MSG::INFO << nam << " mean(t) : " << std::setw( 12 ) << ( *it )->mean()
106 << " ms rms : " << std::setw( 12 ) << ( *it )->rms() << " ms " << endmsg;
107
108 nam = ( *it )->propName();
109 for ( unsigned int i = static_cast<int>( nam.length() ); i < maxname; i++ )
110 nam.insert( i, " " );
111 if ( ( *it )->meanPropVal() == 0 )
112 { log << MSG::INFO << nam << " mean(N) : " << std::setw( 12 ) << endmsg; }
113 else
114 {
115 log << MSG::INFO << nam << " mean(N) : " << std::setw( 12 ) << ( *it )->meanPropVal()
116 << " mean(t/N) : " << 1000. * ( *it )->meanTimePerObject() << " us " << endmsg;
117 }
118 }
119 }
120
121 log << MSG::INFO
122 << "==============================BesTimerSvc::Print==============================="
123 << endmsg;
124}
125
126std::vector<BesTimer*>::iterator BesTimerSvc::begin( void ) { return m_itemList.begin(); }
127std::vector<BesTimer*>::iterator BesTimerSvc::end( void ) { return m_itemList.end(); }
DECLARE_COMPONENT(BesBdkRc)
IMessageSvc * msgSvc()
virtual std::vector< BesTimer * >::iterator begin(void)
virtual BesTimer * addItem(const std::string &name)
virtual StatusCode initialize()
virtual void print()
virtual StatusCode finalize()
virtual std::vector< BesTimer * >::iterator end(void)
BesTimerSvc(const std::string &name, ISvcLocator *svcloc)