The Gaudi Framework  master (d98a2936)
HepRndmBaseEngine.h
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 //====================================================================
12 // CLHEP Basic Random Engine definition file
13 //--------------------------------------------------------------------
14 //
15 // Package : HepRndm ( The LHCb Offline System)
16 // Author : M.Frank
17 // History :
18 // +---------+----------------------------------------------+---------
19 // | Date | Comment | Who
20 // +---------+----------------------------------------------+---------
21 // | 29/10/99| Initial version | MF
22 // +---------+----------------------------------------------+---------
23 //
24 //====================================================================
25 #pragma once
26 
27 // Framework include files
28 #include "RndmEngine.h"
29 #include <CLHEP/Random/Random.h>
30 
31 // Forward declarations
32 namespace CLHEP {
33  class HepRandomEngine;
34 }
35 
36 namespace HepRndm {
37 
38  class BaseEngine : public RndmEngine {
39  protected:
40  std::unique_ptr<CLHEP::HepRandomEngine> m_hepEngine;
41 
42  public:
43  BaseEngine( const std::string& name, ISvcLocator* loc ) : RndmEngine( name, loc ) {}
44  CLHEP::HepRandomEngine* hepEngine() { return m_hepEngine.get(); }
45  const CLHEP::HepRandomEngine* hepEngine() const { return m_hepEngine.get(); }
46  // Retrieve single random number
47  double rndm() const override { return m_hepEngine->flat(); }
48 
49  StatusCode finalize() override {
50  if ( m_hepEngine ) CLHEP::HepRandom::setTheEngine( nullptr );
51  m_hepEngine.reset();
52  return RndmEngine::finalize();
53  }
54 
55  protected:
57  virtual std::unique_ptr<CLHEP::HepRandomEngine> createEngine() = 0;
58  };
59 } // namespace HepRndm
HepRndm::BaseEngine::hepEngine
CLHEP::HepRandomEngine * hepEngine()
Definition: HepRndmBaseEngine.h:44
ISvcLocator
Definition: ISvcLocator.h:42
HepRndm::BaseEngine::createEngine
virtual std::unique_ptr< CLHEP::HepRandomEngine > createEngine()=0
HepRndm::BaseEngine::initEngine
void initEngine()
Definition: HepRndmBaseEngine.h:56
HepRndm::BaseEngine
Definition: HepRndmBaseEngine.h:38
HepRndm::BaseEngine::finalize
StatusCode finalize() override
Definition: HepRndmBaseEngine.h:49
HepRndm::BaseEngine::hepEngine
const CLHEP::HepRandomEngine * hepEngine() const
Definition: HepRndmBaseEngine.h:45
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:223
HepRndm::BaseEngine::m_hepEngine
std::unique_ptr< CLHEP::HepRandomEngine > m_hepEngine
Definition: HepRndmBaseEngine.h:40
HepRndm
Definition: HepRndmBaseEngine.h:36
RndmEngine.h
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:333
StatusCode
Definition: StatusCode.h:64
HepRndm::BaseEngine::rndm
double rndm() const override
Definition: HepRndmBaseEngine.h:47
CLHEP
Definition: HepRndmBaseEngine.h:32
HepRndm::BaseEngine::BaseEngine
BaseEngine(const std::string &name, ISvcLocator *loc)
Definition: HepRndmBaseEngine.h:43
RndmEngine
Random Generator engine definition.
Definition: RndmEngine.h:51