|
ATLAS Offline Software
|
Go to the documentation of this file.
5 #include "GaudiKernel/ISvcLocator.h"
6 #include "GaudiKernel/IIncidentSvc.h"
7 #include "GaudiKernel/Incident.h"
8 #include "GaudiKernel/DataIncident.h"
9 #include "GaudiKernel/ServiceHandle.h"
16 #include "CLHEP/Random/RandGauss.h"
30 m_engines(), m_engines_copy() {
51 (
"Initializing " <<
name() <<
"\n INITIALISING RANDOM NUMBER STREAMS. ");
60 static const int PRIORITY = 100;
61 pIncSvc->addListener(
this,
"EndEvent", PRIORITY);
62 pIncSvc->addListener(
this,
"AfterReseedIncident", PRIORITY);
67 pIncSvc->addListener(
this,
"BeginEvent", PRIORITY);
68 pIncSvc->addListener(
this,
"ReseedIncident", PRIORITY);
70 pIncSvc.release().ignore();
77 return StatusCode::FAILURE;
82 std::vector<uint32_t> seeds;
86 <<
" INITIALISING " <<
stream <<
" stream with seeds ";
87 for (std::vector<uint32_t>::const_iterator
i = seeds.begin();
i != seeds.end(); ++
i){
95 msg() << ((*i) & 0xffffffff
u) <<
" ";
100 <<
stream <<
" stream initialized succesfully" <<
endmsg;
104 return StatusCode::FAILURE;
110 return StatusCode::FAILURE;
124 <<
", reseeding offset " <<
offset);
127 return StatusCode::FAILURE;
131 bool not_found(
true);
134 while (
sf !=
end() && (not_found=((*sf).first !=
stream))) ++
sf;
139 (
" INITIALISING " <<
stream <<
" stream with seeds "
152 return StatusCode::SUCCESS;
158 if ( inc.type() ==
"EndEvent" ||
159 inc.type() ==
"AfterReseedIncident" )
164 CLHEP::HepRandomEngine* engine =
GetEngine(iE->first);
165 std::vector<unsigned long>
v = engine->put();
166 std::vector<uint32_t> tseeds(
v.size());
167 for (
size_t i=0;
i<
v.size(); ++
i) {
175 tseeds[
i] = (
v[
i] & 0xffffffff
u);
182 }
else if (inc.type() ==
"BeginEvent") {
184 EventContext context = inc.context();
185 const EventIDBase& ei = context.eventID();
196 throw GaudiException(
"can not reseed all streams ",
name(), StatusCode::FAILURE);
199 const string& strName(*
i++);
203 throw GaudiException(
string(
"can not reseed stream ") + strName,
204 name(), StatusCode::FAILURE);
207 <<
" for random service " <<
endmsg;
212 else if (inc.type() ==
"ReseedIncident") {
213 typedef ContextIncident<std::pair<unsigned,unsigned> > Ctxt;
214 const Ctxt* incident =
dynamic_cast<const Ctxt*
>(&inc);
215 const std::pair<unsigned,unsigned>&
data = incident->tag();
226 throw GaudiException(
"can not reseed all streams ",
name(), StatusCode::FAILURE);
229 const string& strName(*
i++);
233 throw GaudiException(
string(
"can not reseed stream ") + strName,
234 name(), StatusCode::FAILURE);
237 <<
" for random service " <<
endmsg;
254 for (std::map<std::string, std::vector<uint32_t> >::const_iterator
i =
m_engines_copy.begin();
258 for (std::vector<uint32_t>::const_iterator j = (*i).second.begin(); j !=(*i).second.end(); ++j){
266 return StatusCode::SUCCESS;
279 return (CLHEP::HepRandomEngine*)(*iter).second;
284 long seeds[3] = { (long)
seed1, (
long)
seed2, 0 };
285 const long*
s = seeds;
290 ((*iter).second)->setSeeds(
s, 0);
298 std::vector<unsigned long> longSeeds(seeds.size());
299 for (
size_t i=0;
i<seeds.size(); ++
i) longSeeds[
i]=seeds[
i];
300 return (((*iter).second)->getState( longSeeds ));
323 (
" INITIALISING " <<
StreamName <<
" stream with DEFAULT seeds "
326 long seeds[3] = { (long)
seed1, (
long)
seed2, 0 };
327 const long*
s = seeds;
329 ((*iter).second)->setSeeds(
s,0);
338 std::vector<unsigned long>
v = ((*citer).second)->put();
340 for (std::vector<unsigned long>::const_iterator
i =
v.begin();
i !=
v.end(); ++
i){
348 msg() << ((*i) & 0xffffffff
u) <<
" ";
366 if (hasOffset) theHash=
crc_combine(theHash, citer->second);
386 CLHEP::HepRandomEngine* eng = (*iter).second;
387 eng->setSeed( theSeed, 0 );
388 return (CLHEP::HepRandomEngine*)eng;
AtDSFMTGenSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
char data[hepevt_bytes_allocation_ATLAS]
engineMap::iterator engineIter
long m_PYTHIA_default_seed2
virtual void handle(const Incident &) override
IIncidentListener implementation. Handles EndEvent incident.
std::map< std::string, std::vector< uint32_t > > m_engines_copy
Random engine copy (for output to a file)
engineMap::const_iterator engineConstIter
Gaudi::Property< bool > m_save_to_file
should current engine status be saved to file ?
virtual bool setAllOnDefinedSeeds(uint32_t theSeed) override
seed all streams we manage, combining theSeed and the stream names
virtual void CreateStream(uint32_t seed1, uint32_t seed2, const std::string &streamName) override
virtual void print(void) override
Gaudi::Property< bool > m_read_from_file
read engine status from file
#define ATH_MSG_VERBOSE(x)
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &streamName) override
unsigned int number_of_streams(void) const
virtual StatusCode finalize() override
@ u
Enums for curvilinear frames.
Gaudi::Property< bool > m_eventReseed
reseed for every event
void SetStreamSeeds(const std::string &StreamName)
long m_PYTHIA_default_seed1
virtual StatusCode initialize() override
uint32_t crc_combine(uint32_t seed, uint32_t v)
using crc32 for architecture independence in combining the seeds
engineConstIter end(void) const
Gaudi::Property< std::string > m_file_to_read
name of the file to read the engine status from
::StatusCode StatusCode
StatusCode definition for legacy code.
StringArrayProperty m_reseedStreamNames
streams to be reseeded for every event
std::map< std::string, uint32_t > m_reseedingOffsets
optional offsets to combine to run/evt no when reseeding.
long m_HERWIG_default_seed1
virtual CLHEP::HepRandomEngine * setOnDefinedSeeds(uint32_t theSeed, const std::string &streamName) override
bool interpretSeeds(const std::string &buffer, std::string &stream, uint32_t &seed1, uint32_t &seed2, short &luxury, uint32_t &offset)
AthROOTErrorHandlerSvc * svc
void setFlag(TrigPassFlags *flags, const T *obj, const CONTAINER *container, const std::vector< bool > &flag)
Set the flag at index position.
engineConstIter begin(void) const
#define ATH_MSG_WARNING(x)
A random number engine manager, based on dSFMT. http://www.math.sci.hiroshima-u.ac....
virtual ~AtDSFMTGenSvc()
Standard Destructor.
engineMap::value_type engineValType
StringArrayProperty m_streams_seeds
seeds for the engines, this is a vector of strings of the form "EnginName Seed1 Seed2"
long m_HERWIG_default_seed2
Gaudi::Property< std::string > m_file_to_write
name of the file to save the engine status to.