Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
DBMemento.cpp
Go to the documentation of this file.
1#include "DBMemento.h"
2
3void DBMemento::takeSnapshot(std::shared_ptr<BlockAccessor> blocks) {
4 snapshots.push(blocks);
5}
6
7void DBMemento::restore(size_t n) {
8 auto head = snapshots.top();
9 snapshots.pop();
10
11 for (size_t i = 0; i < n - 1; i++)
12 snapshots.pop();
13
14 auto source = snapshots.top();
15 snapshots.pop();
16 DBMemento::Overwrite(head, source);
17 snapshots.push(head);
18}
19
21 if (n > snapshots.size() - 1) {
22 LOG_ERROR("LogicError", "Please specify an existing snapshot (only", snapshots.size(), "stored, asked", n);
23 }
24
25 std::stack<std::shared_ptr<BlockAccessor>> temp;
26 for (size_t i = 0; i < n; i++) {
27 temp.push(snapshots.top());
28 snapshots.pop();
29 }
30
31 LOG_INFO(snapshots.top());
32
33 for (size_t i = 0; i < n; i++) {
34 snapshots.push(temp.top());
35 temp.pop();
36 }
37}
38
40 return snapshots.size();
41}
42
43void DBMemento::Overwrite(std::shared_ptr<BlockAccessor> &reciever, std::shared_ptr<BlockAccessor> source) {
44 for (const auto& block_name : reciever->get_block_names()) {
45 if (!source->contains(block_name)) {
46 reciever->erase_block(block_name);
47 continue;
48 }
49 for (const auto& id : reciever->at(block_name)->getAllIDs()) {
50 if (!source->has_param(block_name, id)) {
51 reciever->remove_item(block_name, id);
52 } else {
53 reciever->remove_item(block_name, id);
54 reciever->setParameter(block_name, id, source->getParameter(block_name, id));
55 }
56 }
57 }
58}
Concrete memento for BlockAccessor snapshots.
#define LOG_ERROR(type,...)
Macro for logging error messages and terminating the application.
Definition Logger.h:41
#define LOG_INFO(...)
Macro for logging informational messages.
Definition Logger.h:39
size_t stack_size()
Returns the number of snapshots currently stored.
Definition DBMemento.cpp:39
void print_snapshot_content(size_t n=0)
Prints the content of a stored snapshot.
Definition DBMemento.cpp:20
void takeSnapshot(std::shared_ptr< BlockAccessor > blocks)
Takes a snapshot of the given BlockAccessor.
Definition DBMemento.cpp:3
void restore(size_t n_steps=1)
Restores the state n_steps snapshots back.
Definition DBMemento.cpp:7