MINT2
Public Member Functions | Protected Attributes | List of all members
Weights Class Reference

#include <Weights.h>

Inheritance diagram for Weights:
HyperPoint

Public Member Functions

 Weights ()
 
 Weights (double weight)
 
int numWeights () const
 
const std::vector< double > & getWeightsVector ()
 
void printWeight (std::ostream &os=std::cout, int endline=1) const
 
double getWeight (int i=0) const
 
void setWeight (int i, double w)
 
void setWeight (double w)
 
void addWeight (const double &weight)
 
virtual ~Weights ()
 

Protected Attributes

std::vector< double > _weights
 

Detailed Description

HyperPlot, Author: Sam Harnew, sam.h.nosp@m.arne.nosp@m.w@gma.nosp@m.il.c.nosp@m.om , Date: Dec 2015

Holds a vector of weights that is associtated to a HyperPoint via inheritance (sometimes useful to have more than one for systematic studies)

Definition at line 23 of file Weights.h.

Constructor & Destructor Documentation

◆ Weights() [1/2]

Weights::Weights ( )

Empty constructor

Definition at line 5 of file Weights.cpp.

6 {
7 
8 }

◆ Weights() [2/2]

Weights::Weights ( double  weight)

Construct instance with a single weight (probably the most used scenario)

Definition at line 12 of file Weights.cpp.

12  :
13  _weights(1, weight)
14 {
15 
16 }
std::vector< double > _weights
Definition: Weights.h:27

◆ ~Weights()

Weights::~Weights ( )
virtual

Definition at line 75 of file Weights.cpp.

75  {
76 
77 }

Member Function Documentation

◆ addWeight()

void Weights::addWeight ( const double &  weight)

Add weight to the end of the weight vector

Definition at line 71 of file Weights.cpp.

71  {
72  _weights.push_back(weight);
73 }
std::vector< double > _weights
Definition: Weights.h:27

◆ getWeight()

double Weights::getWeight ( int  i = 0) const

Get weight i. If no weights exist just return 1.0.

Definition at line 40 of file Weights.cpp.

40  {
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 }
#define ERROR_LOG
int numWeights() const
Definition: Weights.cpp:20
std::vector< double > _weights
Definition: Weights.h:27

◆ getWeightsVector()

const std::vector<double>& Weights::getWeightsVector ( )
inline

return the vector of weights

Definition at line 36 of file Weights.h.

◆ numWeights()

int Weights::numWeights ( ) const

How many weights have been stored

Definition at line 20 of file Weights.cpp.

20  {
21  return _weights.size();
22 }
std::vector< double > _weights
Definition: Weights.h:27

◆ printWeight()

void Weights::printWeight ( std::ostream &  os = std::cout,
int  endline = 1 
) const

print weights to specified ostream (default is cout)

Definition at line 26 of file Weights.cpp.

26  {
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 }
int numWeights() const
Definition: Weights.cpp:20
double getWeight(int i=0) const
Definition: Weights.cpp:40

◆ setWeight() [1/2]

void Weights::setWeight ( int  i,
double  w 
)

Set weight i to specified value - if this weight doesn't yet exist, keep adding weights of 1.0 until it does

Definition at line 52 of file Weights.cpp.

52  {
53 
54  if (i >= numWeights()) {
55  addWeight(1.0);
56  setWeight(i, w);
57  }
58  else{
59  _weights.at(i) = w;
60  }
61 }
void setWeight(int i, double w)
Definition: Weights.cpp:52
void addWeight(const double &weight)
Definition: Weights.cpp:71
int numWeights() const
Definition: Weights.cpp:20
std::vector< double > _weights
Definition: Weights.h:27

◆ setWeight() [2/2]

void Weights::setWeight ( double  w)

Set weight i=0 to desired value

Definition at line 65 of file Weights.cpp.

65  {
66  setWeight(0, w);
67 }
void setWeight(int i, double w)
Definition: Weights.cpp:52

Member Data Documentation

◆ _weights

std::vector<double> Weights::_weights
protected

vector of weights

Definition at line 27 of file Weights.h.


The documentation for this class was generated from the following files: