CYCLUS
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 
16 namespace cyclus {
17 
18 class Context;
19 
20 /// Reads the given file path into the passed stream without modification.
21 void LoadRawStringstreamFromFile(std::stringstream& stream, std::string file);
22 
23 /// Reads the given file path as XML into the passed stream.
24 /// The format may be "none", "xml", "json", or "py".
25 void LoadStringstreamFromFile(std::stringstream& stream, std::string file,
26  std::string format="none");
27 
28 /// Reads the given file path and returns an XML string.
29 /// The format may be "none", "xml", "json", or "py".
31 
32 /// Returns a list of the full module+agent spec for all agents in the given
33 /// input file.
34 std::vector<AgentSpec> ParseSpecs(std::string infile, std::string format="none");
35 
36 /// Builds and returns a master cyclus input xml schema that includes the
37 /// sub-schemas defined by all installed cyclus modules (e.g. facility agents).
38 /// This is used to validate simulation input files.
40  std::string format="none");
41 
42 /// Creates a composition from the recipe in the query engine.
43 Composition::Ptr ReadRecipe(InfileTree* qe);
44 
45 /// Handles initialization of a database with information from
46 /// a cyclus xml input file.
47 ///
48 /// @warning the LoadSim method is NOT idempotent. Only one / simulation should
49 /// ever be initialized per XMLFileLoader object.
51  public:
52  /// Create a new loader reading from the xml simulation input file and writing
53  /// to and initializing the backends in r. r must already have b registered.
54  /// schema_file identifies the master xml rng schema used to validate the
55  /// input file. The format specifies the input file format from one of:
56  /// "none", "xml", "json", or "py".
58  const std::string input_file="", const std::string format="none", bool ms_print=false);
59 
60  virtual ~XMLFileLoader();
61 
62  /// Load an entire simulation from the inputfile.
63  ///
64  /// @param use_flat_schema whether or not to use the flat schema
65  virtual void LoadSim();
66 
67  protected:
68  /// Load agent specs from the input file to a map by alias
69  void LoadSpecs();
70 
71  /// Method to load the simulation exchange solver.
72  void LoadSolver();
73 
74  /// Method to load the simulation control parameters.
75  void LoadControlParams();
76 
77  /// Method to load recipes from either the primary input file
78  /// or a recipeBook catalog.
79  void LoadRecipes();
80 
81  /// loads a specific recipe
82  void LoadRecipe(InfileTree* qe);
83 
84  /// Creates all initial agent instances from the input file.
85  virtual void LoadInitialAgents();
86 
87  virtual std::string master_schema();
88 
89  /// Processes commodity priorities, such that any without a defined priority
90  /// (i.e., are nonpositive), are given priority lower than the last known
91  /// commodity
92  void ProcessCommodities(std::map<std::string, double>* commodity_priority);
93 
94  /// Creates and builds an agent, notifying its parent. The agent init info is
95  /// translated and stored in the output db.
97 
102 
103  /// flag to indicate printing master schema
104  bool ms_print_;
105 
106  /// filepath to the schema
108 
109  // map<specalias, spec>
110  std::map<std::string, AgentSpec> specs_;
111 
112  /// the parser
113  boost::shared_ptr<XMLParser> parser_;
114 
115  /// the input file name
117 
118  /// the input file format
120 };
121 
122 } // namespace cyclus
123 
124 #endif // CYCLUS_SRC_XML_FILE_LOADER_H_
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...
virtual std::string master_schema()
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...
boost::shared_ptr< XMLParser > parser_
the parser
boost::shared_ptr< Composition > Ptr
Definition: composition.h:43
std::string schema_path_
filepath to the schema
double b(int nuc)
Computes the scattering length [cm] from the coherent and incoherent components.
Definition: pyne.cc:11180
std::string file_
the input file name
void LoadRawStringstreamFromFile(std::stringstream &stream, std::string file)
Reads the given file path into the passed stream without modification.
void LoadRecipes()
Method to load recipes from either the primary input file or a recipeBook catalog.
virtual void LoadInitialAgents()
Creates all initial agent instances from the input file.
void LoadRecipe(InfileTree *qe)
loads a specific recipe
Agent * BuildAgent(std::string proto, Agent *parent)
Creates and builds an agent, notifying its parent.
A class for extracting information from a given XML parser.
Definition: infile_tree.h:22
std::string format_
the input file format
void LoadControlParams()
Method to load the simulation control parameters.
QueryableBackend * b_
Handles initialization of a database with information from a cyclus xml input file.
int parent(int nuc, unsigned int rx, std::string z="n")
Definition: pyne.cc:6621
std::map< std::string, AgentSpec > specs_
Composition::Ptr ReadRecipe(InfileTree *qe)
Creates a composition from the recipe in the query engine.
bool ms_print_
flag to indicate printing master schema
Collects and manages output data generation for the cyclus core and agents during a simulation...
Definition: recorder.h:45
A simulation context provides access to necessary simulation-global functions and state...
Definition: context.h:130
The abstract base class used by all types of agents that live and interact in a simulation.
Definition: agent.h:51
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
void LoadSolver()
Method to load the simulation exchange solver.
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.
void ProcessCommodities(std::map< std::string, double > *commodity_priority)
Processes commodity priorities, such that any without a defined priority (i.e., are nonpositive)...
void LoadStringstreamFromFile(std::stringstream &stream, std::string file, std::string format)
Reads the given file path as XML into the passed stream.
virtual void LoadSim()
Load an entire simulation from the inputfile.
std::string LoadStringFromFile(std::string file, std::string format)
Reads the given file path and returns an XML string.
void LoadSpecs()
Load agent specs from the input file to a map by alias.
Interface implemented by backends that support rudimentary querying.
Controls simulation timestepping and inter-timestep phases.
Definition: timer.h:22