Gaudi Framework, version v23r9

Home   Generated: Thu Jul 18 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RndmGenSvc.cpp
Go to the documentation of this file.
1 //====================================================================
2 // Random Generator service implementation
3 //--------------------------------------------------------------------
4 //
5 // Package : Gaudi/RndmGen ( 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 #define GAUDI_RANDOMGENSVC_RNDMGENSVC_CPP
16 
17 // STL include files
18 #include <cfloat>
19 
20 // Framework include files
21 #include "GaudiKernel/SmartIF.h"
22 #include "GaudiKernel/SvcFactory.h"
25 
26 #include "GaudiKernel/MsgStream.h"
27 
28 #include "RndmGen.h"
29 #include "RndmGenSvc.h"
30 
31 using ROOT::Reflex::PluginService;
32 
33 // Instantiation of a static factory class used by clients to create
34 // instances of this service
36 
37 
38 RndmGenSvc::RndmGenSvc(const std::string& nam, ISvcLocator* svc)
39 : base_class(nam, svc), m_engine(0), m_serialize(0)
40 {
41  declareProperty("Engine", m_engineName = "HepRndm::Engine<CLHEP::RanluxEngine>");
42 }
43 
46 }
47 
51  MsgStream log(msgSvc(), name());
52  std::string machName = name()+".Engine";
55 
56  if ( status.isSuccess() ) {
57  status = setProperties();
58  if ( status.isSuccess() ) { // Check if the Engine service exists:
59  // FIXME: (MCl) why RndmGenSvc cannot create the engine service in a standard way?
60  const bool CREATE = false;
61  engine = serviceLocator()->service(machName, CREATE);
62  if ( !engine.isValid() && mgr.isValid() ) {
63  using Gaudi::Utils::TypeNameString;
64  engine = mgr->createService(TypeNameString(machName, m_engineName));
65  }
66  if ( engine.isValid() ) {
67  SmartIF<ISerialize> serial(engine);
68  SmartIF<IService> service(engine);
69  if ( serial.isValid( ) && service.isValid( ) ) {
70  status = service->sysInitialize();
71  if ( status.isSuccess() ) {
72  m_engine = engine;
73  m_serialize = serial;
74  m_engine->addRef();
76  log << MSG::INFO << "Using Random engine:" << m_engineName << endmsg;
77  return status;
78  }
79  }
80  }
81  }
82  }
83  return status;
84 }
85 
88  StatusCode status = Service::finalize();
90  m_serialize = 0;
91  if ( m_engine ) {
93  service->finalize().ignore();
94  m_engine->release();
95  }
96  m_engine = 0;
97  return status;
98 }
99 
101 
103  if ( 0 != m_serialize ) {
104  return m_serialize->serialize(str);
105  }
106  MsgStream log(msgSvc(), name());
107  log << MSG::ERROR << "Cannot input serialize Generator settings!" << endmsg;
108  return str;
109 }
110 
113  if ( 0 != m_serialize ) {
114  return m_serialize->serialize(str);
115  }
116  MsgStream log(msgSvc(), name());
117  log << MSG::ERROR << "Cannot output serialize Generator settings!" << endmsg;
118  return str;
119 }
120 
123  return m_engine;
124 }
125 
129  IInterface* iface = PluginService::CreateWithId<IInterface*>(par.type(),(IInterface*)m_engine);
130  if ( iface ) {
131  // query requested interface (adds ref count)
132  status = iface->queryInterface(IRndmGen::interfaceID(), (void**)& refpGen);
133  if ( status.isSuccess() ) {
134  status = refpGen->initialize(par);
135  }
136  else {
137  iface->release();
138  }
139  }
140  // Error!
141  return status;
142 }
143 
144 // Single shot returning single random number
145 double RndmGenSvc::rndm() const {
146  if ( 0 != m_engine ) {
147  return m_engine->rndm();
148  }
149  return -1;
150 }
151 
152 /* Multiple shots returning vector with flat random numbers.
153  @param array Array containing random numbers
154  @param howmany fill 'howmany' random numbers into array
155  @param start ... starting at position start
156  @return StatusCode indicating failure or success.
157 */
158 StatusCode RndmGenSvc::rndmArray( std::vector<double>& array, long howmany, long start) const {
159  if ( 0 != m_engine ) {
160  return m_engine->rndmArray(array, howmany, start);
161  }
162  return StatusCode::FAILURE;
163 }
164 
165 // Allow to set new seeds
167  if ( 0 != m_engine ) {
168  return m_engine->setSeeds(seeds);
169  }
170  return StatusCode::FAILURE;
171 }
172 
173 // Allow to get the seeds
175  if ( 0 != m_engine ) {
176  return m_engine->seeds(seeds);
177  }
178  return StatusCode::FAILURE;
179 }
180 

Generated at Thu Jul 18 2013 12:18:05 for Gaudi Framework, version v23r9 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004