PDGCodeList.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  @ Sep 30, 2009 - CA
14  Const correctness: Methods CheckPDGCode(), ExistsInPDGLibrary() and
15  ExistsInPDGCodeList() were made const.
16 
17 */
18 //____________________________________________________________________________
19 
20 #include <algorithm>
21 #include <iomanip>
22 #include <string>
23 
27 
28 using std::setw;
29 using std::setfill;
30 using std::endl;
31 using std::string;
32 
33 using namespace genie;
34 
35 //____________________________________________________________________________
36 namespace genie {
37  ostream & operator << (ostream & stream, const PDGCodeList & list)
38  {
39  list.Print(stream);
40  return stream;
41  }
42 }
43 //___________________________________________________________________________
44 PDGCodeList::PDGCodeList(bool allowdup) :
45 vector<int>()
46 {
47  fAllowDuplicateEntries = allowdup;
48 }
49 //___________________________________________________________________________
51 vector<int>(n)
52 {
53  fAllowDuplicateEntries = allowdup;
54 }
55 //___________________________________________________________________________
57 vector<int>()
58 {
59  this->Copy(list);
60 }
61 //___________________________________________________________________________
63 {
64 
65 }
66 //___________________________________________________________________________
67 void PDGCodeList::push_back(int pdg_code)
68 {
69  if(this->CheckPDGCode(pdg_code)) vector<int>::push_back(pdg_code);
70 }
71 //___________________________________________________________________________
72 void PDGCodeList::insert(iterator pos, size_type n, const int& pdg_code)
73 {
74  if(this->CheckPDGCode(pdg_code)) {
75  if(n>1) n = 1;
76  vector<int>::insert(pos,n,pdg_code);
77  }
78 }
79 //___________________________________________________________________________
80 bool PDGCodeList::CheckPDGCode(int pdg_code) const
81 {
82 // check whether the PDG code can be inserted
83 
84  bool exists = this->ExistsInPDGLibrary(pdg_code);
85  if(!exists) {
86  LOG("PDG", pERROR)
87  << "Can't add non-existent particle [pdgc = " << pdg_code << "]";
88  return false;
89  }
90 
92  bool added = this->ExistsInPDGCodeList(pdg_code);
93  if(added) {
94  LOG("PDG", pDEBUG)
95  << "Particle [pdgc = " << pdg_code << "] was already added";
96  return false;
97  }
98  }
99  return true;
100 }
101 //___________________________________________________________________________
102 bool PDGCodeList::ExistsInPDGLibrary(int pdg_code) const
103 {
104 // check whether the PDG code is a valid one (exists in PDGLibrary)
105 
106  PDGLibrary * pdglib = PDGLibrary::Instance();
107  TParticlePDG * particle = pdglib->Find(pdg_code);
108  if(!particle) return false;
109  return true;
110 }
111 //___________________________________________________________________________
112 bool PDGCodeList::ExistsInPDGCodeList(int pdg_code) const
113 {
114 // check whether the PDG code already exists in the list
115 
116  PDGCodeList::const_iterator bci = this->begin();
117  PDGCodeList::const_iterator eci = this->end();
118 
119  if(find(bci,eci,pdg_code) != eci) return true;
120 
121  return false;
122 /*
123  int n = count(this->begin(), this->end(), pdg_code);
124  if(n!=0) return true;
125  return false;
126 */
127 }
128 //___________________________________________________________________________
129 void PDGCodeList::Print(ostream & stream) const
130 {
131  stream << "\n[-]" << endl;
132 
133  PDGLibrary * pdglib = PDGLibrary::Instance();
134 
135  PDGCodeList::const_iterator iter;
136  size_t nc = this->size();
137 
138  for(iter = this->begin(); iter != this->end(); ++iter) {
139  int pdg_code = *iter;
140  TParticlePDG * p = pdglib->Find(pdg_code);
141 
142  if(!p) {
143  stream << " |---o ** ERR: no particle with PDG code: " << pdg_code;
144  } else {
145  string name = p->GetName();
146  stream << " |---o "
147  << setfill(' ') << setw(15) << name
148  << " (PDG code = " << pdg_code << ")";
149  }
150  if( (--nc) > 0) stream << endl;
151  }
152 }
153 //___________________________________________________________________________
155 {
156  this->clear();
157 
158  PDGCodeList::const_iterator iter;
159  for(iter = list.begin(); iter != list.end(); ++iter) {
160  int code = *iter;
161  this->push_back(code);
162  }
163 
165 }
166 //___________________________________________________________________________
168 {
169  this->Copy(list);
170  return (*this);
171 }
172 //___________________________________________________________________________
173 
const XML_Char * name
Definition: expat.h:151
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
#define pERROR
Definition: Messenger.h:60
PDGCodeList & operator=(const PDGCodeList &list)
overloaded operators
const char * p
Definition: xmltok.h:285
vector< vector< double > > clear
bool ExistsInPDGCodeList(int pdg_code) const
PDGCodeList(bool allowdup=false)
Definition: PDGCodeList.cxx:44
A list of PDG codes.
Definition: PDGCodeList.h:33
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Definition: typedefs.hpp:11
bool fAllowDuplicateEntries
allow duplicate entries in the list?
Definition: PDGCodeList.h:65
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
base_types push_back(int_type())
Definition: inftrees.h:24
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:43
Singleton class to load & serve a TDatabasePDG.
Definition: PDGLibrary.h:30
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
TParticlePDG * Find(int pdgc)
Definition: PDGLibrary.cxx:61
enum BeamMode nc
bool ExistsInPDGLibrary(int pdg_code) const
bool CheckPDGCode(int pdg_code) const
PDG code checks used by PDGCodeList.
Definition: PDGCodeList.cxx:80
void Print(ostream &stream) const
void insert(iterator pos, size_type n, const int &x)
Definition: PDGCodeList.cxx:72
void Copy(const PDGCodeList &list)
copy / print
void push_back(int pdg_code)
Definition: PDGCodeList.cxx:67
#define pDEBUG
Definition: Messenger.h:64
enum BeamMode string