Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-09-12 10:00:20

0001 #ifndef FWCore_Framework_SignallingProductRegistryFiller_h
0002 #define FWCore_Framework_SignallingProductRegistryFiller_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Framework
0006 // Class  :     SignallingProductRegistryFiller
0007 //
0008 /**\class SignallingProductRegistryFiller SignallingProductRegistryFiller.h FWCore/Framework/interface/SignallingProductRegistryFiller.h
0009 
0010  Description: <one line class summary>
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Chris Jones
0018 //         Created:  Fri Sep 23 16:47:10 CEST 2005
0019 //
0020 
0021 // system include files
0022 #include <map>
0023 #include <string>
0024 
0025 #include "FWCore/Utilities/interface/Signal.h"
0026 
0027 // user include files
0028 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0029 #include "FWCore/ServiceRegistry/interface/connect_but_block_self.h"
0030 
0031 // forward declarations
0032 namespace edm {
0033   class SignallingProductRegistryFiller {
0034   public:
0035     SignallingProductRegistryFiller() : productAddedSignal_(), registry_(), typeAddedStack_() {}
0036 
0037     explicit SignallingProductRegistryFiller(ProductRegistry const& preg)
0038         : productAddedSignal_(), registry_(preg), typeAddedStack_() {};
0039 
0040     SignallingProductRegistryFiller(SignallingProductRegistryFiller const&) = delete;
0041     SignallingProductRegistryFiller(SignallingProductRegistryFiller&&) = delete;
0042     SignallingProductRegistryFiller& operator=(SignallingProductRegistryFiller const&) = delete;
0043     SignallingProductRegistryFiller& operator=(SignallingProductRegistryFiller&&) = delete;
0044 
0045     signalslot::Signal<void(ProductDescription const&)> productAddedSignal_;
0046 
0047     void addProduct(ProductDescription const& productdesc, bool iFromListener = false) {
0048       registry_.addProduct_(productdesc);
0049       addCalled(productdesc, iFromListener);
0050     }
0051 
0052     void addLabelAlias(ProductDescription const& productdesc,
0053                        std::string const& labelAlias,
0054                        std::string const& instanceAlias) {
0055       addCalled(registry_.addLabelAlias_(productdesc, labelAlias, instanceAlias), false);
0056     }
0057     void addFromInput(edm::ProductRegistry const& iReg) {
0058       registry_.addFromInput_(iReg, [this](auto const& prod) { addCalled(prod, false); });
0059     }
0060 
0061     //NOTE: this is not const since we only want items that have non-const access to this class to be
0062     // able to call this internal iteration
0063     // Called only for branches that are present (part of avoiding creating type information for dropped branches)
0064     template <typename T>
0065     void callForEachBranch(T const& iFunc) {
0066       //NOTE: If implementation changes from a map, need to check that iterators are still valid
0067       // after an insert with the new container, else need to copy the container and iterate over the copy
0068       for (auto const& entry : registry_.productList()) {
0069         if (entry.second.present()) {
0070           iFunc(entry.second);
0071         }
0072       }
0073     }
0074     void setUnscheduledProducts(std::set<std::string> const& unscheduledLabels) {
0075       registry_.setUnscheduledProducts(unscheduledLabels);
0076     }
0077     ProductRegistry::ProductList& productListUpdator() { return registry_.productListUpdator(); }
0078 
0079     void setCurrentProcess(std::string const& processOrder) {
0080       registry_.setProcessOrder(std::vector<std::string>(1, processOrder));
0081     }
0082 
0083     template <class T>
0084     void watchProductAdditions(const T& iFunc) {
0085       serviceregistry::connect_but_block_self(productAddedSignal_, iFunc);
0086     }
0087     template <class T, class TMethod>
0088     void watchProductAdditions(T const& iObj, TMethod iMethod) {
0089       using std::placeholders::_1;
0090       serviceregistry::connect_but_block_self(productAddedSignal_, std::bind(iMethod, iObj, _1));
0091     }
0092 
0093     ProductRegistry moveTo() { return std::move(registry_); }
0094     ProductRegistry const& registry() const { return registry_; }
0095 
0096     void setFrozen(bool initializeLookupInfo = true) { registry_.setFrozen(initializeLookupInfo); }
0097 
0098     void setFrozen(std::set<TypeID> const& productTypesConsumed,
0099                    std::set<TypeID> const& elementTypesConsumed,
0100                    std::string const& processName) {
0101       registry_.setFrozen(productTypesConsumed, elementTypesConsumed, processName);
0102     }
0103 
0104   private:
0105     void addCalled(ProductDescription const&, bool);
0106     // ---------- member data --------------------------------
0107     ProductRegistry registry_;
0108     std::map<std::string, unsigned int> typeAddedStack_;
0109   };
0110 }  // namespace edm
0111 
0112 #endif