The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
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 <format>
15
#include <iostream>
16
23
24
Stat::Stat
(
IStatSvc
* svc,
const
std::string& tag ) :
m_tag
( tag ),
m_group
(),
m_stat
( svc ) {
25
if
(
m_stat
) {
26
// get from the service
27
StatEntity
* tmp =
m_stat
->stat( tag );
28
if
( !tmp ) {
29
// create if needed
30
m_stat
->stat( tag, 0 );
31
tmp =
m_stat
->stat( tag );
32
tmp->
reset
();
33
}
34
m_entity
= tmp;
35
}
36
}
37
38
Stat::Stat
(
IStatSvc
* svc,
const
std::string& tag,
const
double
flag ) :
m_tag
( tag ),
m_group
(),
m_stat
( svc ) {
39
if
(
m_stat
) {
40
m_stat
->stat( tag, flag );
41
// get from the service
42
m_entity
=
m_stat
->stat( tag );
43
}
44
}
45
46
std::string
Stat::toString
()
const
{
47
std::ostringstream ost;
48
print
( ost );
49
return
ost.str();
50
}
51
52
std::ostream&
Stat::print
( std::ostream& o )
const
{
53
auto
entity
= (
m_entity
) ?
m_entity
->toString() :
"NULL"
;
54
std::string tag;
55
if
( !
m_tag
.empty() ) {
56
if
( !
m_group
.empty() ) {
57
tag = std::format(
"\"{}::{}\""
,
m_group
,
m_tag
);
58
}
else
{
59
tag = std::format(
"\"{}\""
,
m_tag
);
60
}
61
}
62
return
o << std::format(
" {:^30} {}"
, tag,
entity
);
63
}
64
65
Stat
operator+
(
const
Stat
& stat,
const
double
value ) {
66
Stat
s( stat );
67
s += value;
68
return
s;
69
}
70
71
Stat
operator-
(
const
Stat
& stat,
const
double
value ) {
72
Stat
s( stat );
73
s -= value;
74
return
s;
75
}
76
77
Stat
operator+
(
const
double
value,
const
Stat
& stat ) {
78
Stat
s( stat );
79
s += value;
80
return
s;
81
}
82
83
Stat
operator+
(
const
Stat
& stat,
const
Stat
& value ) {
84
Stat
s( stat );
85
s += value;
86
return
s;
87
}
88
89
std::ostream&
operator<<
( std::ostream& stream,
const
Stat
& stat ) {
return
stat.
print
( stream ); }
IStatSvc.h
operator<<
std::ostream & operator<<(std::ostream &stream, const Stat &stat)
external printout operator to std::ostream
Definition
Stat.cpp:89
operator-
Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition
Stat.cpp:71
operator+
Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition
Stat.cpp:65
Stat.h
StatEntity.h
IStatSvc
"Stat"-related part of interface IChronoStatSvc
Definition
IStatSvc.h:25
StatEntity
backward compatible StatEntity class.
Definition
StatEntity.h:23
StatEntity::reset
friend void reset(StatEntity &s)
Definition
StatEntity.h:40
Stat
Small wrapper class for easy manipulation with generic counters and IStatSvc interface.
Definition
Stat.h:48
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition
Stat.h:240
Stat::Stat
Stat(StatEntity *entity=0, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition
Stat.h:66
Stat::toString
std::string toString() const
representation as string
Definition
Stat.cpp:46
Stat::entity
const StatEntity * entity() const
get the entity
Definition
Stat.h:128
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition
Stat.h:238
Stat::print
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition
Stat.cpp:52
Stat::m_stat
SmartIF< IStatSvc > m_stat
Stat service.
Definition
Stat.h:244
Stat::m_group
std::string m_group
Definition
Stat.h:242
GaudiKernel
src
Lib
Stat.cpp
Generated on
for The Gaudi Framework by
1.17.0