BesRndmGenSvc Class Reference

#include <BesRndmGenSvc.h>

Inheritance diagram for BesRndmGenSvc:

IBesRndmGenSvc List of all members.
typedef std::map< std::string,
CLHEP::RanluxEngine * > 
engineMap
 CLHEP engines typedefs:.
typedef engineMap::iterator engineIter
typedef engineMap::const_iterator engineConstIter
typedef engineMap::value_type engineValType
CLHEP::HepRandomEngine * GetEngine (const std::string &StreamName)
 Interface to the CLHEP engine.
void CreateStream (long seed, const std::string &StreamName)
engineConstIter begin (void) const
engineConstIter end (void) const
unsigned int number_of_streams (void) const
void setGenseed (long i)
long getGenseed ()
void print (const std::string &StreamName)
 Print methods.
void print (void)
CLHEP::HepRandomEngine * setOnDefinedSeeds (int EventNumber, const std::string &StreamName)
 set the seeds for an engine. First param will usually be the event number
StatusCode initialize ()
 Gaudi Service Implementation.
StatusCode finalize ()
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)

Public Member Functions

void handle (const Incident &)
 IIncidentListener implementation. Handles EndEvent incident.

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Gaudi boilerplate.

Protected Member Functions

 BesRndmGenSvc (const std::string &name, ISvcLocator *svc)
 Standard Constructor.
virtual ~BesRndmGenSvc ()
 Standard Destructor.

Private Types

typedef std::vector< std::stringVStrings
 Service Properties.

Private Member Functions

void SetStreamSeeds (const std::string &StreamName)

Private Attributes

VStrings m_streams_seeds
std::map< std::string, std::vector<
long int > > 
m_engines_copy
 Random engine copy (for output to a file).
bool m_read_from_file
std::string m_file_to_read
std::string ofile
long genSeed
engineMapm_engines
long m_default_seed
 Default seed values.
long m_EVTGEN_default_seed
long m_PYTHIA_default_seed
long m_HERWIG_default_seed
long m_LUNDCRM_default_seed
long m_SIM_default_seed
long m_MIX_default_seed
long m_KKMC_default_seed
std::string m_StreamName
std::string Stream_EVTGEN
std::string Stream_PYTHIA
std::string Stream_HERWIG
std::string Stream_LUNDCRM
std::string Stream_SIM
std::string Stream_MIX
std::string Stream_KKMC

Friends

class SvcFactory< BesRndmGenSvc >

Detailed Description

Definition at line 34 of file BesRndmGenSvc.h.


Member Typedef Documentation

typedef engineMap::const_iterator BesRndmGenSvc::engineConstIter

Definition at line 49 of file BesRndmGenSvc.h.

typedef engineMap::iterator BesRndmGenSvc::engineIter

Definition at line 48 of file BesRndmGenSvc.h.

typedef std::map<std::string, CLHEP::RanluxEngine*> BesRndmGenSvc::engineMap

CLHEP engines typedefs:.

Definition at line 47 of file BesRndmGenSvc.h.

typedef engineMap::value_type BesRndmGenSvc::engineValType

Definition at line 50 of file BesRndmGenSvc.h.

typedef std::vector< std::string > BesRndmGenSvc::VStrings [private]

Service Properties.

Definition at line 81 of file BesRndmGenSvc.h.


Constructor & Destructor Documentation

BesRndmGenSvc::BesRndmGenSvc ( const std::string name,
ISvcLocator *  svc 
) [protected]

Standard Constructor.

Definition at line 39 of file BesRndmGenSvc.cxx.

References m_default_seed, m_engines, m_EVTGEN_default_seed, m_file_to_read, m_HERWIG_default_seed, m_KKMC_default_seed, m_LUNDCRM_default_seed, m_MIX_default_seed, m_PYTHIA_default_seed, m_read_from_file, m_SIM_default_seed, m_StreamName, m_streams_seeds, ofile, Stream_EVTGEN, Stream_HERWIG, Stream_KKMC, Stream_LUNDCRM, Stream_MIX, Stream_PYTHIA, and Stream_SIM.

