Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   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/DualRand.h"
00038 #include "CLHEP/Random/TripleRand.h"
00039 #include "CLHEP/Random/DRand48Engine.h"
00040 #include "CLHEP/Random/Hurd160Engine.h"
00041 #include "CLHEP/Random/Hurd288Engine.h"
00042 #include "CLHEP/Random/JamesRandom.h"
00043 #include "CLHEP/Random/MTwistEngine.h"
00044 #include "CLHEP/Random/RanecuEngine.h"
00045 #include "CLHEP/Random/Ranlux64Engine.h"
00046 #include "CLHEP/Random/RanluxEngine.h"
00047 #include "CLHEP/Random/RanshiEngine.h"
00048 
00049 namespace HepRndm  {
00050 
00051   // Standard constructor
00052   template <class TYPE> Engine<TYPE>::Engine(const std::string& nam, ISvcLocator* loc)
00053   : BaseEngine (nam, loc)    {
00054     declareProperty("Seeds",   m_seeds);
00055     declareProperty("Column",  m_col = 0);
00056     declareProperty("Row",     m_row = 1);
00057     declareProperty("Luxury",  m_lux = 3);
00058     declareProperty("UseTable",m_useTable = false);
00059   }
00060 
00061   // Standard destructor
00062   template <class TYPE> Engine<TYPE>::~Engine()          {  
00063   }
00064 
00065   // Initialize engine
00066   template <class TYPE> StatusCode Engine<TYPE>::initialize()          {  
00067     m_seeds.erase(m_seeds.begin(), m_seeds.end());
00068     StatusCode status = RndmEngine::initialize();
00069     if ( m_seeds.size() == 0 )  {
00070       // Default seeds
00071       long theSeed = 1234567;
00072       m_seeds.push_back(theSeed);
00073       m_seeds.push_back(theSeed+1);
00074     }
00075     MsgStream log(messageService(), name());
00076     if ( status.isSuccess() )   {
00077       status = initializeEngine();
00078       if ( status.isSuccess() )   {
00079         log << MSG::INFO << "Generator engine type:" 
00080                   << System::typeinfoName(typeid(TYPE)) 
00081                   << endreq;
00082         if ( m_useTable )   {
00083           if ( m_row > 214 || m_col > 1 )   {
00084             log << MSG::ERROR << "Generator engine seed table has dimension [215][2], you gave:"
00085                 << " Row=" << m_row << " Column:" << m_col << endreq;
00086             status = StatusCode::FAILURE;
00087           }
00088           else    {
00089             log << MSG::INFO << "Generator engine seeds from table."
00090                 << " Row=" << m_row << " Column:" << m_col << endreq;
00091           }
00092         }
00093         log << "Current Seed:" << m_hepEngine->getSeed();
00094         log << " Luxury:" << m_lux;
00095         log << endreq;
00096         return status;
00097       }
00098     }
00099     log << MSG::ERROR << "Cannot initialze random engine of type:" 
00100           << System::typeinfoName(typeid(TYPE)) 
00101         << endreq;
00102     return status;
00103   }
00104 
00105   // Finalize engine
00106   template <class TYPE> StatusCode Engine<TYPE>::finalize()          {  
00107     m_seeds.erase(m_seeds.begin(), m_seeds.end());
00108     if ( m_hepEngine ) delete m_hepEngine;
00109     m_hepEngine = 0;
00110     return RndmEngine::finalize();
00111   }
00112 
00113   // Retrieve single random number
00114   template <class TYPE> double Engine<TYPE>::rndm() const  {
00115     return m_hepEngine->flat();
00116   }
00117 
00118   // Retrieve seeds
00119   template <class TYPE> StatusCode Engine<TYPE>::setSeeds(const std::vector<long>& seed)   {  
00120     for ( size_t i = 0; i < seed.size(); i++ )  {
00121       if ( m_seeds.size() > i )  
00122         m_seeds[i] = seed[i];
00123       else 
00124         m_seeds.push_back(seed[i]);
00125     }
00126     m_hepEngine->setSeeds((long*)&m_seeds[0], m_lux);
00127     return StatusCode::SUCCESS;
00128   }
00129 
00130   // Retrieve seeds
00131   template <class TYPE> StatusCode Engine<TYPE>::seeds(std::vector<long>& seed)  const  {  
00132     /* 
00133     const long *s = m_hepEngine->getSeeds();
00134     for ( size_t i = 0; i < NUMBER_OF_SEEDS; i++ )   {
00135       seed.push_back(s[i]);
00136       if ( m_seeds.size() > i )  
00137         m_seeds[i] = s[i];
00138       else 
00139         m_seeds.push_back(s[i]);
00140     }
00141     */
00142     seed.push_back(m_hepEngine->getSeed());
00143     return StatusCode::SUCCESS;
00144   }
00145 
00146   // Specialized shoot function for DualRand engine
00147   template <> StatusCode Engine<DualRand>::initializeEngine()  {
00148     m_hepEngine = (m_useTable) ? new DualRand(m_row, m_col) : new DualRand(m_seeds[0]);
00149     return StatusCode::SUCCESS;
00150   }
00151   // Specialized shoot function for TripleRand engine
00152   template <> StatusCode Engine<TripleRand>::initializeEngine()  {
00153     m_hepEngine = (m_useTable) ? new TripleRand(m_row, m_col) : new TripleRand(m_seeds[0]);
00154     return StatusCode::SUCCESS;
00155   }
00156   // Specialized shoot function for DRand48Engine
00157   template <> StatusCode Engine<DRand48Engine>::initializeEngine()  {
00158     m_hepEngine = (m_useTable) ? new DRand48Engine(m_row, m_col) : new DRand48Engine(m_seeds[0]);
00159     return StatusCode::SUCCESS;
00160   }
00161   // Specialized shoot function for Hurd160Engine
00162   template <> StatusCode Engine<Hurd160Engine>::initializeEngine()  {
00163     m_hepEngine = (m_useTable) ? new Hurd160Engine(m_row, m_col) : new Hurd160Engine(m_seeds[0]);
00164     return StatusCode::SUCCESS;
00165   }
00166   // Specialized shoot function for Hurd288Engine
00167   template <> StatusCode Engine<Hurd288Engine>::initializeEngine()  {
00168     m_hepEngine = (m_useTable) ? new Hurd288Engine(m_row, m_col) : new Hurd288Engine(m_seeds[0]);
00169     return StatusCode::SUCCESS;
00170   }
00171   // Specialized shoot function for RanecuEngine
00172   template <> StatusCode Engine<RanecuEngine>::initializeEngine()  {
00173     m_hepEngine = (m_useTable) ? new RanecuEngine(m_row) : new RanecuEngine(m_seeds[0]);
00174     return StatusCode::SUCCESS;
00175   }
00176   // Specialized shoot function for RanshiEngine
00177   template <> StatusCode Engine<RanshiEngine>::initializeEngine()  {
00178     m_hepEngine = (m_useTable) ? new RanshiEngine(m_row, m_col) : new RanshiEngine(m_seeds[0]);
00179     return StatusCode::SUCCESS;
00180   }
00181   // Specialized shoot function for RanluxEngine
00182   template <> StatusCode Engine<RanluxEngine>::initializeEngine()  {
00183     m_hepEngine = (m_useTable) ? new RanluxEngine(m_row, m_col, m_lux) : new RanluxEngine(m_seeds[0], m_lux);
00184     return StatusCode::SUCCESS;
00185   }
00186   // Specialized shoot function for Ranlux64Engine
00187   template <> StatusCode Engine<Ranlux64Engine>::initializeEngine()  {
00188     m_hepEngine = (m_useTable) ? new Ranlux64Engine(m_row, m_col, m_lux) : new Ranlux64Engine(m_seeds[0], m_lux);
00189     return StatusCode::SUCCESS;
00190   }
00191   // Specialized shoot function for MTwistEngine
00192   template <> StatusCode Engine<MTwistEngine>::initializeEngine()  {
00193     m_hepEngine = (m_useTable) ? new MTwistEngine(m_row, m_col) : new MTwistEngine(m_seeds[0]);
00194     return StatusCode::SUCCESS;
00195   }
00196   // Specialized shoot function for HepJamesRandom
00197   template <> StatusCode Engine<HepJamesRandom>::initializeEngine()  {
00198     m_hepEngine = (m_useTable) ? new HepJamesRandom(m_row, m_col) : new HepJamesRandom(m_seeds[0]);
00199     return StatusCode::SUCCESS;
00200   }
00201 
00202 };
00203 
00204 // Instantiate factories
00205 static SvcFactory< HepRndm::Engine<DualRand> >        s_DualRandEngineFactory;
00206 const ISvcFactory& DualRandEngineFactory =            s_DualRandEngineFactory;
00207 
00208 static SvcFactory< HepRndm::Engine<TripleRand> >      s_TripleRandEngineFactory;
00209 const ISvcFactory& TripleRandEngineFactory =          s_TripleRandEngineFactory;
00210 
00211 static SvcFactory< HepRndm::Engine<DRand48Engine> >   s_DRand48EngineFactory;
00212 const ISvcFactory& DRand48EngineFactory =             s_DRand48EngineFactory;
00213 
00214 static SvcFactory< HepRndm::Engine<Hurd160Engine> >   s_Hurd160EngineFactory;
00215 const ISvcFactory& Hurd160EngineFactory =             s_Hurd160EngineFactory;
00216 
00217 static SvcFactory< HepRndm::Engine<Hurd288Engine> >   s_Hurd288EngineFactory;
00218 const ISvcFactory& Hurd288EngineFactory =             s_Hurd288EngineFactory;
00219 
00220 static SvcFactory< HepRndm::Engine<HepJamesRandom> >  s_HepJamesRandomFactory;
00221 const ISvcFactory& HepJamesRandomFactory =            s_HepJamesRandomFactory;
00222 
00223 static SvcFactory< HepRndm::Engine<MTwistEngine> >    s_MTwistEngineFactory;
00224 const ISvcFactory& MTwistEngineFactory =              s_MTwistEngineFactory;
00225 
00226 static SvcFactory< HepRndm::Engine<RanecuEngine> >    s_RanecuEngineFactory;
00227 const ISvcFactory& RanecuEngineFactory =              s_RanecuEngineFactory;
00228 
00229 static SvcFactory< HepRndm::Engine<Ranlux64Engine> >  s_Ranlux64EngineFactory;
00230 const ISvcFactory& Ranlux64EngineFactory =            s_Ranlux64EngineFactory;
00231 
00232 static SvcFactory< HepRndm::Engine<RanluxEngine> >    s_RanluxEngineFactory;
00233 const ISvcFactory& RanluxEngineFactory =              s_RanluxEngineFactory;
00234 
00235 static SvcFactory< HepRndm::Engine<RanshiEngine> >    s_RanshiEngineFactory;
00236 const ISvcFactory& RanshiEngineFactory =              s_RanshiEngineFactory;

Generated at Wed Nov 21 12:22:30 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000