CYCAMORE
Loading...
Searching...
No Matches
build/cycamore/manager_inst.cc
Go to the documentation of this file.
1#line 1 "/cycamore/src/manager_inst.cc"
2// Implements the ManagerInst class
3#include "manager_inst.h"
4
5namespace cycamore {
6
7// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8ManagerInst::ManagerInst(cyclus::Context* ctx)
9 : cyclus::Institution(ctx),
10 latitude(0.0),
11 longitude(0.0),
13
14// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
16
18 Register_(a);
19}
20
22 Unregister_(a);
23}
24
26 cyclus::Institution::EnterNotify();
27 std::set<cyclus::Agent*>::iterator sit;
28 for (sit = cyclus::Agent::children().begin();
29 sit != cyclus::Agent::children().end();
30 ++sit) {
31 Agent* a = *sit;
32 Register_(a);
33 }
34
35 using cyclus::toolkit::CommodityProducer;
36 std::vector<std::string>::iterator vit;
37 for (vit = prototypes.begin(); vit != prototypes.end(); ++vit) {
38 Agent* a = context()->CreateAgent<Agent>(*vit);
39 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
40 if (cp_cast != NULL) {
41 LOG(cyclus::LEV_INFO3, "mani") << "Registering prototype "
42 << a->prototype() << a->id()
43 << " with the Builder interface.";
44 Builder::Register(cp_cast);
45 }
46 }
48}
49
50void ManagerInst::Register_(Agent* a) {
51 using cyclus::toolkit::CommodityProducer;
52 using cyclus::toolkit::CommodityProducerManager;
53
54 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
55 if (cp_cast != NULL) {
56 LOG(cyclus::LEV_INFO3, "mani") << "Registering agent "
57 << a->prototype() << a->id()
58 << " as a commodity producer.";
59 CommodityProducerManager::Register(cp_cast);
60 }
61}
62
63void ManagerInst::Unregister_(Agent* a) {
64 using cyclus::toolkit::CommodityProducer;
65 using cyclus::toolkit::CommodityProducerManager;
66
67 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
68 if (cp_cast != NULL)
69 CommodityProducerManager::Unregister(cp_cast);
70}
71
72// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
74 cyclus::toolkit::CommodityProducer* producer) {
75 using std::set;
76 set<cyclus::toolkit::Commodity,
77 cyclus::toolkit::CommodityCompare> commodities =
78 producer->ProducedCommodities();
79 set<cyclus::toolkit::Commodity, cyclus::toolkit::CommodityCompare>::
80 iterator it;
81
82 LOG(cyclus::LEV_DEBUG3, "maninst") << " Clone produces " << commodities.size()
83 << " commodities.";
84 for (it = commodities.begin(); it != commodities.end(); it++) {
85 LOG(cyclus::LEV_DEBUG3, "maninst") << " Commodity produced: " << it->name();
86 LOG(cyclus::LEV_DEBUG3, "maninst") << " capacity: " <<
87 producer->Capacity(*it);
88 LOG(cyclus::LEV_DEBUG3, "maninst") << " cost: " <<
89 producer->Cost(*it);
90 }
91}
92
94 std::string specification = this->spec();
95 context()
96 ->NewDatum("AgentPosition")
97 ->AddVal("Spec", specification)
98 ->AddVal("Prototype", this->prototype())
99 ->AddVal("AgentId", id())
100 ->AddVal("Latitude", latitude)
101 ->AddVal("Longitude", longitude)
102 ->Record();
103}
104
105// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
106extern "C" cyclus::Agent* ConstructManagerInst(cyclus::Context* ctx) {
107 return new ManagerInst(ctx);
108}
109
110} // namespace cycamore
void Register_(cyclus::Agent *agent)
register a child
virtual void EnterNotify()
enter the simulation and register any children present
virtual ~ManagerInst()
Default destructor.
virtual void DecomNotify(Agent *m)
unregister a child
void WriteProducerInformation(cyclus::toolkit::CommodityProducer *producer)
write information about a commodity producer to a stream
virtual void BuildNotify(Agent *m)
register a new child
void Unregister_(cyclus::Agent *agent)
unregister a child
void RecordPosition()
Records an agent's latitude and longitude to the output db.
std::vector< std::string > prototypes
ManagerInst(cyclus::Context *ctx)
Default constructor.
cyclus::Agent * ConstructManagerInst(cyclus::Context *ctx)
cyclus::toolkit::Position coordinates