CMS 3D CMS Logo

Principal.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_Principal_h
2 #define FWCore_Framework_Principal_h
3 
4 /*----------------------------------------------------------------------
5 
6 Principal: This is the implementation of the classes responsible
7 for management of EDProducts. It is not seen by reconstruction code.
8 
9 The major internal component of the Principal is the ProductResolver, which
10 contains an EDProduct and its associated Provenance, along with
11 ancillary transient information regarding the two. ProductResolvers are handled
12 through shared pointers.
13 
14 The Principal returns BasicHandle, rather than a shared
15 pointer to a ProductResolver, when queried.
16 
17 (Historical note: prior to April 2007 this class was named DataBlockImpl)
18 
19 ----------------------------------------------------------------------*/
32 
33 #include "boost/iterator/filter_iterator.hpp"
34 
35 #include <map>
36 #include <memory>
37 #include <set>
38 #include <string>
39 #include <vector>
40 
41 namespace edm {
42 
43  class HistoryAppender;
44  class MergeableRunProductMetadata;
45  class ModuleCallingContext;
46  class ProcessHistoryRegistry;
47  class ProductResolverIndexHelper;
48  class EDConsumerBase;
50  class InputProductResolver;
51  class WaitingTask;
53 
55  bool operator()(propagate_const<std::shared_ptr<ProductResolverBase>> const& iObj) { return bool(iObj); }
56  };
57 
58  class Principal : public EDProductGetter {
59  public:
60  typedef std::vector<propagate_const<std::shared_ptr<ProductResolverBase>>> ProductResolverCollection;
61  typedef boost::filter_iterator<FilledProductPtr, ProductResolverCollection::const_iterator> const_iterator;
62  typedef boost::filter_iterator<FilledProductPtr, ProductResolverCollection::iterator> iterator;
65  typedef std::vector<BasicHandle> BasicHandleVec;
67 
68  typedef std::shared_ptr<ProductResolverBase> SharedProductPtr;
70 
71  Principal(std::shared_ptr<ProductRegistry const> reg,
72  std::shared_ptr<ProductResolverIndexHelper const> productLookup,
73  ProcessConfiguration const& pc,
74  BranchType bt,
75  HistoryAppender* historyAppender,
76  bool isForPrimaryProcess = true);
77 
78  ~Principal() override;
79 
80  bool adjustToNewProductRegistry(ProductRegistry const& reg);
81 
82  void adjustIndexesAfterProductRegistryAddition();
83 
84  void fillPrincipal(ProcessHistoryID const& hist, ProcessHistoryRegistry const& phr, DelayedReader* reader);
85 
86  void clearPrincipal();
87 
88  void setupUnscheduled(UnscheduledConfigurator const&);
89 
90  void deleteProduct(BranchID const& id) const;
91 
92  EDProductGetter const* prodGetter() const { return this; }
93 
94  // Return a BasicHandle to the product which:
95  // 1. matches the given label, instance, and process
96  // (if process if empty gets the match from the most recent process)
97  // 2. If kindOfType is PRODUCT, then the type of the product matches typeID
98  // 3. If kindOfType is ELEMENT
99  // a. the product is a sequence,
100  // b. the sequence has the nested type 'value_type'
101  // c. typeID is the same as or a public base of
102  // this value_type,
103 
104  BasicHandle getByLabel(KindOfType kindOfType,
105  TypeID const& typeID,
106  InputTag const& inputTag,
107  EDConsumerBase const* consumes,
109  ModuleCallingContext const* mcc) const;
110 
111  BasicHandle getByLabel(KindOfType kindOfType,
112  TypeID const& typeID,
113  std::string const& label,
114  std::string const& instance,
115  std::string const& process,
116  EDConsumerBase const* consumes,
118  ModuleCallingContext const* mcc) const;
119 
120  BasicHandle getByToken(KindOfType kindOfType,
121  TypeID const& typeID,
123  bool skipCurrentProcess,
124  bool& ambiguous,
126  ModuleCallingContext const* mcc) const;
127 
128  void prefetchAsync(WaitingTask* waitTask,
129  ProductResolverIndex index,
130  bool skipCurrentProcess,
131  ServiceToken const& token,
132  ModuleCallingContext const* mcc) const;
133 
134  void getManyByType(TypeID const& typeID,
135  BasicHandleVec& results,
136  EDConsumerBase const* consumes,
138  ModuleCallingContext const* mcc) const;
139 
140  ProcessHistory const& processHistory() const { return *processHistoryPtr_; }
141 
142  ProcessHistoryID const& processHistoryID() const { return processHistoryID_; }
143 
144  ProcessConfiguration const& processConfiguration() const { return *processConfiguration_; }
145 
146  ProductRegistry const& productRegistry() const { return *preg_; }
147 
148  ProductResolverIndexHelper const& productLookup() const { return *productLookup_; }
149 
150  // merge Principals containing different products.
151  void recombine(Principal& other, std::vector<BranchID> const& bids);
152 
154  return const_cast<ProductResolverBase*>(const_cast<const Principal*>(this)->getProductResolver(oid));
155  }
156 
157  size_t size() const;
158 
159  // These iterators skip over any null shared pointers
160  const_iterator begin() const {
161  return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.begin(), productResolvers_.end());
162  }
163  const_iterator end() const {
164  return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.end(), productResolvers_.end());
165  }
166 
167  iterator begin() {
168  return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.begin(), productResolvers_.end());
169  }
170  iterator end() {
171  return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.end(), productResolvers_.end());
172  }
173 
174  Provenance getProvenance(BranchID const& bid, ModuleCallingContext const* mcc) const;
175 
176  void getAllProvenance(std::vector<Provenance const*>& provenances) const;
177 
178  void getAllStableProvenance(std::vector<StableProvenance const*>& provenances) const;
179 
180  BranchType const& branchType() const { return branchType_; }
181 
182  //This will never return 0 so you can use 0 to mean unset
183  typedef unsigned long CacheIdentifier_t;
184  CacheIdentifier_t cacheIdentifier() const { return cacheIdentifier_; }
185 
186  DelayedReader* reader() const { return reader_; }
187 
188  ConstProductResolverPtr getProductResolver(BranchID const& oid) const;
189 
190  ProductData const* findProductByTag(TypeID const& typeID,
191  InputTag const& tag,
192  ModuleCallingContext const* mcc) const;
193 
194  void readAllFromSourceAndMergeImmediately(MergeableRunProductMetadata const* mergeableRunProductMetadata = nullptr);
195 
196  std::vector<unsigned int> const& lookupProcessOrder() const { return lookupProcessOrder_; }
197 
198  ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const& oid) const;
199 
200  protected:
201  // ----- Add a new ProductResolver
202  // *this takes ownership of the ProductResolver, which in turn owns its
203  // data.
204  void addProduct_(std::unique_ptr<ProductResolverBase> phb);
205  void addProductOrThrow(std::unique_ptr<ProductResolverBase> phb);
206  ProductResolverBase* getExistingProduct(BranchID const& branchID);
207  ProductResolverBase const* getExistingProduct(BranchID const& branchID) const;
208  ProductResolverBase const* getExistingProduct(ProductResolverBase const& phb) const;
209 
210  void putOrMerge(BranchDescription const& bd, std::unique_ptr<WrapperBase> edp) const;
211 
212  //F must take an argument of type ProductResolverBase*
213  template <typename F>
214  void applyToResolvers(F iFunc) {
215  for (auto& resolver : productResolvers_) {
216  iFunc(resolver.get());
217  }
218  }
219 
220  private:
221  void addScheduledProduct(std::shared_ptr<BranchDescription const> bd);
222  void addSourceProduct(std::shared_ptr<BranchDescription const> bd);
223  void addInputProduct(std::shared_ptr<BranchDescription const> bd);
224  void addUnscheduledProduct(std::shared_ptr<BranchDescription const> bd);
225  void addAliasedProduct(std::shared_ptr<BranchDescription const> bd);
226  void addSwitchProducerProduct(std::shared_ptr<BranchDescription const> bd);
227  void addSwitchAliasProduct(std::shared_ptr<BranchDescription const> bd);
228  void addParentProcessProduct(std::shared_ptr<BranchDescription const> bd);
229 
230  WrapperBase const* getIt(ProductID const&) const override;
231  WrapperBase const* getThinnedProduct(ProductID const&, unsigned int&) const override;
232  void getThinnedProducts(ProductID const&,
233  std::vector<WrapperBase const*>&,
234  std::vector<unsigned int>&) const override;
235 
236  void findProducts(std::vector<ProductResolverBase const*> const& holders,
237  TypeID const& typeID,
238  BasicHandleVec& results,
240  ModuleCallingContext const* mcc) const;
241 
242  ProductData const* findProductByLabel(KindOfType kindOfType,
243  TypeID const& typeID,
244  InputTag const& inputTag,
245  EDConsumerBase const* consumer,
247  ModuleCallingContext const* mcc) const;
248 
249  ProductData const* findProductByLabel(KindOfType kindOfType,
250  TypeID const& typeID,
251  std::string const& label,
252  std::string const& instance,
253  std::string const& process,
254  EDConsumerBase const* consumer,
256  ModuleCallingContext const* mcc) const;
257 
258  void putOrMerge(std::unique_ptr<WrapperBase> prod, ProductResolverBase const* productResolver) const;
259 
260  std::shared_ptr<ProcessHistory const> processHistoryPtr_;
261 
264 
266 
267  // A vector of product holders.
268  ProductResolverCollection productResolvers_; // products and provenances are persistent
269 
270  // Pointer to the product registry. There is one entry in the registry
271  // for each EDProduct in the event.
272  std::shared_ptr<ProductRegistry const> preg_;
273  std::shared_ptr<ProductResolverIndexHelper const> productLookup_;
274 
275  std::vector<unsigned int> lookupProcessOrder_;
277 
278  // Pointer to the 'source' that will be used to obtain EDProducts
279  // from the persistent store. This 'source' is owned by the input source.
281 
283 
284  // In use cases where the new process should not be appended to
285  // input ProcessHistory, the following pointer should be null.
286  // The Principal does not own this object.
288 
289  CacheIdentifier_t cacheIdentifier_;
290  };
291 
292  template <typename PROD>
293  inline std::shared_ptr<Wrapper<PROD> const> getProductByTag(Principal const& ep,
294  InputTag const& tag,
295  ModuleCallingContext const* mcc) {
296  TypeID tid = TypeID(typeid(PROD));
297  ProductData const* result = ep.findProductByTag(tid, tag, mcc);
298  if (result == nullptr) {
299  return std::shared_ptr<Wrapper<PROD> const>();
300  }
301 
302  if (!(result->wrapper()->dynamicTypeInfo() == typeid(PROD))) {
304  }
305  return std::static_pointer_cast<Wrapper<PROD> const>(result->sharedConstWrapper());
306  }
307 } // namespace edm
308 #endif
BranchType branchType_
Definition: Principal.h:282
size
Write out results.
collection_type::const_iterator const_iterator
ProductRegistry const & productRegistry() const
Definition: Principal.h:146
ProductResolverBase * getModifiableProductResolver(BranchID const &oid)
Definition: Principal.h:153
DelayedReader * reader_
Definition: Principal.h:280
std::string ProcessName
Definition: Principal.h:69
iterator begin()
Definition: Principal.h:167
ProcessHistoryID processHistoryIDBeforeConfig_
Definition: Principal.h:263
unsigned int ProductResolverIndex
ProductResolverCollection productResolvers_
Definition: Principal.h:268
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:46
std::shared_ptr< ProcessHistory const > processHistoryPtr_
Definition: Principal.h:260
const_iterator end() const
Definition: Principal.h:163
static PFTauRenderPlugin instance
std::shared_ptr< ProductResolverBase > SharedProductPtr
Definition: Principal.h:68
ProcessHistoryID processHistoryID_
Definition: Principal.h:262
void applyToResolvers(F iFunc)
Definition: Principal.h:214
WrapperBase const * wrapper() const
Definition: ProductData.h:34
CacheIdentifier_t cacheIdentifier() const
Definition: Principal.h:184
bool operator()(propagate_const< std::shared_ptr< ProductResolverBase >> const &iObj)
Definition: Principal.h:55
edm::propagate_const< HistoryAppender * > historyAppender_
Definition: Principal.h:287
uint16_t size_type
ProcessHistory const & processHistory() const
Definition: Principal.h:140
BranchType
Definition: BranchType.h:11
boost::filter_iterator< FilledProductPtr, ProductResolverCollection::iterator > iterator
Definition: Principal.h:62
std::vector< unsigned int > lookupProcessOrder_
Definition: Principal.h:275
std::vector< propagate_const< std::shared_ptr< ProductResolverBase > > > ProductResolverCollection
Definition: Principal.h:60
char const * label
void throwConvertTypeError(std::type_info const &expected, std::type_info const &actual)
ProductData const * findProductByTag(TypeID const &typeID, InputTag const &tag, ModuleCallingContext const *mcc) const
Definition: Principal.cc:789
T const * getThinnedProduct(RefCore const &ref, unsigned int &thinnedKey, EDProductGetter const *prodGetter)
Definition: RefCoreGet.h:129
std::shared_ptr< ProductResolverIndexHelper const > productLookup_
Definition: Principal.h:273
std::shared_ptr< Wrapper< PROD > const > getProductByTag(Principal const &ep, InputTag const &tag, ModuleCallingContext const *mcc)
Definition: Principal.h:293
std::shared_ptr< ProductRegistry const > preg_
Definition: Principal.h:272
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:142
CacheIdentifier_t cacheIdentifier_
Definition: Principal.h:289
BranchType const & branchType() const
Definition: Principal.h:180
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:196
ProcessHistoryID orderProcessHistoryID_
Definition: Principal.h:276
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:144
DelayedReader * reader() const
Definition: Principal.h:186
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:63
const_iterator begin() const
Definition: Principal.h:160
ProductResolverIndexHelper const & productLookup() const
Definition: Principal.h:148
ProductResolverBase const * ConstProductResolverPtr
Definition: Principal.h:64
iterator end()
Definition: Principal.h:170
HLT enums.
unsigned long CacheIdentifier_t
Definition: Principal.h:183
boost::filter_iterator< FilledProductPtr, ProductResolverCollection::const_iterator > const_iterator
Definition: Principal.h:61
#define PROD(A, B)
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
ProductResolverCollection::size_type size_type
Definition: Principal.h:66
EDProductGetter const * prodGetter() const
Definition: Principal.h:92
ProcessConfiguration const * processConfiguration_
Definition: Principal.h:265
std::shared_ptr< WrapperBase const > sharedConstWrapper() const
Definition: ProductData.h:36
std::vector< BasicHandle > BasicHandleVec
Definition: Principal.h:65