3#ifndef HAVE_NEW_IOSTREAMS
4#define BOOST_NO_STRINGSTREAM 1
6#include <boost/lexical_cast.hpp>
7#include <boost/tokenizer.hpp>
9#include "GaudiKernel/MsgStream.h"
10#include "GaudiKernel/ISvcLocator.h"
11#include "GaudiKernel/IIncidentSvc.h"
12#include "GaudiKernel/Incident.h"
19 string& stream,
std::vector<
unsigned long>& seed) {
23 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
24 boost::char_separator<char> sep(
" ");
25 tokenizer tokens(buffer, sep);
26 if (status = (distance(tokens.begin(), tokens.end()) == 32)) {
27 tokenizer::iterator token(tokens.begin());
30 for(
int i=0; i<31; i++) {
31 long tmp = boost::lexical_cast<long>(*token++);
34 }
catch (boost::bad_lexical_cast e) {
43 : base_class(name,svc)
46 m_read_from_file =
false;
47 m_file_to_read =
"BesRndmGenSvc.out";
48 ofile =
"BesRndmGenSvc.out";
51 m_default_seed = 11000;
52 m_EVTGEN_default_seed = 35910;
53 m_PYTHIA_default_seed = 93531;
54 m_HERWIG_default_seed = 35391;
55 m_LUNDCRM_default_seed = 12456;
56 m_SIM_default_seed = 23569;
57 m_MIX_default_seed = 76543;
58 m_KKMC_default_seed = 26877;
60 declareProperty(
"Seeds", m_streams_seeds);
61 declareProperty(
"StreamName", m_StreamName =
"EVTGEN");
62 declareProperty(
"ReadFromFile", m_read_from_file);
63 declareProperty(
"FileToRead", m_file_to_read);
64 declareProperty(
"RdmOutFile", ofile);
65 declareProperty(
"RndmSeed", m_default_seed);
67 Stream_EVTGEN =
"EVTGEN";
68 Stream_PYTHIA =
"PYTHIA";
69 Stream_HERWIG =
"HERWIG";
70 Stream_LUNDCRM =
"LUNDCRM";
107 MsgStream log( messageService(), name() );
108 log << MSG::INFO <<
"Initializing " << name()
109 <<
" - package version " << PACKAGE_VERSION
110 <<
"\n INITIALISING RANDOM NUMBER STREAMS. " << endreq;
113 if (!(Service::initialize().isSuccess())) {
114 return StatusCode::FAILURE;
118 m_EVTGEN_default_seed = m_default_seed+35910;
119 m_PYTHIA_default_seed = m_default_seed+93531;
120 m_HERWIG_default_seed = m_default_seed+35391;
121 m_LUNDCRM_default_seed = m_default_seed+12456;
122 m_SIM_default_seed = m_default_seed+23569;
123 m_MIX_default_seed = m_default_seed+76543;
124 m_KKMC_default_seed = m_default_seed+26877;
127 IIncidentSvc* pIncSvc(0);
130 if (!(service(
"IncidentSvc", pIncSvc,
true)).isSuccess()) {
132 <<
"Could not locate IncidentSvc "
134 return StatusCode::FAILURE;
138 static const int PRIORITY = 100;
139 pIncSvc->addListener(
this,
"EndEvent", PRIORITY);
141 if (m_read_from_file)
144 ifstream infile( m_file_to_read.c_str() );
147 log << MSG::ERROR <<
" Unable to open: " << m_file_to_read <<endreq;
148 return StatusCode::FAILURE;
153 while (std::getline(infile, buffer))
156 std::vector<unsigned long>
v;
159 log << MSG::DEBUG <<
" INITIALISING " << stream <<
" stream, "<<
" read from file " <<m_file_to_read << endreq;
160 CLHEP::HepRandomEngine* engine =
GetEngine(stream);
163 log << MSG::ERROR <<
"bad line\n" << buffer
164 <<
"\n in input file " << m_file_to_read << endreq;
165 return StatusCode::FAILURE;
173 for (VStrings::const_iterator i = m_streams_seeds.begin(); i != m_streams_seeds.end(); ++i)
176 std::vector<unsigned long>
v;
179 log << MSG::VERBOSE <<
"Seeds property: stream " << stream << endreq;
181 log << MSG::ERROR <<
"bad Seeds property\n" << *i << endreq;
182 return StatusCode::FAILURE;
186 bool not_found =
true;
192 if ((*sf).first == stream) not_found =
false;
194 }
while (sf !=
end() && not_found);
199 log << MSG::DEBUG <<
" INITIALISING " << stream << endreq;
205 return StatusCode::SUCCESS;
210 MsgStream log( messageService(), name() );
211 log << MSG::DEBUG <<
" Handle EndEvent " << endreq;
213 if ( inc.type() ==
"EndEvent")
216 m_engines_copy.clear();
219 CLHEP::HepRandomEngine* engine =
GetEngine((*i).first);
220 std::vector<unsigned long>
s = engine->put();
221 std::vector<long int> tseeds;
222 for(
unsigned int j=0; j<
s.size(); j++) {
223 tseeds.push_back(
s[j]);
225 m_engines_copy.insert(
226 std::map<std::string, std::vector<long int> >::value_type( (*i).first,
256 MsgStream log(messageService(), name());
257 log << MSG::INFO <<
" FINALISING " << endreq;
258 return Service::finalize();
261CLHEP::HepRandomEngine*
265 if ( citer == m_engines->end() )
267 m_engines->insert(
engineValType( StreamName,
new CLHEP::RanluxEngine() ) );
268 SetStreamSeeds ( StreamName );
272 return (CLHEP::HepRandomEngine*)(*iter).second;
279 if ( citer == m_engines->end() ) m_engines->insert(
engineValType( StreamName,
280 new CLHEP::RanluxEngine() ) );
282 ((*iter).second)->setSeed( seed, 3 );
286BesRndmGenSvc::SetStreamSeeds (
const std::string& StreamName )
289 if (StreamName ==
"PYTHIA")
291 theseed = m_PYTHIA_default_seed;
293 else if (StreamName ==
"HERWIG")
295 theseed = m_HERWIG_default_seed;
297 else if (StreamName ==
"EVTGEN")
299 theseed = m_EVTGEN_default_seed;
301 else if (StreamName ==
"LUNDCRM")
303 theseed = m_LUNDCRM_default_seed;
305 else if (StreamName ==
"SIM")
307 theseed = m_SIM_default_seed;
309 else if (StreamName ==
"MIX")
311 theseed = m_MIX_default_seed;
313 else if (StreamName ==
"KKMC")
315 theseed = m_KKMC_default_seed;
319 theseed = m_default_seed;
321 MsgStream log(messageService(), name());
322 log << MSG::WARNING <<
" INITIALISING " << StreamName <<
" stream with DEFAULT seed "
323 << theseed << endreq;
326 ((*iter).second)->setSeed( theseed, 3);
332 MsgStream log(messageService(), name());
334 if ( citer == m_engines->end() )
336 log << MSG::WARNING <<
" Stream = " << StreamName <<
" NOT FOUND" << endreq;
340 const long s = ((*citer).second)->getSeed();
341 log << MSG::INFO <<
" Stream = " << StreamName <<
", Seed = "
349 print( m_StreamName );
352CLHEP::HepRandomEngine*
356 if ( citer == m_engines->end() ) m_engines->insert(
engineValType( StreamName,
357 new CLHEP::RanluxEngine() ) );
361 long theseed = 10000*EventNumber + hashedStream;
362 ((*iter).second)->setSeed( theseed, 3 );
363 return (CLHEP::HepRandomEngine*)(*iter).second;
bool interpretSeeds(const string &buffer, string &stream, std::vector< unsigned long > &seed)
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
StatusCode initialize()
Gaudi Service Implementation.
BesRndmGenSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
engineConstIter begin(void) const
engineMap::iterator engineIter
CLHEP::HepRandomEngine * GetEngine(const std::string &StreamName)
Interface to the CLHEP engine.
void handle(const Incident &)
IIncidentListener implementation. Handles EndEvent incident.
void CreateStream(long seed, const std::string &StreamName)
engineMap::const_iterator engineConstIter
std::map< std::string, CLHEP::RanluxEngine * > engineMap
CLHEP engines typedefs:
engineConstIter end(void) const
CLHEP::HepRandomEngine * setOnDefinedSeeds(int EventNumber, const std::string &StreamName)
set the seeds for an engine. First param will usually be the event number
virtual ~BesRndmGenSvc()
Standard Destructor.
engineMap::value_type engineValType
unsigned int number_of_streams(void) const