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

BCDataPoint.cxx

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

Generated by  doxygen 1.7.1