The Gaudi Framework  v30r3 (a5ef0a68)
HepRndmGenerator.h
Go to the documentation of this file.
1 //====================================================================
2 // CLHEP Random Generator definition file
3 //--------------------------------------------------------------------
4 //
5 // Package : HepRndm ( The LHCb Offline System)
6 // Author : M.Frank
7 // History :
8 // +---------+----------------------------------------------+---------
9 // | Date | Comment | Who
10 // +---------+----------------------------------------------+---------
11 // | 29/10/99| Initial version | MF
12 // +---------+----------------------------------------------+---------
13 //
14 //====================================================================
15 #ifndef HEPRNDM_HEPRNDMGENERATOR_H
16 #define HEPRNDM_HEPRNDMGENERATOR_H 1
17 
18 // Framework include files
19 #include "RndmGen.h"
20 #include "RndmGenSvc.h"
21 
22 #include "HepRndmBaseEngine.h"
23 
24 namespace HepRndm
25 {
26 
27  template <class TYPE>
28  class Generator : public RndmGen
29  {
30  public:
31  typedef TYPE Parameters;
32 
33  protected:
34  CLHEP::HepRandomEngine* m_hepEngine = nullptr;
35  TYPE* m_specs = nullptr;
36 
37  public:
38  Generator( IInterface* engine ) : RndmGen( engine ) {}
40  StatusCode initialize( const IRndmGen::Param& par ) override;
42  double shoot() const override;
43  };
44 
46  template <class TYPE>
48  {
49  StatusCode status = RndmGen::initialize( par );
50  if ( status.isSuccess() ) {
51  try {
52  m_specs = dynamic_cast<TYPE*>( m_params.get() );
53  if ( m_specs ) {
54  BaseEngine* engine = dynamic_cast<BaseEngine*>( m_engine.get() );
55  if ( engine ) {
56  m_hepEngine = engine->hepEngine();
57  if ( m_hepEngine ) {
58  return StatusCode::SUCCESS;
59  }
60  }
61  }
62  } catch ( ... ) {
63  }
64  }
65  return StatusCode::FAILURE;
66  }
67 }
68 
69 #endif // HEPRNDM_HEPRNDMGENERATOR_H
constexpr static const auto FAILURE
Definition: StatusCode.h:88
bool isSuccess() const
Definition: StatusCode.h:287
Generator(IInterface *engine)
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:82
SmartIF< IRndmEngine > m_engine
Hosting service: Access must always be possible.
Definition: RndmGen.h:48
StatusCode initialize(const IRndmGen::Param &par) override
Initialize the generator.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
Definition of the basic interface.
Definition: IInterface.h:277
StatusCode initialize(const IRndmGen::Param &par) override
IRndmGen implementation.
Definition: RndmGen.cpp:26
Random Generator definition.
Definition: RndmGen.h:41
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
T get(T...args)
std::unique_ptr< IRndmGen::Param > m_params
Generation parameters.
Definition: RndmGen.h:46
double shoot() const override
Single shot.
CLHEP::HepRandomEngine * m_hepEngine
CLHEP::HepRandomEngine * hepEngine()