BCDataPoint.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008, Daniel Kollar and Kevin Kroeninger.
00003  * All rights reserved.
00004  *
00005  * For the licensing terms see doc/COPYING.
00006  */
00007 
00008 // ---------------------------------------------------------
00009 
00010 #include "BAT/BCDataPoint.h"
00011 
00012 #include "BAT/BCLog.h"
00013 
00014 #include <TString.h>
00015 
00016 // ---------------------------------------------------------
00017 
00018 BCDataPoint::BCDataPoint(int nvariables)
00019 {
00020    // assign the specified number of variables to the data
00021    // point and fill with zero
00022    fData.assign(nvariables, 0.);
00023 }
00024 
00025 // ---------------------------------------------------------
00026 
00027 BCDataPoint::BCDataPoint(std::vector<double> x)
00028 {
00029    // copy all values of x to the data point
00030    for (std::vector<double>::const_iterator it = x.begin(); it != x.end(); ++it)
00031       fData.push_back(*it);
00032 }
00033 
00034 // ---------------------------------------------------------
00035 
00036 BCDataPoint::~BCDataPoint()
00037 {}
00038 
00039 // ---------------------------------------------------------
00040 
00041 double BCDataPoint::GetValue(int index)
00042 {
00043 // this is not good at all
00044 // -1 can be ok value
00045 // and one can turn off warnings
00046 // so if index is out of range the program should stop
00047    double value = -1.0;
00048 
00049    // check if index is in range. return value if true ...
00050    if (index >= 0 && index < int(fData.size()))
00051       value = fData[index];
00052    // ... or give warning if not.
00053    else
00054       BCLog::Out(BCLog::warning, BCLog::warning,
00055             TString::Format("BCDataPoint::GetValue : Index %d out of range (%d to %d).",index,0,fData.size()));
00056 
00057    return value;
00058 }
00059 
00060 // ---------------------------------------------------------
00061 
00062 void BCDataPoint::SetValue(int index, double value)
00063 {
00064 // this is not good at all
00065 // -1 can be ok value
00066 // and one can turn off warnings
00067 // so if index is out of range the program should stop
00068 
00069    // check if index is in range. set value if true ...
00070    if (index >= 0 && index < int(fData.size()))
00071       fData[index] = value;
00072    // ... or give warning if not.
00073    else
00074       BCLog::Out(BCLog::warning, BCLog::warning,
00075             TString::Format("BCDataPoint::SetValue : Index %d out of range (%d to %d).",index,0,fData.size()));
00076 }
00077 
00078 // ---------------------------------------------------------
00079 
00080 void BCDataPoint::SetValues(std::vector <double> values)
00081 {
00082    // check if sizes are the same. if true, clear the data point and copy from
00083    // the vector passed to the method ...
00084    if (values.size() == fData.size())
00085    {
00086       fData.clear();
00087       for (std::vector<double>::const_iterator it = values.begin(); it != values.end(); ++it)
00088          fData.push_back(*it);
00089    }
00090    // ... or give warning if the size if not the same.
00091    else
00092       BCLog::Out(BCLog::warning, BCLog::warning,"BCDataPoint::SetValues. vectors have different ranges.");
00093 }
00094 
00095 // ---------------------------------------------------------
00096 
00097 

Generated on Thu Feb 11 11:29:30 2010 for BayesianAnalysisToolkit by  doxygen 1.5.1