The Gaudi Framework  master (37c0b60a)
StatSvcAlg.cpp
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 // ============================================================================
12 // Include files
13 // ============================================================================
14 // STD & STL
15 // ============================================================================
16 #include <cmath>
17 // ============================================================================
18 // GaudiKernel
19 // ============================================================================
20 #include <GaudiKernel/IStatSvc.h>
21 #include <GaudiKernel/Stat.h>
22 
23 #include <GaudiKernel/Algorithm.h>
24 // ============================================================================
36 // ============================================================================
37 namespace GaudiTestSuite {
48  class StatSvcAlg : public Algorithm {
49  public:
52 
54  StatusCode initialize() override {
56  if ( sc.isFailure() ) return sc; // RETURN
57  m_stat = service( "ChronoStatSvc", true );
58  return StatusCode::SUCCESS;
59  }
61  StatusCode execute() override;
62 
63  private:
64  // pointer to Stat Service
66  };
67 } // end of namespace GaudiTestSuite
68 // ============================================================================
69 // the main execution method
70 // ============================================================================
72  Stat st1( m_stat, "counter1" );
73  Stat st2( m_stat, "counter2" );
74  Stat st3( m_stat, "counter3", 0.3 );
75 
76  Stat eff( m_stat, "eff", 0 < sin( 10 * st1->flag() ) );
77  //
78  st1 += 0.1;
79  st1 -= 0.1000452;
80  st2 += st1;
81  ++st3;
82  st2--;
83 
84  eff += 0 < cos( 20 * st2->flag() );
85 
86  //
87  return StatusCode::SUCCESS;
88 }
89 // ============================================================================
90 // Factory:
91 // ============================================================================
94 // ============================================================================
95 // The END
96 // ============================================================================
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:178
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:58
Algorithm.h
StatEntity::flag
double flag() const
Definition: StatEntity.h:96
StatusCode
Definition: StatusCode.h:65
GaudiTestSuite::StatSvcAlg
Definition: StatSvcAlg.cpp:48
GaudiTestSuite::StatSvcAlg::execute
StatusCode execute() override
the main execution method
Definition: StatSvcAlg.cpp:71
SmartIF< IStatSvc >
IStatSvc.h
Stat.h
Stat
Definition: Stat.h:56
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Algorithm::service
StatusCode service(std::string_view name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Algorithm.h:206
Gaudi::Algorithm::Algorithm
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition: Algorithm.h:101
GaudiTestSuite::StatSvcAlg::initialize
StatusCode initialize() override
initialize the algorithm
Definition: StatSvcAlg.cpp:54
GaudiTestSuite
Definition: LoggingAuditor.cpp:22
GaudiTestSuite::StatSvcAlg::m_stat
SmartIF< IStatSvc > m_stat
pointer to Stat Service
Definition: StatSvcAlg.cpp:65