00040     : Service(name,svc)
00041 {
00042     // Property Default values
00043     m_read_from_file    =       false;
00044     m_file_to_read      =       "BesRndmGenSvc.out";
00045     ofile = "BesRndmGenSvc.out";
00046 
00047      // Set Default values       
00048     m_default_seed              =       11000;
00049     m_EVTGEN_default_seed       =       35910;
00050     m_PYTHIA_default_seed       =       93531;
00051     m_HERWIG_default_seed       =       35391;
00052     m_LUNDCRM_default_seed      =       12456;
00053     m_SIM_default_seed          =       23569;
00054     m_MIX_default_seed          =       76543;
00055     m_KKMC_default_seed         =       26877;
00056     // Get user's input
00057     declareProperty("Seeds",        m_streams_seeds);
00058     declareProperty("StreamName",   m_StreamName = "EVTGEN");
00059     declareProperty("ReadFromFile", m_read_from_file);
00060     declareProperty("FileToRead",   m_file_to_read);
00061     declareProperty("RdmOutFile",      ofile);
00062     declareProperty("RndmSeed",  m_default_seed);
00063 
00064     Stream_EVTGEN = "EVTGEN";
00065     Stream_PYTHIA = "PYTHIA";
00066     Stream_HERWIG = "HERWIG";
00067     Stream_LUNDCRM = "LUNDCRM";
00068     Stream_SIM    = "SIM";
00069     Stream_MIX    = "MIX";
00070     Stream_KKMC = "KKMC";
00071 
00072     m_engines                   =       new     engineMap();
00073 }

BesRndmGenSvc::~BesRndmGenSvc (  )  [protected, virtual]

Standard Destructor.

Definition at line 77 of file BesRndmGenSvc.cxx.

References m_engines.

00078 {
00079     delete      m_engines;
00080 }


Member Function Documentation

BesRndmGenSvc::engineConstIter BesRndmGenSvc::begin ( void   )  const [inline]

Definition at line 128 of file BesRndmGenSvc.h.

References m_engines.

Referenced by handle(), and initialize().

00129 { return m_engines->begin(); }

void BesRndmGenSvc::CreateStream ( long  seed,
const std::string StreamName 
) [virtual]

Implements IBesRndmGenSvc.

Definition at line 273 of file BesRndmGenSvc.cxx.

References iter(), and m_engines.

Referenced by initialize().

00274 {
00275     engineConstIter citer = m_engines->find(StreamName);
00276     if ( citer == m_engines->end() ) m_engines->insert( engineValType(  StreamName,
00277                                                                         new CLHEP::RanluxEngine() ) );
00278     engineIter  iter    =       m_engines->find(StreamName);
00279     ((*iter).second)->setSeed( seed, 3 );
00280 }

BesRndmGenSvc::engineConstIter BesRndmGenSvc::end ( void   )  const [inline]

Definition at line 132 of file BesRndmGenSvc.h.

References m_engines.

Referenced by handle(), and initialize().

00133 { return m_engines->end(); }

StatusCode BesRndmGenSvc::finalize (  ) 

Definition at line 251 of file BesRndmGenSvc.cxx.

References Bes_Common::INFO.

00252 {
00253     MsgStream log(messageService(), name());
00254     log << MSG::INFO << " FINALISING " << endreq;
00255     return Service::finalize();
00256 }

CLHEP::HepRandomEngine * BesRndmGenSvc::GetEngine ( const std::string StreamName  )  [virtual]

Interface to the CLHEP engine.

Implements IBesRndmGenSvc.

Definition at line 259 of file BesRndmGenSvc.cxx.

References iter(), m_engines, and SetStreamSeeds().

Referenced by handle(), and initialize().

00260 {
00261     engineConstIter citer = m_engines->find(StreamName);
00262     if ( citer == m_engines->end() )
00263     {
00264         m_engines->insert( engineValType( StreamName, new CLHEP::RanluxEngine() ) );
00265         SetStreamSeeds  ( StreamName );
00266     }
00267     
00268     engineIter  iter    =       m_engines->find(StreamName);
00269     return      (CLHEP::HepRandomEngine*)(*iter).second;
00270 }

long BesRndmGenSvc::getGenseed (  )  [inline, virtual]

Implements IBesRndmGenSvc.

Definition at line 58 of file BesRndmGenSvc.h.

References genSeed.

00058 { return genSeed; }

void BesRndmGenSvc::handle ( const Incident &   ) 

IIncidentListener implementation. Handles EndEvent incident.

Definition at line 206 of file BesRndmGenSvc.cxx.

References begin(), Bes_Common::DEBUG, end(), GetEngine(), genRecEmupikp::i, ganga-rec::j, m_engines_copy, s, deljobs::string, and dchain::value_type().

00206                                          {
00207   MsgStream log( messageService(), name() );
00208   log << MSG::DEBUG << " Handle EndEvent " << endreq;
00209 
00210   if ( inc.type() == "EndEvent") 
00211   {
00212 
00213     m_engines_copy.clear();
00214     for (engineConstIter i = begin(); i != end(); ++i)
00215     {
00216       CLHEP::HepRandomEngine* engine = GetEngine((*i).first);
00217       std::vector<unsigned long> s = engine->put();
00218       std::vector<long int> tseeds;
00219       for(unsigned int j=0; j<s.size(); j++) {
00220         tseeds.push_back(s[j]);
00221       }
00222       m_engines_copy.insert( 
00223         std::map<std::string, std::vector<long int> >::value_type( (*i).first,
00224                                                                    tseeds ) );
00225     }
00226     // Write the status of the Service into a file
00227 /*
00228     ofstream    outfile( ofile.c_str() );
00229     if ( !outfile )
00230     {
00231       log <<MSG::ERROR << "error: unable to open: " << ofile << endreq;
00232     }
00233     else
00234     {
00235         for (std::map<std::string, std::vector<long int> >::const_iterator i = m_engines_copy.begin();
00236              i != m_engines_copy.end();
00237              ++i)
00238         {
00239             outfile << (*i).first;
00240             for(unsigned int j=0; j<((*i).second).size(); j++)
00241               outfile << " " << (*i).second[j];
00242             outfile <<"\n";
00243         }
00244     }
00245 */
00246 //    print();    
00247   }
00248 }

StatusCode BesRndmGenSvc::initialize (  ) 

Gaudi Service Implementation.

Incident Service

Definition at line 102 of file BesRndmGenSvc.cxx.

References begin(), CreateStream(), Bes_Common::DEBUG, end(), calibUtil::ERROR, GetEngine(), genRecEmupikp::i, Bes_Common::INFO, interpretSeeds(), m_default_seed, m_EVTGEN_default_seed, m_file_to_read, m_HERWIG_default_seed, m_KKMC_default_seed, m_LUNDCRM_default_seed, m_MIX_default_seed, m_PYTHIA_default_seed, m_read_from_file, m_SIM_default_seed, m_streams_seeds, number_of_streams(), deljobs::string, v, and VERBOSE.

00103 {
00104   MsgStream log( messageService(), name() );
00105   log << MSG::INFO << "Initializing " << name()
00106       << " - package version " << PACKAGE_VERSION 
00107       << "\n INITIALISING RANDOM NUMBER STREAMS. " << endreq;
00108 
00109 
00110     if (!(Service::initialize().isSuccess())) {
00111       return StatusCode::FAILURE;
00112     }
00113 
00114     //set up different stream seeds by default seed
00115     m_EVTGEN_default_seed       =       m_default_seed+35910;
00116     m_PYTHIA_default_seed       =       m_default_seed+93531;
00117     m_HERWIG_default_seed       =       m_default_seed+35391;
00118     m_LUNDCRM_default_seed      =       m_default_seed+12456;
00119     m_SIM_default_seed          =       m_default_seed+23569;
00120     m_MIX_default_seed          =       m_default_seed+76543;
00121     m_KKMC_default_seed         =       m_default_seed+26877;
00122 
00124     IIncidentSvc* pIncSvc(0);
00125 
00126     // set up the incident service:
00127     if (!(service("IncidentSvc", pIncSvc, true)).isSuccess()) {
00128       log << MSG::ERROR 
00129           << "Could not locate IncidentSvc "
00130           << endreq;
00131       return StatusCode::FAILURE;
00132     }
00133   
00134     //start listening to "EndEvent"
00135     static const int PRIORITY = 100;
00136     pIncSvc->addListener(this, "EndEvent", PRIORITY);
00137 
00138     if (m_read_from_file)
00139     {
00140         // Read from a file
00141         ifstream infile( m_file_to_read.c_str() );
00142         if ( !infile )
00143         {
00144             log << MSG::ERROR << " Unable to open: " << m_file_to_read <<endreq;
00145             return StatusCode::FAILURE;
00146         }
00147         else
00148         {
00149             std::string buffer;
00150             while (std::getline(infile, buffer))
00151             {
00152               string stream; 
00153               std::vector<unsigned long> v;
00154               //split the space-separated string in 3 words:
00155               if (interpretSeeds(buffer, stream, v)) {
00156                 log << MSG::DEBUG << " INITIALISING " << stream << " stream, "<< " read from file " <<m_file_to_read << endreq;
00157                 CLHEP::HepRandomEngine* engine = GetEngine(stream);
00158                 engine->get(v);
00159               } else {          
00160                 log << MSG::ERROR << "bad line\n" << buffer 
00161                     << "\n in input file " << m_file_to_read << endreq;
00162                 return StatusCode::FAILURE;
00163               }         
00164             }
00165             
00166         }
00167     }
00168 
00169     // Create the various streams according to user's request
00170     for (VStrings::const_iterator i = m_streams_seeds.begin(); i != m_streams_seeds.end(); ++i)
00171     {
00172         string stream; 
00173         std::vector<unsigned long> v;
00174         //split the space-separated string in 3 words:
00175         if (interpretSeeds(*i, stream, v)) {
00176           log << MSG::VERBOSE << "Seeds property: stream " << stream << endreq; 
00177         } else {
00178           log << MSG::ERROR << "bad Seeds property\n" << *i << endreq; 
00179           return StatusCode::FAILURE;
00180         }               
00181         
00182         // Check if stream already generated (e.g. from reading a file)
00183         bool                            not_found       =       true;
00184         if ( number_of_streams() != 0 )
00185         {
00186             BesRndmGenSvc::engineConstIter sf           =       begin();
00187             do
00188             {
00189                 if ((*sf).first == stream) not_found = false;
00190                 ++sf;
00191             } while (sf != end() && not_found);
00192         }
00193         
00194         if (not_found)
00195         {
00196             log << MSG::DEBUG << " INITIALISING " << stream << endreq;
00197             CreateStream(v[0], stream);
00198         }
00199         
00200     }
00201     
00202     return StatusCode::SUCCESS;
00203 }

const InterfaceID & IBesRndmGenSvc::interfaceID (  )  [inline, static, inherited]

Gaudi boilerplate.

Definition at line 51 of file IBesRndmGenSvc.h.

Referenced by queryInterface().

00051                             {
00052   static const InterfaceID _IID("IBesRndmGenSvc", 1, 0);
00053   return _IID;
00054 }

unsigned int BesRndmGenSvc::number_of_streams ( void   )  const [inline]

Definition at line 136 of file BesRndmGenSvc.h.

References m_engines.

Referenced by initialize().

00137 { return m_engines->size(); }

void BesRndmGenSvc::print ( void   )  [virtual]

Implements IBesRndmGenSvc.

Definition at line 344 of file BesRndmGenSvc.cxx.

