CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CommonTools/UtilAlgos/interface/SelectionAdderTrait.h

Go to the documentation of this file.
00001 #ifndef UtilAlgos_SelectionAdderTrait_h
00002 #define UtilAlgos_SelectionAdderTrait_h
00003 /* \class SelectionAdderTrait
00004  *
00005  * \author Luca Lista, INFN
00006  */
00007 #include "DataFormats/Common/interface/Handle.h"
00008 #include "DataFormats/Common/interface/RefVector.h"
00009 #include "DataFormats/Common/interface/PtrVector.h"
00010 #include "DataFormats/Common/interface/RefToBaseVector.h"
00011 #include "DataFormats/Common/interface/RefToBaseProd.h"
00012 #include "DataFormats/Common/interface/RefProd.h"
00013 #include "DataFormats/Common/interface/AssociationVector.h"
00014 #include <boost/static_assert.hpp>
00015 
00016 namespace helper {
00017 
00018   template<typename StoreContainer>
00019   struct SelectionCopyAdder {
00020     template<typename C>
00021     void operator()( StoreContainer & selected, const edm::Handle<C> & c, size_t idx ) {
00022       selected.push_back( ( * c )[ idx ] );
00023     }
00024   };
00025 
00026   template<typename StoreContainer>
00027   struct SelectionPointerAdder {
00028     template<typename C>
00029     void operator()( StoreContainer & selected, const edm::Handle<C> & c, size_t idx ) {
00030       selected.push_back( & ( * c )[ idx ] );
00031     }
00032   };
00033 
00034   template<typename StoreContainer>
00035   struct SelectionPointerDerefAdder {
00036     template<typename C>
00037     void operator()( StoreContainer & selected, const edm::Handle<C> & c, size_t idx ) {
00038       selected.push_back( & * ( * c )[ idx ] );
00039     }
00040   };
00041 
00042   template<typename StoreContainer>
00043   struct SelectionFirstPointerAdder {
00044     template<typename C>
00045     void operator()( StoreContainer & selected, const edm::Handle<C> & c, size_t idx ) {
00046       selected.push_back( & * ( ( * c )[ idx ].first ) );
00047     }
00048   };
00049 
00050   template<typename StoreContainer>
00051   struct SelectionFirstRefAdder {
00052     template<typename C>
00053     void operator()( StoreContainer & selected, const edm::Handle<C> & c, size_t idx ) {
00054       selected.push_back( ( * c )[ idx ].first );
00055     }
00056   };
00057 
00058   template<typename StoreContainer>
00059   struct SelectionRefAdder {
00060     template<typename C>
00061     void operator()( StoreContainer & selected, const edm::Handle<C> & c, size_t idx ) {
00062       selected.push_back( edm::Ref<C>( c, idx ) );
00063     }
00064   };
00065 
00066   template<typename T>
00067   struct SelectionRefViewAdder {
00068     void operator()( edm::RefToBaseVector<T> & selected, const edm::Handle<edm::View<T> > & c, size_t idx ) {
00069       selected.push_back( c->refAt( idx ) );
00070     }
00071   };
00072 
00073   template<typename T>
00074   struct SelectionPtrViewAdder {
00075     void operator()( edm::PtrVector<T> & selected, const edm::Handle<edm::View<T> > & c, size_t idx ) {
00076       selected.push_back( c->ptrAt( idx ) );
00077     }
00078   };
00079 
00080   template<typename InputCollection, typename StoreContainer>
00081   struct SelectionAdderTrait {
00082     BOOST_STATIC_ASSERT(sizeof(InputCollection) == 0); 
00083   };
00084 
00085   template<typename InputCollection, typename T>
00086   struct SelectionAdderTrait<InputCollection, std::vector<const T *> > {
00087     typedef SelectionPointerAdder<std::vector<const T *> > type;
00088   };
00089 
00090   template<typename InputCollection, typename C>
00091   struct SelectionAdderTrait<InputCollection, edm::RefVector<C> > {
00092     typedef SelectionRefAdder<edm::RefVector<C> > type;
00093   };
00094 
00095   template<typename C>
00096   struct SelectionAdderTrait<edm::RefVector<C>, edm::RefVector<C> > {
00097     typedef SelectionCopyAdder<edm::RefVector<C> > type;
00098   };
00099 
00100   template<typename C, typename T>
00101   struct SelectionAdderTrait<edm::RefVector<C>, std::vector<const T *> > {
00102     typedef SelectionPointerDerefAdder<std::vector<const T *> > type;
00103   };
00104 
00105   template<typename T>
00106   struct SelectionAdderTrait<edm::RefToBaseVector<T>, edm::RefToBaseVector<T> > {
00107     typedef SelectionCopyAdder<edm::RefToBaseVector<T> > type;
00108   };
00109 
00110   template<typename T>
00111   struct SelectionAdderTrait<edm::RefToBaseVector<T>, std::vector<const T *> > {
00112     typedef SelectionPointerDerefAdder<std::vector<const T *> > type;
00113   };
00114 
00115   template<typename K, typename C, typename T>
00116   struct SelectionAdderTrait<edm::AssociationVector<edm::RefProd<K>, C>, std::vector<const T *> > {
00117     typedef SelectionFirstPointerAdder<std::vector<const T *> > type;
00118   };
00119 
00120   template<typename C, typename T>
00121   struct SelectionAdderTrait<edm::AssociationVector<edm::RefToBaseProd<T>, C>, std::vector<const T *> > {
00122     typedef SelectionFirstPointerAdder<std::vector<const T *> > type;
00123   };
00124 
00125   template<typename K, typename C>
00126   struct SelectionAdderTrait<edm::AssociationVector<edm::RefProd<K>, C>, edm::RefVector<K> > {
00127     typedef SelectionFirstRefAdder<edm::RefVector<K> > type;
00128   };
00129 
00130   template<typename T, typename C>
00131   struct SelectionAdderTrait<edm::AssociationVector<edm::RefToBaseProd<T>, C>, 
00132                              edm::RefToBaseVector<T> > {
00133     typedef SelectionFirstRefAdder<edm::RefToBaseVector<T> > type;
00134   };
00135 
00136   template<typename T>
00137   struct SelectionAdderTrait<edm::View<T>, edm::RefToBaseVector<T> > {
00138     typedef SelectionRefViewAdder<T> type;
00139   };
00140 
00141   template<typename T>
00142   struct SelectionAdderTrait<edm::View<T>, edm::PtrVector<T> > {
00143     typedef SelectionPtrViewAdder<T> type;
00144   };
00145 
00146 }
00147 
00148 #endif