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
11
12void DeployInst::Build(cyclus::Agent* parent) {
13 cyclus::Institution::Build(parent);
14 BuildSched::iterator it;
15 std::set<std::string> protos;
16 for (int i = 0; i < prototypes.size(); i++) {
17 std::string proto = prototypes[i];
18
19 std::stringstream ss;
20 ss << proto;
21
22 if (lifetimes.size() == prototypes.size()) {
23 cyclus::Agent* a = context()->CreateAgent<Agent>(proto);
24 if (a->lifetime() != lifetimes[i]) {
25 a->lifetime(lifetimes[i]);
26
27 if (lifetimes[i] == -1) {
28 ss << "_life_forever";
29 } else {
30 ss << "_life_" << lifetimes[i];
31 }
32 proto = ss.str();
33 if (protos.count(proto) == 0) {
34 protos.insert(proto);
35 context()->AddPrototype(proto, a);
36 }
37 }
38 }
39
40 int t = build_times[i];
41 for (int j = 0; j < n_build[i]; j++) {
42 context()->SchedBuild(this, proto, t);
43 }
44 }
45}
46
48 cyclus::Institution::EnterNotify();
49 int n = prototypes.size();
50 if (build_times.size() != n) {
51 std::stringstream ss;
52 ss << "prototype '" << prototype() << "' has " << build_times.size()
53 << " build_times vals, expected " << n;
54 throw cyclus::ValueError(ss.str());
55 } else if (n_build.size() != n) {
56 std::stringstream ss;
57 ss << "prototype '" << prototype() << "' has " << n_build.size()
58 << " n_build vals, expected " << n;
59 throw cyclus::ValueError(ss.str());
60 } else if (lifetimes.size() > 0 && lifetimes.size() != n) {
61 std::stringstream ss;
62 ss << "prototype '" << prototype() << "' has " << lifetimes.size()
63 << " lifetimes vals, expected " << n;
64 throw cyclus::ValueError(ss.str());
65 }
66
67 InitializePosition();
68}
69
71 Register_(a);
72}
73
75 Unregister_(a);
76}
77
78void DeployInst::Register_(Agent* a) {
79 using cyclus::toolkit::CommodityProducer;
80 using cyclus::toolkit::CommodityProducerManager;
81
82 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
83 if (cp_cast != NULL) {
84 LOG(cyclus::LEV_INFO3, "mani") << "Registering agent "
85 << a->prototype() << a->id()
86 << " as a commodity producer.";
87 CommodityProducerManager::Register(cp_cast);
88 }
89}
90
91void DeployInst::Unregister_(Agent* a) {
92 using cyclus::toolkit::CommodityProducer;
93 using cyclus::toolkit::CommodityProducerManager;
94
95 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
96 if (cp_cast != NULL)
97 CommodityProducerManager::Unregister(cp_cast);
98}
99
100// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
102 cyclus::toolkit::CommodityProducer* producer) {
103 using std::set;
104 set<cyclus::toolkit::Commodity,
105 cyclus::toolkit::CommodityCompare> commodities =
106 producer->ProducedCommodities();
107 set<cyclus::toolkit::Commodity, cyclus::toolkit::CommodityCompare>::
108 iterator it;
109
110 LOG(cyclus::LEV_DEBUG3, "maninst") << " Clone produces " << commodities.size()
111 << " commodities.";
112 for (it = commodities.begin(); it != commodities.end(); it++) {
113 LOG(cyclus::LEV_DEBUG3, "maninst") << " Commodity produced: " << it->name();
114 LOG(cyclus::LEV_DEBUG3, "maninst") << " capacity: " <<
115 producer->Capacity(*it);
116 LOG(cyclus::LEV_DEBUG3, "maninst") << " cost: " <<
117 producer->Cost(*it);
118 }
119}
120
121extern "C" cyclus::Agent* ConstructDeployInst(cyclus::Context* ctx) {
122 return new DeployInst(ctx);
123}
124
125} // 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
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)