Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:03:16

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     std::vector<std::string> processLabels_;
0036   };
0037 
0038   GenericConsumer::GenericConsumer(ParameterSet const& config)
0039       : eventLabels_(config.getUntrackedParameter<std::vector<std::string>>("eventProducts")),
0040         lumiLabels_(config.getUntrackedParameter<std::vector<std::string>>("lumiProducts")),
0041         runLabels_(config.getUntrackedParameter<std::vector<std::string>>("runProducts")),
0042         processLabels_(config.getUntrackedParameter<std::vector<std::string>>("processProducts")) {
0043     std::sort(eventLabels_.begin(), eventLabels_.end());
0044     std::sort(lumiLabels_.begin(), lumiLabels_.end());
0045     std::sort(runLabels_.begin(), runLabels_.end());
0046     std::sort(processLabels_.begin(), processLabels_.end());
0047 
0048     callWhenNewProductsRegistered([this](edm::BranchDescription const& branch) {
0049       static const std::string kWildcard("*");
0050       static const std::string kPathStatus("edm::PathStatus");
0051       static const std::string kEndPathStatus("edm::EndPathStatus");
0052 
0053       switch (branch.branchType()) {
0054         case InEvent:
0055           if (std::binary_search(eventLabels_.begin(), eventLabels_.end(), branch.moduleLabel()) or
0056               (std::binary_search(eventLabels_.begin(), eventLabels_.end(), kWildcard) and
0057                branch.className() != kPathStatus and branch.className() != kEndPathStatus))
0058             this->consumes(edm::TypeToGet{branch.unwrappedTypeID(), PRODUCT_TYPE},
0059                            edm::InputTag{branch.moduleLabel(), branch.productInstanceName(), branch.processName()});
0060           break;
0061 
0062         case InLumi:
0063           if (std::binary_search(lumiLabels_.begin(), lumiLabels_.end(), branch.moduleLabel()) or
0064               std::binary_search(lumiLabels_.begin(), lumiLabels_.end(), kWildcard))
0065             this->consumes<edm::InLumi>(
0066                 edm::TypeToGet{branch.unwrappedTypeID(), PRODUCT_TYPE},
0067                 edm::InputTag{branch.moduleLabel(), branch.productInstanceName(), branch.processName()});
0068           break;
0069 
0070         case InRun:
0071           if (std::binary_search(runLabels_.begin(), runLabels_.end(), branch.moduleLabel()) or
0072               std::binary_search(runLabels_.begin(), runLabels_.end(), kWildcard))
0073             this->consumes<edm::InRun>(
0074                 edm::TypeToGet{branch.unwrappedTypeID(), PRODUCT_TYPE},
0075                 edm::InputTag{branch.moduleLabel(), branch.productInstanceName(), branch.processName()});
0076           break;
0077 
0078         case InProcess:
0079           if (std::binary_search(processLabels_.begin(), processLabels_.end(), branch.moduleLabel()) or
0080               std::binary_search(processLabels_.begin(), processLabels_.end(), kWildcard))
0081             this->consumes<edm::InProcess>(
0082                 edm::TypeToGet{branch.unwrappedTypeID(), PRODUCT_TYPE},
0083                 edm::InputTag{branch.moduleLabel(), branch.productInstanceName(), branch.processName()});
0084           break;
0085         default:
0086           throw Exception(errors::LogicError)
0087               << "Unexpected branch type " << branch.branchType() << "\nPlease contact a Framework developer\n";
0088       }
0089     });
0090   }
0091 
0092   void GenericConsumer::fillDescriptions(ConfigurationDescriptions& descriptions) {
0093     descriptions.setComment(
0094         "This plugin depends on all the event, lumi and run products "
0095         "produced by the modules listed in its configuration.");
0096 
0097     ParameterSetDescription desc;
0098     desc.addUntracked<std::vector<std::string>>("eventProducts", {})
0099         ->setComment(
0100             "List of modules whose event products this module will depend on. "
0101             "Use \"*\" to depend on all event products.");
0102     desc.addUntracked<std::vector<std::string>>("lumiProducts", {})
0103         ->setComment(
0104             "List of modules whose lumi products this module will depend on. "
0105             "Use \"*\" to depend on all lumi products.");
0106     desc.addUntracked<std::vector<std::string>>("runProducts", {})
0107         ->setComment(
0108             "List of modules whose run products this module will depend on. "
0109             "Use \"*\" to depend on all run products.");
0110     desc.addUntracked<std::vector<std::string>>("processProducts", {})
0111         ->setComment(
0112             "List of modules whose process products this module will depend on. "
0113             "Use \"*\" to depend on all process products.");
0114     descriptions.addWithDefaultLabel(desc);
0115   }
0116 
0117 }  // namespace edm
0118 
0119 using edm::GenericConsumer;
0120 DEFINE_FWK_MODULE(GenericConsumer);