GENIEGenerator
Loading...
Searching...
No Matches
genie::EventGenerator Class Reference

Encapsulates a full ordered list of (is the aggregate of) concrete EventGeneratorI implementations that must act on the EventRecord to generate an event. Each of these implementations corresponds to a single processing step. More...

#include <EventGenerator.h>

Inheritance diagram for genie::EventGenerator:
[legend]
Collaboration diagram for genie::EventGenerator:
[legend]

Public Member Functions

 EventGenerator ()
 EventGenerator (string config)
 ~EventGenerator ()
void ProcessEventRecord (GHepRecord *event_rec) const
const GVldContextValidityContext (void) const
const InteractionListGeneratorIIntListGenerator (void) const
const XSecAlgorithmICrossSectionAlg (void) const
void Configure (const Registry &config)
void Configure (string param_set)
Public Member Functions inherited from genie::EventGeneratorI
virtual ~EventGeneratorI ()
Public Member Functions inherited from genie::EventRecordVisitorI
virtual ~EventRecordVisitorI ()
Public Member Functions inherited from genie::Algorithm
virtual ~Algorithm ()
virtual void FindConfig (void)
virtual const RegistryGetConfig (void) const
RegistryGetOwnedConfig (void)
virtual const AlgIdId (void) const
 Get algorithm ID.
virtual AlgStatus_t GetStatus (void) const
 Get algorithm status.
virtual bool AllowReconfig (void) const
virtual AlgCmp_t Compare (const Algorithm *alg) const
 Compare with input algorithm.
virtual void SetId (const AlgId &id)
 Set algorithm ID.
virtual void SetId (string name, string config)
const AlgorithmSubAlg (const RgKey &registry_key) const
void AdoptConfig (void)
void AdoptSubstructure (void)
virtual void Print (ostream &stream) const
 Print algorithm info.

Private Member Functions

void Init (void)
void LoadConfig (void)

Private Attributes

vector< const EventRecordVisitorI * > * fEVGModuleVec
 list of modules
vector< double > * fEVGTime
 module timing info
const XSecAlgorithmIfXSecModel
 xsec model for events handled by thread
const InteractionListGeneratorIfIntListGen
 generates list of handled interactions
GVldContextfVldContext
 validity context
TStopwatch * fWatch
 stopwatch for module timing
TBits * fFiltUnphysMask
 mask for allowing unphysical events to pass through (if requested)
GHepRecordHistory fRecHistory
 event record history

Additional Inherited Members

Static Public Member Functions inherited from genie::Algorithm
static string BuildParamVectKey (const std::string &comm_name, unsigned int i)
static string BuildParamVectSizeKey (const std::string &comm_name)
static string BuildParamMatKey (const std::string &comm_name, unsigned int i, unsigned int j)
static string BuildParamMatRowSizeKey (const std::string &comm_name)
static string BuildParamMatColSizeKey (const std::string &comm_name)
Protected Member Functions inherited from genie::EventGeneratorI
 EventGeneratorI ()
 EventGeneratorI (string name)
 EventGeneratorI (string name, string config)
Protected Member Functions inherited from genie::EventRecordVisitorI
 EventRecordVisitorI ()
 EventRecordVisitorI (string name)
 EventRecordVisitorI (string name, string config)
Protected Member Functions inherited from genie::Algorithm
 Algorithm ()
 Algorithm (string name)
 Algorithm (string name, string config)
void Initialize (void)
void DeleteConfig (void)
void DeleteSubstructure (void)
RegistryExtractLocalConfig (const Registry &in) const
RegistryExtractLowerConfig (const Registry &in, const string &alg_key) const
 Split an incoming configuration Registry into a block valid for the sub-algo identified by alg_key.
template<class T>
bool GetParam (const RgKey &name, T &p, bool is_top_call=true) const
template<class T>
bool GetParamDef (const RgKey &name, T &p, const T &def) const
template<class T>
int GetParamVect (const std::string &comm_name, std::vector< T > &v, bool is_top_call=true) const
 Handle to load vectors of parameters.
