Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ModelConfig Class Reference

#include <ModelConfig.h>

Public Member Functions

 ModelConfig (const std::string &savedir, const std::vector< InputConfigKeys > &scalarInputKeys, const std::vector< InputConfigKeys > &vectorInputKeys, const std::vector< std::string > &outputKeys)
 
void load ()
 
bool isLoaded () const
 
std::string getConfigPath () const
 
std::string getModelPath () const
 
std::string getSavedir () const
 
const std::vector< InputConfig > & getScalarInputs () const
 
const std::vector< InputConfig > & getVectorInputs () const
 
const std::vector< std::string > & getOutputNodes () const
 

Static Public Member Functions

static std::string expandPath (const std::string &path)
 

Private Member Functions

void parseConfig (const std::string &fname)
 

Static Private Member Functions

static InputConfig parseInput (pt::ptree &tree, const InputConfigKeys &keys)
 

Private Attributes

std::string savedir
 
bool loaded
 
std::vector< InputConfigKeysscalarInputKeys
 
std::vector< InputConfigKeysvectorInputKeys
 
std::vector< std::stringoutputKeys
 
std::vector< InputConfigscalarInputs
 
std::vector< InputConfigvectorInputs
 
std::vector< std::stringoutputNodes
 

Detailed Description

Definition at line 88 of file ModelConfig.h.

Constructor & Destructor Documentation

ModelConfig::ModelConfig ( const std::string savedir,
const std::vector< InputConfigKeys > &  scalarInputKeys,
const std::vector< InputConfigKeys > &  vectorInputKeys,
const std::vector< std::string > &  outputKeys 
)

Definition at line 23 of file ModelConfig.cxx.

29  loaded(false),
30  scalarInputKeys(scalarInputKeys),
31  vectorInputKeys(vectorInputKeys),
32  outputKeys(outputKeys)
33 {
34  scalarInputs.reserve(scalarInputKeys.size());
35  vectorInputs.reserve(vectorInputKeys.size());
36  outputNodes.reserve(outputKeys.size());
37 }
std::vector< std::string > outputKeys
Definition: ModelConfig.h:129
std::vector< InputConfigKeys > scalarInputKeys
Definition: ModelConfig.h:127
std::vector< std::string > outputNodes
Definition: ModelConfig.h:133
std::vector< InputConfigKeys > vectorInputKeys
Definition: ModelConfig.h:128
std::string savedir
Definition: ModelConfig.h:118
static std::string expandPath(const std::string &path)
Definition: ModelConfig.cxx:6
std::vector< InputConfig > vectorInputs
Definition: ModelConfig.h:132
std::vector< InputConfig > scalarInputs
Definition: ModelConfig.h:131

Member Function Documentation

std::string ModelConfig::expandPath ( const std::string path)
static

Definition at line 6 of file ModelConfig.cxx.

7 {
8  wordexp_t p;
9 
10  int s = wordexp(path.c_str(), &p, WRDE_NOCMD | WRDE_SHOWERR);
11 
12  if ((s != 0) || (p.we_wordc != 1)) {
13  wordfree(&p);
14  return path;
15  }
16 
17  std::string result(p.we_wordv[0]);
18  wordfree(&p);
19 
20  return result;
21 }
static QCString result
std::string string
Definition: nybbler.cc:12
p
Definition: test.py:223
static QCString * s
Definition: config.cpp:1042
std::string ModelConfig::getConfigPath ( ) const

Definition at line 100 of file ModelConfig.cxx.

101 {
102  return savedir + "/" + CONFIG_NAME;
103 }
std::string savedir
Definition: ModelConfig.h:118
const std::string CONFIG_NAME
Definition: ModelConfig.h:55
std::string ModelConfig::getModelPath ( ) const

Definition at line 105 of file ModelConfig.cxx.

106 {
107  return savedir + "/" + MODEL_NAME;
108 }
std::string savedir
Definition: ModelConfig.h:118
const std::string MODEL_NAME
Definition: ModelConfig.h:56
const std::vector< std::string > & ModelConfig::getOutputNodes ( ) const

Definition at line 120 of file ModelConfig.cxx.

121 {
122  return outputNodes;
123 }
std::vector< std::string > outputNodes
Definition: ModelConfig.h:133
std::string ModelConfig::getSavedir ( ) const

Definition at line 95 of file ModelConfig.cxx.