References m_StreamName.

00345 {
00346         print( m_StreamName );
00347 }

void BesRndmGenSvc::print ( const std::string StreamName  )  [virtual]

Print methods.

Implements IBesRndmGenSvc.

Definition at line 327 of file BesRndmGenSvc.cxx.

References Bes_Common::INFO, m_engines, s, and Bes_Common::WARNING.

00328 {
00329     MsgStream log(messageService(), name());
00330     engineConstIter citer = m_engines->find(StreamName);
00331     if ( citer == m_engines->end() )
00332     {
00333         log << MSG::WARNING << " Stream =  " << StreamName << " NOT FOUND" << endreq;
00334     }
00335     else
00336     {
00337         const long s    =       ((*citer).second)->getSeed();
00338         log << MSG::INFO << " Stream =  " << StreamName << ", Seed =  "
00339             << s << endreq;
00340     }
00341 }

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

Definition at line 88 of file BesRndmGenSvc.cxx.

References IBesRndmGenSvc::interfaceID().

00089 {
00090     if ( IBesRndmGenSvc::interfaceID().versionMatch(riid) )    {
00091         *ppvInterface = (IBesRndmGenSvc*)this;
00092     }
00093     else  {
00094         // Interface is not directly available: try out a base class
00095         return Service::queryInterface(riid, ppvInterface);
00096     }
00097     addRef();
00098     return StatusCode::SUCCESS;
00099 }

void BesRndmGenSvc::setGenseed ( long  i  )  [inline, virtual]

Implements IBesRndmGenSvc.

Definition at line 57 of file BesRndmGenSvc.h.

References genSeed.

00057 { genSeed = i; }

CLHEP::HepRandomEngine * BesRndmGenSvc::setOnDefinedSeeds ( int  EventNumber,
const std::string StreamName 
) [virtual]

set the seeds for an engine. First param will usually be the event number

Implements IBesRndmGenSvc.

Definition at line 350 of file BesRndmGenSvc.cxx.

References iter(), and m_engines.

00351 {
00352   engineConstIter citer = m_engines->find(StreamName);
00353   if ( citer == m_engines->end() ) m_engines->insert( engineValType(    StreamName,
00354                                                                         new CLHEP::RanluxEngine() ) );
00355   engineIter    iter    =       m_engines->find(StreamName);
00356   long hashedStream;
00357   // (SG::simpleStringHash(StreamName));
00358   long theseed = 10000*EventNumber + hashedStream;
00359   ((*iter).second)->setSeed( theseed, 3 );
00360   return        (CLHEP::HepRandomEngine*)(*iter).second;
00361 }

void BesRndmGenSvc::SetStreamSeeds ( const std::string StreamName  )  [private]

Definition at line 283 of file BesRndmGenSvc.cxx.

References iter(), m_default_seed, m_engines, m_EVTGEN_default_seed, m_HERWIG_default_seed, m_KKMC_default_seed, m_LUNDCRM_default_seed, m_MIX_default_seed, m_PYTHIA_default_seed, m_SIM_default_seed, and Bes_Common::WARNING.

Referenced by GetEngine().

00284 {
00285     long theseed;
00286     if (StreamName == "PYTHIA")
00287     {
00288         theseed = m_PYTHIA_default_seed;
00289     }
00290     else if (StreamName == "HERWIG")
00291     {
00292         theseed = m_HERWIG_default_seed;
00293     }
00294     else if (StreamName == "EVTGEN")
00295     {
00296         theseed = m_EVTGEN_default_seed;
00297     }
00298     else if (StreamName == "LUNDCRM")
00299     {
00300         theseed = m_LUNDCRM_default_seed;
00301     }
00302     else if (StreamName == "SIM")
00303     {
00304         theseed = m_SIM_default_seed;
00305     }
00306     else if (StreamName == "MIX")
00307     {
00308         theseed = m_MIX_default_seed;
00309     }
00310     else if (StreamName == "KKMC")
00311     {
00312       theseed = m_KKMC_default_seed;
00313     }
00314     else
00315     {
00316         theseed = m_default_seed;
00317     }
00318     MsgStream log(messageService(), name());
00319     log << MSG::WARNING << " INITIALISING " << StreamName << " stream with DEFAULT seed "
00320         << theseed << endreq;
00321     
00322     engineIter  iter    =       m_engines->find(StreamName);
00323     ((*iter).second)->setSeed( theseed, 3);
00324 }


