ATLAS Offline Software
Loading...
Searching...
No Matches
AtRanluxGenSvc Class Reference

The default ATLAS random number engine manager, based on Ranlux64. More...

#include <AtRanluxGenSvc.h>

Inheritance diagram for AtRanluxGenSvc:
Collaboration diagram for AtRanluxGenSvc:

Public Types

CLHEP engines typedefs:
typedef std::map< std::string, CLHEP::Ranlux64Engine * > engineMap
typedef engineMap::iterator engineIter
typedef engineMap::const_iterator engineConstIter
typedef engineMap::value_type engineValType

Public Member Functions

Interface to the CLHEP engine
virtual CLHEP::HepRandomEngine * GetEngine (const std::string &streamName) override
virtual void CreateStream (uint32_t seed1, uint32_t seed2, const std::string &streamName) override
bool CreateStream (const std::vector< uint32_t > &seeds, const std::string &streamName)
Stream access
engineConstIter begin (void) const
engineConstIter end (void) const
unsigned int number_of_streams (void) const
virtual void print (const std::string &streamName) override
virtual void print (void) override
void createStream (uint32_t seed1, uint32_t seed2, const std::string &streamName, short luxLevel)
 allows to specify luxLevel
virtual CLHEP::HepRandomEngine * setOnDefinedSeeds (uint32_t theSeed, const std::string &streamName) override
virtual CLHEP::HepRandomEngine * setOnDefinedSeeds (uint32_t eventNumber, uint32_t runNumber, const std::string &streamName) override
CLHEP::HepRandomEngine * oldSetOnDefinedSeeds (uint32_t theSeed, const std::string &streamName)
 broken, temporarily keep for backward compatibility
CLHEP::HepRandomEngine * oldSetOnDefinedSeeds (uint32_t eventNumber, uint32_t runNumber, const std::string &streamName)
 broken, temporarily keep for backward compatibility
virtual bool setAllOnDefinedSeeds (uint32_t theSeed) override
 seed all streams we manage, combining theSeed and the stream names
virtual bool setAllOnDefinedSeeds (uint32_t eventNumber, uint32_t runNumber) override
 seed all streams, combining eventNumber, runNumber and the stream names
Gaudi Service Implementation
virtual StatusCode initialize () override
virtual StatusCode finalize () override
virtual void handle (const Incident &) override
 IIncidentListener implementation. Handles EndEvent incident.

Private Attributes

Properties
StringArrayProperty m_streams_seeds
 seeds for the engines, this is a vector of strings of the form "EnginName Seed1 Seed2"
Gaudi::Property< bool > m_read_from_file {this,"ReadFromFile",false,"set/restore the status of the engine from file"}
 read engine status from file
Gaudi::Property< std::string > m_file_to_read
 name of the file to read the engine status from
Gaudi::Property< bool > m_save_to_file {this,"SaveToFile", true,"save the status of the engine to file"}
 should current engine status be saved to file ?
Gaudi::Property< std::string > m_file_to_write
 name of the file to save the engine status to.
Gaudi::Property< bool > m_eventReseed {this,"EventReseeding",true,"reseed every event using a hash of run and event numbers"}
 reseed for every event
StringArrayProperty m_reseedStreamNames {this,"ReseedStreamNames",{}, "the streams we are going to set the seeds of (default: all streams)"}
 streams to be reseeded for every event
Gaudi::Property< bool > m_useOldBrokenSeeding {this,"UseOldBrokenSeeding",false}
 backward compatibility only, broken 32/64 bits
std::map< std::string, uint32_t > m_reseedingOffsets
 optional offsets to combine to run/evt no when reseeding.
engineMap m_engines
std::map< std::string, std::vector< uint32_t > > m_engines_copy
 Random engine copy (for output to a file)
short m_defaultLuxLevel
 Ranlux luxury level to be used by default.

Default seed values

uint32_t m_default_seed1
uint32_t m_default_seed2
uint32_t m_PYTHIA_default_seed1
uint32_t m_PYTHIA_default_seed2
uint32_t m_HERWIG_default_seed1
uint32_t m_HERWIG_default_seed2
 AtRanluxGenSvc (const std::string &name, ISvcLocator *svc)
 Standard Gaudi Constructor.
virtual ~AtRanluxGenSvc ()
 Standard Destructor.
void SetStreamSeeds (const std::string &streamName)

Detailed Description

The default ATLAS random number engine manager, based on Ranlux64.

this service mantains a number of named, independent random number sequences. Each sequence is initialized by an entry of the form "SequenceName [LUXURY luxLevel (range 0:2 default 1) ] Seed1 Seed2" in the Seeds property. For example