int GetParamVectKeys (const std::string &comm_name, std::vector< RgKey > &k, bool is_top_call=true) const
template<class T>
int GetParamMat (const std::string &comm_name, TMatrixT< T > &mat, bool is_top_call=true) const
 Handle to load matrix of parameters.
template<class T>
int GetParamMatSym (const std::string &comm_name, TMatrixTSym< T > &mat, bool is_top_call=true) const
int GetParamMatKeys (const std::string &comm_name, std::vector< RgKey > &k, bool is_top_call=true) const
int AddTopRegistry (Registry *rp, bool owns=true)
 add registry with top priority, also update ownership
int AddLowRegistry (Registry *rp, bool owns=true)
 add registry with lowest priority, also update ownership
int MergeTopRegistry (const Registry &r)
int AddTopRegisties (const vector< Registry * > &rs, bool owns=false)
 Add registries with top priority, also udated Ownerships.
Protected Attributes inherited from genie::Algorithm
bool fAllowReconfig
bool fOwnsSubstruc
 true if it owns its substructure (sub-algs,...)
AlgId fID
 algorithm name and configuration set
vector< Registry * > fConfVect
vector< bool > fOwnerships
 ownership for every registry in fConfVect
AlgStatus_t fStatus
 algorithm execution status
AlgMapfOwnedSubAlgMp
 local pool for owned sub-algs (taken out of the factory pool)

Detailed Description

Encapsulates a full ordered list of (is the aggregate of) concrete EventGeneratorI implementations that must act on the EventRecord to generate an event. Each of these implementations corresponds to a single processing step.

Is a concrete implementation of the EventGeneratorI interface.

Author
Costas Andreopoulos <c.andreopoulos \at cern.ch> University of Liverpool
Created:\n October 03, 2004
License:\n Copyright (c) 2003-2025, The GENIE Collaboration
For the full text of the license visit http://copyright.genie-mc.org

Definition at line 38 of file EventGenerator.h.

Constructor & Destructor Documentation

◆ EventGenerator() [1/2]

EventGenerator::EventGenerator ( )

Definition at line 42 of file EventGenerator.cxx.

42 :
43EventGeneratorI("genie::EventGenerator")
44{
45 this->Init();
46}

References genie::EventGeneratorI::EventGeneratorI(), and Init().

◆ EventGenerator() [2/2]

EventGenerator::EventGenerator ( string config)

Definition at line 48 of file EventGenerator.cxx.

48 :
49EventGeneratorI("genie::EventGenerator", config)
50{
51 this->Init();
52}

References genie::EventGeneratorI::EventGeneratorI(), and Init().

◆ ~EventGenerator()

EventGenerator::~EventGenerator ( )

Definition at line 54 of file EventGenerator.cxx.

55{
56 delete fWatch;
57 delete fFiltUnphysMask;
58
60 if(fEVGTime) delete fEVGTime;
61 if(fVldContext) delete fVldContext;
62}
TStopwatch * fWatch
stopwatch for module timing
vector< const EventRecordVisitorI * > * fEVGModuleVec
list of modules
TBits * fFiltUnphysMask
mask for allowing unphysical events to pass through (if requested)
vector< double > * fEVGTime
module timing info
GVldContext * fVldContext
validity context

References fEVGModuleVec, fEVGTime, fFiltUnphysMask, fVldContext, and fWatch.

Member Function Documentation

◆ Configure() [1/2]

void EventGenerator::Configure ( const Registry & config)
virtual

Configure the algorithm with an external registry The registry is merged with the top level registry if it is owned, Otherwise a copy of it is added with the highest priority

Reimplemented from genie::Algorithm.

Definition at line 207 of file EventGenerator.cxx.

208{
209 Algorithm::Configure(config);
210 this->LoadConfig();
211}
virtual void Configure(const Registry &config)
Definition Algorithm.cxx:62

References genie::Algorithm::Configure(), and LoadConfig().

