• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

BCDataPoint.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008-2010, 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, TString::Format(
00055             "BCDataPoint::GetValue : Index %d out of range (%d to %d).", index,
00056             0, fData.size()-1));
00057 
00058    return value;
00059 }
00060 
00061 // ---------------------------------------------------------
00062 
00063 void BCDataPoint::SetValue(int index, double value)
00064 {
00065 // this is not good at all
00066 // -1 can be ok value
00067 // and one can turn off warnings
00068 // so if index is out of range the program should stop
00069 
00070    // check if index is in range. set value if true ...
00071    if (index >= 0 && index < int(fData.size()))
00072       fData[index] = value;
00073    // ... or give warning if not.
00074    else
00075       BCLog::Out(BCLog::warning, BCLog::warning,TString::Format(
00076             "BCDataPoint::SetValue : Index %d out of range (%d to %d).",
00077             index, 0 ,fData.size()-1));
00078 }
00079 
00080 // ---------------------------------------------------------
00081 
00082 void BCDataPoint::SetValues(std::vector <double> values)
00083 {
00084    // check if sizes are the same. if true, clear the data point and copy from
00085    // the vector passed to the method ...
00086    if (values.size() == fData.size())
00087    {
00088       fData.clear();
00089       for (std::vector<double>::const_iterator it = values.begin(); it != values.end(); ++it)
00090          fData.push_back(*it);
00091    }
00092    // ... or give warning if the size if not the same.
00093    else
00094       BCLog::Out(BCLog::warning, BCLog::warning,"BCDataPoint::SetValues : Vectors have different ranges.");
00095 }
00096 
00097 // ---------------------------------------------------------
00098 
00099 

Generated on Mon Aug 30 2010 22:14:54 for Bayesian Analysis Toolkit by  doxygen 1.7.1