GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PDGCodeList.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <c.andreopoulos \at cern.ch>
7  University of Liverpool
8 */
9 //____________________________________________________________________________
10 
11 #include <algorithm>
12 #include <iomanip>
13 #include <string>
14 
18 
19 using std::setw;
20 using std::setfill;
21 using std::endl;
22 using std::string;
23 
24 using namespace genie;
25 
26 //____________________________________________________________________________
27 namespace genie {
28  ostream & operator << (ostream & stream, const PDGCodeList & list)
29  {
30  list.Print(stream);
31  return stream;
32  }
33 }
34 //___________________________________________________________________________
35 PDGCodeList::PDGCodeList(bool allowdup) :
36 vector<int>()
37 {
38  fAllowDuplicateEntries = allowdup;
39 }
40 //___________________________________________________________________________
41 PDGCodeList::PDGCodeList(size_type n, bool allowdup) :
42 vector<int>(n)
43 {
44  fAllowDuplicateEntries = allowdup;
45 }
46 //___________________________________________________________________________
48 vector<int>()
49 {
50  this->Copy(list);
51 }
52 //___________________________________________________________________________
54 {
55 
56 }
57 //___________________________________________________________________________
58 void PDGCodeList::push_back(int pdg_code)
59 {
60  if(this->CheckPDGCode(pdg_code)) vector<int>::push_back(pdg_code);
61 }
62 //___________________________________________________________________________
63 void PDGCodeList::insert(iterator pos, size_type n, const int& pdg_code)
64 {
65  if(this->CheckPDGCode(pdg_code)) {
66  if(n>1) n = 1;
67  vector<int>::insert(pos,n,pdg_code);
68  }
69 }
70 //___________________________________________________________________________
71 bool PDGCodeList::CheckPDGCode(int pdg_code) const
72 {
73 // check whether the PDG code can be inserted
74 
75  bool exists = this->ExistsInPDGLibrary(pdg_code);
76  if(!exists) {
77  LOG("PDG", pERROR)
78  << "Can't add non-existent particle [pdgc = " << pdg_code << "]";
79  return false;
80  }
81 
83  bool added = this->ExistsInPDGCodeList(pdg_code);
84  if(added) {
85  LOG("PDG", pDEBUG)
86  << "Particle [pdgc = " << pdg_code << "] was already added";
87  return false;
88  }
89  }
90  return true;
91 }
92 //___________________________________________________________________________
93 bool PDGCodeList::ExistsInPDGLibrary(int pdg_code) const
94 {
95 // check whether the PDG code is a valid one (exists in PDGLibrary)
96 
97  PDGLibrary * pdglib = PDGLibrary::Instance();
98  TParticlePDG * particle = pdglib->Find(pdg_code);
99  if(!particle) return false;
100  return true;
101 }
102 //___________________________________________________________________________
103 bool PDGCodeList::ExistsInPDGCodeList(int pdg_code) const
104 {
105 // check whether the PDG code already exists in the list
106 
107  PDGCodeList::const_iterator bci = this->begin();
108  PDGCodeList::const_iterator eci = this->end();
109 
110  if(find(bci,eci,pdg_code) != eci) return true;
111 
112  return false;
113 /*
114  int n = count(this->begin(), this->end(), pdg_code);
115  if(n!=0) return true;
116  return false;
117 */
118 }
119 //___________________________________________________________________________
120 void PDGCodeList::Print(ostream & stream) const
121 {
122  stream << "\n[-]" << endl;
123 
124  PDGLibrary * pdglib = PDGLibrary::Instance();
125 
126  PDGCodeList::const_iterator iter;
127  size_t nc = this->size();
128 
129  for(iter = this->begin(); iter != this->end(); ++iter) {
130  int pdg_code = *iter;
131  TParticlePDG * p = pdglib->Find(pdg_code);
132 
133  if(!p) {
134  stream << " |---o ** ERR: no particle with PDG code: " << pdg_code;
135  } else {
136  string name = p->GetName();
137  stream << " |---o "
138  << setfill(' ') << setw(15) << name
139  << " (PDG code = " << pdg_code << ")";
140  }
141  if( (--nc) > 0) stream << endl;
142  }
143 }
144 //___________________________________________________________________________
145 void PDGCodeList::Copy(const PDGCodeList & list)
146 {
147  this->clear();
148 
149  PDGCodeList::const_iterator iter;
150  for(iter = list.begin(); iter != list.end(); ++iter) {
151  int code = *iter;
152  this->push_back(code);
153  }
154 
156 }
157 //___________________________________________________________________________
159 {
160  this->Copy(list);
161  return (*this);
162 }
163 //___________________________________________________________________________
#define pERROR
Definition: Messenger.h:59
PDGCodeList & operator=(const PDGCodeList &list)
overloaded operators
bool ExistsInPDGCodeList(int pdg_code) const
PDGCodeList(bool allowdup=false)
Definition: PDGCodeList.cxx:35
A list of PDG codes.
Definition: PDGCodeList.h:32
bool fAllowDuplicateEntries
allow duplicate entries in the list?
Definition: PDGCodeList.h:64
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:68
Singleton class to load &amp; serve a TDatabasePDG.
Definition: PDGLibrary.h:35
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
bool ExistsInPDGLibrary(int pdg_code) const
Definition: PDGCodeList.cxx:93
bool CheckPDGCode(int pdg_code) const
PDG code checks used by PDGCodeList.
Definition: PDGCodeList.cxx:71
vector< vector< double > > clear
TParticlePDG * Find(int pdgc, bool must_exist=true)
Definition: PDGLibrary.cxx:86
void Print(ostream &stream) const
void insert(iterator pos, size_type n, const int &x)
Definition: PDGCodeList.cxx:63
void Copy(const PDGCodeList &list)
copy / print
void push_back(int pdg_code)
Definition: PDGCodeList.cxx:58
#define pDEBUG
Definition: Messenger.h:63