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 // $Id: PATUserDataMerger.h,v 1.10 2011/10/26 17:01:25 vadler Exp $
3 //
4 
5 #ifndef PhysicsTools_PatAlgos_PATUserDataMerger_h
6 #define PhysicsTools_PatAlgos_PATUserDataMerger_h
7 
34 
37 
38 #include <iostream>
39 
40 
41 namespace pat {
42  namespace helper {
43  struct AddUserInt {
44  typedef int value_type;
46  template<typename ObjectType>
47  void addData(ObjectType &obj, const std::string & key, const value_type &val) { obj.addUserInt(key, val); }
48  };
49  struct AddUserFloat {
50  typedef float value_type;
52  template<typename ObjectType>
53  void addData(ObjectType &obj, const std::string & key, const value_type &val) { obj.addUserFloat(key, val); }
54  };
55  struct AddUserPtr {
58  template<typename ObjectType>
59  void addData(ObjectType &obj, const std::string & key, const value_type &val) {
60  obj.addUserDataFromPtr(key, val);
61  }
62  };
63  struct AddUserCand {
66  template<typename ObjectType>
67  void addData(ObjectType &obj, const std::string & key, const value_type &val) { obj.addUserCand(key, val); }
68  };
69 
70  }
71 
72  template<typename ObjectType, typename Operation>
74 
75  public:
76 
78  PATUserDataMerger(const edm::ParameterSet & iConfig);
80 
81  static void fillDescription(edm::ParameterSetDescription & iDesc);
82 
83  // Method to call from PATUserDataHelper to add information to the PATObject in question.
84  void add(ObjectType & patObject,
85  edm::Event const & iEvent, edm::EventSetup const & iSetup);
86 
87  private:
88 
89  // configurables
90  std::vector<edm::InputTag> userDataSrc_; // ValueMap containing the user data
91  Operation loader_;
92 
93  };
94 
95 }
96 
97 // Constructor: Initilize user data src
98 template<typename ObjectType, typename Operation>
100  userDataSrc_(iConfig.getParameter<std::vector<edm::InputTag> >("src") )
101 {
102 }
103 
104 
105 /* ==================================================================================
106  PATUserDataMerger::add
107  This expects four inputs:
108  patObject: ObjectType to add to
109 
110  from Event:
111  userDataSrc: The data to add, which is a ValueMap keyed by recoObject
112 
113  from Setup:
114  none currently
115 
116  This will simply add the UserData *'s from the value map that are
117  indexed by the reco objects, to the pat object's user data vector.
118  ==================================================================================
119 */
120 
121 template<class ObjectType, typename Operation>
122 void
124  edm::Event const & iEvent,
125  const edm::EventSetup & iSetup )
126 {
127 
128  std::vector<edm::InputTag>::const_iterator input_it = userDataSrc_.begin(),
129 // input_begin = userDataSrc_.begin(), // warning from gcc461: variable 'input_begin' set but not used [-Wunused-but-set-variable]
130  input_end = userDataSrc_.end();
131 
132  for ( ; input_it != input_end; ++input_it ) {
133 
134  // Declare the object handles:
135  // ValueMap containing the values, or edm::Ptr's to the UserData that
136  // is associated to those PAT Objects
138 
139  // Get the objects by label
140  if ( input_it->encode().size() == 0 ) continue;
141  iEvent.getByLabel( *input_it, userData );
142 
143  edm::Ptr<reco::Candidate> recoObject = patObject.originalObjectRef();
144  if ( userData->contains( recoObject.id() ) ) {
145  loader_.addData( patObject, input_it->encode(), (*userData)[recoObject]);
146  }
147 
148  }
149 
150 }
151 
152 template<class ObjectType, typename Operation>
153 void
155 {
156  iDesc.add<std::vector<edm::InputTag> >("src");
157 }
158 
159 #endif
edm::ValueMap< value_type > product_type
Assimilates pat::UserData into pat objects.
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:243
void addData(ObjectType &obj, const std::string &key, const value_type &val)
edm::ValueMap< value_type > product_type
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:164
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
void addData(ObjectType &obj, const std::string &key, const value_type &val)
std::vector< edm::InputTag > userDataSrc_
static void fillDescription(edm::ParameterSetDescription &iDesc)
list key
Definition: combine.py:13
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