PSHist/src/Axis.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: Axis.cpp 2050 2011-06-29 21:30:05Z salnikov@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class Axis...
00007 //
00008 // Author List:
00009 //      Andy Salnikov
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "PSHist/Axis.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 #include <iostream>
00022 
00023 //-------------------------------
00024 // Collaborating Class Headers --
00025 //-------------------------------
00026 #include "PSHist/Exceptions.h"
00027 
00028 //-----------------------------------------------------------------------
00029 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00030 //-----------------------------------------------------------------------
00031 
00032 //              ----------------------------------------
00033 //              -- Public Function Member Definitions --
00034 //              ----------------------------------------
00035 
00036 namespace PSHist {
00037 
00038 //----------------
00039 // Constructors --
00040 //----------------
00041 Axis::Axis(unsigned nbins, double amin, double amax)
00042   : m_amin(amin)
00043   , m_amax(amax)
00044   , m_nbins(nbins)
00045   , m_edges()
00046 {
00047   if (m_nbins == 0) throw ExceptionBins(ERR_LOC);
00048   if (m_amin >= m_amax) throw ExceptionAxisRange(ERR_LOC, m_amin, m_amax);
00049 }
00050 
00051 Axis::Axis(unsigned nbins, const double *edges)
00052   : m_amin()
00053   , m_amax()
00054   , m_nbins(nbins)
00055   , m_edges(edges, edges+nbins+1)
00056 {
00057   if (m_nbins == 0) throw ExceptionBins(ERR_LOC);
00058   // check that it is in increasing order
00059   for (const double* edge = edges; edge != edges+nbins; ++ edge) {
00060     if (*edge >= *(edge+1)) throw ExceptionAxisEdgeOrder(ERR_LOC);
00061   }
00062 }
00063 
00064 const double* 
00065 Axis::edges() const
00066 { 
00067   if (m_edges.empty()) return 0; 
00068   return &m_edges[0];
00069 }
00070 
00071 // print data members
00072 void 
00073 Axis::print(std::ostream& out) const
00074 {
00075   out << "=========================================================\n";
00076   if (m_edges.empty()) { 
00077     out << "Axis with equal bin sizes\n";
00078   } else {
00079     out << "Axis with variable bin sizes\n";
00080   }
00081   out << "Axis::m_nbins=" << m_nbins << " m_amin="  << m_amin << " m_amax="  << m_amax  << '\n';
00082   if (not m_edges.empty()) {
00083     out << "Axis::m_edges[0]=" << m_edges[0] << " m_edges[N]=" << m_edges[m_nbins] << '\n';
00084   }
00085   out << "=========================================================\n";
00086 }
00087 
00088 } // namespace PSHist

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7