summaryrefslogtreecommitdiff
path: root/core/replay.cpp
diff options
context:
space:
mode:
authorJan Huwald <jh@sotun.de>2012-05-07 20:01:51 (GMT)
committerJan Huwald <jh@sotun.de>2012-05-07 20:01:51 (GMT)
commit420d2ef464d4a741028e132e662d5626806a41f5 (patch)
tree1aca6eb512e4ed0fb5f3c10c528cb998b6ffd695 /core/replay.cpp
Initial commitHEADmaster
Diffstat (limited to 'core/replay.cpp')
-rw-r--r--core/replay.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/core/replay.cpp b/core/replay.cpp
new file mode 100644
index 0000000..73f0c44
--- /dev/null
+++ b/core/replay.cpp
@@ -0,0 +1,99 @@
+#include <assert.h>
+#include <errno.h>
+#include <iostream>
+#include <stdlib.h>
+
+#include <boost/type_traits/is_same.hpp>
+
+#include "everything_else.hpp"
+#include "pla_getbyname.hpp"
+#include "sim_replay.hpp"
+#include "system_helpers.hpp"
+#include "template_helpers.hpp"
+#include "time.hpp"
+
+#include "model.hpp"
+
+using namespace std;
+
+template<typename Prop, typename QuantClass = typename Prop::quant::class_t>
+struct Replay;
+
+template<>
+struct Replay<BaseCase, Void> {
+ virtual void operator() (TimeSpan span, IdList<uint64_t> &ids) {
+ assert(false);
+ }
+};
+
+template<typename Prop>
+struct Replay<Prop, ContinuousPropertyClass> : Replay<BaseCase, Void> {
+ typedef typename Prop::quant Quant;
+
+ virtual void operator() (TimeSpan span, IdList<uint64_t> &raw_ids) {
+ IdList<typename Quant::instance_ptr_t::ptr_t> ids(raw_ids);
+ for (auto i : ids)
+ assert(i < Ptr<Quant>::numInstances());
+ SimReplay<Lists::all_ro, Quant> simReplay{ids, span.begin()()};
+
+ // header
+ cout << "# " << Quant::name << "\n# time";
+ for (auto i : ids)
+ cout << "\t" << (uint64_t) i;
+ cout << endl;
+
+ // body
+ for (TimeSpan::iterator t=span.begin(); t.hasNext(); ++t) {
+ cout << t()();
+ for (auto i : ids)
+ cout << "\t" << simReplay.template get<Prop>(Ptr<Quant>(i), t());
+ cout << endl;
+ }
+ }
+};
+
+template<typename Prop>
+struct Replay<Prop, DiscretePropertyClass> : Replay<BaseCase, Void> {
+ virtual void operator() (TimeSpan span, IdList<uint64_t> &raw_ids) {
+ cerr << Prop::name << " is a discrete property" << endl;
+ exit(-1);
+ }
+};
+
+int realmain(int argc, char **argv) __attribute__((noinline));
+int realmain(int argc, char **argv) {
+ if (argc != 6) {
+ cout << "Usage: " << argv[0] << " property instance start stop delta" << endl;
+ return -1;
+ }
+
+ garantueeStackSize(64 * 1024 * 1024);
+
+ // read cmd line params
+ Replay<BaseCase, Void> *replay(NULL);
+ {
+ PropertyComposition<Lists::all_ro> pc;
+ PLA_GetByName<Replay> pla(argv[1]);
+ replay = pc.call(pla);
+ assert(replay != NULL);
+ }
+ errno = 0;
+ char *tail;
+ IdList<uint64_t> ids(argv[2]);
+ Time start(strtod(argv[3], &tail)); assert(*tail == 0);
+ Time stop( strtod(argv[4], &tail)); assert(*tail == 0);
+ Time delta(strtod(argv[5], &tail)); assert(*tail == 0);
+ assert(errno == 0);
+ TimeSpan span(start, stop, delta);
+
+ // replay simulation
+ (*replay)(span, ids);
+
+ return 0;
+}
+
+int main(int argc, char **argv) {
+ garantueeStackSize(64 * 1024 * 1024);
+ assertSimDir();
+ return realmain(argc, argv);
+}
contact: Jan Huwald // Impressum