◆ Configure() [2/2]

void EventGenerator::Configure ( string config)
virtual

Configure the algorithm from the AlgoConfigPool based on param_set string given in input An algorithm contains a vector of registries coming from different xml configuration files, which are loaded according a very precise prioriy This methods will load a number registries in order of priority: 1) "Tunable" parameter set from CommonParametes. This is loaded with the highest prioriry and it is designed to be used for tuning procedure Usage not expected from the user. 2) For every string defined in "CommonParame" the corresponding parameter set will be loaded from CommonParameter.xml 3) parameter set specified by the config string and defined in the xml file of the algorithm 4) if config is not "Default" also the Default parameter set from the same xml file will be loaded Effectively this avoids the repetion of a parameter when it is not changed in the requested configuration

Reimplemented from genie::Algorithm.

Definition at line 213 of file EventGenerator.cxx.

214{
215 Algorithm::Configure(param_set);
216
217 AddLowRegistry( AlgConfigPool::Instance() -> GlobalParameterList(), false ) ;
218
219 this->LoadConfig();
220}
static AlgConfigPool * Instance()
int AddLowRegistry(Registry *rp, bool owns=true)
add registry with lowest priority, also update ownership

References genie::Algorithm::AddLowRegistry(), genie::Algorithm::Configure(), genie::AlgConfigPool::Instance(), and LoadConfig().

◆ CrossSectionAlg()

const XSecAlgorithmI * EventGenerator::CrossSectionAlg ( void ) const
virtual

Implements genie::EventGeneratorI.

Definition at line 202 of file EventGenerator.cxx.

203{
204 return fXSecModel;
205}
const XSecAlgorithmI * fXSecModel
xsec model for events handled by thread

References fXSecModel.

◆ Init()

void EventGenerator::Init ( void )
private

Definition at line 227 of file EventGenerator.cxx.

228{
229 fWatch = new TStopwatch;
230 fVldContext = 0;
231 fEVGModuleVec = 0;
232 fEVGTime = 0;
233 fXSecModel = 0;
234 fIntListGen = 0;
235
236 fFiltUnphysMask = new TBits(GHepFlags::NFlags());
237 fFiltUnphysMask->ResetAllBits(false);
238
239 if (gSystem->Getenv("GUNPHYSMASK")) {
240 unsigned int i=0;
241 const char * bitfield = gSystem->Getenv("GUNPHYSMASK");
242
243 while(bitfield[i]) {
244 bool flag = (bitfield[i]=='1');
245
246 if(i<GHepFlags::NFlags()) fFiltUnphysMask->SetBitNumber(i,flag);
247 i++;
248 }
249 }
250 LOG("EventGenerator", pDEBUG)
251 << "Initializing unphysical event mask (" << GHepFlags::NFlags()
252 << "->0) = " << *fFiltUnphysMask;
253}
#define pDEBUG
Definition Messenger.h:63
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
const InteractionListGeneratorI * fIntListGen
generates list of handled interactions
static unsigned int NFlags(void)
Definition GHepFlags.h:76

References fEVGModuleVec, fEVGTime, fFiltUnphysMask, fIntListGen, fVldContext, fWatch, fXSecModel, LOG, genie::GHepFlags::NFlags(), and pDEBUG.

Referenced by EventGenerator(), and EventGenerator().

◆ IntListGenerator()

const InteractionListGeneratorI * EventGenerator::IntListGenerator ( void ) const
virtual

Implements genie::EventGeneratorI.

Definition at line 197 of file EventGenerator.cxx.

198{
199 return fIntListGen;
200}

References fIntListGen.

◆ LoadConfig()

void EventGenerator::LoadConfig ( void )
private

Definition at line 255 of file EventGenerator.cxx.

