Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:48

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    * This class is the physical EDProducer part of the SwitchProducer
0008    * infrastructure. It must be configured only with the
0009    * SwitchProducer python construct.
0010    *
0011    * The purposes of this EDProducer are
0012    * - Create the consumes() links to the chosen case to make the prefetching work correclty
0013    * - Forward the produces() information to create proper BranchDescription objects
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         // With consumes, create the connection to the chosen case EDProducer for prefetching
0036         this->consumes(edm::TypeToGet{iBranch.unwrappedTypeID(), PRODUCT_TYPE},
0037                        edm::InputTag{iBranch.moduleLabel(), iBranch.productInstanceName(), iBranch.processName()});
0038         // With produces, create a producer-like BranchDescription
0039         // early-enough for it to be flagged as non-OnDemand in case
0040         // the SwithcProducer is on a Path
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 }  // namespace edm
0054 
0055 using edm::SwitchProducer;
0056 DEFINE_FWK_MODULE(SwitchProducer);