MINT2
Weights.cpp
Go to the documentation of this file.
1 #include "Mint/Weights.h"
2 
6 {
7 
8 }
9 
12 Weights::Weights(double weight) :
13  _weights(1, weight)
14 {
15 
16 }
17 
20 int Weights::numWeights() const{
21  return _weights.size();
22 }
23 
26 void Weights::printWeight(std::ostream& os, int endline) const{
27  if (numWeights() != 0){
28  os << "weights = ";
29  for (int i = 0; i < numWeights(); i++) {
30  os << getWeight(i);
31  if (i != (numWeights() -1)) os << ", ";
32  }
33  }
34  if(endline == 1) os << std::endl;
35 
36 }
37 
40 double Weights::getWeight(int i) const{
41  if ( numWeights() == 0 && i == 0) return 1.0; //If no weights, assume it's unweighted i.e. w = 1.0
42  if (i >= numWeights()){
43  ERROR_LOG << "There are not this many weights avaliable. Returning weight 0 - may crash if this doesn't exist";
44  return _weights.at(0);
45  }
46  return _weights.at(i);
47 }
48 
49 
52 void Weights::setWeight(int i, double w){
53 
54  if (i >= numWeights()) {
55  addWeight(1.0);
56  setWeight(i, w);
57  }
58  else{
59  _weights.at(i) = w;
60  }
61 }
62 
65 void Weights::setWeight(double w){
66  setWeight(0, w);
67 }
68 
71 void Weights::addWeight(const double& weight){
72  _weights.push_back(weight);
73 }
74 
76 
77 }
78 
virtual ~Weights()
Definition: Weights.cpp:75
void setWeight(int i, double w)
Definition: Weights.cpp:52
void addWeight(const double &weight)
Definition: Weights.cpp:71
#define ERROR_LOG
int numWeights() const
Definition: Weights.cpp:20
std::vector< double > _weights
Definition: Weights.h:27
double getWeight(int i=0) const
Definition: Weights.cpp:40
void printWeight(std::ostream &os=std::cout, int endline=1) const
Definition: Weights.cpp:26
Weights()
Definition: Weights.cpp:5