CMS 3D CMS Logo

ProducerBase.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_ProducerBase_h
2 #define FWCore_Framework_ProducerBase_h
3 
4 /*----------------------------------------------------------------------
5 
6 EDProducer: The base class of all "modules" that will insert new
7 EDProducts into an Event.
8 
9 ----------------------------------------------------------------------*/
10 
13 
14 #include <functional>
15 #include <unordered_map>
16 #include <string>
17 #include <vector>
18 #include <array>
19 
20 namespace edm {
21  class BranchDescription;
22  class ModuleDescription;
23  class ProductRegistry;
24  class Event;
25  class LuminosityBlock;
26  class Run;
27 
28  class EDProducer;
29  class EDFilter;
30  namespace one {
31  class EDProducerBase;
32  class EDFilterBase;
33  }
34  namespace global {
35  class EDProducerBase;
36  class EDFilterBase;
37  }
38  namespace limited {
39  class EDProducerBase;
40  class EDFilterBase;
41  }
42  namespace stream {
43  template<typename T> class ProducingModuleAdaptorBase;
44  }
45 
46  namespace producerbasehelper{
47  template<typename P> struct PrincipalTraits;
48  template<> struct PrincipalTraits<Run> {
49  static constexpr int kBranchType = InRun;
50  };
51  template<> struct PrincipalTraits<LuminosityBlock> {
52  static constexpr int kBranchType = InLumi;
53  };
54  template<> struct PrincipalTraits<Event> {
55  static constexpr int kBranchType = InEvent;
56  };
57  }
58 
60  public:
62  ProducerBase ();
63  ~ProducerBase() noexcept(false) override;
64 
66  std::function<void(BranchDescription const&)> registrationCallback() const;
67 
68  void registerProducts(ProducerBase*,
70  ModuleDescription const&);
71 
72  using ProductRegistryHelper::produces;
73  using ProductRegistryHelper::typeLabelList;
74  using ProductRegistryHelper::recordProvenanceList;
75 
76  void callWhenNewProductsRegistered(std::function<void(BranchDescription const&)> const& func) {
77  callWhenNewProductsRegistered_ = func;
78  }
79 
80  using ModuleToResolverIndicies = std::unordered_multimap<std::string,
81  std::tuple<edm::TypeID const*, const char*, edm::ProductResolverIndex>>;
82  void resolvePutIndicies(BranchType iBranchType,
83  ModuleToResolverIndicies const& iIndicies,
84  std::string const& moduleLabel);
85 
86  std::vector<edm::ProductResolverIndex> const& indiciesForPutProducts(BranchType iBranchType) const {
87  return putIndicies_[iBranchType];
88  }
89 
90  std::vector<edm::ProductResolverIndex> const&
92  return putTokenToResolverIndex_;
93  }
94  private:
95  friend class EDProducer;
96  friend class EDFilter;
97  friend class one::EDProducerBase;
98  friend class one::EDFilterBase;
99  friend class global::EDProducerBase;
100  friend class global::EDFilterBase;
102  friend class limited::EDFilterBase;
103  friend class PuttableSourceBase;
104  template<typename T> friend class stream::ProducingModuleAdaptorBase;
105 
106  template< typename P>
107  void commit_(P& iPrincipal) {
108  iPrincipal.commit_(putIndicies_[producerbasehelper::PrincipalTraits<P>::kBranchType]);
109  }
110 
111  template< typename P, typename I>
112  void commit_(P& iPrincipal, I* iID) {
113  iPrincipal.commit_(putIndicies_[producerbasehelper::PrincipalTraits<P>::kBranchType], iID);
114  }
115 
116  std::function<void(BranchDescription const&)> callWhenNewProductsRegistered_;
117  std::array<std::vector<edm::ProductResolverIndex>, edm::NumBranchTypes> putIndicies_;
118  std::vector<edm::ProductResolverIndex> putTokenToResolverIndex_;
119  };
120 }
121 #endif
void commit_(P &iPrincipal, I *iID)
Definition: ProducerBase.h:112
std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >> ModuleToResolverIndicies
Definition: ProducerBase.h:81
ProductRegistryHelper::TypeLabelList TypeLabelList
Definition: ProducerBase.h:61
#define noexcept
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex() const
Definition: ProducerBase.h:91
std::function< void(BranchDescription const &)> callWhenNewProductsRegistered_
Definition: ProducerBase.h:116
std::array< std::vector< edm::ProductResolverIndex >, edm::NumBranchTypes > putIndicies_
Definition: ProducerBase.h:117
#define constexpr
BranchType
Definition: BranchType.h:11
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts(BranchType iBranchType) const
Definition: ProducerBase.h:86
std::vector< TypeLabelItem > TypeLabelList
const std::complex< double > I
Definition: I.h:8
std::vector< edm::ProductResolverIndex > putTokenToResolverIndex_
Definition: ProducerBase.h:118
std::pair< OmniClusterRef, TrackingParticleRef > P
HLT enums.
void commit_(P &iPrincipal)
Definition: ProducerBase.h:107
Definition: Run.h:44