CYCLUS
Loading...
Searching...
No Matches
recorder.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_RECORDER_H_
2#define CYCLUS_SRC_RECORDER_H_
3
4#include <list>
5#include <string>
6#include <vector>
7#include <boost/uuid/uuid.hpp>
8#include <boost/uuid/uuid_io.hpp>
9
10#include "error.h"
11
12namespace cyclus {
13
14class Datum;
15class Recorder;
16class RecBackend;
17
18typedef std::vector<Datum*> DatumList;
19
20/// default number of Datum objects to collect before flushing to backends.
21static unsigned int const kDefaultDumpCount = 10000;
22
23/// Collects and manages output data generation for the cyclus core and agents
24/// during a simulation. By default, datum managers are auto-initialized with a
25/// unique uuid simulation id.
26///
27/// Example usage:
28///
29/// @code
30///
31/// Recorder* manager = new Recorder();
32/// CustomBackend* myback = new CustomBackend();
33/// manager->RegisterBackend(myback);
34/// ...
35/// ...
36/// manager->NewDatum("CapacityFactor");
37/// ->AddVal("Name", aname)
38/// ->AddVal("Capacity", cap)
39/// ->Record();
40/// ...
41/// ...
42/// manager->Close();
43///
44/// @endcode
45class Recorder {
46 friend class Datum;
47
48 public:
49 /// create a new recorder with default dump frequency, random
50 /// simulation id, and simulation id injection.
51 Recorder();
52
53 /// create a new recorder with the given dump count, random
54 /// simulation id, and given flag for injecting the simulation id.
56
57 /// create a new recorder with the given dump count and random
58 /// simulation id.
59 Recorder(unsigned int dump_count);
60
61 /// create a new recorder with default dump frequency. the specified
62 /// simulation id, and simulation id injection.
63 Recorder(boost::uuids::uuid simid);
64
65 ~Recorder();
66
67 /// Return the dump frequency, # Datum objects buffered between flushes to
68 /// backends.
69 unsigned int dump_count();
70
71 /// set the Recorder to flush its collected Datum objects to registered
72 /// backends every [count] Datum objects. If count == 0 then Datum objects
73 /// will be flushed immediately as they come.
74 ///
75 /// @param count # Datum objects to buffer before flushing to backends.
76 /// @warning this deletes all buffered data from the recorder.
77 void set_dump_count(unsigned int count);
78
79 /// returns the unique id associated with this cyclus simulation.
80 boost::uuids::uuid sim_id();
81
82 /// returns whether or not the unique simulation id will be injected.
83 bool inject_sim_id() { return inject_sim_id_; };
84
85 /// sets whether or not the unique simulation id will be injected.
86 void inject_sim_id(bool x) {
87 if (x == inject_sim_id_) {
88 return;
89 }
90 Flush();
91 inject_sim_id_ = x;
92 set_dump_count(dump_count_);
93 };
94
95 /// Creates a new datum namespaced under the specified title.
96 ///
97 /// @warning choose title carefully to not conflict with Datum objects from other
98 /// agents. Also note that a static title (e.g. an unchanging string) will
99 /// result in multiple instances of this agent storing datum data together
100 /// (e.g. the same table).
101 Datum* NewDatum(std::string title);
102
103 /// Registers b to receive Datum notifications for all Datum objects collected
104 /// by the Recorder and to receive a flush notification when there
105 /// are no more Datum objects.
106 ///
107 /// @param b backend to receive Datum objects
109
110 /// Flushes all buffered Datum objects and flushes all registered backends.
111 void Flush();
112
113 /// Flushes all buffered Datum objects and flushes all registered backends.
114 /// Unregisters all backends and resets.
115 void Close();
116
117 private:
118 void NotifyBackends();
119 void AddDatum(Datum* d);
120
121 DatumList data_;
122 int index_;
123 std::list<RecBackend*> backs_;
124 unsigned int dump_count_;
125 boost::uuids::uuid uuid_;
126 bool inject_sim_id_;
127};
128
129} // namespace cyclus
130
131// this allows files to use Datum objects without having to explicitly include
132// both recorder.h and datum.h, while avoiding a circular include
133// dependency.
134#include "datum.h"
135
136#endif // CYCLUS_SRC_RECORDER_H_
Used to specify and send a collection of key-value pairs to the Recorder for recording.
Definition datum.h:15
An abstract base class for listeners (e.g.
Definition rec_backend.h:16
Collects and manages output data generation for the cyclus core and agents during a simulation.
Definition recorder.h:45
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
void inject_sim_id(bool x)
sets whether or not the unique simulation id will be injected.
Definition recorder.h:86
boost::uuids::uuid sim_id()
returns the unique id associated with this cyclus simulation.
Definition recorder.cc:49
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: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
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
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters