Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:50

0001 #ifndef __PhysicsTools_PatAlgos_ObjectModifier_h__
0002 #define __PhysicsTools_PatAlgos_ObjectModifier_h__
0003 
0004 #include "CommonTools/CandAlgos/interface/ModifyObjectValueBase.h"
0005 #include <memory>
0006 
0007 namespace pat {
0008   template <class T>
0009   class ObjectModifier {
0010   public:
0011     typedef std::unique_ptr<ModifyObjectValueBase> ModifierPointer;
0012 
0013     ObjectModifier(const edm::ParameterSet& conf, edm::ConsumesCollector&& cc);
0014     ~ObjectModifier() {}
0015 
0016     void setEvent(const edm::Event& event) {
0017       for (unsigned i = 0; i < modifiers_.size(); ++i)
0018         modifiers_[i]->setEvent(event);
0019     }
0020 
0021     void setEventContent(const edm::EventSetup& setup) {
0022       for (unsigned i = 0; i < modifiers_.size(); ++i)
0023         modifiers_[i]->setEventContent(setup);
0024     }
0025 
0026     void modify(T& obj) const {
0027       for (unsigned i = 0; i < modifiers_.size(); ++i)
0028         modifiers_[i]->modifyObject(obj);
0029     }
0030 
0031   private:
0032     std::vector<ModifierPointer> modifiers_;
0033   };
0034 
0035   template <class T>
0036   ObjectModifier<T>::ObjectModifier(const edm::ParameterSet& conf, edm::ConsumesCollector&& cc) {
0037     const std::vector<edm::ParameterSet>& mods = conf.getParameterSetVector("modifications");
0038     for (unsigned i = 0; i < mods.size(); ++i) {
0039       const edm::ParameterSet& iconf = mods[i];
0040       const std::string& mname = iconf.getParameter<std::string>("modifierName");
0041       modifiers_.emplace_back(ModifyObjectValueFactory::get()->create(mname, iconf, cc));
0042     }
0043   }
0044 }  // namespace pat
0045 
0046 #endif