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