Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:43

0001 #include "FWCore/Framework/interface/global/EDProducer.h"
0002 #include "FWCore/Framework/interface/Run.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0006 #include "DataFormats/NanoAOD/interface/UniqueString.h"
0007 
0008 #include <vector>
0009 
0010 class UniqueStringProducer : public edm::global::EDProducer<edm::BeginRunProducer> {
0011 public:
0012   UniqueStringProducer(edm::ParameterSet const& iConfig) {
0013     const edm::ParameterSet& strings = iConfig.getParameter<edm::ParameterSet>("strings");
0014     for (const std::string& vname : strings.getParameterNamesForType<std::string>()) {
0015       strings_.emplace_back(vname, strings.getParameter<std::string>(vname));
0016       produces<nanoaod::UniqueString, edm::InRun>(vname);
0017     }
0018   }
0019 
0020   ~UniqueStringProducer() override {}
0021 
0022   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0023     edm::ParameterSetDescription desc;
0024     edm::ParameterSetDescription strings;
0025     strings.setComment("a parameter set definining the a pair of strings to be added in run flat table");
0026     strings.addNode(edm::ParameterWildcard<std::string>("*", edm::RequireZeroOrMore, true));
0027     desc.add<edm::ParameterSetDescription>("strings", strings);
0028 
0029     descriptions.addWithDefaultLabel(desc);
0030   }
0031   void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override {}  // do nothing
0032 
0033   void globalBeginRunProduce(edm::Run& iRun, edm::EventSetup const&) const override {
0034     for (const auto& pair : strings_) {
0035       iRun.put(std::make_unique<nanoaod::UniqueString>(pair.second), pair.first);
0036     }
0037   }
0038 
0039 protected:
0040   std::vector<std::pair<std::string, std::string>> strings_;
0041 };
0042 
0043 #include "FWCore/Framework/interface/MakerMacros.h"
0044 DEFINE_FWK_MODULE(UniqueStringProducer);