| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# RndmGenSvc Class Reference

`#include <RndmGenSvc.h>`

Inheritance diagram for RndmGenSvc:

[legend]
Collaboration diagram for RndmGenSvc:

[legend]
List of all members.

## Detailed Description

Random Generator service definition.

Description: Definition of a interface for a service to access random generators according to predefined distributions. For more detailed explanations please see the interface definition.

Dependencies:

- Base class: Gaudi/RndmGenSvc/ISerialize.h
- Base class: Gaudi/RndmGenSvc/IRandomGenSvc.h

History :

        +---------+----------------------------------------------+--------+
        |    Date |                 Comment                      | Who    |
        +---------+----------------------------------------------+--------+
        | 21/04/99| Initial version.                             | MF     |
        +---------+----------------------------------------------+--------+

Author: M.Frank Version: 1.0

Definition at line 54 of file RndmGenSvc.h.

## Public Member Functions
| RndmGenSvc (const std::string &name, ISvcLocator *svc)
| Standard Service constructor.
virtual | ~RndmGenSvc ()
| Standard Service destructor.
StatusCode | queryInterface (const InterfaceID &riid, void **ppvInterface)
| Query interface.
virtual StatusCode | initialize ()
| Service override: initialisation.
virtual StatusCode | finalize ()
| Service override: finalisation.
virtual StreamBuffer & | serialize (StreamBuffer &str)
| Input serialisation from stream buffer. Restores the status of the generator engine.
virtual StreamBuffer & | serialize (StreamBuffer &str) const
| Output serialisation to stream buffer. Saves the status of the generator engine.
virtual IRndmEngine * | engine ()
| Retrieve engine.
virtual StatusCode | generator (const IRndmGen::Param &par, IRndmGen *&refpGen)
| Retrieve a valid generator from the service.
virtual double | rndm () const
| Single shot returning single random number.
virtual StatusCode | rndmArray (std::vector< double > &array, long howmany, long start=0) const
| Multiple shots returning vector with flat random numbers.
virtual StatusCode | setSeeds (const std::vector< long > &seeds)
| Allow to set new seeds.
virtual StatusCode | seeds (std::vector< long > &seeds) const
| Allow to get seeds.
## Private Attributes
IRndmEngine * | m_engine
| Random number engine.
ISerialize * | m_serialize
| Serialization interface of random number engine.
std::string | m_engineName
| Engine name.
## Friends
class | Factory< RndmGenSvc, IService *(std::string, ISvcLocator *)>

## Constructor & Destructor Documentation

RndmGenSvc::RndmGenSvc | ( | const std::string & | name,
|  | ISvcLocator * | svc |
| ) |  |  |

Standard Service constructor.

Definition at line 38 of file RndmGenSvc.cpp.

    00039 : Service(nam, svc), m_engine(0), m_serialize(0)
    00040 {
    00041   declareProperty("Engine", m_engineName = "HepRndm::Engine<CLHEP::RanluxEngine>");
    00042 }

RndmGenSvc::~RndmGenSvc | ( |  | ) | `[virtual]`

Standard Service destructor.

Definition at line 45 of file RndmGenSvc.cpp.

    00045                           {
    00046 }

## Member Function Documentation

StatusCode RndmGenSvc::queryInterface | ( | const InterfaceID & | riid,
|  | void ** | ppvInterface |
| ) |  |  | `[virtual]`

Query interface.

Reimplemented from Service.

Definition at line 49 of file RndmGenSvc.cpp.

References Service::addRef(), IID_IRndmEngine, IID_IRndmGenSvc, IID_ISerialize, Service::queryInterface(), and StatusCode::SUCCESS.

    00049                                                                                    {
    00050   if ( IID_IRndmGenSvc == riid )   {
    00051     *ppvInterface = (IRndmGenSvc*)this;
    00052   }
    00053   else if ( IID_IRndmEngine == riid )   {
    00054     *ppvInterface = (IRndmEngine*)this;
    00055   }
    00056   else if ( IID_ISerialize == riid )   {
    00057     *ppvInterface = (ISerialize*)this;
    00058   }
    00059   else  {
    00060     return Service::queryInterface(riid, ppvInterface);
    00061   }
    00062   addRef();
    00063   return StatusCode::SUCCESS;
    00064 }

StatusCode RndmGenSvc::initialize | ( |  | ) | `[virtual]`

Service override: initialisation.

Reimplemented from Service.

Definition at line 67 of file RndmGenSvc.cpp.

