BaryonResList.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 
11 #include <algorithm>
12 
17 
18 using std::endl;
19 
20 using namespace genie;
21 
22 //____________________________________________________________________________
23 namespace genie
24 {
25  ostream & operator<<(ostream & stream, const BaryonResList & res_list)
26  {
27  res_list.Print(stream);
28  return stream;
29  }
30 }
31 //____________________________________________________________________________
33 {
34  fResVec = 0;
35 }
36 //____________________________________________________________________________
38 {
39  fResVec = 0;
40  this->Copy(res_list);
41 }
42 //____________________________________________________________________________
44 {
45  if(fResVec) delete fResVec;
46 }
47 //____________________________________________________________________________
48 unsigned int BaryonResList::NResonances(void) const
49 {
50  if(!fResVec) {
51  SLOG("BaryonResList", pERROR) << "Null Resonance List";
52  return 0;
53  }
54  return fResVec->size();
55 }
56 //____________________________________________________________________________
57 string BaryonResList::ResonanceName(unsigned int ires) const
58 {
59  if(!fResVec) {
60  SLOG("BaryonResList", pERROR) << "Null Resonance List";
61  return "-";
62  }
63  if(ires >= this->NResonances() ) {
64  SLOG("BaryonResList", pERROR) << "Resonance idx: " << ires
65  << " outside limits: [0, " << this->NResonances() << "]";
66  return "-";
67  }
68  return utils::res::AsString( (*fResVec)[ires] );
69 }
70 //____________________________________________________________________________
71 Resonance_t BaryonResList::ResonanceId(unsigned int ires) const
72 {
73  if(!fResVec) {
74  SLOG("BaryonResList", pERROR) << "Null Resonance List";
75  return kNoResonance;
76  }
77  if(ires >= this->NResonances() ) {
78  SLOG("BaryonResList", pERROR) << "Resonance idx: " << ires
79  << " outside limits: [0, " << this->NResonances() << "]";
80  return kNoResonance;
81  }
82  return (*fResVec)[ires];
83 }
84 //____________________________________________________________________________
85 int BaryonResList::ResonancePdgCode(unsigned int /*ires*/) const
86 {
87  return 0;
88 }
89 //____________________________________________________________________________
91 {
92  if(!fResVec) {
93  SLOG("BaryonResList", pWARN) << "NULL resonance list!";
94  return false;
95  }
96  int n = count(fResVec->begin(), fResVec->end(), res);
97  if(n!=0) return true;
98  return false;
99 }
100 //___________________________________________________________________________
101 void BaryonResList::DecodeFromNameList(string input_list, string delimiter)
102 {
103  //-- remove all spaces in the input string coming from the XML config file
104 
105  string list = utils::str::FilterString(" ", input_list);
106 
107  vector<string> resonances = utils::str::Split(list, delimiter);
108 
109  SLOG("BaryonResList", pINFO) << list;
110  SLOG("BaryonResList", pINFO) << resonances.size();
111 
112  if(fResVec) delete fResVec;
113  fResVec = new vector<Resonance_t> (resonances.size());
114 
115  unsigned int ires = 0;
117  for(riter = resonances.begin(); riter != resonances.end(); ++riter) {
118 
119  Resonance_t res = utils::res::FromString( (*riter).c_str() );
120  if( res == kNoResonance ) {
121  SLOG("BaryonResList", pERROR) << "*** Unknown resonance: " << *riter;
122  } else (*fResVec)[ires++] = res;
123  }
124 }
125 //____________________________________________________________________________
127 {
128  if(fResVec) fResVec->clear();
129 }
130 //____________________________________________________________________________
131 void BaryonResList::Copy(const BaryonResList & res_list)
132 {
133  if(fResVec) fResVec->clear();
134 
135  unsigned int nres = res_list.NResonances();
136  if(nres==0) return;
137 
138  if(!fResVec) fResVec = new vector<Resonance_t> (nres);
139 
140  for(unsigned int ires = 0; ires < nres; ires++) {
141  (*fResVec)[ires] = res_list.ResonanceId(ires);
142  }
143 }
144 //____________________________________________________________________________
145 void BaryonResList::Print(ostream & stream) const
146 {
147  stream << "\n [-] Resonance List\n";
148 
150  for(riter = fResVec->begin(); riter != fResVec->end(); ++riter) {
151  stream << " |--> RES: " << utils::res::AsString(*riter) << endl;
152  }
153 }
154 //____________________________________________________________________________
155 auto BaryonResList::begin() noexcept -> typename vector<Resonance_t>::iterator
156 {
157  return fResVec->begin();
158 }
159 //____________________________________________________________________________
160 auto BaryonResList::end() noexcept -> typename vector<Resonance_t>::iterator
161 {
162  return fResVec->end();
163 }
164 //____________________________________________________________________________
166 {
167  return fResVec->begin();
168 }
169 //____________________________________________________________________________
171 {
172  return fResVec->end();
173 }
174 //____________________________________________________________________________
176 {
177  return fResVec->cbegin();
178 }
179 //____________________________________________________________________________
181 {
182  return fResVec->cend();
183 }
184 //____________________________________________________________________________
185 
vector< Resonance_t > * fResVec
Definition: BaryonResList.h:67
Resonance_t FromString(const char *res)
string -> resonance id
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
#define pERROR
Definition: Messenger.h:59
auto cend() const noexcept-> typename vector< Resonance_t >::const_iterator
void Copy(const BaryonResList &rl)
void DecodeFromNameList(string list, string delimiter=",")
string ResonanceName(unsigned int ires) const
struct vector vector
Encapsulates a list of baryon resonances.
Definition: BaryonResList.h:37
intermediate_table::const_iterator const_iterator
auto cbegin() const noexcept-> typename vector< Resonance_t >::const_iterator
enum genie::EResonance Resonance_t
unsigned int NResonances(void) const
std::void_t< T > n
#define pINFO
Definition: Messenger.h:62
void Print(ostream &stream) const
#define pWARN
Definition: Messenger.h:60
string FilterString(string filt, string input)
Definition: StringUtils.cxx:79
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
bool Find(Resonance_t res) const
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
auto end() noexcept-> typename vector< Resonance_t >::iterator
int ResonancePdgCode(unsigned int ires) const
const char * AsString(Resonance_t res)
resonance id -> string
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
auto begin() noexcept-> typename vector< Resonance_t >::iterator
QTextStream & endl(QTextStream &s)
Resonance_t ResonanceId(unsigned int ires) const