CMS 3D CMS Logo

SwitchProducer.cc
Go to the documentation of this file.
1 #ifdef __clang__
2 #pragma GCC diagnostic ignored "-Wc++20-extensions"
3 #endif
4 
8 
9 namespace edm {
20  public:
21  explicit SwitchProducer(ParameterSet const& iConfig);
22  ~SwitchProducer() override = default;
23  static void fillDescriptions(ConfigurationDescriptions& descriptions);
24  void produce(StreamID, Event& e, EventSetup const& c) const final {}
25  };
26 
28  auto const& moduleLabel = iConfig.getParameter<std::string>("@module_label");
29  auto const& chosenLabel = iConfig.getUntrackedParameter<std::string>("@chosen_case");
30  auto const& processName = iConfig.getUntrackedParameter<std::string>("@process_name");
31  callWhenNewProductsRegistered([=, this](edm::BranchDescription const& iBranch) {
32  if (iBranch.moduleLabel() == chosenLabel and iBranch.processName() == processName) {
33  if (iBranch.branchType() != InEvent) {
35  << "SwitchProducer does not support non-event branches. Got " << iBranch.branchType()
36  << " for SwitchProducer with label " << moduleLabel << " whose chosen case is " << chosenLabel << ".";
37  }
38 
39  // With consumes, create the connection to the chosen case EDProducer for prefetching
41  edm::InputTag{iBranch.moduleLabel(), iBranch.productInstanceName(), iBranch.processName()});
42  // With produces, create a producer-like BranchDescription
43  // early-enough for it to be flagged as non-OnDemand in case
44  // the SwithcProducer is on a Path
45  this->produces(iBranch.unwrappedTypeID(), iBranch.productInstanceName()).setSwitchAlias(iBranch.moduleLabel());
46  }
47  });
48  }
49 
52  desc.add<std::vector<std::string>>("@all_cases");
53  desc.addUntracked<std::string>("@chosen_case");
54  desc.addUntracked<std::string>("@process_name");
55  descriptions.addDefault(desc);
56  }
57 } // namespace edm
58 
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
Definition: ProducerBase.h:87
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
BranchType const & branchType() const
TypeID unwrappedTypeID() const
std::string const & processName() const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getUntrackedParameter(std::string const &, T const &) const
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescriptions(ConfigurationDescriptions &descriptions)
SwitchProducer(ParameterSet const &iConfig)
std::string const & productInstanceName() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HLT enums.
void produce(StreamID, Event &e, EventSetup const &c) const final
std::string const & moduleLabel() const
~SwitchProducer() override=default