ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/DGele/PhysicsTools/PatAlgos/interface/PATUserDataHelper.h
Revision: 1.1
Committed: Tue Oct 20 17:15:14 2009 UTC (15 years, 6 months ago) by dgele
Content type: text/plain
Branch: MAIN
Branch point for: ANA
Log Message:
Initial revision

File Contents

# User Rev Content
1 dgele 1.1 //
2     // $Id: PATUserDataHelper.h,v 1.4 2008/10/07 17:44:16 gpetrucc Exp $
3     //
4    
5     #ifndef PhysicsTools_PatAlgos_PATUserDataHelper_h
6     #define PhysicsTools_PatAlgos_PATUserDataHelper_h
7    
8     /**
9     \class pat::PATUserDataHelper PATUserDataHelper.h "PhysicsTools/PatAlgos/interface/PATUserDataHelper.h"
10     \brief Assists in assimilating all pat::UserData into pat objects.
11    
12    
13     This will pull the following from the event stream (if they exist) and put them into the
14     object in question, all indexed by the reco objects that make up the pat objects in question:
15    
16     * ValueMap<double>
17     * ValueMap<int>
18     * ValueMap<UserData>
19    
20     This is accomplished by using PATUserDataMergers.
21    
22     This also can add "in situ" string-parser-based methods directly.
23    
24     \author Salvatore Rappoccio
25     \version $Id: PATUserDataHelper.h,v 1.4 2008/10/07 17:44:16 gpetrucc Exp $
26     */
27    
28    
29     #include "FWCore/Framework/interface/EDProducer.h"
30     #include "FWCore/Framework/interface/Event.h"
31     #include "FWCore/ParameterSet/interface/ParameterSet.h"
32     #include "FWCore/ParameterSet/interface/InputTag.h"
33     #include "DataFormats/Common/interface/View.h"
34     #include "DataFormats/Common/interface/Ptr.h"
35     #include "DataFormats/Common/interface/Association.h"
36     #include "DataFormats/PatCandidates/interface/PATObject.h"
37    
38     #include "DataFormats/PatCandidates/interface/UserData.h"
39     #include "DataFormats/Candidate/interface/Candidate.h"
40     #include "PhysicsTools/PatAlgos/interface/PATUserDataMerger.h"
41     #include "PhysicsTools/Utilities/interface/StringObjectFunction.h"
42    
43    
44     #include <iostream>
45    
46    
47     namespace pat {
48    
49    
50     template<class ObjectType>
51     class PATUserDataHelper {
52    
53     public:
54    
55     typedef StringObjectFunction<ObjectType> function_type;
56    
57     PATUserDataHelper() {}
58     PATUserDataHelper(const edm::ParameterSet & iConfig);
59     ~PATUserDataHelper() {}
60    
61    
62     // Adds information from user data to patObject,
63     // using recoObject as the key
64     void add(ObjectType & patObject,
65     edm::Event const & iEvent, edm::EventSetup const & iSetup);
66    
67     private:
68    
69     // Custom user data
70     pat::PATUserDataMerger<ObjectType, pat::helper::AddUserPtr> userDataMerger_;
71     // User doubles
72     pat::PATUserDataMerger<ObjectType, pat::helper::AddUserFloat> userFloatMerger_;
73     // User ints
74     pat::PATUserDataMerger<ObjectType, pat::helper::AddUserInt> userIntMerger_;
75    
76     // Inline functions that operate on ObjectType
77     std::vector<std::string> functionNames_;
78     std::vector<std::string> functionLabels_;
79     std::vector<function_type > functions_;
80    
81     };
82    
83     // Constructor: Initilize user data src
84     template<class ObjectType>
85     PATUserDataHelper<ObjectType>::PATUserDataHelper(const edm::ParameterSet & iConfig) :
86     userDataMerger_ (iConfig.getParameter<edm::ParameterSet>("userClasses")),
87     userFloatMerger_ (iConfig.getParameter<edm::ParameterSet>("userFloats")),
88     userIntMerger_ (iConfig.getParameter<edm::ParameterSet>("userInts")),
89     functionNames_ (iConfig.getParameter<std::vector<std::string> >("userFunctions")),
90     functionLabels_ (iConfig.getParameter<std::vector<std::string> >("userFunctionLabels"))
91     {
92    
93     // Make sure the sizes match
94     if ( functionNames_.size() != functionLabels_.size() ) {
95     throw cms::Exception("Size mismatch") << "userFunctions and userFunctionLabels do not have the same size, they must be the same\n";
96     }
97     // Loop over the function names, create a new string-parser function object
98     // with all of them. This operates on ObjectType
99     std::vector<std::string>::const_iterator funcBegin = functionNames_.begin(),
100     funcEnd = functionNames_.end(),
101     funcIt = funcBegin;
102     for ( ; funcIt != funcEnd; ++funcIt) {
103     functions_.push_back( StringObjectFunction<ObjectType>( *funcIt ) );
104     }
105     }
106    
107    
108     /* ==================================================================================
109     PATUserDataHelper::add
110     This expects four inputs:
111     patObject: PATObject<ObjectType> to add to
112     recoObject: The base for the value maps
113     iEvent: Passed to the various data mergers
114     iSetup: " "
115    
116     ==================================================================================
117     */
118    
119     template<class ObjectType>
120     void PATUserDataHelper<ObjectType>::add(ObjectType & patObject,
121     edm::Event const & iEvent,
122     const edm::EventSetup & iSetup )
123     {
124    
125     // Add "complex" user data to the PAT object
126     userDataMerger_.add( patObject, iEvent, iSetup );
127     userFloatMerger_.add( patObject, iEvent, iSetup );
128     userIntMerger_.add( patObject, iEvent, iSetup );
129    
130     // Add "inline" user-selected functions to the PAT object
131     typename std::vector<function_type>::const_iterator funcBegin = functions_.begin(),
132     funcEnd = functions_.end(),
133     funcIt = funcBegin;
134     if ( functionLabels_.size() == functions_.size() ) {
135     for ( ; funcIt != funcEnd; ++funcIt) {
136     double d = (*funcIt)( patObject );
137     patObject.addUserFloat( functionLabels_[funcIt - funcBegin], d );
138     }
139     }
140    
141    
142     }
143    
144    
145     }
146     #endif