File indexing completed on 2025-01-31 02:19:33
0001 #ifdef __clang__
0002 #pragma GCC diagnostic ignored "-Wc++20-extensions"
0003 #endif
0004
0005 #include "FWCore/Framework/interface/global/EDProducer.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0008
0009 namespace edm {
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 class SwitchProducer : public global::EDProducer<> {
0020 public:
0021 explicit SwitchProducer(ParameterSet const& iConfig);
0022 ~SwitchProducer() override = default;
0023 static void fillDescriptions(ConfigurationDescriptions& descriptions);
0024 void produce(StreamID, Event& e, EventSetup const& c) const final {}
0025 };
0026
0027 SwitchProducer::SwitchProducer(ParameterSet const& iConfig) {
0028 auto const& moduleLabel = iConfig.getParameter<std::string>("@module_label");
0029 auto const& chosenLabel = iConfig.getUntrackedParameter<std::string>("@chosen_case");
0030 auto const& processName = iConfig.getUntrackedParameter<std::string>("@process_name");
0031 callWhenNewProductsRegistered([=, this](edm::ProductDescription const& iBranch) {
0032 if (iBranch.moduleLabel() == chosenLabel and iBranch.processName() == processName) {
0033 if (iBranch.branchType() != InEvent) {
0034 throw Exception(errors::UnimplementedFeature)
0035 << "SwitchProducer does not support non-event branches. Got " << iBranch.branchType()
0036 << " for SwitchProducer with label " << moduleLabel << " whose chosen case is " << chosenLabel << ".";
0037 }
0038
0039
0040 this->consumes(edm::TypeToGet{iBranch.unwrappedTypeID(), PRODUCT_TYPE},
0041 edm::InputTag{iBranch.moduleLabel(), iBranch.productInstanceName(), iBranch.processName()});
0042
0043
0044
0045 this->produces(iBranch.unwrappedTypeID(), iBranch.productInstanceName()).setSwitchAlias(iBranch.moduleLabel());
0046 }
0047 });
0048 }
0049
0050 void SwitchProducer::fillDescriptions(ConfigurationDescriptions& descriptions) {
0051 ParameterSetDescription desc;
0052 desc.add<std::vector<std::string>>("@all_cases");
0053 desc.addUntracked<std::string>("@chosen_case");
0054 desc.addUntracked<std::string>("@process_name");
0055 descriptions.addDefault(desc);
0056 }
0057 }
0058
0059 using edm::SwitchProducer;
0060 DEFINE_FWK_MODULE(SwitchProducer);