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/// set of agent names.
35std::vector<AgentSpec> ParseSpecs(std::set<std::string> agent_set);
36
37/// Returns a list of the full module+agent spec for all agents in the given
38/// input file.
39std::vector<AgentSpec> ParseSpecs(std::string infile,
40 std::string format = "none");
41
42/// Builds and returns a master cyclus input xml schema that includes the
43/// sub-schemas defined by the provided list of agent specifications.
44/// This is used but other versions of BuildMasterSchema.
45std::string BuildMasterSchema(
46 std::string schema_path, std::vector<AgentSpec> specs);
47
48/// Builds and returns a master cyclus input xml schema that includes the
49/// sub-schemas from all the installed modules.
50std::string BuildMasterSchema(std::string schema_path);
51
52/// Builds and returns a master cyclus input xml schema that includes the
53/// sub-schemas defined by all cyclus modules (e.g. facility agents) referenced
54/// in the input file. This is used to validate simulation input files.
55std::string BuildMasterSchema(std::string schema_path, std::string infile,
56 std::string format = "none");
57
58/// Creates a composition from the recipe in the query engine.
60
61/// Handles initialization of a database with information from
62/// a cyclus xml input file.
63///
64/// @warning the LoadSim method is NOT idempotent. Only one / simulation should
65/// ever be initialized per XMLFileLoader object.
67 public:
68 /// Create a new loader reading from the xml simulation input file and writing
69 /// to and initializing the backends in r. r must already have b registered.
70 /// schema_file identifies the master xml rng schema used to validate the
71 /// input file. The format specifies the input file format from one of:
72 /// "none", "xml", "json", or "py".
73 XMLFileLoader(Recorder* r, QueryableBackend* b, std::string schema_file,
74 const std::string input_file = "",
75 const std::string format = "none", bool ms_print = false);
76
77 virtual ~XMLFileLoader();
78
79 /// Load an entire simulation from the inputfile.
80 ///
81 /// @param use_flat_schema whether or not to use the flat schema
82 virtual void LoadSim();
83
84 protected:
85 /// Load agent specs from the input file to a map by alias
86 void LoadSpecs();
87
88 /// Method to load the simulation exchange solver.
89 void LoadSolver();
90
91 /// Method to load the simulation control parameters.
92 void LoadControlParams();
93
94 /// Method to load recipes from either the primary input file
95 /// or a recipeBook catalog.
96 void LoadRecipes();
97
98 /// loads a specific recipe
100
101 /// Loads packages
102 void LoadPackages();
103
104 /// Loads Transport Units
105 void LoadTransportUnits();
106
107 /// Creates all initial agent instances from the input file.
108 virtual void LoadInitialAgents();
109
110 virtual std::string master_schema();
111
112 /// Processes commodity priorities, such that any without a defined priority
113 /// (i.e., are nonpositive), are given priority lower than the last known
114 /// commodity
115 void ProcessCommodities(std::map<std::string, double>* commodity_priority);
116
117 /// Creates and builds an agent, notifying its parent. The agent init info is
118 /// translated and stored in the output db.
119 Agent* BuildAgent(std::string proto, Agent* parent);
120
125
126 /// flag to indicate printing master schema
128
129 /// filepath to the schema
130 std::string schema_path_;
131
132 // map<specalias, spec>
133 std::map<std::string, AgentSpec> specs_;
134
135 /// the parser
136 boost::shared_ptr<XMLParser> parser_;
137
138 /// the input file name
139 std::string file_;
140
141 /// the input file format
142 std::string format_;
143};
144
145} // namespace cyclus
146
147#endif // CYCLUS_SRC_XML_FILE_LOADER_H_
The abstract base class used by all types of agents that live and interact in a simulation.
Definition agent.h:50
boost::shared_ptr< Composition > Ptr
Definition composition.h:43
A simulation context provides access to necessary simulation-global functions and state.
Definition context.h:146
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
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::vector< AgentSpec > ParseSpecs(std::set< std::string > agent_set)
Returns a list of the full module+agent spec for all agents in the given set of agent names.
std::string LoadStringFromFile(std::string file, std::string format)
Reads the given file path and returns an XML string.
std::string BuildMasterSchema(std::string schema_path, std::vector< AgentSpec > specs)
Builds and returns a master cyclus input xml schema that includes the sub-schemas defined by the prov...