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 void LoadStringstreamFromFile(std::stringstream& stream, std::string file);
25 
26 /// Returns a list of the full module+agent spec for all agents in the given
27 /// input file.
28 std::vector<AgentSpec> ParseSpecs(std::string infile);
29 
30 /// Builds and returns a master cyclus input xml schema that includes the
31 /// sub-schemas defined by all installed cyclus modules (e.g. facility agents).
32 /// This is used to validate simulation input files.
33 std::string BuildMasterSchema(std::string schema_path, std::string infile);
34 
35 /// Creates a composition from the recipe in the query engine.
36 Composition::Ptr ReadRecipe(InfileTree* qe);
37 
38 /// Handles initialization of a database with information from
39 /// a cyclus xml input file.
40 ///
41 /// @warning the LoadSim method is NOT idempotent. Only one / simulation should
42 /// ever be initialized per XMLFileLoader object.
44  public:
45  /// Create a new loader reading from the xml simulation input file and writing
46  /// to and initializing the backends in r. r must already have b registered.
47  /// schema_file identifies the master xml rng schema used to validate the
48  /// input file.
49  XMLFileLoader(Recorder* r, QueryableBackend* b, std::string schema_file,
50  const std::string input_file = "");
51 
52  virtual ~XMLFileLoader();
53 
54  /// Load an entire simulation from the inputfile.
55  ///
56  /// @param use_flat_schema whether or not to use the flat schema
57  virtual void LoadSim();
58 
59  protected:
60  /// Load agent specs from the input file to a map by alias
61  void LoadSpecs();
62 
63  /// Method to load the simulation exchange solver.
64  void LoadSolver();
65 
66  /// Method to load the simulation control parameters.
67  void LoadControlParams();
68 
69  /// Method to load recipes from either the primary input file
70  /// or a recipeBook catalog.
71  void LoadRecipes();
72 
73  /// loads a specific recipe
74  void LoadRecipe(InfileTree* qe);
75 
76  /// Creates all initial agent instances from the input file.
77  virtual void LoadInitialAgents();
78 
79  virtual std::string master_schema();
80 
81  /// Processes commodity priorities, such that any without a defined priority
82  /// (i.e., are nonpositive), are given priority lower than the last known
83  /// commodity
84  void ProcessCommodities(std::map<std::string, double>* commodity_priority);
85 
86  /// Creates and builds an agent, notifying its parent. The agent init info is
87  /// translated and stored in the output db.
88  Agent* BuildAgent(std::string proto, Agent* parent);
89 
94 
95  /// filepath to the schema
96  std::string schema_path_;
97 
98  // map<specalias, spec>
99  std::map<std::string, AgentSpec> specs_;
100 
101  /// the parser
102  boost::shared_ptr<XMLParser> parser_;
103 
104  /// the input file name
105  std::string file_;
106 };
107 
108 } // namespace cyclus
109 
110 #endif // CYCLUS_SRC_XML_FILE_LOADER_H_
virtual std::string master_schema()
boost::shared_ptr< XMLParser > parser_
the parser
std::string BuildMasterSchema(std::string schema_path, std::string infile)
Builds and returns a master cyclus input xml schema that includes the sub-schemas defined by all inst...
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
void LoadControlParams()
Method to load the simulation control parameters.
QueryableBackend * b_
Handles initialization of a database with information from a cyclus xml input file.
void LoadStringstreamFromFile(std::stringstream &stream, std::string file)
Reads the given file path as XML into the passed stream.
int parent(int nuc, unsigned int rx, std::string z="n")
Definition: pyne.cc:6621
std::map< std::string, AgentSpec > specs_
std::vector< AgentSpec > ParseSpecs(std::string infile)
Returns a list of the full module+agent spec for all agents in the given input file.
Composition::Ptr ReadRecipe(InfileTree *qe)
Creates a composition from the recipe in the query engine.
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:128
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.
void ProcessCommodities(std::map< std::string, double > *commodity_priority)
Processes commodity priorities, such that any without a defined priority (i.e., are nonpositive)...
virtual void LoadSim()
Load an entire simulation from the inputfile.
void LoadSpecs()
Load agent specs from the input file to a map by alias.
XMLFileLoader(Recorder *r, QueryableBackend *b, std::string schema_file, const std::string input_file="")
Create a new loader reading from the xml simulation input file and writing to and initializing the ba...
Interface implemented by backends that support rudimentary querying.
Controls simulation timestepping and inter-timestep phases.
Definition: timer.h:22