Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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/Stat.h"
12 #include "GaudiKernel/StatEntity.h"
13 // ============================================================================
14 // Boost
15 // ============================================================================
16 #include "boost/format.hpp"
17 // ============================================================================
24 // ============================================================================
25 /* Constructor from IStatSvc,tag and value
26  *
27  * @code
28  *
29  * IStatSvc* statSvc = ... ;
30  * double eTotal = .... ;
31  *
32  * Stat eTot ( statSvc , "total energy" ) ;
33  * eTot += eTotal ;
34  *
35  * @endcode
36  *
37  * @see IStatSvc
38  * @param svc pointer to Chrono&Stat Service
39  * @paran tag unique tag for the entry
40  */
41 // ============================================================================
42 Stat::Stat( IStatSvc* svc, const std::string& tag ) : m_tag( tag ), m_group(), m_stat( svc ) {
43  if ( m_stat ) {
44  // get from the service
45  StatEntity* tmp = m_stat->stat( tag );
46  if ( !tmp ) {
47  // create if needed
48  m_stat->stat( tag, 0 );
49  tmp = m_stat->stat( tag );
50  tmp->reset();
51  }
52  m_entity = tmp;
53  }
54 }
55 // ============================================================================
56 /* Constructor from IStatSvc,tag and value
57  *
58  * @code
59  *
60  * IStatSvc* statSvc = ... ;
61  * double eTotal = .... ;
62  *
63  * Stat stat( statSvc , "total energy" , eTotal ) ;
64  *
65  * @endcode
66  *
67  * @see IStatSvc
68  * @param svc pointer to Chrono&Stat Service
69  * @paran tag unique tag for the entry
70  * @param flag "flag"(additive quantity) to be used
71  */
72 // ============================================================================
73 Stat::Stat( IStatSvc* svc, const std::string& tag, const double flag ) : m_tag( tag ), m_group(), m_stat( svc ) {
74  if ( m_stat ) {
75  m_stat->stat( tag, flag );
76  // get from the service
77  m_entity = m_stat->stat( tag );
78  }
79 }
80 
81 // ============================================================================
82 // representation as string
83 // ============================================================================
86  print( ost );
87  return ost.str();
88 }
89 // ============================================================================
90 /* printout to std::ostream
91  * @param s the reference to the output stream
92  */
93 // ============================================================================
95  if ( m_group.empty() && m_tag.empty() ) { return !m_entity ? ( o << "NULL" ) : ( o << m_entity ); }
96  if ( !m_group.empty() ) {
97  if ( m_entity ) {
98  return o << boost::format( " %|1$15s|::%|2$-15s| %|32t|%3%" ) % ( "\"" + m_group ) % ( m_tag + "\"" ) %
99  ( *m_entity );
100  } else {
101  return o << boost::format( " %|1$15s|::%|2$-15s| %|32t|%NULL%" ) % ( "\"" + m_group ) % ( m_tag + "\"" );
102  }
103  }
104  if ( m_entity ) { return o << boost::format( " %|1$=30s| %|32t|%2%" ) % ( "\"" + m_tag + "\"" ) % ( *m_entity ); }
105  return o << boost::format( " %|1$=30s| %|32t|%NULL%" ) % ( "\"" + m_tag + "\"" );
106 }
107 // ============================================================================
108 // external operator for addition of Stat and a number
109 // ============================================================================
110 Stat operator+( const Stat& stat, const double value ) {
111  Stat s( stat );
112  s += value;
113  return s;
114 }
115 // ============================================================================
116 // external operator for subtraction of Stat and a number
117 // ============================================================================
118 Stat operator-( const Stat& stat, const double value ) {
119  Stat s( stat );
120  s -= value;
121  return s;
122 }
123 // ============================================================================
124 // external operator for addition of Stat and a number
125 // ============================================================================
126 Stat operator+( const double value, const Stat& stat ) {
127  Stat s( stat );
128  s += value;
129  return s;
130 }
131 // ============================================================================
132 // external operator for addition of Stat and Stat
133 Stat operator+( const Stat& stat, const Stat& value ) {
134  Stat s( stat );
135  s += value;
136  return s;
137 }
138 // ============================================================================
139 // external printout operator to std::ostream
140 std::ostream& operator<<( std::ostream& stream, const Stat& stat ) { return stat.print( stream ); }
141 // ============================================================================
142 
143 // ============================================================================
144 // The END
145 // ============================================================================
T empty(T...args)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:109
Small wrapper class for easy manipulation with generic counters and IStatSvc interface.
Definition: Stat.h:46
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:246
virtual void stat(const StatTag &t, const StatFlag &f)=0
add statistical information to the entity , tagged by its name
StatEntity * m_entity
underlying counter
Definition: Stat.h:240
Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:110
void reset()
Definition: Counters.h:860
STL class.
std::string m_tag
unique stat tag(name)
Definition: Stat.h:242
Stat(StatEntity *entity=0, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:64
std::string m_group
Definition: Stat.h:244
std::string toString() const
representation as string
Definition: Stat.cpp:84
string s
Definition: gaudirun.py:312
std::ostream & operator<<(std::ostream &stream, const Stat &stat)
external printout operator to std::ostream
Definition: Stat.cpp:140
"Stat"-related part of interface IChronoStatSvc
Definition: IStatSvc.h:25
backward compatible StatEntity class.
Definition: Counters.h:837
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition: Stat.cpp:94
STL class.
Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:118