InteractionGeneratorMap.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2019, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Author: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
8  University of Liverpool & STFC Rutherford Appleton Lab - May 13, 2005
9 
10  For the class documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13 
14 */
15 //____________________________________________________________________________
16 
17 #include <iomanip>
18 
19 #include <TMath.h>
20 
28 
29 using std::setw;
30 using std::setfill;
31 using std::endl;
32 using namespace genie;
33 
34 //____________________________________________________________________________
35 namespace genie {
36  ostream & operator << (ostream & stream, const InteractionGeneratorMap & intl)
37  {
38  intl.Print(stream);
39  return stream;
40  }
41 }
42 //___________________________________________________________________________
44 map<string, const EventGeneratorI *> ()
45 {
46  this->Init();
47 }
48 //___________________________________________________________________________
50  const InteractionGeneratorMap & igmap) :
51 map<string, const EventGeneratorI *> ()
52 {
53  this->Copy(igmap);
54 }
55 //___________________________________________________________________________
57 {
58  this->CleanUp();
59 }
60 //___________________________________________________________________________
62 {
63  this->CleanUp();
64  this->Init();
65 }
66 //___________________________________________________________________________
68 {
70 
73 }
74 //___________________________________________________________________________
76 {
77  delete fInitState;
78  delete fInteractionList;
79 
80  this->clear();
81 }
82 //___________________________________________________________________________
84 {
86 
87  fInitState -> Copy (*xsmap.fInitState);
89 
90  this->clear();
91 
92  InteractionGeneratorMap::const_iterator iter;
93 
94  for(iter = xsmap.begin(); iter != xsmap.end(); ++iter) {
95  string code = iter->first;
96  const EventGeneratorI * evg = iter->second;
97 
98  this->insert(map<string, const EventGeneratorI *>::value_type(code,evg));
99  }
100 }
101 //___________________________________________________________________________
103 {
105 }
106 //___________________________________________________________________________
108 {
109  SLOG("IntGenMap", pDEBUG)
110  << "Building 'interaction' -> 'generator' associations";
111  SLOG("IntGenMap", pNOTICE)
112  << "Using all simulated interactions for init-state: "
113  << init_state.AsString();
114  if(!fEventGeneratorList) {
115  LOG("IntGenMap", pWARN) << "No EventGeneratorList was loaded!!";
116  return;
117  }
118 
119  fInitState->Copy(init_state);
120 
121  EventGeneratorList::const_iterator evgliter; // event generator list iter
122  InteractionList::iterator intliter; // interaction list iter
123 
124  // loop over all EventGenerator objects used in the current job
125  for(evgliter = fEventGeneratorList->begin();
126  evgliter != fEventGeneratorList->end(); ++evgliter) {
127  // current EventGenerator
128  const EventGeneratorI * evgen = *evgliter;
129  assert(evgen);
130 
131  // ask the event generator to produce a list of all interaction it can
132  // generate for the input initial state
133  SLOG("IntGenMap", pNOTICE)
134  << "Querying [" << evgen->Id().Key() << "] for its InteractionList";
135 
136  const InteractionListGeneratorI * ilstgen = evgen->IntListGenerator();
137  InteractionList * ilst = ilstgen->CreateInteractionList(init_state);
138 
139  // no point to go on if the list is NULL - continue to next iteration
140  if(!ilst) continue;
141 
142  // append the new InteractionList to the local copy
143  fInteractionList->Append(*ilst);
144 
145  // loop over all interaction that can be genererated by the current
146  // EventGenerator and link all of them to iy
147  for(intliter = ilst->begin(); intliter != ilst->end(); ++intliter)
148  {
149  // current interaction
150  Interaction * interaction = *intliter;
151  string code = interaction->AsString();
152 
153  SLOG("IntGenMap", pDEBUG)
154  << "\nLinking: " << code << " --> to: " << evgen->Id().Key();
155  this->insert(
156  map<string, const EventGeneratorI *>::value_type(code,evgen));
157  } // loop over interactions
158  delete ilst;
159  ilst = 0;
160  } // loop over event generators
161 }
162 //___________________________________________________________________________
164  const Interaction * interaction) const
165 {
166  if(!interaction) {
167  LOG("IntGenMap", pWARN) << "Null interaction!!";
168  return 0;
169  }
170  string code = interaction->AsString();
171  InteractionGeneratorMap::const_iterator evgiter = this->find(code);
172  if(evgiter == this->end()) {
173  LOG("IntGenMap", pWARN)
174  << "No EventGeneratorI was found for interaction: \n" << code;
175  return 0;
176  }
177  const EventGeneratorI * evg = evgiter->second;
178  return evg;
179 }
180 //___________________________________________________________________________
182 {
183  return *fInteractionList;
184 }
185 //___________________________________________________________________________
187 {
188  stream << endl;
189 
190  InteractionGeneratorMap::const_iterator iter;
191 
192  unsigned int maxlen = 0;
193  for(iter = this->begin(); iter != this->end(); ++iter) {
194  string icode = iter->first;
195  unsigned int isz = (unsigned int) icode.size();
196  maxlen=TMath::Max(maxlen,isz);
197  }
198 
199  for(iter = this->begin(); iter != this->end(); ++iter) {
200  const EventGeneratorI * evg = iter->second;
201  string intstr = iter->first;
202  string evgstr = (evg) ? evg->Id().Key() : "** NULL EVENT GENERATOR **";
203 
204  stream << setfill(' ') << setw(maxlen)
205  << intstr << " --> " << evgstr << endl;
206  }
207 }
208 //___________________________________________________________________________
210  const InteractionGeneratorMap & igmap)
211 {
212  this->Copy(igmap);
213  return (*this);
214 }
215 //___________________________________________________________________________
216 
217 
const EventGeneratorList * fEventGeneratorList
InteractionGeneratorMap & operator=(const InteractionGeneratorMap &xsmap)
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
Defines the InteractionListGeneratorI interface. Concrete implementations of this interface generate ...
virtual const InteractionListGeneratorI * IntListGenerator(void) const =0
const EventGeneratorI * FindGenerator(const Interaction *in) const
vector< vector< double > > clear
Defines the EventGeneratorI interface.
void Copy(const InteractionGeneratorMap &xsmap)
string AsString(void) const
void Print(ostream &stream) const
Summary information for an interaction.
Definition: Interaction.h:56
An Interaction -> 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:97
void Copy(const InitialState &init_state)
string AsString(void) const
virtual InteractionList * CreateInteractionList(const InitialState &init) const =0
#define pWARN
Definition: Messenger.h:61
Definition: inftrees.h:24
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
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)
assert(nhit_max >=nhit_nbins)
A vector of Interaction objects.
A vector of EventGeneratorI objects.
#define pNOTICE
Definition: Messenger.h:62
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:85
Module to generate only pions from cosmic rays.
string Key(void) const
Definition: AlgId.h:47
Initial State information.
Definition: InitialState.h:49
#define pDEBUG
Definition: Messenger.h:64