test
CMS 3D CMS Logo

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