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 ----------------------------------------------------------------------*/
20 #include <map>
21 #include <memory>
22 #include <set>
23 #include <string>
24 #include <vector>
25 
26 #include "boost/iterator/filter_iterator.hpp"
27 #include "boost/shared_ptr.hpp"
39 
40 namespace edm {
41  struct FilledGroupPtr {
42  bool operator()(boost::shared_ptr<Group> const& iObj) { return bool(iObj);}
43  };
44 
45  class Principal : public EDProductGetter {
46  public:
47  typedef std::vector<boost::shared_ptr<Group> > GroupCollection;
48  typedef boost::filter_iterator<FilledGroupPtr, GroupCollection::const_iterator> const_iterator;
50  typedef boost::shared_ptr<Group const> SharedConstGroupPtr;
51  typedef std::vector<BasicHandle> BasicHandleVec;
53 
54  typedef boost::shared_ptr<Group> SharedGroupPtr;
55  typedef std::string ProcessName;
56 
57  Principal(boost::shared_ptr<ProductRegistry const> reg,
58  ProcessConfiguration const& pc,
59  BranchType bt);
60 
61  virtual ~Principal();
62 
64 
66 
67  void addGroupScheduled(boost::shared_ptr<ConstBranchDescription> bd);
68 
69  void addGroupSource(boost::shared_ptr<ConstBranchDescription> bd);
70 
71  void addGroupInput(boost::shared_ptr<ConstBranchDescription> bd);
72 
73  void addOnDemandGroup(boost::shared_ptr<ConstBranchDescription> bd);
74 
75  void fillPrincipal(ProcessHistoryID const& hist, boost::shared_ptr<BranchMapper> mapper, boost::shared_ptr<DelayedReader> rtrv);
76 
77  void clearPrincipal();
78 
79  EDProductGetter const* prodGetter() const {return this;}
80 
81  OutputHandle getForOutput(BranchID const& bid, bool getProd) const;
82 
83  BasicHandle getBySelector(TypeID const& tid,
84  SelectorBase const& s) const;
85 
86  BasicHandle getByLabel(TypeID const& tid,
87  std::string const& label,
88  std::string const& productInstanceName,
89  std::string const& processName,
90  size_t& cachedOffset,
91  int& fillCount) const;
92 
93  void getMany(TypeID const& tid,
94  SelectorBase const&,
95  BasicHandleVec& results) const;
96 
97  BasicHandle getByType(TypeID const& tid) const;
98 
99  void getManyByType(TypeID const& tid,
100  BasicHandleVec& results) const;
101 
102  // Return a BasicHandle to the product which:
103  // 1. is a sequence,
104  // 2. and has the nested type 'value_type'
105  // 3. and for which typeID is the same as or a public base of
106  // this value_type,
107  // 4. and which matches the given selector
108  size_t getMatchingSequence(TypeID const& typeID,
109  SelectorBase const& selector,
110  BasicHandle& result) const;
111 
113  return *processHistoryPtr_;
114  }
115 
117  return processHistoryID_;
118  }
119 
121 
122  ProductRegistry const& productRegistry() const {return *preg_;}
123 
124  // merge Principals containing different groups.
125  void recombine(Principal& other, std::vector<BranchID> const& bids);
126 
127  size_t size() const;
128 
129  // These iterators skip over any null shared pointers
130  const_iterator begin() const {return boost::make_filter_iterator<FilledGroupPtr>(groups_.begin(), groups_.end());}
131  const_iterator end() const {return boost::make_filter_iterator<FilledGroupPtr>(groups_.end(), groups_.end());}
132 
133  Provenance getProvenance(BranchID const& bid) const;
134 
135  void getAllProvenance(std::vector<Provenance const*>& provenances) const;
136 
137  BranchType const& branchType() const {return branchType_;}
138 
139  boost::shared_ptr<BranchMapper> branchMapperPtr() const {return branchMapperPtr_;}
140 
141  boost::shared_ptr<DelayedReader> store() const {return store_;}
142 
143  void maybeFlushCache(TypeID const& tid, InputTag const& tag) const;
144 
145  SharedConstGroupPtr const getGroup(BranchID const& oid,
146  bool resolveProd,
147  bool fillOnDemand) const;
148  protected:
150  return *processHistoryPtr_;
151  }
152 
153  // ----- Add a new Group
154  // *this takes ownership of the Group, which in turn owns its
155  // data.
156  void addGroup_(std::auto_ptr<Group> g);
157  void addGroupOrThrow(std::auto_ptr<Group> g);
158  Group* getExistingGroup(BranchID const& branchID);
159  Group* getExistingGroup(Group const& g);
160 
162  bool resolveProd,
163  bool fillOnDemand) const;
164 
165  // Make my DelayedReader get the EDProduct for a Group or
166  // trigger unscheduled execution if required. The Group is
167  // a cache, and so can be modified through the const reference.
168  // We do not change the *number* of groups through this call, and so
169  // *this is const.
170  void resolveProduct(Group const& g, bool fillOnDemand) const {resolveProduct_(g, fillOnDemand);}
171 
172  void swapBase(Principal&);
173 
174  // throws if the pointed to product is already in the Principal.
175  void checkUniquenessAndType(std::auto_ptr<EDProduct>& prod, Group const* group) const;
176 
177  void putOrMerge(std::auto_ptr<EDProduct> prod, Group const* group) const;
178 
179  void putOrMerge(std::auto_ptr<EDProduct> prod, std::auto_ptr<ProductProvenance> prov, Group* group);
180 
182 
183  private:
184  virtual EDProduct const* getIt(ProductID const&) const;
185 
186  virtual bool unscheduledFill(std::string const& moduleLabel) const = 0;
187 
188  // Used for indices to find groups by type and process
190 
191  size_t findGroup(TypeID const& typeID,
192  TypeLookup const& typeLookup,
193  SelectorBase const& selector,
194  BasicHandle& result) const;
195 
196  bool findGroupByLabel(TypeID const& typeID,
197  TypeLookup const& typeLookup,
198  std::string const& moduleLabel,
199  std::string const& productInstanceName,
200  std::string const& processName,
201  size_t& cachedOffset,
202  int& fillCount,
203  BasicHandle& result) const;
204 
205  size_t findGroups(TypeID const& typeID,
206  TypeLookup const& typeLookup,
207  SelectorBase const& selector,
208  BasicHandleVec& results) const;
209 
210  // defaults to no-op unless overridden in derived class.
211  virtual void resolveProduct_(Group const& g, bool fillOnDemand) const {}
212 
213  boost::shared_ptr<ProcessHistory> processHistoryPtr_;
214 
216 
218 
219  // A vector of groups.
220  GroupCollection groups_; // products and provenances are persistent
221 
222  // Pointer to the product registry. There is one entry in the registry
223  // for each EDProduct in the event.
224  boost::shared_ptr<ProductRegistry const> preg_;
225 
226  // Pointer to the 'mapper' that will get provenance information
227  // from the persistent store.
228  boost::shared_ptr<BranchMapper> branchMapperPtr_;
229 
230  // Pointer to the 'source' that will be used to obtain EDProducts
231  // from the persistent store.
232  boost::shared_ptr<DelayedReader> store_;
233 
234  // Used to check for duplicates. The same product instance must not be in more than one group.
235  mutable std::set<EDProduct *> productPtrs_;
236 
238  };
239 
240  template <typename PROD>
241  inline
242  boost::shared_ptr<Wrapper<PROD> const>
243  getProductByTag(Principal const& ep, InputTag const& tag) {
244  TypeID tid = TypeID(typeid(PROD));
245  ep.maybeFlushCache(tid, tag);
246  return boost::dynamic_pointer_cast<Wrapper<PROD> const>(ep.getByLabel(tid, tag.label(), tag.instance(), tag.process(), tag.cachedOffset(), tag.fillCount()).product());
247  }
248 }
249 #endif
BranchType branchType_
Definition: Principal.h:237
collection_type::const_iterator const_iterator
void maybeFlushCache(TypeID const &tid, InputTag const &tag) const
Definition: Principal.cc:595
ProductRegistry const & productRegistry() const
Definition: Principal.h:122
void clearPrincipal()
Definition: Principal.cc:125
boost::shared_ptr< BranchMapper > branchMapperPtr_
Definition: Principal.h:228
void swapBase(Principal &)
Definition: Principal.cc:647
boost::shared_ptr< Wrapper< PROD > const > getProductByTag(Principal const &ep, InputTag const &tag)
Definition: Principal.h:243
size_t size() const
Definition: Principal.cc:65
size_t findGroup(TypeID const &typeID, TypeLookup const &typeLookup, SelectorBase const &selector, BasicHandle &result) const
Definition: Principal.cc:392
void addGroupScheduled(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:100
boost::shared_ptr< DelayedReader > store() const
Definition: Principal.h:141
std::string ProcessName
Definition: Principal.h:55
SharedConstGroupPtr const getGroupByIndex(ProductTransientIndex const &oid, bool resolveProd, bool fillOnDemand) const
Definition: Principal.cc:216
const std::string & label
Definition: MVAComputer.cc:186
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:254
Principal(boost::shared_ptr< ProductRegistry const > reg, ProcessConfiguration const &pc, BranchType bt)
Definition: Principal.cc:20
const_iterator end() const
Definition: Principal.h:131
void addGroup_(std::auto_ptr< Group > g)
Definition: Principal.cc:170
Group * getExistingGroup(BranchID const &branchID)
Definition: Principal.cc:155
void putOrMerge(std::auto_ptr< EDProduct > prod, Group const *group) const
Definition: Principal.cc:623
void addGroupOrThrow(std::auto_ptr< Group > g)
Definition: Principal.cc:184
ProcessHistoryID processHistoryID_
Definition: Principal.h:215
void getAllProvenance(std::vector< Provenance const * > &provenances) const
Definition: Principal.cc:562
boost::shared_ptr< ProductRegistry const > preg_
Definition: Principal.h:224
uint16_t size_type
GroupCollection::size_type size_type
Definition: Principal.h:52
void addGroupSource(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:106
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:112
boost::shared_ptr< ProcessHistory > processHistoryPtr_
Definition: Principal.h:213
BranchType
Definition: BranchType.h:11
void resolveProduct(Group const &g, bool fillOnDemand) const
Definition: Principal.h:170
size_t & cachedOffset() const
Definition: InputTag.h:37
GroupCollection groups_
Definition: Principal.h:220
int & fillCount() const
Definition: InputTag.h:39
boost::shared_ptr< Group > SharedGroupPtr
Definition: Principal.h:54
void getMany(TypeID const &tid, SelectorBase const &, BasicHandleVec &results) const
Definition: Principal.cc:287
ProcessHistoryID const & processHistoryID() const
Definition: Principal.h:116
void setProcessHistory(Principal const &principal)
Definition: Principal.cc:201
BranchType const & branchType() const
Definition: Principal.h:137
size_t findGroups(TypeID const &typeID, TypeLookup const &typeLookup, SelectorBase const &selector, BasicHandleVec &results) const
Definition: Principal.cc:352
tuple result
Definition: query.py:137
void fillPrincipal(ProcessHistoryID const &hist, boost::shared_ptr< BranchMapper > mapper, boost::shared_ptr< DelayedReader > rtrv)
Definition: Principal.cc:138
void checkUniquenessAndType(std::auto_ptr< EDProduct > &prod, Group const *group) const
Definition: Principal.cc:608
size_t getMatchingSequence(TypeID const &typeID, SelectorBase const &selector, BasicHandle &result) const
Definition: Principal.cc:339
bool operator()(boost::shared_ptr< Group > const &iObj)
Definition: Principal.h:42
OutputHandle getForOutput(BranchID const &bid, bool getProd) const
Definition: Principal.cc:523
virtual void resolveProduct_(Group const &g, bool fillOnDemand) const
Definition: Principal.h:211
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:120
virtual EDProduct const * getIt(ProductID const &) const
Definition: Principal.cc:589
virtual ~Principal()
Definition: Principal.cc:58
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:49
const_iterator begin() const
Definition: Principal.h:130
SharedConstGroupPtr const getGroup(BranchID const &oid, bool resolveProd, bool fillOnDemand) const
Definition: Principal.cc:207
std::string const & label() const
Definition: InputTag.h:25
void getManyByType(TypeID const &tid, BasicHandleVec &results) const
Definition: Principal.cc:326
std::string const & process() const
Definition: InputTag.h:29
std::set< EDProduct * > productPtrs_
Definition: Principal.h:235
void addGroupInput(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:112
BasicHandle getByType(TypeID const &tid) const
Definition: Principal.cc:300
boost::filter_iterator< FilledGroupPtr, GroupCollection::const_iterator > const_iterator
Definition: Principal.h:48
author Stefano ARGIRO author Bill Tanenbaum
virtual bool unscheduledFill(std::string const &moduleLabel) const =0
bool adjustToNewProductRegistry(ProductRegistry const &reg)
Definition: Principal.cc:78
#define PROD(A, B)
BasicHandle getBySelector(TypeID const &tid, SelectorBase const &s) const
Definition: Principal.cc:229
bool findGroupByLabel(TypeID const &typeID, TypeLookup const &typeLookup, std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, size_t &cachedOffset, int &fillCount, BasicHandle &result) const
Definition: Principal.cc:444
std::vector< boost::shared_ptr< Group > > GroupCollection
Definition: Principal.h:47
boost::shared_ptr< BranchMapper > branchMapperPtr() const
Definition: Principal.h:139
TransientProductLookupMap TypeLookup
Definition: Principal.h:189
void adjustIndexesAfterProductRegistryAddition()
Definition: Principal.cc:658
string s
Definition: asciidump.py:422
EDProductGetter const * prodGetter() const
Definition: Principal.h:79
Provenance getProvenance(BranchID const &bid) const
Definition: Principal.cc:538
void recombine(Principal &other, std::vector< BranchID > const &bids)
Definition: Principal.cc:576
std::string const & instance() const
Definition: InputTag.h:26
boost::shared_ptr< Group const > SharedConstGroupPtr
Definition: Principal.h:50
ProcessConfiguration const * processConfiguration_
Definition: Principal.h:217
ProcessHistory & processHistoryUpdate()
Definition: Principal.h:149
std::vector< BasicHandle > BasicHandleVec
Definition: Principal.h:51
boost::shared_ptr< DelayedReader > store_
Definition: Principal.h:232
void addOnDemandGroup(boost::shared_ptr< ConstBranchDescription > bd)
Definition: Principal.cc:118
const std::string * moduleLabel() const
Definition: HLTadd.h:40