| # Gaudi Framework, version v21r7 |

Home |  | Generated: 22 Jan 2010

# RndmGenSvc Class Reference

Random Generator service definition. More...

`#include <RndmGenSvc.h>`

Inheritance diagram for RndmGenSvc:

[legend]
Collaboration diagram for RndmGenSvc:

[legend]

List of all members.

## Public Member Functions
| RndmGenSvc (const std::string &name, ISvcLocator *svc)
| Standard Service constructor.
virtual | ~RndmGenSvc ()
| Standard Service destructor.
virtual StatusCode | initialize ()
| Service override: initialization.
virtual StatusCode | finalize ()
| Service override: finalization.
virtual StreamBuffer & | serialize (StreamBuffer &str)
| IRndmGenSvc interface implementation.
virtual StreamBuffer & | serialize (StreamBuffer &str) const
| Output serialization 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 *)>

## 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.

## Constructor & Destructor Documentation

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

Standard Service constructor.

Definition at line 38 of file RndmGenSvc.cpp.

    00039 : base_class(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::initialize | ( |  | ) | `[virtual]`

Service override: initialization.

Reimplemented from Service.

Definition at line 49 of file RndmGenSvc.cpp.

    00049                                     {
    00050   StatusCode status = Service::initialize();
    00051   MsgStream log(msgSvc(), name());
    00052   std::string machName = name()+".Engine";
    00053   SmartIF<IRndmEngine> engine;
    00054   SmartIF<ISvcManager> mgr(serviceLocator());
    00055
    00056   if ( status.isSuccess() )   {
    00057     status = setProperties();
    00058     if ( status.isSuccess() )   {  // Check if the Engine service exists:
    00059       // FIXME: (MCl) why RndmGenSvc cannot create the engine service in a standard way?
    00060       const bool CREATE = false;
    00061       engine = serviceLocator()->service(machName, CREATE);
    00062       if ( !engine.isValid() && mgr.isValid() )   {
    00063         using Gaudi::Utils::TypeNameString;
    00064         engine = mgr->createService(TypeNameString(machName, m_engineName));
    00065       }
    00066       if ( engine.isValid() )   {
    00067         SmartIF<ISerialize> serial(engine);
    00068         SmartIF<IService>   service(engine);
    00069         if ( serial.isValid( ) && service.isValid( ) )  {
    00070           status = service->sysInitialize();
    00071           if ( status.isSuccess() )   {
    00072             m_engine = engine;
    00073             m_serialize = serial;
    00074             m_engine->addRef();
    00075             m_serialize->addRef();
    00076             log << MSG::INFO << "Using Random engine:" << m_engineName << endmsg;
    00077             return status;
    00078           }
    00079         }
    00080       }
    00081     }
    00082   }
    00083   return status;
    00084 }

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

Service override: finalization.

Reimplemented from Service.

Definition at line 87 of file RndmGenSvc.cpp.

    00087                                   {
    00088   StatusCode status = Service::finalize();
    00089   if ( m_serialize ) m_serialize->release();
    00090   m_serialize = 0;
    00091   if ( m_engine ) {
    00092     SmartIF<IService> service(m_engine);
    00093     service->finalize().ignore();
    00094     m_engine->release();
    00095   }
    00096   m_engine = 0;
    00097   return status;
    00098 }

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

IRndmGenSvc interface implementation.

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

Definition at line 102 of file RndmGenSvc.cpp.

    00102                                                         {
    00103   if ( 0 != m_serialize )    {
    00104     return m_serialize->serialize(str);
    00105   }
    00106   MsgStream log(msgSvc(), name());
    00107   log << MSG::ERROR << "Cannot input serialize Generator settings!" << endmsg;
    00108   return str;
    00109 }

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

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

Definition at line 112 of file RndmGenSvc.cpp.

    00112                                                               {
    00113   if ( 0 != m_serialize )    {
    00114     return m_serialize->serialize(str);
    00115   }
    00116   MsgStream log(msgSvc(), name());
    00117   log << MSG::ERROR << "Cannot output serialize Generator settings!" << endmsg;
    00118   return str;
    00119 }

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

Retrieve engine.

Definition at line 122 of file RndmGenSvc.cpp.

    00122                                     {
    00123   return m_engine;
    00124 }

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

Retrieve a valid generator from the service.

Definition at line 127 of file RndmGenSvc.cpp.

    00127                                                                                {
    00128   StatusCode status = StatusCode::FAILURE;
    00129   IInterface* iface = PluginService::CreateWithId<IInterface*>(par.type(),(IInterface*)m_engine);
    00130   if ( iface ) {
    00131     // query requested interface (adds ref count)
    00132     status = iface->queryInterface(IRndmGen::interfaceID(), (void**)& refpGen);
    00133     if ( status.isSuccess() )   {
    00134       status = refpGen->initialize(par);
    00135     }
    00136     else  {
    00137       iface->release();
    00138     }
    00139   }
    00140   // Error!
    00141   return status;
    00142 }

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

Single shot returning single random number.

Definition at line 145 of file RndmGenSvc.cpp.

    00145                                 {
    00146   if ( 0 != m_engine )    {
    00147     return m_engine->rndm();
    00148   }
    00149   return -1;
    00150 }

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.

Definition at line 158 of file RndmGenSvc.cpp.

    00158                                                                                             {
    00159   if ( 0 != m_engine )    {
    00160     return m_engine->rndmArray(array, howmany, start);
    00161   }
    00162   return StatusCode::FAILURE;
    00163 }

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

Allow to set new seeds.

Definition at line 166 of file RndmGenSvc.cpp.

    00166                                                               {
    00167   if ( 0 != m_engine )    {
    00168     return m_engine->setSeeds(seeds);
    00169   }
    00170   return StatusCode::FAILURE;
    00171 }

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

Allow to get seeds.

Definition at line 174 of file RndmGenSvc.cpp.

    00174                                                            {
    00175   if ( 0 != m_engine )    {
    00176     return m_engine->seeds(seeds);
    00177   }
    00178   return StatusCode::FAILURE;
    00179 }

## 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.

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

Serialization interface of random number engine.

Definition at line 60 of file RndmGenSvc.h.

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

Engine name.

Definition at line 62 of file RndmGenSvc.h.

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

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