The Gaudi Framework  master (37c0b60a)
HistoProps.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 // GaudiKernel
15 // ============================================================================
18 // ============================================================================
20 #include <GaudiKernel/Algorithm.h>
21 #include <fmt/format.h>
22 // ============================================================================
28 // ============================================================================
29 namespace Gaudi {
30  namespace TestSuite {
38  class HistoProps : public ::Algorithm {
39  public:
41 
42  StatusCode initialize() override {
43  return Algorithm::initialize().andThen( [&] {
45  using axis_t = Gaudi::Accumulators::Axis<double>;
46  m_hist1 = std::make_unique<hist_t>( this, "Histo1", "Histogram 1", axis_t{ m_hist1def.value() } );
47  m_hist2 = std::make_unique<hist_t>( this, "Histo2", "Histogram 2", axis_t( m_hist2def.value() ) );
48  } );
49  }
50  StatusCode execute() override {
51  Rndm::Numbers gauss( randSvc(), Rndm::Gauss( 0.0, 1.0 ) );
52 
53  ++( *m_hist1 )[gauss()];
54  ++( *m_hist2 )[gauss()];
55 
56  return StatusCode::SUCCESS;
57  }
58  StatusCode finalize() override {
59  auto format = []( std::string_view name, const nlohmann::json& data ) {
60  return fmt::format( " | {:25} | {:25} | {:7} |", name, data["axis"][0]["title"].get<std::string>(),
61  data["nEntries"].get<unsigned long long>() );
62  };
63  always() << fmt::format( "Histograms report\n | {:25} | {:25} | {:7} |\n", "name", "title", "entries" )
64  << format( "Histo1", *m_hist1 ) << '\n'
65  << format( "Histo2", *m_hist2 ) << endmsg;
66  return Algorithm::finalize();
67  }
68  // ======================================================================
69  private:
70  Gaudi::Property<Gaudi::Histo1DDef> m_hist1def{ this, "Histo1", Gaudi::Histo1DDef( "Histogram1", -3, 3, 200 ),
71  "The parameters for the first histogram" };
73  this, "Histo2", { "Histogram2", -5, 5, 200 }, "The parameters for the second histogram" };
74 
77  };
78  } // namespace TestSuite
79 } // end of namespace Gaudi
80 
Gaudi::TestSuite::HistoProps::m_hist2
std::unique_ptr< Gaudi::Accumulators::StaticHistogram< 1 > > m_hist2
Definition: HistoProps.cpp:76
Gaudi::TestSuite::HistoProps::m_hist2def
Gaudi::Property< Gaudi::Histo1DDef > m_hist2def
Definition: HistoProps.cpp:72
RndmGenerators.h
Gaudi::Algorithm::randSvc
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
Definition: Algorithm.cpp:563
StatusCode::andThen
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition: StatusCode.h:163
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:526
TestSuite
#define TestSuite
Definition: MakeAndConsume.cpp:658
Gaudi::Accumulators::HistogramingCounterBase
A base counter dealing with Histograms.
Definition: StaticHistogram.h:653
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:178
jsonFromLHCbLog.json
json
Definition: jsonFromLHCbLog.py:86
IRndmGenSvc.h
Algorithm.h
Gaudi::TestSuite::HistoProps::finalize
StatusCode finalize() override
Definition: HistoProps.cpp:58
Gaudi::TestSuite::HistoProps
Definition: HistoProps.cpp:38
Gaudi::TestSuite::HistoProps::initialize
StatusCode initialize() override
Definition: HistoProps.cpp:42
Gaudi::Histo1DDef
Definition: HistoDef.h:41
StatusCode
Definition: StatusCode.h:65
Rndm::Gauss
Parameters for the Gauss random number generation.
Definition: RndmGenerators.h:32
Rndm::Numbers
Random number accessor This small class encapsulates the use of the random number generator.
Definition: RndmGenerators.h:359
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:90
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:237
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
Gaudi::TestSuite::HistoProps::execute
StatusCode execute() override
Definition: HistoProps.cpp:50
Gaudi::TestSuite::HistoProps::m_hist1def
Gaudi::Property< Gaudi::Histo1DDef > m_hist1def
Definition: HistoProps.cpp:70
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:184
Gaudi::Units::gauss
constexpr double gauss
Definition: SystemOfUnits.h:252
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Algorithm::Algorithm
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition: Algorithm.h:101
std::unique_ptr
STL class.
Gaudi::TestSuite::HistoProps::m_hist1
std::unique_ptr< Gaudi::Accumulators::StaticHistogram< 1 > > m_hist1
Definition: HistoProps.cpp:75
Gaudi::Accumulators::Axis
Definition of a default type of Histogram Axis It contains number of bins, min and max value plus a t...
Definition: StaticHistogram.h:229
Gaudi::Property< Gaudi::Histo1DDef >
StaticHistogram.h