KeptProvenance.cc
Go to the documentation of this file.
2 // vim: set sw=2 expandtab :
3 
6 
7 #include <set>
8 #include <vector>
9 
10 using namespace std;
11 
12 namespace art {
13  namespace detail {
14 
15  KeptProvenance::~KeptProvenance() = default;
16 
17  KeptProvenance::KeptProvenance(DropMetaData const dropMetaData,
18  bool const dropMetaDataForDroppedData,
19  set<ProductID>& branchesWithStoredHistory)
20  : dropMetaData_{dropMetaData}
21  , dropMetaDataForDroppedData_{dropMetaDataForDroppedData}
22  , branchesWithStoredHistory_{branchesWithStoredHistory}
23  {}
24 
25  ProductProvenance const&
27  {
28  return *provenance_.insert(pp).first;
29  }
30 
31  ProductProvenance const&
33  {
34  return *provenance_.emplace(pid, status).first;
35  }
36 
37  void
39  Principal const& principal)
40  {
41  vector<ProductProvenance const*> stacked_pp;
42  stacked_pp.push_back(&pp);
43  while (1) {
44  if (stacked_pp.size() == 0) {
45  break;
46  }
47  ProductProvenance const* current_pp = stacked_pp.back();
48  stacked_pp.pop_back();
49  for (auto const parent_pid : current_pp->parentage().parents()) {
50  auto parent_pp =
51  principal.branchMapper().branchToProductProvenance(parent_pid);
52  if (!parent_pp || (dropMetaData_ != DropMetaData::DropNone)) {
53  continue;
54  }
55 
56  // These two data structures should be in sync.
57  branchesWithStoredHistory_.insert(parent_pid);
58  provenance_.insert(*parent_pp);
59 
60  auto const* parent_bd =
61  principal.getForOutput(parent_pp->productID(), false).desc();
62 
63  if (!parent_bd) {
64  // FIXME: Is this an error condition?
65  continue;
66  }
67  if (!parent_bd->produced()) {
68  // We got it from the input, nothing to do.
69  continue;
70  }
73  stacked_pp.push_back(parent_pp.get());
74  }
75  }
76  }
77  }
78 
79  void
81  ProductStatus const status)
82  {
83  if (provenance_.erase(key) != 1ull) {
84  throw Exception(errors::LogicError, "KeptProvenance::setStatus")
85  << "Attempt to set product status for product whose provenance is "
86  "not "
87  "being recorded.\n";
88  }
89  provenance_.emplace(key.productID(), status);
90  }
91 
92  } // namespace detail
93 } // namespace art
ProductID const & productID() const
void setStatus(ProductProvenance const &, ProductStatus)
ProductProvenance const & insert(ProductProvenance const &)
DropMetaData const dropMetaData_
std::vector< ProductID > const & parents() const
Definition: Parentage.cc:51
STL namespace.
unsigned char ProductStatus
Definition: ProductStatus.h:12
bool const dropMetaDataForDroppedData_
Parentage const & parentage() const
OutputHandle getForOutput(ProductID const &, bool resolveProd) const
Definition: Principal.cc:1087
std::set< ProductProvenance > provenance_
void insertAncestors(ProductProvenance const &iGetParents, Principal const &principal)
ProductProvenance const & emplace(ProductID, ProductStatus)
cet::exempt_ptr< ProductProvenance const > branchToProductProvenance(ProductID const &) const
Definition: Principal.cc:505
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::set< ProductID > & branchesWithStoredHistory_