Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r0 (2143aa4c)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HistoProps.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 // ============================================================================
19 // GaudiAlg
20 // ============================================================================
22 #include "GaudiKernel/Algorithm.h"
23 #include <fmt/format.h>
24 // ============================================================================
30 // ============================================================================
31 namespace Gaudi {
32  namespace Examples {
38  class HistoProps : public ::Algorithm {
39  public:
41 
42  StatusCode initialize() override {
43  return Algorithm::initialize().andThen( [&] {
44  ;
45  using hist_t = Gaudi::Accumulators::Histogram<1>;
46  using axis_t = hist_t::AccumulatorType::AxisType;
47  m_hist1 = std::make_unique<hist_t>( this, "Histo1", "Histogram 1", axis_t{ m_hist1def.value() } );
48  m_hist2 = std::make_unique<hist_t>( this, "Histo2", "Histogram 2", axis_t( m_hist2def.value() ) );
49  } );
50  }
51  StatusCode execute() override {
52  Rndm::Numbers gauss( randSvc(), Rndm::Gauss( 0.0, 1.0 ) );
53 
54  ++( *m_hist1 )[gauss()];
55  ++( *m_hist2 )[gauss()];
56 
57  return StatusCode::SUCCESS;
58  }
59  StatusCode finalize() override {
60  auto format = []( std::string_view name, const nlohmann::json& data ) {
61  return fmt::format( " | {:25} | {:25} | {:7} |", name, data["axis"][0]["title"].get<std::string>(),
62  data["nEntries"].get<unsigned long long>() );
63  };
64  always() << fmt::format( "Histograms report\n | {:25} | {:25} | {:7} |\n", "name", "title", "entries" )
65  << format( "Histo1", *m_hist1 ) << '\n'
66  << format( "Histo2", *m_hist2 ) << endmsg;
67  return Algorithm::finalize();
68  }
69  // ======================================================================
70  private:
71  Gaudi::Property<Gaudi::Histo1DDef> m_hist1def{ this, "Histo1", Gaudi::Histo1DDef( "Histogram1", -3, 3, 200 ),
72  "The parameters for the first histogram" };
74  this, "Histo2", { "Histogram2", -5, 5, 200 }, "The parameters for the second histogram" };
75 
78  };
79  } // namespace Examples
80 } // end of namespace Gaudi
81 
RndmGenerators.h
Gaudi::Algorithm::randSvc
SmartIF< IRndmGenSvc > & randSvc() const
The standard RandomGen service, Return a pointer to the service if present.
Definition: Algorithm.cpp:565
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:528
Histogram.h
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::Examples::HistoProps::m_hist1
std::unique_ptr< Gaudi::Accumulators::Histogram< 1 > > m_hist1
Definition: HistoProps.cpp:76
Gaudi::Examples::HistoProps::finalize
StatusCode finalize() override
Definition: HistoProps.cpp:59
Gaudi::Histo1DDef
Definition: HistoDef.h:41
Gaudi::Examples::HistoProps::m_hist2
std::unique_ptr< Gaudi::Accumulators::Histogram< 1 > > m_hist2
Definition: HistoProps.cpp:77
Gaudi::Examples::HistoProps::execute
StatusCode execute() override
Definition: HistoProps.cpp:51
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::Examples::HistoProps::m_hist2def
Gaudi::Property< Gaudi::Histo1DDef > m_hist2def
Definition: HistoProps.cpp:73
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:239
Gaudi::Examples::HistoProps::m_hist1def
Gaudi::Property< Gaudi::Histo1DDef > m_hist1def
Definition: HistoProps.cpp:71
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:203
Gaudi
Header file for std:chrono::duration-based Counters.
Definition: __init__.py:1
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
Gaudi::Examples::HistoProps::initialize
StatusCode initialize() override
Definition: HistoProps.cpp:42
Gaudi::Examples::HistoProps
Definition: HistoProps.cpp:38
Gaudi::Accumulators::HistogramingCounterBaseInternal
A base counter dealing with Histograms.
Definition: Histogram.h:464
std::unique_ptr
STL class.
Gaudi::Property< Gaudi::Histo1DDef >