Go to the documentation of this file.00001
00002
00003
00004
00005 #ifndef PhysicsTools_PatAlgos_PATUserDataMerger_h
00006 #define PhysicsTools_PatAlgos_PATUserDataMerger_h
00007
00024 #include "FWCore/Framework/interface/EDProducer.h"
00025 #include "FWCore/Framework/interface/Event.h"
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027 #include "FWCore/Utilities/interface/InputTag.h"
00028 #include "DataFormats/Common/interface/View.h"
00029 #include "DataFormats/Common/interface/Ptr.h"
00030 #include "DataFormats/Common/interface/Association.h"
00031 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00032 #include "DataFormats/Candidate/interface/Candidate.h"
00033 #include "DataFormats/PatCandidates/interface/PATObject.h"
00034
00035 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00036 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00037
00038 #include <iostream>
00039
00040
00041 namespace pat {
00042 namespace helper {
00043 struct AddUserInt {
00044 typedef int value_type;
00045 typedef edm::ValueMap<value_type> product_type;
00046 template<typename ObjectType>
00047 void addData(ObjectType &obj, const std::string & key, const value_type &val) { obj.addUserInt(key, val); }
00048 };
00049 struct AddUserFloat {
00050 typedef float value_type;
00051 typedef edm::ValueMap<value_type> product_type;
00052 template<typename ObjectType>
00053 void addData(ObjectType &obj, const std::string & key, const value_type &val) { obj.addUserFloat(key, val); }
00054 };
00055 struct AddUserPtr {
00056 typedef edm::Ptr<UserData> value_type;
00057 typedef edm::ValueMap<value_type> product_type;
00058 template<typename ObjectType>
00059 void addData(ObjectType &obj, const std::string & key, const value_type &val) {
00060 obj.addUserDataFromPtr(key, val);
00061 }
00062 };
00063 struct AddUserCand {
00064 typedef reco::CandidatePtr value_type;
00065 typedef edm::ValueMap<value_type> product_type;
00066 template<typename ObjectType>
00067 void addData(ObjectType &obj, const std::string & key, const value_type &val) { obj.addUserCand(key, val); }
00068 };
00069
00070 }
00071
00072 template<typename ObjectType, typename Operation>
00073 class PATUserDataMerger {
00074
00075 public:
00076
00077 PATUserDataMerger() {}
00078 PATUserDataMerger(const edm::ParameterSet & iConfig);
00079 ~PATUserDataMerger() {}
00080
00081 static void fillDescription(edm::ParameterSetDescription & iDesc);
00082
00083
00084 void add(ObjectType & patObject,
00085 edm::Event const & iEvent, edm::EventSetup const & iSetup);
00086
00087 private:
00088
00089
00090 std::vector<edm::InputTag> userDataSrc_;
00091 Operation loader_;
00092
00093 };
00094
00095 }
00096
00097
00098 template<typename ObjectType, typename Operation>
00099 pat::PATUserDataMerger<ObjectType, Operation>::PATUserDataMerger(const edm::ParameterSet & iConfig) :
00100 userDataSrc_(iConfig.getParameter<std::vector<edm::InputTag> >("src") )
00101 {
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 template<class ObjectType, typename Operation>
00122 void
00123 pat::PATUserDataMerger<ObjectType, Operation>::add(ObjectType & patObject,
00124 edm::Event const & iEvent,
00125 const edm::EventSetup & iSetup )
00126 {
00127
00128 std::vector<edm::InputTag>::const_iterator input_it = userDataSrc_.begin(),
00129 input_begin = userDataSrc_.begin(),
00130 input_end = userDataSrc_.end();
00131
00132 for ( ; input_it != input_end; ++input_it ) {
00133
00134
00135
00136
00137 edm::Handle<typename Operation::product_type> userData;
00138
00139
00140 if ( input_it->encode().size() == 0 ) continue;
00141 iEvent.getByLabel( *input_it, userData );
00142
00143 edm::Ptr<reco::Candidate> recoObject = patObject.originalObjectRef();
00144 if ( userData->contains( recoObject.id() ) ) {
00145 loader_.addData( patObject, input_it->encode(), (*userData)[recoObject]);
00146 }
00147
00148 }
00149
00150 }
00151
00152 template<class ObjectType, typename Operation>
00153 void
00154 pat::PATUserDataMerger<ObjectType, Operation>::fillDescription(edm::ParameterSetDescription & iDesc)
00155 {
00156 iDesc.add<std::vector<edm::InputTag> >("src");
00157 }
00158
00159 #endif