96 {
97  return savedir;
98 }
std::string savedir
Definition: ModelConfig.h:118
const std::vector< InputConfig > & ModelConfig::getScalarInputs ( ) const

Definition at line 110 of file ModelConfig.cxx.

111 {
112  return scalarInputs;
113 }
std::vector< InputConfig > scalarInputs
Definition: ModelConfig.h:131
const std::vector< InputConfig > & ModelConfig::getVectorInputs ( ) const

Definition at line 115 of file ModelConfig.cxx.

116 {
117  return vectorInputs;
118 }
std::vector< InputConfig > vectorInputs
Definition: ModelConfig.h:132
bool ModelConfig::isLoaded ( ) const

Definition at line 39 of file ModelConfig.cxx.

40 {
41  return loaded;
42 }
void ModelConfig::load ( )

Definition at line 44 of file ModelConfig.cxx.

45 {
46  if (loaded) {
47  return;
48  }
49 
50  const std::string configPath = getConfigPath();
51  try {
52  parseConfig(configPath);
53  }
54  catch (const std::exception& e) {
55  throw std::runtime_error(
56  "Failed to parse config file: " + configPath + ". : " + e.what()
57  );
58  }
59 
60  loaded = true;
61 }
std::string getConfigPath() const
std::string string
Definition: nybbler.cc:12
void parseConfig(const std::string &fname)
Definition: ModelConfig.cxx:77
const double e
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void ModelConfig::parseConfig ( const std::string fname)
private

Definition at line 77 of file ModelConfig.cxx.

78 {
79  pt::ptree tree;
80  pt::read_json(fname, tree);
81 
82  for (const auto &inputKeys : scalarInputKeys) {
83  scalarInputs.emplace_back(parseInput(tree, inputKeys));
84  }
85 
86  for (const auto &inputKeys : vectorInputKeys) {
87  vectorInputs.emplace_back(parseInput(tree, inputKeys));
88  }
89 
90  for (const auto &outputKey : outputKeys) {
91  outputNodes.emplace_back(tree.get<std::string>(outputKey));
92  }
93 }
std::vector< std::string > outputKeys
Definition: ModelConfig.h:129
std::vector< InputConfigKeys > scalarInputKeys
Definition: ModelConfig.h:127
std::vector< std::string > outputNodes
Definition: ModelConfig.h:133
std::vector< InputConfigKeys > vectorInputKeys
Definition: ModelConfig.h:128
std::string string
Definition: nybbler.cc:12
std::vector< InputConfig > vectorInputs
Definition: ModelConfig.h:132
std::vector< InputConfig > scalarInputs
Definition: ModelConfig.h:131
static InputConfig parseInput(pt::ptree &tree, const InputConfigKeys &keys)
Definition: ModelConfig.cxx:63
InputConfig ModelConfig::parseInput ( pt::ptree &  tree,
const InputConfigKeys keys 
)
staticprivate

Definition at line 63 of file ModelConfig.cxx.

66 {
67  std::string nodeName = tree.get<std::string>(keys.nodeName);
68  std::vector<std::string> varNames;
69 
70  for (auto &stree : tree.get_child(keys.varNames)) {
71  varNames.push_back(stree.second.get_value<std::string>());
72  }
73 
74  return InputConfig{ std::move(nodeName), std::move(varNames) };
75 }
std::string nodeName
Definition: ModelConfig.h:84
std::string string
Definition: nybbler.cc:12
std::string varNames
Definition: ModelConfig.h:85
def move(depos, offset)
Definition: depos.py:107

Member Data Documentation

bool ModelConfig::loaded
private

Definition at line 119 of file ModelConfig.h.

std::vector<std::string> ModelConfig::outputKeys
private

Definition at line 129 of file ModelConfig.h.

std::vector<std::string> ModelConfig::outputNodes
private

Definition at line 133 of file ModelConfig.h.

std::string ModelConfig::savedir
private

Definition at line 118 of file ModelConfig.h.

std::vector<InputConfigKeys> ModelConfig::scalarInputKeys
private

Definition at line 127 of file ModelConfig.h.

std::vector<InputConfig> ModelConfig::scalarInputs
private

Definition at line 131 of file ModelConfig.h.

std::vector<InputConfigKeys> ModelConfig::vectorInputKeys
private

Definition at line 128 of file ModelConfig.h.

std::vector<InputConfig> ModelConfig::vectorInputs
private

Definition at line 132 of file ModelConfig.h.


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