Seeds = [ "PYTHIA LUXURY 2 4789899 989240512",
"PYTHIA_INIT LUXURY 0 820021 2347532",
"JIMMY 390020611 821000366",
"JIMMY_INIT LUXURY 0 820021 2347532",
"HERWIG 390020611 821000366", "HERWIG_INIT 820021 2347532" ]

At the end of the job in AtRanluxGenSvc::finalize(), the status of the engine is dumped as an array of uint32_t to the ASCII file "AtRanluxGenSvc.out":

PITHIA 4010409557 1071463497 2862960128 1068652744 145815808 1072305199 2363435712 1072215177 2274024032 1071848040 1607052768 1070928280 1688486400 1071840599 2068481888 1067315347 62450688 1072023539 312153120 1070857822 2535009472 1070427845 3698875904 1070616419 3726185024 0 0 11 1 202
PITHIA_INIT 4010409557 1057836705 3838836736 1072443439 2098440704 1066892778 3689119744 1072151794 3818888768 1071853913 3574320864 1071982408 3603063712 1071718264 2168786016 1072391676 2208235040 1072000044 3037871232 1072480358 3292613248 1071901297 579757952 1065720911 3788918784 0 0 11 1 202

This file can be used to restore the status of the engine in another job by setting the properties

ReadFromFile = true
FileToRead = path_to_ascii_file

Definition at line 54 of file AtRanluxGenSvc.h.

Member Typedef Documentation

◆ engineConstIter

typedef engineMap::const_iterator AtRanluxGenSvc::engineConstIter

Definition at line 70 of file AtRanluxGenSvc.h.

◆ engineIter

typedef engineMap::iterator AtRanluxGenSvc::engineIter

Definition at line 69 of file AtRanluxGenSvc.h.

◆ engineMap

typedef std::map<std::string, CLHEP::Ranlux64Engine*> AtRanluxGenSvc::engineMap

Definition at line 68 of file AtRanluxGenSvc.h.

◆ engineValType

typedef engineMap::value_type AtRanluxGenSvc::engineValType

Definition at line 71 of file AtRanluxGenSvc.h.

Constructor & Destructor Documentation

◆ AtRanluxGenSvc()

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

Standard Gaudi Constructor.

Standard Constructor.

Definition at line 29 of file AtRanluxGenSvc.cxx.

30 : base_class(name,svc),
34{
35 // Set Default values
36 m_default_seed1 = 3591;
37 m_default_seed2 = 2309736;
38 m_PYTHIA_default_seed1 = 93453591;
42}
uint32_t m_PYTHIA_default_seed2
uint32_t m_HERWIG_default_seed1
std::map< std::string, uint32_t > m_reseedingOffsets
optional offsets to combine to run/evt no when reseeding.
short m_defaultLuxLevel
Ranlux luxury level to be used by default.
std::map< std::string, std::vector< uint32_t > > m_engines_copy
Random engine copy (for output to a file)
uint32_t m_default_seed1
uint32_t m_default_seed2
uint32_t m_HERWIG_default_seed2
engineMap m_engines
uint32_t m_PYTHIA_default_seed1

◆ ~AtRanluxGenSvc()

AtRanluxGenSvc::~AtRanluxGenSvc ( )
virtual

Standard Destructor.

Definition at line 46 of file AtRanluxGenSvc.cxx.

47{
48 engineIter i(m_engines.begin()), e(m_engines.end());
49 while (i != e) delete (i++)->second;
50}
engineMap::iterator engineIter

Member Function Documentation

◆ begin()

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

Definition at line 173 of file AtRanluxGenSvc.h.

174{ return m_engines.begin(); }

◆ CreateStream() [1/2]

bool AtRanluxGenSvc::CreateStream ( const std::vector< uint32_t > & seeds,
const std::string & streamName )

Definition at line 326 of file AtRanluxGenSvc.cxx.

328{
329 engineConstIter citer = m_engines.find(streamName);
330 if ( citer == m_engines.end() )
331 m_engines.insert(engineValType(streamName,
332 new CLHEP::Ranlux64Engine() ) );
333 engineIter iter = m_engines.find(streamName);
334 std::vector<unsigned long> longSeeds(seeds.size());
335 for (size_t i=0; i<seeds.size(); ++i) longSeeds[i]=seeds[i];
336 return (((*iter).second)->getState( longSeeds ));
337}
engineMap::const_iterator engineConstIter
engineMap::value_type engineValType

◆ CreateStream() [2/2]

void AtRanluxGenSvc::CreateStream ( uint32_t seed1,
uint32_t seed2,
const std::string & streamName )
overridevirtual

Definition at line 306 of file AtRanluxGenSvc.cxx.

