BOSS 8.0.0
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 33 of file BesRndmGenSvc.h.

Member Typedef Documentation

◆ engineConstIter

typedef engineMap::const_iterator BesRndmGenSvc::engineConstIter

Definition at line 48 of file BesRndmGenSvc.h.

◆ engineIter

typedef engineMap::iterator BesRndmGenSvc::engineIter

Definition at line 47 of file BesRndmGenSvc.h.

◆ engineMap

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

CLHEP engines typedefs:

Definition at line 46 of file BesRndmGenSvc.h.

◆ engineValType

typedef engineMap::value_type BesRndmGenSvc::engineValType

Definition at line 49 of file BesRndmGenSvc.h.

Constructor & Destructor Documentation

◆ BesRndmGenSvc()

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

Standard Constructor.

Definition at line 43 of file BesRndmGenSvc.cxx.

44 : base_class( name, svc ) {
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:

Referenced by SvcFactory< BesRndmGenSvc >.

◆ ~BesRndmGenSvc()

BesRndmGenSvc::~BesRndmGenSvc ( )
virtual

Standard Destructor.

Definition at line 79 of file BesRndmGenSvc.cxx.

79{ delete m_engines; }

Member Function Documentation

◆ begin()

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

Definition at line 122 of file BesRndmGenSvc.h.

122 {
123 return m_engines->begin();
124}

Referenced by handle(), and initialize().

◆ CreateStream()

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

Definition at line 259 of file BesRndmGenSvc.cxx.

259 {
260 engineConstIter citer = m_engines->find( StreamName );
261 if ( citer == m_engines->end() )
262 m_engines->insert( engineValType( StreamName, new CLHEP::RanluxEngine() ) );
263 engineIter iter = m_engines->find( StreamName );
264 ( ( *iter ).second )->setSeed( seed, 3 );
265}
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
engineMap::const_iterator engineConstIter
engineMap::value_type engineValType
engineMap::iterator engineIter

Referenced by initialize().

◆ end()

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

Definition at line 126 of file BesRndmGenSvc.h.

126 {
127 return m_engines->end();
128}

Referenced by handle(), and initialize().

◆ finalize()

StatusCode BesRndmGenSvc::finalize ( )

Definition at line 241 of file BesRndmGenSvc.cxx.

241 {
242 MsgStream log( msgSvc(), name() );
243 log << MSG::INFO << " FINALISING " << endmsg;
244 return Service::finalize();
245}
IMessageSvc * msgSvc()

◆ GetEngine()

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

Interface to the CLHEP engine.

Definition at line 247 of file BesRndmGenSvc.cxx.

247 {
248 engineConstIter citer = m_engines->find( StreamName );
249 if ( citer == m_engines->end() )
250 {
251 m_engines->insert( engineValType( StreamName, new CLHEP::RanluxEngine() ) );
252 SetStreamSeeds( StreamName );
253 }
254
255 engineIter iter = m_engines->find( StreamName );
256 return (CLHEP::HepRandomEngine*)( *iter ).second;
257}

Referenced by handle(), and initialize().

◆ getGenseed()

long BesRndmGenSvc::getGenseed ( )
inline

Definition at line 57 of file BesRndmGenSvc.h.

57{ return genSeed; }

◆ handle()

void BesRndmGenSvc::handle ( const Incident & inc)

IIncidentListener implementation. Handles EndEvent incident.

Definition at line 200 of file BesRndmGenSvc.cxx.

200 {
201 MsgStream log( msgSvc(), name() );
202 log << MSG::DEBUG << " Handle EndEvent " << endmsg;
203
204 if ( inc.type() == "EndEvent" )
205 {
206
207 m_engines_copy.clear();
208 for ( engineConstIter i = begin(); i != end(); ++i )
209 {
210 CLHEP::HepRandomEngine* engine = GetEngine( ( *i ).first );
211 std::vector<unsigned long> s = engine->put();
212 std::vector<long int> tseeds;
213 for ( unsigned int j = 0; j < s.size(); j++ ) { tseeds.push_back( s[j] ); }
214 m_engines_copy.insert(
215 std::map<std::string, std::vector<long int>>::value_type( ( *i ).first, tseeds ) );
216 }
217 // Write the status of the Service into a file
218 /*
219 ofstream outfile( ofile.c_str() );
220 if ( !outfile )
221 {
222 log <<MSG::ERROR << "error: unable to open: " << ofile << endmsg;
223 }
224 else
225 {
226 for (std::map<std::string, std::vector<long int> >::const_iterator i =
227 m_engines_copy.begin(); i != m_engines_copy.end();
228 ++i)
229 {
230 outfile << (*i).first;
231 for(unsigned int j=0; j<((*i).second).size(); j++)
232 outfile << " " << (*i).second[j];
233 outfile <<"\n";
234 }
235 }
236 */
237 // print();
238 }
239}
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 100 of file BesRndmGenSvc.cxx.

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

130 {
131 return m_engines->size();
132}

Referenced by initialize().

◆ print() [1/2]

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

Print methods.

Definition at line 288 of file BesRndmGenSvc.cxx.

288 {
289 MsgStream log( msgSvc(), name() );
290 engineConstIter citer = m_engines->find( StreamName );
291 if ( citer == m_engines->end() )
292 { log << MSG::WARNING << " Stream = " << StreamName << " NOT FOUND" << endmsg; }
293 else
294 {
295 const long s = ( ( *citer ).second )->getSeed();
296 log << MSG::INFO << " Stream = " << StreamName << ", Seed = " << s << endmsg;
297 }
298}

◆ print() [2/2]

void BesRndmGenSvc::print ( void )

Definition at line 300 of file BesRndmGenSvc.cxx.

300{ print( m_StreamName ); }

Referenced by print().

◆ setGenseed()

void BesRndmGenSvc::setGenseed ( long i)
inline

Definition at line 56 of file BesRndmGenSvc.h.

56{ 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 302 of file BesRndmGenSvc.cxx.

303 {
304 engineConstIter citer = m_engines->find( StreamName );
305 if ( citer == m_engines->end() )
306 m_engines->insert( engineValType( StreamName, new CLHEP::RanluxEngine() ) );
307 engineIter iter = m_engines->find( StreamName );
308 // (SG::simpleStringHash(StreamName));
309 long theseed = 10000 * EventNumber;
310 ( ( *iter ).second )->setSeed( theseed, 3 );
311 return (CLHEP::HepRandomEngine*)( *iter ).second;
312}

◆ SvcFactory< BesRndmGenSvc >

friend class SvcFactory< BesRndmGenSvc >
friend

Definition at line 110 of file BesRndmGenSvc.h.


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