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

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

- Search for |

- File List
- File Members

# HepRndmEngines.cpp

Go to the documentation of this file.

    00001 //====================================================================
    00002 //      Random Engine implementations
    00003 //--------------------------------------------------------------------
    00004 //
    00005 //      Package    : HepRndm ( The LHCb Offline System)
    00006 //      Author     : M.Frank
    00007 //  History    :
    00008 // +---------+----------------------------------------------+---------
    00009 // |    Date |                 Comment                      | Who
    00010 // +---------+----------------------------------------------+---------
    00011 // | 29/10/99| Initial version                              | MF
    00012 // +---------+----------------------------------------------+---------
    00013 //
    00014 //  Note: Currently all engines require only ONE seed
    00015 //        We aill return only the first number, because
    00016 //        the implementation in CLHEP does not allow to
    00017 //        determine the proper number of seeds used.
    00018 #define NUMBER_OF_SEEDS    1
    00019 //
    00020 //====================================================================
    00021 #define HEPRNDM_HEPRNDMENGINES_CPP
    00022
    00023 // STL include files
    00024 #include <iostream>
    00025 #include <cfloat>
    00026 #include <ctime>
    00027 #include <cmath>
    00028
    00029 // Framework include files
    00030 #include "GaudiKernel/SvcFactory.h"
    00031 #include "GaudiKernel/System.h"
    00032 #include "GaudiKernel/MsgStream.h"
    00033
    00034 #include "RndmGenSvc.h"
    00035 #include "HepRndmEngine.h"
    00036
    00037 #include "CLHEP/Random/Random.h"
    00038 #include "CLHEP/Random/DualRand.h"
    00039 #include "CLHEP/Random/TripleRand.h"
    00040 #include "CLHEP/Random/DRand48Engine.h"
    00041 #include "CLHEP/Random/Hurd160Engine.h"
    00042 #include "CLHEP/Random/Hurd288Engine.h"
    00043 #include "CLHEP/Random/JamesRandom.h"
    00044 #include "CLHEP/Random/MTwistEngine.h"
    00045 #include "CLHEP/Random/RanecuEngine.h"
    00046 #include "CLHEP/Random/Ranlux64Engine.h"
    00047 #include "CLHEP/Random/RanluxEngine.h"
    00048 #include "CLHEP/Random/RanshiEngine.h"
    00049
    00050 namespace HepRndm  {
    00051
    00052   // Standard constructor
    00053   template <class TYPE> Engine<TYPE>::Engine(const std::string& nam, ISvcLocator* loc)
    00054   : BaseEngine (nam, loc)    {
    00055     declareProperty("Seeds",       m_seeds);
    00056     declareProperty("Column",      m_col = 0);
    00057     declareProperty("Row",         m_row = 1);
    00058     declareProperty("Luxury",      m_lux = 3);
    00059     declareProperty("UseTable",    m_useTable     = false);
    00060     declareProperty("SetSingleton",m_setSingleton = false);
    00061   }
    00062
    00063   // Standard destructor
    00064   template <class TYPE> Engine<TYPE>::~Engine()          {
    00065   }
    00066
    00067   // Initialize engine
    00068   template <class TYPE> StatusCode Engine<TYPE>::initialize()          {
    00069     m_seeds.erase(m_seeds.begin(), m_seeds.end());
    00070     StatusCode status = RndmEngine::initialize();
    00071     if ( m_seeds.size() == 0 )  {
    00072       // Default seeds
    00073       long theSeed = 1234567;
    00074       m_seeds.push_back(theSeed);
    00075       m_seeds.push_back(0);
    00076     }
    00077     MsgStream log(messageService(), name());
    00078     if ( status.isSuccess() )   {
    00079       status = initializeEngine();
    00080       if ( status.isSuccess() )   {
    00081         log << MSG::INFO << "Generator engine type:"
    00082                   << System::typeinfoName(typeid(TYPE))
    00083                   << endmsg;
    00084         if ( m_useTable )   {
    00085           if ( m_row > 214 || m_col > 1 )   {
    00086             log << MSG::ERROR << "Generator engine seed table has dimension [215][2], you gave:"
    00087                 << " Row=" << m_row << " Column:" << m_col << endmsg;
    00088             status = StatusCode::FAILURE;
    00089           }
    00090           else    {
    00091             log << MSG::INFO << "Generator engine seeds from table."
    00092                 << " Row=" << m_row << " Column:" << m_col << endmsg;
    00093           }
    00094         }
    00095         log << "Current Seed:" << m_hepEngine->getSeed();
    00096         log << " Luxury:" << m_lux;
    00097         log << endmsg;
    00098         // Use the default static engine if required (e.g. for GEANT4)
    00099         if ( m_setSingleton )   {
    00100           HepRandom::setTheEngine(m_hepEngine);
    00101           log << "This is the GEANT4 engine!" << endmsg;
    00102         }
    00103         return status;
    00104       }
    00105     }
    00106     log << MSG::ERROR << "Cannot initialze random engine of type:"
    00107           << System::typeinfoName(typeid(TYPE))
    00108         << endmsg;
    00109     return status;
    00110   }
    00111
    00112   // Finalize engine
    00113   template <class TYPE> StatusCode Engine<TYPE>::finalize()          {
    00114     if ( m_hepEngine )   {
    00115       HepRandom::setTheEngine(0);
    00116       delete m_hepEngine;
    00117     }
    00118     m_seeds.clear();
    00119     m_hepEngine = 0;
    00120     return RndmEngine::finalize();
    00121   }
    00122
    00123   // Retrieve single random number
    00124   template <class TYPE> double Engine<TYPE>::rndm() const  {
    00125     return m_hepEngine->flat();
    00126   }
    00127
    00128   // Retrieve seeds
    00129   template <class TYPE> StatusCode Engine<TYPE>::setSeeds(const std::vector<long>& seed)   {
    00130     typedef std::vector<long> seed_t;
    00131     m_seeds.clear();
    00132     for ( seed_t::const_iterator i = seed.begin(); i < seed.end(); i++ )   {
    00133       m_seeds.push_back(*i);
    00134     }
    00135     if ( m_seeds.size() > 0 )   {
    00136       if ( m_seeds.back() != 0 )    {
    00137         m_seeds.push_back(0);
    00138       }
    00139       m_hepEngine->setSeeds(&m_seeds[0], m_lux);
    00140       return StatusCode::SUCCESS;
    00141     }
    00142     return StatusCode::FAILURE;
    00143   }
    00144
    00145   // Retrieve seeds
    00146   template <class TYPE> StatusCode Engine<TYPE>::seeds(std::vector<long>& seed)  const  {
    00147     /*
    00148     const long *s = m_hepEngine->getSeeds();
    00149     for ( size_t i = 0; i < NUMBER_OF_SEEDS; i++ )   {
    00150       seed.push_back(s[i]);
    00151       if ( m_seeds.size() > i )
    00152         m_seeds[i] = s[i];
    00153       else
    00154         m_seeds.push_back(s[i]);
    00155     }
    00156     */
    00157     seed.push_back(m_hepEngine->getSeed());
    00158     return StatusCode::SUCCESS;
    00159   }
    00160
    00161   // Specialized shoot function for DualRand engine
    00162   template <> StatusCode Engine<DualRand>::initializeEngine()  {
    00163     m_hepEngine = (m_useTable) ? new DualRand(m_row, m_col) : new DualRand(m_seeds[0]);
    00164     return StatusCode::SUCCESS;
    00165   }
    00166   // Specialized shoot function for TripleRand engine
    00167   template <> StatusCode Engine<TripleRand>::initializeEngine()  {
    00168     m_hepEngine = (m_useTable) ? new TripleRand(m_row, m_col) : new TripleRand(m_seeds[0]);
    00169     return StatusCode::SUCCESS;
    00170   }
    00171   // Specialized shoot function for DRand48Engine
    00172   template <> StatusCode Engine<DRand48Engine>::initializeEngine()  {
    00173     m_hepEngine = (m_useTable) ? new DRand48Engine(m_row, m_col) : new DRand48Engine(m_seeds[0]);
    00174     return StatusCode::SUCCESS;
    00175   }
    00176   // Specialized shoot function for Hurd160Engine
    00177   template <> StatusCode Engine<Hurd160Engine>::initializeEngine()  {
    00178     m_hepEngine = (m_useTable) ? new Hurd160Engine(m_row, m_col) : new Hurd160Engine(m_seeds[0]);
    00179     return StatusCode::SUCCESS;
    00180   }
    00181   // Specialized shoot function for Hurd288Engine
    00182   template <> StatusCode Engine<Hurd288Engine>::initializeEngine()  {
    00183     m_hepEngine = (m_useTable) ? new Hurd288Engine(m_row, m_col) : new Hurd288Engine(m_seeds[0]);
    00184     return StatusCode::SUCCESS;
    00185   }
    00186   // Specialized shoot function for RanecuEngine
    00187   template <> StatusCode Engine<RanecuEngine>::initializeEngine()  {
    00188     m_hepEngine = (m_useTable) ? new RanecuEngine(m_row) : new RanecuEngine(m_seeds[0]);
    00189     return StatusCode::SUCCESS;
    00190   }
    00191   // Specialized shoot function for RanshiEngine
    00192   template <> StatusCode Engine<RanshiEngine>::initializeEngine()  {
    00193     m_hepEngine = (m_useTable) ? new RanshiEngine(m_row, m_col) : new RanshiEngine(m_seeds[0]);
    00194     return StatusCode::SUCCESS;
    00195   }
    00196   // Specialized shoot function for RanluxEngine
    00197   template <> StatusCode Engine<RanluxEngine>::initializeEngine()  {
    00198     m_hepEngine = (m_useTable) ? new RanluxEngine(m_row, m_col, m_lux) : new RanluxEngine(m_seeds[0], m_lux);
    00199     return StatusCode::SUCCESS;
    00200   }
    00201   // Specialized shoot function for Ranlux64Engine
    00202   template <> StatusCode Engine<Ranlux64Engine>::initializeEngine()  {
    00203     m_hepEngine = (m_useTable) ? new Ranlux64Engine(m_row, m_col, m_lux) : new Ranlux64Engine(m_seeds[0], m_lux);
    00204     return StatusCode::SUCCESS;
    00205   }
    00206   // Specialized shoot function for MTwistEngine
    00207   template <> StatusCode Engine<MTwistEngine>::initializeEngine()  {
    00208     m_hepEngine = (m_useTable) ? new MTwistEngine(m_row, m_col) : new MTwistEngine(m_seeds[0]);
    00209     return StatusCode::SUCCESS;
    00210   }
    00211   // Specialized shoot function for HepJamesRandom
    00212   template <> StatusCode Engine<HepJamesRandom>::initializeEngine()  {
    00213     m_hepEngine = (m_useTable) ? new HepJamesRandom(m_row, m_col) : new HepJamesRandom(m_seeds[0]);
    00214     return StatusCode::SUCCESS;
    00215   }
    00216
    00217 }
    00218
    00219 typedef HepRndm::Engine<DualRand> e1; DECLARE_SERVICE_FACTORY(e1)
    00220 typedef HepRndm::Engine<TripleRand> e2; DECLARE_SERVICE_FACTORY(e2)
    00221 typedef HepRndm::Engine<DRand48Engine> e3; DECLARE_SERVICE_FACTORY(e3)
    00222 typedef HepRndm::Engine<Hurd160Engine> e4; DECLARE_SERVICE_FACTORY(e4)
    00223 typedef HepRndm::Engine<Hurd288Engine> e5; DECLARE_SERVICE_FACTORY(e5)
    00224 typedef HepRndm::Engine<HepJamesRandom> e6; DECLARE_SERVICE_FACTORY(e6)
    00225 typedef HepRndm::Engine<MTwistEngine> e7; DECLARE_SERVICE_FACTORY(e7)
    00226 typedef HepRndm::Engine<RanecuEngine> e8; DECLARE_SERVICE_FACTORY(e8)
    00227 typedef HepRndm::Engine<Ranlux64Engine> e9; DECLARE_SERVICE_FACTORY(e9)
    00228 typedef HepRndm::Engine<RanluxEngine> e10; DECLARE_SERVICE_FACTORY(e10)
    00229 typedef HepRndm::Engine<RanshiEngine> e11; DECLARE_SERVICE_FACTORY(e11)
    00230
    00231