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