References IInterface::addRef(), endreq(), engine(), ISvcLocator::getService(), IID_IRndmEngine, IID_ISerialize, IID_IService, IID_ISvcManager, MSG::INFO, Service::initialize(), StatusCode::isSuccess(), SmartIFBase< TYPE >::isValid(), m_engine, m_engineName, m_serialize, Service::msgSvc(), Service::name(), Service::service(), Service::serviceLocator(), and Service::setProperties().

    00067                                     {
    00068   StatusCode status = Service::initialize();
    00069   MsgStream log(msgSvc(), name());
    00070   std::string machName = name()+".Engine";
    00071   SmartIF<IRndmEngine> engine(IID_IRndmEngine);
    00072   SmartIF<ISvcManager> mgr(IID_ISvcManager, serviceLocator());
    00073
    00074   if ( status.isSuccess() )   {
    00075     status = setProperties();
    00076     if ( status.isSuccess() )   {  // Check if the Engine service exists:
    00077       // FIXME: (MCl) why RndmGenSvc cannot create the engine service in a standard way?
    00078       status = serviceLocator()->getService(machName, IID_IRndmEngine, (IInterface*&)engine.pRef());
    00079       if ( !status.isSuccess() && mgr.isValid( ) )   {
    00080         IService* service = 0;
    00081         // Engine does not exist: We have to create one!
    00082         status = mgr->createService(m_engineName,machName,service);
    00083         if (status.isSuccess()) {
    00084           engine = service;
    00085           service->release();
    00086         }
    00087       }
    00088       if ( status.isSuccess() )   {
    00089         SmartIF<ISerialize> serial(IID_ISerialize, engine);
    00090         SmartIF<IService>   service(IID_IService,  engine);
    00091         if ( serial.isValid( ) && service.isValid( ) )  {
    00092           status = service->sysInitialize();
    00093           if ( status.isSuccess() )   {
    00094             m_engine = engine;
    00095             m_serialize = serial;
    00096             m_engine->addRef();
    00097             m_serialize->addRef();
    00098             log << MSG::INFO << "Using Random engine:" << m_engineName << endreq;
    00099             return status;
    00100           }
    00101         }
    00102       }
    00103     }
    00104   }
    00105   return status;
    00106 }

StatusCode RndmGenSvc::finalize | ( |  | ) | `[virtual]`

Service override: finalisation.

Reimplemented from Service.

Definition at line 109 of file RndmGenSvc.cpp.

References Service::finalize(), StatusCode::ignore(), IID_IService, m_engine, m_serialize, IInterface::release(), and Service::service().

    00109                                   {
    00110   StatusCode status = Service::finalize();
    00111   if ( m_serialize ) m_serialize->release();
    00112   m_serialize = 0;
    00113   if ( m_engine ) {
    00114     SmartIF<IService> service(IID_IService, m_engine);
    00115     service->finalize().ignore();
    00116     m_engine->release();
    00117   }
    00118   m_engine = 0;
    00119   return status;
    00120 }

StreamBuffer & RndmGenSvc::serialize | ( | StreamBuffer & | str | ) | `[virtual]`

Input serialisation from stream buffer. Restores the status of the generator engine.

Implements ISerialize.

Definition at line 124 of file RndmGenSvc.cpp.

References endreq(), MSG::ERROR, m_serialize, Service::msgSvc(), Service::name(), and ISerialize::serialize().

    00124                                                         {
    00125   if ( 0 != m_serialize )    {
    00126     return m_serialize->serialize(str);
    00127   }
    00128   MsgStream log(msgSvc(), name());
    00129   log << MSG::ERROR << "Cannot input serialize Generator settings!" << endreq;
    00130   return str;
    00131 }

StreamBuffer & RndmGenSvc::serialize | ( | StreamBuffer & | str | ) | const`[virtual]`

Output serialisation to stream buffer. Saves the status of the generator engine.

Implements ISerialize.

Definition at line 134 of file RndmGenSvc.cpp.

References endreq(), MSG::ERROR, m_serialize, Service::msgSvc(), Service::name(), and ISerialize::serialize().

    00134                                                               {
    00135   if ( 0 != m_serialize )    {
    00136     return m_serialize->serialize(str);
    00137   }
    00138   MsgStream log(msgSvc(), name());
    00139   log << MSG::ERROR << "Cannot output serialize Generator settings!" << endreq;
    00140   return str;
    00141 }

IRndmEngine * RndmGenSvc::engine | ( |  | ) | `[virtual]`

Retrieve engine.

Implements IRndmGenSvc.

Definition at line 144 of file RndmGenSvc.cpp.

References m_engine.

