PhysicsTools
PatAlgos
interface
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
23
#include "
FWCore/Framework/interface/EDProducer.h
"
24
#include "
FWCore/Framework/interface/Event.h
"
25
#include "
FWCore/Framework/interface/ConsumesCollector.h
"
26
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
27
#include "
FWCore/Utilities/interface/InputTag.h
"
28
#include "
FWCore/Utilities/interface/transform.h
"
29
#include "
DataFormats/Common/interface/View.h
"
30
#include "
DataFormats/Common/interface/Ptr.h
"
31
#include "
DataFormats/Common/interface/Association.h
"
32
#include "
DataFormats/Candidate/interface/CandidateFwd.h
"
33
#include "
DataFormats/Candidate/interface/Candidate.h
"
34
#include "
DataFormats/PatCandidates/interface/PATObject.h
"
35
36
#include "
FWCore/ParameterSet/interface/ConfigurationDescriptions.h
"
37
#include "
FWCore/ParameterSet/interface/ParameterSetDescription.h
"
38
39
#include <iostream>
40
41
namespace
pat
{
42
namespace
helper
{
43
struct
AddUserInt
{
44
typedef
int
value_type
;
45
typedef
edm::ValueMap<value_type>
product_type
;
46
template
<
typename
ObjectType>
47
void
addData
(
ObjectType
&
obj
,
const
std::string
&
key
,
const
value_type
&
val
) {
48
obj
.addUserInt(
key
,
val
);
49
}
50
};
51
struct
AddUserFloat
{
52
typedef
float
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
obj
.addUserFloat(
key
,
val
);
57
}
58
};
59
struct
AddUserPtr
{
60
typedef
edm::Ptr<UserData>
value_type
;
61
typedef
edm::ValueMap<value_type>
product_type
;
62
template
<
typename
ObjectType>
63
void
addData
(
ObjectType
&
obj
,
const
std::string
&
key
,
const
value_type
&
val
) {
64
obj
.addUserDataFromPtr(
key
,
val
);
65
}
66
};
67
struct
AddUserCand
{
68
typedef
reco::CandidatePtr
value_type
;
69
typedef
edm::ValueMap<value_type>
product_type
;
70
template
<
typename
ObjectType>
71
void
addData
(
ObjectType
&
obj
,
const
std::string
&
key
,
const
value_type
&
val
) {
72
obj
.addUserCand(
key
,
val
);
73
}
74
};
75
76
}
// namespace helper
77
78
template
<
typename
ObjectType,
typename
Operation>
79
class
PATUserDataMerger
{
80
public
:
81
PATUserDataMerger
() {}
82
PATUserDataMerger
(
const
edm::ParameterSet
&iConfig,
edm::ConsumesCollector
&iC);
83
~PATUserDataMerger
() {}
84
85
static
void
fillDescription
(
edm::ParameterSetDescription
&iDesc);
86
87
// Method to call from PATUserDataHelper to add information to the PATObject in question.
88
void
add
(
ObjectType
&patObject,
edm::Event
const
&
iEvent
,
edm::EventSetup
const
&iSetup);
89
90
private
:
91
// configurables
92
std::vector<edm::InputTag>
userDataSrc_
;
93
std::vector<edm::EDGetTokenT<typename Operation::product_type>>
userDataSrcTokens_
;
94
std::vector<std::string>
labelPostfixesToStrip_
,
labels_
;
95
Operation
loader_
;
96
};
97
98
}
// namespace pat
99
100
// Constructor: Initilize user data src
101
template
<
typename
ObjectType,
typename
Operation>
102
pat::PATUserDataMerger<ObjectType, Operation>::PATUserDataMerger
(
const
edm::ParameterSet
&iConfig,
103
edm::ConsumesCollector
&iC)
104
: userDataSrc_(iConfig.getParameter<
std
::vector<
edm
::
InputTag
>>(
"src"
)),
105
labelPostfixesToStrip_(iConfig.existsAs<
std
::vector<
std
::
string
>>(
"labelPostfixesToStrip"
)
106
? iConfig.getParameter<
std
::vector<
std
::
string
>>(
"labelPostfixesToStrip"
)
107
:
std
::vector<
std
::
string
>()) {
108
for
(std::vector<edm::InputTag>::const_iterator input_it = userDataSrc_.begin(); input_it != userDataSrc_.end();
109
++input_it) {
110
userDataSrcTokens_.push_back(iC.
consumes
<
typename
Operation::product_type>(*input_it));
111
}
112
for
(
edm::InputTag
tag
: userDataSrc_) {
// copy by value
113
for
(
const
std::string
&stripme : labelPostfixesToStrip_) {
114
auto
match
=
tag
.label().rfind(stripme);
115
if
(
match
== (
tag
.label().length() - stripme.length())) {
116
tag
=
edm::InputTag
(
tag
.label().substr(0,
match
),
tag
.instance(),
tag
.process());
117
}
118
}
119
labels_.push_back(
tag
.encode());
120
}
121
}
122
123
/* ==================================================================================
124
PATUserDataMerger::add
125
This expects four inputs:
126
patObject: ObjectType to add to
127
128
from Event:
129
userDataSrc: The data to add, which is a ValueMap keyed by recoObject
130
131
from Setup:
132
none currently
133
134
This will simply add the UserData *'s from the value map that are
135
indexed by the reco objects, to the pat object's user data vector.
136
==================================================================================
137
*/
138
139
template
<
class
ObjectType,
typename
Operation>
140
void
pat::PATUserDataMerger<ObjectType, Operation>::add
(
ObjectType
&patObject,
141
edm::Event
const
&
iEvent
,
142
const
edm::EventSetup
&iSetup) {
143
typename
std::vector<edm::EDGetTokenT<typename Operation::product_type>>::const_iterator
144
token_begin = userDataSrcTokens_.begin(),
145
token_it = userDataSrcTokens_.begin(), token_end = userDataSrcTokens_.end();
146
147
for
(; token_it != token_end; ++token_it) {
148
const
std::string
&encoded = (labels_.at(token_it - token_begin));
149
150
// Declare the object handles:
151
// ValueMap containing the values, or edm::Ptr's to the UserData that
152
// is associated to those PAT Objects
153
edm::Handle<typename Operation::product_type>
userData
;
154
155
// Get the objects by label
156
if
(encoded.empty())
157
continue
;
158
iEvent
.getByToken(*token_it,
userData
);
159
160
edm::Ptr<reco::Candidate>
recoObject = patObject.originalObjectRef();
161
loader_.addData(patObject, encoded, (*
userData
)[recoObject]);
162
}
163
}
164
165
template
<
class
ObjectType,
typename
Operation>
166
void
pat::PATUserDataMerger<ObjectType, Operation>::fillDescription
(
edm::ParameterSetDescription
&iDesc) {
167
iDesc.
add
<std::vector<edm::InputTag>>(
"src"
);
168
iDesc.
addOptional
<std::vector<std::string>>(
"labelPostfixesToStrip"
, std::vector<std::string>());
169
}
170
171
#endif
pat::helper::AddUserInt::product_type
edm::ValueMap< value_type > product_type
Definition:
PATUserDataMerger.h:45
ConfigurationDescriptions.h
pat::helper::AddUserInt::value_type
int value_type
Definition:
PATUserDataMerger.h:44
pat::helper::AddUserPtr::addData
void addData(ObjectType &obj, const std::string &key, const value_type &val)
Definition:
PATUserDataMerger.h:63
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition:
ParameterSetDescription.h:95
EDProducer.h
pat::helper::AddUserFloat::product_type
edm::ValueMap< value_type > product_type
Definition:
PATUserDataMerger.h:53
edm
HLT enums.
Definition:
AlignableModifier.h:19
edm::ParameterSetDescription
Definition:
ParameterSetDescription.h:52
pat::PATUserDataMerger
Assimilates pat::UserData into pat objects.
Definition:
PATUserDataMerger.h:79
pat::helper::AddUserCand::value_type
reco::CandidatePtr value_type
Definition:
PATUserDataMerger.h:68
electronProducer_cfi.userData
userData
Definition:
electronProducer_cfi.py:19
pat::PATUserDataMerger::fillDescription
static void fillDescription(edm::ParameterSetDescription &iDesc)
Definition:
PATUserDataMerger.h:166
pat::helper::AddUserCand::product_type
edm::ValueMap< value_type > product_type
Definition:
PATUserDataMerger.h:69
Association.h
pat::helper::AddUserCand
Definition:
PATUserDataMerger.h:67
edm::Handle
Definition:
AssociativeIterator.h:50
edm::ParameterSetDescription::addOptional
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
Definition:
ParameterSetDescription.h:105
CandidateFwd.h
pat::PATUserDataMerger::labels_
std::vector< std::string > labels_
Definition:
PATUserDataMerger.h:94
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition:
GlobalPosition_Frontier_DevDB_cff.py:11
pat::helper::AddUserFloat::addData
void addData(ObjectType &obj, const std::string &key, const value_type &val)
Definition:
PATUserDataMerger.h:55
edm::ConsumesCollector::consumes
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Definition:
ConsumesCollector.h:49
ParameterSetDescription.h
getGTfromDQMFile.obj
obj
Definition:
getGTfromDQMFile.py:32
pat::helper::AddUserFloat
Definition:
PATUserDataMerger.h:51
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
pat::helper::AddUserPtr::value_type
edm::Ptr< UserData > value_type
Definition:
PATUserDataMerger.h:60
HLT_2018_cff.InputTag
InputTag
Definition:
HLT_2018_cff.py:79016
edm::ParameterSet
Definition:
ParameterSet.h:36
pat::PATUserDataMerger::~PATUserDataMerger
~PATUserDataMerger()
Definition:
PATUserDataMerger.h:83
Event.h
ecaldqm::binning::ObjectType
ObjectType
Definition:
MESetBinningUtils.h:17
pat::helper::AddUserCand::addData
void addData(ObjectType &obj, const std::string &key, const value_type &val)
Definition:
PATUserDataMerger.h:71
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition:
Utils.h:10
helper
Definition:
helper.py:1
Ptr.h
iEvent
int iEvent
Definition:
GenABIO.cc:224
pat::PATUserDataMerger::add
void add(ObjectType &patObject, edm::Event const &iEvent, edm::EventSetup const &iSetup)
Definition:
PATUserDataMerger.h:140
edm::EventSetup
Definition:
EventSetup.h:57
pat
Definition:
HeavyIon.h:7
pat::helper::AddUserInt::addData
void addData(ObjectType &obj, const std::string &key, const value_type &val)
Definition:
PATUserDataMerger.h:47
InputTag.h
edm::Ptr
Definition:
AssociationVector.h:31
pat::helper::AddUserPtr
Definition:
PATUserDataMerger.h:59
heppy_batch.val
val
Definition:
heppy_batch.py:351
std
Definition:
JetResolutionObject.h:76
pat::helper::AddUserPtr::product_type
edm::ValueMap< value_type > product_type
Definition:
PATUserDataMerger.h:61
transform.h
pat::PATUserDataMerger::labelPostfixesToStrip_
std::vector< std::string > labelPostfixesToStrip_
Definition:
PATUserDataMerger.h:94
edm::ValueMap
Definition:
ValueMap.h:107
pat::PATUserDataMerger::PATUserDataMerger
PATUserDataMerger()
Definition:
PATUserDataMerger.h:81
pat::PATUserDataMerger::loader_
Operation loader_
Definition:
PATUserDataMerger.h:95
ConsumesCollector.h
Candidate.h
View.h
ParameterSet.h
pat::helper::AddUserFloat::value_type
float value_type
Definition:
PATUserDataMerger.h:52
edm::Event
Definition:
Event.h:73
crabWrapper.key
key
Definition:
crabWrapper.py:19
pat::PATUserDataMerger::userDataSrcTokens_
std::vector< edm::EDGetTokenT< typename Operation::product_type > > userDataSrcTokens_
Definition:
PATUserDataMerger.h:93
edm::InputTag
Definition:
InputTag.h:15
pat::helper::AddUserInt
Definition:
PATUserDataMerger.h:43
edm::ConsumesCollector
Definition:
ConsumesCollector.h:39
pat::PATUserDataMerger::userDataSrc_
std::vector< edm::InputTag > userDataSrc_
Definition:
PATUserDataMerger.h:92
PATObject.h
Generated for CMSSW Reference Manual by
1.8.16