CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 ModuleCallingContext;
45  class ProcessHistoryRegistry;
46  class ProductResolverIndexHelper;
47  class EDConsumerBase;
49  class InputProductResolver;
50  class WaitingTask;
51 
53  bool operator()(propagate_const<std::shared_ptr<ProductResolverBase>> const& iObj) { return bool(iObj);}
54  };
55 
56  class Principal : public EDProductGetter {
57  public:
58  typedef std::vector<propagate_const<std::shared_ptr<ProductResolverBase>> > ProductResolverCollection;
59  typedef boost::filter_iterator<FilledProductPtr, ProductResolverCollection::const_iterator> const_iterator;
60  typedef boost::filter_iterator<FilledProductPtr, ProductResolverCollection::iterator> iterator;
63  typedef std::vector<BasicHandle> BasicHandleVec;
65 
66  typedef std::shared_ptr<ProductResolverBase> SharedProductPtr;
68 
69  Principal(std::shared_ptr<ProductRegistry const> reg,
70  std::shared_ptr<ProductResolverIndexHelper const> productLookup,
71  ProcessConfiguration const& pc,
72  BranchType bt,
73  HistoryAppender* historyAppender,
74  bool isForPrimaryProcess = true);
75 
76  virtual ~Principal();
77 
78  bool adjustToNewProductRegistry(ProductRegistry const& reg);
79 
80  void adjustIndexesAfterProductRegistryAddition();
81 
82  void fillPrincipal(ProcessHistoryID const& hist, ProcessHistoryRegistry const& phr, DelayedReader* reader);
83 
84  void clearPrincipal();
85 
86  void deleteProduct(BranchID const& id) const;
87 
88  EDProductGetter const* prodGetter() const {return this;}
89 
90  // Return a BasicHandle to the product which:
91  // 1. matches the given label, instance, and process
92  // (if process if empty gets the match from the most recent process)
93  // 2. If kindOfType is PRODUCT, then the type of the product matches typeID
94  // 3. If kindOfType is ELEMENT
95  // a. the product is a sequence,
96  // b. the sequence has the nested type 'value_type'
97  // c. typeID is the same as or a public base of
98  // this value_type,
99 
100  BasicHandle getByLabel(KindOfType kindOfType,
101  TypeID const& typeID,
102  InputTag const& inputTag,
103  EDConsumerBase const* consumes,
105  ModuleCallingContext const* mcc) const;
106 
107  BasicHandle getByLabel(KindOfType kindOfType,
108  TypeID const& typeID,
109  std::string const& label,
110  std::string const& instance,
111  std::string const& process,
112  EDConsumerBase const* consumes,
114  ModuleCallingContext const* mcc) const;
115 
116  BasicHandle getByToken(KindOfType kindOfType,
117  TypeID const& typeID,
119  bool skipCurrentProcess,
120  bool& ambiguous,
122  ModuleCallingContext const* mcc) const;
123 
124  void prefetchAsync(WaitingTask* waitTask,
125  ProductResolverIndex index,
126  bool skipCurrentProcess,
127  ModuleCallingContext const* mcc) const;
128 
129  void getManyByType(TypeID const& typeID,
130  BasicHandleVec& results,
131  EDConsumerBase const* consumes,
133  ModuleCallingContext const* mcc) const;
134 
136  return *processHistoryPtr_;
137  }
138 
140  return processHistoryID_;
141  }
142 
143  ProcessConfiguration const& processConfiguration() const {return *processConfiguration_;}
144 
145  ProductRegistry const& productRegistry() const {return *preg_;}
146 
147  ProductResolverIndexHelper const& productLookup() const {return *productLookup_;}
148 
149  // merge Principals containing different products.
150  void recombine(Principal& other, std::vector<BranchID> const& bids);
151 
153  return const_cast<ProductResolverBase*>( const_cast<const Principal*>(this)->getProductResolver(oid));
154  }
155 
156  size_t size() const;
157 
158  // These iterators skip over any null shared pointers
159  const_iterator begin() const {return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.begin(), productResolvers_.end());}
160  const_iterator end() const {return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.end(), productResolvers_.end());}
161 
162  iterator begin() {return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.begin(), productResolvers_.end());}
163  iterator end() {return boost::make_filter_iterator<FilledProductPtr>(productResolvers_.end(), productResolvers_.end());}
164 
165  Provenance getProvenance(BranchID const& bid,
166  ModuleCallingContext const* mcc) const;
167 
168  void getAllProvenance(std::vector<Provenance const*>& provenances) const;
169 
170  void getAllStableProvenance(std::vector<StableProvenance const*>& provenances) const;
171 
172  BranchType const& branchType() const {return branchType_;}
173 
174  //This will never return 0 so you can use 0 to mean unset
175  typedef unsigned long CacheIdentifier_t;
176  CacheIdentifier_t cacheIdentifier() const {return cacheIdentifier_;}
177 
178  DelayedReader* reader() const {return reader_;}
179 
180  ConstProductResolverPtr getProductResolver(BranchID const& oid) const;
181 
182  ProductData const* findProductByTag(TypeID const& typeID, InputTag const& tag, ModuleCallingContext const* mcc) const;
183 
184  void readAllFromSourceAndMergeImmediately();
185  //For end Run/Lumi we need to reset products failed in the begin
186  // transition since they may be put into the Principal at the
187  // end transition
188  void resetFailedFromThisProcess();
189 
190  std::vector<unsigned int> const& lookupProcessOrder() const { return lookupProcessOrder_; }
191 
192  ConstProductResolverPtr getProductResolverByIndex(ProductResolverIndex const& oid) const;
193 
194  bool isComplete() const {return isComplete_();}
195 
196  protected:
197 
198  // ----- Add a new ProductResolver
199  // *this takes ownership of the ProductResolver, which in turn owns its
200  // data.
201  void addProduct_(std::unique_ptr<ProductResolverBase> phb);
202  void addProductOrThrow(std::unique_ptr<ProductResolverBase> phb);
203  ProductResolverBase* getExistingProduct(BranchID const& branchID);
204  ProductResolverBase const* getExistingProduct(BranchID const& branchID) const;
205  ProductResolverBase const* getExistingProduct(ProductResolverBase const& phb) const;
206 
207  void putOrMerge(BranchDescription const& bd, std::unique_ptr<WrapperBase> edp) const;
208 
209  //F must take an argument of type ProductResolverBase*
210  template <typename F>
211  void applyToResolvers( F iFunc) {
212  for(auto& resolver: productResolvers_) {
213  iFunc(resolver.get());
214  }
215  }
216 
217  private:
218 
219  void addScheduledProduct(std::shared_ptr<BranchDescription const> bd);
220  void addSourceProduct(std::shared_ptr<BranchDescription const> bd);
221  void addInputProduct(std::shared_ptr<BranchDescription const> bd);
222  void addUnscheduledProduct(std::shared_ptr<BranchDescription const> bd);
223  void addAliasedProduct(std::shared_ptr<BranchDescription const> bd);
224  void addParentProcessProduct(std::shared_ptr<BranchDescription const> bd);
225 
226 
227  virtual WrapperBase const* getIt(ProductID const&) const override;
228  virtual WrapperBase const* getThinnedProduct(ProductID const&, unsigned int&) const override;
229  virtual void getThinnedProducts(ProductID const&,
230  std::vector<WrapperBase const*>&,
231  std::vector<unsigned int>&) const override;
232 
233  void findProducts(std::vector<ProductResolverBase const*> const& holders,
234  TypeID const& typeID,
235  BasicHandleVec& results,
237  ModuleCallingContext const* mcc) const;
238 
239  ProductData const* findProductByLabel(KindOfType kindOfType,
240  TypeID const& typeID,
241  InputTag const& inputTag,
242  EDConsumerBase const* consumer,
244  ModuleCallingContext const* mcc) const;
245 
246  ProductData const* findProductByLabel(KindOfType kindOfType,
247  TypeID const& typeID,
248  std::string const& label,
249  std::string const& instance,
250  std::string const& process,
251  EDConsumerBase const* consumer,
253  ModuleCallingContext const* mcc) const;
254 
255  virtual bool isComplete_() const {return true;}
256 
257  void putOrMerge(std::unique_ptr<WrapperBase> prod, ProductResolverBase const* productResolver) const;
258 
259  std::shared_ptr<ProcessHistory const> processHistoryPtr_;
260 
262 
264 
265  // A vector of product holders.
266  ProductResolverCollection productResolvers_; // products and provenances are persistent
267 
268  // Pointer to the product registry. There is one entry in the registry
269  // for each EDProduct in the event.
270  std::shared_ptr<ProductRegistry const> preg_;
271  std::shared_ptr<ProductResolverIndexHelper const> productLookup_;
272 
273  std::vector<unsigned int> lookupProcessOrder_;
275 
276  // Pointer to the 'source' that will be used to obtain EDProducts
277  // from the persistent store. This 'source' is owned by the input source.
279 
281 
282  // In use cases where the new process should not be appended to
283  // input ProcessHistory, the following pointer should be null.
284  // The Principal does not own this object.
286 
287  CacheIdentifier_t cacheIdentifier_;
288 
289  };
290 
291  template <typename PROD>
292  inline
293  std::shared_ptr<Wrapper<PROD> const>
294  getProductByTag(Principal const& ep, InputTag const& tag, ModuleCallingContext const* mcc) {
295  TypeID tid = TypeID(typeid(PROD));
296  ProductData const* result = ep.findProductByTag(tid, tag, mcc);
297  if(result == nullptr) {
298  return std::shared_ptr<Wrapper<PROD> const>();
299  }
300 
301  if(!(result->wrapper()->dynamicTypeInfo() == typeid(PROD))) {
303  }
304  return std::static_pointer_cast<Wrapper<PROD> const>(result->sharedConstWrapper());
305  }
306 }
307 #endif
BranchType branchType_
Definition: Principal.h:280
size
Write out results.
collection_type::const_iterator const_iterator
ProductRegistry const & productRegistry() const
Definition: Principal.h:145
ProductResolverBase * getModifiableProductResolver(BranchID const &oid)
Definition: Principal.h:152
DelayedReader * reader_
Definition: Principal.h:278
std::string ProcessName
Definition: Principal.h:67
iterator begin()
Definition: Principal.h:162
unsigned int ProductResolverIndex
ProductResolverCollection productResolvers_
Definition: Principal.h:266
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:38
std::shared_ptr< ProcessHistory const > processHistoryPtr_
Definition: Principal.h:259
const_iterator end() const
Definition: Principal.h:160
static PFTauRenderPlugin instance
std::shared_ptr< ProductResolverBase > SharedProductPtr
Definition: Principal.h:66
bool isComplete() const
Definition: Principal.h:194
ProcessHistoryID processHistoryID_
Definition: Principal.h:261
virtual bool isComplete_() const
Definition: Principal.h:255
void applyToResolvers(F iFunc)
Definition: Principal.h:211
WrapperBase const * wrapper() const
Definition: ProductData.h:32
CacheIdentifier_t cacheIdentifier() const
Definition: Principal.h:176
bool operator()(propagate_const< std::shared_ptr< ProductResolverBase >> const &iObj)
Definition: Principal.h:53
edm::propagate_const< HistoryAppender * > historyAppender_
Definition: Principal.h:285
uint16_t size_type
ProcessHistory const & processHistory() const
Definition: Principal.h:135
BranchType
Definition: BranchType.h:11
boost::filter_iterator< FilledProductPtr, ProductResolverCollection::iterator > iterator
Definition: Principal.h:60
std::vector< unsigned int > lookupProcessOrder_
Definition: Principal.h:273
std::vector< propagate_const< std::shared_ptr< ProductResolverBase > > > ProductResolverCollection
Definition: Principal.h:58
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:700
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:271
std::shared_ptr< Wrapper< PROD > const > getProductByTag(Principal const &ep, InputTag const &tag, ModuleCallingContext const *mcc)
Definition: Principal.h:294
std::shared_ptr< ProductRegistry const > preg_
Definition: Principal.h:270
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:139
CacheIdentifier_t cacheIdentifier_
Definition: Principal.h:287
BranchType const & branchType() const
Definition: Principal.h:172
std::vector< unsigned int > const & lookupProcessOrder() const
Definition: Principal.h:190
ProcessHistoryID orderProcessHistoryID_
Definition: Principal.h:274
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:143
DelayedReader * reader() const
Definition: Principal.h:178
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:61
const_iterator begin() const
Definition: Principal.h:159
ProductResolverIndexHelper const & productLookup() const
Definition: Principal.h:147
ProductResolverBase const * ConstProductResolverPtr
Definition: Principal.h:62
iterator end()
Definition: Principal.h:163
HLT enums.
unsigned long CacheIdentifier_t
Definition: Principal.h:175
boost::filter_iterator< FilledProductPtr, ProductResolverCollection::const_iterator > const_iterator
Definition: Principal.h:59
#define PROD(A, B)
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
ProductResolverCollection::size_type size_type
Definition: Principal.h:64
EDProductGetter const * prodGetter() const
Definition: Principal.h:88
ProcessConfiguration const * processConfiguration_
Definition: Principal.h:263
std::shared_ptr< WrapperBase const > sharedConstWrapper() const
Definition: ProductData.h:35
std::vector< BasicHandle > BasicHandleVec
Definition: Principal.h:63