CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PATUserDataMerger.h
Go to the documentation of this file.
1 //
2 //
3 
4 #ifndef PhysicsTools_PatAlgos_PATUserDataMerger_h
5 #define PhysicsTools_PatAlgos_PATUserDataMerger_h
6 
35 
38 
39 #include <iostream>
40 
41 
42 namespace pat {
43  namespace helper {
44  struct AddUserInt {
45  typedef int value_type;
47  template<typename ObjectType>
48  void addData(ObjectType &obj, const std::string & key, const value_type &val) { obj.addUserInt(key, val); }
49  };
50  struct AddUserFloat {
51  typedef float value_type;
53  template<typename ObjectType>
54  void addData(ObjectType &obj, const std::string & key, const value_type &val) { obj.addUserFloat(key, val); }
55  };
56  struct AddUserPtr {
59  template<typename ObjectType>
60  void addData(ObjectType &obj, const std::string & key, const value_type &val) {
61  obj.addUserDataFromPtr(key, val);
62  }
63  };
64  struct AddUserCand {
67  template<typename ObjectType>
68  void addData(ObjectType &obj, const std::string & key, const value_type &val) { obj.addUserCand(key, val); }
69  };
70 
71  }
72 
73  template<typename ObjectType, typename Operation>
75 
76  public:
77 
81 
82  static void fillDescription(edm::ParameterSetDescription & iDesc);
83 
84  // Method to call from PATUserDataHelper to add information to the PATObject in question.
85  void add(ObjectType & patObject,
86  edm::Event const & iEvent, edm::EventSetup const & iSetup);
87 
88  private:
89 
90  // configurables
91  std::vector<edm::InputTag> userDataSrc_;
92  std::vector<edm::EDGetTokenT<typename Operation::product_type> > userDataSrcTokens_;
93  Operation loader_;
94 
95  };
96 
97 }
98 
99 // Constructor: Initilize user data src
100 template<typename ObjectType, typename Operation>
102  userDataSrc_(iConfig.getParameter<std::vector<edm::InputTag> >("src"))
103 {
104  for ( std::vector<edm::InputTag>::const_iterator input_it = userDataSrc_.begin(); input_it != userDataSrc_.end(); ++input_it ) {
105  userDataSrcTokens_.push_back( iC.consumes< typename Operation::product_type >( *input_it ) );
106  }
107 }
108 
109 
110 /* ==================================================================================
111  PATUserDataMerger::add
112  This expects four inputs:
113  patObject: ObjectType to add to
114 
115  from Event:
116  userDataSrc: The data to add, which is a ValueMap keyed by recoObject
117 
118  from Setup:
119  none currently
120 
121  This will simply add the UserData *'s from the value map that are
122  indexed by the reco objects, to the pat object's user data vector.
123  ==================================================================================
124 */
125 
126 template<class ObjectType, typename Operation>
127 void
129  edm::Event const & iEvent,
130  const edm::EventSetup& iSetup)
131 {
132 
133  typename std::vector<edm::EDGetTokenT<typename Operation::product_type> >::const_iterator token_begin = userDataSrcTokens_.begin(), token_it = userDataSrcTokens_.begin(), token_end = userDataSrcTokens_.end();
134 
135  for ( ; token_it != token_end; ++token_it ) {
136  const std::string encoded( userDataSrc_.at(token_it - token_begin).encode() );
137 
138  // Declare the object handles:
139  // ValueMap containing the values, or edm::Ptr's to the UserData that
140  // is associated to those PAT Objects
142 
143  // Get the objects by label
144  if ( encoded.size() == 0 ) continue;
145  iEvent.getByToken( *token_it, userData );
146 
147  edm::Ptr<reco::Candidate> recoObject = patObject.originalObjectRef();
148  loader_.addData( patObject, encoded, (*userData)[recoObject]);
149 
150  }
151 
152 }
153 
154 template<class ObjectType, typename Operation>
155 void
157 {
158  iDesc.add<std::vector<edm::InputTag> >("src");
159 }
160 
161 #endif
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
edm::ValueMap< value_type > product_type
std::vector< edm::EDGetTokenT< typename Operation::product_type > > userDataSrcTokens_
Assimilates pat::UserData into pat objects.
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
reco::CandidatePtr value_type
void addData(ObjectType &obj, const std::string &key, const value_type &val)
edm::ValueMap< value_type > product_type
edm::ValueMap< value_type > product_type
int iEvent
Definition: GenABIO.cc:230
void addData(ObjectType &obj, const std::string &key, const value_type &val)
edm::ValueMap< value_type > product_type
ParameterDescriptionBase * add(U const &iLabel, T const &value)
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
void addData(ObjectType &obj, const std::string &key, const value_type &val)
std::vector< edm::InputTag > userDataSrc_
static void fillDescription(edm::ParameterSetDescription &iDesc)
void addData(ObjectType &obj, const std::string &key, const value_type &val)
void add(ObjectType &patObject, edm::Event const &iEvent, edm::EventSetup const &iSetup)
edm::Ptr< UserData > value_type