Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r7 (7f57a304)
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 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #include "GaudiKernel/Stat.h"
12 #include "GaudiKernel/IStatSvc.h"
13 #include "GaudiKernel/StatEntity.h"
14 #include <fmt/format.h>
15 #include <fmt/ostream.h>
16 #include <sstream>
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 o the reference to the output stream
92  */
93 // ============================================================================
95  auto entity = ( m_entity ) ? fmt::format( "{}", *m_entity ) : "NULL";
96  std::string tag;
97  if ( !m_tag.empty() ) {
98  if ( !m_group.empty() ) {
99  tag = fmt::format( "\"{}::{}\"", m_group, m_tag );
100  } else {
101  tag = fmt::format( "\"{}\"", m_tag );
102  }
103  }
104  return o << fmt::format( " {:^30} {}", tag, entity );
105 }
106 // ============================================================================
107 // external operator for addition of Stat and a number
108 // ============================================================================
109 Stat operator+( const Stat& stat, const double value ) {
110  Stat s( stat );
111  s += value;
112  return s;
113 }
114 // ============================================================================
115 // external operator for subtraction of Stat and a number
116 // ============================================================================
117 Stat operator-( const Stat& stat, const double value ) {
118  Stat s( stat );
119  s -= value;
120  return s;
121 }
122 // ============================================================================
123 // external operator for addition of Stat and a number
124 // ============================================================================
125 Stat operator+( const double value, const Stat& stat ) {
126  Stat s( stat );
127  s += value;
128  return s;
129 }
130 // ============================================================================
131 // external operator for addition of Stat and Stat
132 Stat operator+( const Stat& stat, const Stat& value ) {
133  Stat s( stat );
134  s += value;
135  return s;
136 }
137 // ============================================================================
138 // external printout operator to std::ostream
139 std::ostream& operator<<( std::ostream& stream, const Stat& stat ) { return stat.print( stream ); }
140 // ============================================================================
141 
142 // ============================================================================
143 // The END
144 // ============================================================================
StatEntity::reset
void reset()
Definition: StatEntity.h:40
Stat::print
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition: Stat.cpp:94
Write.stream
stream
Definition: Write.py:32
std::string
STL class.
operator+
Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:109
gaudirun.s
string s
Definition: gaudirun.py:346
operator<<
std::ostream & operator<<(std::ostream &stream, const Stat &stat)
external printout operator to std::ostream
Definition: Stat.cpp:139
StatEntity
backward compatible StatEntity class.
Definition: StatEntity.h:23
StatEntity.h
Stat::entity
const StatEntity * entity() const
get the entity
Definition: Stat.h:137
Stat::m_stat
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:256
IStatSvc
Definition: IStatSvc.h:35
Stat::m_group
std::string m_group
Definition: Stat.h:254
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:252
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:250
operator-
Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:117
std::ostream
STL class.
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
Stat::Stat
Stat(StatEntity *entity=0, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:74
IStatSvc.h
Stat.h
Stat
Definition: Stat.h:56
std::ostringstream
STL class.
std::string::empty
T empty(T... args)
std::ostringstream::str
T str(T... args)
Stat::toString
std::string toString() const
representation as string
Definition: Stat.cpp:84