GENIEGenerator
Loading...
Searching...
No Matches
genie::NaturalIsotopes Class Reference

Singleton class to load & serve tables of natural occurring isotopes. More...

#include <NaturalIsotopes.h>

Collaboration diagram for genie::NaturalIsotopes:
[legend]

Classes

struct  Cleaner

Public Member Functions

int NElements (int Z) const
const NaturalIsotopeElementDataElementData (int Z, int ielement) const
const NaturalIsotopeElementDataElementDataPdg (int Z, int pdgcode) const

Static Public Member Functions

static NaturalIsotopesInstance (void)

Private Member Functions

 NaturalIsotopes ()
 NaturalIsotopes (const NaturalIsotopes &)
virtual ~NaturalIsotopes ()
bool LoadTable (void)

Private Attributes

map< int, vector< NaturalIsotopeElementData * > > fNaturalIsotopesTable

Static Private Attributes

static NaturalIsotopesfInstance = 0

Friends

struct Cleaner

Detailed Description

Singleton class to load & serve tables of natural occurring isotopes.

Author
Costas Andreopoulos <c.andreopoulos \at cern.ch> University of Liverpool
  Jim Dobson <j.dobson07@imperial.ac.uk>
Imperial College London
Created:\n May 30, 2008
License:\n Copyright (c) 2003-2025, The GENIE Collaboration
For the full text of the license visit http://copyright.genie-mc.org

Definition at line 33 of file NaturalIsotopes.h.

Constructor & Destructor Documentation

◆ NaturalIsotopes() [1/2]

NaturalIsotopes::NaturalIsotopes ( )
private

Definition at line 31 of file NaturalIsotopes.cxx.

32{
33 if( ! this->LoadTable() ) {
34 LOG("NatIsotop", pERROR) << "NaturalIsotopes initialization failed!";
35 }
36 fInstance = 0;
37}
#define pERROR
Definition Messenger.h:59
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
static NaturalIsotopes * fInstance

References fInstance, LoadTable(), LOG, and pERROR.

Referenced by Instance(), and NaturalIsotopes().

◆ NaturalIsotopes() [2/2]

genie::NaturalIsotopes::NaturalIsotopes ( const NaturalIsotopes & )
private

References NaturalIsotopes().

◆ ~NaturalIsotopes()

NaturalIsotopes::~NaturalIsotopes ( )
privatevirtual

Definition at line 39 of file NaturalIsotopes.cxx.

40{
41 cout << "NaturalIsotopes singleton dtor: "
42 << "Deleting natural isotope data tables" << endl;
43
44 map<int, vector<NaturalIsotopeElementData*> >::iterator miter;
45 vector<NaturalIsotopeElementData*>::iterator viter;
46
47 for(miter = fNaturalIsotopesTable.begin();
48 miter != fNaturalIsotopesTable.end(); ++miter) {
49 vector<NaturalIsotopeElementData*> vec = miter->second;
50 for(viter = vec.begin(); viter != vec.end(); ++viter) {
51 NaturalIsotopeElementData * element_data = *viter;
52 if(element_data) {
53 delete element_data;
54 element_data = 0;
55 }
56 }
57 vec.clear();
58 }
60 fInstance = 0;
61}
map< int, vector< NaturalIsotopeElementData * > > fNaturalIsotopesTable

References fInstance, and fNaturalIsotopesTable.

Member Function Documentation

◆ ElementData()

const NaturalIsotopeElementData * NaturalIsotopes::ElementData ( int Z,
int ielement ) const

Definition at line 90 of file NaturalIsotopes.cxx.

91{
92 map<int, vector<NaturalIsotopeElementData*> >::const_iterator miter;
93
94 if( (miter=fNaturalIsotopesTable.find(Z)) == fNaturalIsotopesTable.end()) {
95 LOG("NatIsotop", pWARN)
96 << "Table has no elements for natural isotope Z = " << Z;
97 return 0;
98 }
99 vector<NaturalIsotopeElementData*> vec = miter->second;
100 if(ielement >= (int)vec.size() || ielement < 0) {
101 LOG("NatIsotop", pWARN)
102 << "Natural isotope Z = " << Z << " has " << vec.size() << " elements"
103 << " (element = " << ielement << " was requested)";
104 return 0;
105 }
106 return vec[ielement];
107}
#define pWARN
Definition Messenger.h:60

References fNaturalIsotopesTable, LOG, and pWARN.

Referenced by main().

◆ ElementDataPdg()

const NaturalIsotopeElementData * NaturalIsotopes::ElementDataPdg ( int Z,
int pdgcode ) const

Definition at line 110 of file NaturalIsotopes.cxx.

111{
112 map<int, vector<NaturalIsotopeElementData*> >::const_iterator miter;
113
114 if( (miter=fNaturalIsotopesTable.find(Z)) == fNaturalIsotopesTable.end()) {
115 LOG("NatIsotop", pWARN)
116 << "Table has no elements for natural isotope Z = " << Z;
117 return 0;
118 }
119
120 vector<NaturalIsotopeElementData*> vec = miter->second;
121 for (int i; i<vec.size(); i++) {
122 if (vec[i]->PdgCode()==pdgcode) return vec[i];
123 }
124
125 LOG("NatIsotop", pWARN)
126 << "Natural isotope Z = " << Z << " has " << vec.size() << " elements"
127 << " (pdgcode = " << pdgcode << " was requested)";
128 return 0;
129
130}
int PdgCode(Resonance_t res, int Q)
(resonance id, charge) -> PDG code

References fNaturalIsotopesTable, LOG, and pWARN.

◆ Instance()

NaturalIsotopes * NaturalIsotopes::Instance ( void )
static

Definition at line 63 of file NaturalIsotopes.cxx.

64{
65 if(fInstance == 0) {
66 LOG("NatIsotop", pINFO) << "NaturalIsotopes late initialization";
67
68 static NaturalIsotopes::Cleaner cleaner;
70
72 }
73 return fInstance;
74}
#define pINFO
Definition Messenger.h:62

References genie::NaturalIsotopes::Cleaner::DummyMethodAndSilentCompiler(), fInstance, LOG, NaturalIsotopes(), and pINFO.

Referenced by main().

◆ LoadTable()

bool NaturalIsotopes::LoadTable ( void )
private

eof

Definition at line 132 of file NaturalIsotopes.cxx.

133{
134 // get the natural isotopes table filename
135 string filename = string(gSystem->Getenv("GENIE")) +
136 string("/data/evgen/catalogues/iso/natural-isotopes.data");
137
138 LOG("NatIsotop", pINFO)
139 << "Loading natural occurring isotope table from file: " << filename;
140
141 bool is_accessible = ! (gSystem->AccessPathName( filename.c_str() ));
142 if (!is_accessible) {
143 LOG("NatIsotop", pWARN) << "Can not read file: " << filename;
144 return false;
145 }
146
147 // load the natural isotopes .txt file
148 string input_buf;
149 std::ifstream input(filename.c_str());
150 if (input.is_open()){
151
152 //skip first 8 lines (comments)
153 for(int i=0; i<8; i++){
154 string buffer;
155 getline(input, buffer);
156 }
157
158 int Z = -1, Z_previous = -1, nelements = 0, pdgcode = 0;
159 double atomicmass = 0, abundance = 0;
160 string elementname, subelementname;
161
162 while( !input.eof() ) {
163
164 //read in naturally occuring element info
165 input >> Z;
166 input >> elementname;
167 input >> nelements;
168
169 vector<NaturalIsotopeElementData *> vec;
170 NaturalIsotopeElementData * data = 0;
171
172 // check not re-reading same element
173 if(Z!=Z_previous){
174 LOG("NatIsotop", pDEBUG) << "Reading entry for Z = " << Z;
175 for(int n=0 ; n < nelements; n++){
176 input >> subelementname;
177 input >> pdgcode;
178 input >> atomicmass;
179 input >> abundance;
180 LOG("NatIsotop", pDEBUG)
181 << " - Element: " << n << ", pdg = " << pdgcode
182 << ", A = " << atomicmass << ", abundance = " << abundance;
183 data = new NaturalIsotopeElementData(pdgcode, abundance,atomicmass);
184 vec.push_back(data);
185 }
187 map<int,vector<NaturalIsotopeElementData*> >::value_type(Z,vec));
188 }
189 Z_previous = Z;
190 } //!eof
191
192 } else {
193 return false;
194 } //open?
195
196 return true;
197}
#define pDEBUG
Definition Messenger.h:63

References fNaturalIsotopesTable, LOG, pDEBUG, pINFO, and pWARN.

Referenced by NaturalIsotopes().

◆ NElements()

int NaturalIsotopes::NElements ( int Z) const

Definition at line 76 of file NaturalIsotopes.cxx.

77{
78 map<int, vector<NaturalIsotopeElementData*> >::const_iterator miter;
79
80 if( (miter=fNaturalIsotopesTable.find(Z)) == fNaturalIsotopesTable.end()) {
81 LOG("NatIsotop", pWARN)
82 << "Table has no elements for natural isotope Z = " << Z;
83 return 0;
84 }
85 vector<NaturalIsotopeElementData*> vec = miter->second;
86 return vec.size();
87}

References fNaturalIsotopesTable, LOG, and pWARN.

Referenced by main().

◆ Cleaner

friend struct Cleaner
friend

Definition at line 62 of file NaturalIsotopes.h.

Member Data Documentation

◆ fInstance

NaturalIsotopes * NaturalIsotopes::fInstance = 0
staticprivate

◆ fNaturalIsotopesTable

map<int, vector<NaturalIsotopeElementData*> > genie::NaturalIsotopes::fNaturalIsotopesTable
private

Definition at line 51 of file NaturalIsotopes.h.

Referenced by ElementData(), ElementDataPdg(), LoadTable(), NElements(), and ~NaturalIsotopes().


The documentation for this class was generated from the following files: