Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
genie::FermiMomentumTablePool Class Reference

Singleton class to load & serve tables of Fermi momentum constants. More...

#include <FermiMomentumTablePool.h>

Classes

struct  Cleaner
 

Public Member Functions

const FermiMomentumTableGetTable (string name)
 

Static Public Member Functions

static FermiMomentumTablePoolInstance (void)
 

Private Member Functions

 FermiMomentumTablePool ()
 
 FermiMomentumTablePool (const FermiMomentumTablePool &fmc)
 
virtual ~FermiMomentumTablePool ()
 
bool LoadTables (void)
 
XmlParserStatus_t ParseXMLTables (string filename)
 

Private Attributes

map< string, FermiMomentumTable * > fKFSets
 

Static Private Attributes

static FermiMomentumTablePoolfInstance = 0
 

Friends

struct Cleaner
 

Detailed Description

Singleton class to load & serve tables of Fermi momentum constants.

Author
Costas Andreopoulos <constantinos.andreopoulos cern.ch> University of Liverpool & STFC Rutherford Appleton Laboratory

August 18, 2005

Copyright (c) 2003-2020, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 34 of file FermiMomentumTablePool.h.

Constructor & Destructor Documentation

FermiMomentumTablePool::FermiMomentumTablePool ( )
private

Definition at line 42 of file FermiMomentumTablePool.cxx.

43 {
44  if( ! this->LoadTables() ) {
45  LOG("FermiP", pERROR) << "FermiMomentumTablePool initialization failed!";
46  }
47  fInstance = 0;
48 }
#define pERROR
Definition: Messenger.h:59
static FermiMomentumTablePool * fInstance
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
genie::FermiMomentumTablePool::FermiMomentumTablePool ( const FermiMomentumTablePool fmc)
private
FermiMomentumTablePool::~FermiMomentumTablePool ( )
privatevirtual

Definition at line 50 of file FermiMomentumTablePool.cxx.

51 {
53  for(titer = fKFSets.begin(); titer != fKFSets.end(); ++titer) {
54  FermiMomentumTable * t = titer->second;
55  if(t) delete t;
56  t=0;
57  }
58  fKFSets.clear();
59  fInstance = 0;
60 }
intermediate_table::iterator iterator
static FermiMomentumTablePool * fInstance
A table of Fermi momentum constants.
map< string, FermiMomentumTable * > fKFSets

Member Function Documentation

const FermiMomentumTable * FermiMomentumTablePool::GetTable ( string  name)

Definition at line 76 of file FermiMomentumTablePool.cxx.

77 {
78  string defopt = "Default"; // default option
79 
81  FermiMomentumTable * table = 0;
82 
83  if(fKFSets.count(name) == 1) {
84  table_iter = fKFSets.find(name);
85  table = table_iter->second;
86  if(table) return table;
87  }
88  if(fKFSets.count(defopt) == 1) {
89  LOG("FermiP", pWARN)
90  << "Fermi momentum table: [" << name << "] was not found! "
91  << "Switching to table: [" << defopt << "]";
92  table_iter = fKFSets.find(defopt);
93  table = table_iter->second;
94  if(table) return table;
95  }
96  LOG("FermiP", pERROR)
97  << "Not even the default Fermi momentum table was not found!";
98  return 0;
99 }
static QCString name
Definition: declinfo.cpp:673
#define pERROR
Definition: Messenger.h:59
A table of Fermi momentum constants.
intermediate_table::const_iterator const_iterator
map< string, FermiMomentumTable * > fKFSets
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
FermiMomentumTablePool * FermiMomentumTablePool::Instance ( void  )
static

Definition at line 62 of file FermiMomentumTablePool.cxx.

63 {
64  if(fInstance == 0) {
65 
66  LOG("FermiP", pINFO) << "FermiMomentumTablePool late initialization";
67 
68  static FermiMomentumTablePool::Cleaner cleaner;
70 
72  }
73  return fInstance;
74 }
static FermiMomentumTablePool * fInstance
#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
bool FermiMomentumTablePool::LoadTables ( void  )
private

Definition at line 101 of file FermiMomentumTablePool.cxx.

102 {
103  bool loaded = true;
104 
105  //-- Fermi momenta sets XML file using GXMLPATH + default locations
106  string filename = utils::xml::GetXMLFilePath("FermiMomentumTables.xml");
107 
108  LOG("FermiP", pINFO) << "Loading Fermi momenta from file: " << filename;
109 
110  bool is_accessible = ! (gSystem->AccessPathName( filename.c_str() ));
111 
112  if(is_accessible) {
113  XmlParserStatus_t status = this->ParseXMLTables(filename);
114  if(status != kXmlOK) {
115  LOG("FermiP", pWARN)
116  << "XML parser status: " << XmlParserStatus::AsString(status)
117  << " - Couldn't read file: " << filename;
118  loaded = false;
119  }
120  } else {
121  LOG("FermiP", pWARN) << "Not accessible file: " << filename;
122  loaded = false;
123  }
124  return loaded;
125 };
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
string GetXMLFilePath(string basename)
#define pINFO
Definition: Messenger.h:62
#define pWARN
Definition: Messenger.h:60
static const char * AsString(XmlParserStatus_t status)
XmlParserStatus_t ParseXMLTables(string filename)
enum genie::EXmlParseStatus XmlParserStatus_t
XmlParserStatus_t FermiMomentumTablePool::ParseXMLTables ( string  filename)
private