307 {
308 createStream(seed1, seed2, streamName, m_defaultLuxLevel);
309}
void createStream(uint32_t seed1, uint32_t seed2, const std::string &streamName, short luxLevel)
allows to specify luxLevel

◆ createStream()

void AtRanluxGenSvc::createStream ( uint32_t seed1,
uint32_t seed2,
const std::string & streamName,
short luxLevel )

allows to specify luxLevel

Definition at line 312 of file AtRanluxGenSvc.cxx.

314{
315 uint32_t seeds[2] = { seed1, seed2 };
316 const uint32_t* s = seeds;
317 engineConstIter citer = m_engines.find(streamName);
318 if ( citer == m_engines.end() )
319 m_engines.insert(engineValType(streamName,
320 new CLHEP::Ranlux64Engine(s[0], luxLevel)));
321 engineIter iter = m_engines.find(streamName);
322 ((*iter).second)->setSeed(s[0], luxLevel);
323}
setEventNumber uint32_t

◆ end()

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

Definition at line 177 of file AtRanluxGenSvc.h.

178{ return m_engines.end(); }

◆ finalize()

StatusCode AtRanluxGenSvc::finalize ( )
overridevirtual

Definition at line 265 of file AtRanluxGenSvc.cxx.

266{
267 ATH_MSG_INFO (" FINALISING ");
268
269 if (m_save_to_file) {
270 // Write the status of the Service to file
271 std::ofstream outfile( m_file_to_write.value().c_str() );
272 if ( !outfile ) {
273 ATH_MSG_ERROR ("error: unable to open: " << m_file_to_write.value());
274 } else {
275 for (std::map<std::string, std::vector<uint32_t> >::const_iterator i = m_engines_copy.begin();
276 i != m_engines_copy.end();
277 ++i) {
278 outfile << (*i).first << " ";
279 for (std::vector<uint32_t>::const_iterator j = (*i).second.begin(); j !=(*i).second.end(); ++j){
280 outfile << (*j) << " ";
281 }
282 outfile << endl;
283 }
284 ATH_MSG_DEBUG (" wrote seeds to " << m_file_to_write.value() );
285
286 }
287 }
288 return StatusCode::SUCCESS;
289}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Gaudi::Property< std::string > m_file_to_write
name of the file to save the engine status to.
Gaudi::Property< bool > m_save_to_file
should current engine status be saved to file ?

◆ GetEngine()

CLHEP::HepRandomEngine * AtRanluxGenSvc::GetEngine ( const std::string & streamName)
overridevirtual

Definition at line 292 of file AtRanluxGenSvc.cxx.

293{
294 engineConstIter citer = m_engines.find(StreamName);
295 if ( citer == m_engines.end() )
296 {
297 m_engines.insert( engineValType( StreamName, new CLHEP::Ranlux64Engine() ) );
298 SetStreamSeeds ( StreamName );
299 }
300
301 engineIter iter = m_engines.find(StreamName);
302 return (CLHEP::HepRandomEngine*)(*iter).second;
303}
void SetStreamSeeds(const std::string &streamName)

◆ handle()

void AtRanluxGenSvc::handle ( const Incident & inc)
overridevirtual

IIncidentListener implementation. Handles EndEvent incident.

Definition at line 170 of file AtRanluxGenSvc.cxx.

170 {
171 ATH_MSG_DEBUG (" Handle EndEvent ");
172
173 if ( inc.type() == "EndEvent" ||
174 inc.type() == "AfterReseedIncident" )
175 {
176
177 m_engines_copy.clear();
178 engineConstIter iE(begin()), eE(end());
179 while(iE != eE) {
180 CLHEP::HepRandomEngine* engine = GetEngine(iE->first);
181 std::vector<unsigned long> v = engine->put();
182 std::vector<uint32_t> tseeds(v.size());
183 for (size_t i=0; i<v.size(); ++i) {
184 // The state returned is a set of 32-bit numbers.
185 // On 64-bit platforms, though, the vector holds 64-bit ints.
186 // For the first word, one gets garbage in the high 32 bits.
187 // (This is because the crc32 routine used in clhep
188 // to hash the engine names doesn't mask down to 32 bits.)
189 // Mask off the garbage to get consistent results
190 // across platforms.
191 tseeds[i] = (v[i] & 0xffffffffu);
192 }
193 m_engines_copy.insert(std::make_pair(iE->first, tseeds));
194 ++iE;
195 }
196
197 print();
198 } else if (inc.type() == "BeginEvent") {
199 ATH_MSG_DEBUG (" Handle BeginEvent ");
200 EventContext context = inc.context();
201 const EventIDBase& ei = context.eventID();
202 //clear static RandGauss cache (generates two numbers per call to shoot()
203 CLHEP::RandGauss::setFlag(false);
204 //loop over generator streams, combining the stream name to the hash
205 vector<string>::const_iterator i(m_reseedStreamNames.begin());
206 vector<string>::const_iterator e(m_reseedStreamNames.end());
207 //by default (when no streams are specified in streamNames, seed all
208 //streams
209 if (i == e) {
210 if (!(this->setAllOnDefinedSeeds(ei.event_number(),
211 ei.run_number())))
212 throw GaudiException("can not reseed all streams ", name(), StatusCode::FAILURE);
213 } else {
214 while (i != e) {
215 const string& strName(*i++);
216 if (0 == this->setOnDefinedSeeds(ei.event_number(),
217 ei.run_number(),
218 strName)) {
219 throw GaudiException(string("can not reseed stream ") + strName,
220 name(), StatusCode::FAILURE);
221 } else {
222 msg() << MSG::VERBOSE << "Reseeded stream " << strName
223 << " for random service " << endmsg;
224 }
225 }
226 }
227 }
228 else if (inc.type() == "ReseedIncident") {
229 typedef ContextIncident<std::pair<unsigned,unsigned> > Ctxt;
230 const Ctxt* incident = dynamic_cast<const Ctxt*>(&inc);
231 if (!incident) {
232 throw GaudiException(string("can not cast to ContextIncident "),
233 name(), StatusCode::FAILURE);
234 }
235 const std::pair<unsigned,unsigned>& data = incident->tag();
236 //clear static RandGauss cache (generates two numbers per call to shoot()
237 CLHEP::RandGauss::setFlag(false);
238 //loop over generator streams, combining the stream name to the hash
239 vector<string>::const_iterator i(m_reseedStreamNames.begin());
240 vector<string>::const_iterator e(m_reseedStreamNames.end());
241 //by default (when no streams are specified in streamNames, seed all
242 //streams
243 if (i == e) {
244 if (!(this->setAllOnDefinedSeeds(data.first,
245 data.second)))
246 throw GaudiException("can not reseed all streams ", name(), StatusCode::FAILURE);
247 } else {
248 while (i != e) {
249 const string& strName(*i++);
250 if (0 == this->setOnDefinedSeeds(data.first,
251 data.second,
252 strName)) {
253 throw GaudiException(string("can not reseed stream ") + strName,
254 name(), StatusCode::FAILURE);
255 } else {
256 msg() << MSG::VERBOSE << "Reseeded stream " << strName
257 << " for random service " << endmsg;
258 }
259 }
260 }
261 }
262}
#define endmsg
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
engineConstIter end(void) const
virtual bool setAllOnDefinedSeeds(uint32_t theSeed) override
seed all streams we manage, combining theSeed and the stream names
StringArrayProperty m_reseedStreamNames
streams to be reseeded for every event
engineConstIter begin(void) const
virtual CLHEP::HepRandomEngine * setOnDefinedSeeds(uint32_t theSeed, const std::string &streamName) override
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &streamName) override
virtual void print(void) override
MsgStream & msg
Definition testRead.cxx:32

◆ initialize()

StatusCode AtRanluxGenSvc::initialize ( )
overridevirtual

Incident Service

Definition at line 54 of file AtRanluxGenSvc.cxx.