256{
257 if(fEVGModuleVec) delete fEVGModuleVec;
258 if(fEVGTime) delete fEVGTime;
259 if(fVldContext) delete fVldContext;
260
261 LOG("EventGenerator", pDEBUG) << "Loading the generator validity context";
262
263 string encoded_vld_context ;
264 GetParam("VldContext", encoded_vld_context ) ;
265 fVldContext = new GVldContext;
266 fVldContext->Decode( encoded_vld_context );
267
268 LOG("EventGenerator", pDEBUG) << "Loading the event generation modules";
269
270 int nsteps ;
271 GetParam("NModules", nsteps) ;
272 if(nsteps == 0) {
273 LOG("EventGenerator", pFATAL)
274 << "EventGenerator configuration declares null visitor list!";
275 }
276 assert(nsteps>0);
277
278 fEVGModuleVec = new vector<const EventRecordVisitorI *> (nsteps);
279 fEVGTime = new vector<double>(nsteps);
280
281 for(int istep = 0; istep < nsteps; istep++) {
282
283 ostringstream keystream;
284 keystream << "Module-" << istep;
285 RgKey key = keystream.str();
286
287 RgAlg temp_alg ;
288 GetParam( key, temp_alg ) ;
289
290 SLOG("EventGenerator", pINFO)
291 << " -- Loading module " << istep << " : " << temp_alg ;
292
293 const EventRecordVisitorI * visitor =
294 dynamic_cast<const EventRecordVisitorI *>(this->SubAlg(key));
295
296 (*fEVGModuleVec)[istep] = visitor;
297 (*fEVGTime)[istep] = 0;
298 }
299
300 //-- load the interaction list generator
301 RgKey ikey = "ILstGen";
302 RgAlg ialg ;
303 GetParam( ikey, ialg ) ;
304 LOG("EventGenerator", pINFO)
305 << " -- Loading the interaction list generator: " << ialg;
306 fIntListGen =
307 dynamic_cast<const InteractionListGeneratorI *> (this->SubAlg(ikey));
308 assert(fIntListGen);
309
310 //-- load the cross section model
311 RgKey xkey = "XSecModel@" + this->Id().Key();
312 RgAlg xalg ;
313 GetParam( xkey, xalg ) ;
314 LOG("EventGenerator", pINFO)
315 << " -- Loading the cross section model: " << xalg;
316 fXSecModel =
317 dynamic_cast<const XSecAlgorithmI *> (
318 this -> SubAlg( xkey ) ) ;
319 assert(fXSecModel);
320}
#define pINFO
Definition Messenger.h:62
#define pFATAL
Definition Messenger.h:56
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition Messenger.h:84
string RgKey
string Key(void) const
Definition AlgId.h:46
bool GetParam(const RgKey &name, T &p, bool is_top_call=true) const
const Algorithm * SubAlg(const RgKey &registry_key) const
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition Algorithm.h:98

References fEVGModuleVec, fEVGTime, fIntListGen, fVldContext, fXSecModel, genie::Algorithm::GetParam(), genie::Algorithm::Id(), genie::AlgId::Key(), LOG, pDEBUG, pFATAL, pINFO, SLOG, and genie::Algorithm::SubAlg().

Referenced by Configure(), and Configure().

◆ ProcessEventRecord()

void EventGenerator::ProcessEventRecord ( GHepRecord * event_rec) const
virtual

Implements genie::EventRecordVisitorI.

Definition at line 64 of file EventGenerator.cxx.