Definition at line 127 of file FermiMomentumTablePool.cxx.

128 {
129  LOG("FermiP", pDEBUG) << "Reading XML file: " << filename;
130 
131  xmlDocPtr xml_doc = xmlParseFile(filename.c_str());
132  if(xml_doc == NULL) return kXmlNotParsed;
133 
134  xmlNodePtr xml_root = xmlDocGetRootElement(xml_doc);
135  if(xml_root==NULL)
136  {
137  xmlFreeDoc(xml_doc);
138  return kXmlEmpty;
139  }
140 
141  const xmlChar * xml_root_name = (const xmlChar *)"fermi_momentum_const";
142  if( xmlStrcmp(xml_root->name, xml_root_name) )
143  {
144  xmlFreeDoc(xml_doc);
145  return kXmlInvalidRoot;
146  }
147 
148  xmlNodePtr xml_kft = xml_root->xmlChildrenNode; // <kf_table>'s
149 
150  // loop over <kf_table> nodes
151  while (xml_kft != NULL) {
152  if( (!xmlStrcmp(xml_kft->name, (const xmlChar *) "kf_table")) ) {
153 
154  string name = utils::str::TrimSpaces(
155  utils::xml::GetAttribute(xml_kft, "name"));
156 
157  LOG("FermiP", pDEBUG) << "Reading Fermi momenta table: " << name;
158 
159  FermiMomentumTable * kftable = new FermiMomentumTable; // new table
160 
161  // loop over <kf> nodes
162  xmlNodePtr xml_kf = xml_kft->xmlChildrenNode; // <kf_table> children
163  while (xml_kf != NULL) {
164  if( (!xmlStrcmp(xml_kf->name, (const xmlChar *) "kf")) ) {
165 
166  string spdgc = utils::str::TrimSpaces(
167  utils::xml::GetAttribute(xml_kf, "nucleus_pdgc"));
168  int pdgc = atoi (spdgc.c_str());
169 
170  xmlNodePtr xml_cur = xml_kf->xmlChildrenNode; // <kf> children
171  const xmlChar * ntag = (const xmlChar *)"n";
172  const xmlChar * ptag = (const xmlChar *)"p";
173  double kfp=0, kfn=0, kf=0;
174  // loop over <kf> children
175  while (xml_cur != NULL) {
176  bool isp = !xmlStrcmp(xml_cur->name, ptag);
177  bool isn = !xmlStrcmp(xml_cur->name, ntag);
178  if(isn || isp) {
179  string skf = utils::xml::TrimSpaces(
180  xmlNodeListGetString(xml_doc, xml_cur->xmlChildrenNode, 1));
181  kf = atof(skf.c_str());
182  }
183  if(isp) kfp = kf;
184  if(isn) kfn = kf;
185  xml_cur = xml_cur->next;
186  }
187  xmlFreeNode(xml_cur);
188 
189  KF_t kft;
190  kft.p = kfp;
191  kft.n = kfn;
192 
193  LOG("FermiP", pDEBUG)
194  << "Add KF table entry: PDGC = " << pdgc
195  << " --> " << "kf(p) = " << kft.p << ", kf(n) = " << kft.n;
196  kftable->AddTableEntry(pdgc,kft);
197  } //<x> == <kf>
198  xml_kf = xml_kf->next;
199  } //<kf> loop
200  xmlFreeNode(xml_kf);
201 
202  fKFSets.insert(
203  map<string, FermiMomentumTable *>::value_type(name,kftable));
204 
205  } //<x> == <kf_table>
206  xml_kft = xml_kft->next;
207  } //<kf_table> loop
208  xmlFreeNode(xml_kft);
209  xmlFreeDoc(xml_doc);
210 
211  return kXmlOK;
212 }
static QCString name
Definition: declinfo.cpp:673
string TrimSpaces(xmlChar *xmls)
A table of Fermi momentum constants.
string filename
Definition: train.py:213
map< string, FermiMomentumTable * > fKFSets
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void AddTableEntry(int target_pdgc, KF_t kf)
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
string GetAttribute(xmlNodePtr xml_cur, string attr_name)
#define pDEBUG
Definition: Messenger.h:63

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 62 of file FermiMomentumTablePool.h.

Member Data Documentation

FermiMomentumTablePool * FermiMomentumTablePool::fInstance = 0
staticprivate

Definition at line 49 of file FermiMomentumTablePool.h.

map<string, FermiMomentumTable *> genie::FermiMomentumTablePool::fKFSets
private

Definition at line 51 of file FermiMomentumTablePool.h.


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