1 |
dgele |
1.1 |
//
|
2 |
|
|
// $Id: PATUserDataMerger.h,v 1.4.4.2 2009/04/28 14:29:39 gpetrucc Exp $
|
3 |
|
|
//
|
4 |
|
|
|
5 |
|
|
#ifndef PhysicsTools_PatAlgos_PATUserDataMerger_h
|
6 |
|
|
#define PhysicsTools_PatAlgos_PATUserDataMerger_h
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
\class pat::PATUserDataMerger PATUserDataMerger.h "PhysicsTools/PatAlgos/interface/PATUserDataMerger.h"
|
10 |
|
|
\brief Assimilates pat::UserData into pat objects
|
11 |
|
|
|
12 |
|
|
This expects one input:
|
13 |
|
|
src: The data to add to the objects that get passed to this
|
14 |
|
|
object, which are ValueMaps to some type (like UserData or double).
|
15 |
|
|
|
16 |
|
|
This will be called from PATUserDataHelper to handle the templated cases
|
17 |
|
|
like UserData or double. PATUserDataHelper will then add all the instantiated
|
18 |
|
|
cases.
|
19 |
|
|
|
20 |
|
|
\author Salvatore Rappoccio
|
21 |
|
|
\version $Id: PATUserDataMerger.h,v 1.4.4.2 2009/04/28 14:29:39 gpetrucc Exp $
|
22 |
|
|
*/
|
23 |
|
|
|
24 |
|
|
#include "FWCore/Framework/interface/EDProducer.h"
|
25 |
|
|
#include "FWCore/Framework/interface/Event.h"
|
26 |
|
|
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
27 |
|
|
#include "FWCore/ParameterSet/interface/InputTag.h"
|
28 |
|
|
#include "DataFormats/Common/interface/View.h"
|
29 |
|
|
#include "DataFormats/Common/interface/Ptr.h"
|
30 |
|
|
#include "DataFormats/Common/interface/Association.h"
|
31 |
|
|
#include "DataFormats/Candidate/interface/Candidate.h"
|
32 |
|
|
#include "DataFormats/PatCandidates/interface/PATObject.h"
|
33 |
|
|
|
34 |
|
|
#include <iostream>
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
namespace pat {
|
38 |
|
|
namespace helper {
|
39 |
|
|
struct AddUserInt {
|
40 |
|
|
typedef int value_type;
|
41 |
|
|
typedef edm::ValueMap<value_type> product_type;
|
42 |
|
|
template<typename ObjectType>
|
43 |
|
|
void addData(ObjectType &obj, const std::string & key, const value_type &val) { obj.addUserInt(key, val); }
|
44 |
|
|
};
|
45 |
|
|
struct AddUserFloat {
|
46 |
|
|
typedef float value_type;
|
47 |
|
|
typedef edm::ValueMap<value_type> product_type;
|
48 |
|
|
template<typename ObjectType>
|
49 |
|
|
void addData(ObjectType &obj, const std::string & key, const value_type &val) { obj.addUserFloat(key, val); }
|
50 |
|
|
};
|
51 |
|
|
struct AddUserPtr {
|
52 |
|
|
typedef edm::Ptr<UserData> value_type;
|
53 |
|
|
typedef edm::ValueMap<value_type> product_type;
|
54 |
|
|
template<typename ObjectType>
|
55 |
|
|
void addData(ObjectType &obj, const std::string & key, const value_type &val) {
|
56 |
|
|
if (val.isNonnull()) obj.addUserDataFromPtr(key, val);
|
57 |
|
|
}
|
58 |
|
|
};
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
template<typename ObjectType, typename Operation>
|
62 |
|
|
class PATUserDataMerger {
|
63 |
|
|
|
64 |
|
|
public:
|
65 |
|
|
|
66 |
|
|
PATUserDataMerger() {}
|
67 |
|
|
PATUserDataMerger(const edm::ParameterSet & iConfig);
|
68 |
|
|
~PATUserDataMerger() {}
|
69 |
|
|
|
70 |
|
|
// Method to call from PATUserDataHelper to add information to the PATObject in question.
|
71 |
|
|
void add(ObjectType & patObject,
|
72 |
|
|
edm::Event const & iEvent, edm::EventSetup const & iSetup);
|
73 |
|
|
|
74 |
|
|
private:
|
75 |
|
|
|
76 |
|
|
// configurables
|
77 |
|
|
std::vector<edm::InputTag> userDataSrc_; // ValueMap containing the user data
|
78 |
|
|
Operation loader_;
|
79 |
|
|
|
80 |
|
|
};
|
81 |
|
|
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
// Constructor: Initilize user data src
|
85 |
|
|
template<typename ObjectType, typename Operation>
|
86 |
|
|
pat::PATUserDataMerger<ObjectType, Operation>::PATUserDataMerger(const edm::ParameterSet & iConfig) :
|
87 |
|
|
userDataSrc_(iConfig.getParameter<std::vector<edm::InputTag> >("src") )
|
88 |
|
|
{
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
/* ==================================================================================
|
93 |
|
|
PATUserDataMerger::add
|
94 |
|
|
This expects four inputs:
|
95 |
|
|
patObject: ObjectType to add to
|
96 |
|
|
|
97 |
|
|
from Event:
|
98 |
|
|
userDataSrc: The data to add, which is a ValueMap keyed by recoObject
|
99 |
|
|
|
100 |
|
|
from Setup:
|
101 |
|
|
none currently
|
102 |
|
|
|
103 |
|
|
This will simply add the UserData *'s from the value map that are
|
104 |
|
|
indexed by the reco objects, to the pat object's user data vector.
|
105 |
|
|
==================================================================================
|
106 |
|
|
*/
|
107 |
|
|
|
108 |
|
|
template<class ObjectType, typename Operation>
|
109 |
|
|
void
|
110 |
|
|
pat::PATUserDataMerger<ObjectType, Operation>::add(ObjectType & patObject,
|
111 |
|
|
edm::Event const & iEvent,
|
112 |
|
|
const edm::EventSetup & iSetup )
|
113 |
|
|
{
|
114 |
|
|
|
115 |
|
|
std::vector<edm::InputTag>::const_iterator input_it = userDataSrc_.begin(),
|
116 |
|
|
input_begin = userDataSrc_.begin(),
|
117 |
|
|
input_end = userDataSrc_.end();
|
118 |
|
|
|
119 |
|
|
for ( ; input_it != input_end; ++input_it ) {
|
120 |
|
|
|
121 |
|
|
// Declare the object handles:
|
122 |
|
|
// ValueMap containing the values, or edm::Ptr's to the UserData that
|
123 |
|
|
// is associated to those PAT Objects
|
124 |
|
|
edm::Handle<typename Operation::product_type> userData;
|
125 |
|
|
|
126 |
|
|
// Get the objects by label
|
127 |
|
|
iEvent.getByLabel( *input_it, userData );
|
128 |
|
|
|
129 |
|
|
edm::Ptr<reco::Candidate> recoObject = patObject.originalObjectRef();
|
130 |
|
|
if ( userData->contains( recoObject.id() ) ) {
|
131 |
|
|
loader_.addData( patObject, input_it->encode(), (*userData)[recoObject]);
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
}
|
135 |
|
|
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
#endif
|