The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
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
14#include <GaudiKernel/SmartIF.h>
16#include <iostream>
17#include <string>
18
49public:
66 Stat( StatEntity* entity = 0, const std::string& name = "", const std::string& group = "" )
67 : m_entity( entity ), m_tag( name ), m_group( group ) {}
68
82 Stat( StatEntity& entity, const std::string& name = "", const std::string& group = "" )
83 : m_entity( &entity ), m_tag( name ), m_group( group ) {}
84
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 }
155
169 if ( m_entity ) { ++( *m_entity ); }
170 return *this;
171 }
172
184 Stat& operator++( int ) {
185 if ( m_entity ) { ( *m_entity )++; }
186 return *this;
187 }
188
193 Stat& operator-=( const double f ) {
194 if ( m_entity ) { ( *m_entity ) -= f; }
195 return *this;
196 }
197
199 if ( m_entity ) { --( *m_entity ); }
200 return *this;
201 }
202
203 Stat& operator--( int ) {
204 if ( m_entity ) { ( *m_entity )--; }
205 return *this;
206 }
207
208 Stat& operator+=( const StatEntity& right ) {
209 if ( m_entity ) { ( *m_entity ) += right; }
210 return *this;
211 }
212
213 Stat& operator+=( const Stat& right ) {
214 if ( 0 != right.entity() ) { ( *this ) += *right.entity(); }
215 return *this;
216 }
217
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
236private:
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};
246
247GAUDI_API Stat operator+( const Stat& stat, const double value );
249GAUDI_API Stat operator-( const Stat& stat, const double value );
251GAUDI_API Stat operator+( const double value, const Stat& stat );
253GAUDI_API Stat operator+( const Stat& stat, const Stat& value );
255GAUDI_API std::ostream& operator<<( std::ostream& stream, const Stat& stat );
#define GAUDI_API
Definition Kernel.h:49
GAUDI_API std::ostream & operator<<(std::ostream &stream, const Stat &stat)
external printout operator to std::ostream
Definition Stat.cpp:93
GAUDI_API Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition Stat.cpp:69
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition Stat.cpp:75
"Stat"-related part of interface IChronoStatSvc
Definition IStatSvc.h:25
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
backward compatible StatEntity class.
Definition StatEntity.h:23
Small wrapper class for easy manipulation with generic counters and IStatSvc interface.
Definition Stat.h:48
const StatEntity * operator->() const
dereference operaqtor
Definition Stat.h:130
Stat(StatEntity &entity, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition Stat.h:82
Stat & operator+=(const double f)
General increment for the counter.
Definition Stat.h:151
std::ostream & fillStream(std::ostream &o) const
printout to std::ostream
Definition Stat.h:228
Stat & operator++()
Pre-increment operator for the counter.
Definition Stat.h:168
~Stat()=default
destructor
std::string m_tag
unique stat tag(name)
Definition Stat.h:240
Stat & operator+=(const Stat &right)
increment with other stat objects
Definition Stat.h:213
Stat(const Stat &)=default
copy constructor
Stat(StatEntity *entity=0, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition Stat.h:66
Stat & operator-=(const double f)
General decrement operator for the counter.
Definition Stat.h:193
const StatEntity * entity() const
get the entity
Definition Stat.h:128
Stat & operator--()
Pre-decrement operator for the flag.
Definition Stat.h:198
Stat & operator++(int)
Post-increment operator for the counter.
Definition Stat.h:184
StatEntity * m_entity
underlying counter
Definition Stat.h:238
Stat & operator+=(const StatEntity &right)
increment with StatEntity object
Definition Stat.h:208
Stat & operator--(int)
Post-decrement operator for the flag.
Definition Stat.h:203
Stat & operator=(const Stat &)=default
Assignement operator.
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition Stat.cpp:56
SmartIF< IStatSvc > m_stat
Stat service.
Definition Stat.h:244
StatEntity * counter() const
alternative access to underlying counter
Definition Stat.h:230
bool operator!() const
check validity
Definition Stat.h:134
std::string m_group
Definition Stat.h:242
const std::string & name() const
counter name
Definition Stat.h:232
const std::string & group() const
counter group
Definition Stat.h:234