CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
36 
42 
43 #include <iostream>
44 
45 namespace pat {
46 
47  template <class ObjectType>
49  public:
51 
55 
57 
58  // Adds information from user data to patObject,
59  // using recoObject as the key
60  void add(ObjectType& patObject, edm::Event const& iEvent, edm::EventSetup const& iSetup);
61 
62  private:
63  // Custom user data
65  // User doubles
67  // User ints
69  // User candidate ptrs
71 
72  // Inline functions that operate on ObjectType
73  std::vector<std::string> functionNames_;
74  std::vector<std::string> functionLabels_;
75  std::vector<function_type> functions_;
76  };
77 
78  // Constructor: Initilize user data src
79  template <class ObjectType>
81  : userDataMerger_(iConfig.getParameter<edm::ParameterSet>("userClasses"), iC),
82  userFloatMerger_(iConfig.getParameter<edm::ParameterSet>("userFloats"), iC),
83  userIntMerger_(iConfig.getParameter<edm::ParameterSet>("userInts"), iC),
84  userCandMerger_(iConfig.getParameter<edm::ParameterSet>("userCands"), iC),
85  functionNames_(iConfig.getParameter<std::vector<std::string> >("userFunctions")),
86  functionLabels_(iConfig.getParameter<std::vector<std::string> >("userFunctionLabels")) {
87  // Make sure the sizes match
88  if (functionNames_.size() != functionLabels_.size()) {
89  throw cms::Exception("Size mismatch")
90  << "userFunctions and userFunctionLabels do not have the same size, they must be the same\n";
91  }
92  // Loop over the function names, create a new string-parser function object
93  // with all of them. This operates on ObjectType
94  std::vector<std::string>::const_iterator funcBegin = functionNames_.begin(), funcEnd = functionNames_.end(),
95  funcIt = funcBegin;
96  for (; funcIt != funcEnd; ++funcIt) {
97  functions_.push_back(StringObjectFunction<ObjectType>(*funcIt));
98  }
99  }
100 
101  /* ==================================================================================
102  PATUserDataHelper::add
103  This expects four inputs:
104  patObject: PATObject<ObjectType> to add to
105  recoObject: The base for the value maps
106  iEvent: Passed to the various data mergers
107  iSetup: " "
108 
109  ==================================================================================
110 */
111 
112  template <class ObjectType>
114  edm::Event const& iEvent,
115  const edm::EventSetup& iSetup) {
116  // Add "complex" user data to the PAT object
117  userDataMerger_.add(patObject, iEvent, iSetup);
118  userFloatMerger_.add(patObject, iEvent, iSetup);
119  userIntMerger_.add(patObject, iEvent, iSetup);
120  userCandMerger_.add(patObject, iEvent, iSetup);
121 
122  // Add "inline" user-selected functions to the PAT object
123  typename std::vector<function_type>::const_iterator funcBegin = functions_.begin(), funcEnd = functions_.end(),
124  funcIt = funcBegin;
125  if (functionLabels_.size() == functions_.size()) {
126  for (; funcIt != funcEnd; ++funcIt) {
127  double d = (*funcIt)(patObject);
128  patObject.addUserFloat(functionLabels_[funcIt - funcBegin], d);
129  }
130  }
131  }
132 
133  template <class ObjectType>
135  edm::ParameterSetDescription dataMergerPSet;
137  iDesc.add("userClasses", dataMergerPSet);
138  iDesc.add("userFloats", dataMergerPSet);
139  iDesc.add("userInts", dataMergerPSet);
140  iDesc.add("userCands", dataMergerPSet);
141  std::vector<std::string> emptyVectorOfStrings;
142  iDesc.add<std::vector<std::string> >("userFunctions", emptyVectorOfStrings);
143  iDesc.add<std::vector<std::string> >("userFunctionLabels", emptyVectorOfStrings);
144  }
145 
146 } // namespace pat
147 #endif
Assists in assimilating all pat::UserData into pat objects.
pat::PATUserDataMerger< ObjectType, pat::helper::AddUserFloat > userFloatMerger_
std::vector< function_type > functions_
pat::PATUserDataMerger< ObjectType, pat::helper::AddUserPtr > userDataMerger_
pat::PATUserDataMerger< ObjectType, pat::helper::AddUserCand > userCandMerger_
StringObjectFunction< ObjectType > function_type
static void fillDescription(edm::ParameterSetDescription &iDesc)
std::vector< std::string > functionLabels_
tuple d
Definition: ztail.py:151
int iEvent
Definition: GenABIO.cc:224
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(ObjectType &patObject, edm::Event const &iEvent, edm::EventSetup const &iSetup)
std::vector< std::string > functionNames_
static void fillDescription(edm::ParameterSetDescription &iDesc)
pat::PATUserDataMerger< ObjectType, pat::helper::AddUserInt > userIntMerger_