Friends And Related Function Documentation

friend class SvcFactory< BesRndmGenSvc > [friend]

Definition at line 117 of file BesRndmGenSvc.h.


Member Data Documentation

long BesRndmGenSvc::genSeed [private]

Definition at line 90 of file BesRndmGenSvc.h.

Referenced by getGenseed(), and setGenseed().

long BesRndmGenSvc::m_default_seed [private]

Default seed values.

Definition at line 95 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc(), initialize(), and SetStreamSeeds().

engineMap* BesRndmGenSvc::m_engines [private]

Definition at line 91 of file BesRndmGenSvc.h.

Referenced by begin(), BesRndmGenSvc(), CreateStream(), end(), GetEngine(), number_of_streams(), print(), setOnDefinedSeeds(), SetStreamSeeds(), and ~BesRndmGenSvc().

std::map<std::string, std::vector<long int> > BesRndmGenSvc::m_engines_copy [private]

Random engine copy (for output to a file).

Definition at line 85 of file BesRndmGenSvc.h.

Referenced by handle().

long BesRndmGenSvc::m_EVTGEN_default_seed [private]

Definition at line 96 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc(), initialize(), and SetStreamSeeds().

std::string BesRndmGenSvc::m_file_to_read [private]

Definition at line 88 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc(), and initialize().

long BesRndmGenSvc::m_HERWIG_default_seed [private]

Definition at line 98 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc(), initialize(), and SetStreamSeeds().

long BesRndmGenSvc::m_KKMC_default_seed [private]

Definition at line 102 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc(), initialize(), and SetStreamSeeds().

long BesRndmGenSvc::m_LUNDCRM_default_seed [private]

Definition at line 99 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc(), initialize(), and SetStreamSeeds().

long BesRndmGenSvc::m_MIX_default_seed [private]

Definition at line 101 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc(), initialize(), and SetStreamSeeds().

long BesRndmGenSvc::m_PYTHIA_default_seed [private]

Definition at line 97 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc(), initialize(), and SetStreamSeeds().

bool BesRndmGenSvc::m_read_from_file [private]

Definition at line 87 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc(), and initialize().

long BesRndmGenSvc::m_SIM_default_seed [private]

Definition at line 100 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc(), initialize(), and SetStreamSeeds().

std::string BesRndmGenSvc::m_StreamName [private]

Definition at line 103 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc(), and print().

VStrings BesRndmGenSvc::m_streams_seeds [private]

Definition at line 82 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc(), and initialize().

std::string BesRndmGenSvc::ofile [private]

Definition at line 89 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc().

std::string BesRndmGenSvc::Stream_EVTGEN [private]

Definition at line 104 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc().

std::string BesRndmGenSvc::Stream_HERWIG [private]

Definition at line 106 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc().

std::string BesRndmGenSvc::Stream_KKMC [private]

Definition at line 110 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc().

std::string BesRndmGenSvc::Stream_LUNDCRM [private]

Definition at line 107 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc().

std::string BesRndmGenSvc::Stream_MIX [private]

Definition at line 109 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc().

std::string BesRndmGenSvc::Stream_PYTHIA [private]

Definition at line 105 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc().

std::string BesRndmGenSvc::Stream_SIM [private]

Definition at line 108 of file BesRndmGenSvc.h.

Referenced by BesRndmGenSvc().


Generated on Tue Nov 29 23:17:34 2016 for BOSS_7.0.2 by  doxygen 1.4.7