Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

FloatFunBinning.C

Go to the documentation of this file.
00001 
00033 #include "jbltools/sfh/FloatFunBinning.h"
00034 #include "jbltools/sfh/FloatFunBase.h"
00035 
00036 #include <cassert>
00037 #include <cmath>
00038 #include <string.h>
00039 #include <stdio.h>
00040 
00041 static const char *ident="@(#)$Id: FloatFunBinning.C,v 1.15 2006/06/30 11:05:00 blist Exp $";
00042 
00043 FloatFunBinning::FloatFunBinning (const FloatFunPoR& fun_, 
00044                                   int nbins_, 
00045                                   double xlow_, 
00046                                   double xhigh_, 
00047                                   const char *varname_)
00048 : BinningFun (nbins_, xlow_, xhigh_), 
00049   fun(fun_.pff), 
00050   varname(0), 
00051   varnamelength(0)
00052 { assert (getNBins() >= 1);
00053   assert (getNBins() < 999); // We were lazy!
00054   initvarname (varname_);
00055 }
00056 
00057 FloatFunBinning::FloatFunBinning (const FloatFunPoR& fun_, 
00058                                   int nbins_, 
00059                                   const float binedges_[], 
00060                                   const char *varname_)
00061 :  BinningFun (nbins_, binedges_), 
00062    fun(fun_.pff), 
00063    varname(0), 
00064    varnamelength(0) 
00065 {
00066   assert (getNBins() >= 1);
00067   assert (getNBins() < 999); // We were lazy!
00068   initvarname (varname_);
00069 }
00070 
00071 FloatFunBinning::FloatFunBinning (const FloatFunPoR& fun_, 
00072                                   int nbins_, 
00073                                   const double binedges_[], 
00074                                   const char *varname_)
00075 :  BinningFun (nbins_, binedges_), 
00076    fun(fun_.pff), 
00077    varname(0), 
00078    varnamelength(0) 
00079 {
00080   assert (getNBins() >= 1);
00081   assert (getNBins() < 999); // We were lazy!
00082   initvarname (varname_);
00083 }
00084 
00085 FloatFunBinning::FloatFunBinning (const FloatFunPoR& fun_, 
00086                                   const Binning& binning_, 
00087                                   const char *varname_)
00088 :  BinningFun (binning_), 
00089    fun(fun_.pff), 
00090    varname(0), 
00091    varnamelength(0) 
00092 {
00093   assert (getNBins() >= 1);
00094   assert (getNBins() < 999); // We were lazy!
00095   initvarname (varname_);
00096 }
00097 
00098 
00099 void FloatFunBinning::initvarname (const char *varname_) {
00100   if (!varname_) varname_ = "X";
00101   varnamelength = strlen (varname_);
00102   varname = new char[varnamelength+1]; 
00103   strncpy (varname, varname_, varnamelength+1);
00104   varname[varnamelength] = '\0'; 
00105 }                                  
00106 
00107 
00108 int FloatFunBinning::operator() () const {
00109   if (!fun) return -1; 
00110   return getBin ((*fun)()); 
00111 }   
00112 
00113     // returns a title string.
00114     // The title string MAY, and MUST, be destroyed by the user!
00115     // therefore: you MUST NOT return a string constant here, like "dummy"!
00116 const char *FloatFunBinning::getBinTitle(int i) const {
00117   size_t size = 20+varnamelength;
00118   char *title = new char [size];
00119   if (i < 0 || i > getNBins()) {
00120     snprintf (title, size, "illegal bin number!");
00121   } else if (i == getNBins()) {
00122     snprintf (title, size, "%4.2f < %s < %4.2f", 
00123               getLowerEdge(), varname, getUpperEdge());
00124   } else {
00125     assert (i >= 0 && i < getNBins());
00126     snprintf (title, size, "%4.2f < %s < %4.2f", 
00127               getLowerBinEdge(i), varname, getUpperBinEdge(i));
00128   }
00129   return title;
00130 }
00131     
00132     
00133 const char *FloatFunBinning::getBinName(int i) const{
00134   size_t size = 4;
00135   char *name = new char [size];
00136   if (i < 0 || i > getNBins()) {
00137     snprintf (name, size, "999");
00138   } else {
00139     assert (i >= 0 && i <= getNBins());
00140     snprintf (name, size, "%03d", i);
00141   }
00142   return name;
00143 }
00144     
00145 FloatFunBinning::~FloatFunBinning() {
00146   delete[] varname;
00147   varname = 0;
00148 }
00149 
00150 const FillIterator *FloatFunBinning::getIterator() const {  
00151   assert (fun);
00152   return fun->getIterator(); 
00153 }
00154 

Generated on Thu Oct 26 12:52:56 2006 for SFH by doxygen 1.3.2