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