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