The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Stat.h
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 #pragma once
12 
13 #include <GaudiKernel/IStatSvc.h>
14 #include <GaudiKernel/SmartIF.h>
15 #include <GaudiKernel/StatEntity.h>
16 #include <iostream>
17 #include <string>
18 
48 class GAUDI_API Stat {
49 public:
66  Stat( StatEntity* entity = 0, const std::string& name = "", const std::string& group = "" )
67  : m_entity( entity ), m_tag( name ), m_group( group ) {}
82  Stat( StatEntity& entity, const std::string& name = "", const std::string& group = "" )
83  : m_entity( &entity ), m_tag( name ), m_group( group ) {}
102  Stat( IStatSvc* svc, const std::string& tag );
120  Stat( IStatSvc* svc, const std::string& tag, const double flag );
122  Stat( const Stat& ) = default;
124  Stat& operator=( const Stat& ) = default;
126  ~Stat() = default;
128  const StatEntity* entity() const { return m_entity; }
130  const StatEntity* operator->() const { return entity(); }
132  operator const StatEntity&() const { return *entity(); }
134  bool operator!() const { return 0 == m_entity; }
151  Stat& operator+=( const double f ) {
152  if ( m_entity ) { ( *m_entity ) += f; }
153  return *this;
154  }
169  if ( m_entity ) { ++( *m_entity ); }
170  return *this;
171  }
184  Stat& operator++( int ) {
185  if ( m_entity ) { ( *m_entity )++; }
186  return *this;
187  }
193  Stat& operator-=( const double f ) {
194  if ( m_entity ) { ( *m_entity ) -= f; }
195  return *this;
196  }
199  if ( m_entity ) { --( *m_entity ); }
200  return *this;
201  }
203  Stat& operator--( int ) {
204  if ( m_entity ) { ( *m_entity )--; }
205  return *this;
206  }
208  Stat& operator+=( const StatEntity& right ) {
209  if ( m_entity ) { ( *m_entity ) += right; }
210  return *this;
211  }
213  Stat& operator+=( const Stat& right ) {
214  if ( 0 != right.entity() ) { ( *this ) += *right.entity(); }
215  return *this;
216  }
218  std::string toString() const;
223  std::ostream& print( std::ostream& o = std::cout ) const;
228  std::ostream& fillStream( std::ostream& o ) const { return print( o ); }
230  StatEntity* counter() const { return m_entity; }
232  const std::string& name() const { return m_tag; }
234  const std::string& group() const { return m_group; }
235 
236 private:
237  // underlying counter
238  StatEntity* m_entity = nullptr;
239  // unique stat tag(name)
240  std::string m_tag;
241  // group
242  std::string m_group;
243  // Stat service
245 };
247 GAUDI_API Stat operator+( const Stat& stat, const double value );
249 GAUDI_API Stat operator-( const Stat& stat, const double value );
251 GAUDI_API Stat operator+( const double value, const Stat& stat );
253 GAUDI_API Stat operator+( const Stat& stat, const Stat& value );
255 GAUDI_API std::ostream& operator<<( std::ostream& stream, const Stat& stat );
Stat::Stat
Stat(const Stat &)=default
copy constructor
Stat::fillStream
std::ostream & fillStream(std::ostream &o) const
printout to std::ostream
Definition: Stat.h:228
Write.stream
stream
Definition: Write.py:32
Stat::operator++
Stat & operator++(int)
Post-increment operator for the counter.
Definition: Stat.h:184
StatEntity
backward compatible StatEntity class.
Definition: StatEntity.h:23
StatEntity.h
Stat::operator+=
Stat & operator+=(const double f)
General increment for the counter.
Definition: Stat.h:151
Stat::entity
const StatEntity * entity() const
get the entity
Definition: Stat.h:128
operator<<
GAUDI_API std::ostream & operator<<(std::ostream &stream, const Stat &stat)
external printout operator to std::ostream
Definition: Stat.cpp:93
Stat::m_stat
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:244
IStatSvc
Definition: IStatSvc.h:25
Stat::name
const std::string & name() const
counter name
Definition: Stat.h:232
Stat::m_group
std::string m_group
Definition: Stat.h:242
SmartIF.h
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:240
Stat::operator++
Stat & operator++()
Pre-increment operator for the counter.
Definition: Stat.h:168
Stat::operator--
Stat & operator--()
Pre-decrement operator for the flag.
Definition: Stat.h:198
Stat::Stat
Stat(StatEntity &entity, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:82
Stat::operator--
Stat & operator--(int)
Post-decrement operator for the flag.
Definition: Stat.h:203
Stat::operator+=
Stat & operator+=(const StatEntity &right)
increment with StatEntity object
Definition: Stat.h:208
SmartIF< IStatSvc >
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
Definition: Stat.h:48
Stat::operator->
const StatEntity * operator->() const
dereference operaqtor
Definition: Stat.h:130
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:326
Gaudi::Utils::Histos::Formats::Stat
@ Stat
Definition: HistoTableFormat.h:99
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Stat::~Stat
~Stat()=default
destructor
Stat::group
const std::string & group() const
counter group
Definition: Stat.h:234
Stat::operator=
Stat & operator=(const Stat &)=default
Assignement operator.
operator+
GAUDI_API Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:69
Stat::counter
StatEntity * counter() const
alternative access to underlying counter
Definition: Stat.h:230
Stat::operator!
bool operator!() const
check validity
Definition: Stat.h:134
Stat::operator-=
Stat & operator-=(const double f)
General decrement operator for the counter.
Definition: Stat.h:193
Stat::operator+=
Stat & operator+=(const Stat &right)
increment with other stat objects
Definition: Stat.h:213
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:49
operator-
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:75