Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:50

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