|
[yoda-svn] r477 - in trunk: . include/YODAblackhole at projects.hepforge.org blackhole at projects.hepforge.orgMon Jul 2 23:58:09 BST 2012
Author: buckley Date: Mon Jul 2 23:58:08 2012 New Revision: 477 Log: More incremental progress toward a working 2D bin hash mechanism. Modified: trunk/ChangeLog trunk/include/YODA/Axis2D.h Modified: trunk/ChangeLog ============================================================================== --- trunk/ChangeLog Mon Jul 2 23:38:03 2012 (r476) +++ trunk/ChangeLog Mon Jul 2 23:58:08 2012 (r477) @@ -1,3 +1,7 @@ +2012-07-02 Andy Buckley <andy.buckley at cern.ch> + + * More incremental progress toward a working 2D bin hash mechanism. + 2012-05-03 Andy Buckley <andy.buckley at cern.ch> * Adding nice constructor behaviours to the Histo1D and Profile2D Modified: trunk/include/YODA/Axis2D.h ============================================================================== --- trunk/include/YODA/Axis2D.h Mon Jul 2 23:38:03 2012 (r476) +++ trunk/include/YODA/Axis2D.h Mon Jul 2 23:58:08 2012 (r477) @@ -40,7 +40,7 @@ /// @brief Type used to implement a search table of low bin edges (in 2D) mapped to bin indices. /// An index of -1 indicates a gap interval, without a corresponding bin. - typedef std::map<double, int> SubBinHash; + typedef std::map<double, long int> SubBinHash; typedef std::map<double, SubBinHash> BinHash; //@} @@ -543,29 +543,54 @@ /// /// The bin hash is purely for searching, and is generated from the bins list only. void _updateAxis() { - std::sort(_bins.begin(), _bins.end()); - _binhash.clear(); - /// @todo Create a double hash based on the two sets of low edges - - /// @todo First, set up the collection of low edges based on all unique edges + /// First, set up the collection of low edges based on all unique edges std::vector<double> xedges, yedges; + std::sort(_bins.begin(), _bins.end()); for (size_t i = 0; i < numBins(); ++i) { xedges.push_back(bin(i).xMin()); + xedges.push_back(bin(i).xMax()); // only the unique max edges will "survive" yedges.push_back(bin(i).yMin()); + yedges.push_back(bin(i).xMax()); // only the unique max edges will "survive" } std::unique(xedges.begin(), xedges.end()); std::unique(yedges.begin(), yedges.end()); - for (size_t i = 0; i < numBins(); ++i) { - // Add low edge hash for each bin - //_binhash[bin(i).xMin()] = i; + // Create a double-map hash based on the two sets of low edges. Initialize with null bin indices. + _binhash.clear(); + for (size_t ix = 0; ix < xedges.size() - 1; ++ix) { + _binhash[xedges[ix]] = SubBinHash(); + for (size_t iy = 0; iy < yedges.size() - 1; ++iy) { + _binhash[xedges[ix]][yedges[iy]] = -1; + } + } - /// @todo Make a 2D version of this gap detection, allowing for duplicate indices + // Loop over bins, setting each one's non-null bin index appropriately in the double-hashmap. + for (size_t ib = 0; ib < numBins(); ++ib) { - // If the next bin is not contiguous, add a gap index for the high edge of this bin - if (i+1 < numBins() && !fuzzyEquals(bin(i).xMax(), bin(i+1).xMin())) { - //_binhash[bin(i).xMax()] = -1; + // Find the axis low edges contained within this bin + const double xmin(bin(ib).xMin()), ymin(bin(ib).xMin()); + std::vector<double> xlowedges_in_bin, ylowedges_in_bin; + /// @todo STL alg for this? + for (size_t ix = 0; ix < xedges.size() - 1; ++ix) { + if (xedges[ix] >= xmin) xlowedges_in_bin.push_back(xedges[ix]); + } + /// @todo STL alg for this? + for (size_t iy = 0; iy < yedges.size() - 1; ++iy) { + if (yedges[iy] >= ymin) ylowedges_in_bin.push_back(yedges[iy]); + } + + // Set bin indices + for (std::vector<double>::const_iterator x = xlowedges_in_bin.begin(); x != xlowedges_in_bin.end(); ++x) { + for (std::vector<double>::const_iterator y = ylowedges_in_bin.begin(); y != ylowedges_in_bin.end(); ++y) { + _binhash[*x][*y] = ib; + } } + + /// @todo Make a 2D version of this gap detection, allowing for duplicate indices + // If the next bin is not contiguous, add a gap index for the high edge of this bin + // if (i+1 < numBins() && !fuzzyEquals(bin(i).xMax(), bin(i+1).xMin())) { + // _binhash[bin(i).xMax()] = -1; + // } } }
More information about the yoda-svn mailing list |