Gaudi Framework, version v25r0

Home   Generated: Mon Feb 17 2014
 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"
25 
26 #include "GaudiKernel/MsgStream.h"
27 
28 #include "RndmGen.h"
29 #include "RndmGenSvc.h"
30 
31 // Instantiation of a static factory class used by clients to create
32 // instances of this service
34 
35 
36 RndmGenSvc::RndmGenSvc(const std::string& nam, ISvcLocator* svc)
37 : base_class(nam, svc), m_engine(0), m_serialize(0)
38 {
39  declareProperty("Engine", m_engineName = "HepRndm::Engine<CLHEP::RanluxEngine>");
40 }
41 
44 }
45 
49  MsgStream log(msgSvc(), name());
50  std::string machName = name()+".Engine";
53 
54  if ( status.isSuccess() ) {
55  status = setProperties();
56  if ( status.isSuccess() ) { // Check if the Engine service exists:
57  // FIXME: (MCl) why RndmGenSvc cannot create the engine service in a standard way?
58  const bool CREATE = false;
59  engine = serviceLocator()->service(machName, CREATE);
60  if ( !engine.isValid() && mgr.isValid() ) {
61  using Gaudi::Utils::TypeNameString;
62  engine = mgr->createService(TypeNameString(machName, m_engineName));
63  }
64  if ( engine.isValid() ) {
65  SmartIF<ISerialize> serial(engine);
66  SmartIF<IService> service(engine);
67  if ( serial.isValid( ) && service.isValid( ) ) {
68  status = service->sysInitialize();
69  if ( status.isSuccess() ) {
70  m_engine = engine;
71  m_serialize = serial;
72  m_engine->addRef();
74  log << MSG::INFO << "Using Random engine:" << m_engineName << endmsg;
75  return status;
76  }
77  }
78  }
79  }
80  }
81  return status;
82 }
83 
86  StatusCode status = Service::finalize();
88  m_serialize = 0;
89  if ( m_engine ) {
91  service->finalize().ignore();
92  m_engine->release();
93  }
94  m_engine = 0;
95  return status;
96 }
97 
99 
101  if ( 0 != m_serialize ) {
102  return m_serialize->serialize(str);
103  }
104  MsgStream log(msgSvc(), name());
105  log << MSG::ERROR << "Cannot input serialize Generator settings!" << endmsg;
106  return str;
107 }
108 
111  if ( 0 != m_serialize ) {
112  return m_serialize->serialize(str);
113  }
114  MsgStream log(msgSvc(), name());
115  log << MSG::ERROR << "Cannot output serialize Generator settings!" << endmsg;
116  return str;
117 }
118 
121  return m_engine;
122 }
123 
127  IInterface* iface = ObjFactory::create(par.type(),(IInterface*)m_engine);
128  if ( iface ) {
129  // query requested interface (adds ref count)
130  status = iface->queryInterface(IRndmGen::interfaceID(), (void**)& refpGen);
131  if ( status.isSuccess() ) {
132  status = refpGen->initialize(par);
133  }
134  else {
135  iface->release();
136  }
137  }
138  // Error!
139  return status;
140 }
141 
142 // Single shot returning single random number
143 double RndmGenSvc::rndm() const {
144  if ( 0 != m_engine ) {
145  return m_engine->rndm();
146  }
147  return -1;
148 }
149 
150 /* Multiple shots returning vector with flat random numbers.
151  @param array Array containing random numbers
152  @param howmany fill 'howmany' random numbers into array
153  @param start ... starting at position start
154  @return StatusCode indicating failure or success.
155 */
157  if ( 0 != m_engine ) {
158  return m_engine->rndmArray(array, howmany, start);
159  }
160  return StatusCode::FAILURE;
161 }
162 
163 // Allow to set new seeds
165  if ( 0 != m_engine ) {
166  return m_engine->setSeeds(seeds);
167  }
168  return StatusCode::FAILURE;
169 }
170 
171 // Allow to get the seeds
173  if ( 0 != m_engine ) {
174  return m_engine->seeds(seeds);
175  }
176  return StatusCode::FAILURE;
177 }
178 

Generated at Mon Feb 17 2014 14:37:48 for Gaudi Framework, version v25r0 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004