55{
57 ("Initializing " << name()
58 << "\n INITIALISING RANDOM NUMBER STREAMS. ");
59
61 ServiceHandle<IIncidentSvc> pIncSvc("IncidentSvc", name());
62
63 // set up the incident service:
64 ATH_CHECK( pIncSvc.retrieve() );
65
66 //start listening to "EndEvent"
67 static const int PRIORITY = 100;
68 pIncSvc->addListener(this, "EndEvent", PRIORITY);
69 pIncSvc->addListener(this, "AfterReseedIncident", PRIORITY);
70
71 //and to BeginEvent if we are reseeding
72 if (m_eventReseed) {
73 ATH_MSG_INFO ("will be reseeded for every event");
74 pIncSvc->addListener(this, "BeginEvent", PRIORITY);
75 pIncSvc->addListener(this, "ReseedIncident", PRIORITY);
76 }
77 pIncSvc.release().ignore();
78
79
80 //3 is not valid for ranlux, but whatever, that's what we had before...
82
83 if (m_read_from_file) {
84 // Read from a file
85 ifstream infile( m_file_to_read.value().c_str() );
86 if ( !infile ) {
87 ATH_MSG_ERROR (" Unable to open: " << m_file_to_read.value());
88 return StatusCode::FAILURE;
89 } else {
90 std::string buffer;
91 while (std::getline(infile, buffer)) {
92 string stream;
93 std::vector<uint32_t> seeds;
94 //split the space-separated string in 3 words:
95 if (interpretSeeds(buffer, stream, seeds)) {
96 msg (MSG::DEBUG)
97 << " INITIALISING " << stream << " stream with seeds ";
98 for (std::vector<uint32_t>::const_iterator i = seeds.begin(); i != seeds.end(); ++i){
99 // The state returned is a set of 32-bit numbers.
100 // On 64-bit platforms, though, the vector holds 64-bit ints.
101 // For the first word, one gets garbage in the high 32 bits.
102 // (This is because the crc32 routine used in clhep
103 // to hash the engine names doesn't mask down to 32 bits.)
104 // So mask off the garbage so that we get consistent results
105 // across platforms.
106 msg() << ((*i) & 0xffffffffu) << " ";
107 }
108 msg() << " read from file " << m_file_to_read.value() << endmsg;
109 if (CreateStream(seeds, stream)) {
110 msg(MSG::DEBUG)
111 << stream << " stream initialized succesfully" <<endmsg;
112 } else {
113 msg(MSG::ERROR)
114 << stream << " stream FAILED to initialize" <<endmsg;
115 return StatusCode::FAILURE;
116 }
117 } else {
118 msg(MSG::ERROR)
119 << "bad line\n" << buffer
120 << "\n in input file " << m_file_to_read.value() << endmsg;
121 return StatusCode::FAILURE;
122 }
123 }
124
125 }
126 }
127 // Create the various streams according to user's request
128 //for (VStrings::const_iterator i = m_streams_seeds.begin(); i != m_streams_seeds.end(); ++i) {
129 for (const auto& i : m_streams_seeds) {
130 string stream;
132 //parse the stream property string
133 short ll(m_defaultLuxLevel); // temp copy so we don't overwrite default
134 if (interpretSeeds(i, stream, seed1, seed2, ll, offset)) {
135 ATH_MSG_VERBOSE("Seeds property: stream " << stream
136 << " seeds " << seed1 << ' ' << seed2
137 << ", luxury level " << ll
138 << ", reseeding offset " << offset);
139 } else {
140 ATH_MSG_ERROR("bad Seeds property\n" << i);
141 return StatusCode::FAILURE;
142 }
143
144 // Check if stream already generated (e.g. from reading a file)
145 bool not_found(true);
146 if ( number_of_streams() != 0 ) {
148 while (sf != end() && (not_found=((*sf).first != stream))) ++sf;
149 }
150
151 if (not_found) {
153 (" INITIALISING " << stream << " stream with seeds "
154 << seed1 << " " << seed2);
155 createStream(seed1, seed2, stream, ll);
156 if (m_eventReseed) {
157 m_reseedingOffsets.insert(std::make_pair(stream, offset));
158 // apply the offset we just inserted
159 ATH_MSG_DEBUG("Applying reseeding offset " << offset <<
160 " to stream " << stream);
161 this->setOnDefinedSeeds(seed1, seed2, stream);
162 }
163 }
164
165 }
166 return StatusCode::SUCCESS;
167}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
virtual void CreateStream(uint32_t seed1, uint32_t seed2, const std::string &streamName) override
unsigned int number_of_streams(void) const
Gaudi::Property< std::string > m_file_to_read
name of the file to read the engine status from
StringArrayProperty m_streams_seeds
seeds for the engines, this is a vector of strings of the form "EnginName Seed1 Seed2"
Gaudi::Property< bool > m_eventReseed
reseed for every event
Gaudi::Property< bool > m_read_from_file
read engine status from file
Gaudi::Property< bool > m_useOldBrokenSeeding
backward compatibility only, broken 32/64 bits
bool interpretSeeds(const std::string &buffer, std::string &stream, uint32_t &seed1, uint32_t &seed2, short &luxury, uint32_t &offset)
long long ll
str infile
Definition run.py:13

◆ number_of_streams()

unsigned int AtRanluxGenSvc::number_of_streams ( void ) const
inline

Definition at line 181 of file AtRanluxGenSvc.h.

182{ return m_engines.size(); }

◆ oldSetOnDefinedSeeds() [1/2]

CLHEP::HepRandomEngine * AtRanluxGenSvc::oldSetOnDefinedSeeds ( uint32_t eventNumber,
uint32_t runNumber,
const std::string & streamName )

broken, temporarily keep for backward compatibility

Definition at line 444 of file AtRanluxGenSvc.cxx.

