Skip to content

Commit

Permalink
bump state id only if resource is not new, if new it already has a ne…
Browse files Browse the repository at this point in the history
…w stateid
  • Loading branch information
nuclearkatie committed Sep 10, 2024
1 parent 14aea99 commit 7335591
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ Resource::Ptr Material::PackageExtract(double qty, std::string new_package_name)
// this material regardless of composition.
other->prev_decay_time_ = prev_decay_time_;

tracker_.Extract(&other->tracker_);
// this call to res_tracker must come first before the parent resource
// state id gets modified
other->tracker_.Package(&tracker_);
if (qty_ > cyclus::eps_rsrc()) {
tracker_.Modify();
}
return boost::static_pointer_cast<Resource>(other);
}

Expand Down
8 changes: 7 additions & 1 deletion src/product.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "error.h"
#include "logger.h"
#include "cyc_limits.h"

namespace cyclus {

Expand Down Expand Up @@ -84,7 +85,12 @@ Resource::Ptr Product::PackageExtract(double qty, std::string new_package_name)
quantity_ -= qty;
Product::Ptr other(new Product(ctx_, qty, quality_, new_package_name));

tracker_.Extract(&other->tracker_);
// this call to res_tracker must come first before the parent resource
// state id gets modified
other->tracker_.Package(&tracker_);
if (quantity_ > cyclus::eps_rsrc()) {
tracker_.Modify();
}
return boost::static_pointer_cast<Resource>(other);
}

Expand Down
32 changes: 26 additions & 6 deletions src/res_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ void ResTracker::Create(Agent* creator) {

parent1_ = 0;
parent2_ = 0;
Record();
bool no_bump = true;
Record(no_bump);
ctx_->NewDatum("ResCreators")
->AddVal("ResourceId", res_->state_id())
->AddVal("AgentId", creator->id())
Expand Down Expand Up @@ -69,17 +70,36 @@ void ResTracker::Absorb(ResTracker* absorbed) {
Record();
}

void ResTracker::Package() {
void ResTracker::Package(ResTracker* parent) {
if (!tracked_) {
return;
}

parent2_ = 0;
tracked_ = tracked_;
package_name_ = res_->package_name();
Record();

if (parent != NULL) {
parent1_ = parent->res_->state_id();

// Resource was just created, with packaging info, and assigned a state id.
// Do not need to bump again
bool no_bump = true;
Record(no_bump);
} else {
// Resource was not just created. It is being re-packaged. It needs to be
// bumped to get a new state id.
parent1_ = res_->state_id();
Record();
}



}

void ResTracker::Record() {
res_->BumpStateId();
void ResTracker::Record(bool no_bump) {
if (!no_bump) {
res_->BumpStateId();
}
ctx_->NewDatum("Resources")
->AddVal("ResourceId", res_->state_id())
->AddVal("ObjId", res_->obj_id())
Expand Down
9 changes: 6 additions & 3 deletions src/res_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ class ResTracker {
/// decay).
void Modify();

/// Should be called when a resource's package gets modified
void Package();
/// Should be called when a resource's package gets modified. If the resource
/// was just created from a parent resource, the parent should be passed in.
/// If the resource is just being repackaged (e.g. to unpackaged), the parent
/// should be NULL.
void Package(ResTracker* parent = NULL);

private:
void Record();
void Record(bool no_bump = false);

int parent1_;
int parent2_;
Expand Down

0 comments on commit 7335591

Please sign in to comment.