Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
genie::TabulatedHadronTensorModelI Class Referenceabstract

Creates hadron tensor objects for cross section calculations using precomputed data tables. More...

#include <TabulatedHadronTensorModelI.h>

Inheritance diagram for genie::TabulatedHadronTensorModelI:
genie::HadronTensorModelI genie::Algorithm genie::NievesMECHadronTensorModel genie::SuSAv2MECHadronTensorModel genie::SuSAv2QELHadronTensorModel

Classes

struct  HadronTensorID
 Struct used to provide a unique ID for each tensor object. More...
 

Public Member Functions

virtual ~TabulatedHadronTensorModelI ()
 
virtual void Configure (const Registry &config)
 
virtual void Configure (std::string config)
 
virtual const HadronTensorIGetTensor (int tensor_pdg, HadronTensorType_t type) const
 
- Public Member Functions inherited from genie::HadronTensorModelI
virtual ~HadronTensorModelI ()
 
- Public Member Functions inherited from genie::Algorithm
virtual ~Algorithm ()
 
virtual void FindConfig (void)
 
virtual const RegistryGetConfig (void) const
 
RegistryGetOwnedConfig (void)
 
virtual const AlgIdId (void) const
 Get algorithm ID. More...
 
virtual AlgStatus_t GetStatus (void) const
 Get algorithm status. More...
 
virtual bool AllowReconfig (void) const
 
virtual AlgCmp_t Compare (const Algorithm *alg) const
 Compare with input algorithm. More...
 
virtual void SetId (const AlgId &id)
 Set algorithm ID. More...
 
virtual void SetId (string name, string config)
 
const AlgorithmSubAlg (const RgKey &registry_key) const
 
void AdoptConfig (void)
 
void AdoptSubstructure (void)
 
virtual void Print (ostream &stream) const
 Print algorithm info. More...
 

Protected Member Functions

 TabulatedHadronTensorModelI ()
 
 TabulatedHadronTensorModelI (std::string name)
 
 TabulatedHadronTensorModelI (std::string name, std::string config)
 
void LoadConfig ()
 Saves some basic XML config parameters to data members. More...
 
std::string FindTensorTableFile (const std::string &basename, bool &ok) const
 
const HadronTensorIBuildTensor (const HadronTensorID &ht_id) const
 Create a HadronTensorI object given a particular HadronTensorID. More...
 
std::string GetTensorFileBasename (const HadronTensorID &ht_id) const
 
virtual HadronTensorIParseTensorFile (const std::string &full_file_name) const =0
 
- Protected Member Functions inherited from genie::HadronTensorModelI
 HadronTensorModelI ()
 
 HadronTensorModelI (std::string name)
 
 HadronTensorModelI (std::string name, std::string config)
 
- Protected Member Functions inherited from genie::Algorithm
 Algorithm ()
 
 Algorithm (string name)
 
 Algorithm (string name, string config)
 
void Initialize (void)
 
void DeleteConfig (void)
 
void DeleteSubstructure (void)
 
RegistryExtractLocalConfig (const Registry &in) const
 
RegistryExtractLowerConfig (const Registry &in, const string &alg_key) const
 Split an incoming configuration Registry into a block valid for the sub-algo identified by alg_key. More...
 
template<class T >
bool GetParam (const RgKey &name, T &p, bool is_top_call=true) const
 
template<class T >
bool GetParamDef (const RgKey &name, T &p, const T &def) const
 
template<class T >
int GetParamVect (const std::string &comm_name, std::vector< T > &v, bool is_top_call=true) const
 Handle to load vectors of parameters. More...
 
int GetParamVectKeys (const std::string &comm_name, std::vector< RgKey > &k, bool is_top_call=true) const
 
int AddTopRegistry (Registry *rp, bool owns=true)
 add registry with top priority, also update ownership More...
 
int AddLowRegistry (Registry *rp, bool owns=true)
 add registry with lowest priority, also update ownership More...
 
int MergeTopRegistry (const Registry &r)
 
int AddTopRegisties (const vector< Registry * > &rs, bool owns=false)
 Add registries with top priority, also udated Ownerships. More...
 

Protected Attributes

bool fWarnIfMissing
 
std::map< HadronTensorID, HadronTensorI * > fTensors
 
std::vector< std::stringfDataPaths
 Paths to check when searching for hadron tensor data files. More...
 
- Protected Attributes inherited from genie::Algorithm
bool fAllowReconfig
 
bool fOwnsSubstruc
 true if it owns its substructure (sub-algs,...) More...
 
AlgId fID
 algorithm name and configuration set More...
 
vector< Registry * > fConfVect
 
vector< boolfOwnerships
 ownership for every registry in fConfVect More...
 
AlgStatus_t fStatus
 algorithm execution status More...
 
AlgMapfOwnedSubAlgMp
 local pool for owned sub-algs (taken out of the factory pool) More...
 

Additional Inherited Members

- Static Public Member Functions inherited from genie::Algorithm
static string BuildParamVectKey (const std::string &comm_name, unsigned int i)
 
static string BuildParamVectSizeKey (const std::string &comm_name)
 

Detailed Description

Creates hadron tensor objects for cross section calculations using precomputed data tables.

Author
Steven Gardiner <gardiner fnal.gov> Fermi National Accelerator Laboratory

April 26, 2019

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

Definition at line 35 of file TabulatedHadronTensorModelI.h.

Constructor & Destructor Documentation

genie::TabulatedHadronTensorModelI::~TabulatedHadronTensorModelI ( )
virtual

Definition at line 143 of file TabulatedHadronTensorModelI.cxx.

144 {
146  for (it = fTensors.begin(); it != fTensors.end(); ++it) {
147  HadronTensorI* t = it->second;
148  if ( t ) delete t;
149  }
150  fTensors.clear();
151 }
intermediate_table::iterator iterator
std::map< HadronTensorID, HadronTensorI * > fTensors
genie::TabulatedHadronTensorModelI::TabulatedHadronTensorModelI ( )
protected

Definition at line 85 of file TabulatedHadronTensorModelI.cxx.

87 {
88 
89 }
Creates hadron tensor objects for use in cross section calculations.
genie::TabulatedHadronTensorModelI::TabulatedHadronTensorModelI ( std::string  name)
protected

Definition at line 92 of file TabulatedHadronTensorModelI.cxx.

94 {
95 
96 }
static QCString name
Definition: declinfo.cpp:673
Creates hadron tensor objects for use in cross section calculations.
genie::TabulatedHadronTensorModelI::TabulatedHadronTensorModelI ( std::string  name,
std::string  config 
)
protected

Definition at line 99 of file TabulatedHadronTensorModelI.cxx.

101 {
102 
103 }
static QCString name
Definition: declinfo.cpp:673
static Config * config
Definition: config.cpp:1054
Creates hadron tensor objects for use in cross section calculations.

Member Function Documentation

const genie::HadronTensorI * genie::TabulatedHadronTensorModelI::BuildTensor ( const HadronTensorID ht_id) const
protected

Create a HadronTensorI object given a particular HadronTensorID.

Todo:
Switch to using std::unique_ptr here for easy cleanup once C++11 features are allowed in GENIE

Definition at line 190 of file TabulatedHadronTensorModelI.cxx.

192 {
193  bool tensor_ok = true;
194 
195  std::string tensor_file_basename = this->GetTensorFileBasename( tensor_id );
196 
197  // Tensor values are represented using a 2D grid that is stored in a data
198  // file. Get the full path to the file, or an empty string if it could not
199  // be found. Also set the tensor_ok flag to false if the file could not be
200  // found.
201  std::string full_file_name = FindTensorTableFile(tensor_file_basename,
202  tensor_ok);
203 
204  if ( tensor_ok ) {
205 
206  // Create the new hadron tensor object
207  LOG("TabulatedHadronTensorModelI", pINFO) << "Loading the hadron"
208  << " tensor data file " << full_file_name;
209 
210  genie::HadronTensorI* temp_ptr = this->ParseTensorFile( full_file_name );
211 
212  // Place a pointer to it in the map of loaded tensor objects for easy
213  // retrieval.
214  /// \todo Switch to using std::unique_ptr here for easy cleanup
215  /// once C++11 features are allowed in GENIE
216  fTensors[tensor_id] = temp_ptr;
217 
218  // Return a pointer to the newly-created hadron tensor object
219  return temp_ptr;
220  }
221 
222  else {
223  // If we couldn't make the hadron tensor, store a nullptr to avoid
224  // unsuccessful repeat attempts. These can otherwise slow things down
225  // for no good reason.
226  fTensors[tensor_id] = NULL;
227 
228  if ( fWarnIfMissing ) {
229  LOG("TabulatedHadronTensorModelI", pERROR) << "The hadron tensor data file \""
230  << full_file_name << "\" requested for target pdg = "
231  << tensor_id.target_pdg << " and hadron tensor type "
232  << tensor_id.type << " could not be found.";
233  }
234  }
235 
236  // If there was a problem, return a null pointer
237  return NULL;
238 }
std::string GetTensorFileBasename(const HadronTensorID &ht_id) const
std::string FindTensorTableFile(const std::string &basename, bool &ok) const
#define pERROR
Definition: Messenger.h:59
std::string string
Definition: nybbler.cc:12
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
Abstract interface for an object that computes the elements a hadron tensor . Also computes the contr...
Definition: HadronTensorI.h:53
#define pINFO
Definition: Messenger.h:62
virtual HadronTensorI * ParseTensorFile(const std::string &full_file_name) const =0
std::map< HadronTensorID, HadronTensorI * > fTensors
void genie::TabulatedHadronTensorModelI::Configure ( const Registry config)
virtual

Configure the algorithm with an external registry The registry is merged with the top level registry if it is owned, Otherwise a copy of it is added with the highest priority

Reimplemented from genie::Algorithm.

Definition at line 106 of file TabulatedHadronTensorModelI.cxx.

107 {
109  this->LoadConfig();
110 }
static Config * config
Definition: config.cpp:1054
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
void LoadConfig()
Saves some basic XML config parameters to data members.
void genie::TabulatedHadronTensorModelI::Configure ( std::string  config)
virtual

Configure the algorithm from the AlgoConfigPool based on param_set string given in input An algorithm contains a vector of registries coming from different xml configuration files, which are loaded according a very precise prioriy This methods will load a number registries in order of priority: 1) "Tunable" parameter set from CommonParametes. This is loaded with the highest prioriry and it is designed to be used for tuning procedure Usage not expected from the user. 2) For every string defined in "CommonParame" the corresponding parameter set will be loaded from CommonParameter.xml 3) parameter set specified by the config string and defined in the xml file of the algorithm 4) if config is not "Default" also the Default parameter set from the same xml file will be loaded Effectively this avoids the repetion of a parameter when it is not changed in the requested configuration

Reimplemented from genie::Algorithm.

Definition at line 112 of file TabulatedHadronTensorModelI.cxx.

113 {
115  this->LoadConfig();
116 }
static Config * config
Definition: config.cpp:1054
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
void LoadConfig()
Saves some basic XML config parameters to data members.
std::string genie::TabulatedHadronTensorModelI::FindTensorTableFile ( const std::string basename,
bool ok 
) const
protected

Looks up the full path when constructing hadron tensor objects that are based on a data file

Definition at line 175 of file TabulatedHadronTensorModelI.cxx.

177 {
178  for (size_t p = 0; p < fDataPaths.size(); ++p) {
179  const std::string& path = fDataPaths.at( p );
180  std::string full_name = path + '/' + basename;
181  if ( file_exists(full_name) ) return full_name;
182  }
183 
184  // A matching file could not be found
185  ok = false;
186  return std::string();
187 }
std::string string
Definition: nybbler.cc:12
p
Definition: test.py:223
std::vector< std::string > fDataPaths
Paths to check when searching for hadron tensor data files.
bool file_exists(std::string const &qualified_filename)
Definition: filesystem.cc:14
const genie::HadronTensorI * genie::TabulatedHadronTensorModelI::GetTensor ( int  tensor_pdg,
HadronTensorType_t  type 
) const
virtual

Retrieves a pointer to a hadron tensor object appropriate for this model

Parameters
[in]tensor_pdgThe PDG code for the nuclide described by the tensor
[in]typeThe desired kind of hadron tensor
Returns
A pointer to the requested hadron tensor, or NULL if a match could not be found/created

Implements genie::HadronTensorModelI.

Definition at line 153 of file TabulatedHadronTensorModelI.cxx.

