[yoda-svn] r234 - in trunk/include/YODA: . Utils

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Thu Aug 11 02:00:28 BST 2011


Author: buckley
Date: Thu Aug 11 02:00:27 2011
New Revision: 234

Log:
Remove accidental implicit std namespace in headers and add many missing std:: declarations, and add persistency constructors to Histo1D and Axis1D.

Modified:
   trunk/include/YODA/Axis1D.h
   trunk/include/YODA/Histo1D.h
   trunk/include/YODA/Histo2D.h
   trunk/include/YODA/ReaderAIDA.h
   trunk/include/YODA/Utils/StringUtils.h

Modified: trunk/include/YODA/Axis1D.h
==============================================================================
--- trunk/include/YODA/Axis1D.h	Thu Aug 11 01:35:04 2011	(r233)
+++ trunk/include/YODA/Axis1D.h	Thu Aug 11 02:00:27 2011	(r234)
@@ -16,8 +16,6 @@
 #include <cmath>
 #include <algorithm>
 
-using namespace std;
-
 namespace YODA {
 
 
@@ -46,42 +44,6 @@
     //@}
 
 
-  private:
-
-    /// @todo Remove
-    void _mkBinHash() {
-      for (size_t i = 0; i < numBins(); i++) {
-        // Insert upper bound mapped to bin ID
-        _binHash.insert(make_pair(_cachedBinEdges[i+1],i));
-      }
-    }
-
-
-    void _mkAxis(const vector<double>& binedges) {
-      const size_t nbins = binedges.size() - 1;
-      for (size_t i = 0; i < nbins; ++i) {
-        _bins.insert( BIN1D(binedges.at(i), binedges.at(i+1)) );
-      }
-
-      /// @todo Remove
-      _cachedBinEdges = binedges;
-      std::sort(_cachedBinEdges.begin(), _cachedBinEdges.end());
-      _mkBinHash();
-    }
-
-
-    void _mkAxis(const Bins& bins) {
-      _bins = bins;
-
-      /// @todo Remove
-      for (size_t i = 0; i < bins.size(); ++i) {
-        _cachedBinEdges.push_back(bins.at(i).lowEdge());
-      }
-      _cachedBinEdges.push_back(bins.back().highEdge());
-      _mkBinHash();
-    }
-
-
   public:
 
 
@@ -92,7 +54,7 @@
 
     /// Constructor with a list of bin edges
     /// @todo Accept a general iterable and remove this silly special-casing for std::vector
-    Axis1D(const vector<double>& binedges) {
+    Axis1D(const std::vector<double>& binedges) {
       assert(binedges.size() > 1);
       _mkAxis(binedges);
     }
@@ -106,18 +68,21 @@
 
 
     /// @todo Accept a general iterable and remove this silly special-casing for std::vector
-    Axis1D(const vector<BIN1D>& bins) {
+    Axis1D(const std::vector<BIN1D>& bins) {
       assert(!bins.empty());
       Bins sbins;
-      for (typename vector<BIN1D>::const_iterator b = bins.begin(); b != bins.end(); ++b) {
+      for (typename std::vector<BIN1D>::const_iterator b = bins.begin(); b != bins.end(); ++b) {
         sbins.insert(*b);
       }
       _mkAxis(sbins);
     }
 
 
-    /// @todo Accept a general iterable (and remove this internal detail special-casing?)
-    Axis1D(const Bins& bins) {
+    /// @brief State-setting constructor
+    /// Principally intended for internal persistency use.
+    Axis1D(const Bins& bins, const Dbn1D& dbn_tot, const Dbn1D& dbn_uflow, const Dbn1D& dbn_oflow)
+      : _dbn(dbn_tot), _underflow(dbn_uflow), _overflow(dbn_oflow)
+    {
       assert(!bins.empty());
       _mkAxis(bins);
     }
@@ -149,7 +114,7 @@
 
     std::pair<double,double> binEdges(size_t binId) const {
       assert(binId < numBins());
-      return make_pair(_cachedBinEdges[binId], _cachedBinEdges[binId+1]);
+      return std::make_pair(_cachedBinEdges[binId], _cachedBinEdges[binId+1]);
     }
 
 
@@ -321,6 +286,42 @@
 
   private:
 
+    /// @todo Remove
+    void _mkBinHash() {
+      for (size_t i = 0; i < numBins(); i++) {
+        // Insert upper bound mapped to bin ID
+        _binHash.insert(std::make_pair(_cachedBinEdges[i+1],i));
+      }
+    }
+
+
+    void _mkAxis(const std::vector<double>& binedges) {
+      const size_t nbins = binedges.size() - 1;
+      for (size_t i = 0; i < nbins; ++i) {
+        _bins.insert( BIN1D(binedges.at(i), binedges.at(i+1)) );
+      }
+
+      /// @todo Remove
+      _cachedBinEdges = binedges;
+      std::sort(_cachedBinEdges.begin(), _cachedBinEdges.end());
+      _mkBinHash();
+    }
+
+
+    void _mkAxis(const Bins& bins) {
+      _bins = bins;
+
+      /// @todo Remove
+      for (size_t i = 0; i < bins.size(); ++i) {
+        _cachedBinEdges.push_back(bins.at(i).lowEdge());
+      }
+      _cachedBinEdges.push_back(bins.back().highEdge());
+      _mkBinHash();
+    }
+
+
+  private:
+
 
     /// @todo Store bins in a more flexible (and sorted) way
     /// @todo Check non-overlap of bins
@@ -334,14 +335,14 @@
     /// The bins contained in this histogram
     Bins _bins;
 
+    /// A distribution counter for the whole histogram
+    DBN _dbn;
+
     /// A distribution counter for overflow fills
     DBN _underflow;
     /// A distribution counter for underlow fills
     DBN _overflow;
 
-    /// A distribution counter for the whole histogram
-    DBN _dbn;
-
     /// Bin edges: lower edges, except last entry,
     /// which is the high edge of the last bin
     std::vector<double> _cachedBinEdges;

Modified: trunk/include/YODA/Histo1D.h
==============================================================================
--- trunk/include/YODA/Histo1D.h	Thu Aug 11 01:35:04 2011	(r233)
+++ trunk/include/YODA/Histo1D.h	Thu Aug 11 02:00:27 2011	(r234)
@@ -53,13 +53,13 @@
         _axis(binedges)
     { }
 
-    /// Constructor giving a vector of bins.
-    /// @todo Allow any iterable of bins (use Boost::Range?)
-    Histo1D(const std::vector<HistoBin1D>& bins,
-            const std::string& path="", const std::string& title="")
-      : AnalysisObject("Histo1D", path, title),
-        _axis(bins)
-    { }
+    // /// Constructor giving a vector of bins.
+    // /// @todo Allow any iterable of bins (use Boost::Range?)
+    // Histo1D(const std::vector<HistoBin1D>& bins,
+    //         const std::string& path="", const std::string& title="")
+    //   : AnalysisObject("Histo1D", path, title),
+    //     _axis(bins)
+    // { }
 
     /// Copy constructor with optional new path
     Histo1D(const Histo1D& h, const std::string& path="");
@@ -70,24 +70,20 @@
     /// Constructor from a Profile1D's binning, with optional new path
     Histo1D(const Profile1D& p, const std::string& path="");
 
+    /// @brief State-setting constructor.
+    /// Intended principally for internal persistency use.
+    Histo1D(const std::vector<HistoBin1D>& bins,
+            const Dbn1D& dbn_tot, const Dbn1D& dbn_uflow, const Dbn1D& dbn_oflow,
+            const std::string& path="", const std::string& title="")
+      : AnalysisObject("Histo1D", path, title),
+        _axis(bins, dbn_tot, dbn_uflow, dbn_oflow)
+    { }
+
     //@}
 
 
   public:
 
-    /// @name Persistency hooks
-    //@{
-
-    /// Get name of the analysis object type, for persisting
-    std::string type() const { return "Histo1D"; }
-
-    /// Set the state of the histo object, for unpersisting
-    /// @todo Need to set annotations (do that on AO), all-histo Dbns, and dbns for every bin. Delegate!
-    // void _setstate() = 0;
-
-    //@}
-
-
     /// @name Modifiers
     //@{
 

Modified: trunk/include/YODA/Histo2D.h
==============================================================================
--- trunk/include/YODA/Histo2D.h	Thu Aug 11 01:35:04 2011	(r233)
+++ trunk/include/YODA/Histo2D.h	Thu Aug 11 02:00:27 2011	(r234)
@@ -284,43 +284,49 @@
     /// @name Slicing operators
     //@{
 
-    /// Create a Histo1D for the bin slice parallel to the x axis at the specified y coordinate
+    /// @brief Create a Histo1D for the bin slice parallel to the x axis at the specified y coordinate
+    /// Note that the created histogram will not have correctly filled underflow and overflow bins.
     /// @todo It's not really *at* the specified y coord: it's for the corresponding bin row.
-    /// @todo Checking that there is such a thing as a continuous row?
+    /// @todo Need to check that there is a continuous row for this y
     /// @todo Change the name!
-    Histo1D cutterX(double atY) {
+    Histo1D cutterX(double atY, const std::string& path="", const std::string& title="") {
       if (atY < lowEdgeY() || atY > highEdgeY()) throw RangeError("Y is outside the grid");
       vector<HistoBin1D> tempBins;
       /// @todo Make all Bin1D constructions happen in loop, to reduce code duplication
       const HistoBin2D& first = binByCoord(lowEdgeX(), atY);
-      Dbn1D dbn(first.numEntries(), first.sumW(), first.sumW2(), first.sumWX(), first.sumWX2());
+      const Dbn1D dbn(first.numEntries(), first.sumW(), first.sumW2(), first.sumWX(), first.sumWX2());
       tempBins.push_back(HistoBin1D(first.lowEdgeX(), first.highEdgeX(), dbn));
       for (double i = first.xMax() + first.widthX()/2; i < highEdgeX(); i += first.widthX()) {
         const HistoBin2D& b2 = binByCoord(i, atY);
-        Dbn1D dbn2(b2.numEntries(), b2.sumW(), b2.sumW2(), b2.sumWX(), b2.sumWX2());
+        const Dbn1D dbn2(b2.numEntries(), b2.sumW(), b2.sumW2(), b2.sumWX(), b2.sumWX2());
         tempBins.push_back(HistoBin1D(b2.lowEdgeX(), b2.highEdgeX(), dbn2));
       }
-      return Histo1D(tempBins);
+      /// @todo Think about the total, underflow and overflow distributions
+      /// @todo Create total dbn from input bins
+      return Histo1D(tempBins, Dbn1D(), Dbn1D(), Dbn1D(), path, title);
     }
 
 
     /// Create a Histo1D for the bin slice parallel to the y axis at the specified x coordinate
+    /// Note that the created histogram will not have correctly filled underflow and overflow bins.
     /// @todo It's not really *at* the specified x coord: it's for the corresponding bin row.
-    /// @todo Checking that there is such a thing as a continuous row?
+    /// @todo Need to check that there is a continuous column for this x
     /// @todo Change the name!
-    Histo1D cutterY(double atX) {
+    Histo1D cutterY(double atX, const std::string& path="", const std::string& title="") {
       if (atX < lowEdgeX() || atX > highEdgeX()) throw RangeError("X is outside the grid");
       vector<HistoBin1D> tempBins;
       /// @todo Make all Bin1D constructions happen in loop, to reduce code duplication
       const HistoBin2D& first = binByCoord(atX, lowEdgeY());
-      Dbn1D dbn(first.numEntries(), first.sumW(), first.sumW2(), first.sumWX(), first.sumWX2());
+      const Dbn1D dbn(first.numEntries(), first.sumW(), first.sumW2(), first.sumWX(), first.sumWX2());
       tempBins.push_back(HistoBin1D(first.lowEdgeY(), first.highEdgeY(), dbn));
       for (double i = first.yMax() + first.widthY()/2; i < highEdgeY(); i += first.widthY()) {
         const HistoBin2D& b2 = binByCoord(atX, i);
-        Dbn1D dbn2(b2.numEntries(), b2.sumW(), b2.sumW2(), b2.sumWX(), b2.sumWX2());
+        const Dbn1D dbn2(b2.numEntries(), b2.sumW(), b2.sumW2(), b2.sumWX(), b2.sumWX2());
         tempBins.push_back(HistoBin1D(b2.lowEdgeY(), b2.highEdgeY(), dbn2));
       }
-      return Histo1D(tempBins);
+      /// @todo Think about the total, underflow and overflow distributions
+      /// @todo Create total dbn from input bins
+      return Histo1D(tempBins, Dbn1D(), Dbn1D(), Dbn1D(), path, title);
     }
 
 

Modified: trunk/include/YODA/ReaderAIDA.h
==============================================================================
--- trunk/include/YODA/ReaderAIDA.h	Thu Aug 11 01:35:04 2011	(r233)
+++ trunk/include/YODA/ReaderAIDA.h	Thu Aug 11 02:00:27 2011	(r234)
@@ -34,7 +34,7 @@
 
   protected:
 
-    void _readDoc(std::istream& stream, vector<AnalysisObject*>& aos);
+    void _readDoc(std::istream& stream, std::vector<AnalysisObject*>& aos);
     //void readGenericAO(std::istream& stream);
     // virtual void readHisto(std::istream& stream, const Histo1D& h);
     // virtual void readProfile(std::istream& stream, const Profile1D& p);

Modified: trunk/include/YODA/Utils/StringUtils.h
==============================================================================
--- trunk/include/YODA/Utils/StringUtils.h	Thu Aug 11 01:35:04 2011	(r233)
+++ trunk/include/YODA/Utils/StringUtils.h	Thu Aug 11 02:00:27 2011	(r234)
@@ -9,24 +9,26 @@
 namespace YODA {
   namespace Utils {
 
+
     /// Replace
-    inline string encodeForXML(const string& in) {
-      string out = in;
-      typedef pair<string, string> CharsToEntities;
-      vector<CharsToEntities> cs2es;
-      cs2es.push_back(make_pair("&", "&"));
-      cs2es.push_back(make_pair("<", "<"));
-      cs2es.push_back(make_pair(">", ">"));
-
-      for (vector<CharsToEntities>::const_iterator c2e = cs2es.begin(); c2e != cs2es.end(); ++c2e) {
-        string::size_type pos = -1;
-        while ( ( pos = out.find(c2e->first, pos + 1) ) != string::npos ) {
+    inline std::string encodeForXML(const std::string& in) {
+      std::string out = in;
+      typedef std::pair<std::string, std::string> CharsToEntities;
+      std::vector<CharsToEntities> cs2es;
+      cs2es.push_back(std::make_pair("&", "&"));
+      cs2es.push_back(std::make_pair("<", "<"));
+      cs2es.push_back(std::make_pair(">", ">"));
+
+      for (std::vector<CharsToEntities>::const_iterator c2e = cs2es.begin(); c2e != cs2es.end(); ++c2e) {
+        std::string::size_type pos = -1;
+        while ( ( pos = out.find(c2e->first, pos + 1) ) != std::string::npos ) {
           out.replace(pos, 1, c2e->second);
         }
       }
       return out;
     }
 
+
   }
 }
 


More information about the yoda-svn mailing list