CYCLUS
commodity_recipe_context.cc
Go to the documentation of this file.
1 #include <utility>
2 
4 
5 namespace cyclus {
6 namespace toolkit {
7 
8 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
10  std::string in_recipe,
11  std::string out_commod,
12  std::string out_recipe) {
13  in_commods_.insert(in_commod);
14  out_commods_.insert(out_commod);
15  out_commod_map_[in_commod] = out_commod;
16  in_recipes_[in_commod] = in_recipe;
17  out_recipes_[in_commod] = out_recipe;
18 }
19 
20 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22  rsrc_commod_map_[rsrc->obj_id()] = commod;
23 }
24 
25 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
27  rsrc_commod_map_.erase(rsrc->obj_id());
28 }
29 
30 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32  rsrc_commod_map_[rsrc->obj_id()] = commod;
33 }
34 
35 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37  std::string recipe) {
38  in_recipes_[incommod] = recipe;
39 }
40 
42  return new CommodityRecipeContext(*this);
43 }
44 
46  int nfuel = qe->NMatches("fuel");
47  for (int i = 0; i < nfuel; i++) {
48  InfileTree* fuel = qe->SubTree("fuel", i);
49  di.NewDatum("CommodityRecipeContext_inoutmap")
50  ->AddVal("in_commod", fuel->GetString("incommodity"))
51  ->AddVal("in_recipe", fuel->GetString("inrecipe"))
52  ->AddVal("out_commod", fuel->GetString("outcommodity"))
53  ->AddVal("out_recipe", fuel->GetString("outrecipe"))
54  ->Record();
55  }
56 }
57 
59  QueryResult qr = b->Query("CommodityRecipeContext_inoutmap", NULL);
60  for (int i = 0; i < qr.rows.size(); ++i) {
61  AddInCommod(qr.GetVal<std::string>("in_commod", i),
62  qr.GetVal<std::string>("in_recipe", i),
63  qr.GetVal<std::string>("out_commod", i),
64  qr.GetVal<std::string>("out_recipe", i));
65  }
66 
67  try {
68  qr = b->Query("CommodityRecipeContext_resmap", NULL);
69  } catch(std::exception err) { return; } // Table doesn't exist (okay)
70 
71  for (int i = 0; i < qr.rows.size(); ++i) {
72  std::string commod = qr.GetVal<std::string>("commod", i);
73  int id = qr.GetVal<int>("res_id", i);
74  rsrc_commod_map_[id] = commod;
75  }
76 }
77 
79  std::set<std::string>::iterator it2;
80  for (it2 = in_commods_.begin(); it2 != in_commods_.end(); ++it2) {
81  std::string c = *it2;
82  di.NewDatum("CommodityRecipeContext_inoutmap")
83  ->AddVal("in_commod", c)
84  ->AddVal("in_recipe", in_recipes_[c])
85  ->AddVal("out_commod", out_commod_map_[c])
86  ->AddVal("out_recipe", out_recipes_[c])
87  ->Record();
88  }
89 
90  std::map<int, std::string>::iterator it = rsrc_commod_map_.begin();
91  for (; it != rsrc_commod_map_.end(); ++it) {
92  di.NewDatum("CommodityRecipeContext_resmap")
93  ->AddVal("commod", it->second)
94  ->AddVal("res_id", it->first)
95  ->Record();
96  }
97 }
98 
100  return
101  " <oneOrMore> \n"
102  " <element name=\"fuel\"> \n"
103  " <element name=\"incommodity\"><text/></element>\n"
104  " <element name=\"inrecipe\"><text/></element>\n"
105  " <element name=\"outcommodity\"><text/></element>\n"
106  " <element name=\"outrecipe\"><text/></element>\n"
107  " </element> \n"
108  " </oneOrMore> \n";
109 }
110 
111 } // namespace toolkit
112 } // namespace cyclus
void UpdateRsrc(std::string commod, Resource::Ptr rsrc)
update a resource and its commodity affiliation
virtual void Snapshot(DbInit di)
Snapshots agent-internal state to the output db via di.
double b(int nuc)
Computes the scattering length [cm] from the coherent and incoherent components.
Definition: pyne.cc:11180
virtual int NMatches(std::string query)
investigates the current status and returns the number of elements matching a query ...
Definition: infile_tree.cc:49
Meta data and results of a query.
A class for extracting information from a given XML parser.
Definition: infile_tree.h:22
virtual void InfileToDb(InfileTree *qe, DbInit di)
Translates info for the object from input file information to the database by reading parameters from...
Datum * NewDatum(std::string title)
Returns a new datum to be used exactly as the Context::NewDatum method.
Definition: db_init.cc:12
T GetVal(std::string field, int row=0)
Convenience method for retrieving a value from a specific row and named field (column).
std::string out_recipe(std::string in_commod)
void AddRsrc(std::string commod, Resource::Ptr rsrc)
add a resource and its commodity affiliation
virtual std::string GetString(std::string query, int index=0)
investigates the current status and returns a string representing the content of a query at a given i...
Definition: infile_tree.cc:54
virtual std::string schema()
Returns an object&#39;s xml rng schema for initializing from input files.
void AddInCommod(std::string in_commod, std::string in_recipe, std::string out_commod, std::string out_recipe)
add an input commodity and its relations
Datum * AddVal(const char *field, boost::spirit::hold_any val, std::vector< int > *shape=NULL)
Add an arbitrary field-value pair to the datum.
Definition: datum.cc:22
a CommodityRecipeContext contains relationships between commodities, recipes and resources ...
DbInit provides an interface for agents to record data to the output db that automatically injects th...
Definition: db_init.h:14
void UpdateInRec(std::string in_commod, std::string recipe)
update an input recipe and its commodity affiliation
InfileTree * SubTree(std::string query, int index=0)
populates a child infile based on a query and index
Definition: infile_tree.cc:132
boost::shared_ptr< Resource > Ptr
Definition: resource.h:24
virtual QueryResult Query(std::string table, std::vector< Cond > *conds)=0
Return a set of rows from the specificed table that match all given conditions.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
std::vector< QueryRow > rows
ordered results of a query
int id(int nuc)
Definition: pyne.cc:2716
std::string in_recipe(std::string in_commod)
void Record()
Record this datum to its Recorder.
Definition: datum.cc:35
void RemoveRsrc(Resource::Ptr rsrc)
removes a resource from the context
virtual void InitFrom(QueryableBackend *b)
Intializes an agent&#39;s internal state from an output database.
Interface implemented by backends that support rudimentary querying.
virtual CommodityRecipeContext * Clone()
Return a newly created/allocated object that is an exact copy of this.
std::string out_commod(std::string in_commod)