LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
Principal.h
Go to the documentation of this file.
1 #ifndef art_Framework_Principal_Principal_h
2 #define art_Framework_Principal_Principal_h
3 // vim: set sw=2:
4 
5 // =================================================================
6 // Principal
7 //
8 // Pure abstract base class for Run-, SubRun-, and EventPrincipal,
9 // the classes which manage data products.
10 //
11 // The major internal component is the Group, which contains an
12 // EDProduct and its associated Provenance, along with ancillary
13 // transient information regarding the two. Groups are handled
14 // through shared pointers.
15 //
16 // The Principal returns GroupQueryResult, rather than a shared
17 // pointer to a Group, when queried.
18 // =================================================================
19 
38 #include "cetlib/exempt_ptr.h"
39 
40 #include <cstdio>
41 #include <map>
42 #include <memory>
43 #include <string>
44 #include <vector>
45 
46 namespace art {
47 
49 
50  public: // TYPES
51  using GroupCollection = std::map<ProductID, std::unique_ptr<Group>>;
54  using GroupQueryResultVec = std::vector<GroupQueryResult>;
55  using size_type = GroupCollection::size_type;
56  using ProcessName = std::string;
57 
58  public: // MEMBER FUNCTIONS
59  virtual ~Principal() noexcept = default;
60 
61  // Disable copying
62  Principal(Principal const&) = delete;
63  Principal& operator=(Principal const&) = delete;
64 
66  ProcessHistoryID const&,
67  cet::exempt_ptr<ProductTable const> presentProducts,
68  std::unique_ptr<BranchMapper>&&,
69  std::unique_ptr<DelayedReader>&&);
70 
71  EDProductGetter const* productGetter(ProductID const pid) const;
72 
73  OutputHandle getForOutput(ProductID const, bool resolveProd) const;
74 
76  SelectorBase const&) const;
77 
79 
81  std::string const& label,
82  std::string const& productInstanceName,
83  std::string const& processName) const;
84 
86  SelectorBase const&) const;
87 
88  // ROOT-FIXME: Return a vector of GroupQueryResults to the products which:
89  // 1. are sequences,
90  // 2. and have the nested type 'value_type'
91  // 3. and for which elementType is the same as or a public base of
92  // this value_type,
93  // 4. and which matches the given selector
94 
96 
97  void removeCachedProduct(ProductID const pid) const;
98 
99  void
100  addSecondaryPrincipal(std::unique_ptr<Principal>&& val)
101  {
102  secondaryPrincipals_.emplace_back(std::move(val));
103  }
104 
105  void
106  setProducedProducts(ProductTable const& producedProducts)
107  {
108  producedProducts_ = cet::make_exempt_ptr(&producedProducts);
109  }
110 
111  void
113  {
115  for (auto const& val : groups_) {
116  if (!val.second->productUnavailable()) {
117  val.second->resolveProduct(val.second->producedWrapperType());
118  }
119  }
120  }
121 
122  void
124  {
125  for (auto const& val : groups_) {
126  (void)val.second->productProvenancePtr();
127  }
128  branchMapperPtr_->setDelayedRead(false);
129  }
130 
131  ProcessHistory const&
133  {
134  return processHistory_;
135  }
136 
137  ProcessConfiguration const&
139  {
140  return processConfiguration_;
141  }
142 
143  BranchMapper const&
144  branchMapper() const
145  {
146  return *branchMapperPtr_;
147  }
148 
149  size_t
150  size() const
151  {
152  return groups_.size();
153  }
154 
156  begin() const
157  {
158  return groups_.begin();
159  }
160 
162  cbegin() const
163  {
164  return groups_.cbegin();
165  }
166 
168  end() const
169  {
170  return groups_.end();
171  }
172 
174  cend() const
175  {
176  return groups_.cend();
177  }
178 
179  // Flag that we have been updated in the current process.
180  void addToProcessHistory();
181 
182  // Obtain the branch type suitable for products inserted into the
183  // principal.
184  virtual BranchType branchType() const = 0;
185 
186  virtual void fillGroup(BranchDescription const&) = 0;
187 
188  virtual RangeSet seenRanges() const = 0;
189 
190  protected: // MEMBER FUNCTIONS
191  BranchMapper&
193  {
194  return *branchMapperPtr_;
195  }
196 
199  {
200  return *store_;
201  }
202 
203  // We take ownership of the Group, which in turn owns its data.
204  void
205  fillGroup(std::unique_ptr<Group>&& group)
206  {
207  BranchDescription const& pd = group->productDescription();
208  assert(!pd.producedClassName().empty());
209  assert(!pd.friendlyClassName().empty());
210  assert(!pd.moduleLabel().empty());
211  assert(!pd.processName().empty());
212  group->setResolvers(branchMapper(), *store_);
213  groups_[pd.productID()] = std::move(group);
214  }
215 
216  int tryNextSecondaryFile() const;
217 
218  cet::exempt_ptr<Group const> getGroupForPtr(ProductID const pid) const;
219 
220  cet::exempt_ptr<Group const> getGroup(ProductID const pid) const;
221 
222  cet::exempt_ptr<Group const> getResolvedGroup(ProductID const pid,
223  bool resolveProd) const;
224 
225  private: // MEMBER FUNCTIONS
226  virtual ProcessHistoryID const& processHistoryID() const = 0;
227 
228  virtual void setProcessHistoryID(ProcessHistoryID const&) = 0;
229 
231  SelectorBase const&) const;
232 
234  SelectorBase const&,
235  bool stopIfProcessHasMatch) const;
236 
237  size_t findGroupsFromInputFile(WrappedTypeID const& wrapped,
238  SelectorBase const&,
239  GroupQueryResultVec& results,
240  bool stopIfProcessHasMatch) const;
241 
242  size_t findGroups(ProcessLookup const&,
243  SelectorBase const&,
244  GroupQueryResultVec& results,
245  bool stopIfProcessHasMatch,
246  TypeID wanted_wrapper = TypeID{}) const;
247 
248  size_t findGroupsForProcess(std::vector<ProductID> const& vpid,
249  SelectorBase const& selector,
250  GroupQueryResultVec& results,
251  TypeID wanted_wrapper) const;
252 
253  bool presentFromSource(ProductID) const;
254 
255  private: // MEMBER DATA
256  // This function and its associated member datum are required to
257  // handle the lifetime of a deferred getter, which in turn is
258  // required because a group does not exist until it is placed in
259  // the event.
260  EDProductGetter const* deferredGetter_(ProductID const pid) const;
261 
262  EDProductGetter const*
263  getEDProductGetterImpl(ProductID const pid) const final override
264  {
265  return getByProductID(pid).result().get();
266  }
267 
269 
271  cet::exempt_ptr<ProductTable const> presentProducts_;
272  cet::exempt_ptr<ProductTable const> producedProducts_{nullptr};
273 
274  mutable std::map<ProductID, std::shared_ptr<DeferredProductGetter const>>
276 
277  mutable bool processHistoryModified_{false};
278 
279  // Products and provenances are persistent.
281 
282  // Pointer to the mapper that will get provenance information from
283  // the persistent store.
284  std::unique_ptr<BranchMapper> branchMapperPtr_;
285 
286  // Pointer to the reader that will be used to obtain EDProducts
287  // from the persistent store.
288  std::unique_ptr<DelayedReader> store_;
289 
290  // Secondary principals. Note that the lifetime of run and subRun
291  // principals is the lifetime of the input file, while the
292  // lifetime of event principals ends at the next event read.
293  std::vector<std::unique_ptr<Principal>> secondaryPrincipals_{};
294 
295  // Index into the secondary file names vector of the next file
296  // that a secondary principal should be created from.
297  mutable int nextSecondaryFileIdx_{};
298  };
299 
300 } // namespace art
301 
302 // Local Variables:
303 // mode: c++
304 // End:
305 #endif /* art_Framework_Principal_Principal_h */
cet::exempt_ptr< ProductTable const > presentProducts_
Definition: Principal.h:271
GroupQueryResultVec findGroupsForProduct(WrappedTypeID const &wrapped, SelectorBase const &, bool stopIfProcessHasMatch) const
Definition: Principal.cc:278
virtual ~Principal() noexcept=default
std::unique_ptr< BranchMapper > branchMapperPtr_
Definition: Principal.h:284
bool presentFromSource(ProductID) const
Definition: Principal.cc:470
std::map< std::string, std::vector< ProductID >> ProcessLookup
Definition: type_aliases.h:15
void fillGroup(std::unique_ptr< Group > &&group)
Definition: Principal.h:205
size_t findGroupsFromInputFile(WrappedTypeID const &wrapped, SelectorBase const &, GroupQueryResultVec &results, bool stopIfProcessHasMatch) const
Definition: Principal.cc:334
GroupCollection groups_
Definition: Principal.h:280
const std::string label
const_iterator cbegin() const
Definition: Principal.h:162
ProcessHistory processHistory_
Definition: Principal.h:268
void removeCachedProduct(ProductID const pid) const
Definition: Principal.cc:259
STL namespace.
cet::exempt_ptr< Group const > getGroup(ProductID const pid) const
Definition: Principal.cc:525
int tryNextSecondaryFile() const
Definition: Principal.cc:184
cet::exempt_ptr< ProductTable const > producedProducts_
Definition: Principal.h:272
std::string const & producedClassName() const
GroupQueryResult getBySelector(WrappedTypeID const &wrapped, SelectorBase const &) const
Definition: Principal.cc:110
collection_type::const_iterator const_iterator
size_t size() const
Definition: Principal.h:150
virtual RangeSet seenRanges() const =0
std::unique_ptr< DelayedReader > store_
Definition: Principal.h:288
std::string ProcessName
Definition: Principal.h:56
DelayedReader & productReader()
Definition: Principal.h:198
cet::exempt_ptr< Group const > getResolvedGroup(ProductID const pid, bool resolveProd) const
Definition: Principal.cc:452
void readImmediate() const
Definition: Principal.h:112
bool processHistoryModified_
Definition: Principal.h:277
const_iterator cend() const
Definition: Principal.h:174
void setProducedProducts(ProductTable const &producedProducts)
Definition: Principal.h:106
OutputHandle getForOutput(ProductID const, bool resolveProd) const
Definition: Principal.cc:424
const_iterator begin() const
Definition: Principal.h:156
intermediate_table::const_iterator const_iterator
size_t findGroups(ProcessLookup const &, SelectorBase const &, GroupQueryResultVec &results, bool stopIfProcessHasMatch, TypeID wanted_wrapper=TypeID{}) const
Definition: Principal.cc:355
void addToProcessHistory()
Definition: Principal.cc:80
BranchMapper const & branchMapper() const
Definition: Principal.h:144
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:53
std::string const & moduleLabel() const
GroupQueryResultVec getMatchingSequence(SelectorBase const &) const
Definition: Principal.cc:195
std::map< ProductID, std::shared_ptr< DeferredProductGetter const > > deferredGetters_
Definition: Principal.h:275
const_iterator end() const
Definition: Principal.h:168
GroupCollection::size_type size_type
Definition: Principal.h:55
void readProvenanceImmediate() const
Definition: Principal.h:123
virtual ProcessHistoryID const & processHistoryID() const =0
ProductID productID() const
virtual void fillGroup(BranchDescription const &)=0
std::vector< GroupQueryResult > GroupQueryResultVec
Definition: Principal.h:54
GroupQueryResultVec getMany(WrappedTypeID const &wrapped, SelectorBase const &) const
Definition: Principal.cc:178
BranchMapper & branchMapper()
Definition: Principal.h:192
void addSecondaryPrincipal(std::unique_ptr< Principal > &&val)
Definition: Principal.h:100
EDProductGetter const * productGetter(ProductID const pid) const
Definition: Principal.cc:532
int nextSecondaryFileIdx_
Definition: Principal.h:297
GroupQueryResultVec matchingSequenceFromInputFile(SelectorBase const &) const
Definition: Principal.cc:247
ProcessConfiguration const & processConfiguration_
Definition: Principal.h:270
cet::exempt_ptr< Group const > result() const
BranchType
Definition: BranchType.h:18
std::map< ProductID, std::unique_ptr< Group >> GroupCollection
Definition: Principal.h:51
ProcessHistory const & processHistory() const
Definition: Principal.h:132
EDProductGetter const * getEDProductGetterImpl(ProductID const pid) const final override
Definition: Principal.h:263
HLT enums.
virtual BranchType branchType() const =0
size_t findGroupsForProcess(std::vector< ProductID > const &vpid, SelectorBase const &selector, GroupQueryResultVec &results, TypeID wanted_wrapper) const
Definition: Principal.cc:377
std::string const & processName() const
EDProductGetter const * deferredGetter_(ProductID const pid) const
Definition: Principal.cc:412
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_
Definition: Principal.h:293
GroupQueryResult getByProductID(ProductID const pid) const
Definition: Principal.cc:131
GroupCollection::const_iterator const_iterator
Definition: Principal.h:52
std::string const & friendlyClassName() const
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:138
cet::exempt_ptr< Group const > getGroupForPtr(ProductID const pid) const
Definition: Principal.cc:481
GroupQueryResult getByLabel(WrappedTypeID const &wrapped, std::string const &label, std::string const &productInstanceName, std::string const &processName) const
Definition: Principal.cc:143
virtual void setProcessHistoryID(ProcessHistoryID const &)=0