446{
447 engineConstIter citer = m_engines.find(streamName);
448 if ( citer == m_engines.end() )
449 m_engines.insert( engineValType(streamName, new CLHEP::Ranlux64Engine() ) );
450 engineIter iter = m_engines.find(streamName);
451 int hashedStream(SG::simpleStringHash(streamName));
452 long seeds[2] = { (long)(1000*runNumber + hashedStream),
453 (long)eventNumber };
454 assert( seeds[0] > 0 );
455 assert( seeds[1] > 0 );
456 const long* s = seeds;
457 ((*iter).second)->setSeed( s[0], m_defaultLuxLevel);
458 return (CLHEP::HepRandomEngine*)(*iter).second;
459}
int simpleStringHash(const std::string &str, int maxInt=0xFFFF)
simple hash function derived from Sedgewick Algorithms in C++ 3rd ed

◆ oldSetOnDefinedSeeds() [2/2]

CLHEP::HepRandomEngine * AtRanluxGenSvc::oldSetOnDefinedSeeds ( uint32_t theSeed,
const std::string & streamName )

broken, temporarily keep for backward compatibility

Definition at line 462 of file AtRanluxGenSvc.cxx.

463 {
464 engineConstIter citer = m_engines.find(streamName);
465 if ( citer == m_engines.end() )
466 m_engines.insert( engineValType(streamName, new CLHEP::Ranlux64Engine() ) );
467 engineIter iter = m_engines.find(streamName);
468 int hashedStream(SG::simpleStringHash(streamName));
469 long seeds[2] = { (long)(hashedStream % (theSeed+13)),
470 (long)theSeed };
471 assert( seeds[0] > 0 );
472 assert( seeds[1] > 0 );
473 const long* s = seeds;
474 ((*iter).second)->setSeed( s[0], m_defaultLuxLevel );
475 return (CLHEP::HepRandomEngine*)(*iter).second;
476}

◆ print() [1/2]

void AtRanluxGenSvc::print ( const std::string & streamName)
overridevirtual

Definition at line 370 of file AtRanluxGenSvc.cxx.

371{
372 engineConstIter citer = m_engines.find(StreamName);
373 if ( citer == m_engines.end() ) {
374 ATH_MSG_WARNING (" Stream = " << StreamName << " NOT FOUND");
375 } else {
376 std::vector<unsigned long> v = ((*citer).second)->put();
377 msg(MSG::INFO) << " Stream = " << StreamName << " ";
378 for (std::vector<unsigned long>::const_iterator i = v.begin(); i != v.end(); ++i){
379 // The state returned is a set of 32-bit numbers.
380 // On 64-bit platforms, though, the vector holds 64-bit ints.
381 // For the first word, one gets garbage in the high 32 bits.
382 // (This is because the crc32 routine used in clhep
383 // to hash the engine names doesn't mask down to 32 bits.)
384 // So mask off the garbage so that we get consistent results
385 // across platforms.
386 msg() << ((*i) & 0xffffffffu) << " ";
387 }
388 msg() << endmsg;
389 }
390}
#define ATH_MSG_WARNING(x)

◆ print() [2/2]

void AtRanluxGenSvc::print ( void )
overridevirtual

Definition at line 393 of file AtRanluxGenSvc.cxx.

394{
395 for (engineConstIter i = m_engines.begin(); i != m_engines.end(); ++i)
396 print( (*i).first );
397}

◆ setAllOnDefinedSeeds() [1/2]

bool AtRanluxGenSvc::setAllOnDefinedSeeds ( uint32_t eventNumber,
uint32_t runNumber )
overridevirtual

seed all streams, combining eventNumber, runNumber and the stream names

Definition at line 480 of file AtRanluxGenSvc.cxx.

481{
482 bool allOK(true);
483 engineIter i(m_engines.begin()), e(m_engines.end());
484 while (i!=e &&
485 (allOK=(0 != this->setOnDefinedSeeds(eventNumber,
486 runNumber,
487 (*i++).first)))) {
488 /*empty*/
489 }
490 return allOK;
491}

◆ setAllOnDefinedSeeds() [2/2]

bool AtRanluxGenSvc::setAllOnDefinedSeeds ( uint32_t theSeed)
overridevirtual

seed all streams we manage, combining theSeed and the stream names

Definition at line 494 of file AtRanluxGenSvc.cxx.

494 {
495 bool allOK(true);
496 engineIter i(m_engines.begin()), e(m_engines.end());
497 while (i!=e &&
498 (allOK=(0 != this->setOnDefinedSeeds(theSeed, (*i++).first)))) {
499 /*empty*/
500 }
501 return allOK;
502}

◆ setOnDefinedSeeds() [1/2]

CLHEP::HepRandomEngine * AtRanluxGenSvc::setOnDefinedSeeds ( uint32_t eventNumber,
uint32_t runNumber,
const std::string & streamName )
overridevirtual