155 {
156  HadronTensorID temp_id(tensor_pdg, type);
157 
158  // First check to see if the hadron tensor object already exists in memory.
159  // If it does, return the existing object.
160  if ( fTensors.count(temp_id) ) return fTensors.find(temp_id)->second;
161 
162  // If not, try to create it
163  const HadronTensorI* ht = this->BuildTensor( temp_id );
164 
165  if ( !ht && fWarnIfMissing ) {
166  LOG("TabulatedHadronTensorModelI", pWARN) << "Unable to create a hadron tensor"
167  << " for target pdg = " << temp_id.target_pdg
168  << " and hadron tensor type " << temp_id.type;
169  }
170 
171  return ht;
172 }
#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
const HadronTensorI * BuildTensor(const HadronTensorID &ht_id) const
Create a HadronTensorI object given a particular HadronTensorID.
std::map< HadronTensorID, HadronTensorI * > fTensors
std::string genie::TabulatedHadronTensorModelI::GetTensorFileBasename ( const HadronTensorID ht_id) const
protected

Loads the basename for a particular hadron tensor file from the configuration Registry

Definition at line 241 of file TabulatedHadronTensorModelI.cxx.

243 {
244 
245  std::string tgt_string;
246  std::stringstream ss;
247  ss << ht_id.target_pdg;
248  tgt_string = ss.str();
249 
250  RgKey key = tensor_type_to_string( ht_id.type ) + "@Pdg="
251  + tgt_string;
252 
254  GetParamDef( key, basename, std::string("TENSOR_FILE_NOT_FOUND") );
255 
256  return basename;
257 }
std::string string
Definition: nybbler.cc:12
def key(type, name=None)
Definition: graph.py:13
string RgKey
bool GetParamDef(const RgKey &name, T &p, const T &def) const
void genie::TabulatedHadronTensorModelI::LoadConfig ( void  )
protected

Saves some basic XML config parameters to data members.

Definition at line 118 of file TabulatedHadronTensorModelI.cxx.

119 {
120  GetParamDef( "WarnIfMissing", fWarnIfMissing, true );
121 
122  // Either a data path relative to the root GENIE folder
123  // or an absolute path can be used. Find out which
124  // option was chosen.
125  std::string path_type;
126  GetParamDef( "DataPathType", path_type, std::string("relative") );
127 
128  // Right now, there can only be a single data path
129  // specified. We use a vector of paths to allow for
130  // easy expansion later.
131  std::string data_path;
132  GetParam( "DataPath", data_path );
133 
134  // Convert the relative path to an absolute one if needed
135  if ( path_type == "relative" ) {
136  data_path = std::string( gSystem->Getenv("GENIE") ) + '/' + data_path;
137  }
138 
139  fDataPaths.push_back( data_path );
140 }
std::string string
Definition: nybbler.cc:12
std::vector< std::string > fDataPaths
Paths to check when searching for hadron tensor data files.
bool GetParamDef(const RgKey &name, T &p, const T &def) const
bool GetParam(const RgKey &name, T &p, bool is_top_call=true) const
virtual HadronTensorI* genie::TabulatedHadronTensorModelI::ParseTensorFile ( const std::string full_file_name) const
protectedpure virtual

Parses the hadron tensor file (specified by its full file name, including the path) and returns a HadronTensorI* to it

Implemented in genie::NievesMECHadronTensorModel, genie::SuSAv2MECHadronTensorModel, and genie::SuSAv2QELHadronTensorModel.

Member Data Documentation

std::vector<std::string> genie::TabulatedHadronTensorModelI::fDataPaths
protected

Paths to check when searching for hadron tensor data files.

Definition at line 85 of file TabulatedHadronTensorModelI.h.

std::map< HadronTensorID, HadronTensorI* > genie::TabulatedHadronTensorModelI::fTensors
mutableprotected

Cache of hadron tensor objects that have been fully loaded into memory

Keys are tensor IDs, values are pointers to hadron tensor objects

Definition at line 82 of file TabulatedHadronTensorModelI.h.

bool genie::TabulatedHadronTensorModelI::fWarnIfMissing
protected

If true, logging messages will be issued when a requested hadron tensor file cannot be found

Definition at line 77 of file TabulatedHadronTensorModelI.h.


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