BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
BesRndmGenSvc Class Reference

#include <BesRndmGenSvc.h>

+ Inheritance diagram for BesRndmGenSvc:

Public Types

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
 

Public Member Functions

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 ()
 
void handle (const Incident &)
 IIncidentListener implementation. Handles EndEvent incident.
 
 BesRndmGenSvc (const std::string &name, ISvcLocator *svc)
 Standard Constructor.
 
virtual ~BesRndmGenSvc ()
 Standard Destructor.
 

Friends

class SvcFactory< BesRndmGenSvc >
 

Detailed Description

Definition at line 34 of file BesRndmGenSvc.h.

Member Typedef Documentation

◆ engineConstIter

engineMap::const_iterator BesRndmGenSvc::engineConstIter

Definition at line 49 of file BesRndmGenSvc.h.

◆ engineIter

engineMap::iterator BesRndmGenSvc::engineIter

Definition at line 48 of file BesRndmGenSvc.h.

◆ engineMap

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

CLHEP engines typedefs:

Definition at line 47 of file BesRndmGenSvc.h.

◆ engineValType

engineMap::value_type BesRndmGenSvc::engineValType

Definition at line 50 of file BesRndmGenSvc.h.

Constructor & Destructor Documentation

◆ BesRndmGenSvc()

BesRndmGenSvc::BesRndmGenSvc ( const std::string & name,
ISvcLocator * svc )

Standard Constructor.

Definition at line 42 of file BesRndmGenSvc.cxx.

43 : base_class(name,svc)
44{
45 // Property Default values
46 m_read_from_file = false;
47 m_file_to_read = "BesRndmGenSvc.out";
48 ofile = "BesRndmGenSvc.out";
49
50 // Set Default values
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;
59 // Get user's input
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);
66
67 Stream_EVTGEN = "EVTGEN";
68 Stream_PYTHIA = "PYTHIA";
69 Stream_HERWIG = "HERWIG";
70 Stream_LUNDCRM = "LUNDCRM";
71 Stream_SIM = "SIM";
72 Stream_MIX = "MIX";
73 Stream_KKMC = "KKMC";
74
75 m_engines = new engineMap();
76}
std::map< std::string, CLHEP::RanluxEngine * > engineMap
CLHEP engines typedefs:

◆ ~BesRndmGenSvc()

BesRndmGenSvc::~BesRndmGenSvc ( )
virtual

Standard Destructor.

Definition at line 80 of file BesRndmGenSvc.cxx.

81{
82 delete m_engines;
83}

Member Function Documentation

◆ begin()

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

Definition at line 128 of file BesRndmGenSvc.h.

129{ return m_engines->begin(); }

Referenced by handle(), and initialize().

◆ CreateStream()

void BesRndmGenSvc::CreateStream ( long seed,
const std::string & StreamName )

Definition at line 276 of file BesRndmGenSvc.cxx.

277{
278 engineConstIter citer = m_engines->find(StreamName);
279 if ( citer == m_engines->end() ) m_engines->insert( engineValType( StreamName,
280 new CLHEP::RanluxEngine() ) );
281 engineIter iter = m_engines->find(StreamName);
282 ((*iter).second)->setSeed( seed, 3 );
283}
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
engineMap::iterator engineIter
engineMap::const_iterator engineConstIter
engineMap::value_type engineValType

Referenced by initialize().

◆ end()

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

Definition at line 132 of file BesRndmGenSvc.h.

133{ return m_engines->end(); }

Referenced by handle(), and initialize().

◆ finalize()

StatusCode BesRndmGenSvc::finalize ( )

Definition at line 254 of file BesRndmGenSvc.cxx.

255{
256 MsgStream log(messageService(), name());
257 log << MSG::INFO << " FINALISING " << endreq;
258 return Service::finalize();
259}

◆ GetEngine()

CLHEP::HepRandomEngine * BesRndmGenSvc::GetEngine ( const std::string & StreamName)

Interface to the CLHEP engine.

Definition at line 262 of file BesRndmGenSvc.cxx.

263{
264 engineConstIter citer = m_engines->find(StreamName);
265 if ( citer == m_engines->end() )
266 {
267 m_engines->insert( engineValType( StreamName, new CLHEP::RanluxEngine() ) );
268 SetStreamSeeds ( StreamName );
269 }
270
271 engineIter iter = m_engines->find(StreamName);
272 return (CLHEP::HepRandomEngine*)(*iter).second;
273}

Referenced by handle(), and initialize().

◆ getGenseed()

long BesRndmGenSvc::getGenseed ( )
inline

Definition at line 58 of file BesRndmGenSvc.h.

58{ return genSeed; }

◆ handle()

void BesRndmGenSvc::handle ( const Incident & inc)

IIncidentListener implementation. Handles EndEvent incident.

Definition at line 209 of file BesRndmGenSvc.cxx.

209 {
210 MsgStream log( messageService(), name() );
211 log << MSG::DEBUG << " Handle EndEvent " << endreq;
212
213 if ( inc.type() == "EndEvent")
214 {
215
216 m_engines_copy.clear();
217 for (engineConstIter i = begin(); i != end(); ++i)
218 {
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]);
224 }
225 m_engines_copy.insert(
226 std::map<std::string, std::vector<long int> >::value_type( (*i).first,
227 tseeds ) );
228 }
229 // Write the status of the Service into a file
230/*
231 ofstream outfile( ofile.c_str() );
232 if ( !outfile )
233 {
234 log <<MSG::ERROR << "error: unable to open: " << ofile << endreq;
235 }
236 else
237 {
238 for (std::map<std::string, std::vector<long int> >::const_iterator i = m_engines_copy.begin();
239 i != m_engines_copy.end();
240 ++i)
241 {
242 outfile << (*i).first;
243 for(unsigned int j=0; j<((*i).second).size(); j++)
244 outfile << " " << (*i).second[j];
245 outfile <<"\n";
246 }
247 }
248*/
249// print();
250 }
251}
XmlRpcServer s
engineConstIter begin(void) const
CLHEP::HepRandomEngine * GetEngine(const std::string &StreamName)
Interface to the CLHEP engine.
engineConstIter end(void) const

◆ initialize()

StatusCode BesRndmGenSvc::initialize ( )

Gaudi Service Implementation.

Incident Service

Definition at line 105 of file BesRndmGenSvc.cxx.

