CYCLUS
Loading...
Searching...
No Matches
res_tracker.cc
Go to the documentation of this file.
1#include "res_tracker.h"
2
3#include "recorder.h"
4#include "cyc_limits.h"
5
6namespace cyclus {
7
9 : tracked_(true),
10 res_(r),
11 ctx_(ctx),
12 parent1_(0),
13 parent2_(0) {}
14
16 tracked_ = false;
17}
18
20 if (!tracked_) {
21 return;
22 }
23
24 parent1_ = 0;
25 parent2_ = 0;
26 bool bumpId = false;
27 Record(bumpId);
28 ctx_->NewDatum("ResCreators")
29 ->AddVal("ResourceId", res_->state_id())
30 ->AddVal("AgentId", creator->id())
31 ->Record();
32}
33
35 if (!tracked_) {
36 return;
37 }
38
39 parent1_ = res_->state_id();
40 parent2_ = 0;
41 Record();
42}
43
45 if (!tracked_) {
46 return;
47 }
48
49 if (res_->quantity() > eps_rsrc()) {
50 parent1_ = res_->state_id();
51 parent2_ = 0;
52 }
53
54 // removed parent must be set before the resource is recorded, otherwise
55 // removed ends up with parent1 of the other child (which is this resource
56 // after being bumped)
57 removed->parent1_ = res_->state_id();
58 removed->parent2_ = 0;
59 removed->tracked_ = tracked_;
60 removed->Record();
61
62 if (res_->quantity() > eps_rsrc()) {
63 Record();
64 }
65}
66
68 if (!tracked_) {
69 return;
70 }
71
72 parent1_ = res_->state_id();
73 parent2_ = absorbed->res_->state_id();
74 Record();
75}
76
78 if (!tracked_) {
79 return;
80 }
81 parent2_ = 0;
82 tracked_ = tracked_;
83 package_name_ = res_->package_name();
84
85 if (parent != NULL) {
86 parent1_ = parent->res_->state_id();
87
88 // Resource was just created, with packaging info, and assigned a state id.
89 // Do not need to bump again
90 bool bumpId = false;
91 Record(bumpId);
92 } else {
93 // Resource was not just created. It is being re-packaged. It needs to be
94 // bumped to get a new state id.
95 parent1_ = res_->state_id();
96 Record();
97 }
98
99
100
101}
102
103void ResTracker::Record(bool bumpId) {
104 if (bumpId) {
105 res_->BumpStateId();
106 }
107 ctx_->NewDatum("Resources")
108 ->AddVal("ResourceId", res_->state_id())
109 ->AddVal("ObjId", res_->obj_id())
110 ->AddVal("Type", res_->type())
111 ->AddVal("TimeCreated", ctx_->time())
112 ->AddVal("Quantity", res_->quantity())
113 ->AddVal("Units", res_->units())
114 ->AddVal("QualId", res_->qual_id())
115 ->AddVal("PackageName", res_->package_name())
116 ->AddVal("Parent1", parent1_)
117 ->AddVal("Parent2", parent2_)
118 ->Record();
119 res_->Record(ctx_);
120}
121
122} // namespace cyclus
The abstract base class used by all types of agents that live and interact in a simulation.
Definition agent.h:49
A simulation context provides access to necessary simulation-global functions and state.
Definition context.h:145
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
Definition context.cc:351
virtual int time()
Returns the current simulation timestep.
Definition context.cc:313
Datum * AddVal(const char *field, boost::spirit::hold_any val, std::vector< int > *shape=NULL)
Add an arbitrary field-value pair to the datum.
Definition datum.cc:22
void Record()
Record this datum to its Recorder.
Definition datum.cc:35
Tracks and records the state and parent-child relationships of resources as they are changed.
Definition res_tracker.h:21
void Create(Agent *creator)
Should be called when a resource instance is newly created.
void Modify()
Should be called when the state of a resource changes (e.g.
void Extract(ResTracker *removed)
Should be called when a resource has some quantity removed from it (e.g.
void Package(ResTracker *parent=NULL)
Should be called when a resource's package gets modified.
void Absorb(ResTracker *absorbed)
Should be called when a resource is combined with another.
ResTracker(Context *ctx, Resource *r)
Create a new tracker following r.
Definition res_tracker.cc:8
void DontTrack()
Prevent a resource's heritage from being tracked and recorded.
Resource defines an abstract interface implemented by types that are offered, requested,...
Definition resource.h:22
const int state_id() const
Returns the unique id corresponding to this resource and its current state.
Definition resource.h:42
virtual const ResourceType type() const =0
A unique type/name for the concrete resource implementation.
virtual std::string units() const =0
Returns the units this resource is based in (e.g. "kg").
virtual void Record(Context *ctx) const =0
Records the resource's state to the output database.
virtual double quantity() const =0
Returns the quantity of this resource with dimensions as specified by the return value of units().
const int obj_id() const
Returns the unique id corresponding to this resource object.
Definition resource.h:36
virtual std::string package_name()
Returns the package id.
Definition resource.h:96
void BumpStateId()
Assigns a new, unique internal id to this resource and its state.
Definition resource.cc:8
virtual int qual_id() const =0
Returns an id representing the specific resource implementation's internal state that is not accessib...
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
double eps_rsrc()
an epsilon value to be used by resources
Definition cyc_limits.h:19
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters