Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/global/EDProducer.h"
0002 #include "FWCore/Framework/interface/Run.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "DataFormats/NanoAOD/interface/UniqueString.h"
0005 
0006 #include <vector>
0007 
0008 class UniqueStringProducer : public edm::global::EDProducer<edm::BeginRunProducer> {
0009 public:
0010   UniqueStringProducer(edm::ParameterSet const& iConfig) {
0011     const edm::ParameterSet& strings = iConfig.getParameter<edm::ParameterSet>("strings");
0012     for (const std::string& vname : strings.getParameterNamesForType<std::string>()) {
0013       strings_.emplace_back(vname, strings.getParameter<std::string>(vname));
0014       produces<nanoaod::UniqueString, edm::InRun>(vname);
0015     }
0016   }
0017 
0018   ~UniqueStringProducer() override {}
0019 
0020   void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {}  // do nothing
0021 
0022   void globalBeginRunProduce(edm::Run& iRun, edm::EventSetup const&) const override {
0023     for (const auto& pair : strings_) {
0024       iRun.put(std::make_unique<nanoaod::UniqueString>(pair.second), pair.first);
0025     }
0026   }
0027 
0028 protected:
0029   std::vector<std::pair<std::string, std::string>> strings_;
0030 };
0031 
0032 #include "FWCore/Framework/interface/MakerMacros.h"
0033 DEFINE_FWK_MODULE(UniqueStringProducer);