Referenced by initialize().

    00144                                     {
    00145   return m_engine;
    00146 }

StatusCode RndmGenSvc::generator | ( | const IRndmGen::Param & | par,
|  | IRndmGen *& | refpGen |
| ) |  |  | `[virtual]`

Retrieve a valid generator from the service.

Implements IRndmGenSvc.

Definition at line 149 of file RndmGenSvc.cpp.

References StatusCode::FAILURE, IID_IRndmGen, StatusCode::isSuccess(), m_engine, IInterface::queryInterface(), IInterface::release(), and IRndmGen::Param::type().

    00149                                                                                {
    00150   StatusCode status = StatusCode::FAILURE;
    00151   IInterface* iface = PluginService::CreateWithId<IInterface*>(par.type(),(IInterface*)m_engine);
    00152   if ( iface ) {
    00153     // query requested interface (adds ref count)
    00154     status = iface->queryInterface(IID_IRndmGen, (void**)& refpGen);
    00155     if ( status.isSuccess() )   {
    00156       status = refpGen->initialize(par);
    00157     }
    00158     else  {
    00159       iface->release();
    00160     }
    00161   }
    00162   // Error!
    00163   return status;
    00164 }

double RndmGenSvc::rndm | ( |  | ) | const`[virtual]`

Single shot returning single random number.

Implements IRndmEngine.

Definition at line 167 of file RndmGenSvc.cpp.

References m_engine, and IRndmEngine::rndm().

    00167                                 {
    00168   if ( 0 != m_engine )    {
    00169     return m_engine->rndm();
    00170   }
    00171   return -1;
    00172 }

StatusCode RndmGenSvc::rndmArray | ( | std::vector< double > & | array,
|  | long | howmany,
|  | long | start = `0` |
| ) |  |  | const`[virtual]`

Multiple shots returning vector with flat random numbers.

Parameters:

  | array | Array containing random numbers
  | howmany | fill 'howmany' random numbers into array
  | start | ... starting at position start

Returns:
  StatusCode indicating failure or success.

Implements IRndmEngine.

Definition at line 180 of file RndmGenSvc.cpp.

References StatusCode::FAILURE, m_engine, and IRndmEngine::rndmArray().

    00180                                                                                             {
    00181   if ( 0 != m_engine )    {
    00182     return m_engine->rndmArray(array, howmany, start);
    00183   }
    00184   return StatusCode::FAILURE;
    00185 }

StatusCode RndmGenSvc::setSeeds | ( | const std::vector< long > & | seeds | ) | `[virtual]`

Allow to set new seeds.

Implements IRndmEngine.

Definition at line 188 of file RndmGenSvc.cpp.

References StatusCode::FAILURE, m_engine, seeds(), and IRndmEngine::setSeeds().

    00188                                                               {
    00189   if ( 0 != m_engine )    {
    00190     return m_engine->setSeeds(seeds);
    00191   }
    00192   return StatusCode::FAILURE;
    00193 }

StatusCode RndmGenSvc::seeds | ( | std::vector< long > & | seeds | ) | const`[virtual]`

Allow to get seeds.

Implements IRndmEngine.

Definition at line 196 of file RndmGenSvc.cpp.

References StatusCode::FAILURE, m_engine, and IRndmEngine::seeds().

Referenced by setSeeds().

    00196                                                            {
    00197   if ( 0 != m_engine )    {
    00198     return m_engine->seeds(seeds);
    00199   }
    00200   return StatusCode::FAILURE;
    00201 }

## Friends And Related Function Documentation

friend class Factory< RndmGenSvc, IService *(std::string, ISvcLocator *)>`[friend]`

Definition at line 56 of file RndmGenSvc.h.

## Member Data Documentation

IRndmEngine* RndmGenSvc::m_engine`[mutable, private]`

Random number engine.

Definition at line 58 of file RndmGenSvc.h.

Referenced by engine(), finalize(), generator(), initialize(), rndm(), rndmArray(), seeds(), and setSeeds().

ISerialize* RndmGenSvc::m_serialize`[mutable, private]`

Serialization interface of random number engine.

Definition at line 60 of file RndmGenSvc.h.

Referenced by finalize(), initialize(), and serialize().

std::string RndmGenSvc::m_engineName`[private]`

Engine name.

Definition at line 62 of file RndmGenSvc.h.

Referenced by initialize().

The documentation for this class was generated from the following files:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiSvc/v17r1/src/RndmGenSvc/RndmGenSvc.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiSvc/v17r1/src/RndmGenSvc/RndmGenSvc.cpp