GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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:
Inheritance graph
[legend]
Collaboration diagram for genie::TabulatedHadronTensorModelI:
Collaboration graph
[legend]

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 Configure (string config)
 
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
 
template<class T >
int GetParamMat (const std::string &comm_name, TMatrixT< T > &mat, bool is_top_call=true) const
 Handle to load matrix of parameters. More...
 
template<class T >
int GetParamMatSym (const std::string &comm_name, TMatrixTSym< T > &mat, bool is_top_call=true) const
 
int GetParamMatKeys (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::string > fDataPaths
 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< bool > fOwnerships
 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)
 
static string BuildParamMatKey (const std::string &comm_name, unsigned int i, unsigned int j)
 
static string BuildParamMatRowSizeKey (const std::string &comm_name)
 
static string BuildParamMatColSizeKey (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> Liang Liu <liangliu fnal.gov> Fermi National Accelerator Laboratory
Created:
April 26, 2019
License:
Copyright (c) 2003-2024, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org or see $GENIE/LICENSE

Definition at line 37 of file TabulatedHadronTensorModelI.h.

Constructor & Destructor Documentation

genie::TabulatedHadronTensorModelI::~TabulatedHadronTensorModelI ( )
virtual

Definition at line 255 of file TabulatedHadronTensorModelI.cxx.

256 {
257  std::map< HadronTensorID, HadronTensorI* >::iterator it;
258  for (it = fTensors.begin(); it != fTensors.end(); ++it) {
259  HadronTensorI* t = it->second;
260  if ( t ) delete t;
261  }
262  fTensors.clear();
263 }
std::map< HadronTensorID, HadronTensorI * > fTensors
genie::TabulatedHadronTensorModelI::TabulatedHadronTensorModelI ( )
protected

Definition at line 197 of file TabulatedHadronTensorModelI.cxx.

199 {
200 
201 }
Creates hadron tensor objects for use in cross section calculations.
genie::TabulatedHadronTensorModelI::TabulatedHadronTensorModelI ( std::string  name)
protected

Definition at line 204 of file TabulatedHadronTensorModelI.cxx.

206 {
207 
208 }
const char * name
Creates hadron tensor objects for use in cross section calculations.
genie::TabulatedHadronTensorModelI::TabulatedHadronTensorModelI ( std::string  name,
std::string  config 
)
protected

Definition at line 211 of file TabulatedHadronTensorModelI.cxx.

213 {
214 
215 }
const char * name
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 302 of file TabulatedHadronTensorModelI.cxx.

References LOG, pERROR, pINFO, genie::TabulatedHadronTensorModelI::HadronTensorID::target_pdg, and genie::TabulatedHadronTensorModelI::HadronTensorID::type.

304 {
305  bool tensor_ok = true;
306 
307  std::string tensor_file_basename = this->GetTensorFileBasename( tensor_id );
308 
309  // Tensor values are represented using a 2D grid that is stored in a data
310  // file. Get the full path to the file, or an empty string if it could not
311  // be found. Also set the tensor_ok flag to false if the file could not be
312  // found.
313  std::string full_file_name = FindTensorTableFile(tensor_file_basename,
314  tensor_ok);
315 
316  if ( tensor_ok ) {
317 
318  // Create the new hadron tensor object
319  LOG("TabulatedHadronTensorModelI", pINFO) << "Loading the hadron"
320  << " tensor data file " << full_file_name;
321 
322  genie::HadronTensorI* temp_ptr = this->ParseTensorFile( full_file_name );
323 
324  // Place a pointer to it in the map of loaded tensor objects for easy
325  // retrieval.
326  /// \todo Switch to using std::unique_ptr here for easy cleanup
327  /// once C++11 features are allowed in GENIE
328  fTensors[tensor_id] = temp_ptr;
329 
330  // Return a pointer to the newly-created hadron tensor object
331  return temp_ptr;
332  }
333 
334  else {
335  // If we couldn't make the hadron tensor, store a nullptr to avoid
336  // unsuccessful repeat attempts. These can otherwise slow things down
337  // for no good reason.
338  fTensors[tensor_id] = NULL;
339 
340  if ( fWarnIfMissing ) {
341  LOG("TabulatedHadronTensorModelI", pERROR) << "The hadron tensor data file \""
342  << full_file_name << "\" requested for target pdg = "
343  << tensor_id.target_pdg << " and hadron tensor type "
344  << tensor_id.type << " could not be found.";
345  }
346  }
347 
348  // If there was a problem, return a null pointer
349  return NULL;
350 }
std::string GetTensorFileBasename(const HadronTensorID &ht_id) const
std::string FindTensorTableFile(const std::string &basename, bool &ok) const
#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
Abstract interface for an object that computes the elements a hadron tensor . Also computes the contr...
Definition: HadronTensorI.h:95
#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 218 of file TabulatedHadronTensorModelI.cxx.

References genie::Algorithm::Configure().

219 {
221  this->LoadConfig();
222 }
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

Definition at line 224 of file TabulatedHadronTensorModelI.cxx.

References genie::Algorithm::Configure().

225 {
227  this->LoadConfig();
228 }
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 287 of file TabulatedHadronTensorModelI.cxx.

289 {
290  for (size_t p = 0; p < fDataPaths.size(); ++p) {
291  const std::string& path = fDataPaths.at( p );
292  std::string full_name = path + '/' + basename;
293  if ( file_exists(full_name) ) return full_name;
294  }
295 
296  // A matching file could not be found
297  ok = false;
298  return std::string();
299 }
std::vector< std::string > fDataPaths
Paths to check when searching for hadron tensor data files.
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 265 of file TabulatedHadronTensorModelI.cxx.

References LOG, pWARN, genie::TabulatedHadronTensorModelI::HadronTensorID::target_pdg, and genie::TabulatedHadronTensorModelI::HadronTensorID::type.

267 {
268  HadronTensorID temp_id(tensor_pdg, type);
269 
270  // First check to see if the hadron tensor object already exists in memory.
271  // If it does, return the existing object.
272  if ( fTensors.count(temp_id) ) return fTensors.find(temp_id)->second;
273 
274  // If not, try to create it
275  const HadronTensorI* ht = this->BuildTensor( temp_id );
276 
277  if ( !ht && fWarnIfMissing ) {
278  LOG("TabulatedHadronTensorModelI", pWARN) << "Unable to create a hadron tensor"
279  << " for target pdg = " << temp_id.target_pdg
280  << " and hadron tensor type " << temp_id.type;
281  }
282 
283  return ht;
284 }
#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 353 of file TabulatedHadronTensorModelI.cxx.

References genie::TabulatedHadronTensorModelI::HadronTensorID::target_pdg, and genie::TabulatedHadronTensorModelI::HadronTensorID::type.

355 {
356 
357  std::string tgt_string;
358  std::stringstream ss;
359  ss << ht_id.target_pdg;
360  tgt_string = ss.str();
361 
362  RgKey key = tensor_type_to_string( ht_id.type ) + "@Pdg="
363  + tgt_string;
364 
365  std::string basename;
366  GetParamDef( key, basename, std::string("TENSOR_FILE_NOT_FOUND") );
367 
368  return basename;
369 }
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 230 of file TabulatedHadronTensorModelI.cxx.

231 {
232  GetParamDef( "WarnIfMissing", fWarnIfMissing, true );
233 
234  // Either a data path relative to the root GENIE folder
235  // or an absolute path can be used. Find out which
236  // option was chosen.
237  std::string path_type;
238  GetParamDef( "DataPathType", path_type, std::string("relative") );
239 
240  // Right now, there can only be a single data path
241  // specified. We use a vector of paths to allow for
242  // easy expansion later.
243  std::string data_path;
244  GetParam( "DataPath", data_path );
245 
246  // Convert the relative path to an absolute one if needed
247  if ( path_type == "relative" ) {
248  data_path = std::string( gSystem->Getenv("GENIE") ) + '/' + data_path;
249  }
250 
251  fDataPaths.push_back( data_path );
252 }
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 87 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 84 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 79 of file TabulatedHadronTensorModelI.h.


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