| The Gaudi Framework v30r0 (c919700c)

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

- File List
- File Members

Stat.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // STD & STL
5 // ============================================================================
6 #include <sstream>
7 // ============================================================================
8 // GaudiKernel
9 // ============================================================================
10 #include "GaudiKernel/ICounterSvc.h"
11 #include "GaudiKernel/IStatSvc.h"
12 #include "GaudiKernel/Stat.h"
13 #include "GaudiKernel/StatEntity.h"
14 // ============================================================================
15 // Boost
16 // ============================================================================
17 #include "boost/format.hpp"
18 // ============================================================================
25 // ============================================================================
26 /* Constructor from IStatSvc,tag and value
27 *
28 * @code
29 *
30 * IStatSvc* statSvc = ... ;
31 * double eTotal = .... ;
32 *
33 * Stat eTot ( statSvc , "total energy" ) ;
34 * eTot += eTotal ;
35 *
36 * @endcode
37 *
38 * @see IStatSvc
39 * @param svc pointer to Chrono&Stat Service
40 * @paran tag unique tag for the entry
41 */
42 // ============================================================================
43 Stat::Stat( IStatSvc* svc, const std::string& tag ) : m_tag( tag ), m_group(), m_stat( svc )
44 {
45 if ( m_stat ) {
46 // get from the service
47 const StatEntity* tmp = m_stat->stat( tag );
48 if ( !tmp ) {
49 // create if needed
50 m_stat->stat( tag, 0 );
51 tmp = m_stat->stat( tag );
52 StatEntity* aux = const_cast<StatEntity*>( tmp );
53 aux->reset();
54 }
55 m_entity = const_cast<StatEntity*>( tmp );
56 }
57 }
58 // ============================================================================
59 /* Constructor from IStatSvc,tag and value
60 *
61 * @code
62 *
63 * IStatSvc* statSvc = ... ;
64 * double eTotal = .... ;
65 *
66 * Stat stat( statSvc , "total energy" , eTotal ) ;
67 *
68 * @endcode
69 *
70 * @see IStatSvc
71 * @param svc pointer to Chrono&Stat Service
72 * @paran tag unique tag for the entry
73 * @param flag "flag"(additive quantity) to be used
74 */
75 // ============================================================================
76 Stat::Stat( IStatSvc* svc, const std::string& tag, const double flag ) : m_tag( tag ), m_group(), m_stat( svc )
77 {
78 if ( m_stat ) {
79 m_stat->stat( tag, flag );
80 // get from the service
81 m_entity = const_cast<StatEntity*>( m_stat->stat( tag ) );
82 }
83 }
84 // ============================================================================
85 /* constructor from ICounterSvc, group and name
86 * @see ICounterSvc::get
87 * @see ICounterSvc::create
88 * @param svc pointer to Counter Service
89 * @param group group name
90 * @param name counter name
91 */
92 // ============================================================================
93 Stat::Stat( ICounterSvc* svc, const std::string& group, const std::string& name )
94 : m_tag( name ), m_group( group ), m_counter( svc )
95 {
96 if ( m_counter ) {
97 // get from the service
98 m_entity = m_counter->get( group, name );
99 // create if needed:
100 if ( !m_entity ) {
101 m_counter->create( group, name, 0, m_entity );
102 }
103 }
104 }
105
106 // ============================================================================
107 // representation as string
108 // ============================================================================
109 std::string Stat::toString() const
110 {
111 std::ostringstream ost;
112 print( ost );
113 return ost.str();
114 }
115 // ============================================================================
116 /* printout to std::ostream
117 * @param s the reference to the output stream
118 */
119 // ============================================================================
120 std::ostream& Stat::print( std::ostream& o ) const
121 {
122 if ( m_group.empty() && m_tag.empty() ) {
123 return !m_entity ? ( o << "NULL" ) : ( o << m_entity );
124 }
125 if ( !m_group.empty() ) {
126 if ( m_entity ) {
127 return o << boost::format( " %|1$15s|::%|2$-15s| %|32t|%3%" ) % ( "\"" + m_group ) % ( m_tag + "\"" ) %
128 ( *m_entity );
129 } else {
130 return o << boost::format( " %|1$15s|::%|2$-15s| %|32t|%NULL%" ) % ( "\"" + m_group ) % ( m_tag + "\"" );
131 }
132 }
133 if ( m_entity ) {
134 return o << boost::format( " %|1$=30s| %|32t|%2%" ) % ( "\"" + m_tag + "\"" ) % ( *m_entity );
135 }
136 return o << boost::format( " %|1$=30s| %|32t|%NULL%" ) % ( "\"" + m_tag + "\"" );
137 }
138 // ============================================================================
139 // external operator for addition of Stat and a number
140 // ============================================================================
141 Stat operator+( const Stat& stat, const double value )
142 {
143 Stat s( stat );
144 s += value;
145 return s;
146 }
147 // ============================================================================
148 // external operator for subtraction of Stat and a number
149 // ============================================================================
150 Stat operator-( const Stat& stat, const double value )
151 {
152 Stat s( stat );
153 s -= value;
154 return s;
155 }
156 // ============================================================================
157 // external operator for addition of Stat and a number
158 // ============================================================================
159 Stat operator+( const double value, const Stat& stat )
160 {
161 Stat s( stat );
162 s += value;
163 return s;
164 }
165 // ============================================================================
166 // external operator for addition of Stat and Stat
167 Stat operator+( const Stat& stat, const Stat& value )
168 {
169 Stat s( stat );
170 s += value;
171 return s;
172 }
173 // ============================================================================
174 // external printout operator to std::ostream
175 std::ostream& operator<<( std::ostream& stream, const Stat& stat ) { return stat.print( stream ); }
176 // ============================================================================
177
178 // ============================================================================
179 // The END
180 // ============================================================================
ICounterSvc::create
virtual StatusCode create(const std::string &group, const std::string &name, longlong initial_value, Counter *&refpCounter)=0
Create a new counter object.
std::string::empty
T empty(T...args)
ICounterSvc::get
virtual Counter * get(const std::string &group, const std::string &name) const =0
Access an existing counter object.
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:120
Stat
Small wrapper class for easy manipulation with generic counters and IStatSvc&ICounterSvc interface...
Definition: Stat.h:46
ICounterSvc
Create / access multi purpose counters.
Definition: ICounterSvc.h:75
Stat::m_stat
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:293
IStatSvc::stat
virtual void stat(const StatTag &t, const StatFlag &f)=0
add statistical information to the entity , tagged by its name
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
operator+
Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:141
StatEntity::reset
void reset()
reset the counters
Definition: StatEntity.cpp:207
Stat::name
const std::string & name() const
counter name
Definition: Stat.h:281
std::string
STL class.
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:289
Stat::m_counter
SmartIF< ICounterSvc > m_counter
Counter Service.
Definition: Stat.h:295
IStatSvc.h
std::ostringstream
STL class.
Stat::Stat
Stat(StatEntity *entity=0, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:65
Stat::m_group
std::string m_group
Definition: Stat.h:291
std::ostringstream::str
T str(T...args)
StatEntity.h
Stat::toString
std::string toString() const
representation as string
Definition: Stat.cpp:109
gaudirun.s
string s
Definition: gaudirun.py:253
Stat.h
operator<<
std::ostream & operator<<(std::ostream &stream, const Stat &stat)
output operator for the counter object
Definition: Stat.cpp:175
IStatSvc
"Stat"-related part of interface IChronoStatSvc
Definition: IStatSvc.h:25
StatEntity
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:65
Stat::print
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition: Stat.cpp:120
ICounterSvc.h
std::ostream
STL class.
Stat::group
const std::string & group() const
counter group (for ICounterSvc)
Definition: Stat.h:283
operator-
Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:150