Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  *  This plugin depends on all the event, lumi and run products produced by the modules listed in its configuration:
0003  *    - eventProducts: depend on the event products from these modules
0004  *    - lumiProducts:  depend on the lumi products from these modules
0005  *    - runProducts:   depend on the run products from these modules
0006  *
0007  *  Use "*" to depend on all the products in a given branch.
0008  */
0009 
0010 #include <algorithm>
0011 #include <string>
0012 #include <vector>
0013 
0014 #include "FWCore/Framework/interface/global/EDAnalyzer.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0017 #include "FWCore/ParameterSet/interface/ParameterDescriptionNode.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0020 
0021 namespace edm {
0022   class GenericConsumer : public edm::global::EDAnalyzer<> {
0023   public:
0024     explicit GenericConsumer(ParameterSet const&);
0025     ~GenericConsumer() override = default;
0026 
0027     void analyze(StreamID, Event const&, EventSetup const&) const override {}
0028 
0029     static void fillDescriptions(ConfigurationDescriptions& descriptions);
0030 
0031   private:
0032     std::vector<std::string> eventLabels_;
0033     std::vector<std::string> lumiLabels_;
0034     std::vector<std::string> runLabels_;
0035   };
0036 
0037   GenericConsumer::GenericConsumer(ParameterSet const& config)
0038       : eventLabels_(config.getUntrackedParameter<std::vector<std::string>>("eventProducts")),
0039         lumiLabels_(config.getUntrackedParameter<std::vector<std::string>>("lumiProducts")),
0040         runLabels_(config.getUntrackedParameter<std::vector<std::string>>("runProducts")) {
0041     std::sort(eventLabels_.begin(), eventLabels_.end());
0042     std::sort(lumiLabels_.begin(), lumiLabels_.end());
0043     std::sort(runLabels_.begin(), runLabels_.end());
0044 
0045     callWhenNewProductsRegistered([this](edm::BranchDescription const& branch) {
0046       static const std::string kWildcard("*");
0047       static const std::string kPathStatus("edm::PathStatus");
0048       static const std::string kEndPathStatus("edm::EndPathStatus");
0049 
0050       switch (branch.branchType()) {
0051         case InEvent:
0052           if (std::binary_search(eventLabels_.begin(), eventLabels_.end(), branch.moduleLabel()) or
0053               (std::binary_search(eventLabels_.begin(), eventLabels_.end(), kWildcard) and
0054                branch.className() != kPathStatus and branch.className() != kEndPathStatus))
0055             this->consumes(edm::TypeToGet{branch.unwrappedTypeID(), PRODUCT_TYPE},
0056                            edm::InputTag{branch.moduleLabel(), branch.productInstanceName(), branch.processName()});
0057           break;
0058 
0059         case InLumi:
0060           if (std::binary_search(lumiLabels_.begin(), lumiLabels_.end(), branch.moduleLabel()) or
0061               std::binary_search(lumiLabels_.begin(), lumiLabels_.end(), kWildcard))
0062             this->consumes<edm::InLumi>(
0063                 edm::TypeToGet{branch.unwrappedTypeID(), PRODUCT_TYPE},
0064                 edm::InputTag{branch.moduleLabel(), branch.productInstanceName(), branch.processName()});
0065           break;
0066 
0067         case InRun:
0068           if (std::binary_search(runLabels_.begin(), runLabels_.end(), branch.moduleLabel()) or
0069               std::binary_search(runLabels_.begin(), runLabels_.end(), kWildcard))
0070             this->consumes<edm::InRun>(
0071                 edm::TypeToGet{branch.unwrappedTypeID(), PRODUCT_TYPE},
0072                 edm::InputTag{branch.moduleLabel(), branch.productInstanceName(), branch.processName()});
0073           break;
0074 
0075         default:
0076           throw Exception(errors::LogicError)
0077               << "Unexpected branch type " << branch.branchType() << "\nPlease contact a Framework developer\n";
0078       }
0079     });
0080   }
0081 
0082   void GenericConsumer::fillDescriptions(ConfigurationDescriptions& descriptions) {
0083     descriptions.setComment(
0084         "This plugin depends on all the event, lumi and run products "
0085         "produced by the modules listed in its configuration.");
0086 
0087     ParameterSetDescription desc;
0088     desc.addUntracked<std::vector<std::string>>("eventProducts", {})
0089         ->setComment(
0090             "List of modules whose event products this module will depend on. "
0091             "Use \"*\" to depend on all event products.");
0092     desc.addUntracked<std::vector<std::string>>("lumiProducts", {})
0093         ->setComment(
0094             "List of modules whose lumi products this module will depend on. "
0095             "Use \"*\" to depend on all event products.");
0096     desc.addUntracked<std::vector<std::string>>("runProducts", {})
0097         ->setComment(
0098             "List of modules whose run products this module will depend on. "
0099             "Use \"*\" to depend on all event products.");
0100     descriptions.addWithDefaultLabel(desc);
0101   }
0102 
0103 }  // namespace edm
0104 
0105 using edm::GenericConsumer;
0106 DEFINE_FWK_MODULE(GenericConsumer);