Definition at line 400 of file AtRanluxGenSvc.cxx.

402{
404 return oldSetOnDefinedSeeds(eventNumber, runNumber, streamName);
405 // do it properly
406 uint32_t theHash(eventNumber);
407 map<string, uint32_t>::const_iterator citer(m_reseedingOffsets.find(streamName));
408 bool hasOffset(citer != m_reseedingOffsets.end() && 0 != citer->second);
409 if (hasOffset) theHash=crc_combine(theHash, citer->second);
410
411 theHash=crc_combine(theHash, runNumber);
412 ATH_MSG_VERBOSE( "Reseeding stream " << streamName
413 << " with eventNumber " << eventNumber
414 << " runNumber " << runNumber);
415 if (hasOffset) ATH_MSG_VERBOSE("Applied offset " << citer->second);
416 return this->setOnDefinedSeeds(theHash, streamName);
417}
uint32_t crc_combine(uint32_t seed, uint32_t v)
using crc32 for architecture independence in combining the seeds
CLHEP::HepRandomEngine * oldSetOnDefinedSeeds(uint32_t theSeed, const std::string &streamName)
broken, temporarily keep for backward compatibility

◆ setOnDefinedSeeds() [2/2]

CLHEP::HepRandomEngine * AtRanluxGenSvc::setOnDefinedSeeds ( uint32_t theSeed,
const std::string & streamName )
overridevirtual

create engine if not found. FIXME this may not be a good idea

Definition at line 420 of file AtRanluxGenSvc.cxx.

421 {
423 return oldSetOnDefinedSeeds(theSeed, streamName);
424 //do it propertly
425 engineConstIter citer = m_engines.find(streamName);
427 if ( citer == m_engines.end() )
428 m_engines.insert(engineValType(streamName,
429 new CLHEP::Ranlux64Engine() ) );
430
431 engineIter iter = m_engines.find(streamName);
432 theSeed=crc_combine(theSeed, streamName);
433 ATH_MSG_DEBUG("Reseeding stream " << streamName << " with " << theSeed);
434 CLHEP::Ranlux64Engine* eng = (*iter).second;
435 //Ranlux64 takes a long as seed and makes a test on the sign of the seed
436 //so let's make sure that our seed is presented to Ranlux64 as a 32 bit
437 //signed int
438 eng->setSeed( (int32_t)theSeed, eng->getLuxury() );
439 return eng;
440}

◆ SetStreamSeeds()

void AtRanluxGenSvc::SetStreamSeeds ( const std::string & streamName)
private

Definition at line 340 of file AtRanluxGenSvc.cxx.

341{
344 if (StreamName == "PYTHIA")
345 {
348 }
349 else if (StreamName == "HERWIG")
350 {
353 }
354 else
355 {
358 }
360 (" INITIALISING " << StreamName << " stream with DEFAULT seeds "
361 << seed1 << " " << seed2);
362
363 uint32_t seeds[2] = { seed1, seed2 };
364 const uint32_t* s = seeds;
365 engineIter iter = m_engines.find(StreamName);
366 ((*iter).second)->setSeed(s[0]); //FIXME no need to set luxLevel?
367}

Member Data Documentation

◆ m_default_seed1

uint32_t AtRanluxGenSvc::m_default_seed1
private

Definition at line 153 of file AtRanluxGenSvc.h.

◆ m_default_seed2

uint32_t AtRanluxGenSvc::m_default_seed2
private

Definition at line 154 of file AtRanluxGenSvc.h.

◆ m_defaultLuxLevel

short AtRanluxGenSvc::m_defaultLuxLevel
private

Ranlux luxury level to be used by default.

Definition at line 148 of file AtRanluxGenSvc.h.

◆ m_engines

engineMap AtRanluxGenSvc::m_engines
private

Definition at line 145 of file AtRanluxGenSvc.h.

◆ m_engines_copy

std::map<std::string, std::vector<uint32_t> > AtRanluxGenSvc::m_engines_copy
private

Random engine copy (for output to a file)

Definition at line 147 of file AtRanluxGenSvc.h.

◆ m_eventReseed

Gaudi::Property<bool> AtRanluxGenSvc::m_eventReseed {this,"EventReseeding",true,"reseed every event using a hash of run and event numbers"}
private

reseed for every event

Definition at line 134 of file AtRanluxGenSvc.h.

134{this,"EventReseeding",true,"reseed every event using a hash of run and event numbers"};

◆ m_file_to_read

Gaudi::Property<std::string> AtRanluxGenSvc::m_file_to_read
private
Initial value:
{this,"FileToRead",this->name()+".out",
"name of a ASCII file, usually produced by AtRanLuxGenSvc itself at the end of a job, "
"containing the information to fully set/restore the status of Ranlux64"
}

