| # Gaudi Framework, version v23r0 |

Home |  | Generated: Mon Jan 30 2012

Public Member Functions | Private Attributes | Friends

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

    : base_class(nam, svc), m_engine(0), m_serialize(0)
    {
      declareProperty("Engine", m_engineName = "HepRndm::Engine<CLHEP::RanluxEngine>");
    }

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

Standard Service destructor.

Definition at line 45 of file RndmGenSvc.cpp.

                              {
    }

## Member Function Documentation

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

Retrieve engine.

Definition at line 122 of file RndmGenSvc.cpp.

                                        {
      return m_engine;
    }

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

Service override: finalization.

Reimplemented from Service.

Definition at line 87 of file RndmGenSvc.cpp.

                                      {
      StatusCode status = Service::finalize();
      if ( m_serialize ) m_serialize->release();
      m_serialize = 0;
      if ( m_engine ) {
        SmartIF<IService> service(m_engine);
        service->finalize().ignore();
        m_engine->release();
      }
      m_engine = 0;
      return status;
    }

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.

                                                                                   {
      StatusCode status = StatusCode::FAILURE;
      IInterface* iface = PluginService::CreateWithId<IInterface*>(par.type(),(IInterface*)m_engine);
      if ( iface ) {
        // query requested interface (adds ref count)
        status = iface->queryInterface(IRndmGen::interfaceID(), (void**)& refpGen);
        if ( status.isSuccess() )   {
          status = refpGen->initialize(par);
        }
        else  {
          iface->release();
        }
      }
      // Error!
      return status;
    }

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

Service override: initialization.

Reimplemented from Service.

Definition at line 49 of file RndmGenSvc.cpp.

                                        {
      StatusCode status = Service::initialize();
      MsgStream log(msgSvc(), name());
      std::string machName = name()+".Engine";
      SmartIF<IRndmEngine> engine;
      SmartIF<ISvcManager> mgr(serviceLocator());

      if ( status.isSuccess() )   {
        status = setProperties();
        if ( status.isSuccess() )   {  // Check if the Engine service exists:
          // FIXME: (MCl) why RndmGenSvc cannot create the engine service in a standard way?
          const bool CREATE = false;
          engine = serviceLocator()->service(machName, CREATE);
          if ( !engine.isValid() && mgr.isValid() )   {
            using Gaudi::Utils::TypeNameString;
            engine = mgr->createService(TypeNameString(machName, m_engineName));
          }
          if ( engine.isValid() )   {
            SmartIF<ISerialize> serial(engine);
            SmartIF<IService>   service(engine);
            if ( serial.isValid( ) && service.isValid( ) )  {
              status = service->sysInitialize();
              if ( status.isSuccess() )   {
                m_engine = engine;
                m_serialize = serial;
                m_engine->addRef();
                m_serialize->addRef();
                log << MSG::INFO << "Using Random engine:" << m_engineName << endmsg;
                return status;
              }
            }
          }
        }
      }
      return status;
    }

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

Single shot returning single random number.

Definition at line 145 of file RndmGenSvc.cpp.

                                    {
      if ( 0 != m_engine )    {
        return m_engine->rndm();
      }
      return -1;
    }

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.

                                                                                                {
      if ( 0 != m_engine )    {
        return m_engine->rndmArray(array, howmany, start);
      }
      return StatusCode::FAILURE;
    }

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

Allow to get seeds.

Definition at line 174 of file RndmGenSvc.cpp.

                                                               {
      if ( 0 != m_engine )    {
        return m_engine->seeds(seeds);
      }
      return StatusCode::FAILURE;
    }

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.

                                                                  {
      if ( 0 != m_serialize )    {
        return m_serialize->serialize(str);
      }
      MsgStream log(msgSvc(), name());
      log << MSG::ERROR << "Cannot output serialize Generator settings!" << endmsg;
      return str;
    }

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.

                                                            {
      if ( 0 != m_serialize )    {
        return m_serialize->serialize(str);
      }
      MsgStream log(msgSvc(), name());
      log << MSG::ERROR << "Cannot input serialize Generator settings!" << endmsg;
      return str;
    }

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

Allow to set new seeds.

Definition at line 166 of file RndmGenSvc.cpp.

                                                                  {
      if ( 0 != m_engine )    {
        return m_engine->setSeeds(seeds);
      }
      return StatusCode::FAILURE;
    }

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

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

Engine name.

Definition at line 62 of file RndmGenSvc.h.

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

Serialization interface of random number engine.

Definition at line 60 of file RndmGenSvc.h.

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

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines