diff options
author | Jan Huwald <jh@sotun.de> | 2012-05-07 20:01:51 (GMT) |
---|---|---|
committer | Jan Huwald <jh@sotun.de> | 2012-05-07 20:01:51 (GMT) |
commit | 420d2ef464d4a741028e132e662d5626806a41f5 (patch) | |
tree | 1aca6eb512e4ed0fb5f3c10c528cb998b6ffd695 /core/coarse_replay.cpp |
Diffstat (limited to 'core/coarse_replay.cpp')
-rw-r--r-- | core/coarse_replay.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/core/coarse_replay.cpp b/core/coarse_replay.cpp new file mode 100644 index 0000000..24412cc --- /dev/null +++ b/core/coarse_replay.cpp @@ -0,0 +1,89 @@ +#include <assert.h> +#include <errno.h> +#include <iostream> +#include <stdlib.h> + +#include <boost/type_traits/is_same.hpp> + +#include "everything_else.hpp" +#include "id_list.hpp" +#include "time.hpp" +#include "template_helpers.hpp" +#include "pla_getbyname.hpp" +#include "property_composition.hpp" + +#include "model.hpp" + +#include "mempool.hpp" + +using namespace std; + +template<typename Prop, typename QuantClass = typename Prop::quant::class_t> +struct CoarseReplay; + +// define base case with virtual op() to runtime dispatch call by property name +template<> +struct CoarseReplay<BaseCase, Void> { + virtual void operator() (Time start, Time stop, IdList<uint64_t> rawIds) { + assert(false); + } +}; + +template<typename Prop> +struct CoarseReplay<Prop, ContinuousPropertyClass> : CoarseReplay<BaseCase, Void> { + virtual void operator() (Time start, Time stop, + IdList<uint64_t> rawIds) { + IdList<typename Ptr<typename Prop::quant>::ptr_t> ids(rawIds); + PropertyInstance<Prop, true> pi; + assert(stop <= pi.data.timeLimit); + assert(start >= 0); + + // print header + cout << "#"; + for (auto i : ids) cout << "\tval(" << (uint64_t) i << ")"; + for (auto i : ids) cout << "\ttime(" << (uint64_t) i << ")"; + cout << endl; + + // print data + for (Time t = start; t <= stop; t = t + pi.data.interval()) { + cout << t(); + for (auto i : ids) cout << "\t" << pi.data.getValue(t, i); + for (auto i : ids) cout << "\t" << pi.data.getTime (t, i); + cout << endl; + } + } +}; + +template<typename Prop> +struct CoarseReplay<Prop, DiscretePropertyClass> : CoarseReplay<BaseCase, Void> { + virtual void operator() (Time start, Time stop, uint64_t raw_addr) { + cerr << Prop::name << " is a discrete property" << endl; + exit(-1); + } +}; + + +int main(int argc, char **argv) { + // read cmd line params + assert(argc == 5); + assertSimDir(); + + { + PropertyComposition<Lists::all> pc; + PLA_GetByName<CoarseReplay> pla(argv[1]); + CoarseReplay<BaseCase, Void> *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); + assert(errno == 0); + + // output + (*replay)(start, stop, ids); + } + + return 0; +} |