CYCAMORE
src/deploy_inst.cc
Go to the documentation of this file.
1 // Implements the DeployInst class
2 #include "deploy_inst.h"
3 
4 namespace cycamore {
5 
6 DeployInst::DeployInst(cyclus::Context* ctx)
7  : cyclus::Institution(ctx),
8  latitude(0.0),
9  longitude(0.0),
11 
13 
14 void DeployInst::Build(cyclus::Agent* parent) {
15  cyclus::Institution::Build(parent);
16  BuildSched::iterator it;
17  std::set<std::string> protos;
18  for (int i = 0; i < prototypes.size(); i++) {
19  std::string proto = prototypes[i];
20 
21  std::stringstream ss;
22  ss << proto;
23 
24  if (lifetimes.size() == prototypes.size()) {
25  cyclus::Agent* a = context()->CreateAgent<Agent>(proto);
26  if (a->lifetime() != lifetimes[i]) {
27  a->lifetime(lifetimes[i]);
28 
29  if (lifetimes[i] == -1) {
30  ss << "_life_forever";
31  } else {
32  ss << "_life_" << lifetimes[i];
33  }
34  proto = ss.str();
35  if (protos.count(proto) == 0) {
36  protos.insert(proto);
37  context()->AddPrototype(proto, a);
38  }
39  }
40  }
41 
42  int t = build_times[i];
43  for (int j = 0; j < n_build[i]; j++) {
44  context()->SchedBuild(this, proto, t);
45  }
46  }
47 }
48 
50  cyclus::Institution::EnterNotify();
51  int n = prototypes.size();
52  if (build_times.size() != n) {
53  std::stringstream ss;
54  ss << "prototype '" << prototype() << "' has " << build_times.size()
55  << " build_times vals, expected " << n;
56  throw cyclus::ValueError(ss.str());
57  } else if (n_build.size() != n) {
58  std::stringstream ss;
59  ss << "prototype '" << prototype() << "' has " << n_build.size()
60  << " n_build vals, expected " << n;
61  throw cyclus::ValueError(ss.str());
62  } else if (lifetimes.size() > 0 && lifetimes.size() != n) {
63  std::stringstream ss;
64  ss << "prototype '" << prototype() << "' has " << lifetimes.size()
65  << " lifetimes vals, expected " << n;
66  throw cyclus::ValueError(ss.str());
67  }
69 }
70 
72  std::string specification = this->spec();
73  context()
74  ->NewDatum("AgentPosition")
75  ->AddVal("Spec", specification)
76  ->AddVal("Prototype", this->prototype())
77  ->AddVal("AgentId", id())
78  ->AddVal("Latitude", latitude)
79  ->AddVal("Longitude", longitude)
80  ->Record();
81 }
82 
83 extern "C" cyclus::Agent* ConstructDeployInst(cyclus::Context* ctx) {
84  return new DeployInst(ctx);
85 }
86 
87 } // namespace cycamore
double longitude
virtual void Build(cyclus::Agent *parent)
cyclus::Agent * ConstructDeployInst(cyclus::Context *ctx)
std::vector< std::string > prototypes
cycamore::GrowthRegion string
cyclus::toolkit::Position coordinates
void RecordPosition()
Records an agent&#39;s latitude and longitude to the output db.