CYCLUS
Loading...
Searching...
No Matches
xml_file_loader.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_XML_FILE_LOADER_H_
2#define CYCLUS_SRC_XML_FILE_LOADER_H_
3
4#include <map>
5#include <string>
6#include <sstream>
7#include <boost/shared_ptr.hpp>
8
9#include "composition.h"
10#include "dynamic_module.h"
11#include "infile_tree.h"
12#include "xml_parser.h"
13#include "timer.h"
14#include "recorder.h"
15#include "package.h"
16
17namespace cyclus {
18
19class Context;
20
21/// Reads the given file path into the passed stream without modification.
22void LoadRawStringstreamFromFile(std::stringstream& stream, std::string file);
23
24/// Reads the given file path as XML into the passed stream.
25/// The format may be "none", "xml", "json", or "py".
26void LoadStringstreamFromFile(std::stringstream& stream, std::string file,
27 std::string format="none");
28
29/// Reads the given file path and returns an XML string.
30/// The format may be "none", "xml", "json", or "py".
31std::string LoadStringFromFile(std::string file, std::string format="none");
32
33/// Returns a list of the full module+agent spec for all agents in the given
34/// input file.
35std::vector<AgentSpec> ParseSpecs(std::string infile, std::string format="none");
36
37/// Builds and returns a master cyclus input xml schema that includes the
38/// sub-schemas defined by all installed cyclus modules (e.g. facility agents).
39/// This is used to validate simulation input files.
40std::string BuildMasterSchema(std::string schema_path, std::string infile,
41 std::string format="none");
42
43/// Creates a composition from the recipe in the query engine.
44Composition::Ptr ReadRecipe(InfileTree* qe);
45
46/// Handles initialization of a database with information from
47/// a cyclus xml input file.
48///
49/// @warning the LoadSim method is NOT idempotent. Only one / simulation should
50/// ever be initialized per XMLFileLoader object.
52 public:
53 /// Create a new loader reading from the xml simulation input file and writing
54 /// to and initializing the backends in r. r must already have b registered.
55 /// schema_file identifies the master xml rng schema used to validate the
56 /// input file. The format specifies the input file format from one of:
57 /// "none", "xml", "json", or "py".
59 const std::string input_file="", const std::string format="none", bool ms_print=false);
60
61 virtual ~XMLFileLoader();
62
63 /// Load an entire simulation from the inputfile.
64 ///
65 /// @param use_flat_schema whether or not to use the flat schema
66 virtual void LoadSim();
67
68 protected:
69 /// Load agent specs from the input file to a map by alias
70 void LoadSpecs();
71
72 /// Method to load the simulation exchange solver.
73 void LoadSolver();
74
75 /// Method to load the simulation control parameters.
76 void LoadControlParams();
77
78 /// Method to load recipes from either the primary input file
79 /// or a recipeBook catalog.
80 void LoadRecipes();
81
82 /// loads a specific recipe
84
85 /// Loads packages
86 void LoadPackages();
87
88 /// Loads Transport Units
89 void LoadTransportUnits();
90
91 /// Creates all initial agent instances from the input file.
92 virtual void LoadInitialAgents();
93
94 virtual std::string master_schema();
95
96 /// Processes commodity priorities, such that any without a defined priority
97 /// (i.e., are nonpositive), are given priority lower than the last known
98 /// commodity
99 void ProcessCommodities(std::map<std::string, double>* commodity_priority);
100
101 /// Creates and builds an agent, notifying its parent. The agent init info is
102 /// translated and stored in the output db.
103 Agent* BuildAgent(std::string proto, Agent* parent);
104
109
110 /// flag to indicate printing master schema
112
113 /// filepath to the schema
114 std::string schema_path_;
115
116 // map<specalias, spec>
117 std::map<std::string, AgentSpec> specs_;
118
119 /// the parser
120 boost::shared_ptr<XMLParser> parser_;
121
122 /// the input file name
123 std::string file_;
124
125 /// the input file format
126 std::string format_;
127};
128
129} // namespace cyclus
130
131#endif // CYCLUS_SRC_XML_FILE_LOADER_H_
a holding class for information related to a TradeExecutor
The abstract base class used by all types of agents that live and interact in a simulation.
Definition agent.h:49
boost::shared_ptr< Composition > Ptr
Definition composition.h:43
A simulation context provides access to necessary simulation-global functions and state.
Definition context.h:145
A class for extracting information from a given XML parser.
Definition infile_tree.h:22
Interface implemented by backends that support rudimentary querying.
Collects and manages output data generation for the cyclus core and agents during a simulation.
Definition recorder.h:45
Controls simulation timestepping and inter-timestep phases.
Definition timer.h:22
Handles initialization of a database with information from a cyclus xml input file.
void LoadRecipe(InfileTree *qe)
loads a specific recipe
XMLFileLoader(Recorder *r, QueryableBackend *b, std::string schema_file, const std::string input_file="", const std::string format="none", bool ms_print=false)
Create a new loader reading from the xml simulation input file and writing to and initializing the ba...
void LoadPackages()
Loads packages.
void LoadRecipes()
Method to load recipes from either the primary input file or a recipeBook catalog.
std::string format_
the input file format
void LoadControlParams()
Method to load the simulation control parameters.
boost::shared_ptr< XMLParser > parser_
the parser
void LoadSolver()
Method to load the simulation exchange solver.
void LoadSpecs()
Load agent specs from the input file to a map by alias.
bool ms_print_
flag to indicate printing master schema
virtual std::string master_schema()
QueryableBackend * b_
std::string schema_path_
filepath to the schema
void LoadTransportUnits()
Loads Transport Units.
std::map< std::string, AgentSpec > specs_
virtual void LoadInitialAgents()
Creates all initial agent instances from the input file.
Agent * BuildAgent(std::string proto, Agent *parent)
Creates and builds an agent, notifying its parent.
void ProcessCommodities(std::map< std::string, double > *commodity_priority)
Processes commodity priorities, such that any without a defined priority (i.e., are nonpositive),...
std::string file_
the input file name
virtual void LoadSim()
Load an entire simulation from the inputfile.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
void LoadRawStringstreamFromFile(std::stringstream &stream, std::string file)
Reads the given file path into the passed stream without modification.
Composition::Ptr ReadRecipe(InfileTree *qe)
Creates a composition from the recipe in the query engine.
void LoadStringstreamFromFile(std::stringstream &stream, std::string file, std::string format)
Reads the given file path as XML into the passed stream.
std::string BuildMasterSchema(std::string schema_path, std::string infile, std::string format)
Builds and returns a master cyclus input xml schema that includes the sub-schemas defined by all inst...
std::string LoadStringFromFile(std::string file, std::string format)
Reads the given file path and returns an XML string.
std::vector< AgentSpec > ParseSpecs(std::string infile, std::string format)
Returns a list of the full module+agent spec for all agents in the given input file.
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters