SusyNtuple
|
00001 // Dear emacs, this is -*- c++ -*- 00002 #ifndef SUSY_VEC_UTILS_H 00003 #define SUSY_VEC_UTILS_H 00004 00005 /* 00006 Vector utility functions 00007 00008 Most of these are useful to manipulate the mc truth table. 00009 00010 davide.gerbaudo@gmail.com 00011 April 2014 00012 */ 00013 00014 #include <algorithm> 00015 #include <string> 00016 #include <vector> 00017 #include <algorithm> // find 00018 00019 namespace Susy{ 00020 namespace utils{ 00021 00022 typedef std::vector< int > vint_t; 00023 typedef std::vector< vint_t > vvint_t; 00024 00026 00034 template<typename T, size_t N> 00035 T * end(T (&ra)[N]) { 00036 return ra + N; 00037 } 00039 template < class T > 00040 bool contains(const std::vector<T> &v, const T& val) { 00041 return std::find(v.begin(), v.end(), val)!=v.end(); 00042 } 00044 bool containsAnyOf(const vint_t &firstVec, const vint_t &subVec); 00046 std::string vecToString(const vint_t &vec); 00048 std::string vecVecToString(const vvint_t &vvec); 00050 void removeDuplicates(vint_t &vec); 00051 00053 template < template <typename, typename> class Container, 00054 typename Predicate, 00055 typename Allocator, 00056 typename A 00057 > 00058 Container<A, Allocator> filter(Container<A, Allocator> const & container, Predicate const & pred) { 00059 Container<A, Allocator> filtered(container); 00060 filtered.erase(remove_if(filtered.begin(), filtered.end(), pred), filtered.end()); 00061 return filtered; 00062 } 00063 00064 00065 } // utils 00066 } // susy 00067 #endif