65{
66 LOG("EventGenerator", pNOTICE) << "Generating Event...";
67
68 //-- Clear previous virtual list folder
69 LOG("EventGenerator", pNOTICE) << "Clearing the GHepVirtualListFolder";
70 GHepVirtualListFolder * vlfolder = GHepVirtualListFolder::Instance();
71 vlfolder->Clear();
72
73 //-- Clean previous history + add the bootstrap record in the buffer
74 fRecHistory.PurgeHistory();
75 fRecHistory.AddSnapshot(-1, event_rec);
76
77 //-- Initialize evg thread control flags
78 bool ffwd = false;
79 unsigned int nexceptions = 0;
80
81 //-- Reset stop-watch
82 fWatch->Reset();
83
84 string mesgh = "Event generation thread: " + this->Id().Key() +
85 " -> Running module: ";
86
87 //-- Loop over the event record processing modules
88 int istep=0;
89 vector<const EventRecordVisitorI *>::const_iterator miter;
90
91 for(miter = fEVGModuleVec->begin();
92 miter != fEVGModuleVec->end(); ++miter)
93 {
94 const EventRecordVisitorI * visitor = *miter; // generation module
95
96 string mesg = mesgh + visitor->Id().Key();
97 LOG("EventGenerator", pNOTICE)
98 << utils::print::PrintFramedMesg(mesg,0,'~');
99 if(ffwd) {
100 LOG("EventGenerator", pNOTICE)
101 << "Fast Forward flag was set - Skipping processing step!";
102 continue;
103 }
104 try
105 {
106 fWatch->Start();
107 visitor->ProcessEventRecord(event_rec);
108 fWatch->Stop();
109 fRecHistory.AddSnapshot(istep, event_rec);
110 (*fEVGTime)[istep] = fWatch->CpuTime(); // sec
111 }
112 catch (EVGThreadException exception)
113 {
114 LOG("EventGenerator", pNOTICE)
115 << "An exception was thrown and caught by EventGenerator!";
116 LOG("EventGenerator", pNOTICE) << exception;
117
118 nexceptions++;
119 if ( nexceptions > kMaxEVGThreadExceptions ) {
120 LOG("EventGenerator", pFATAL)
121 << "Caught max allowed number (" << kMaxEVGThreadExceptions
122 << ") of EVGThreadExceptions/thread. Aborting";
123 LOG("EventGenerator", pFATAL) << "Event : \n" << *event_rec ;
124 exit(1);
125 }
126
127 //
128 // What should I do with this exception?
129 // Check whether the user wants to get this unphysical event anyway
130 // If not, follow instructions coming with the expection thrown:
131 // Either step back to a particular processing step and try re-generating
132 // the event or pass it through
133 //
134
135 // check whether user wants this type of unphysical events passed through
136 bool accept = event_rec->Accept();
137 if(accept) {
138 LOG("EventGenerator", pWARN)
139 << "An unphysical event was generated and was accepted by the user";
140 break;
141 } else {
142 LOG("EventGenerator", pWARN)
143 << "An unphysical event was generated and was rejected";
144 }
145
146 // now, follow instructions contained in the exception itself
147
148 // make sure we are not asked to go at both directions...
149 assert( !(exception.FastForward() && exception.StepBack()) );
150
151 ffwd = exception.FastForward();
152 if(exception.StepBack()) {
153
154 // get return step (if return_step > current_step just ignore it)
155 if(exception.ReturnStep() >= 0 && exception.ReturnStep() <= istep) {
156
157 int rstep = exception.ReturnStep();
158 LOG("EventGenerator", pNOTICE)
159 << "Return at processing step " << rstep;
160 advance(miter, rstep-istep-1);
161 istep = rstep;
162
163 // restore the event record as it was just before the processing
164 // step we are about to return to
165 LOG("EventGenerator", pNOTICE)
166 << "Restoring GHEP as it was just before the return step";
167 event_rec->ResetRecord();
168 istep--;
169 GHepRecord * snapshot = fRecHistory[istep];
170 fRecHistory.PurgeRecentHistory(istep+1);
171 event_rec->Copy(*snapshot);
172 } // valid-return-step
173 } // step-back
174 } // catch exception
175
176 istep++;
177 }
178
179 LOG("EventGenerator", pNOTICE)
180 << utils::print::PrintFramedMesg("Thread Summary",0,'*');
181 LOG("EventGenerator", pNOTICE)
182 << "The EventRecord was visited by all EventRecordVisitors";
183
184 LOG("EventGenerator", pINFO) << "** Event generation timing info **";
185 istep=0;
186 for(miter = fEVGModuleVec->begin();
187 miter != fEVGModuleVec->end(); ++miter){
188 const EventRecordVisitorI * visitor = *miter;
189
190 BLOG("EventGenerator", pINFO)
191 << "module " << visitor->Id().Key() << " -> ~"
192 << TMath::Max(0.,(*fEVGTime)[istep++]) << " s";
193 }
194 LOG("EventGenerator", pNOTICE) << "Done generating event!";
195}
#define pNOTICE
Definition Messenger.h:61
#define BLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending no additional information.
Definition Messenger.h:212
#define pWARN
Definition Messenger.h:60
GHepRecordHistory fRecHistory
event record history
virtual void ProcessEventRecord(GHepRecord *event_rec) const =0
virtual void ResetRecord(void)
virtual bool Accept(void) const
virtual void Copy(const GHepRecord &record)
static GHepVirtualListFolder * Instance(void)
static const unsigned int kMaxEVGThreadExceptions
Definition Controls.h:33
string PrintFramedMesg(string mesg, unsigned int nl=1, const char f=' *')

