00001
00002
00003 #include "osl/stat/activityCount.h"
00004 #include <algorithm>
00005 #include <cstdio>
00006
00007 osl::stat::
00008 ActivityCount::ActivityCount(unsigned int l)
00009 : counts(new int[l]), length(l)
00010 {
00011 std::fill(&counts[0], &counts[l], 0);
00012 }
00013
00014 osl::stat::
00015 ActivityCount::~ActivityCount()
00016 {
00017 }
00018
00019 void osl::stat::
00020 ActivityCount::clear()
00021 {
00022 std::fill(&counts[0], &counts[length], 0);
00023 }
00024
00025 void osl::stat::
00026 ActivityCount::setBinary(int threshold)
00027 {
00028 unsigned int actives = 0;
00029 for (unsigned int i=0; i<length; ++i)
00030 {
00031 if (counts[i] >= threshold)
00032 {
00033 ++actives;
00034 counts[i] = 1;
00035 }
00036 else
00037 {
00038 counts[i] = 0;
00039 }
00040 }
00041 fprintf(stderr, "active count %d\n", actives);
00042 }
00043
00044 void osl::stat::
00045 ActivityCount::loadBinary(const char *filename, int threshold)
00046 {
00047 clear();
00048 FILE *fp = fopen(filename, "r");
00049 assert(fp);
00050 for (unsigned int i=0; i<length; ++i)
00051 {
00052 int occur;
00053 fscanf(fp, "%d", &occur);
00054 counts[i] = (occur >= threshold) ? 1 : 0;
00055 }
00056 fclose(fp);
00057 }
00058
00059 void osl::stat::
00060 ActivityCount::show(const char *filename) const
00061 {
00062 FILE *fp = fopen(filename, "w");
00063 assert(fp);
00064 for (unsigned int i=0; i<length; ++i)
00065 {
00066 fprintf(fp, "%d\n", counts[i]);
00067 }
00068 fclose(fp);
00069 }
00070
00071
00072
00073
00074
00075