Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
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-2025 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/IStatSvc.h>
12 #include <GaudiKernel/Stat.h>
13 #include <GaudiKernel/StatEntity.h>
14 #include <fmt/format.h>
15 #include <fmt/ostream.h>
16 #include <sstream>
17 
25 template <>
26 struct fmt::formatter<StatEntity> : fmt::ostream_formatter {};
27 
28 Stat::Stat( IStatSvc* svc, const std::string& tag ) : m_tag( tag ), m_group(), m_stat( svc ) {
29  if ( m_stat ) {
30  // get from the service
31  StatEntity* tmp = m_stat->stat( tag );
32  if ( !tmp ) {
33  // create if needed
34  m_stat->stat( tag, 0 );
35  tmp = m_stat->stat( tag );
36  tmp->reset();
37  }
38  m_entity = tmp;
39  }
40 }
41 
42 Stat::Stat( IStatSvc* svc, const std::string& tag, const double flag ) : m_tag( tag ), m_group(), m_stat( svc ) {
43  if ( m_stat ) {
44  m_stat->stat( tag, flag );
45  // get from the service
46  m_entity = m_stat->stat( tag );
47  }
48 }
49 
50 std::string Stat::toString() const {
51  std::ostringstream ost;
52  print( ost );
53  return ost.str();
54 }
55 
56 std::ostream& Stat::print( std::ostream& o ) const {
57  auto entity = ( m_entity ) ? fmt::format( "{}", *m_entity ) : "NULL";
58  std::string tag;
59  if ( !m_tag.empty() ) {
60  if ( !m_group.empty() ) {
61  tag = fmt::format( "\"{}::{}\"", m_group, m_tag );
62  } else {
63  tag = fmt::format( "\"{}\"", m_tag );
64  }
65  }
66  return o << fmt::format( " {:^30} {}", tag, entity );
67 }
68 
69 Stat operator+( const Stat& stat, const double value ) {
70  Stat s( stat );
71  s += value;
72  return s;
73 }
74 
75 Stat operator-( const Stat& stat, const double value ) {
76  Stat s( stat );
77  s -= value;
78  return s;
79 }
80 
81 Stat operator+( const double value, const Stat& stat ) {
82  Stat s( stat );
83  s += value;
84  return s;
85 }
86 
87 Stat operator+( const Stat& stat, const Stat& value ) {
88  Stat s( stat );
89  s += value;
90  return s;
91 }
92 
93 std::ostream& operator<<( std::ostream& stream, const Stat& stat ) { return stat.print( stream ); }
Stat::print
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition: Stat.cpp:56
Write.stream
stream
Definition: Write.py:32
operator+
Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:69
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:93
StatEntity
backward compatible StatEntity class.
Definition: StatEntity.h:23
StatEntity.h
Stat::entity
const StatEntity * entity() const
get the entity
Definition: Stat.h:128
Stat::m_stat
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:244
IStatSvc
Definition: IStatSvc.h:25
Stat::m_group
std::string m_group
Definition: Stat.h:242
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:240
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:238
operator-
Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:75
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:93
Stat::Stat
Stat(StatEntity *entity=0, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:66
IStatSvc.h
Stat.h
Stat
Definition: Stat.h:48
StatEntity::reset
friend void reset(StatEntity &s)
Definition: StatEntity.h:40
Stat::toString
std::string toString() const
representation as string
Definition: Stat.cpp:50