ATLAS Offline Software
AtRndmGenSvc.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ATRNDMGENSVC_H
6 #define ATRNDMGENSVC_H
7 
17 #include <map>
18 
19 //base classes
21 #include "GaudiKernel/IIncidentListener.h"
23 
24 #include "CLHEP/Random/RandomEngine.h"
25 #include "CLHEP/Random/RanecuEngine.h"
26 
27 class IAlgorithm;
28 class ISvcLocator;
29 class IIncident;
30 
31 
56 class AtRndmGenSvc : public extends<AthService, IAtRndmGenSvc, IIncidentListener>
57 {
58 public:
60 
61  virtual CLHEP::HepRandomEngine* GetEngine ( const std::string& streamName ) override;
62  virtual void CreateStream ( uint32_t seed1, uint32_t seed2,
63  const std::string& streamName ) override;
65 
67  typedef std::map<std::string, CLHEP::RanecuEngine*> engineMap;
69  typedef engineMap::const_iterator engineConstIter;
70  typedef engineMap::value_type engineValType;
71 
73 
74  engineConstIter begin (void) const;
75  engineConstIter end (void) const;
76  unsigned int number_of_streams (void) const;
77  virtual void print ( const std::string& streamName ) override;
78  virtual void print ( void ) override;
80 
81  virtual CLHEP::HepRandomEngine* setOnDefinedSeeds (uint32_t theSeed,
82  const std::string& streamName) override;
83  virtual CLHEP::HepRandomEngine* setOnDefinedSeeds (uint32_t eventNumber,
85  const std::string& streamName) override;
87  CLHEP::HepRandomEngine* oldSetOnDefinedSeeds (uint32_t theSeed,
88  const std::string& streamName);
90  CLHEP::HepRandomEngine* oldSetOnDefinedSeeds (uint32_t eventNumber,
92  const std::string& streamName);
94  virtual bool setAllOnDefinedSeeds (uint32_t theSeed) override;
98 
99  virtual StatusCode initialize() override;
100  virtual StatusCode finalize() override;
102 
104  virtual void handle(const Incident&) override;
105 
106 
107 private:
109 
110 
111  Gaudi::Property<bool> m_useOldBrokenSeeding{this,"UseOldBrokenSeeding",false};
112  StringArrayProperty m_streams_seeds{this,"Seeds",{},
113  "seeds for the engines, this is a vector of strings of the form ['SequenceName [OFFSET num] Seed1 Seed2', ...] "\
114  "where OFFSET is an optional integer that allows to change the sequence of randoms for a given run/event no " \
115  "and SequenceName combination. Notice that Seed1/Seed2 are dummy when EventReseeding is used",
116  "OrderedSet<std::string>"};
117 
118 
119  Gaudi::Property<bool> m_read_from_file{this,"ReadFromFile",false,"set/restore the status of the engine from file"};
120  Gaudi::Property<std::string> m_file_to_read{this,"FileToRead",this->name()+".out",
121  "name of a ASCII file, usually produced by AtRndmGenSvc itself at the end of a job, "\
122  "containing the information to fully set/restore the status of Ranecu",
123  };
124  Gaudi::Property<bool> m_save_to_file{this,"SaveToFile", true,"save the status of the engine to file"};
125  Gaudi::Property<std::string> m_file_to_write{this,"FileToWrite",this->name()+".out",
126  "name of an ASCII file which will be produced on finalize, containing the information to fully set/restore the status"};
127 
128  Gaudi::Property<bool> m_eventReseed{this,"EventReseeding",true,"reseed every event using a hash of run and event numbers"};
129  StringArrayProperty m_reseedStreamNames{this,"ReseedStreamNames",{}, "the streams we are going to set the seeds of (default: all streams)"};
131 
132 
135  std::map<std::string, uint32_t> m_reseedingOffsets;
136 
139  std::map<std::string, std::vector<long int> > m_engines_copy;
140 
141 
143 
151 
152  void SetStreamSeeds( const std::string& streamName );
153 
154 public:
155 
156  // Standard Constructor
157  AtRndmGenSvc(const std::string& name, ISvcLocator* svc);
158 
159  // Standard Destructor
160  virtual ~AtRndmGenSvc();
161 
162 };
163 
166 { return m_engines.begin(); }
167 
169 AtRndmGenSvc::end (void) const
170 { return m_engines.end(); }
171 
172 inline unsigned int
174 { return m_engines.size(); }
175 
176 #endif // ATRNDMGENSVC_H
177 
178 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AtRndmGenSvc::finalize
virtual StatusCode finalize() override
Definition: AtRndmGenSvc.cxx:232
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
AtRndmGenSvc::GetEngine
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &streamName) override
Definition: AtRndmGenSvc.cxx:254
AtRndmGenSvc::AtRndmGenSvc
AtRndmGenSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: AtRndmGenSvc.cxx:27
AtRndmGenSvc::m_default_seed2
long m_default_seed2
Definition: AtRndmGenSvc.h:145
AtRndmGenSvc::m_reseedStreamNames
StringArrayProperty m_reseedStreamNames
streams to be reseeded for every event
Definition: AtRndmGenSvc.h:129
AtRndmGenSvc::m_read_from_file
Gaudi::Property< bool > m_read_from_file
read engine status from file
Definition: AtRndmGenSvc.h:119
AtRndmGenSvc::number_of_streams
unsigned int number_of_streams(void) const
Definition: AtRndmGenSvc.h:173
AtRndmGenSvc::m_engines_copy
std::map< std::string, std::vector< long int > > m_engines_copy
Random engine copy (for output to a file)
Definition: AtRndmGenSvc.h:139
AtRndmGenSvc::m_HERWIG_default_seed1
long m_HERWIG_default_seed1
Definition: AtRndmGenSvc.h:148
genPbPbJobOpt.seed2
seed2
Definition: genPbPbJobOpt.py:57
AtRndmGenSvc::setOnDefinedSeeds
virtual CLHEP::HepRandomEngine * setOnDefinedSeeds(uint32_t theSeed, const std::string &streamName) override
AtRndmGenSvc::begin
engineConstIter begin(void) const
Definition: AtRndmGenSvc.h:165
AtRndmGenSvc::SetStreamSeeds
void SetStreamSeeds(const std::string &streamName)
Definition: AtRndmGenSvc.cxx:280
AtRndmGenSvc::m_file_to_read
Gaudi::Property< std::string > m_file_to_read
name of the file to read the engine status from
Definition: AtRndmGenSvc.h:120
AtRndmGenSvc::~AtRndmGenSvc
virtual ~AtRndmGenSvc()
Standard Destructor.
Definition: AtRndmGenSvc.cxx:43
AtRndmGenSvc::m_PYTHIA_default_seed1
long m_PYTHIA_default_seed1
Definition: AtRndmGenSvc.h:146
AtRndmGenSvc::m_reseedingOffsets
std::map< std::string, uint32_t > m_reseedingOffsets
optional offsets to combine to run/evt no when reseeding.
Definition: AtRndmGenSvc.h:135
AtRndmGenSvc::m_HERWIG_default_seed2
long m_HERWIG_default_seed2
Definition: AtRndmGenSvc.h:149
AtRndmGenSvc::setAllOnDefinedSeeds
virtual bool setAllOnDefinedSeeds(uint32_t theSeed) override
seed all streams we manage, combining theSeed and the stream names
AtRndmGenSvc::m_streams_seeds
StringArrayProperty m_streams_seeds
Definition: AtRndmGenSvc.h:112
AtRndmGenSvc::engineMap
std::map< std::string, CLHEP::RanecuEngine * > engineMap
CLHEP engines typedefs:
Definition: AtRndmGenSvc.h:67
AtRndmGenSvc::setAllOnDefinedSeeds
virtual bool setAllOnDefinedSeeds(uint32_t eventNumber, uint32_t runNumber) override
seed all streams, combining eventNumber, runNumber and the stream names
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AtRndmGenSvc::engineIter
engineMap::iterator engineIter
Definition: AtRndmGenSvc.h:68
AtRndmGenSvc::m_save_to_file
Gaudi::Property< bool > m_save_to_file
should current engine status be saved to file ?
Definition: AtRndmGenSvc.h:124
AtRndmGenSvc::setOnDefinedSeeds
virtual CLHEP::HepRandomEngine * setOnDefinedSeeds(uint32_t eventNumber, uint32_t runNumber, const std::string &streamName) override
AtRndmGenSvc::m_useOldBrokenSeeding
Gaudi::Property< bool > m_useOldBrokenSeeding
backward compatibility only, broken 32/64 bits
Definition: AtRndmGenSvc.h:111
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
AtRndmGenSvc
A random number engine manager, based on Ranecu. Its usage is deprecated, at least when high quality ...
Definition: AtRndmGenSvc.h:57
AtRndmGenSvc::print
virtual void print(const std::string &streamName) override
IAtRndmGenSvc.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AtRndmGenSvc::oldSetOnDefinedSeeds
CLHEP::HepRandomEngine * oldSetOnDefinedSeeds(uint32_t theSeed, const std::string &streamName)
broken, temporarily keep for backward compatibility
Definition: AtRndmGenSvc.cxx:392
AtRndmGenSvc::m_eventReseed
Gaudi::Property< bool > m_eventReseed
reseed for every event
Definition: AtRndmGenSvc.h:128
AtRndmGenSvc::m_engines
engineMap m_engines
Definition: AtRndmGenSvc.h:137
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
AtRndmGenSvc::CreateStream
virtual void CreateStream(uint32_t seed1, uint32_t seed2, const std::string &streamName) override
Definition: AtRndmGenSvc.cxx:268
AthenaPoolExample_Copy.streamName
string streamName
Definition: AthenaPoolExample_Copy.py:39
AtRndmGenSvc::print
virtual void print(void) override
AtRndmGenSvc::m_default_seed1
long m_default_seed1
Definition: AtRndmGenSvc.h:144
genPbPbJobOpt.seed1
seed1
Definition: genPbPbJobOpt.py:56
AthService.h
AtRndmGenSvc::m_file_to_write
Gaudi::Property< std::string > m_file_to_write
name of the file to save the engine status to.
Definition: AtRndmGenSvc.h:125
AtRndmGenSvc::handle
virtual void handle(const Incident &) override
IIncidentListener implementation. Handles EndEvent incident.
Definition: AtRndmGenSvc.cxx:150
AtRndmGenSvc::engineConstIter
engineMap::const_iterator engineConstIter
Definition: AtRndmGenSvc.h:69
AtRndmGenSvc::m_PYTHIA_default_seed2
long m_PYTHIA_default_seed2
Definition: AtRndmGenSvc.h:147
AtRndmGenSvc::engineValType
engineMap::value_type engineValType
Definition: AtRndmGenSvc.h:70
AtRndmGenSvc::initialize
virtual StatusCode initialize() override
Definition: AtRndmGenSvc.cxx:51
AtRndmGenSvc::end
engineConstIter end(void) const
Definition: AtRndmGenSvc.h:169