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

BCDataPoint.cxx

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008-2012, 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 #include <cstdlib>
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 BCDataPoint::BCDataPoint(std::vector<double> x)
00027 {
00028    // copy all values of x to the data point
00029    for (std::vector<double>::const_iterator it = x.begin(); it != x.end(); ++it)
00030       fData.push_back(*it);
00031 }
00032 
00033 // ---------------------------------------------------------
00034 BCDataPoint::BCDataPoint(const BCDataPoint & datapoint)
00035 {
00036    // debugKK
00037    fData = datapoint.fData;
00038 }
00039 
00040 // ---------------------------------------------------------
00041 BCDataPoint::~BCDataPoint()
00042 {}
00043 
00044 // ---------------------------------------------------------
00045 BCDataPoint & BCDataPoint::operator = (const BCDataPoint & datapoint)
00046 {
00047    fData = datapoint.fData;
00048 
00049    // return this
00050    return *this;
00051 }
00052 
00053 // ---------------------------------------------------------
00054 double BCDataPoint::GetValue(int index)
00055 {
00056    double value;
00057 
00058    // check if index is in range. return value if true ...
00059    if (index >= 0 && index < int(fData.size()))
00060       value = fData[index];
00061    // ... or give error if not.
00062    else {
00063       // exit on error
00064       BCLog::OutError(
00065             Form("BCDataPoint::GetValue : Index %d out of range (%d to %d).",
00066                  index,0, (int)fData.size()-1));
00067       exit(1);
00068    }
00069 
00070    return value;
00071 }
00072 
00073 // ---------------------------------------------------------
00074 void BCDataPoint::SetValue(int index, double value)
00075 {
00076    // check if index is in range. set value if true ...
00077    if (index >= 0 && index < int(fData.size()))
00078       fData[index] = value;
00079    // ... or give error if not.
00080    else {
00081       // exit on error
00082       BCLog::OutError(
00083             Form("BCDataPoint::SetValue : Index %d out of range (%d to %d).",
00084                  index, 0 ,(int)fData.size()-1));
00085       exit(1);
00086    }
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       exit(1);
00104    }
00105 }
00106 
00107 // ---------------------------------------------------------
00108 
00109 

Generated by  doxygen 1.7.1