GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InteractionGeneratorMap.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <c.andreopoulos \at cern.ch>
7  University of Liverpool
8 */
9 //____________________________________________________________________________
10 
11 #include <iomanip>
12 
13 #include <TMath.h>
14 
22 
23 using std::setw;
24 using std::setfill;
25 using std::endl;
26 using namespace genie;
27 
28 //____________________________________________________________________________
29 namespace genie {
30  ostream & operator << (ostream & stream, const InteractionGeneratorMap & intl)
31  {
32  intl.Print(stream);
33  return stream;
34  }
35 }
36 //___________________________________________________________________________
38 map<string, const EventGeneratorI *> ()
39 {
40  this->Init();
41 }
42 //___________________________________________________________________________
44  const InteractionGeneratorMap & igmap) :
45 map<string, const EventGeneratorI *> ()
46 {
47  this->Copy(igmap);
48 }
49 //___________________________________________________________________________
51 {
52  this->CleanUp();
53 }
54 //___________________________________________________________________________
56 {
57  this->CleanUp();
58  this->Init();
59 }
60 //___________________________________________________________________________
62 {
64 
67 }
68 //___________________________________________________________________________
70 {
71  delete fInitState;
72  delete fInteractionList;
73 
74  this->clear();
75 }
76 //___________________________________________________________________________
78 {
80 
81  fInitState -> Copy (*xsmap.fInitState);
83 
84  this->clear();
85 
86  InteractionGeneratorMap::const_iterator iter;
87 
88  for(iter = xsmap.begin(); iter != xsmap.end(); ++iter) {
89  string code = iter->first;
90  const EventGeneratorI * evg = iter->second;
91 
92  this->insert(map<string, const EventGeneratorI *>::value_type(code,evg));
93  }
94 }
95 //___________________________________________________________________________
97 {
99 }
100 //___________________________________________________________________________
102 {
103  SLOG("IntGenMap", pDEBUG)
104  << "Building 'interaction' -> 'generator' associations";
105  SLOG("IntGenMap", pNOTICE)
106  << "Using all simulated interactions for init-state: "
107  << init_state.AsString();
108  if(!fEventGeneratorList) {
109  LOG("IntGenMap", pWARN) << "No EventGeneratorList was loaded!!";
110  return;
111  }
112 
113  fInitState->Copy(init_state);
114 
115  EventGeneratorList::const_iterator evgliter; // event generator list iter
116  InteractionList::iterator intliter; // interaction list iter
117 
118  // loop over all EventGenerator objects used in the current job
119  for(evgliter = fEventGeneratorList->begin();
120  evgliter != fEventGeneratorList->end(); ++evgliter) {
121  // current EventGenerator
122  const EventGeneratorI * evgen = *evgliter;
123  assert(evgen);
124 
125  // ask the event generator to produce a list of all interaction it can
126  // generate for the input initial state
127  SLOG("IntGenMap", pNOTICE)
128  << "Querying [" << evgen->Id().Key() << "] for its InteractionList";
129 
130  const InteractionListGeneratorI * ilstgen = evgen->IntListGenerator();
131  InteractionList * ilst = ilstgen->CreateInteractionList(init_state);
132 
133  // no point to go on if the list is NULL - continue to next iteration
134  if(!ilst) continue;
135 
136  // append the new InteractionList to the local copy
137  fInteractionList->Append(*ilst);
138 
139  // loop over all interaction that can be genererated by the current
140  // EventGenerator and link all of them to iy
141  for(intliter = ilst->begin(); intliter != ilst->end(); ++intliter)
142  {
143  // current interaction
144  Interaction * interaction = *intliter;
145  string code = interaction->AsString();
146 
147  SLOG("IntGenMap", pDEBUG)
148  << "\nLinking: " << code << " --> to: " << evgen->Id().Key();
149  this->insert(
150  map<string, const EventGeneratorI *>::value_type(code,evgen));
151  } // loop over interactions
152  delete ilst;
153  ilst = 0;
154  } // loop over event generators
155 }
156 //___________________________________________________________________________
158  const Interaction * interaction) const
159 {
160  if(!interaction) {
161  LOG("IntGenMap", pWARN) << "Null interaction!!";
162  return 0;
163  }
164  string code = interaction->AsString();
165  InteractionGeneratorMap::const_iterator evgiter = this->find(code);
166  if(evgiter == this->end()) {
167  LOG("IntGenMap", pWARN)
168  << "No EventGeneratorI was found for interaction: \n" << code;
169  return 0;
170  }
171  const EventGeneratorI * evg = evgiter->second;
172  return evg;
173 }
174 //___________________________________________________________________________
176 {
177  return *fInteractionList;
178 }
179 //___________________________________________________________________________
180 void InteractionGeneratorMap::Print(ostream & stream) const
181 {
182  stream << endl;
183 
184  InteractionGeneratorMap::const_iterator iter;
185 
186  unsigned int maxlen = 0;
187  for(iter = this->begin(); iter != this->end(); ++iter) {
188  string icode = iter->first;
189  unsigned int isz = (unsigned int) icode.size();
190  maxlen=TMath::Max(maxlen,isz);
191  }
192 
193  for(iter = this->begin(); iter != this->end(); ++iter) {
194  const EventGeneratorI * evg = iter->second;
195  string intstr = iter->first;
196  string evgstr = (evg) ? evg->Id().Key() : "** NULL EVENT GENERATOR **";
197 
198  stream << setfill(' ') << setw(maxlen)
199  << intstr << " --> " << evgstr << endl;
200  }
201 }
202 //___________________________________________________________________________
204  const InteractionGeneratorMap & igmap)
205 {
206  this->Copy(igmap);
207  return (*this);
208 }
209 //___________________________________________________________________________
const EventGeneratorList * fEventGeneratorList
InteractionGeneratorMap & operator=(const InteractionGeneratorMap &xsmap)
Defines the InteractionListGeneratorI interface. Concrete implementations of this interface generate ...
const EventGeneratorI * FindGenerator(const Interaction *in) const
Defines the EventGeneratorI interface.
void Copy(const InteractionGeneratorMap &xsmap)
virtual InteractionList * CreateInteractionList(const InitialState &init) const =0
string AsString(void) const
void Print(ostream &stream) const
Summary information for an interaction.
Definition: Interaction.h:56
An Interaction -&gt; EventGeneratorI associative container. The container is being built for the loaded ...
void BuildMap(const InitialState &init_state)
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void Copy(const InitialState &init_state)
string AsString(void) const
#define pWARN
Definition: Messenger.h:60
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition: Algorithm.h:98
void Append(const InteractionList &intl)
const InteractionList & GetInteractionList(void) const
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
A vector of Interaction objects.
A vector of EventGeneratorI objects.
vector< vector< double > > clear
virtual const InteractionListGeneratorI * IntListGenerator(void) const =0
#define pNOTICE
Definition: Messenger.h:61
void UseGeneratorList(const EventGeneratorList *list)
#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 Key(void) const
Definition: AlgId.h:46
Initial State information.
Definition: InitialState.h:48
#define pDEBUG
Definition: Messenger.h:63