References genie::GHepRecord::Accept(), BLOG, genie::GHepVirtualListFolder::Clear(), genie::GHepRecord::Copy(), genie::exceptions::EVGThreadException::FastForward(), fEVGModuleVec, fEVGTime, fRecHistory, fWatch, genie::Algorithm::Id(), genie::GHepVirtualListFolder::Instance(), genie::AlgId::Key(), genie::controls::kMaxEVGThreadExceptions, LOG, pFATAL, pINFO, pNOTICE, genie::utils::print::PrintFramedMesg(), genie::EventRecordVisitorI::ProcessEventRecord(), pWARN, genie::GHepRecord::ResetRecord(), genie::exceptions::EVGThreadException::ReturnStep(), and genie::exceptions::EVGThreadException::StepBack().

◆ ValidityContext()

const GVldContext & EventGenerator::ValidityContext ( void ) const
virtual

Implements genie::EventGeneratorI.

Definition at line 222 of file EventGenerator.cxx.

223{
224 return *fVldContext;
225}

References fVldContext.

Member Data Documentation

◆ fEVGModuleVec

vector<const EventRecordVisitorI *>* genie::EventGenerator::fEVGModuleVec
private

list of modules

Definition at line 64 of file EventGenerator.h.

Referenced by Init(), LoadConfig(), ProcessEventRecord(), and ~EventGenerator().

◆ fEVGTime

vector<double>* genie::EventGenerator::fEVGTime
private

module timing info

Definition at line 65 of file EventGenerator.h.

Referenced by Init(), LoadConfig(), ProcessEventRecord(), and ~EventGenerator().

◆ fFiltUnphysMask

TBits* genie::EventGenerator::fFiltUnphysMask
private

mask for allowing unphysical events to pass through (if requested)

Definition at line 70 of file EventGenerator.h.

Referenced by Init(), and ~EventGenerator().

◆ fIntListGen

const InteractionListGeneratorI* genie::EventGenerator::fIntListGen
private

generates list of handled interactions

Definition at line 67 of file EventGenerator.h.

Referenced by Init(), IntListGenerator(), and LoadConfig().

◆ fRecHistory

GHepRecordHistory genie::EventGenerator::fRecHistory
mutableprivate

event record history

Definition at line 71 of file EventGenerator.h.

Referenced by ProcessEventRecord().

◆ fVldContext

GVldContext* genie::EventGenerator::fVldContext
private

validity context

Definition at line 68 of file EventGenerator.h.

Referenced by Init(), LoadConfig(), ValidityContext(), and ~EventGenerator().

◆ fWatch

TStopwatch* genie::EventGenerator::fWatch
private

stopwatch for module timing

Definition at line 69 of file EventGenerator.h.

Referenced by Init(), ProcessEventRecord(), and ~EventGenerator().

◆ fXSecModel

const XSecAlgorithmI* genie::EventGenerator::fXSecModel
private

xsec model for events handled by thread

Definition at line 66 of file EventGenerator.h.

Referenced by CrossSectionAlg(), Init(), and LoadConfig().


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