Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:15

0001 #include "Utilities/General/interface/precomputed_value_sort.h"
0002 #include "DataFormats/GeometrySurface/interface/Plane.h"
0003 #include "DataFormats/GeometrySurface/interface/GeometricSorting.h"
0004 #include <iostream>
0005 #include <iterator>
0006 
0007 using namespace std;
0008 using namespace geomsort;
0009 
0010 typedef Surface::PositionType PositionType;
0011 typedef Surface::RotationType RotationType;
0012 
0013 // A simple helper for printing the object
0014 struct dump {
0015   void operator()(const Surface& o) {
0016     cout << o.position() << " R  : " << o.position().perp() << " Phi: " << o.position().phi()
0017          << " Z  : " << o.position().z() << endl;
0018   }
0019   void operator()(const std::unique_ptr<Surface>& o) { operator()(*o); }
0020   void operator()(const Surface* o) { operator()(*o); }
0021 };
0022 
0023 int main() {
0024   using Pointer = std::unique_ptr<Surface>;
0025   //
0026   // Example of sorting a vector of objects store by value.
0027   //
0028 
0029   // Fill the vector to be sorted
0030   vector<Pointer> v;
0031   v.push_back(Pointer(new Plane(PositionType(2, 1, 1), RotationType())));
0032   v.push_back(Pointer(new Plane(PositionType(1, 1, 2), RotationType())));
0033   v.push_back(Pointer(new Plane(PositionType(1, 2, 3), RotationType())));
0034   v.push_back(Pointer(new Plane(PositionType(2, 2, 4), RotationType())));
0035 
0036   cout << "Original  vector: " << endl;
0037   for_each(v.begin(), v.end(), dump());
0038 
0039   /*
0040   cout << "Sort in R       : " << endl;
0041   // Here we sort in R
0042   precomputed_value_sort(v.begin(),v.end(),ExtractR<Surface>());
0043   for_each(v.begin(),v.end(), dump());
0044 
0045   cout << "Sort in phi     : " << endl;
0046   // Here we sort in phi
0047   precomputed_value_sort(v.begin(),v.end(),ExtractPhi<Surface>());
0048   for_each(v.begin(),v.end(), dump());
0049 
0050   cout << "Sort in z       : " << endl;
0051   // Here we sort in Z
0052   precomputed_value_sort(v.begin(),v.end(),ExtractZ<Surface>());
0053   for_each(v.begin(),v.end(), dump());
0054   */
0055 
0056   //
0057   // Now do the same with a vector of pointers
0058   //
0059   cout << endl << "Again with pointers" << endl;
0060 
0061   vector<const Surface*> vp;
0062   for (auto i = v.begin(); i != v.end(); i++) {
0063     vp.push_back(&(**i));
0064   }
0065 
0066   cout << "Sort in R       : " << endl;
0067   // Here we sort in R
0068   precomputed_value_sort(vp.begin(), vp.end(), ExtractR<Surface>());
0069   for_each(vp.begin(), vp.end(), dump());
0070 
0071   cout << "Sort in phi     : " << endl;
0072   // Here we sort in phi
0073   precomputed_value_sort(vp.begin(), vp.end(), ExtractPhi<Surface>());
0074   for_each(vp.begin(), vp.end(), dump());
0075 
0076   cout << "Sort in z       : " << endl;
0077   // Here we sort in Z
0078   precomputed_value_sort(vp.begin(), vp.end(), ExtractZ<Surface>());
0079   for_each(vp.begin(), vp.end(), dump());
0080 
0081   return 0;
0082 }