Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef FWCore_Framework_ProducerBase_h
0002 #define FWCore_Framework_ProducerBase_h
0003 
0004 /*----------------------------------------------------------------------
0005 
0006 EDProducer: The base class of all "modules" that will insert new
0007 EDProducts into an Event.
0008 
0009 ----------------------------------------------------------------------*/
0010 
0011 #include "FWCore/Framework/interface/ProductRegistryHelper.h"
0012 #include "FWCore/Framework/interface/ProducesCollector.h"
0013 #include "FWCore/Utilities/interface/ProductResolverIndex.h"
0014 
0015 #include <functional>
0016 #include <unordered_map>
0017 #include <string>
0018 #include <vector>
0019 #include <array>
0020 
0021 namespace edm {
0022   class BranchDescription;
0023   class ModuleDescription;
0024   class ProducesCollector;
0025   class ProductRegistry;
0026   class Event;
0027   class LuminosityBlock;
0028   class ProcessBlock;
0029   class Run;
0030 
0031   class EDProducer;
0032   namespace one {
0033     class EDProducerBase;
0034     class EDFilterBase;
0035   }  // namespace one
0036   namespace global {
0037     class EDProducerBase;
0038     class EDFilterBase;
0039   }  // namespace global
0040   namespace limited {
0041     class EDProducerBase;
0042     class EDFilterBase;
0043   }  // namespace limited
0044   namespace stream {
0045     template <typename T>
0046     class ProducingModuleAdaptorBase;
0047   }
0048 
0049   namespace producerbasehelper {
0050     template <typename P>
0051     struct PrincipalTraits;
0052     template <>
0053     struct PrincipalTraits<ProcessBlock> {
0054       static constexpr int kBranchType = InProcess;
0055     };
0056     template <>
0057     struct PrincipalTraits<Run> {
0058       static constexpr int kBranchType = InRun;
0059     };
0060     template <>
0061     struct PrincipalTraits<LuminosityBlock> {
0062       static constexpr int kBranchType = InLumi;
0063     };
0064     template <>
0065     struct PrincipalTraits<Event> {
0066       static constexpr int kBranchType = InEvent;
0067     };
0068   }  // namespace producerbasehelper
0069 
0070   class ProducerBase : private ProductRegistryHelper {
0071   public:
0072     typedef ProductRegistryHelper::TypeLabelList TypeLabelList;
0073     ProducerBase();
0074     ~ProducerBase() noexcept(false) override;
0075 
0076     /// used by the fwk to register list of products
0077     std::function<void(BranchDescription const&)> registrationCallback() const;
0078 
0079     void registerProducts(ProducerBase*, ProductRegistry*, ModuleDescription const&);
0080 
0081     using ProductRegistryHelper::recordProvenanceList;
0082     using ProductRegistryHelper::typeLabelList;
0083 
0084     template <typename T>
0085     using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT<T>;
0086 
0087     void callWhenNewProductsRegistered(std::function<void(BranchDescription const&)> const& func) {
0088       callWhenNewProductsRegistered_ = func;
0089     }
0090 
0091     using ModuleToResolverIndicies =
0092         std::unordered_multimap<std::string, std::tuple<edm::TypeID const*, const char*, edm::ProductResolverIndex>>;
0093     void resolvePutIndicies(BranchType iBranchType,
0094                             ModuleToResolverIndicies const& iIndicies,
0095                             std::string const& moduleLabel);
0096 
0097     std::vector<edm::ProductResolverIndex> const& indiciesForPutProducts(BranchType iBranchType) const {
0098       return putIndicies_[iBranchType];
0099     }
0100 
0101     std::vector<edm::ProductResolverIndex> const& putTokenIndexToProductResolverIndex() const {
0102       return putTokenToResolverIndex_;
0103     }
0104 
0105   protected:
0106     ProducesCollector producesCollector();
0107     using ProductRegistryHelper::produces;
0108 
0109   private:
0110     friend class one::EDProducerBase;
0111     friend class one::EDFilterBase;
0112     friend class global::EDProducerBase;
0113     friend class global::EDFilterBase;
0114     friend class limited::EDProducerBase;
0115     friend class limited::EDFilterBase;
0116     friend class PuttableSourceBase;
0117     friend class TransformerBase;
0118     template <typename T>
0119     friend class stream::ProducingModuleAdaptorBase;
0120 
0121     template <typename P>
0122     void commit_(P& iPrincipal) {
0123       iPrincipal.commit_(putIndicies_[producerbasehelper::PrincipalTraits<P>::kBranchType]);
0124     }
0125 
0126     template <typename P, typename I>
0127     void commit_(P& iPrincipal, I* iID) {
0128       iPrincipal.commit_(putIndicies_[producerbasehelper::PrincipalTraits<P>::kBranchType], iID);
0129     }
0130 
0131     using ProductRegistryHelper::transforms;
0132 
0133     std::function<void(BranchDescription const&)> callWhenNewProductsRegistered_;
0134     std::array<std::vector<edm::ProductResolverIndex>, edm::NumBranchTypes> putIndicies_;
0135     std::vector<edm::ProductResolverIndex> putTokenToResolverIndex_;
0136   };
0137 }  // namespace edm
0138 #endif