name of the file to read the engine status from

Definition at line 126 of file AtRanluxGenSvc.h.

126 {this,"FileToRead",this->name()+".out",
127 "name of a ASCII file, usually produced by AtRanLuxGenSvc itself at the end of a job, " \
128 "containing the information to fully set/restore the status of Ranlux64"
129 };

◆ m_file_to_write

Gaudi::Property<std::string> AtRanluxGenSvc::m_file_to_write
private
Initial value:
{this,"FileToWrite",this->name()+".out",
"name of an ASCII file which will be produced on finalize, containing the information to fully set/restore the status"}

name of the file to save the engine status to.

Definition at line 131 of file AtRanluxGenSvc.h.

131 {this,"FileToWrite",this->name()+".out",
132 "name of an ASCII file which will be produced on finalize, containing the information to fully set/restore the status"};

◆ m_HERWIG_default_seed1

uint32_t AtRanluxGenSvc::m_HERWIG_default_seed1
private

Definition at line 157 of file AtRanluxGenSvc.h.

◆ m_HERWIG_default_seed2

uint32_t AtRanluxGenSvc::m_HERWIG_default_seed2
private

Definition at line 158 of file AtRanluxGenSvc.h.

◆ m_PYTHIA_default_seed1

uint32_t AtRanluxGenSvc::m_PYTHIA_default_seed1
private

Definition at line 155 of file AtRanluxGenSvc.h.

◆ m_PYTHIA_default_seed2

uint32_t AtRanluxGenSvc::m_PYTHIA_default_seed2
private

Definition at line 156 of file AtRanluxGenSvc.h.

◆ m_read_from_file

Gaudi::Property<bool> AtRanluxGenSvc::m_read_from_file {this,"ReadFromFile",false,"set/restore the status of the engine from file"}
private

read engine status from file

Definition at line 125 of file AtRanluxGenSvc.h.

125{this,"ReadFromFile",false,"set/restore the status of the engine from file"};

◆ m_reseedingOffsets

std::map<std::string, uint32_t> AtRanluxGenSvc::m_reseedingOffsets
private

optional offsets to combine to run/evt no when reseeding.

Set using OFFSET keyword of the Seeds property

Definition at line 143 of file AtRanluxGenSvc.h.

◆ m_reseedStreamNames

StringArrayProperty AtRanluxGenSvc::m_reseedStreamNames {this,"ReseedStreamNames",{}, "the streams we are going to set the seeds of (default: all streams)"}
private

streams to be reseeded for every event

Definition at line 135 of file AtRanluxGenSvc.h.

135{this,"ReseedStreamNames",{}, "the streams we are going to set the seeds of (default: all streams)"};

◆ m_save_to_file

Gaudi::Property<bool> AtRanluxGenSvc::m_save_to_file {this,"SaveToFile", true,"save the status of the engine to file"}
private

should current engine status be saved to file ?

Definition at line 130 of file AtRanluxGenSvc.h.

130{this,"SaveToFile", true,"save the status of the engine to file"};

◆ m_streams_seeds

StringArrayProperty AtRanluxGenSvc::m_streams_seeds
private
Initial value:
{this,"Seeds",{},
"seeds for the engines, a string of the form ['SequenceName [LUXURY luxLevel (range 0:2 default 1)()] "
"[OFFSET num] Seed1 Seed2', ...] where OFFSET is an optional integer that allows to change the "
"sequence of randoms for a given run/event no and SequenceName combination. Notice that "
"Seed1/Seed2 are dummy when EventReseeding is used",
"OrderedSet<std::string>"}

seeds for the engines, this is a vector of strings of the form "EnginName Seed1 Seed2"

Definition at line 117 of file AtRanluxGenSvc.h.

117 {this,"Seeds",{},
118 "seeds for the engines, a string of the form ['SequenceName [LUXURY luxLevel (range 0:2 default 1)()] " \
119 "[OFFSET num] Seed1 Seed2', ...] where OFFSET is an optional integer that allows to change the " \
120 "sequence of randoms for a given run/event no and SequenceName combination. Notice that " \
121 "Seed1/Seed2 are dummy when EventReseeding is used",
122 "OrderedSet<std::string>"};

◆ m_useOldBrokenSeeding

Gaudi::Property<bool> AtRanluxGenSvc::m_useOldBrokenSeeding {this,"UseOldBrokenSeeding",false}
private

backward compatibility only, broken 32/64 bits

Definition at line 138 of file AtRanluxGenSvc.h.

138{this,"UseOldBrokenSeeding",false};

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