CYCAMORE
Loading...
Searching...
No Matches
build/cycamore/deploy_inst.cc
Go to the documentation of this file.
1#line 1 "/cycamore/src/deploy_inst.cc"
2// Implements the DeployInst class
3#include "deploy_inst.h"
4
5namespace cycamore {
6
7DeployInst::DeployInst(cyclus::Context* ctx)
8 : cyclus::Institution(ctx),
9 latitude(0.0),
10 longitude(0.0),
12
14
15void DeployInst::Build(cyclus::Agent* parent) {
16 cyclus::Institution::Build(parent);
17 BuildSched::iterator it;
18 std::set<std::string> protos;
19 for (int i = 0; i < prototypes.size(); i++) {
20 std::string proto = prototypes[i];
21
22 std::stringstream ss;
23 ss << proto;
24
25 if (lifetimes.size() == prototypes.size()) {
26 cyclus::Agent* a = context()->CreateAgent<Agent>(proto);
27 if (a->lifetime() != lifetimes[i]) {
28 a->lifetime(lifetimes[i]);
29
30 if (lifetimes[i] == -1) {
31 ss << "_life_forever";
32 } else {
33 ss << "_life_" << lifetimes[i];
34 }
35 proto = ss.str();
36 if (protos.count(proto) == 0) {
37 protos.insert(proto);
38 context()->AddPrototype(proto, a);
39 }
40 }
41 }
42
43 int t = build_times[i];
44 for (int j = 0; j < n_build[i]; j++) {
45 context()->SchedBuild(this, proto, t);
46 }
47 }
48}
49
51 cyclus::Institution::EnterNotify();
52 int n = prototypes.size();
53 if (build_times.size() != n) {
54 std::stringstream ss;
55 ss << "prototype '" << prototype() << "' has " << build_times.size()
56 << " build_times vals, expected " << n;
57 throw cyclus::ValueError(ss.str());
58 } else if (n_build.size() != n) {
59 std::stringstream ss;
60 ss << "prototype '" << prototype() << "' has " << n_build.size()
61 << " n_build vals, expected " << n;
62 throw cyclus::ValueError(ss.str());
63 } else if (lifetimes.size() > 0 && lifetimes.size() != n) {
64 std::stringstream ss;
65 ss << "prototype '" << prototype() << "' has " << lifetimes.size()
66 << " lifetimes vals, expected " << n;
67 throw cyclus::ValueError(ss.str());
68 }
70}
71
73 Register_(a);
74}
75
77 Unregister_(a);
78}
79
80void DeployInst::Register_(Agent* a) {
81 using cyclus::toolkit::CommodityProducer;
82 using cyclus::toolkit::CommodityProducerManager;
83
84 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
85 if (cp_cast != NULL) {
86 LOG(cyclus::LEV_INFO3, "mani") << "Registering agent "
87 << a->prototype() << a->id()
88 << " as a commodity producer.";
89 CommodityProducerManager::Register(cp_cast);
90 }
91}
92
93void DeployInst::Unregister_(Agent* a) {
94 using cyclus::toolkit::CommodityProducer;
95 using cyclus::toolkit::CommodityProducerManager;
96
97 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
98 if (cp_cast != NULL)
99 CommodityProducerManager::Unregister(cp_cast);
100}
101
102// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
104 cyclus::toolkit::CommodityProducer* producer) {
105 using std::set;
106 set<cyclus::toolkit::Commodity,
107 cyclus::toolkit::CommodityCompare> commodities =
108 producer->ProducedCommodities();
109 set<cyclus::toolkit::Commodity, cyclus::toolkit::CommodityCompare>::
110 iterator it;
111
112 LOG(cyclus::LEV_DEBUG3, "maninst") << " Clone produces " << commodities.size()
113 << " commodities.";
114 for (it = commodities.begin(); it != commodities.end(); it++) {
115 LOG(cyclus::LEV_DEBUG3, "maninst") << " Commodity produced: " << it->name();
116 LOG(cyclus::LEV_DEBUG3, "maninst") << " capacity: " <<
117 producer->Capacity(*it);
118 LOG(cyclus::LEV_DEBUG3, "maninst") << " cost: " <<
119 producer->Cost(*it);
120 }
121}
122
124 std::string specification = this->spec();
125 context()
126 ->NewDatum("AgentPosition")
127 ->AddVal("Spec", specification)
128 ->AddVal("Prototype", this->prototype())
129 ->AddVal("AgentId", id())
130 ->AddVal("Latitude", latitude)
131 ->AddVal("Longitude", longitude)
132 ->Record();
133}
134
135extern "C" cyclus::Agent* ConstructDeployInst(cyclus::Context* ctx) {
136 return new DeployInst(ctx);
137}
138
139} // namespace cycamore
void WriteProducerInformation(cyclus::toolkit::CommodityProducer *producer)
write information about a commodity producer to a stream
void Unregister_(cyclus::Agent *agent)
unregister a child
void RecordPosition()
Records an agent's latitude and longitude to the output db.
DeployInst(cyclus::Context *ctx)
virtual void DecomNotify(Agent *m)
void Register_(cyclus::Agent *agent)
register a child
virtual void Build(cyclus::Agent *parent)
std::vector< std::string > prototypes
virtual void BuildNotify(Agent *m)
cyclus::Agent * ConstructDeployInst(cyclus::Context *ctx)
cyclus::toolkit::Position coordinates