XSecAlgorithmMap.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2020, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
7  University of Liverpool & STFC Rutherford Appleton Laboratory
8 */
9 //____________________________________________________________________________
10 
19 
20 using std::endl;
21 using namespace genie;
22 
23 //____________________________________________________________________________
24 namespace genie {
25  ostream & operator << (ostream & stream, const XSecAlgorithmMap & intl)
26  {
27  intl.Print(stream);
28  return stream;
29  }
30 }
31 //___________________________________________________________________________
33 map<string, const XSecAlgorithmI *> ()
34 {
35  this->Init();
36 }
37 //___________________________________________________________________________
39 map<string, const XSecAlgorithmI *> ()
40 {
41  this->Copy(xsmap);
42 }
43 //___________________________________________________________________________
45 {
46  this->CleanUp();
47 }
48 //___________________________________________________________________________
50 {
51  this->CleanUp();
52  this->Init();
53 }
54 //___________________________________________________________________________
56 {
58 
61 }
62 //___________________________________________________________________________
64 {
65  delete fInitState;
66  delete fInteractionList;
67 
68  this->clear();
69 }
70 //___________________________________________________________________________
72 {
74 
75  fInitState -> Copy (*xsmap.fInitState);
77 
78  this->clear();
79 
81 
82  for(iter = xsmap.begin(); iter != xsmap.end(); ++iter) {
83  string code = iter->first;
84  const XSecAlgorithmI * alg = iter->second;
85 
86  this->insert(map<string, const XSecAlgorithmI *>::value_type(code,alg));
87  }
88 }
89 //___________________________________________________________________________
91 {
92  fEventGeneratorList = list;
93 }
94 //___________________________________________________________________________
95 void XSecAlgorithmMap::BuildMap(const InitialState & init_state)
96 {
97  LOG("XSecAlgMap", pNOTICE)
98  << "Building 'interaction' -> 'xsec algorithm' associations";
99  LOG("XSecAlgMap", pNOTICE)
100  << "Using all simulated interactions for init-state: "
101  << init_state.AsString();
102  if(!fEventGeneratorList) {
103  LOG("XSecAlgMap", pWARN)
104  << "No EventGeneratorList was loaded. Will not build XSecAlgorithmMap";
105  return;
106  }
107 
108  fInitState->Copy(init_state);
109 
110  EventGeneratorList::const_iterator evgliter; // event generator list iter
111  InteractionList::iterator intliter; // interaction list iter
112 
113  // loop over all EventGenerator objects used in the current job
114  for(evgliter = fEventGeneratorList->begin();
115  evgliter != fEventGeneratorList->end(); ++evgliter) {
116  // current EventGenerator
117  const EventGeneratorI * evgen = *evgliter;
118  assert(evgen);
119 
120  // ask the event generator to produce a list of all interaction it can
121  // generate for the input initial state
122  LOG("XSecAlgMap", pNOTICE)
123  << "Querying [" << evgen->Id().Key() << "] for its InteractionList";
124 
125  const InteractionListGeneratorI * ilstgen = evgen->IntListGenerator();
126  InteractionList * ilst = ilstgen->CreateInteractionList(init_state);
127 
128  // no point to go on if the list is NULL - continue to next iteration
129  if(!ilst) continue;
130 
131  // append the new InteractionList to the local copy
132  fInteractionList->Append(*ilst);
133 
134  // cross section algorithm used by this EventGenerator
135  const XSecAlgorithmI * xsec_alg = evgen->CrossSectionAlg();
136 
137  // loop over all interaction that can be genererated by the current
138  // EventGenerator and link all of them to the current XSecAlgorithmI
139  for(intliter = ilst->begin(); intliter != ilst->end(); ++intliter)
140  {
141  // current interaction
142  Interaction * interaction = *intliter;
143  string code = interaction->AsString();
144 
145  // link with the xsec algorithm
146  SLOG("XSecAlgMap", pINFO)
147  << "\nLinking: " << code
148  << "\n --> with xsec algorithm: " << xsec_alg->Id().Key();
149  this->insert(
150  map<string, const XSecAlgorithmI *>::value_type(code,xsec_alg));
151 
152  } // loop over interactions
153  delete ilst;
154  ilst = 0;
155  } // loop over event generators
156 }
157 //___________________________________________________________________________
159  const Interaction * interaction) const
160 {
161  if(!interaction) {
162  LOG("XSecAlgMap", pWARN) << "Null interaction!!";
163  return 0;
164  }
165 
166  string code = interaction->AsString();
167 
168  XSecAlgorithmMap::const_iterator xsec_alg_iter = this->find(code);
169  if(xsec_alg_iter == this->end()) {
170  LOG("XSecAlgMap", pWARN)
171  << "No XSecAlgorithmI was found for interaction: \n" << code;
172  return 0;
173  }
174 
175  const XSecAlgorithmI * xsec_alg = xsec_alg_iter->second;
176  return xsec_alg;
177 }
178 //___________________________________________________________________________
180 {
181  return *fInteractionList;
182 }
183 //___________________________________________________________________________
184 void XSecAlgorithmMap::Print(ostream & stream) const
185 {
187 
188  stream<< "Printing 'interaction' -> 'xsec algorithm' associations" << endl;
189 
190  for(iter = this->begin(); iter != this->end(); ++iter) {
191  string code = iter->first;
192  const XSecAlgorithmI * alg = iter->second;
193  if(alg) {
194  stream << code << " -> " << alg->Id().Key() << endl;
195  } else {
196  stream << code << " -> **** NULL XSEC ALGORITHM ****" << endl;
197  }
198  }
199 }
200 //___________________________________________________________________________
202 {
203  this->Copy(xs);
204  return (*this);
205 }
206 //___________________________________________________________________________
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
Cross Section Calculation Interface.
intermediate_table::iterator iterator
XSecAlgorithmMap & operator=(const XSecAlgorithmMap &xsmap)
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
const InteractionList & GetInteractionList(void) const
Defines the InteractionListGeneratorI interface. Concrete implementations of this interface generate ...
std::string string
Definition: nybbler.cc:12
virtual const InteractionListGeneratorI * IntListGenerator(void) const =0
const EventGeneratorList * fEventGeneratorList
Defines the EventGeneratorI interface.
intermediate_table::const_iterator const_iterator
string AsString(void) const
void Copy(const XSecAlgorithmMap &xsmap)
void BuildMap(const InitialState &init_state)
Summary information for an interaction.
Definition: Interaction.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
An Interaction -> XSecAlgorithmI associative container. The container is being built for the loaded E...
const XSecAlgorithmI * FindXSecAlgorithm(const Interaction *in) const
void Copy(const InitialState &init_state)
void UseGeneratorList(const EventGeneratorList *list)
string AsString(void) const
CodeOutputInterface * code
#define pINFO
Definition: Messenger.h:62
void Print(ostream &stream) const
virtual InteractionList * CreateInteractionList(const InitialState &init) const =0
#define pWARN
Definition: Messenger.h:60
virtual const XSecAlgorithmI * CrossSectionAlg(void) const =0
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition: Algorithm.h:97
void Append(const InteractionList &intl)
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
InteractionList * fInteractionList
A vector of Interaction objects.
A vector of EventGeneratorI objects.
vector< vector< double > > clear
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
#define pNOTICE
Definition: Messenger.h:61
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
Event Generation using GENIE, cosmics or single particles.
string Key(void) const
Definition: AlgId.h:46
QTextStream & endl(QTextStream &s)
Initial State information.
Definition: InitialState.h:48