BayesianAnalysisToolkit
0.9.3
Main Page
Namespaces
Classes
Files
File List
File Members
src
BCDataPoint.cxx
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2007-2013, the BAT core developer team
3
* All rights reserved.
4
*
5
* For the licensing terms see doc/COPYING.
6
* For documentation see http://mpp.mpg.de/bat
7
*/
8
9
// ---------------------------------------------------------
10
11
#include "
BCDataPoint.h
"
12
#include "
BCLog.h
"
13
14
#include <TString.h>
15
16
#include <cstdlib>
17
18
// ---------------------------------------------------------
19
BCDataPoint::BCDataPoint
(
int
nvariables)
20
{
21
// assign the specified number of variables to the data
22
// point and fill with zero
23
fData
.assign(nvariables, 0.);
24
}
25
26
// ---------------------------------------------------------
27
BCDataPoint::BCDataPoint
(
const
std::vector<double> & x)
28
{
29
// copy all values of x to the data point
30
fData
= x;
31
}
32
33
// ---------------------------------------------------------
34
double
BCDataPoint::GetValue
(
unsigned
index)
const
35
{
36
double
value;
37
38
// check if index is in range. return value if true ...
39
if
(index <
fData
.size())
40
value =
fData
[index];
41
// ... or give error if not.
42
else
{
43
// exit on error
44
BCLog::OutError
(
45
Form(
"BCDataPoint::GetValue : Index %u out of range (%u to %u)."
,
46
index, 0,
unsigned
(
fData
.size()-1)));
47
exit(1);
48
}
49
50
return
value;
51
}
52
53
// ---------------------------------------------------------
54
void
BCDataPoint::SetValue
(
unsigned
index,
double
value)
55
{
56
// check if index is in range. set value if true ...
57
if
(index <
fData
.size())
58
fData
[index] = value;
59
// ... or give error if not.
60
else
{
61
// exit on error
62
BCLog::OutError
(
63
Form(
"BCDataPoint::SetValue : Index %u out of range (%u to %u)."
,
64
index, 0 ,
unsigned
(
fData
.size()-1)));
65
exit(1);
66
}
67
}
68
69
// ---------------------------------------------------------
70
void
BCDataPoint::SetValues
(
const
std::vector<double> & values)
71
{
72
// check if sizes are the same. if true, clear the data point and copy from
73
// the vector passed to the method ...
74
if
(values.size() ==
fData
.size())
75
{
76
fData
= values;
77
}
78
// ... or give error if the size if not the same.
79
else
{
80
BCLog::OutError
(
"BCDataPoint::SetValues : Vectors have different ranges."
);
81
exit(1);
82
}
83
}
Generated by
1.8.4