The Gaudi Framework  master (37c0b60a)
Stat.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 #ifndef __GAUDI_CHRONOSTATSVC_STAT_H__
12 #define __GAUDI_CHRONOSTATSVC_STAT_H__
13 // ============================================================================
14 // Iinclude files
15 // ============================================================================
16 // STD & STL
17 // ============================================================================
18 #include <iostream>
19 #include <string>
20 // ============================================================================
21 // GaudiKernel
22 // ============================================================================
23 #include <GaudiKernel/IStatSvc.h>
24 #include <GaudiKernel/SmartIF.h>
25 #include <GaudiKernel/StatEntity.h>
26 // ============================================================================
56 class GAUDI_API Stat {
57 public:
74  Stat( StatEntity* entity = 0, const std::string& name = "", const std::string& group = "" )
75  : m_entity( entity ), m_tag( name ), m_group( group ) {}
90  Stat( StatEntity& entity, const std::string& name = "", const std::string& group = "" )
91  : m_entity( &entity ), m_tag( name ), m_group( group ) {}
110  Stat( IStatSvc* svc, const std::string& tag );
128  Stat( IStatSvc* svc, const std::string& tag, const double flag );
130  Stat( const Stat& ) = default;
132  Stat& operator=( const Stat& ) = default;
134  ~Stat() = default;
135  // ==========================================================================
137  const StatEntity* entity() const { return m_entity; }
139  const StatEntity* operator->() const { return entity(); }
141  operator const StatEntity&() const { return *entity(); }
143  bool operator!() const { return 0 == m_entity; }
144  // ==========================================================================
161  Stat& operator+=( const double f ) {
162  if ( m_entity ) { ( *m_entity ) += f; }
163  return *this;
164  }
179  if ( m_entity ) { ++( *m_entity ); }
180  return *this;
181  }
194  Stat& operator++( int ) {
195  if ( m_entity ) { ( *m_entity )++; }
196  return *this;
197  }
203  Stat& operator-=( const double f ) {
204  if ( m_entity ) { ( *m_entity ) -= f; }
205  return *this;
206  }
209  if ( m_entity ) { --( *m_entity ); }
210  return *this;
211  }
213  Stat& operator--( int ) {
214  if ( m_entity ) { ( *m_entity )--; }
215  return *this;
216  }
218  Stat& operator+=( const StatEntity& right ) {
219  if ( m_entity ) { ( *m_entity ) += right; }
220  return *this;
221  }
223  Stat& operator+=( const Stat& right ) {
224  if ( 0 != right.entity() ) { ( *this ) += *right.entity(); }
225  return *this;
226  }
227  // ==========================================================================
229  std::string toString() const;
234  std::ostream& print( std::ostream& o = std::cout ) const;
239  std::ostream& fillStream( std::ostream& o ) const { return print( o ); }
240  // ==========================================================================
242  StatEntity* counter() const { return m_entity; }
244  const std::string& name() const { return m_tag; }
246  const std::string& group() const { return m_group; }
247  // ==========================================================================
248 private:
249  // underlying counter
250  StatEntity* m_entity = nullptr;
251  // unique stat tag(name)
253  // group
255  // Stat service
257 };
258 // ============================================================================
260 GAUDI_API Stat operator+( const Stat& stat, const double value );
261 // ============================================================================
263 GAUDI_API Stat operator-( const Stat& stat, const double value );
264 // ============================================================================
266 GAUDI_API Stat operator+( const double value, const Stat& stat );
267 // ============================================================================
269 GAUDI_API Stat operator+( const Stat& stat, const Stat& value );
270 // ============================================================================
273 // ============================================================================
274 
275 // ============================================================================
276 // The END
277 // ============================================================================
278 #endif // __GAUDI_CHRONOSTATSVC_STAT_H__
Stat::Stat
Stat(const Stat &)=default
copy constructor
Stat::fillStream
std::ostream & fillStream(std::ostream &o) const
printout to std::ostream
Definition: Stat.h:239
Write.stream
stream
Definition: Write.py:32
std::string
STL class.
Stat::operator++
Stat & operator++(int)
Post-increment operator for the counter.
Definition: Stat.h:194
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:161
Stat::entity
const StatEntity * entity() const
get the entity
Definition: Stat.h:137
operator<<
GAUDI_API std::ostream & operator<<(std::ostream &stream, const Stat &stat)
external printout operator to std::ostream
Definition: Stat.cpp:143
Stat::m_stat
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:256
IStatSvc
Definition: IStatSvc.h:35
Stat::name
const std::string & name() const
counter name
Definition: Stat.h:244
Stat::m_group
std::string m_group
Definition: Stat.h:254
SmartIF.h
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:252
std::ostream
STL class.
Stat::operator++
Stat & operator++()
Pre-increment operator for the counter.
Definition: Stat.h:178
Stat::operator--
Stat & operator--()
Pre-decrement operator for the flag.
Definition: Stat.h:208
Stat::Stat
Stat(StatEntity &entity, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:90
Stat::operator--
Stat & operator--(int)
Post-decrement operator for the flag.
Definition: Stat.h:213
Stat::operator+=
Stat & operator+=(const StatEntity &right)
increment with StatEntity object
Definition: Stat.h:218
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:74
IStatSvc.h
Stat
Definition: Stat.h:56
Stat::operator->
const StatEntity * operator->() const
dereference operaqtor
Definition: Stat.h:139
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:353
Gaudi::Utils::Histos::Formats::Stat
@ Stat
Definition: HistoTableFormat.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Stat::~Stat
~Stat()=default
destructor
Stat::group
const std::string & group() const
counter group
Definition: Stat.h:246
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:113
Stat::counter
StatEntity * counter() const
alternative access to underlying counter
Definition: Stat.h:242
Stat::operator!
bool operator!() const
check validity
Definition: Stat.h:143
Stat::operator-=
Stat & operator-=(const double f)
General decrement operator for the counter.
Definition: Stat.h:203
Stat::operator+=
Stat & operator+=(const Stat &right)
increment with other stat objects
Definition: Stat.h:223
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
operator-
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:121