GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
genie::NaturalIsotopes Class Reference

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

#include <NaturalIsotopes.h>

Collaboration diagram for genie::NaturalIsotopes:
Collaboration graph
[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 cern.ch> University of Liverpool
  Jim Dobson <j.dobson07@imperial.ac.uk>
Imperial College London
Created:
May 30, 2008
License:
Copyright (c) 2003-2024, 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::NaturalIsotopes ( )
private

Definition at line 31 of file NaturalIsotopes.cxx.

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

Referenced by Instance().

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
genie::NaturalIsotopes::NaturalIsotopes ( const NaturalIsotopes )
private
NaturalIsotopes::~NaturalIsotopes ( )
privatevirtual

Definition at line 39 of file NaturalIsotopes.cxx.

References fInstance, and fNaturalIsotopesTable.

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  }
59  fNaturalIsotopesTable.clear();
60  fInstance = 0;
61 }
map< int, vector< NaturalIsotopeElementData * > > fNaturalIsotopesTable
static NaturalIsotopes * fInstance

Member Function Documentation

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

Definition at line 90 of file NaturalIsotopes.cxx.

References fNaturalIsotopesTable, LOG, and pWARN.

Referenced by main().

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 LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
map< int, vector< NaturalIsotopeElementData * > > fNaturalIsotopesTable
#define pWARN
Definition: Messenger.h:60
const NaturalIsotopeElementData * NaturalIsotopes::ElementDataPdg ( int  Z,
int  pdgcode 
) const

Definition at line 110 of file NaturalIsotopes.cxx.

References fNaturalIsotopesTable, LOG, genie::utils::res::PdgCode(), and pWARN.

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) -&gt; PDG code
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
map< int, vector< NaturalIsotopeElementData * > > fNaturalIsotopesTable
#define pWARN
Definition: Messenger.h:60
NaturalIsotopes * NaturalIsotopes::Instance ( void  )
static

Definition at line 63 of file NaturalIsotopes.cxx.

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

Referenced by main().

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 LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pINFO
Definition: Messenger.h:62
static NaturalIsotopes * fInstance
bool NaturalIsotopes::LoadTable ( void  )
private

eof

Definition at line 132 of file NaturalIsotopes.cxx.

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

Referenced by NaturalIsotopes().

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  }
186  fNaturalIsotopesTable.insert(
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 LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
map< int, vector< NaturalIsotopeElementData * > > fNaturalIsotopesTable
#define pINFO
Definition: Messenger.h:62
#define pWARN
Definition: Messenger.h:60
#define pDEBUG
Definition: Messenger.h:63
int NaturalIsotopes::NElements ( int  Z) const

Definition at line 76 of file NaturalIsotopes.cxx.

References fNaturalIsotopesTable, LOG, and pWARN.

Referenced by main().

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 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
map< int, vector< NaturalIsotopeElementData * > > fNaturalIsotopesTable
#define pWARN
Definition: Messenger.h:60

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 62 of file NaturalIsotopes.h.

Member Data Documentation

NaturalIsotopes * NaturalIsotopes::fInstance = 0
staticprivate
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: