CYCLUS
Loading...
Searching...
No Matches
recorder.cc
Go to the documentation of this file.
1#include "recorder.h"
2
3#include <boost/uuid/uuid_generators.hpp>
4#include <boost/uuid/uuid_io.hpp>
5#include <boost/lexical_cast.hpp>
6
7#include "datum.h"
8#include "logger.h"
9#include "rec_backend.h"
10
11namespace cyclus {
12
13Recorder::Recorder() : index_(0), inject_sim_id_(true) {
14 uuid_ = boost::uuids::random_generator()();
16}
17
18Recorder::Recorder(bool inject_sim_id) : index_(0), inject_sim_id_(inject_sim_id) {
19 uuid_ = boost::uuids::random_generator()();
21}
22
23Recorder::Recorder(unsigned int dump_count) : index_(0), inject_sim_id_(true) {
24 uuid_ = boost::uuids::random_generator()();
26}
27
28Recorder::Recorder(boost::uuids::uuid simid) : index_(0), uuid_(simid), \
29 inject_sim_id_(true) {
31}
32
34 try {
35 Flush();
36 } catch (Error err) {
37 CLOG(LEV_ERROR) << "Error in Recorder destructor: " << err.what();
38 }
39
40 for (int i = 0; i < data_.size(); ++i) {
41 delete data_[i];
42 }
43}
44
45unsigned int Recorder::dump_count() {
46 return dump_count_;
47}
48
49boost::uuids::uuid Recorder::sim_id() {
50 return uuid_;
51}
52
53void Recorder::set_dump_count(unsigned int count) {
54 for (int i = 0; i < data_.size(); ++i) {
55 delete data_[i];
56 }
57 data_.clear();
58 data_.reserve(count);
59 for (int i = 0; i < count; ++i) {
60 Datum* d = new Datum(this, "");
61 if (inject_sim_id_) {
62 d->AddVal("SimId", uuid_);
63 }
64 data_.push_back(d);
65 }
66 dump_count_ = count;
67}
68
69Datum* Recorder::NewDatum(std::string title) {
70 Datum* d = data_[index_];
71 d->title_ = title;
72 if (inject_sim_id_) {
73 d->vals_.resize(1);
74 d->shapes_.resize(1);
75 d->fields_.resize(1);
76 } else {
77 d->vals_.resize(0);
78 d->shapes_.resize(0);
79 d->fields_.resize(0);
80 }
81
82 index_++;
83 return d;
84}
85
86void Recorder::AddDatum(Datum* d) {
87 if (index_ >= data_.size()) {
88 NotifyBackends();
89 }
90}
91
93 if (index_ == 0)
94 return;
95 DatumList tmp = data_;
96 tmp.resize(index_);
97 index_ = 0;
98 std::list<RecBackend*>::iterator it;
99 for (it = backs_.begin(); it != backs_.end(); it++) {
100 (*it)->Notify(tmp);
101 (*it)->Flush();
102 }
103}
104
105void Recorder::NotifyBackends() {
106 index_ = 0;
107 std::list<RecBackend*>::iterator it;
108 for (it = backs_.begin(); it != backs_.end(); it++) {
109 (*it)->Notify(data_);
110 }
111}
112
114 backs_.push_back(b);
115}
116
118 Flush();
119 backs_.clear();
120}
121
122} // namespace cyclus
Used to specify and send a collection of key-value pairs to the Recorder for recording.
Definition datum.h:15
A generic mechanism to manually manage exceptions.
Definition error.h:12
An abstract base class for listeners (e.g.
Definition rec_backend.h:16
friend class Datum
Definition recorder.h:46
void RegisterBackend(RecBackend *b)
Registers b to receive Datum notifications for all Datum objects collected by the Recorder and to rec...
Definition recorder.cc:113
boost::uuids::uuid sim_id()
returns the unique id associated with this cyclus simulation.
Definition recorder.cc:49
void set_dump_count(unsigned int count)
set the Recorder to flush its collected Datum objects to registered backends every [count] Datum obje...
Definition recorder.cc:53
void Flush()
Flushes all buffered Datum objects and flushes all registered backends.
Definition recorder.cc:92
unsigned int dump_count()
Return the dump frequency, # Datum objects buffered between flushes to backends.
Definition recorder.cc:45
Datum * NewDatum(std::string title)
Creates a new datum namespaced under the specified title.
Definition recorder.cc:69
Recorder()
create a new recorder with default dump frequency, random simulation id, and simulation id injection.
Definition recorder.cc:13
void Close()
Flushes all buffered Datum objects and flushes all registered backends.
Definition recorder.cc:117
Code providing rudimentary logging capability for the Cyclus core.
#define CLOG(level)
Definition logger.h:39
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
static unsigned int const kDefaultDumpCount
default number of Datum objects to collect before flushing to backends.
Definition recorder.h:21
std::vector< Datum * > DatumList
Definition rec_backend.h:12
@ LEV_ERROR
Use for errors that require agent code or input file modification (use extremely sparingly)
Definition logger.h:51
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters