Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-11 22:29:29

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   class EDFilter;
0033   namespace one {
0034     class EDProducerBase;
0035     class EDFilterBase;
0036   }  // namespace one
0037   namespace global {
0038     class EDProducerBase;
0039     class EDFilterBase;
0040   }  // namespace global
0041   namespace limited {
0042     class EDProducerBase;
0043     class EDFilterBase;
0044   }  // namespace limited
0045   namespace stream {
0046     template <typename T>
0047     class ProducingModuleAdaptorBase;
0048   }
0049 
0050   namespace producerbasehelper {
0051     template <typename P>
0052     struct PrincipalTraits;
0053     template <>
0054     struct PrincipalTraits<ProcessBlock> {
0055       static constexpr int kBranchType = InProcess;
0056     };
0057     template <>
0058     struct PrincipalTraits<Run> {
0059       static constexpr int kBranchType = InRun;
0060     };
0061     template <>
0062     struct PrincipalTraits<LuminosityBlock> {
0063       static constexpr int kBranchType = InLumi;
0064     };
0065     template <>
0066     struct PrincipalTraits<Event> {
0067       static constexpr int kBranchType = InEvent;
0068     };
0069   }  // namespace producerbasehelper
0070 
0071   class ProducerBase : private ProductRegistryHelper {
0072   public:
0073     typedef ProductRegistryHelper::TypeLabelList TypeLabelList;
0074     ProducerBase();
0075     ~ProducerBase() noexcept(false) override;
0076 
0077     /// used by the fwk to register list of products
0078     std::function<void(BranchDescription const&)> registrationCallback() const;
0079 
0080     void registerProducts(ProducerBase*, ProductRegistry*, ModuleDescription const&);
0081 
0082     using ProductRegistryHelper::recordProvenanceList;
0083     using ProductRegistryHelper::typeLabelList;
0084 
0085     template <typename T>
0086     using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT<T>;
0087 
0088     void callWhenNewProductsRegistered(std::function<void(BranchDescription const&)> const& func) {
0089       callWhenNewProductsRegistered_ = func;
0090     }
0091 
0092     using ModuleToResolverIndicies =
0093         std::unordered_multimap<std::string, std::tuple<edm::TypeID const*, const char*, edm::ProductResolverIndex>>;
0094     void resolvePutIndicies(BranchType iBranchType,
0095                             ModuleToResolverIndicies const& iIndicies,
0096                             std::string const& moduleLabel);
0097 
0098     std::vector<edm::ProductResolverIndex> const& indiciesForPutProducts(BranchType iBranchType) const {
0099       return putIndicies_[iBranchType];
0100     }
0101 
0102     std::vector<edm::ProductResolverIndex> const& putTokenIndexToProductResolverIndex() const {
0103       return putTokenToResolverIndex_;
0104     }
0105 
0106   protected:
0107     ProducesCollector producesCollector();
0108     using ProductRegistryHelper::produces;
0109 
0110   private:
0111     friend class EDProducer;
0112     friend class EDFilter;
0113     friend class one::EDProducerBase;
0114     friend class one::EDFilterBase;
0115     friend class global::EDProducerBase;
0116     friend class global::EDFilterBase;
0117     friend class limited::EDProducerBase;
0118     friend class limited::EDFilterBase;
0119     friend class PuttableSourceBase;
0120     friend class TransformerBase;
0121     template <typename T>
0122     friend class stream::ProducingModuleAdaptorBase;
0123 
0124     template <typename P>
0125     void commit_(P& iPrincipal) {
0126       iPrincipal.commit_(putIndicies_[producerbasehelper::PrincipalTraits<P>::kBranchType]);
0127     }
0128 
0129     template <typename P, typename I>
0130     void commit_(P& iPrincipal, I* iID) {
0131       iPrincipal.commit_(putIndicies_[producerbasehelper::PrincipalTraits<P>::kBranchType], iID);
0132     }
0133 
0134     using ProductRegistryHelper::transforms;
0135 
0136     std::function<void(BranchDescription const&)> callWhenNewProductsRegistered_;
0137     std::array<std::vector<edm::ProductResolverIndex>, edm::NumBranchTypes> putIndicies_;
0138     std::vector<edm::ProductResolverIndex> putTokenToResolverIndex_;
0139   };
0140 }  // namespace edm
0141 #endif