ATLAS Offline Software
AtRanluxGenSvc.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 ATRANLUXGENSVC_H
6 #define ATRANLUXGENSVC_H
7 
14 #include <map>
15 
16 //base classes
18 #include "GaudiKernel/IIncidentListener.h"
20 #include "Gaudi/Property.h"
21 
22 #include "CLHEP/Random/Ranlux64Engine.h"
23 
54 class AtRanluxGenSvc : public extends<AthService, IAtRndmGenSvc, IIncidentListener>
55 {
56 public:
58 
59  virtual CLHEP::HepRandomEngine* GetEngine(const std::string& streamName) override;
61  const std::string& streamName) override;
62  bool CreateStream(const std::vector<uint32_t>& seeds,
63  const std::string& streamName);
65 
67 
68  typedef std::map<std::string, CLHEP::Ranlux64Engine*> engineMap;
70  typedef engineMap::const_iterator engineConstIter;
71  typedef engineMap::value_type engineValType;
73 
75 
76  engineConstIter begin (void) const;
77  engineConstIter end (void) const;
78  unsigned int number_of_streams (void) const;
79  virtual void print ( const std::string& streamName ) override;
80  virtual void print ( void ) override;
83  const std::string& streamName, short luxLevel);
85 
86  virtual CLHEP::HepRandomEngine* setOnDefinedSeeds (uint32_t theSeed,
87  const std::string& streamName) override;
88  virtual CLHEP::HepRandomEngine* setOnDefinedSeeds (uint32_t eventNumber,
90  const std::string& streamName) override;
92  CLHEP::HepRandomEngine* oldSetOnDefinedSeeds (uint32_t theSeed,
93  const std::string& streamName);
95  CLHEP::HepRandomEngine* oldSetOnDefinedSeeds (uint32_t eventNumber,
97  const std::string& streamName);
99  virtual bool setAllOnDefinedSeeds (uint32_t theSeed) override;
102 
104 
105  virtual StatusCode initialize() override;
106  virtual StatusCode finalize() override;
108 
110  virtual void handle(const Incident&) override;
111 
112 
113 private:
115 
116  StringArrayProperty m_streams_seeds{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>"};
123 
124 
125  Gaudi::Property<bool> m_read_from_file{this,"ReadFromFile",false,"set/restore the status of the engine from file"};
126  Gaudi::Property<std::string> m_file_to_read{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  };
130  Gaudi::Property<bool> m_save_to_file{this,"SaveToFile", true,"save the status of the engine to file"};
131  Gaudi::Property<std::string> m_file_to_write{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"};
133 
134  Gaudi::Property<bool> m_eventReseed{this,"EventReseeding",true,"reseed every event using a hash of run and event numbers"};
135  StringArrayProperty m_reseedStreamNames{this,"ReseedStreamNames",{}, "the streams we are going to set the seeds of (default: all streams)"};
137 
138  Gaudi::Property<bool> m_useOldBrokenSeeding{this,"UseOldBrokenSeeding",false};
139 
140 
143  std::map<std::string, uint32_t> m_reseedingOffsets;
144 
147  std::map<std::string, std::vector<uint32_t> > m_engines_copy;
149 
150 
152 
160 
161  void SetStreamSeeds( const std::string& streamName );
162 
163 public:
164 
166  AtRanluxGenSvc(const std::string& name, ISvcLocator* svc);
167 
168  virtual ~AtRanluxGenSvc();
169 
170 };
171 
174 { return m_engines.begin(); }
175 
178 { return m_engines.end(); }
179 
180 inline unsigned int
182 { return m_engines.size(); }
183 
184 #endif // ATRANLUXGENSVC_H
185 
186 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AtRanluxGenSvc::finalize
virtual StatusCode finalize() override
Definition: AtRanluxGenSvc.cxx:261
AtRanluxGenSvc::m_HERWIG_default_seed1
uint32_t m_HERWIG_default_seed1
Definition: AtRanluxGenSvc.h:157
AtRanluxGenSvc::AtRanluxGenSvc
AtRanluxGenSvc(const std::string &name, ISvcLocator *svc)
Standard Gaudi Constructor.
Definition: AtRanluxGenSvc.cxx:29
AtRanluxGenSvc::initialize
virtual StatusCode initialize() override
Definition: AtRanluxGenSvc.cxx:54
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
AtRanluxGenSvc::setOnDefinedSeeds
virtual CLHEP::HepRandomEngine * setOnDefinedSeeds(uint32_t eventNumber, uint32_t runNumber, const std::string &streamName) override
AtRanluxGenSvc::SetStreamSeeds
void SetStreamSeeds(const std::string &streamName)
Definition: AtRanluxGenSvc.cxx:336
AtRanluxGenSvc::m_file_to_write
Gaudi::Property< std::string > m_file_to_write
name of the file to save the engine status to.
Definition: AtRanluxGenSvc.h:131
AtRanluxGenSvc::~AtRanluxGenSvc
virtual ~AtRanluxGenSvc()
Standard Destructor.
Definition: AtRanluxGenSvc.cxx:46
AtRanluxGenSvc::createStream
void createStream(uint32_t seed1, uint32_t seed2, const std::string &streamName, short luxLevel)
allows to specify luxLevel
Definition: AtRanluxGenSvc.cxx:308
AtRanluxGenSvc::print
virtual void print(void) override
AtRanluxGenSvc::engineConstIter
engineMap::const_iterator engineConstIter
Definition: AtRanluxGenSvc.h:70
AtRanluxGenSvc::end
engineConstIter end(void) const
Definition: AtRanluxGenSvc.h:177
genPbPbJobOpt.seed2
seed2
Definition: genPbPbJobOpt.py:57
AtRanluxGenSvc::m_engines
engineMap m_engines
Definition: AtRanluxGenSvc.h:145
AtRanluxGenSvc::CreateStream
virtual void CreateStream(uint32_t seed1, uint32_t seed2, const std::string &streamName) override
AtRanluxGenSvc::number_of_streams
unsigned int number_of_streams(void) const
Definition: AtRanluxGenSvc.h:181
AtRanluxGenSvc::m_PYTHIA_default_seed2
uint32_t m_PYTHIA_default_seed2
Definition: AtRanluxGenSvc.h:156
AtRanluxGenSvc::m_HERWIG_default_seed2
uint32_t m_HERWIG_default_seed2
Definition: AtRanluxGenSvc.h:158
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AtRanluxGenSvc::m_reseedingOffsets
std::map< std::string, uint32_t > m_reseedingOffsets
optional offsets to combine to run/evt no when reseeding.
Definition: AtRanluxGenSvc.h:143
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
AtRanluxGenSvc
The default ATLAS random number engine manager, based on Ranlux64.
Definition: AtRanluxGenSvc.h:55
AtRanluxGenSvc::setOnDefinedSeeds
virtual CLHEP::HepRandomEngine * setOnDefinedSeeds(uint32_t theSeed, const std::string &streamName) override
AtRanluxGenSvc::oldSetOnDefinedSeeds
CLHEP::HepRandomEngine * oldSetOnDefinedSeeds(uint32_t theSeed, const std::string &streamName)
broken, temporarily keep for backward compatibility
Definition: AtRanluxGenSvc.cxx:458
AtRanluxGenSvc::m_defaultLuxLevel
short m_defaultLuxLevel
Ranlux luxury level to be used by default.
Definition: AtRanluxGenSvc.h:148
AtRanluxGenSvc::m_PYTHIA_default_seed1
uint32_t m_PYTHIA_default_seed1
Definition: AtRanluxGenSvc.h:155
IAtRndmGenSvc.h
AtRanluxGenSvc::m_reseedStreamNames
StringArrayProperty m_reseedStreamNames
streams to be reseeded for every event
Definition: AtRanluxGenSvc.h:135
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
AtRanluxGenSvc::m_read_from_file
Gaudi::Property< bool > m_read_from_file
read engine status from file
Definition: AtRanluxGenSvc.h:125
AtRanluxGenSvc::handle
virtual void handle(const Incident &) override
IIncidentListener implementation. Handles EndEvent incident.
Definition: AtRanluxGenSvc.cxx:170
AtRanluxGenSvc::m_save_to_file
Gaudi::Property< bool > m_save_to_file
should current engine status be saved to file ?
Definition: AtRanluxGenSvc.h:130
AtRanluxGenSvc::m_default_seed2
uint32_t m_default_seed2
Definition: AtRanluxGenSvc.h:154
AtRanluxGenSvc::m_engines_copy
std::map< std::string, std::vector< uint32_t > > m_engines_copy
Random engine copy (for output to a file)
Definition: AtRanluxGenSvc.h:147
AtRanluxGenSvc::m_eventReseed
Gaudi::Property< bool > m_eventReseed
reseed for every event
Definition: AtRanluxGenSvc.h:134
AtRanluxGenSvc::setAllOnDefinedSeeds
virtual bool setAllOnDefinedSeeds(uint32_t theSeed) override
seed all streams we manage, combining theSeed and the stream names
AtRanluxGenSvc::engineMap
std::map< std::string, CLHEP::Ranlux64Engine * > engineMap
Definition: AtRanluxGenSvc.h:68
DeMoAtlasDataLoss.runNumber
string runNumber
Definition: DeMoAtlasDataLoss.py:64
AthenaPoolExample_Copy.streamName
string streamName
Definition: AthenaPoolExample_Copy.py:39
AtRanluxGenSvc::m_default_seed1
uint32_t m_default_seed1
Definition: AtRanluxGenSvc.h:153
AtRanluxGenSvc::engineValType
engineMap::value_type engineValType
Definition: AtRanluxGenSvc.h:71
AtRanluxGenSvc::setAllOnDefinedSeeds
virtual bool setAllOnDefinedSeeds(uint32_t eventNumber, uint32_t runNumber) override
seed all streams, combining eventNumber, runNumber and the stream names
AtRanluxGenSvc::m_useOldBrokenSeeding
Gaudi::Property< bool > m_useOldBrokenSeeding
backward compatibility only, broken 32/64 bits
Definition: AtRanluxGenSvc.h:138
genPbPbJobOpt.seed1
seed1
Definition: genPbPbJobOpt.py:56
AtRanluxGenSvc::m_file_to_read
Gaudi::Property< std::string > m_file_to_read
name of the file to read the engine status from
Definition: AtRanluxGenSvc.h:126
AthService.h
AtRanluxGenSvc::m_streams_seeds
StringArrayProperty m_streams_seeds
seeds for the engines, this is a vector of strings of the form "EnginName Seed1 Seed2"
Definition: AtRanluxGenSvc.h:117
AtRanluxGenSvc::engineIter
engineMap::iterator engineIter
Definition: AtRanluxGenSvc.h:69
AtRanluxGenSvc::begin
engineConstIter begin(void) const
Definition: AtRanluxGenSvc.h:173
AtRanluxGenSvc::GetEngine
virtual CLHEP::HepRandomEngine * GetEngine(const std::string &streamName) override
Definition: AtRanluxGenSvc.cxx:288
AtRanluxGenSvc::print
virtual void print(const std::string &streamName) override