LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
DataViewImpl.cc
Go to the documentation of this file.
2 
11 #include "cetlib/HorizontalRule.h"
12 #include "cetlib/container_algorithms.h"
13 
14 #include <algorithm>
15 
16 using namespace cet;
17 using namespace std;
18 
19 namespace art {
20 
21  DataViewImpl::DataViewImpl(Principal const& pcpl,
22  ModuleDescription const& md,
23  BranchType const branchType,
24  bool const recordParents,
25  cet::exempt_ptr<Consumer> consumer)
26  : principal_{pcpl}
27  , md_{md}
28  , branchType_{branchType}
29  , recordParents_{recordParents}
30  , consumer_{consumer}
31  {}
32 
33  size_t
35  {
36  return putProducts_.size() + principal_.size();
37  }
38 
41  SelectorBase const& sel) const
42  {
43  return principal_.getBySelector(wrapped, sel);
44  }
45 
48  {
49  return principal_.getByProductID(pid);
50  }
51 
54  SelectorBase const& sel) const
55  {
56  return principal_.getMany(wrapped, sel);
57  }
58 
61  string const& label,
62  string const& productInstanceName,
63  string const& processName) const
64  {
65  return principal_.getByLabel(
66  wrapped, label, productInstanceName, processName);
67  }
68 
71  string const& productInstanceName,
72  string const& processName) const
73  {
74  Selector const sel{ModuleLabelSelector{label} &&
75  ProductInstanceNameSelector{productInstanceName} &&
76  ProcessNameSelector{processName}};
77  return principal_.getMatchingSequence(sel);
78  }
79 
80  ProcessHistory const&
82  {
83  return principal_.processHistory();
84  }
85 
86  void
88  {
89  if (prov.productDescription().transient()) {
90  // If the product retrieved is transient, don't use its
91  // ProductID; use the ProductID's of its parents.
92  auto const& parents = prov.parents();
93  retrievedProducts_.insert(cbegin(parents), cend(parents));
94  } else {
95  retrievedProducts_.insert(prov.productID());
96  }
97  }
98 
101  {
102  std::vector<ProductID> result;
103  result.reserve(retrievedProducts_.size());
104  result.assign(cbegin(retrievedProducts_), cend(retrievedProducts_));
105  return result;
106  }
107 
108  void
109  DataViewImpl::checkPutProducts(bool const checkProducts,
110  std::set<TypeLabel> const& expectedProducts,
111  TypeLabelMap const& putProducts)
112  {
113  if (!checkProducts)
114  return;
115 
116  std::vector<std::string> missing;
117  for (auto const& typeLabel : expectedProducts) {
118  if (putProducts.find(typeLabel) != putProducts.cend())
119  continue;
120 
121  std::ostringstream desc;
122  desc << getProductDescription(typeLabel.typeID(),
123  typeLabel.productInstanceName());
124  missing.emplace_back(desc.str());
125  }
126 
127  if (!missing.empty()) {
128  std::ostringstream errmsg;
129  HorizontalRule rule{25};
130  errmsg << "The following products have been declared with 'produces',\n"
131  << "but they have not been placed onto the event:\n"
132  << rule('=') << '\n';
133  for (auto const& desc : missing) {
134  errmsg << desc << rule('=') << '\n';
135  }
136  throw Exception{errors::LogicError, "DataViewImpl::checkPutProducts"}
137  << errmsg.str();
138  }
139  }
140 
141  BranchDescription const&
143  string const& productInstanceName) const
144  {
145  return get_ProductDescription(type,
146  md_.processName(),
148  branchType_,
149  md_.moduleLabel(),
150  productInstanceName);
151  }
152 
153  void
154  DataViewImpl::removeNonViewableMatches_(TypeID const& requestedElementType,
155  GroupQueryResultVec& results) const
156  {
157  // To determine if the requested view is allowed, the matched
158  // 'results' (products) must be read.
159  auto not_convertible = [&requestedElementType](auto const& query_result) {
160  // Assns collections do not support views; we therefore do not
161  // need to worry about an exception throw when calling
162  // uniqueProduct.
163  auto group = query_result.result();
164  assert(group->productDescription().supportsView());
165  auto p = group->uniqueProduct();
166  return !detail::upcastAllowed(*p->typeInfo(),
167  requestedElementType.typeInfo());
168  };
169  results.erase(std::remove_if(begin(results), end(results), not_convertible),
170  end(results));
171  }
172 
173  void
174  DataViewImpl::ensureUniqueProduct_(std::size_t const nFound,
175  TypeID const& typeID,
176  std::string const& moduleLabel,
177  std::string const& productInstanceName,
178  std::string const& processName) const
179  {
180  if (nFound == 1)
181  return;
182 
184  e << "getView: Found "
185  << (nFound == 0 ? "no products" : "more than one product")
186  << " matching all criteria\n"
187  << "Looking for sequence of type: " << typeID << "\n"
188  << "Looking for module label: " << moduleLabel << "\n"
189  << "Looking for productInstanceName: " << productInstanceName << "\n";
190  if (!processName.empty())
191  e << "Looking for processName: " << processName << "\n";
192  throw e;
193  }
194 
195  void
197  {
199  }
200 
201 } // art
std::vector< ProductID > const & parents() const
Definition: Provenance.h:100
BranchDescription const & get_ProductDescription(BranchType branch_type, std::string const &module_label, std::string const &instance_name)
Principal const & principal_
Definition: DataViewImpl.h:276
void recordAsParent(Provenance const &prov) const
Definition: DataViewImpl.cc:87
void ensureUniqueProduct_(std::size_t nFound, TypeID const &typeID, std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName) const
GroupQueryResult get_(WrappedTypeID const &wrapped, SelectorBase const &) const
Definition: DataViewImpl.cc:40
void removeCachedProduct(ProductID const pid) const
Definition: Principal.cc:259
ProcessHistory const & processHistory() const
Definition: DataViewImpl.cc:81
STL namespace.
GroupQueryResult getBySelector(WrappedTypeID const &wrapped, SelectorBase const &) const
Definition: Principal.cc:110
size_t size() const
Definition: Principal.h:150
BranchDescription const & getProductDescription(TypeID const &type, std::string const &productInstanceName) const
BranchType const branchType_
Definition: DataViewImpl.h:283
cet::exempt_ptr< Consumer > consumer_
Definition: DataViewImpl.h:291
ProductID const & productID() const
Definition: Provenance.h:113
static ProductMetaData const & instance()
void removeNonViewableMatches_(TypeID const &requestedElementType, GroupQueryResultVec &results) const
std::map< TypeLabel, PMValue > TypeLabelMap
Definition: DataViewImpl.h:177
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
std::vector< ProductID > RetrievedProductIDs
Definition: DataViewImpl.h:175
GroupQueryResultVec getMatchingSequence(SelectorBase const &) const
Definition: Principal.cc:195
std::type_info const & typeInfo() const
Definition: TypeID.h:114
ModuleDescription const & md_
Definition: DataViewImpl.h:280
std::string const & processName() const
GroupQueryResult getByProductID_(ProductID const pid) const
Definition: DataViewImpl.cc:47
GroupQueryResult getByLabel_(WrappedTypeID const &wrapped, std::string const &label, std::string const &productInstanceName, std::string const &processName) const
Definition: DataViewImpl.cc:60
GroupQueryResultVec getMany(WrappedTypeID const &wrapped, SelectorBase const &) const
Definition: Principal.cc:178
GroupQueryResultVec getMany_(WrappedTypeID const &wrapped, SelectorBase const &sel) const
Definition: DataViewImpl.cc:53
std::string const & moduleLabel() const
GroupQueryResultVec getMatchingSequenceByLabel_(std::string const &label, std::string const &productInstanceName, std::string const &processName) const
Definition: DataViewImpl.cc:70
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
ProductList const & productList() const
std::vector< GroupQueryResult > GroupQueryResultVec
Definition: DataViewImpl.h:214
void removeCachedProduct_(ProductID const pid) const
RetrievedProductSet retrievedProducts_
Definition: DataViewImpl.h:272
BranchType
Definition: BranchType.h:18
TypeLabelMap & putProducts()
Definition: DataViewImpl.h:183
ProcessHistory const & processHistory() const
Definition: Principal.h:132
HLT enums.
RetrievedProductIDs retrievedProductIDs() const
bool upcastAllowed(std::type_info const &tiFrom, std::type_info const &tiTo)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
BranchDescription const & productDescription() const
Definition: Provenance.h:46
TypeLabelMap putProducts_
Definition: DataViewImpl.h:266
void checkPutProducts(bool checkProducts, std::set< TypeLabel > const &expectedProducts, TypeLabelMap const &putProducts)
GroupQueryResult getByProductID(ProductID const pid) const
Definition: Principal.cc:131
Float_t e
Definition: plot.C:34
size_t size() const
Definition: DataViewImpl.cc:34
GroupQueryResult getByLabel(WrappedTypeID const &wrapped, std::string const &label, std::string const &productInstanceName, std::string const &processName) const
Definition: Principal.cc:143
bool const recordParents_
Definition: DataViewImpl.h:286