106{
107 MsgStream log( messageService(), name() );
108 log << MSG::INFO << "Initializing " << name()
109 << " - package version " << PACKAGE_VERSION
110 << "\n INITIALISING RANDOM NUMBER STREAMS. " << endreq;
111
112
113 if (!(Service::initialize().isSuccess())) {
114 return StatusCode::FAILURE;
115 }
116
117 //set up different stream seeds by default seed
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;
125
126 /// Incident Service
127 IIncidentSvc* pIncSvc(0);
128
129 // set up the incident service:
130 if (!(service("IncidentSvc", pIncSvc, true)).isSuccess()) {
131 log << MSG::ERROR
132 << "Could not locate IncidentSvc "
133 << endreq;
134 return StatusCode::FAILURE;
135 }
136
137 //start listening to "EndEvent"
138 static const int PRIORITY = 100;
139 pIncSvc->addListener(this, "EndEvent", PRIORITY);
140
141 if (m_read_from_file)
142 {
143 // Read from a file
144 ifstream infile( m_file_to_read.c_str() );
145 if ( !infile )
146 {
147 log << MSG::ERROR << " Unable to open: " << m_file_to_read <<endreq;
148 return StatusCode::FAILURE;
149 }
150 else
151 {
152 std::string buffer;
153 while (std::getline(infile, buffer))
154 {
155 string stream;
156 std::vector<unsigned long> v;
157 //split the space-separated string in 3 words:
158 if (interpretSeeds(buffer, stream, v)) {
159 log << MSG::DEBUG << " INITIALISING " << stream << " stream, "<< " read from file " <<m_file_to_read << endreq;
160 CLHEP::HepRandomEngine* engine = GetEngine(stream);
161 engine->get(v);
162 } else {
163 log << MSG::ERROR << "bad line\n" << buffer
164 << "\n in input file " << m_file_to_read << endreq;
165 return StatusCode::FAILURE;
166 }
167 }
168
169 }
170 }
171
172 // Create the various streams according to user's request
173 for (VStrings::const_iterator i = m_streams_seeds.begin(); i != m_streams_seeds.end(); ++i)
174 {
175 string stream;
176 std::vector<unsigned long> v;
177 //split the space-separated string in 3 words:
178 if (interpretSeeds(*i, stream, v)) {
179 log << MSG::VERBOSE << "Seeds property: stream " << stream << endreq;
180 } else {
181 log << MSG::ERROR << "bad Seeds property\n" << *i << endreq;
182 return StatusCode::FAILURE;
183 }
184
185 // Check if stream already generated (e.g. from reading a file)
186 bool not_found = true;
187 if ( number_of_streams() != 0 )
188 {
190 do
191 {
192 if ((*sf).first == stream) not_found = false;
193 ++sf;
194 } while (sf != end() && not_found);
195 }
196
197 if (not_found)
198 {
199 log << MSG::DEBUG << " INITIALISING " << stream << endreq;
200 CreateStream(v[0], stream);
201 }
202
203 }
204
205 return StatusCode::SUCCESS;
206}
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
Definition KarLud.h:35
void CreateStream(long seed, const std::string &StreamName)
unsigned int number_of_streams(void) const

◆ number_of_streams()

unsigned int BesRndmGenSvc::number_of_streams ( void ) const
inline

Definition at line 136 of file BesRndmGenSvc.h.

137{ return m_engines->size(); }

Referenced by initialize().

◆ print() [1/2]

void BesRndmGenSvc::print ( const std::string & StreamName)

Print methods.

Definition at line 330 of file BesRndmGenSvc.cxx.

331{
332 MsgStream log(messageService(), name());
333 engineConstIter citer = m_engines->find(StreamName);
334 if ( citer == m_engines->end() )
335 {
336 log << MSG::WARNING << " Stream = " << StreamName << " NOT FOUND" << endreq;
337 }
338 else
339 {
340 const long s = ((*citer).second)->getSeed();
341 log << MSG::INFO << " Stream = " << StreamName << ", Seed = "
342 << s << endreq;
343 }
344}

◆ print() [2/2]

void BesRndmGenSvc::print ( void )

Definition at line 347 of file BesRndmGenSvc.cxx.

348{
349 print( m_StreamName );
350}

Referenced by print().

◆ setGenseed()

void BesRndmGenSvc::setGenseed ( long i)
inline

Definition at line 57 of file BesRndmGenSvc.h.

57{ genSeed = i; }

◆ setOnDefinedSeeds()

CLHEP::HepRandomEngine * BesRndmGenSvc::setOnDefinedSeeds ( int EventNumber,
const std::string & StreamName )

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

Definition at line 353 of file BesRndmGenSvc.cxx.

354{
355 engineConstIter citer = m_engines->find(StreamName);
356 if ( citer == m_engines->end() ) m_engines->insert( engineValType( StreamName,
357 new CLHEP::RanluxEngine() ) );
358 engineIter iter = m_engines->find(StreamName);
359 long hashedStream;
360 // (SG::simpleStringHash(StreamName));
361 long theseed = 10000*EventNumber + hashedStream;
362 ((*iter).second)->setSeed( theseed, 3 );
363 return (CLHEP::HepRandomEngine*)(*iter).second;
364}

Friends And Related Symbol Documentation

◆ SvcFactory< BesRndmGenSvc >

friend class SvcFactory< BesRndmGenSvc >
friend

Definition at line 113 of file BesRndmGenSvc.h.


The documentation for this class was generated from the following files: