GENIEGenerator
Loading...
Searching...
No Matches
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:
[legend]
Collaboration diagram for genie::TabulatedHadronTensorModelI:
[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.
virtual AlgStatus_t GetStatus (void) const
 Get algorithm status.
virtual bool AllowReconfig (void) const
virtual AlgCmp_t Compare (const Algorithm *alg) const
 Compare with input algorithm.
virtual void SetId (const AlgId &id)
 Set algorithm ID.
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.

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.
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.
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.
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.
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.
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
int AddLowRegistry (Registry *rp, bool owns=true)
 add registry with lowest priority, also update ownership
int MergeTopRegistry (const Registry &r)
int AddTopRegisties (const vector< Registry * > &rs, bool owns=false)
 Add registries with top priority, also udated Ownerships.

Protected Attributes

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

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 \at fnal.gov> Liang Liu <liangliu \at fnal.gov> Fermi National Accelerator Laboratory
Created:\n April 26, 2019
License:\n Copyright (c) 2003-2025, 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

◆ ~TabulatedHadronTensorModelI()

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

References fTensors.

◆ TabulatedHadronTensorModelI() [1/3]

◆ TabulatedHadronTensorModelI() [2/3]

genie::TabulatedHadronTensorModelI::TabulatedHadronTensorModelI ( std::string name)
protected

Definition at line 204 of file TabulatedHadronTensorModelI.cxx.

205 : genie::HadronTensorModelI( name )
206{
207
208}

References genie::HadronTensorModelI::HadronTensorModelI().

◆ TabulatedHadronTensorModelI() [3/3]

genie::TabulatedHadronTensorModelI::TabulatedHadronTensorModelI ( std::string name,
std::string config )
protected

Definition at line 211 of file TabulatedHadronTensorModelI.cxx.

212 : genie::HadronTensorModelI(name, config)
213{
214
215}

References genie::HadronTensorModelI::HadronTensorModelI().

Member Function Documentation

◆ BuildTensor()

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.

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}
#define pINFO
Definition Messenger.h:62
#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
std::string GetTensorFileBasename(const HadronTensorID &ht_id) const
std::string FindTensorTableFile(const std::string &basename, bool &ok) const
virtual HadronTensorI * ParseTensorFile(const std::string &full_file_name) const =0

References FindTensorTableFile(), fTensors, fWarnIfMissing, GetTensorFileBasename(), LOG, ParseTensorFile(), pERROR, pINFO, genie::TabulatedHadronTensorModelI::HadronTensorID::target_pdg, and genie::TabulatedHadronTensorModelI::HadronTensorID::type.

Referenced by GetTensor().

◆ Configure() [1/2]

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.

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.

References genie::Algorithm::Configure(), and LoadConfig().

◆ Configure() [2/2]

void genie::TabulatedHadronTensorModelI::Configure ( std::string config)
virtual

Definition at line 224 of file TabulatedHadronTensorModelI.cxx.

225{
227 this->LoadConfig();
228}

References genie::Algorithm::Configure(), and LoadConfig().

◆ FindTensorTableFile()

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.
bool file_exists(const std::string &file_name)
Returns true if a given file exists and is accessible, or false otherwise.

References fDataPaths.

Referenced by BuildTensor().

◆ GetTensor()

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.

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 pWARN
Definition Messenger.h:60
const HadronTensorI * BuildTensor(const HadronTensorID &ht_id) const
Create a HadronTensorI object given a particular HadronTensorID.
Struct used to provide a unique ID for each tensor object.

References BuildTensor(), fTensors, fWarnIfMissing, LOG, pWARN, genie::TabulatedHadronTensorModelI::HadronTensorID::target_pdg, and genie::TabulatedHadronTensorModelI::HadronTensorID::type.

◆ GetTensorFileBasename()

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.

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
std::string tensor_type_to_string(genie::HadronTensorType_t htt)
Converts a genie::HadronTensorType_t value to a string.

References genie::Algorithm::GetParamDef(), genie::TabulatedHadronTensorModelI::HadronTensorID::target_pdg, and genie::TabulatedHadronTensorModelI::HadronTensorID::type.

Referenced by BuildTensor().

◆ LoadConfig()

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}
bool GetParam(const RgKey &name, T &p, bool is_top_call=true) const

References fDataPaths, fWarnIfMissing, genie::Algorithm::GetParam(), and genie::Algorithm::GetParamDef().

Referenced by Configure(), and Configure().

◆ ParseTensorFile()

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.

Referenced by BuildTensor().

Member Data Documentation

◆ fDataPaths

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.

Referenced by FindTensorTableFile(), and LoadConfig().

◆ fTensors

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.

Referenced by BuildTensor(), GetTensor(), and ~TabulatedHadronTensorModelI().

◆ fWarnIfMissing

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.

Referenced by BuildTensor(), GetTensor(), and LoadConfig().


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