-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistogramCollection.h
More file actions
69 lines (62 loc) · 1.92 KB
/
HistogramCollection.h
File metadata and controls
69 lines (62 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <vector>
#include <stdio.h>
#include "Histogram.h"
using namespace std;
class HistogramCollection{
private:
vector<Histogram*> hists; //collection of histograms
public:
HistogramCollection (){
hists.clear();
}
void add (Histogram* h){
hists.push_back (h);
}
void print (){
int nhists = hists.size();
if (nhists <= 0){
cout << "Histogram collection is empty" << endl;
return;
}
int sum [nhists];
memset (sum, 0, nhists * sizeof (int));
int nbins = hists [0]->size(); // number of bins in each hist
vector<double> range = hists [0]->get_range();
float delta = (range[1] - range [0])/nbins;
float st = range [0];
int ndots = 15 + nhists * 6;
for (int i=0; i< ndots; i++)
cout << "-";
cout << endl;
for (int i=0; i<nbins; i++){
printf ("[%5.2f,%5.2f): ", st, st + delta);
for (int j=0; j<nhists; j++){
cout << setw(5) << hists[j]->get_hist()[i] << " ";
sum [j] += hists[j]->get_hist()[i];
}
cout << endl;
st += delta;
}
//cout << "--------------------------------------------------------------------------------------" << endl;
for (int i=0; i< ndots; i++)
cout << "-";
cout << endl;
printf ("[%5.2f,%5.2f): ", range[0], range[1]);
for (int j=0; j<nhists; j++){
cout << setw(5) << sum [j] << " ";
}
cout << endl;
}
void update(int person, double val){
hists[person]->m.lock();
hists[person]->update(val);
hists[person]->m.unlock();
}
void fillHist(int num){ //fills the histogram with empty hists
for(int i =0;i<num;i++){
Histogram* a = new Histogram(10,-2,2);
add(a);
}
}
};