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