|
[yoda-svn] r284 - trunk/include/YODAblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Aug 18 17:28:07 BST 2011
Author: mkawalec Date: Thu Aug 18 17:28:07 2011 New Revision: 284 Log: Made _isGrid to be a bool with its value regenerated after every change to Axis2D. This way the speedup works for general case as just a variable needs to be read and not a function called. Modified: trunk/include/YODA/Axis2D.h trunk/include/YODA/Histo2D.h Modified: trunk/include/YODA/Axis2D.h ============================================================================== --- trunk/include/YODA/Axis2D.h Thu Aug 18 17:16:04 2011 (r283) +++ trunk/include/YODA/Axis2D.h Thu Aug 18 17:28:07 2011 (r284) @@ -76,7 +76,7 @@ /// Constructor provided with a vector of bin delimiters Axis2D(const vector<Segment>& binLimits) { _mkAxis(binLimits); - if(_isGrid()) _setOutflows(); + if(_isGrid) _setOutflows(); } @@ -115,7 +115,7 @@ _bins[i] = bins[i]; } _regenDelimiters(); - if(_isGrid()) _setOutflows(); + if(_isGrid) _setOutflows(); _outflows = outflows; _dbn = totalDbn; @@ -373,7 +373,7 @@ /// interest. const int getBinIndex(double coordX, double coordY) const { /// In case we are just operating on a regular grid - if(_isGrid()) { + if(_isGrid) { coordX += 0.00000000001; coordY += 0.00000000001; size_t indexY = (*_binHashSparse.first._cache.lower_bound(approx(coordY))).second; @@ -579,7 +579,7 @@ /// inner subcaches and half of this amount in the outer (grid boundary) /// subcaches. This makes _isGrid() a very, very fast function. /// @todo This is far too big to be inline: move it to the .cc - bool _isGrid() const { + void _genGridCache() { /// Check if the number of edges parallel to X axis /// is proper in every subcache. @@ -587,11 +587,11 @@ for (size_t i = 1; i < _binHashSparse.first.size(); ++i) { if (i == _binHashSparse.first.size() - 1) { if (_binHashSparse.first[i].second.size() != sizeX) { - return false; + _isGrid = false; } } else if (_binHashSparse.first[i].second.size() != 2*sizeX) { - return false; + _isGrid = false; } } @@ -600,16 +600,16 @@ for (size_t i=1; i < _binHashSparse.second.size(); ++i) { if (i != _binHashSparse.second.size() - 1) { if (2*sizeY != _binHashSparse.second[i].second.size()) { - return false; + _isGrid = false; } } else if (_binHashSparse.second[i].second.size() != sizeY) { - return -1; + _isGrid = false; } } /// If everything is proper, announce it. - return true; + _isGrid = true; } @@ -915,6 +915,7 @@ _binHashSparse.first.regenCache(); _binHashSparse.second.regenCache(); _regenDelimiters(); + _genGridCache(); } @@ -976,6 +977,9 @@ /// Low/high edges double _highEdgeX, _highEdgeY, _lowEdgeX, _lowEdgeY; + /// Is it a grid? + bool _isGrid; + }; Modified: trunk/include/YODA/Histo2D.h ============================================================================== --- trunk/include/YODA/Histo2D.h Thu Aug 18 17:16:04 2011 (r283) +++ trunk/include/YODA/Histo2D.h Thu Aug 18 17:28:07 2011 (r284) @@ -296,7 +296,7 @@ /// @todo Need to check that there is a continuous row for this y /// @todo Change the name! Histo1D cutterX(double atY, const std::string& path="", const std::string& title="") { - if (!_axis._isGrid()) throw GridError("I cannot cut a Histo2D that is not a grid!"); + if (!_axis._isGrid) throw GridError("I cannot cut a Histo2D that is not a grid!"); if (atY < lowEdgeY() || atY > highEdgeY()) throw RangeError("Y is outside the grid"); vector<HistoBin1D> tempBins; @@ -325,7 +325,7 @@ /// @todo Need to check that there is a continuous column for this x /// @todo Change the name! Histo1D cutterY(double atX, const std::string& path="", const std::string& title="") { - if (!_axis._isGrid()) throw GridError("I cannot cut a Histo2D that is not a grid!"); + if (!_axis._isGrid) throw GridError("I cannot cut a Histo2D that is not a grid!"); if (atX < lowEdgeX() || atX > highEdgeX()) throw RangeError("X is outside the grid"); vector<HistoBin1D> tempBins; @@ -349,7 +349,7 @@ /// @brief X-wise Profile1D creator from Histo2D Profile1D mkProfileX() { - if (!_axis._isGrid()) throw GridError("Profile1D cannot be made from a histogram that is not a grid!"); + if (!_axis._isGrid) throw GridError("Profile1D cannot be made from a histogram that is not a grid!"); vector<ProfileBin1D> prof; for(int i = lowEdgeX() + _axis.bin(0).midpoint().first; i < highEdgeX(); i+= _axis.bin(0).widthX()) { @@ -385,7 +385,7 @@ /// @brief Y-wise Profile1D creator from Histo2D Profile1D mkProfileY() { - if (!_axis._isGrid()) throw GridError("Profile1D cannot be made from a histogram that is not a grid!"); + if (!_axis._isGrid) throw GridError("Profile1D cannot be made from a histogram that is not a grid!"); vector<ProfileBin1D> prof; for(int i = lowEdgeY() + _axis.bin(0).midpoint().second; i < highEdgeY(); i+= _axis.bin(0).widthY()) {
More information about the yoda-svn mailing list |