63d62
< #include "base/stats/bin.hh"
67d65
< #include "config/stats_binning.hh"
106,110d103
< * @return true if the stat is binned.
< */
< virtual bool binned() const = 0;
<
< /**
163d155
< virtual bool binned() const { return s.binned(); }
206d197
< virtual bool binned() const { return s.binned(); }
264d254
< virtual bool binned() const { return s.binned(); }
303d292
< typedef typename Stat::bin_t bin_t;
308d296
< virtual bool binned() const { return bin_t::binned; }
345d332
< typedef typename Stat::bin_t bin_t;
350d336
< virtual bool binned() const { return bin_t::binned; }
362d347
<
618d602
< * @todo add lateny to the stat and fix binning.
624,631c608
< struct Params
< {
< /**
< * The current count. We stash this here because the current
< * value is not a binned value.
< */
< Counter current;
< };
---
> struct Params { };
633a611,612
> /** The current count. */
> Counter current;
643c622
< AvgStor(Params &p) : total(0), last(0) { p.current = Counter(); }
---
> AvgStor(Params &p) : current(0), total(0), last(0) { }
652c631
< total += p.current * (curTick - last);
---
> total += current * (curTick - last);
654c633
< p.current = val;
---
> current = val;
662c641
< void inc(Counter val, Params &p) { set(p.current + val, p); }
---
> void inc(Counter val, Params &p) { set(current + val, p); }
669c648
< void dec(Counter val, Params &p) { set(p.current - val, p); }
---
> void dec(Counter val, Params &p) { set(current - val, p); }
676c655
< Counter value(const Params &p) const { return p.current; }
---
> Counter value(const Params &p) const { return current; }
685c664
< total += p.current * (curTick - last);
---
> total += current * (curTick - last);
687c666
< return (Result)(total + p.current) / (Result)(curTick + 1);
---
> return (Result)(total + current) / (Result)(curTick + 1);
707,708c686
< * Storage template. The storage for this stat is held within the Bin class.
< * This allows for breaking down statistics across multiple bins easily.
---
> * Storage template.
710c688
< template <class Storage, class Bin>
---
> template <class Stor>
713a692,693
> typedef Stor Storage;
>
715,717c695
< typedef typename Storage::Params params_t;
< /** Define the bin type. */
< typedef typename Bin::template Bin<Storage> bin_t;
---
> typedef typename Storage::Params Params;
720,721c698,700
< /** The bin of this stat. */
< bin_t bin;
---
> /** The storage of this stat. */
> char storage[sizeof(Storage)];
>
723c702
< params_t params;
---
> Params params;
727,728c706,708
< * Retrieve the storage from the bin.
< * @return The storage object for this stat.
---
> * Retrieve the storage.
> * @param index The vector index to access.
> * @return The storage object at the given index.
730c710,715
< Storage *data() { return bin.data(params); }
---
> Storage *
> data()
> {
> return reinterpret_cast<Storage *>(storage);
> }
>
732,733c717,720
< * Retrieve a const pointer to the storage from the bin.
< * @return A const pointer to the storage object for this stat.
---
> * Retrieve a const pointer to the storage.
> * for the given index.
> * @param index The vector index to access.
> * @return A const pointer to the storage object at the given index.
735c722,723
< const Storage *data() const
---
> const Storage *
> data() const
737,739c725
< bin_t *_bin = const_cast<bin_t *>(&bin);
< params_t *_params = const_cast<params_t *>(&params);
< return _bin->data(*_params);
---
> return reinterpret_cast<const Storage *>(storage);
741a728,734
> void
> doInit()
> {
> new (storage) Storage(params);
> setInit();
> }
>
754,756c747
< {
< bin.init(params);
< }
---
> { }
805,809d795
< /**
< * Return true if stat is binned.
< *@return True is stat is binned.
< */
< bool binned() const { return bin_t::binned; }
811c797
< bool check() const { return bin.initialized(); }
---
> bool check() const { return true; }
816c802
< void reset() { bin.reset(); }
---
> void reset() { data()->reset(); }
832d817
< virtual bool binned() const { return false; }
894d878
< bool binned() const { return proxy->binned(); }
906,907d889
< template <class Storage, class Bin>
< class ScalarProxy;
910,1017d891
< * Implementation of a vector of stats. The type of stat is determined by the
< * Storage class. @sa ScalarBase
< */
< template <class Storage, class Bin>
< class VectorBase : public DataAccess
< {
< public:
< /** Define the params of the storage class. */
< typedef typename Storage::Params params_t;
< /** Define the bin type. */
< typedef typename Bin::template VectorBin<Storage> bin_t;
<
< protected:
< /** The bin of this stat. */
< bin_t bin;
< /** The parameters for this stat. */
< params_t params;
<
< protected:
< /**
< * Retrieve the storage from the bin for the given index.
< * @param index The vector index to access.
< * @return The storage object at the given index.
< */
< Storage *data(int index) { return bin.data(index, params); }
< /**
< * Retrieve a const pointer to the storage from the bin
< * for the given index.
< * @param index The vector index to access.
< * @return A const pointer to the storage object at the given index.
< */
< const Storage *data(int index) const
< {
< bin_t *_bin = const_cast<bin_t *>(&bin);
< params_t *_params = const_cast<params_t *>(&params);
< return _bin->data(index, *_params);
< }
<
< public:
< void value(VCounter &vec) const
< {
< vec.resize(size());
< for (int i = 0; i < size(); ++i)
< vec[i] = data(i)->value(params);
< }
<
< /**
< * Copy the values to a local vector and return a reference to it.
< * @return A reference to a vector of the stat values.
< */
< void result(VResult &vec) const
< {
< vec.resize(size());
< for (int i = 0; i < size(); ++i)
< vec[i] = data(i)->result(params);
< }
<
< /**
< * @return True is stat is binned.
< */
< bool binned() const { return bin_t::binned; }
<
< /**
< * Return a total of all entries in this vector.
< * @return The total of all vector entries.
< */
< Result total() const {
< Result total = 0.0;
< for (int i = 0; i < size(); ++i)
< total += data(i)->result(params);
< return total;
< }
<
< /**
< * @return the number of elements in this vector.
< */
< size_t size() const { return bin.size(); }
<
< bool zero() const
< {
< for (int i = 0; i < size(); ++i)
< if (data(i)->zero())
< return true;
< return false;
< }
<
< bool check() const { return bin.initialized(); }
< void reset() { bin.reset(); }
<
< public:
< VectorBase() {}
<
< /** Friend this class with the associated scalar proxy. */
< friend class ScalarProxy<Storage, Bin>;
<
< /**
< * Return a reference (ScalarProxy) to the stat at the given index.
< * @param index The vector index to access.
< * @return A reference of the stat.
< */
< ScalarProxy<Storage, Bin> operator[](int index);
<
< void update(StatData *data) {}
< };
<
< const StatData * getStatData(const void *stat);
<
< /**
1021c895
< template <class Storage, class Bin>
---
> template <class Stat>
1024,1029d897
< public:
< /** Define the params of the storage class. */
< typedef typename Storage::Params params_t;
< /** Define the bin type. */
< typedef typename Bin::template VectorBin<Storage> bin_t;
<
1031,1034c899,901
< /** Pointer to the bin in the parent VectorBase. */
< bin_t *bin;
< /** Pointer to the params in the parent VectorBase. */
< params_t *params;
---
> /** Pointer to the parent Vector. */
> Stat *stat;
>
1037,1038d903
< /** Keep a pointer to the original stat so was can get data */
< void *stat;
1040,1056d904
< protected:
< /**
< * Retrieve the storage from the bin.
< * @return The storage from the bin for this stat.
< */
< Storage *data() { return bin->data(index, *params); }
< /**
< * Retrieve a const pointer to the storage from the bin.
< * @return A const pointer to the storage for this stat.
< */
< const Storage *data() const
< {
< bin_t *_bin = const_cast<bin_t *>(bin);
< params_t *_params = const_cast<params_t *>(params);
< return _bin->data(index, *_params);
< }
<
1062c910
< Counter value() const { return data()->value(*params); }
---
> Counter value() const { return stat->data(index)->value(stat->params); }
1068c916
< Result result() const { return data()->result(*params); }
---
> Result result() const { return stat->data(index)->result(stat->params); }
1073d920
< * @param b The bin to use.
1077,1078c924,929
< ScalarProxy(bin_t &b, params_t &p, int i, void *s)
< : bin(&b), params(&p), index(i), stat(s) {}
---
> ScalarProxy(Stat *s, int i)
> : stat(s), index(i)
> {
> assert(stat);
> }
>
1084c935,937
< : bin(sp.bin), params(sp.params), index(sp.index), stat(sp.stat) {}
---
> : stat(sp.stat), index(sp.index)
> {}
>
1091,1093d943
< bin = sp.bin;
< params = sp.params;
< index = sp.index;
1094a945
> index = sp.index;
1104c955
< void operator++() { data()->inc(1, *params); }
---
> void operator++() { stat->data(index)->inc(1, stat->params); }
1109c960
< void operator--() { data()->dec(1, *params); }
---
> void operator--() { stat->data(index)->dec(1, stat->params); }
1122c973
< void operator=(const U &v) { data()->set(v, *params); }
---
> void operator=(const U &v) { stat->data(index)->set(v, stat->params); }
1130c981
< void operator+=(const U &v) { data()->inc(v, *params); }
---
> void operator+=(const U &v) { stat->data(index)->inc(v, stat->params); }
1138c989
< void operator-=(const U &v) { data()->dec(v, *params); }
---
> void operator-=(const U &v) { stat->data(index)->dec(v, stat->params); }
1147,1152d997
< * Return true if stat is binned.
< *@return false since Proxies aren't printed/binned
< */
< bool binned() const { return false; }
<
< /**
1158,1159c1003,1004
< const StatData *statData() const { return getStatData(stat); }
< std::string str() const
---
> std::string
> str() const
1161c1006
< return csprintf("%s[%d]", this->statData()->name, index);
---
> return csprintf("%s[%d]", stat->str(), index);
1166,1168c1011,1016
< template <class Storage, class Bin>
< inline ScalarProxy<Storage, Bin>
< VectorBase<Storage, Bin>::operator[](int index)
---
> /**
> * Implementation of a vector of stats. The type of stat is determined by the
> * Storage class. @sa ScalarBase
> */
> template <class Stor>
> class VectorBase : public DataAccess
1170,1172c1018,1019
< assert (index >= 0 && index < size());
< return ScalarProxy<Storage, Bin>(bin, params, index, this);
< }
---
> public:
> typedef Stor Storage;
1174,1175c1021,1022
< template <class Storage, class Bin>
< class VectorProxy;
---
> /** Define the params of the storage class. */
> typedef typename Storage::Params Params;
1177,1182c1024,1025
< template <class Storage, class Bin>
< class Vector2dBase : public DataAccess
< {
< public:
< typedef typename Storage::Params params_t;
< typedef typename Bin::template VectorBin<Storage> bin_t;
---
> /** Proxy type */
> typedef ScalarProxy<VectorBase<Storage> > Proxy;
1183a1027,1028
> friend class ScalarProxy<VectorBase<Storage> >;
>
1185,1188c1030,1032
< size_t x;
< size_t y;
< bin_t bin;
< params_t params;
---
> /** The storage of this stat. */
> Storage *storage;
> size_t _size;
1189a1034,1036
> /** The parameters for this stat. */
> Params params;
>
1191,1192c1038,1053
< Storage *data(int index) { return bin.data(index, params); }
< const Storage *data(int index) const
---
> /**
> * Retrieve the storage.
> * @param index The vector index to access.
> * @return The storage object at the given index.
> */
> Storage *data(int index) { return &storage[index]; }
>
> /**
> * Retrieve a const pointer to the storage.
> * @param index The vector index to access.
> * @return A const pointer to the storage object at the given index.
> */
> const Storage *data(int index) const { return &storage[index]; }
>
> void
> doInit(int s)
1194,1196c1055,1065
< bin_t *_bin = const_cast<bin_t *>(&bin);
< params_t *_params = const_cast<params_t *>(&params);
< return _bin->data(index, *_params);
---
> assert(s > 0 && "size must be positive!");
> assert(!storage && "already initialized");
> _size = s;
>
> char *ptr = new char[_size * sizeof(Storage)];
> storage = reinterpret_cast<Storage *>(ptr);
>
> for (int i = 0; i < _size; ++i)
> new (&storage[i]) Storage(params);
>
> setInit();
1200c1069,1074
< Vector2dBase() {}
---
> void value(VCounter &vec) const
> {
> vec.resize(size());
> for (int i = 0; i < size(); ++i)
> vec[i] = data(i)->value(params);
> }
1202c1076,1080
< void update(Vector2dData *data)
---
> /**
> * Copy the values to a local vector and return a reference to it.
> * @return A reference to a vector of the stat values.
> */
> void result(VResult &vec) const
1204,1207c1082,1084
< int size = this->size();
< data->cvec.resize(size);
< for (int i = 0; i < size; ++i)
< data->cvec[i] = this->data(i)->value(params);
---
> vec.resize(size());
> for (int i = 0; i < size(); ++i)
> vec[i] = data(i)->result(params);
1210c1087,1096
< std::string ysubname(int i) const { return (*this->y_subnames)[i]; }
---
> /**
> * Return a total of all entries in this vector.
> * @return The total of all vector entries.
> */
> Result total() const {
> Result total = 0.0;
> for (int i = 0; i < size(); ++i)
> total += data(i)->result(params);
> return total;
> }
1212,1213c1098,1101
< friend class VectorProxy<Storage, Bin>;
< VectorProxy<Storage, Bin> operator[](int index);
---
> /**
> * @return the number of elements in this vector.
> */
> size_t size() const { return _size; }
1215,1216c1103,1110
< size_t size() const { return bin.size(); }
< bool zero() const { return data(0)->value(params) == 0.0; }
---
> bool
> zero() const
> {
> for (int i = 0; i < size(); ++i)
> if (data(i)->zero())
> return false;
> return true;
> }
1217a1112,1139
> bool
> check() const
> {
> return storage != NULL;
> }
>
> void
> reset()
> {
> for (int i = 0; i < size(); ++i)
> data(i)->reset();
> }
>
> public:
> VectorBase()
> : storage(NULL)
> {}
>
> ~VectorBase()
> {
> if (!storage)
> return;
>
> for (int i = 0; i < _size; ++i)
> data(i)->~Storage();
> delete [] reinterpret_cast<char *>(storage);
> }
>
1219c1141,1143
< * Reset stat value to default
---
> * Return a reference (ScalarProxy) to the stat at the given index.
> * @param index The vector index to access.
> * @return A reference of the stat.
1221c1145,1150
< void reset() { bin.reset(); }
---
> Proxy
> operator[](int index)
> {
> assert (index >= 0 && index < size());
> return Proxy(this, index);
> }
1223c1152
< bool check() { return bin.initialized(); }
---
> void update(StatData *data) {}
1226c1155
< template <class Storage, class Bin>
---
> template <class Stat>
1229,1232d1157
< public:
< typedef typename Storage::Params params_t;
< typedef typename Bin::template VectorBin<Storage> bin_t;
<
1234,1235c1159
< bin_t *bin;
< params_t *params;
---
> Stat *stat;
1238d1161
< void *stat;
1241c1164
< mutable VResult *vec;
---
> mutable VResult vec;
1243c1166,1168
< Storage *data(int index) {
---
> typename Stat::Storage *
> data(int index)
> {
1245c1170
< return bin->data(offset + index, *params);
---
> return stat->data(offset + index);
1248,1251c1173,1177
< const Storage *data(int index) const {
< bin_t *_bin = const_cast<bin_t *>(bin);
< params_t *_params = const_cast<params_t *>(params);
< return _bin->data(offset + index, *_params);
---
> const typename Stat::Storage *
> data(int index) const
> {
> assert(index < len);
> return const_cast<Stat *>(stat)->data(offset + index);
1255,1259c1181,1184
< const VResult &result() const {
< if (vec)
< vec->resize(size());
< else
< vec = new VResult(size());
---
> const VResult &
> result() const
> {
> vec.resize(size());
1262c1187
< (*vec)[i] = data(i)->result(*params);
---
> vec[i] = data(i)->result(stat->params);
1264c1189
< return *vec;
---
> return vec;
1267,1268c1192,1195
< Result total() const {
< Result total = 0.0;
---
> Result
> total() const
> {
> Result total = 0;
1270c1197
< total += data(i)->result(*params);
---
> total += data(i)->result(stat->params);
1275,1276c1202,1203
< VectorProxy(bin_t &b, params_t &p, int o, int l, void *s)
< : bin(&b), params(&p), offset(o), len(l), stat(s), vec(NULL)
---
> VectorProxy(Stat *s, int o, int l)
> : stat(s), offset(o), len(l)
1281,1282c1208
< : bin(sp.bin), params(sp.params), offset(sp.offset), len(sp.len),
< stat(sp.stat), vec(NULL)
---
> : stat(sp.stat), offset(sp.offset), len(sp.len)
1286c1212,1213
< ~VectorProxy()
---
> const VectorProxy &
> operator=(const VectorProxy &sp)
1288,1295c1215
< if (vec)
< delete vec;
< }
<
< const VectorProxy &operator=(const VectorProxy &sp)
< {
< bin = sp.bin;
< params = sp.params;
---
> stat = sp.stat;
1298,1301d1217
< stat = sp.stat;
< if (vec)
< delete vec;
< vec = NULL;
1305c1221
< ScalarProxy<Storage, Bin> operator[](int index)
---
> ScalarProxy<Stat> operator[](int index)
1308c1224
< return ScalarProxy<Storage, Bin>(*bin, *params, offset + index, stat);
---
> return ScalarProxy<Stat>(stat, offset + index);
1314,1319d1229
< * Return true if stat is binned.
< *@return false since Proxies aren't printed/binned
< */
< bool binned() const { return false; }
<
< /**
1325,1327c1235,1236
< template <class Storage, class Bin>
< inline VectorProxy<Storage, Bin>
< Vector2dBase<Storage, Bin>::operator[](int index)
---
> template <class Stor>
> class Vector2dBase : public DataAccess
1329,1332c1238,1243
< int offset = index * y;
< assert (index >= 0 && offset < size());
< return VectorProxy<Storage, Bin>(bin, params, offset, y, this);
< }
---
> public:
> typedef Stor Storage;
> typedef typename Storage::Params Params;
> typedef VectorProxy<Vector2dBase<Storage> > Proxy;
> friend class ScalarProxy<Vector2dBase<Storage> >;
> friend class VectorProxy<Vector2dBase<Storage> >;
1333a1245,1348
> protected:
> size_t x;
> size_t y;
> size_t _size;
> Storage *storage;
> Params params;
>
> protected:
> Storage *data(int index) { return &storage[index]; }
> const Storage *data(int index) const { return &storage[index]; }
>
> void
> doInit(int _x, int _y)
> {
> assert(_x > 0 && _y > 0 && "sizes must be positive!");
> assert(!storage && "already initialized");
>
> Vector2dData *statdata = dynamic_cast<Vector2dData *>(find());
>
> x = _x;
> y = _y;
> statdata->x = _x;
> statdata->y = _y;
> _size = x * y;
>
> char *ptr = new char[_size * sizeof(Storage)];
> storage = reinterpret_cast<Storage *>(ptr);
>
> for (int i = 0; i < _size; ++i)
> new (&storage[i]) Storage(params);
>
> setInit();
> }
>
> public:
> Vector2dBase()
> : storage(NULL)
> {}
>
> ~Vector2dBase()
> {
> if (!storage)
> return;
>
> for (int i = 0; i < _size; ++i)
> data(i)->~Storage();
> delete [] reinterpret_cast<char *>(storage);
> }
>
> void
> update(Vector2dData *newdata)
> {
> int size = this->size();
> newdata->cvec.resize(size);
> for (int i = 0; i < size; ++i)
> newdata->cvec[i] = data(i)->value(params);
> }
>
> std::string ysubname(int i) const { return (*this->y_subnames)[i]; }
>
> Proxy
> operator[](int index)
> {
> int offset = index * y;
> assert (index >= 0 && offset + index < size());
> return Proxy(this, offset, y);
> }
>
>
> size_t
> size() const
> {
> return _size;
> }
>
> bool
> zero() const
> {
> return data(0)->zero();
> #if 0
> for (int i = 0; i < size(); ++i)
> if (!data(i)->zero())
> return false;
> return true;
> #endif
> }
>
> /**
> * Reset stat value to default
> */
> void
> reset()
> {
> for (int i = 0; i < size(); ++i)
> data(i)->reset();
> }
>
> bool
> check()
> {
> return storage != NULL;
> }
> };
>
1379,1382d1393
< /**
< * Construct this storage with the supplied params.
< * @param params The parameters.
< */
1384,1386c1395
< : min_val(INT_MAX), max_val(INT_MIN), underflow(Counter()),
< overflow(Counter()), sum(Counter()), squares(Counter()),
< samples(Counter()), cvec(params.size)
---
> : cvec(params.size)
1621c1630
< template <class Storage, class Bin>
---
> template <class Stor>
1624a1634
> typedef Stor Storage;
1626,1628c1636
< typedef typename Storage::Params params_t;
< /** Define the bin type. */
< typedef typename Bin::template Bin<Storage> bin_t;
---
> typedef typename Storage::Params Params;
1631,1632c1639,1641
< /** The bin of this stat. */
< bin_t bin;
---
> /** The storage for this stat. */
> char storage[sizeof(Storage)];
>
1634c1643
< params_t params;
---
> Params params;
1638c1647
< * Retrieve the storage from the bin.
---
> * Retrieve the storage.
1641c1650,1654
< Storage *data() { return bin.data(params); }
---
> Storage *data()
> {
> return reinterpret_cast<Storage *>(storage);
> }
>
1643c1656
< * Retrieve a const pointer to the storage from the bin.
---
> * Retrieve a const pointer to the storage.
1646c1659,1660
< const Storage *data() const
---
> const Storage *
> data() const
1648,1650c1662
< bin_t *_bin = const_cast<bin_t *>(&bin);
< params_t *_params = const_cast<params_t *>(&params);
< return _bin->data(*_params);
---
> return reinterpret_cast<const Storage *>(storage);
1652a1665,1671
> void
> doInit()
> {
> new (storage) Storage(params);
> setInit();
> }
>
1680a1700
>
1682,1685d1701
< * @return True is stat is binned.
< */
< bool binned() const { return bin_t::binned; }
< /**
1688c1704,1705
< void reset()
---
> void
> reset()
1690c1707
< bin.reset();
---
> data()->reset();
1693c1710,1714
< bool check() { return bin.initialized(); }
---
> bool
> check()
> {
> return true;
> }
1696c1717
< template <class Storage, class Bin>
---
> template <class Stat>
1699c1720
< template <class Storage, class Bin>
---
> template <class Stor>
1703,1704c1724,1727
< typedef typename Storage::Params params_t;
< typedef typename Bin::template VectorBin<Storage> bin_t;
---
> typedef Stor Storage;
> typedef typename Storage::Params Params;
> typedef DistProxy<VectorDistBase<Storage> > Proxy;
> friend class DistProxy<VectorDistBase<Storage> >;
1707,1708c1730,1732
< bin_t bin;
< params_t params;
---
> Storage *storage;
> size_t _size;
> Params params;
1711,1712c1735,1736
< Storage *data(int index) { return bin.data(index, params); }
< const Storage *data(int index) const
---
> Storage *
> data(int index)
1714,1716c1738
< bin_t *_bin = const_cast<bin_t *>(&bin);
< params_t *_params = const_cast<params_t *>(&params);
< return _bin->data(index, *_params);
---
> return &storage[index];
1718a1741,1762
> const Storage *
> data(int index) const
> {
> return &storage[index];
> }
>
> void
> doInit(int s)
> {
> assert(s > 0 && "size must be positive!");
> assert(!storage && "already initialized");
> _size = s;
>
> char *ptr = new char[_size * sizeof(Storage)];
> storage = reinterpret_cast<Storage *>(ptr);
>
> for (int i = 0; i < _size; ++i)
> new (&storage[i]) Storage(params);
>
> setInit();
> }
>
1720c1764,1766
< VectorDistBase() {}
---
> VectorDistBase()
> : storage(NULL)
> {}
1722,1724c1768,1771
< friend class DistProxy<Storage, Bin>;
< DistProxy<Storage, Bin> operator[](int index);
< const DistProxy<Storage, Bin> operator[](int index) const;
---
> ~VectorDistBase()
> {
> if (!storage)
> return ;
1726,1727c1773,1797
< size_t size() const { return bin.size(); }
< bool zero() const { return false; }
---
> for (int i = 0; i < _size; ++i)
> data(i)->~Storage();
> delete [] reinterpret_cast<char *>(storage);
> }
>
> Proxy operator[](int index);
>
> size_t
> size() const
> {
> return _size;
> }
>
> bool
> zero() const
> {
> return false;
> #if 0
> for (int i = 0; i < size(); ++i)
> if (!data(i)->zero(params))
> return false;
> return true;
> #endif
> }
>
1729,1733d1798
< * Return true if stat is binned.
< *@return True is stat is binned.
< */
< bool binned() const { return bin_t::binned; }
< /**
1736c1801,1806
< void reset() { bin.reset(); }
---
> void
> reset()
> {
> for (int i = 0; i < size(); ++i)
> data(i)->reset();
> }
1738,1739c1808,1809
< bool check() { return bin.initialized(); }
< void update(VectorDistData *base)
---
> bool
> check()
1740a1811,1816
> return storage != NULL;
> }
>
> void
> update(VectorDistData *base)
> {
1750c1826
< template <class Storage, class Bin>
---
> template <class Stat>
1753,1757d1828
< public:
< typedef typename Storage::Params params_t;
< typedef typename Bin::template Bin<Storage> bin_t;
< typedef VectorDistBase<Storage, Bin> base_t;
<
1759,1762c1830
< union {
< base_t *stat;
< const base_t *cstat;
< };
---
> Stat *stat;
1766,1767c1834,1835
< Storage *data() { return stat->data(index); }
< const Storage *data() const { return cstat->data(index); }
---
> typename Stat::Storage *data() { return stat->data(index); }
> const typename Stat::Storage *data() const { return stat->data(index); }
1770,1771c1838,1841
< DistProxy(const VectorDistBase<Storage, Bin> &s, int i)
< : cstat(&s), index(i) {}
---
> DistProxy(Stat *s, int i)
> : stat(s), index(i)
> {}
>
1773,1775c1843,1850
< : cstat(sp.cstat), index(sp.index) {}
< const DistProxy &operator=(const DistProxy &sp) {
< cstat = sp.cstat; index = sp.index; return *this;
---
> : stat(sp.stat), index(sp.index)
> {}
>
> const DistProxy &operator=(const DistProxy &sp)
> {
> stat = sp.stat;
> index = sp.index;
> return *this;
1780c1855,1859
< void sample(const U &v, int n = 1) { data()->sample(v, n, cstat->params); }
---
> void
> sample(const U &v, int n = 1)
> {
> data()->sample(v, n, stat->params);
> }
1782,1783c1861,1872
< size_t size() const { return 1; }
< bool zero() const { return data()->zero(cstat->params); }
---
> size_t
> size() const
> {
> return 1;
> }
>
> bool
> zero() const
> {
> return data()->zero(stat->params);
> }
>
1785,1789d1873
< * Return true if stat is binned.
< *@return false since Proxies are not binned/printed.
< */
< bool binned() const { return false; }
< /**
1795,1797c1879,1881
< template <class Storage, class Bin>
< inline DistProxy<Storage, Bin>
< VectorDistBase<Storage, Bin>::operator[](int index)
---
> template <class Storage>
> inline typename VectorDistBase<Storage>::Proxy
> VectorDistBase<Storage>::operator[](int index)
1800c1884
< return DistProxy<Storage, Bin>(*this, index);
---
> return typename VectorDistBase<Storage>::Proxy(this, index);
1803,1810d1886
< template <class Storage, class Bin>
< inline const DistProxy<Storage, Bin>
< VectorDistBase<Storage, Bin>::operator[](int index) const
< {
< assert (index >= 0 && index < size());
< return DistProxy<Storage, Bin>(*this, index);
< }
<
1812c1888
< template <class Storage, class Bin>
---
> template <class Storage>
1814c1890
< VectorDistBase<Storage, Bin>::total(int index) const
---
> VectorDistBase<Storage>::total(int index) const
1817,1818c1893,1894
< for (int i=0; i < x_size(); ++i) {
< total += data(i)->result(*params);
---
> for (int i = 0; i < x_size(); ++i) {
> total += data(i)->result(stat->params);
1851,1855d1926
< /**
< * Return true if stat is binned.
< *@return True is stat is binned.
< */
< virtual bool binned() const = 0;
1882,1886d1952
< /**
< * Return true if stat is binned.
< *@return True is stat is binned.
< */
< virtual bool binned() const { return data->binned(); }
1894c1960
< template <class Storage, class Bin>
---
> template <class Stat>
1898c1964
< const ScalarProxy<Storage, Bin> proxy;
---
> const ScalarProxy<Stat> proxy;
1902,1904c1968,1973
< ScalarProxyNode(const ScalarProxy<Storage, Bin> &p)
< : proxy(p), vresult(1) { }
< virtual const VResult &result() const
---
> ScalarProxyNode(const ScalarProxy<Stat> &p)
> : proxy(p), vresult(1)
> { }
>
> virtual const VResult &
> result() const
1909d1977
< virtual Result total() const { return proxy.result(); };
1911,1916c1979,1983
< virtual size_t size() const { return 1; }
< /**
< * Return true if stat is binned.
< *@return True is stat is binned.
< */
< virtual bool binned() const { return proxy.binned(); }
---
> virtual Result
> total() const
> {
> return proxy.result();
> }
1917a1985,1990
> virtual size_t
> size() const
> {
> return 1;
> }
>
1921c1994,1998
< virtual std::string str() const { return proxy.str(); }
---
> virtual std::string
> str() const
> {
> return proxy.str();
> }
1935,1939d2011
< /**
< * Return true if stat is binned.
< *@return True is stat is binned.
< */
< virtual bool binned() const { return data->binned(); }
1955,1961d2026
<
< /**
< * Return true if stat is binned.
< *@return False since constants aren't binned.
< */
< virtual bool binned() const { return false; }
<
2035,2039d2099
< /**
< * Return true if child of node is binned.
< *@return True if child of node is binned.
< */
< virtual bool binned() const { return l->binned(); }
2106,2110d2165
< /**
< * Return true if any children of node are binned
< *@return True if either child of node is binned.
< */
< virtual bool binned() const { return (l->binned() || r->binned()); }
2159,2163d2213
< /**
< * Return true if child of node is binned.
< *@return True if child of node is binned.
< */
< virtual bool binned() const { return l->binned(); }
2179,2181c2229
< * These are the statistics that are used in the simulator. By default these
< * store counters and don't use binning, but are templatized to accept any type
< * and any Bin class.
---
> * These are the statistics that are used in the simulator.
2186,2196d2233
< * This is an easy way to assign all your stats to be binned or not
< * binned. If the typedef is NoBin, nothing is binned. If it is
< * MainBin, then all stats are binned under that Bin.
< */
< #if STATS_BINNING
< typedef MainBin DefaultBin;
< #else
< typedef NoBin DefaultBin;
< #endif
<
< /**
2200,2204c2237,2238
< template <class Bin = DefaultBin>
< class Scalar
< : public Wrap<Scalar<Bin>,
< ScalarBase<StatStor, Bin>,
< ScalarStatData>
---
> template<int N = 0>
> class Scalar : public Wrap<Scalar<N>, ScalarBase<StatStor>, ScalarStatData>
2208c2242
< typedef ScalarBase<StatStor, Bin> Base;
---
> typedef ScalarBase<StatStor> Base;
2212c2246
< this->setInit();
---
> this->doInit();
2224,2227c2258
< class Value
< : public Wrap<Value,
< ValueBase,
< ScalarStatData>
---
> class Value : public Wrap<Value, ValueBase, ScalarStatData>
2252,2256c2283,2284
< template <class Bin = DefaultBin>
< class Average
< : public Wrap<Average<Bin>,
< ScalarBase<AvgStor, Bin>,
< ScalarStatData>
---
> template<int N = 0>
> class Average : public Wrap<Average<N>, ScalarBase<AvgStor>, ScalarStatData>
2260c2288
< typedef ScalarBase<AvgStor, Bin> Base;
---
> typedef ScalarBase<AvgStor> Base;
2264c2292
< this->setInit();
---
> this->doInit();
2280,2284c2308,2309
< template <class Bin = DefaultBin>
< class Vector
< : public WrapVec<Vector<Bin>,
< VectorBase<StatStor, Bin>,
< VectorStatData>
---
> template<int N = 0>
> class Vector : public WrapVec<Vector<N>, VectorBase<StatStor>, VectorStatData>
2288c2313
< typedef ScalarBase<StatStor, Bin> Base;
---
> typedef ScalarBase<StatStor> Base;
2296,2298c2321
< this->bin.init(size, this->params);
< this->setInit();
<
---
> this->doInit(size);
2307c2330
< template <class Bin = DefaultBin>
---
> template<int N = 0>
2309,2311c2332
< : public WrapVec<AverageVector<Bin>,
< VectorBase<AvgStor, Bin>,
< VectorStatData>
---
> : public WrapVec<AverageVector<N>, VectorBase<AvgStor>, VectorStatData>
2320,2322c2341
< this->bin.init(size, this->params);
< this->setInit();
<
---
> this->doInit(size);
2331c2350
< template <class Bin = DefaultBin>
---
> template<int N = 0>
2333,2335c2352
< : public WrapVec2d<Vector2d<Bin>,
< Vector2dBase<StatStor, Bin>,
< Vector2dStatData>
---
> : public WrapVec2d<Vector2d<N>, Vector2dBase<StatStor>, Vector2dStatData>
2338,2343c2355,2356
< Vector2d &init(size_t _x, size_t _y) {
< this->statData()->x = this->x = _x;
< this->statData()->y = this->y = _y;
< this->bin.init(this->x * this->y, this->params);
< this->setInit();
<
---
> Vector2d &init(size_t x, size_t y) {
> this->doInit(x, y);
2352c2365
< template <class Bin = DefaultBin>
---
> template<int N = 0>
2354,2356c2367
< : public Wrap<Distribution<Bin>,
< DistBase<DistStor, Bin>,
< DistStatData>
---
> : public Wrap<Distribution<N>, DistBase<DistStor>, DistStatData>
2360c2371
< typedef DistBase<DistStor, Bin> Base;
---
> typedef DistBase<DistStor> Base;
2362c2373
< typedef typename DistStor::Params Params;
---
> typedef DistStor::Params Params;
2377,2379c2388
< this->bin.init(this->params);
< this->setInit();
<
---
> this->doInit();
2388c2397
< template <class Bin = DefaultBin>
---
> template<int N = 0>
2390,2392c2399
< : public Wrap<StandardDeviation<Bin>,
< DistBase<FancyStor, Bin>,
< DistStatData>
---
> : public Wrap<StandardDeviation<N>, DistBase<FancyStor>, DistStatData>
2396c2403
< typedef DistBase<DistStor, Bin> Base;
---
> typedef DistBase<DistStor> Base;
2398c2405
< typedef typename DistStor::Params Params;
---
> typedef DistStor::Params Params;
2405,2406c2412
< this->bin.init(this->params);
< this->setInit();
---
> this->doInit();
2414c2420
< template <class Bin = DefaultBin>
---
> template<int N = 0>
2416,2418c2422
< : public Wrap<AverageDeviation<Bin>,
< DistBase<AvgFancy, Bin>,
< DistStatData>
---
> : public Wrap<AverageDeviation<N>, DistBase<AvgFancy>, DistStatData>
2422c2426
< typedef DistBase<DistStor, Bin> Base;
---
> typedef DistBase<DistStor> Base;
2424c2428
< typedef typename DistStor::Params Params;
---
> typedef DistStor::Params Params;
2432,2433c2436
< this->bin.init(this->params);
< this->setInit();
---
> this->doInit();
2441c2444
< template <class Bin = DefaultBin>
---
> template<int N = 0>
2443,2444c2446,2447
< : public WrapVec<VectorDistribution<Bin>,
< VectorDistBase<DistStor, Bin>,
---
> : public WrapVec<VectorDistribution<N>,
> VectorDistBase<DistStor>,
2449c2452
< typedef VectorDistBase<DistStor, Bin> Base;
---
> typedef VectorDistBase<DistStor> Base;
2451c2454
< typedef typename DistStor::Params Params;
---
> typedef DistStor::Params Params;
2467,2469c2470
< this->bin.init(size, this->params);
< this->setInit();
<
---
> this->doInit(size);
2478c2479
< template <class Bin = DefaultBin>
---
> template<int N = 0>
2480,2481c2481,2482
< : public WrapVec<VectorStandardDeviation<Bin>,
< VectorDistBase<FancyStor, Bin>,
---
> : public WrapVec<VectorStandardDeviation<N>,
> VectorDistBase<FancyStor>,
2486c2487
< typedef VectorDistBase<FancyStor, Bin> Base;
---
> typedef VectorDistBase<FancyStor> Base;
2488c2489
< typedef typename DistStor::Params Params;
---
> typedef DistStor::Params Params;
2497,2499c2498
< this->bin.init(size, this->params);
< this->setInit();
<
---
> this->doInit(size);
2508c2507
< template <class Bin = DefaultBin>
---
> template<int N = 0>
2510,2511c2509,2510
< : public WrapVec<VectorAverageDeviation<Bin>,
< VectorDistBase<AvgFancy, Bin>,
---
> : public WrapVec<VectorAverageDeviation<N>,
> VectorDistBase<AvgFancy>,
2516c2515
< typedef VectorDistBase<AvgFancy, Bin> Base;
---
> typedef VectorDistBase<AvgFancy> Base;
2518c2517
< typedef typename DistStor::Params Params;
---
> typedef DistStor::Params Params;
2527,2529c2526
< this->bin.init(size, this->params);
< this->setInit();
<
---
> this->doInit(size);
2573,2579d2569
< /**
< * Return true if Formula is binned. i.e. any of its children
< * nodes are binned
< * @return True if Formula is binned.
< */
< bool binned() const;
<
2618d2607
< virtual bool binned() const { return s.binned(); }
2685d2673
< virtual bool binned() const { return formula.binned(); }
2719,2720c2707,2708
< template <class Bin>
< Temp(const Scalar<Bin> &s)
---
> template <int N>
> Temp(const Scalar<N> &s)
2734,2735c2722,2723
< template <class Bin>
< Temp(const Average<Bin> &s)
---
> template <int N>
> Temp(const Average<N> &s)
2742,2743c2730,2731
< template <class Bin>
< Temp(const Vector<Bin> &s)
---
> template <int N>
> Temp(const Vector<N> &s)
2756,2758c2744,2746
< template <class Storage, class Bin>
< Temp(const ScalarProxy<Storage, Bin> &p)
< : node(new ScalarProxyNode<Storage, Bin>(p)) { }
---
> template <class Stat>
> Temp(const ScalarProxy<Stat> &p)
> : node(new ScalarProxyNode<Stat>(p)) { }