CMS 3D CMS Logo

PATUserDataHelper.h
Go to the documentation of this file.
1 //
2 //
3 
4 #ifndef PhysicsTools_PatAlgos_PATUserDataHelper_h
5 #define PhysicsTools_PatAlgos_PATUserDataHelper_h
6 
37 
43 
44 #include <iostream>
45 
46 namespace pat {
47 
48  template <class ObjectType>
50  public:
52 
56 
58 
59  // Adds information from user data to patObject,
60  // using recoObject as the key
61  void add(ObjectType& patObject, edm::Event const& iEvent, edm::EventSetup const& iSetup);
62 
63  private:
64  // Custom user data
66  // User doubles
68  // User ints
70  // User candidate ptrs
72 
73  // Inline functions that operate on ObjectType
74  std::vector<std::string> functionNames_;
75  std::vector<std::string> functionLabels_;
76  std::vector<function_type> functions_;
77  };
78 
79  // Constructor: Initilize user data src
80  template <class ObjectType>
82  : userDataMerger_(iConfig.getParameter<edm::ParameterSet>("userClasses"), iC),
83  userFloatMerger_(iConfig.getParameter<edm::ParameterSet>("userFloats"), iC),
84  userIntMerger_(iConfig.getParameter<edm::ParameterSet>("userInts"), iC),
85  userCandMerger_(iConfig.getParameter<edm::ParameterSet>("userCands"), iC),
86  functionNames_(iConfig.getParameter<std::vector<std::string> >("userFunctions")),
87  functionLabels_(iConfig.getParameter<std::vector<std::string> >("userFunctionLabels")) {
88  // Make sure the sizes match
89  if (functionNames_.size() != functionLabels_.size()) {
90  throw cms::Exception("Size mismatch")
91  << "userFunctions and userFunctionLabels do not have the same size, they must be the same\n";
92  }
93  // Loop over the function names, create a new string-parser function object
94  // with all of them. This operates on ObjectType
95  std::vector<std::string>::const_iterator funcBegin = functionNames_.begin(), funcEnd = functionNames_.end(),
96  funcIt = funcBegin;
97  for (; funcIt != funcEnd; ++funcIt) {
98  functions_.push_back(StringObjectFunction<ObjectType>(*funcIt));
99  }
100  }
101 
102  /* ==================================================================================
103  PATUserDataHelper::add
104  This expects four inputs:
105  patObject: PATObject<ObjectType> to add to
106  recoObject: The base for the value maps
107  iEvent: Passed to the various data mergers
108  iSetup: " "
109 
110  ==================================================================================
111 */
112 
113  template <class ObjectType>
115  edm::Event const& iEvent,
116  const edm::EventSetup& iSetup) {
117  // Add "complex" user data to the PAT object
118  userDataMerger_.add(patObject, iEvent, iSetup);
119  userFloatMerger_.add(patObject, iEvent, iSetup);
120  userIntMerger_.add(patObject, iEvent, iSetup);
121  userCandMerger_.add(patObject, iEvent, iSetup);
122 
123  // Add "inline" user-selected functions to the PAT object
124  typename std::vector<function_type>::const_iterator funcBegin = functions_.begin(), funcEnd = functions_.end(),
125  funcIt = funcBegin;
126  if (functionLabels_.size() == functions_.size()) {
127  for (; funcIt != funcEnd; ++funcIt) {
128  double d = (*funcIt)(patObject);
129  patObject.addUserFloat(functionLabels_[funcIt - funcBegin], d);
130  }
131  }
132  }
133 
134  template <class ObjectType>
136  edm::ParameterSetDescription dataMergerPSet;
138  iDesc.add("userClasses", dataMergerPSet);
139  iDesc.add("userFloats", dataMergerPSet);
140  iDesc.add("userInts", dataMergerPSet);
141  iDesc.add("userCands", dataMergerPSet);
142  std::vector<std::string> emptyVectorOfStrings;
143  iDesc.add<std::vector<std::string> >("userFunctions", emptyVectorOfStrings);
144  iDesc.add<std::vector<std::string> >("userFunctionLabels", emptyVectorOfStrings);
145  }
146 
147 } // namespace pat
148 #endif
PATUserDataMerger.h
pat::PATUserDataHelper
Assists in assimilating all pat::UserData into pat objects.
Definition: PATUserDataHelper.h:49
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
StringObjectFunction
Definition: StringObjectFunction.h:16
pat::PATUserDataHelper::userIntMerger_
pat::PATUserDataMerger< ObjectType, pat::helper::AddUserInt > userIntMerger_
Definition: PATUserDataHelper.h:69
EDProducer.h
pat::PATUserDataHelper::function_type
StringObjectFunction< ObjectType > function_type
Definition: PATUserDataHelper.h:51
pat::PATUserDataHelper::userCandMerger_
pat::PATUserDataMerger< ObjectType, pat::helper::AddUserCand > userCandMerger_
Definition: PATUserDataHelper.h:71
edm
HLT enums.
Definition: AlignableModifier.h:19
pat::PATUserDataHelper::fillDescription
static void fillDescription(edm::ParameterSetDescription &iDesc)
Definition: PATUserDataHelper.h:135
pat::PATUserDataHelper::functionLabels_
std::vector< std::string > functionLabels_
Definition: PATUserDataHelper.h:75
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
pat::PATUserDataMerger< ObjectType, pat::helper::AddUserPtr >
pat::PATUserDataHelper::PATUserDataHelper
PATUserDataHelper()
Definition: PATUserDataHelper.h:53
pat::PATUserDataMerger::fillDescription
static void fillDescription(edm::ParameterSetDescription &iDesc)
Definition: PATUserDataMerger.h:166
Association.h
pat::PATUserDataHelper::userFloatMerger_
pat::PATUserDataMerger< ObjectType, pat::helper::AddUserFloat > userFloatMerger_
Definition: PATUserDataHelper.h:67
CandidateFwd.h
pat::PATUserDataHelper::add
void add(ObjectType &patObject, edm::Event const &iEvent, edm::EventSetup const &iSetup)
Definition: PATUserDataHelper.h:114
pat::PATUserDataHelper::userDataMerger_
pat::PATUserDataMerger< ObjectType, pat::helper::AddUserPtr > userDataMerger_
Definition: PATUserDataHelper.h:65
pat::PATUserDataHelper::functionNames_
std::vector< std::string > functionNames_
Definition: PATUserDataHelper.h:74
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
ParameterSet
Definition: Functions.h:16
ecaldqm::binning::ObjectType
ObjectType
Definition: MESetBinningUtils.h:17
UserData.h
PVValHelper::add
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
Definition: PVValidationHelpers.cc:12
Ptr.h
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
InputTag.h
std
Definition: JetResolutionObject.h:76
Exception
Definition: hltDiff.cc:246
pat::PATUserDataHelper::~PATUserDataHelper
~PATUserDataHelper()
Definition: PATUserDataHelper.h:55
ztail.d
d
Definition: ztail.py:151
ConsumesCollector.h
Candidate.h
View.h
ParameterSet.h
pat::PATUserDataHelper::functions_
std::vector< function_type > functions_
Definition: PATUserDataHelper.h:76
edm::Event
Definition: Event.h:73
StringObjectFunction.h
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
PATObject.h