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 Group, which
10 contains an EDProduct and its associated Provenance, along with
11 ancillary transient information regarding the two. Groups are handled
12 through shared pointers.
13 
14 The Principal returns BasicHandle, rather than a shared
15 pointer to a Group, when queried.
16 
17 (Historical note: prior to April 2007 this class was named DataBlockImpl)
18 
19 ----------------------------------------------------------------------*/
34 
35 #include "boost/iterator/filter_iterator.hpp"
36 #include "boost/shared_ptr.hpp"
37 
38 #include <map>
39 #include <memory>
40 #include <set>
41 #include <string>
42 #include <vector>
43 
44 namespace edm {
45 
46  class HistoryAppender;
47 
48  struct FilledGroupPtr {
49  bool operator()(boost::shared_ptr<Group> const& iObj) { return bool(iObj);}
50  };
51 
52  class Principal : public EDProductGetter {
53  public:
54  typedef std::vector<boost::shared_ptr<Group> > GroupCollection;
55  typedef boost::filter_iterator<FilledGroupPtr, GroupCollection::const_iterator> const_iterator;
57  typedef Group const* ConstGroupPtr;
58  typedef std::vector<BasicHandle> BasicHandleVec;
60 
61  typedef boost::shared_ptr<Group> SharedGroupPtr;
62  typedef std::string ProcessName;
63 
64  Principal(boost::shared_ptr<ProductRegistry const> reg,
65  ProcessConfiguration const& pc,
66  BranchType bt,
67  HistoryAppender* historyAppender);
68 
69  virtual ~Principal();
70 
72 
74 
75  void addGroupScheduled(boost::shared_ptr<ConstBranchDescription> bd);
76 
77  void addGroupSource(boost::shared_ptr<ConstBranchDescription> bd);
78 
79  void addGroupInput(boost::shared_ptr<ConstBranchDescription> bd);
80 
81  void addOnDemandGroup(boost::shared_ptr<ConstBranchDescription> bd);
82 
84 
85  void clearPrincipal();
86 
87  void deleteProduct(BranchID const& id);
88 
89  EDProductGetter const* prodGetter() const {return this;}
90 
91  OutputHandle getForOutput(BranchID const& bid, bool getProd) const;
92 
93  BasicHandle getBySelector(TypeID const& tid,
94  SelectorBase const& s) const;
95 
96  BasicHandle getByLabel(TypeID const& tid,
97  std::string const& label,
98  std::string const& productInstanceName,
99  std::string const& processName,
100  size_t& cachedOffset,
101  int& fillCount) const;
102 
103  void getMany(TypeID const& tid,
104  SelectorBase const&,
105  BasicHandleVec& results) const;
106 
107  BasicHandle getByType(TypeID const& tid) const;
108 
109  void getManyByType(TypeID const& tid,
110  BasicHandleVec& results) const;
111 
112  // Return a BasicHandle to the product which:
113  // 1. is a sequence,
114  // 2. and has the nested type 'value_type'
115  // 3. and for which typeID is the same as or a public base of
116  // this value_type,
117  // 4. and which matches the given selector
118  size_t getMatchingSequence(TypeID const& typeID,
119  SelectorBase const& selector,
120  BasicHandle& result) const;
121 
123  return *processHistoryPtr_;
124  }
125 
127  return processHistoryID_;
128  }
129 
131 
132  ProductRegistry const& productRegistry() const {return *preg_;}
133 
134  // merge Principals containing different groups.
135  void recombine(Principal& other, std::vector<BranchID> const& bids);
136 
137  size_t size() const;
138 
139  // These iterators skip over any null shared pointers
140  const_iterator begin() const {return boost::make_filter_iterator<FilledGroupPtr>(groups_.begin(), groups_.end());}
141  const_iterator end() const {return boost::make_filter_iterator<FilledGroupPtr>(groups_.end(), groups_.end());}
142 
143  Provenance getProvenance(BranchID const& bid) const;
144 
145  void getAllProvenance(std::vector<Provenance const*>& provenances) const;
146 
147  BranchType const& branchType() const {return branchType_;}
148 
149  DelayedReader* reader() const {return reader_;}
150 
151  void maybeFlushCache(TypeID const& tid, InputTag const& tag) const;
152 
153  ConstGroupPtr getGroup(BranchID const& oid,
154  bool resolveProd,
155  bool fillOnDemand) const;
156 
157  ProductData const* findGroupByTag(TypeID const& typeID, InputTag const& tag) const;
158 
159  protected:
160 
161  // ----- Add a new Group
162  // *this takes ownership of the Group, which in turn owns its
163  // data.
164  void addGroup_(std::auto_ptr<Group> g);
165  void addGroupOrThrow(std::auto_ptr<Group> g);
166  Group* getExistingGroup(BranchID const& branchID);
167  Group* getExistingGroup(Group const& g);
168 
170  bool resolveProd,
171  bool fillOnDemand) const;
172 
173  // Make my DelayedReader get the EDProduct for a Group or
174  // trigger unscheduled execution if required. The Group is
175  // a cache, and so can be modified through the const reference.
176  // We do not change the *number* of groups through this call, and so
177  // *this is const.
178  void resolveProduct(Group const& g, bool fillOnDemand) const {resolveProduct_(g, fillOnDemand);}
179 
180  // throws if the pointed to product is already in the Principal.
181  void checkUniquenessAndType(WrapperOwningHolder const& prod, Group const* group) const;
182 
183  void putOrMerge(WrapperOwningHolder const& prod, Group const* group) const;
184 
185  void putOrMerge(WrapperOwningHolder const& prod, ProductProvenance& prov, Group* group);
186 
187  private:
188  virtual WrapperHolder getIt(ProductID const&) const;
189 
190  virtual bool unscheduledFill(std::string const& moduleLabel) const = 0;
191 
192  // Used for indices to find groups by type and process
194 
195  size_t findGroup(TypeID const& typeID,
196  TypeLookup const& typeLookup,
197  SelectorBase const& selector,
198  BasicHandle& result) const;
199 
200  ProductData const* findGroupByLabel(TypeID const& typeID,
201  TypeLookup const& typeLookup,
202  std::string const& moduleLabel,
203  std::string const& productInstanceName,
204  std::string const& processName,
205  size_t& cachedOffset,
206  int& fillCount) const;
207 
208  size_t findGroups(TypeID const& typeID,
209  TypeLookup const& typeLookup,
210  SelectorBase const& selector,
211  BasicHandleVec& results) const;
212 
213  // defaults to no-op unless overridden in derived class.
214  virtual void resolveProduct_(Group const&, bool /*fillOnDemand*/) const {}
215 
217 
219 
221 
222  // A vector of groups.
223  GroupCollection groups_; // products and provenances are persistent
224 
225  // Pointer to the product registry. There is one entry in the registry
226  // for each EDProduct in the event.
227  boost::shared_ptr<ProductRegistry const> preg_;
228 
229  // Pointer to the 'source' that will be used to obtain EDProducts
230  // from the persistent store. This 'source' is owned by the input source.
232 
233  // Used to check for duplicates. The same product instance must not be in more than one group.
234  mutable std::set<void const*> productPtrs_;
235 
237 
238  // In use cases where the new process should not be appended to
239  // input ProcessHistory, the following pointer should be null.
240  // The Principal does not own this object.
242 
244  };
245 
246  template <typename PROD>
247  inline
248  boost::shared_ptr<Wrapper<PROD> const>
249  getProductByTag(Principal const& ep, InputTag const& tag) {
250  TypeID tid = TypeID(typeid(PROD));
251  ep.maybeFlushCache(tid, tag);
252  ProductData const* result = ep.findGroupByTag(tid, tag);
253 
254  if(result->getInterface() &&
255  (!(result->getInterface()->dynamicTypeInfo() == typeid(PROD)))) {
257  }
258  return boost::static_pointer_cast<Wrapper<PROD> const>(result->wrapper_);
259  }
260 }
261 #endif
BranchType branchType_
Definition: Principal.h:236
collection_type::const_iterator const_iterator
void maybeFlushCache(TypeID const &tid, InputTag const &tag) const
Definition: Principal.cc:731
ProductRegistry const & productRegistry() const
Definition: Principal.h:132
void clearPrincipal()
Definition: Principal.cc:206
boost::shared_ptr< Wrapper< PROD > const > getProductByTag(Principal const &ep, InputTag const &tag)
Definition: Principal.h:249
size_t size() const
Definition: Principal.cc:146
size_t findGroup(TypeID const &typeID, TypeLookup const &typeLookup, SelectorBase const &selector, BasicHandle &result) const
Definition: Principal.cc:490
void addGroupScheduled(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:181
DelayedReader * reader_
Definition: Principal.h:231
std::string ProcessName
Definition: Principal.h:62
WrapperInterfaceBase const * getInterface() const
Definition: ProductData.h:25
HistoryAppender * historyAppender_
Definition: Principal.h:241
BasicHandle getByLabel(TypeID const &tid, std::string const &label, std::string const &productInstanceName, std::string const &processName, size_t &cachedOffset, int &fillCount) const
Definition: Principal.cc:355
const_iterator end() const
Definition: Principal.h:141
void addGroup_(std::auto_ptr< Group > g)
Definition: Principal.cc:282
Group * getExistingGroup(BranchID const &branchID)
Definition: Principal.cc:267
void addGroupOrThrow(std::auto_ptr< Group > g)
Definition: Principal.cc:296
ConstGroupPtr getGroup(BranchID const &oid, bool resolveProd, bool fillOnDemand) const
Definition: Principal.cc:313
ProcessHistoryID processHistoryID_
Definition: Principal.h:218
void getAllProvenance(std::vector< Provenance const * > &provenances) const
Definition: Principal.cc:699
boost::shared_ptr< ProductRegistry const > preg_
Definition: Principal.h:227
std::type_info const & dynamicTypeInfo() const
ProcessHistory const * processHistoryPtr_
Definition: Principal.h:216
uint16_t size_type
GroupCollection::size_type size_type
Definition: Principal.h:59
void addGroupSource(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:187
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
ProcessHistory const & processHistory() const
Definition: Principal.h:122
ProductData const * findGroupByTag(TypeID const &typeID, InputTag const &tag) const
Definition: Principal.cc:643
BranchType
Definition: BranchType.h:11
void resolveProduct(Group const &g, bool fillOnDemand) const
Definition: Principal.h:178
GroupCollection groups_
Definition: Principal.h:223
Group const * ConstGroupPtr
Definition: Principal.h:57
virtual void resolveProduct_(Group const &, bool) const
Definition: Principal.h:214
void throwConvertTypeError(std::type_info const &expected, std::type_info const &actual)
boost::shared_ptr< Group > SharedGroupPtr
Definition: Principal.h:61
void getMany(TypeID const &tid, SelectorBase const &, BasicHandleVec &results) const
Definition: Principal.cc:379
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:126
BranchType const & branchType() const
Definition: Principal.h:147
size_t findGroups(TypeID const &typeID, TypeLookup const &typeLookup, SelectorBase const &selector, BasicHandleVec &results) const
Definition: Principal.cc:440
ProductData const * findGroupByLabel(TypeID const &typeID, TypeLookup const &typeLookup, std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, size_t &cachedOffset, int &fillCount) const
Definition: Principal.cc:551
tuple result
Definition: query.py:137
size_t getMatchingSequence(TypeID const &typeID, SelectorBase const &selector, BasicHandle &result) const
Definition: Principal.cc:427
boost::shared_ptr< void const > wrapper_
Definition: ProductData.h:46
bool operator()(boost::shared_ptr< Group > const &iObj)
Definition: Principal.h:49
OutputHandle getForOutput(BranchID const &bid, bool getProd) const
Definition: Principal.cc:659
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:130
std::set< void const * > productPtrs_
Definition: Principal.h:234
DelayedReader * reader() const
Definition: Principal.h:149
ConstGroupPtr getGroupByIndex(ProductTransientIndex const &oid, bool resolveProd, bool fillOnDemand) const
Definition: Principal.cc:322
virtual ~Principal()
Definition: Principal.cc:139
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:56
const_iterator begin() const
Definition: Principal.h:140
virtual WrapperHolder getIt(ProductID const &) const
Definition: Principal.cc:725
void getManyByType(TypeID const &tid, BasicHandleVec &results) const
Definition: Principal.cc:414
void addGroupInput(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:193
BasicHandle getByType(TypeID const &tid) const
Definition: Principal.cc:392
boost::filter_iterator< FilledGroupPtr, GroupCollection::const_iterator > const_iterator
Definition: Principal.h:55
author Stefano ARGIRO author Bill Tanenbaum
virtual bool unscheduledFill(std::string const &moduleLabel) const =0
bool adjustToNewProductRegistry(ProductRegistry const &reg)
Definition: Principal.cc:159
#define PROD(A, B)
BasicHandle getBySelector(TypeID const &tid, SelectorBase const &s) const
Definition: Principal.cc:335
Principal(boost::shared_ptr< ProductRegistry const > reg, ProcessConfiguration const &pc, BranchType bt, HistoryAppender *historyAppender)
Definition: Principal.cc:99
std::vector< boost::shared_ptr< Group > > GroupCollection
Definition: Principal.h:54
void fillPrincipal(ProcessHistoryID const &hist, DelayedReader *reader)
Definition: Principal.cc:229
TransientProductLookupMap TypeLookup
Definition: Principal.h:193
void adjustIndexesAfterProductRegistryAddition()
Definition: Principal.cc:783
static ProcessHistory emptyProcessHistory_
Definition: Principal.h:243
EDProductGetter const * prodGetter() const
Definition: Principal.h:89
Provenance getProvenance(BranchID const &bid) const
Definition: Principal.cc:677
void recombine(Principal &other, std::vector< BranchID > const &bids)
Definition: Principal.cc:713
void checkUniquenessAndType(WrapperOwningHolder const &prod, Group const *group) const
Definition: Principal.cc:744
ProcessConfiguration const * processConfiguration_
Definition: Principal.h:220
std::vector< BasicHandle > BasicHandleVec
Definition: Principal.h:58
void addOnDemandGroup(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:199
void putOrMerge(WrapperOwningHolder const &prod, Group const *group) const
Definition: Principal.cc:759
void deleteProduct(BranchID const &id)
Definition: Principal.cc:217