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"
16 string& stream, std::vector<unsigned long>& seed) {
20 typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
21 boost::char_separator<char> sep(
" ");
22 tokenizer tokens(buffer, sep);
23 if (status = (distance(tokens.begin(), tokens.end()) == 32)) {
24 tokenizer::iterator token(tokens.begin());
27 for(
int i=0; i<31; i++) {
28 long tmp = boost::lexical_cast<long>(*token++);
31 }
catch (boost::bad_lexical_cast e) {
43 m_read_from_file =
false;
44 m_file_to_read =
"BesRndmGenSvc.out";
45 ofile =
"BesRndmGenSvc.out";
48 m_default_seed = 11000;
49 m_EVTGEN_default_seed = 35910;
50 m_PYTHIA_default_seed = 93531;
51 m_HERWIG_default_seed = 35391;
52 m_LUNDCRM_default_seed = 12456;
53 m_SIM_default_seed = 23569;
54 m_MIX_default_seed = 76543;
55 m_KKMC_default_seed = 26877;
57 declareProperty(
"Seeds", m_streams_seeds);
58 declareProperty(
"StreamName", m_StreamName =
"EVTGEN");
59 declareProperty(
"ReadFromFile", m_read_from_file);
60 declareProperty(
"FileToRead", m_file_to_read);
61 declareProperty(
"RdmOutFile", ofile);
62 declareProperty(
"RndmSeed", m_default_seed);
64 Stream_EVTGEN =
"EVTGEN";
65 Stream_PYTHIA =
"PYTHIA";
66 Stream_HERWIG =
"HERWIG";
67 Stream_LUNDCRM =
"LUNDCRM";
95 return Service::queryInterface(riid, ppvInterface);
98 return StatusCode::SUCCESS;
104 MsgStream log( messageService(), name() );
105 log << MSG::INFO <<
"Initializing " << name()
106 <<
" - package version " << PACKAGE_VERSION
107 <<
"\n INITIALISING RANDOM NUMBER STREAMS. " << endreq;
110 if (!(Service::initialize().isSuccess())) {
111 return StatusCode::FAILURE;
115 m_EVTGEN_default_seed = m_default_seed+35910;
116 m_PYTHIA_default_seed = m_default_seed+93531;
117 m_HERWIG_default_seed = m_default_seed+35391;
118 m_LUNDCRM_default_seed = m_default_seed+12456;
119 m_SIM_default_seed = m_default_seed+23569;
120 m_MIX_default_seed = m_default_seed+76543;
121 m_KKMC_default_seed = m_default_seed+26877;
124 IIncidentSvc* pIncSvc(0);
127 if (!(service(
"IncidentSvc", pIncSvc,
true)).isSuccess()) {
129 <<
"Could not locate IncidentSvc "
131 return StatusCode::FAILURE;
135 static const int PRIORITY = 100;
136 pIncSvc->addListener(
this,
"EndEvent", PRIORITY);
138 if (m_read_from_file)
141 ifstream infile( m_file_to_read.c_str() );
144 log << MSG::ERROR <<
" Unable to open: " << m_file_to_read <<endreq;
145 return StatusCode::FAILURE;
150 while (std::getline(infile, buffer))
153 std::vector<unsigned long>
v;
156 log << MSG::DEBUG <<
" INITIALISING " << stream <<
" stream, "<<
" read from file " <<m_file_to_read << endreq;
157 CLHEP::HepRandomEngine* engine =
GetEngine(stream);
160 log << MSG::ERROR <<
"bad line\n" << buffer
161 <<
"\n in input file " << m_file_to_read << endreq;
162 return StatusCode::FAILURE;
170 for (VStrings::const_iterator i = m_streams_seeds.begin(); i != m_streams_seeds.end(); ++i)
173 std::vector<unsigned long>
v;
176 log << MSG::VERBOSE <<
"Seeds property: stream " << stream << endreq;
178 log << MSG::ERROR <<
"bad Seeds property\n" << *i << endreq;
179 return StatusCode::FAILURE;
183 bool not_found =
true;
189 if ((*sf).first == stream) not_found =
false;
191 }
while (sf !=
end() && not_found);
196 log << MSG::DEBUG <<
" INITIALISING " << stream << endreq;
202 return StatusCode::SUCCESS;
207 MsgStream log( messageService(), name() );
208 log << MSG::DEBUG <<
" Handle EndEvent " << endreq;
210 if ( inc.type() ==
"EndEvent")
213 m_engines_copy.clear();
216 CLHEP::HepRandomEngine* engine =
GetEngine((*i).first);
217 std::vector<unsigned long>
s = engine->put();
218 std::vector<long int> tseeds;
219 for(
unsigned int j=0; j<
s.size(); j++) {
220 tseeds.push_back(
s[j]);
222 m_engines_copy.insert(
223 std::map<std::string, std::vector<long int> >::value_type( (*i).first,
253 MsgStream log(messageService(), name());
254 log << MSG::INFO <<
" FINALISING " << endreq;
255 return Service::finalize();
258CLHEP::HepRandomEngine*
262 if ( citer == m_engines->end() )
264 m_engines->insert(
engineValType( StreamName,
new CLHEP::RanluxEngine() ) );
265 SetStreamSeeds ( StreamName );
269 return (CLHEP::HepRandomEngine*)(*iter).second;
276 if ( citer == m_engines->end() ) m_engines->insert(
engineValType( StreamName,
277 new CLHEP::RanluxEngine() ) );
279 ((*iter).second)->setSeed( seed, 3 );
283BesRndmGenSvc::SetStreamSeeds (
const std::string& StreamName )
286 if (StreamName ==
"PYTHIA")
288 theseed = m_PYTHIA_default_seed;
290 else if (StreamName ==
"HERWIG")
292 theseed = m_HERWIG_default_seed;
294 else if (StreamName ==
"EVTGEN")
296 theseed = m_EVTGEN_default_seed;
298 else if (StreamName ==
"LUNDCRM")
300 theseed = m_LUNDCRM_default_seed;
302 else if (StreamName ==
"SIM")
304 theseed = m_SIM_default_seed;
306 else if (StreamName ==
"MIX")
308 theseed = m_MIX_default_seed;
310 else if (StreamName ==
"KKMC")
312 theseed = m_KKMC_default_seed;
316 theseed = m_default_seed;
318 MsgStream log(messageService(), name());
319 log << MSG::WARNING <<
" INITIALISING " << StreamName <<
" stream with DEFAULT seed "
320 << theseed << endreq;
323 ((*iter).second)->setSeed( theseed, 3);
329 MsgStream log(messageService(), name());
331 if ( citer == m_engines->end() )
333 log << MSG::WARNING <<
" Stream = " << StreamName <<
" NOT FOUND" << endreq;
337 const long s = ((*citer).second)->getSeed();
338 log << MSG::INFO <<
" Stream = " << StreamName <<
", Seed = "
346 print( m_StreamName );
349CLHEP::HepRandomEngine*
353 if ( citer == m_engines->end() ) m_engines->insert(
engineValType( StreamName,
354 new CLHEP::RanluxEngine() ) );
358 long theseed = 10000*EventNumber + hashedStream;
359 ((*iter).second)->setSeed( theseed, 3 );
360 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
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
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
manage multiple CLHEP random engines as named streams
static const InterfaceID & interfaceID()
Gaudi boilerplate.