BOSS 6.6.4.p01
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 ()
 
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvInterface)
 
void handle (const Incident &)
 IIncidentListener implementation. Handles EndEvent incident.
 
- Public Member Functions inherited from IBesRndmGenSvc
virtual CLHEP::HepRandomEngine * GetEngine (const std::string &StreamName)=0
 Interface to the CLHEP engine.
 
virtual void CreateStream (long seed1, const std::string &StreamName)=0
 
virtual CLHEP::HepRandomEngine * setOnDefinedSeeds (int EventNumber, const std::string &StreamName)=0
 set the seeds for an engine. First param will usually be the event number
 
virtual void print (const std::string &StreamName)=0
 Print methods.
 
virtual void print ()=0
 
virtual void setGenseed (long)=0
 
virtual long getGenseed ()=0
 
virtual ~IBesRndmGenSvc ()
 

Protected Member Functions

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

Friends

class SvcFactory< BesRndmGenSvc >
 

Additional Inherited Members

- Static Public Member Functions inherited from IBesRndmGenSvc
static const InterfaceID & interfaceID ()
 Gaudi boilerplate.
 

Detailed Description

Definition at line 34 of file BesRndmGenSvc.h.

Member Typedef Documentation

◆ engineConstIter

typedef engineMap::const_iterator BesRndmGenSvc::engineConstIter

Definition at line 49 of file BesRndmGenSvc.h.

◆ engineIter

typedef engineMap::iterator BesRndmGenSvc::engineIter

Definition at line 48 of file BesRndmGenSvc.h.

◆ engineMap

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

CLHEP engines typedefs:

Definition at line 47 of file BesRndmGenSvc.h.

◆ engineValType

typedef 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 
)
protected

Standard Constructor.

Definition at line 39 of file BesRndmGenSvc.cxx.

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

◆ ~BesRndmGenSvc()

BesRndmGenSvc::~BesRndmGenSvc ( )
protectedvirtual

Standard Destructor.

Definition at line 77 of file BesRndmGenSvc.cxx.

78{
79 delete m_engines;
80}

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 
)
virtual

Implements IBesRndmGenSvc.

Definition at line 273 of file BesRndmGenSvc.cxx.

274{
275 engineConstIter citer = m_engines->find(StreamName);
276 if ( citer == m_engines->end() ) m_engines->insert( engineValType( StreamName,
277 new CLHEP::RanluxEngine() ) );
278 engineIter iter = m_engines->find(StreamName);
279 ((*iter).second)->setSeed( seed, 3 );
280}
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
engineMap::const_iterator engineConstIter
Definition: BesRndmGenSvc.h:49
engineMap::value_type engineValType
Definition: BesRndmGenSvc.h:50
engineMap::iterator engineIter
Definition: BesRndmGenSvc.h:48

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 251 of file BesRndmGenSvc.cxx.

252{
253 MsgStream log(messageService(), name());
254 log << MSG::INFO << " FINALISING " << endreq;
255 return Service::finalize();
256}

◆ GetEngine()

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

Interface to the CLHEP engine.

Implements IBesRndmGenSvc.

Definition at line 259 of file BesRndmGenSvc.cxx.

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

Referenced by handle(), and initialize().

◆ getGenseed()

long BesRndmGenSvc::getGenseed ( )
inlinevirtual

Implements IBesRndmGenSvc.

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 206 of file BesRndmGenSvc.cxx.

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

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

◆ 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)
virtual

Print methods.

Implements IBesRndmGenSvc.

Definition at line 327 of file BesRndmGenSvc.cxx.

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

◆ print() [2/2]

void BesRndmGenSvc::print ( void  )
virtual

Implements IBesRndmGenSvc.

Definition at line 344 of file BesRndmGenSvc.cxx.

345{
346 print( m_StreamName );
347}
void print(void)

Referenced by print().

◆ queryInterface()

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

Definition at line 88 of file BesRndmGenSvc.cxx.

89{
90 if ( IBesRndmGenSvc::interfaceID().versionMatch(riid) ) {
91 *ppvInterface = (IBesRndmGenSvc*)this;
92 }
93 else {
94 // Interface is not directly available: try out a base class
95 return Service::queryInterface(riid, ppvInterface);
96 }
97 addRef();
98 return StatusCode::SUCCESS;
99}
manage multiple CLHEP random engines as named streams
static const InterfaceID & interfaceID()
Gaudi boilerplate.

◆ setGenseed()

void BesRndmGenSvc::setGenseed ( long  i)
inlinevirtual

Implements IBesRndmGenSvc.

Definition at line 57 of file BesRndmGenSvc.h.

57{ genSeed = i; }

◆ setOnDefinedSeeds()

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.

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

Friends And Related Function 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: