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>>;
52  using const_iterator = GroupCollection::const_iterator;
54  using GroupQueryResultVec = std::vector<GroupQueryResult>;
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
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  virtual bool parentageEnabled() const = 0;
191 
192  virtual bool rangesEnabled() const = 0;
193 
194  protected: // MEMBER FUNCTIONS
195  BranchMapper&
197  {
198  return *branchMapperPtr_;
199  }
200 
203  {
204  return *store_;
205  }
206 
207  // We take ownership of the Group, which in turn owns its data.
208  void
209  fillGroup(std::unique_ptr<Group>&& group)
210  {
211  BranchDescription const& pd = group->productDescription();
212  assert(!pd.producedClassName().empty());
213  assert(!pd.friendlyClassName().empty());
214  assert(!pd.moduleLabel().empty());
215  assert(!pd.processName().empty());
216  group->setResolvers(branchMapper(), *store_);
217  groups_[pd.productID()] = std::move(group);
218  }
219 
220  int tryNextSecondaryFile() const;
221 
223 
225 
227  bool resolveProd) const;
228 
229  private: // MEMBER FUNCTIONS
230  virtual ProcessHistoryID const& processHistoryID() const = 0;
231 
232  virtual void setProcessHistoryID(ProcessHistoryID const&) = 0;
233 
235  SelectorBase const&) const;
236 
238  SelectorBase const&,
239  bool stopIfProcessHasMatch) const;
240 
241  size_t findGroupsFromInputFile(WrappedTypeID const& wrapped,
242  SelectorBase const&,
244  bool stopIfProcessHasMatch) const;
245 
246  size_t findGroups(ProcessLookup const&,
247  SelectorBase const&,
248  GroupQueryResultVec& results,
249  bool stopIfProcessHasMatch,
250  TypeID wanted_wrapper = TypeID{}) const;
251 
252  size_t findGroupsForProcess(std::vector<ProductID> const& vpid,
253  SelectorBase const& selector,
254  GroupQueryResultVec& results,
255  TypeID wanted_wrapper) const;
256 
257  bool presentFromSource(ProductID) const;
258 
259  private: // MEMBER DATA
260  // This function and its associated member datum are required to
261  // handle the lifetime of a deferred getter, which in turn is
262  // required because a group does not exist until it is placed in
263  // the event.
264  EDProductGetter const* deferredGetter_(ProductID const pid) const;
265 
266  EDProductGetter const*
267  getEDProductGetterImpl(ProductID const pid) const final override
268  {
269  return getByProductID(pid).result().get();
270  }
271 
276 
280 
281  mutable std::map<ProductID, std::shared_ptr<DeferredProductGetter const>>
283 
284  mutable bool processHistoryModified_{false};
285 
286  // Products and provenances are persistent.
288 
289  // Pointer to the mapper that will get provenance information from
290  // the persistent store.
291  std::unique_ptr<BranchMapper> branchMapperPtr_;
292 
293  // Pointer to the reader that will be used to obtain EDProducts
294  // from the persistent store.
295  std::unique_ptr<DelayedReader> store_;
296 
297  // Secondary principals. Note that the lifetime of run and subRun
298  // principals is the lifetime of the input file, while the
299  // lifetime of event principals ends at the next event read.
300  std::vector<std::unique_ptr<Principal>> secondaryPrincipals_{};
301 
302  // Index into the secondary file names vector of the next file
303  // that a secondary principal should be created from.
304  mutable int nextSecondaryFileIdx_{};
305  };
306 
307 } // namespace art
308 
309 // Local Variables:
310 // mode: c++
311 // End:
312 #endif /* art_Framework_Principal_Principal_h */
cet::exempt_ptr< ProductTable const > presentProducts_
Definition: Principal.h:278
virtual ~Principal() noexcept=default
std::unique_ptr< BranchMapper > branchMapperPtr_
Definition: Principal.h:291
std::map< std::string, std::vector< ProductID >> ProcessLookup
Definition: type_aliases.h:15
void fillGroup(std::unique_ptr< Group > &&group)
Definition: Principal.h:209
GroupCollection groups_
Definition: Principal.h:287
const_iterator cbegin() const
Definition: Principal.h:162
ProcessHistory processHistory_
Definition: Principal.h:272
size_t findGroups(ProcessLookup const &, SelectorBase const &, GroupQueryResultVec &results, bool stopIfProcessHasMatch, TypeID wanted_wrapper=TypeID{}) const
OutputHandle getForOutput(ProductID const, bool resolveProd) const
void addToProcessHistory()
cet::exempt_ptr< ProductTable const > producedProducts_
Definition: Principal.h:279
std::string const & producedClassName() const
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:295
std::string ProcessName
Definition: Principal.h:56
DelayedReader & productReader()
Definition: Principal.h:202
const char * label
GroupQueryResult getBySelector(WrappedTypeID const &wrapped, SelectorBase const &) const
static ProcessHistory previousProcessHistory_
Definition: Principal.h:273
void readImmediate() const
Definition: Principal.h:112
bool processHistoryModified_
Definition: Principal.h:284
size_t findGroupsFromInputFile(WrappedTypeID const &wrapped, SelectorBase const &, GroupQueryResultVec &results, bool stopIfProcessHasMatch) const
GroupQueryResult getByLabel(WrappedTypeID const &wrapped, std::string const &label, std::string const &productInstanceName, std::string const &processName) const
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Definition: typedefs.hpp:11
const_iterator cend() const
Definition: Principal.h:174
void setProducedProducts(ProductTable const &producedProducts)
Definition: Principal.h:106
bool presentFromSource(ProductID) const
const_iterator begin() const
Definition: Principal.h:156
BranchMapper const & branchMapper() const
Definition: Principal.h:144
exempt_ptr< E > make_exempt_ptr(E *) noexcept
ProcessHistory::const_iterator ProcessNameConstIterator
Definition: Principal.h:53
std::string const & moduleLabel() const
void removeCachedProduct(ProductID const pid) const
int tryNextSecondaryFile() const
virtual bool parentageEnabled() const =0
std::map< ProductID, std::shared_ptr< DeferredProductGetter const > > deferredGetters_
Definition: Principal.h:282
const_iterator end() const
Definition: Principal.h:168
GroupCollection::size_type size_type
Definition: Principal.h:55
GroupQueryResultVec getMatchingSequence(SelectorBase const &) const
void readProvenanceImmediate() const
Definition: Principal.h:123
virtual ProcessHistoryID const & processHistoryID() const =0
cet::exempt_ptr< Group const > getResolvedGroup(ProductID const pid, bool resolveProd) const
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
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
virtual bool rangesEnabled() const =0
GroupQueryResultVec matchingSequenceFromInputFile(SelectorBase const &) const
BranchMapper & branchMapper()
Definition: Principal.h:196
void addSecondaryPrincipal(std::unique_ptr< Principal > &&val)
Definition: Principal.h:100
size_t findGroupsForProcess(std::vector< ProductID > const &vpid, SelectorBase const &selector, GroupQueryResultVec &results, TypeID wanted_wrapper) const
EDProductGetter const * deferredGetter_(ProductID const pid) const
int nextSecondaryFileIdx_
Definition: Principal.h:304
static ProcessHistory pendingProcessHistory_
Definition: Principal.h:274
cet::exempt_ptr< Group const > getGroup(ProductID const pid) const
ProcessConfiguration const & processConfiguration_
Definition: Principal.h:277
cet::exempt_ptr< Group const > result() const
BranchType
Definition: BranchType.h:18
assert(nhit_max >=nhit_nbins)
std::map< ProductID, std::unique_ptr< Group >> GroupCollection
Definition: Principal.h:51
static int pendingProcessHistorySet_
Definition: Principal.h:275
ProcessHistory const & processHistory() const
Definition: Principal.h:132
EDProductGetter const * getEDProductGetterImpl(ProductID const pid) const final override
Definition: Principal.h:267
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
virtual BranchType branchType() const =0
std::string const & processName() const
cet::exempt_ptr< Group const > getGroupForPtr(ProductID const pid) const
GroupQueryResult getByProductID(ProductID const pid) const
std::vector< std::unique_ptr< Principal > > secondaryPrincipals_
Definition: Principal.h:300
GroupCollection::const_iterator const_iterator
Definition: Principal.h:52
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData
EDProductGetter const * productGetter(ProductID const pid) const
GroupQueryResultVec findGroupsForProduct(WrappedTypeID const &wrapped, SelectorBase const &, bool stopIfProcessHasMatch) const
std::string const & friendlyClassName() const
ProcessConfiguration const & processConfiguration() const
Definition: Principal.h:138
virtual void setProcessHistoryID(ProcessHistoryID const &)=0