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>

Classes

struct  Cleaner
 

Public Member Functions

int NElements (int Z) const
 
const NaturalIsotopeElementDataElementData (int Z, int ielement) 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 <constantinos.andreopoulos cern.ch> University of Liverpool & STFC Rutherford Appleton Laboratory
  Jim Dobson <j.dobson07@imperial.ac.uk>
Imperial College London

May 30, 2008

Copyright (c) 2003-2020, 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.

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.

40 {
41  cout << "NaturalIsotopes singleton dtor: "
42  << "Deleting natural isotope data tables" << endl;
43 
44  map<int, vector<NaturalIsotopeElementData*> >::iterator miter;
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 }
intermediate_table::iterator iterator
map< int, vector< NaturalIsotopeElementData * > > fNaturalIsotopesTable
static NaturalIsotopes * fInstance
QTextStream & endl(QTextStream &s)

Member Function Documentation

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 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.

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 109 of file NaturalIsotopes.cxx.

110 {
111  // get the natural isotopes table filename
112  string filename = string(gSystem->Getenv("GENIE")) +
113  string("/data/evgen/catalogues/iso/natural-isotopes.data");
114 
115  LOG("NatIsotop", pINFO)
116  << "Loading natural occurring isotope table from file: " << filename;
117 
118  bool is_accessible = ! (gSystem->AccessPathName( filename.c_str() ));
119  if (!is_accessible) {
120  LOG("NatIsotop", pWARN) << "Can not read file: " << filename;
121  return false;
122  }
123 
124  // load the natural isotopes .txt file
125  string input_buf;
126  std::ifstream input(filename.c_str());
127  if (input.is_open()){
128 
129  //skip first 8 lines (comments)
130  for(int i=0; i<8; i++){
131  string buffer;
132  getline(input, buffer);
133  }
134 
135  int Z = -1, Z_previous = -1, nelements = 0, pdgcode = 0;
136  double atomicmass = 0, abundance = 0;
137  string elementname, subelementname;
138 
139  while( !input.eof() ) {
140 
141  //read in naturally occuring element info
142  input >> Z;
143  input >> elementname;
144  input >> nelements;
145 
146  vector<NaturalIsotopeElementData *> vec;
148 
149  // check not re-reading same element
150  if(Z!=Z_previous){
151  LOG("NatIsotop", pDEBUG) << "Reading entry for Z = " << Z;
152  for(int n=0 ; n < nelements; n++){
153  input >> subelementname;
154  input >> pdgcode;
155  input >> atomicmass;
156  input >> abundance;
157  LOG("NatIsotop", pDEBUG)
158  << " - Element: " << n << ", pdg = " << pdgcode
159  << ", A = " << atomicmass << ", abundance = " << abundance;
160  data = new NaturalIsotopeElementData(pdgcode, abundance);
161  vec.push_back(data);
162  }
163  fNaturalIsotopesTable.insert(
164  map<int,vector<NaturalIsotopeElementData*> >::value_type(Z,vec));
165  }
166  Z_previous = Z;
167  } //!eof
168 
169  } else {
170  return false;
171  } //open?
172 
173  return true;
174 }
std::string string
Definition: nybbler.cc:12
string filename
Definition: train.py:213
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
static int input(void)
Definition: code.cpp:15695
std::void_t< T > n
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.

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 61 of file NaturalIsotopes.h.

Member Data Documentation

NaturalIsotopes * NaturalIsotopes::fInstance = 0
staticprivate

Definition at line 48 of file NaturalIsotopes.h.

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

Definition at line 50 of file NaturalIsotopes.h.


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