|
[yoda-svn] r238 - in trunk: include/YODA src testsblackhole at projects.hepforge.org blackhole at projects.hepforge.orgSat Aug 13 10:37:22 BST 2011
Author: mkawalec Date: Sat Aug 13 10:37:21 2011 New Revision: 238 Log: Fixed the comments, removed some of the unnecessary caches, fixed building. More to come (and be fixed, for example division of histograms is left in nonworking state) today. Modified: trunk/include/YODA/Axis2D.h trunk/include/YODA/Histo2D.h trunk/src/Histo2D.cc trunk/tests/TestHisto2D.cc Modified: trunk/include/YODA/Axis2D.h ============================================================================== --- trunk/include/YODA/Axis2D.h Fri Aug 12 21:03:48 2011 (r237) +++ trunk/include/YODA/Axis2D.h Sat Aug 13 10:37:21 2011 (r238) @@ -12,6 +12,7 @@ #include <cassert> #include <cmath> #include <algorithm> +#include <limits> using namespace std; @@ -28,7 +29,8 @@ /// the true extent when booking. /// @todo Also, the code convention is that _foo is a private member variable/function: /// for constants use all-caps, e.g. LARGENUM. -const double _largeNum = 1000000000000000000000.0; +const double LARGENUM = numeric_limits<double>::max(); +const double SMALLNUM = numeric_limits<double>::min(); namespace YODA { @@ -38,9 +40,8 @@ /// @todo Only use C++ //-type comments, please /// @brief 2D bin container and provider - /** This class handles almost all boiler-plate operations - * on 2D bins (like creating axis, adding, searching, testing). - */ + /// This class handles almost all boiler-plate operations + /// on 2D bins (like creating axis, adding, searching, testing). template <typename BIN> class Axis2D { public: @@ -49,16 +50,14 @@ typedef BIN Bin; typedef typename std::vector<BIN> Bins; - /** When edge is added to the collection it must - * obey the following format. size_t specifies the bin this - * edge is a member of, a pair contains a beginning and end of the edge. - */ + /// When edge is added to the collection it must + /// obey the following format. size_t specifies the bin this + /// edge is a member of, a pair contains a beginning and end of the edge. typedef typename std::pair<size_t, std::pair<double,double> > Edge; - /** A type being a basic substructure of _binHashSparse. It contains a indicator - * specifying the major coordinate and a collection of edges sharing the same major - * coordinate. - */ + /// A type being a basic substructure of _binHashSparse. It contains a indicator + /// specifying the major coordinate and a collection of edges sharing the same major + /// coordinate. typedef typename std::pair<double, std::vector<Edge> > EdgeCollection; /// A simple point in 2D @todo Should Point2D be used? @@ -74,19 +73,18 @@ /// the same structure so that we can find what we're looking for. /// @brief Segment validator function - /** This a 'dispatcher' function. It checks if the segment in question - * is vertical or horizontal and launches the appropriate function - * searching for cuts in the prope direction. Since it operates on - * a vector of segments it is prepared to act on arbitrarly large sets of edges, - * in practice usually being four sides of a rectangular bin. - * - * Notice that it will never be checked, in the current state, if there is a cut - * in edges in the edgeset. This imposes the requirement of provide the program - * with non-degenerate bins, until checking in implemented. However, it doesn't seem - * to be needed, as edges are not generated by a user. - * - * This is also a perfect place to paralellize the program, if required. - */ + /// This a 'dispatcher' function. It checks if the segment in question + /// is vertical or horizontal and launches the appropriate function + /// searching for cuts in the prope direction. Since it operates on + /// a vector of segments it is prepared to act on arbitrarly large sets of edges, + /// in practice usually being four sides of a rectangular bin. + /// + /// Notice that it will never be checked, in the current state, if there is a cut + /// in edges in the edgeset. This imposes the requirement of provide the program + /// with non-degenerate bins, until checking in implemented. However, it doesn't seem + /// to be needed, as edges are not generated by a user. + /// + /// This is also a perfect place to paralellize the program, if required. bool _validateEdge(vector<Segment>& edges) { /// Setting the return variable. True means that no cuts were detected. @@ -94,23 +92,20 @@ /// Looping over all the edges provided for(unsigned int i=0; i < edges.size(); i++) { - /** If the X coordinate of the starting point is the same - * as X coordinate of the ending one, checks if there are cuts - * on this vertical segment. - */ + /// If the X coordinate of the starting point is the same + /// as X coordinate of the ending one, checks if there are cuts + /// on this vertical segment. if(fuzzyEquals(edges[i].first.first, edges[i].second.first)) ret = _findCutsY(edges[i]); /// Check if the segment is horizontal and is it cutting any bin that already exists else if(fuzzyEquals(edges[i].first.second, edges[i].second.second)) ret = _findCutsX(edges[i]); - /** This is a check that discards the bin if it is not a rectangle - * composed of vertical and horizontal segments. - */ + /// This is a check that discards the bin if it is not a rectangle + /// composed of vertical and horizontal segments. else ret = false; - /** If a cut was detected, say it. There is no point in checking other edges - * in the set. - */ + /// If a cut was detected, say it. There is no point in checking other edges + /// in the set. if(!ret) return false; } /// If no cuts were detected in any of the edges, tell the launching function about this @@ -118,11 +113,10 @@ } /// @brief A binary search function - /** This is conceptually the same implementation as in STL - * but because it returns the index of an element in a vector, - * it is easier to use in our case than the STL implementation - * that returns a pointer at the element. - */ + /// This is conceptually the same implementation as in STL + /// but because it returns the index of an element in a vector, + /// it is easier to use in our case than the STL implementation + /// that returns a pointer at the element. size_t _binaryS(Utils::cachedvector<EdgeCollection>& toSearch, double value, size_t lower, size_t higher) { @@ -139,50 +133,43 @@ return _binaryS(toSearch, value, where, higher); } - /** This is not a redundant check, because - * of the nature of int division. - */ + /// This is not a redundant check, because + /// of the nature of int division. if (where == 0) return where; - /** Check if the value is somewhere inbetween - * an element at the position in question and - * an element at a lower position. If so, return - * an index to the current positon. - */ + /// Check if the value is somewhere inbetween + /// an element at the position in question and + /// an element at a lower position. If so, return + /// an index to the current positon. if(value >= toSearch[where-1].first) return where; - /** If none of the above occurs, the value must - * be smaller that the element at the current - * position. In such case, launch the search on - * half of the interval below the current position. - */ + /// If none of the above occurs, the value must + /// be smaller that the element at the current + /// position. In such case, launch the search on + /// half of the interval below the current position. return _binaryS(toSearch, value, lower, where); } /// @brief Function that finds cuts of horizontal edges. - /** A specialised function that tries to exploit the fact - * that edges can cut one another only on right angles - * to the highest extent. The inner workings are explained - * in the comments placed in the function body. - */ + /// A specialised function that tries to exploit the fact + /// that edges can cut one another only on right angles + /// to the highest extent. The inner workings are explained + /// in the comments placed in the function body. bool _findCutsX(Segment& edge) { - /** Look up the limits of search in the _binHashSparse - * structure. We are not interested in the vertical edges - * that are before the beginning of our segment or after its end. - */ + /// Look up the limits of search in the _binHashSparse + /// structure. We are not interested in the vertical edges + /// that are before the beginning of our segment or after its end. size_t i = _binaryS(_binHashSparse.second, edge.first.first, 0, _binHashSparse.second.size()); size_t end = _binaryS(_binHashSparse.second, edge.second.first, 0, _binHashSparse.second.size()); for(; i < end; i++) { - /** Scroll through all the vertical segments with a given X coordinate - * and see if any of those fulfills the cutting requirement. If it does, - * announce it. - */ + /// Scroll through all the vertical segments with a given X coordinate + /// and see if any of those fulfills the cutting requirement. If it does, + /// announce it. for(unsigned int j = 0; j < _binHashSparse.second[i].second.size(); j++) { - /** Note that we are not taking into account the edges touching the - * segment in question. That's because sides of a bin touch - */ + /// Note that we are not taking into account the edges touching the + /// segment in question. That's because sides of a bin touch if(_binHashSparse.second[i].second[j].second.first < edge.first.second && _binHashSparse.second[i].second[j].second.second > edge.first.second && !fuzzyEquals(_binHashSparse.second[i].second[j].second.first, edge.first.second) && @@ -196,9 +183,8 @@ } /// @brief Function that finds cuts of vertical edges - /** For a detailed descpription, please look into - * documentation for _findCutsX(). - */ + /// For a detailed descpription, please look into + /// documentation for _findCutsX(). bool _findCutsY(Segment& edge) { size_t i = _binaryS(_binHashSparse.first, edge.first.second, 0, _binHashSparse.first.size()); size_t end = _binaryS(_binHashSparse.first, edge.second.second, 0, _binHashSparse.first.size()); @@ -217,55 +203,48 @@ } /// @brief Function executed when a set of edges is dropped. - /** It does not have any information about which edge in the set - * had failed the check. If this is needed such additional information - * can be readily implemented. - */ + /// It does not have any information about which edge in the set + /// had failed the check. If this is needed such additional information + /// can be readily implemented. void _dropEdge(vector<Segment>& edges) { std::cerr << "A set of edges was dropped." << endl; } /// @brief Bin adder. - /** It contains all the commands that need to executed - * to properly add a bin. Specifially edges are added to - * the edge cache (_binHashSparse) and a bin is created from - * those edges. - */ + /// It contains all the commands that need to executed + /// to properly add a bin. Specifially edges are added to + /// the edge cache (_binHashSparse) and a bin is created from + /// those edges. void _addEdge(vector<Segment>& edges, pair<Utils::cachedvector<EdgeCollection>, Utils::cachedvector<EdgeCollection> >& binHash, bool addBin = true) { /// Check if there was no mistake made when adding segments to a vector. if(edges.size() != 4) throw Exception("The segments supplied don't describe a full bin!"); - /** This is the part in charge of adding each of the segments - * to the edge cache. Segments are assumed to be validated - * beforehand. - */ + /// This is the part in charge of adding each of the segments + /// to the edge cache. Segments are assumed to be validated + /// beforehand. for(unsigned int j=0; j < edges.size(); j++) { /// Association made for convinience. Segment edge = edges[j]; - /** Do the following if the edge is vertical. - * Those two cases need to be distinguished - * because of the way in which edge cache is structured. - */ + /// Do the following if the edge is vertical. + /// Those two cases need to be distinguished + /// because of the way in which edge cache is structured. if(edge.first.first == edge.second.first) { - /** See if our edge has the same X coordinate as any other - * edge that is currently in the cache. - */ + /// See if our edge has the same X coordinate as any other + /// edge that is currently in the cache. /// Keeps the status of the search bool found = false; - /** There is only a certain set of X coordinates that we need to sweep - * to check if our segment has the same X coordinate. Find them. - */ + /// There is only a certain set of X coordinates that we need to sweep + /// to check if our segment has the same X coordinate. Find them. size_t i = _binaryS(binHash.second, edge.first.first, 0, binHash.second.size())-1; if(i < 0) i = 0; size_t end = i+3; - /** For the coordinates in range, check if one of them is an X coordinate of - * the sement. - */ + /// For the coordinates in range, check if one of them is an X coordinate of + /// the sement. for(; i < binHash.second.size() && i < end ; i++) { /// If this is the case, do what is needed to be done. if(fuzzyEquals(binHash.second[i].first, edge.first.first)) { @@ -275,9 +254,8 @@ } } - /** If no edge with the same X coordinate exist, create - * a new subhash at the X coordinate of a segment. - */ + /// If no edge with the same X coordinate exist, create + /// a new subhash at the X coordinate of a segment. if(!found) { vector<Edge> temp; temp.push_back(make_pair(_bins.size(), make_pair(edge.first.second, edge.second.second))); @@ -311,10 +289,9 @@ } /// @brief Orientation fixer - /** Check if the orientation of an edge is proper - * for the rest of the algorithm to work on, and if it is not - * fix it. - */ + /// Check if the orientation of an edge is proper + /// for the rest of the algorithm to work on, and if it is not + /// fix it. void _fixOrientation(Segment& edge) { if(fuzzyEquals(edge.first.first, edge.second.first)) { if(edge.first.second > edge.second.second) { @@ -331,14 +308,13 @@ } /// @brief Axis creator - /** The top-level function taking part in the process of - * adding edges. Creating an axis is the same operation - * for it as adding new bins so it can be as well used to - * add some custom bins. - * - * It accepts two extremal points of a rectangle - * (top-right and bottom-left) as input. - */ + /// The top-level function taking part in the process of + /// adding edges. Creating an axis is the same operation + /// for it as adding new bins so it can be as well used to + /// add some custom bins. + /// + /// It accepts two extremal points of a rectangle + /// (top-right and bottom-left) as input. void _mkAxis(const vector<Segment>& binLimits) { /// For each of the rectangles @@ -379,18 +355,16 @@ } /// @brief Plot extrema (re)generator. - /** Since scrolling through every bin is an expensive - * operation to do every time we need the limits of - * the plot, there are caches set up. This function - * regenerates them. It should be run after any change is made - * to bin layout. - */ - /// @todo Was this caching actually profiled and found to be *needed*? + /// Since scrolling through every bin is an expensive + /// operation to do every time we need the limits of + /// the plot, there are caches set up. This function + /// regenerates them. It should be run after any change is made + /// to bin layout. void _regenDelimiters() { - double highEdgeX = -_largeNum; - double highEdgeY = -_largeNum; - double lowEdgeX = _largeNum; - double lowEdgeY = _largeNum; + double highEdgeX = SMALLNUM; + double highEdgeY = SMALLNUM; + double lowEdgeX = LARGENUM; + double lowEdgeY = LARGENUM; /// Scroll through the bins and set the delimiters. for(unsigned int i=0; i < _bins.size(); i++) { @@ -406,12 +380,16 @@ _highEdgeY = highEdgeY; } - int _findBinIndex(double coordX, double coordY) const { - for(size_t i=0; i < _bins.size(); i++) { - if(_bins[i].lowEdgeX() <= coordX && _bins[i].highEdgeX() >= coordX && - _bins[i].lowEdgeY() <= coordY && _bins[i].highEdgeY() >= coordY) return i; - } - return -1; + /// @brief BIn index finder + /// Looks through all the bins to see which + /// one contains the point of interest. + int _findBinIndex(double coordX, double coordY) const + { + for(size_t i=0; i < _bins.size(); i++) { + if(_bins[i].lowEdgeX() <= coordX && _bins[i].highEdgeX() >= coordX && + _bins[i].lowEdgeY() <= coordY && _bins[i].highEdgeY() >= coordY) return i; + } + return -1; } @@ -420,9 +398,8 @@ //@{ /// @brief Empty constructor - /** Only added because it is required by SWIG. - * It doesn't make much sense to use it. - */ + /// Only added because it is required by SWIG. + /// It doesn't make much sense to use it. Axis2D() { vector<Segment> edges; @@ -456,23 +433,21 @@ //@{ /// @brief Bin addition operator - /** This operator is provided a vector of limiting - * points in the format required by _mkAxis(). - * It should be noted that there is nothing special about - * the initiation stage of Axis2D, and the edges can be added - * online if they meet all the requirements of non-degeneracy. - * No merging is supported, and I don't think it should before the support - * for merging for '+' operator (codewise it should be the same thing). - */ + /// This operator is provided a vector of limiting + /// points in the format required by _mkAxis(). + /// It should be noted that there is nothing special about + /// the initiation stage of Axis2D, and the edges can be added + /// online if they meet all the requirements of non-degeneracy. + /// No merging is supported, and I don't think it should before the support + /// for merging for '+' operator (codewise it should be the same thing). void addBin(const vector<Segment>& binLimits) { _mkAxis(binLimits); } /// @brief Bin addition operator - /** This operator is supplied with whe extreamal coordinates of just - * one bin. It then launches the standard bin addition procedure. - */ + /// This operator is supplied with whe extreamal coordinates of just + /// one bin. It then launches the standard bin addition procedure. void addBin(double lowX, double lowY, double highX, double highY) { vector<Segment> coords; @@ -485,20 +460,18 @@ /// @name Some helper functions: //@{ - /// @brief Checks if our bins form a grid. - /** This function uses a neat property of _binHashSparse. - * If it is containing a set of edges forming a grid without - * gaps in the middle it will have the same number of edges in the - * inner subcaches and half of this amount in the outer (grid boundary) - * subcaches. This makes isGriddy() a very, very fast function. - */ - int isGriddy() + /// This function uses a neat property of _binHashSparse. + /// If it is containing a set of edges forming a grid without + /// gaps in the middle it will have the same number of edges in the + /// inner subcaches and half of this amount in the outer (grid boundary) + /// subcaches. This makes isGriddy() a very, very fast function. + /// @todo Is the name appropriate? + int isGriddy() const { - /** Check if the number of edges parallel to X axis - * is proper in every subcache. - */ + /// Check if the number of edges parallel to X axis + /// is proper in every subcache. unsigned int sizeX = _binHashSparse.first[0].second.size(); for(unsigned int i=1; i < _binHashSparse.first.size(); i++) { if(i == _binHashSparse.first.size() - 1) { @@ -676,22 +649,6 @@ return _underflow; } - /// Get the binHash(non-const version) - /// @todo Why are we exposing this? Also, note that the YODA method naming convention doesn't have "get"s - std::pair<Utils::cachedvector<EdgeCollection>, - Utils::cachedvector<EdgeCollection> > getHash() - { - return _binHashSparse; - } - - /// Get the binHash(const version) - /// @todo Why are we exposing this? Also, note that the YODA method naming convention doesn't have "get"s - const std::pair<Utils::cachedvector<EdgeCollection>, - Utils::cachedvector<EdgeCollection > > getHash() const - { - return _binHashSparse; - } - /// Get bin index from external classes (non-const version) /// @todo Change: the YODA method naming convention doesn't have "get"s /// @todo Why isn't *this* method const? @@ -718,9 +675,8 @@ } /// @brief Axis scaler - /** Scales the axis with a given scale. If no scale is given, assumes - * identity transform. - */ + /// Scales the axis with a given scale. If no scale is given, assumes + /// identity transform. void scale(double scaleX = 1.0, double scaleY = 1.0) { // Two loops are put on purpose, just to protect @@ -779,9 +735,8 @@ } /// @brief Addition operator - /** At this stage it is only possible to add two histograms with - * the same binnings. Compatible but not equal binning to come soon. - */ + /// At this stage it is only possible to add two histograms with + /// the same binnings. Compatible but not equal binning to come soon. Axis2D<BIN>& operator += (const Axis2D<BIN>& toAdd) { if (*this != toAdd) { @@ -825,14 +780,13 @@ Dbn2D _dbn; /// @brief Bin hash structure - /** First in pair is holding the horizontal edges indexed by first.first - * which is an y coordinate. The last pair specifies x coordinates (begin, end) of - * the horizontal edge. - * Analogous for the second member of the pair. - * - * For the fullest description, see typedefs at the beginning - * of this file. - */ + /// First in pair is holding the horizontal edges indexed by first.first + /// which is an y coordinate. The last pair specifies x coordinates (begin, end) of + /// the horizontal edge. + /// Analogous for the second member of the pair. + /// + /// For the fullest description, see typedefs at the beginning + /// of this file. std::pair<Utils::cachedvector<EdgeCollection>, Utils::cachedvector<EdgeCollection> > _binHashSparse; @@ -840,9 +794,6 @@ /// Low/High edges: double _highEdgeX, _highEdgeY, _lowEdgeX, _lowEdgeY; - ///Some additional hashes: - vector<Edge> _hashX; vector<Edge> _hashY; - }; /// Addition operator @@ -862,13 +813,6 @@ tmp -= second; return tmp; } - - typedef typename std::pair<size_t, std::pair<double,double> > Edge; - template <typename BIN> - Axis2D<BIN> operator < (Edge first, Edge second) { - return first.second.second < second.second.second; - } - } #endif Modified: trunk/include/YODA/Histo2D.h ============================================================================== --- trunk/include/YODA/Histo2D.h Fri Aug 12 21:03:48 2011 (r237) +++ trunk/include/YODA/Histo2D.h Sat Aug 13 10:37:21 2011 (r238) @@ -212,7 +212,7 @@ /// Hash returner (non-const version) /// @todo This needs a typedef - std::pair<Utils::cachedvector<pair<double,std::vector<pair<size_t, pair<double,double> > > > >, + /* std::pair<Utils::cachedvector<pair<double,std::vector<pair<size_t, pair<double,double> > > > >, Utils::cachedvector<pair<double,std::vector<pair<size_t, pair<double,double> > > > > > getHash() { return _axis.getHash(); } @@ -222,7 +222,7 @@ const std::pair<Utils::cachedvector<pair<double,std::vector<pair<size_t, pair<double,double> > > > >, Utils::cachedvector<pair<double,std::vector<pair<size_t, pair<double,double> > > > > > getHash() const { return _axis.getHash(); - } + }*/ //@} public: @@ -277,7 +277,15 @@ _axis -= toSubtract._axis; return *this; } + + /*bool operator == (const Histo2D& other) { + return _axis == other._axis; + } + bool operator != (const Histo2D& other) { + return ! operator == (other); + } +*/ //@} Modified: trunk/src/Histo2D.cc ============================================================================== --- trunk/src/Histo2D.cc Fri Aug 12 21:03:48 2011 (r237) +++ trunk/src/Histo2D.cc Sat Aug 13 10:37:21 2011 (r238) @@ -115,8 +115,8 @@ /// Divide two histograms - Scatter3D operator / (const Histo2D& numer, const Histo2D& denom) { - if(numer.getHash() != denom.getHash()) throw GridError("The two Histos are not the same!"); + /* Scatter3D operator / (Histo2D& numer, const Histo2D& denom) { + if(numer!=denom) throw GridError("The two Histos are not the same!"); Scatter3D tmp; for (size_t i = 0; i < numer.numBinsTotal(); ++i) { const HistoBin2D& b1 = numer.bin(i); @@ -151,5 +151,5 @@ assert(tmp.numPoints() == numer.numBinsTotal()); return tmp; } - +*/ } Modified: trunk/tests/TestHisto2D.cc ============================================================================== --- trunk/tests/TestHisto2D.cc Fri Aug 12 21:03:48 2011 (r237) +++ trunk/tests/TestHisto2D.cc Sat Aug 13 10:37:21 2011 (r238) @@ -63,13 +63,13 @@ tS = (startTime.tv_sec*1000000 + startTime.tv_usec)/(double)1000000; tE = (endTime.tv_sec*1000000 + endTime.tv_usec)/(double)1000000; - cout << "Time taken to fill 200k bins: " << tE - tS << "s" << endl; + cout << "Time taken to fill 2000 bins: " << tE - tS << "s" << endl; if((tE - tS) > 50.0) { cout << "Performance is not sufficient. Probably broken caches?" << endl; return -1; } - printStats(h, true); + printStats(h, false); cout << h.numBinsTotal() << endl; /// Testing if fill() function does what it should
More information about the yoda-svn mailing list |