gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
Gambit::IniParser Namespace Reference

Namespaces

 Types
 

Classes

class  IniFile
 Main inifile class. More...
 
class  Parser
 Inifile parser base class. More...
 

Typedefs

typedef Types::Observable ObservableType
 
typedef std::vector< ObservableTypeObservablesType
 

Functions

errorinifile_error ()
 IniFile errors. More...
 
warninginifile_warning ()
 IniFile warnings. More...
 
int importRound (YAML::Node node, const std::string &filename)
 Recursive import. More...
 
void recursiveImport (const YAML::Node &node, const std::string &filename)
 

Typedef Documentation

◆ ObservablesType

Definition at line 86 of file yaml_parser.hpp.

◆ ObservableType

Function Documentation

◆ importRound()

int Gambit::IniParser::importRound ( YAML::Node  node,
const std::string &  filename 
)

Recursive import.

Definition at line 37 of file yaml_parser_base.cpp.

References Gambit::Utils::dir_name(), inifile_error(), LOCAL_INFO, and combine_hdf5::rank.

Referenced by recursiveImport().

38  {
39  int counter = 0;
40  if (node.IsScalar())
41  {
42  if ( node.Tag() == "!import" )
43  {
44  #ifdef WITH_MPI
45  int rank = GMPI::Comm().Get_rank();
46  #else
47  int rank = 0;
48  #endif
49  YAML::Node import;
50  std::string new_filename = node.as<std::string>();
51  if (rank == 0) std::cout << "Importing: " << new_filename << std::endl;
52  try
53  {
54  // We want to do the import relative to the path in which the YAML file
55  // sits, unless it has a forward slash at the beginning (in which case we
56  // will interpret it as an absolute path)
57  std::string file_location = Utils::dir_name(filename); // "outer" file location
58  if(new_filename.at(0)=='/') // POSIX
59  {
60  // Use the absolute path as given
61  import = YAML::LoadFile(new_filename);
62  }
63  else
64  {
65  // Append the path of the outer file
66  new_filename = file_location+"/"+new_filename;
67  import = YAML::LoadFile(new_filename);
68  }
69  }
70  catch (YAML::Exception &e)
71  {
72  std::ostringstream msg;
73  msg << "Error importing \""<<new_filename<<"\"! ";
74  msg << "Please check that file exists! Error occurred during parsing of YAML file '"<<filename<<"'" << endl;
75  msg << "(yaml-cpp error: "<<e.what()<<" )";
76  inifile_error().raise(LOCAL_INFO,msg.str());
77  }
78  node = import;
79  return 1;
80  }
81  return 0;
82  }
83  if (node.IsSequence())
84  {
85  for (unsigned int i = 0; i<node.size(); ++i)
86  {
87  counter += importRound(node[i],filename);
88  }
89  return counter;
90  }
91  if (node.IsMap())
92  {
93  for (YAML::const_iterator it = node.begin(); it != node.end(); ++it)
94  {
95  counter += importRound(it->second,filename); // Only values are processed
96  }
97  return counter;
98  }
99  return 0;
100  }
EXPORT_SYMBOLS str dir_name(const str &path)
Get directory name from full path+filename (POSIX)
#define LOCAL_INFO
Definition: local_info.hpp:34
int importRound(YAML::Node node, const std::string &filename)
Recursive import.
error & inifile_error()
IniFile errors.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inifile_error()

error & Gambit::IniParser::inifile_error ( )

IniFile errors.

Definition at line 112 of file standalone_error_handlers.cpp.

References Gambit::LogTags::inifile.

Referenced by Gambit::IniParser::Parser::basicParse(), Gambit::IniParser::Parser::filename_to_node(), Gambit::IniParser::Parser::getModelParameterEntry(), Gambit::IniParser::Parser::getValue(), and importRound().

113  {
114  static error local("A problem has been encountered in the iniFile reader subsystem.","inifile_error", inifile);
115  return local;
116  }
Here is the caller graph for this function:

◆ inifile_warning()

warning & Gambit::IniParser::inifile_warning ( )

IniFile warnings.

Definition at line 119 of file standalone_error_handlers.cpp.

References Gambit::LogTags::inifile.

120  {
121  static warning local("A problem has been encountered in the iniFile reader subsystem.","inifile_warning", inifile);
122  return local;
123  }

◆ recursiveImport()

void Gambit::IniParser::recursiveImport ( const YAML::Node &  node,
const std::string &  filename 
)

Definition at line 102 of file yaml_parser_base.cpp.

References importRound(), and combine_hdf5::rank.

Referenced by Gambit::IniParser::Parser::basicParse().

103  {
104  int import_counter = 0;
105  int last_import_counter = 0;
106  for ( int i = 0; i < 10; ++i)
107  {
108  last_import_counter = importRound(node,filename);
109  import_counter += last_import_counter;
110  }
111  if (last_import_counter > 0)
112  {
113  #ifdef WITH_MPI
114  int rank = GMPI::Comm().Get_rank();
115  #else
116  int rank = 0;
117  #endif
118  if (rank == 0)
119  {
120  std::cout << last_import_counter << std::endl;
121  std::cout << "WARNING: YAML imports were truncated after 10 recursions." << std::endl;
122  }
123  }
124  }
int importRound(YAML::Node node, const std::string &filename)
Recursive import.
Here is the call graph for this function:
Here is the caller graph for this function: