| The Gaudi Framework v28r2-patches (bc4ad17a)

- 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/IStatSvc.h"
11 #include "GaudiKernel/ICounterSvc.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 ,
44 const std::string& tag )
45 : m_tag ( tag )
46 , m_group ( )
47 , m_stat ( svc )
48 {
49 if ( m_stat )
50 {
51 // get from the service
52 const StatEntity* tmp = m_stat->stat ( tag ) ;
53 if ( !tmp )
54 {
55 // create if needed
56 m_stat->stat ( tag , 0 ) ;
57 tmp = m_stat->stat ( tag ) ;
58 StatEntity* aux = const_cast<StatEntity*>( tmp );
59 aux->reset () ;
60 }
61 m_entity = const_cast<StatEntity*> ( tmp ) ;
62 }
63 }
64 // ============================================================================
65 /* Constructor from IStatSvc,tag and value
66 *
67 * @code
68 *
69 * IStatSvc* statSvc = ... ;
70 * double eTotal = .... ;
71 *
72 * Stat stat( statSvc , "total energy" , eTotal ) ;
73 *
74 * @endcode
75 *
76 * @see IStatSvc
77 * @param svc pointer to Chrono&Stat Service
78 * @paran tag unique tag for the entry
79 * @param flag "flag"(additive quantity) to be used
80 */
81 // ============================================================================
82 Stat::Stat ( IStatSvc* svc ,
83 const std::string& tag ,
84 const double flag )
85 : m_tag ( tag )
86 , m_group ( )
87 , m_stat ( svc )
88 {
89 if ( m_stat )
90 {
91 m_stat -> stat( tag , flag ) ;
92 // get from the service
93 m_entity = const_cast<StatEntity*>( m_stat -> stat ( tag ) ) ;
94 }
95 }
96 // ============================================================================
97 /* constructor from ICounterSvc, group and name
98 * @see ICounterSvc::get
99 * @see ICounterSvc::create
100 * @param svc pointer to Counter Service
101 * @param group group name
102 * @param name counter name
103 */
104 // ============================================================================
105 Stat::Stat ( ICounterSvc* svc ,
106 const std::string& group ,
107 const std::string& name )
108 : m_tag ( name )
109 , m_group ( group )
110 , m_counter ( svc )
111 {
112 if ( m_counter )
113 {
114 // get from the service
115 m_entity = m_counter -> get ( group , name ) ;
116 // create if needed:
117 if ( ! m_entity ) { m_counter -> create( group , name , 0 , m_entity ) ; }
118 }
119 }
120
121 // ============================================================================
122 // representation as string
123 // ============================================================================
124 std::string Stat::toString() const
125 {
126 std::ostringstream ost ;
127 print ( ost ) ;
128 return ost.str () ;
129 }
130 // ============================================================================
131 /* printout to std::ostream
132 * @param s the reference to the output stream
133 */
134 // ============================================================================
135 std::ostream& Stat::print( std::ostream& o ) const
136 {
137 if ( m_group.empty() && m_tag.empty() )
138 { return !m_entity ? ( o << "NULL" ) : ( o << m_entity ) ; }
139 if ( !m_group.empty() )
140 {
141 if ( m_entity )
142 {
143 return o << boost::format(" %|1$15s|::%|2$-15s| %|32t|%3%")
144 % ( "\"" + m_group ) % ( m_tag + "\"") % (*m_entity) ;
145 }
146 else
147 {
148 return o << boost::format(" %|1$15s|::%|2$-15s| %|32t|%NULL%")
149 % ( "\"" + m_group ) % ( m_tag + "\"") ;
150 }
151 }
152 if ( m_entity )
153 {
154 return o << boost::format(" %|1$=30s| %|32t|%2%")
155 % ("\"" + m_tag + "\"" ) % (*m_entity) ;
156 }
157 return o << boost::format(" %|1$=30s| %|32t|%NULL%")
158 % ( "\"" + m_tag + "\"" ) ;
159 }
160 // ============================================================================
161 // external operator for addition of Stat and a number
162 // ============================================================================
163 Stat operator+( const Stat& stat , const double value )
164 { Stat s( stat ) ; s += value ; return s ; }
165 // ============================================================================
166 // external operator for subtraction of Stat and a number
167 // ============================================================================
168 Stat operator-( const Stat& stat , const double value )
169 { Stat s( stat ) ; s -= value ; return s ; }
170 // ============================================================================
171 // external operator for addition of Stat and a number
172 // ============================================================================
173 Stat operator+( const double value , const Stat& stat )
174 { Stat s( stat ) ; s += value ; return s ; }
175 // ============================================================================
176 // external operator for addition of Stat and Stat
177 Stat operator+( const Stat& stat , const Stat& value )
178 { Stat s( stat ) ; s += value ; return s ; }
179 // ============================================================================
180 // external printout operator to std::ostream
181 std::ostream& operator<<( std::ostream& stream , const Stat& stat )
182 { return stat.print( stream ) ; }
183 // ============================================================================
184
185 // ============================================================================
186 // The END
187 // ============================================================================
std::string::empty
T empty(T...args)
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
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:290
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:284
operator+
Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:163
StatEntity::reset
void reset()
reset the counters
Definition: StatEntity.cpp:232
Stat::name
const std::string & name() const
counter name
Definition: Stat.h:278
std::string
STL class.
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:286
Stat::m_counter
SmartIF< ICounterSvc > m_counter
Counter Service.
Definition: Stat.h:292
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:288
std::ostringstream::str
T str(T...args)
StatEntity.h
Stat::toString
std::string toString() const
representation as string
Definition: Stat.cpp:124
gaudirun.s
string s
Definition: gaudirun.py:245
Stat.h
operator<<
std::ostream & operator<<(std::ostream &stream, const Stat &stat)
output operator for the counter object
Definition: Stat.cpp:181
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:135
ICounterSvc.h
std::ostream
STL class.
Stat::group
const std::string & group() const
counter group (for ICounterSvc)
Definition: Stat.h:280
operator-
Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:168