The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
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// ============================================================================
21#include <fmt/format.h>
22// ============================================================================
28// ============================================================================
29namespace Gaudi {
30 namespace TestSuite {
38 class HistoProps : public ::Algorithm {
39 public:
41
43 return Algorithm::initialize().andThen( [&] {
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
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
75 std::unique_ptr<Gaudi::Accumulators::StaticHistogram<1>> m_hist1;
76 std::unique_ptr<Gaudi::Accumulators::StaticHistogram<1>> m_hist2;
77 };
78 } // namespace TestSuite
79} // end of namespace Gaudi
80
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
Definition of a default type of Histogram Axis It contains number of bins, min and max value plus a t...
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition Algorithm.h:98
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition Algorithm.h:175
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition Algorithm.h:181
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
const std::string & name() const override
The identifying name of the algorithm object.
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
Definition HistoDef.h:30
Implementation of property with value of concrete type.
Definition PropertyFwd.h:27
simple example, which illustrates the usage of "histogram properties" DO NOT USE.
std::unique_ptr< Gaudi::Accumulators::StaticHistogram< 1 > > m_hist1
StatusCode finalize() override
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition Algorithm.h:98
StatusCode initialize() override
StatusCode execute() override
std::unique_ptr< Gaudi::Accumulators::StaticHistogram< 1 > > m_hist2
Gaudi::Property< Gaudi::Histo1DDef > m_hist2def
Gaudi::Property< Gaudi::Histo1DDef > m_hist1def
Parameters for the Gauss random number generation.
Random number accessor This small class encapsulates the use of the random number generator.
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
Definition StatusCode.h:163
constexpr static const auto SUCCESS
Definition StatusCode.h:99
HistogramingCounterBase< ND, Atomicity, Arithmetic, naming::histogramString, HistogramingAccumulator, AxisTupleType > StaticHistogram
standard static histograming counter. See HistogramingCounterBase for details
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1