CYCLUS
res_tracker.cc
Go to the documentation of this file.
1 #include "res_tracker.h"
2 
3 #include "recorder.h"
4 
5 namespace cyclus {
6 
8  : tracked_(true),
9  res_(r),
10  ctx_(ctx),
11  parent1_(0),
12  parent2_(0) {}
13 
15  tracked_ = false;
16 }
17 
18 void ResTracker::Create(Agent* creator) {
19  if (!tracked_) {
20  return;
21  }
22 
23  parent1_ = 0;
24  parent2_ = 0;
25  Record();
26  ctx_->NewDatum("ResCreators")
27  ->AddVal("ResourceId", res_->state_id())
28  ->AddVal("AgentId", creator->id())
29  ->Record();
30 }
31 
33  if (!tracked_) {
34  return;
35  }
36 
37  parent1_ = res_->state_id();
38  parent2_ = 0;
39  Record();
40 }
41 
43  if (!tracked_) {
44  return;
45  }
46 
47  parent1_ = res_->state_id();
48  parent2_ = 0;
49  removed->parent1_ = res_->state_id();
50  removed->parent2_ = 0;
51  removed->tracked_ = tracked_;
52 
53  Record();
54  removed->Record();
55 }
56 
57 void ResTracker::Absorb(ResTracker* absorbed) {
58  if (!tracked_) {
59  return;
60  }
61 
62  parent1_ = res_->state_id();
63  parent2_ = absorbed->res_->state_id();
64  Record();
65 }
66 
67 void ResTracker::Record() {
68  res_->BumpStateId();
69  ctx_->NewDatum("Resources")
70  ->AddVal("ResourceId", res_->state_id())
71  ->AddVal("ObjId", res_->obj_id())
72  ->AddVal("Type", res_->type())
73  ->AddVal("TimeCreated", ctx_->time())
74  ->AddVal("Quantity", res_->quantity())
75  ->AddVal("Units", res_->units())
76  ->AddVal("QualId", res_->qual_id())
77  ->AddVal("Parent1", parent1_)
78  ->AddVal("Parent2", parent2_)
79  ->Record();
80 
81  res_->Record(ctx_);
82 }
83 
84 } // namespace cyclus
void Absorb(ResTracker *absorbed)
Should be called when a resource is combined with another.
Definition: res_tracker.cc:57
virtual const ResourceType type() const =0
A unique type/name for the concrete resource implementation.
void Create(Agent *creator)
Should be called when a resource instance is newly created.
Definition: res_tracker.cc:18
virtual int qual_id() const =0
Returns an id representing the specific resource implementation's internal state that is not accessib...
virtual double quantity() const =0
Returns the quantity of this resource with dimensions as specified by the return value of units()...
Tracks and records the state and parent-child relationships of resources as they are changed...
Definition: res_tracker.h:22
virtual std::string units() const =0
Returns the units this resource is based in (e.g. "kg").
Resource defines an abstract interface implemented by types that are offered, requested, and transferred between simulation agents.
Definition: resource.h:19
virtual int time()
Returns the current simulation timestep.
Definition: context.cc:225
void DontTrack()
Prevent a resource's heritage from being tracked and recorded.
Definition: res_tracker.cc:14
void BumpStateId()
Assigns a new, unique internal id to this resource and its state.
Definition: resource.cc:8
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:12
void Modify()
Should be called when the state of a resource changes (e.g.
Definition: res_tracker.cc:32
const int obj_id() const
Returns the unique id corresponding to this resource object.
Definition: resource.h:33
void Extract(ResTracker *removed)
Should be called when a resource has some quantity removed from it (e.g.
Definition: res_tracker.cc:42
A simulation context provides access to necessary simulation-global functions and state...
Definition: context.h:128
The abstract base class used by all types of agents that live and interact in a simulation.
Definition: agent.h:51
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
void Record()
Record this datum to its Recorder.
Definition: datum.cc:24
virtual const int id() const
The agent instance&#39;s unique ID within a simulation.
Definition: agent.h:354
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
Definition: context.cc:237
const int state_id() const
Returns the unique id corresponding to this resource and its current state.
Definition: resource.h:39
virtual void Record(Context *ctx) const =0
Records the resource&#39;s state to the output database.
ResTracker(Context *ctx, Resource *r)
Create a new tracker following r.
Definition: res_tracker.cc:7