CYCAMORE
Loading...
Searching...
No Matches
src/deploy_inst.cc
Go to the documentation of this file.
1// Implements the DeployInst class
2#include "deploy_inst.h"
3
4namespace cycamore {
5
6DeployInst::DeployInst(cyclus::Context* ctx)
7 : cyclus::Institution(ctx),
8 latitude(0.0),
9 longitude(0.0),
11
12DeployInst::~DeployInst() {}
13
14void 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
49void DeployInst::EnterNotify() {
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
71void DeployInst::BuildNotify(Agent* a) {
72 Register_(a);
73}
74
75void DeployInst::DecomNotify(Agent* a) {
76 Unregister_(a);
77}
78
79void DeployInst::Register_(Agent* a) {
80 using cyclus::toolkit::CommodityProducer;
81 using cyclus::toolkit::CommodityProducerManager;
82
83 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
84 if (cp_cast != NULL) {
85 LOG(cyclus::LEV_INFO3, "mani") << "Registering agent "
86 << a->prototype() << a->id()
87 << " as a commodity producer.";
88 CommodityProducerManager::Register(cp_cast);
89 }
90}
91
92void DeployInst::Unregister_(Agent* a) {
93 using cyclus::toolkit::CommodityProducer;
94 using cyclus::toolkit::CommodityProducerManager;
95
96 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
97 if (cp_cast != NULL)
98 CommodityProducerManager::Unregister(cp_cast);
99}
100
101// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
102void DeployInst::WriteProducerInformation(
103 cyclus::toolkit::CommodityProducer* producer) {
104 using std::set;
105 set<cyclus::toolkit::Commodity,
106 cyclus::toolkit::CommodityCompare> commodities =
107 producer->ProducedCommodities();
108 set<cyclus::toolkit::Commodity, cyclus::toolkit::CommodityCompare>::
109 iterator it;
110
111 LOG(cyclus::LEV_DEBUG3, "maninst") << " Clone produces " << commodities.size()
112 << " commodities.";
113 for (it = commodities.begin(); it != commodities.end(); it++) {
114 LOG(cyclus::LEV_DEBUG3, "maninst") << " Commodity produced: " << it->name();
115 LOG(cyclus::LEV_DEBUG3, "maninst") << " capacity: " <<
116 producer->Capacity(*it);
117 LOG(cyclus::LEV_DEBUG3, "maninst") << " cost: " <<
118 producer->Cost(*it);
119 }
120}
121
122void DeployInst::RecordPosition() {
123 std::string specification = this->spec();
124 context()
125 ->NewDatum("AgentPosition")
126 ->AddVal("Spec", specification)
127 ->AddVal("Prototype", this->prototype())
128 ->AddVal("AgentId", id())
129 ->AddVal("Latitude", latitude)
130 ->AddVal("Longitude", longitude)
131 ->Record();
132}
133
134extern "C" cyclus::Agent* ConstructDeployInst(cyclus::Context* ctx) {
135 return new DeployInst(ctx);
136}
137
138} // namespace cycamore
DeployInst(cyclus::Context *ctx)
void RecordPosition()
Records an agent's latitude and longitude to the output db.
cyclus::Agent * ConstructDeployInst(cyclus::Context *ctx)
void Unregister_(cyclus::Agent *agent)
unregister a child
void Register_(cyclus::Agent *agent)
register a child
cyclus::toolkit::Position coordinates