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
19 : index_(0), inject_sim_id_(inject_sim_id) {
20 uuid_ = boost::uuids::random_generator()();
22}
23
24Recorder::Recorder(unsigned int dump_count) : index_(0), inject_sim_id_(true) {
25 uuid_ = boost::uuids::random_generator()();
27}
28
29Recorder::Recorder(boost::uuids::uuid simid)
30 : index_(0), uuid_(simid), inject_sim_id_(true) {
32}
33
35 try {
36 Flush();
37 } catch (Error err) {
38 CLOG(LEV_ERROR) << "Error in Recorder destructor: " << err.what();
39 }
40
41 for (int i = 0; i < data_.size(); ++i) {
42 delete data_[i];
43 }
44}
45
46unsigned int Recorder::dump_count() {
47 return dump_count_;
48}
49
50boost::uuids::uuid Recorder::sim_id() {
51 return uuid_;
52}
53
54void Recorder::set_dump_count(unsigned int count) {
55 for (int i = 0; i < data_.size(); ++i) {
56 delete data_[i];
57 }
58 data_.clear();
59 data_.reserve(count);
60 for (int i = 0; i < count; ++i) {
61 Datum* d = new Datum(this, "");
62 if (inject_sim_id_) {
63 d->AddVal("SimId", uuid_);
64 }
65 data_.push_back(d);
66 }
67 dump_count_ = count;
68}
69
70Datum* Recorder::NewDatum(std::string title) {
71 Datum* d = data_[index_];
72 d->title_ = title;
73 if (inject_sim_id_) {
74 d->vals_.resize(1);
75 d->shapes_.resize(1);
76 d->fields_.resize(1);
77 } else {
78 d->vals_.resize(0);
79 d->shapes_.resize(0);
80 d->fields_.resize(0);
81 }
82
83 index_++;
84 return d;
85}
86
87void Recorder::AddDatum(Datum* d) {
88 if (index_ >= data_.size()) {
89 NotifyBackends();
90 }
91}
92
94 if (index_ == 0) 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
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:21
A generic mechanism to manually manage exceptions.
Definition error.h:12
virtual const char * what() const
Returns the error message associated with this Error.
Definition error.cc:9
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:50
bool inject_sim_id()
returns whether or not the unique simulation id will be injected.
Definition recorder.h:83
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:54
void Flush()
Flushes all buffered Datum objects and flushes all registered backends.
Definition recorder.cc:93
unsigned int dump_count()
Return the dump frequency, # Datum objects buffered between flushes to backends.
Definition recorder.cc:46
Datum * NewDatum(std::string title)
Creates a new datum namespaced under the specified title.
Definition recorder.cc:70
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:40
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:56