17 #include "canvas/Persistency/Common/FindMany.h" 18 #include "canvas/Persistency/Common/FindManyP.h" 19 #include "canvas/Persistency/Common/FindOne.h" 20 #include "canvas/Persistency/Common/FindOneP.h" 26 #include "boost/type_traits.hpp" 28 #include <initializer_list> 30 #include <type_traits> 57 template <
template <
typename,
typename>
class FO>
60 template <
template <
typename,
typename>
class FM>
75 template <
class R,
class W>
79 template <
typename T,
template <
typename>
class WRAP>
80 std::enable_if_t<boost::has_dereference<WRAP<T>>
::value,
T const&>
87 template <
typename T,
template <
typename>
class WRAP>
96 char const*
const X[] = {
"zero",
"one",
"two"};
97 char const*
const A[] = {
"A",
"B",
"C"};
98 size_t const AI[] = {2, 0, 1};
99 size_t const BI[] = {1, 2, 0};
103 template <
typename I,
typename D,
typename F,
typename FV>
105 check_get_one_impl(F
const& fA, FV
const& fAV)
109 for (
size_t i = 0;
i < 3; ++
i) {
110 fA.get(
i, item, data);
129 template <
typename T,
typename D,
template <
typename,
typename>
class FO>
130 std::enable_if_t<std::is_same<FO<T, void>, art::FindOne<T, void>>::value>
131 check_get(FO<T, D>
const& fA, FO<T, void>
const& fAV)
135 check_get_one_impl<item_t, data_t>(fA, fAV);
139 template <
typename T,
typename D,
template <
typename,
typename>
class FO>
140 std::enable_if_t<std::is_same<FO<T, void>, art::FindOneP<T, void>>::value>
141 check_get(FO<T, D>
const& fA, FO<T, void>
const& fAV)
145 check_get_one_impl<item_t, data_t>(fA, fAV);
149 template <
typename T,
typename D,
template <
typename,
typename>
class FM>
150 std::enable_if_t<std::is_same<FM<T, void>, art::FindMany<T, void>>::value ||
151 std::is_same<FM<T, void>, art::FindManyP<T, void>>::value>
152 check_get(FM<T, D>
const& fA, FM<T, void>
const& fAV)
154 typename FM<T, void>::value_type item;
155 typename FM<T, D>::dataColl_t::value_type data;
156 BOOST_CHECK_EQUAL((fAV.get(0ul, item)), 1ul);
157 BOOST_CHECK_EQUAL((fAV.get(1ul, item)), 2ul);
158 BOOST_CHECK_EQUAL((fAV.get(2ul, item)), 1ul);
159 BOOST_CHECK_EQUAL((fA.get(0ul, item, data)), 1ul);
160 BOOST_CHECK_EQUAL((fA.get(1ul, item, data)), 2ul);
161 BOOST_CHECK_EQUAL((fA.get(2ul, item, data)), 1ul);
181 consumes<AssnsAB_t>(
"noModule");
189 testOne<art::FindOne>(
e);
190 testOne<art::FindOneP>(
e);
192 testMany<art::FindMany>(
e);
193 testMany<art::FindManyP>(
e);
196 template <
template <
typename,
typename =
void>
class FO>
201 static constexpr
bool isFOP =
202 std::is_same<typename FO<B_t>::value_type,
211 BOOST_REQUIRE_EQUAL(hAB->
size(), 3ul);
213 BOOST_REQUIRE_EQUAL(hABV->
size(), 3ul);
215 BOOST_CHECK_THROW((*hAB).at(3), std::out_of_range);
216 BOOST_CHECK_EQUAL(&(*hAB).data(0), &(*hAB).data((*hAB).begin()));
217 BOOST_CHECK_THROW((*hAB).data(3), std::out_of_range);
221 BOOST_REQUIRE_EQUAL(hBA->
size(), 3ul);
223 BOOST_REQUIRE_EQUAL(hBAV->
size(), 3ul);
225 BOOST_CHECK_THROW((*hBA).at(3), std::out_of_range);
226 BOOST_CHECK_EQUAL(&(*hBA).data(0), &(*hBA).data((*hBA).begin()));
227 BOOST_CHECK_THROW((*hBA).data(3), std::out_of_range);
235 FO<B_t, arttest::AssnTestData> foDead(hAcoll, e,
"noModule");
237 BOOST_REQUIRE_EXCEPTION(
240 e.
history().back() ==
"ProductNotFound";
242 BOOST_REQUIRE_EXCEPTION(
245 e.
history().back() ==
"ProductNotFound";
251 std::unique_ptr<FO<A_t, arttest::AssnTestData>> foA;
252 std::unique_ptr<FO<A_t>> foAV;
254 foA.reset(
new FO<A_t, arttest::AssnTestData>{hBcoll,
e,
inputLabel_});
257 if (extendedTestsOK) {
258 FO<B_t, arttest::AssnTestData> foB(hAcoll, e,
inputLabel_);
259 FO<B_t, arttest::AssnTestData> foB2(vhAcoll, e,
inputLabel_);
261 std::vector<art::Ptr<A_t>> vp;
263 for (
size_t i = 0;
i < 3; ++
i) {
264 vp.emplace_back(hAcoll,
i);
266 BOOST_CHECK_EQUAL(*(*hAB)[
i].first,
i);
270 BOOST_CHECK_EQUAL((*hAB).data(
i).d1, (*hAB)[
i].first.key());
271 BOOST_CHECK_EQUAL((*hAB).data(
i).d2, (*hAB)[
i].second.key());
273 BOOST_CHECK_EQUAL(*(*hABV)[i].first, i);
282 BOOST_CHECK_EQUAL(*(*hBA)[
i].
second,
i);
283 BOOST_CHECK_EQUAL((*hBA).data(
i).d2, (*hBA)[
i].first.key());
284 BOOST_CHECK_EQUAL((*hBA).data(
i).d1, (*hBA)[
i].second.key());
287 BOOST_CHECK_EQUAL(*(*hBAV)[i].first,
std::string(X[i]));
289 BOOST_CHECK_EQUAL(*(*hBAV)[i].second, i);
292 BOOST_CHECK(!foBV.at(
i));
296 BOOST_CHECK_EQUAL(
dereference(foA->data(i)).d1, AI[i]);
297 BOOST_CHECK_EQUAL(
dereference(foA->data(i)).d2, i);
298 BOOST_CHECK_EQUAL(
dereference(foAV->at(i)), BI[i]);
299 BOOST_CHECK_NO_THROW(check_get(*foA, *foAV));
301 for (
auto const&
f : {foB, foB2}) {
312 FO<B_t, arttest::AssnTestData> foBv(va, e,
inputLabel_);
315 std::unique_ptr<FO<A_t, arttest::AssnTestData>> foAv;
318 foAv.reset(
new FO<A_t, arttest::AssnTestData>{vb,
e,
inputLabel_});
322 auto va2 = va.
vals();
325 swap(*va2.begin(), *(va2.begin() + 1));
326 swap(*va2.begin(), *(va2.begin() + 2));
329 FO<B_t, arttest::AssnTestData> foBv2(va2, e,
inputLabel_);
330 for (
size_t i = 0, e = foBv2.size();
i !=
e; ++
i) {
332 auto it = find(va.
begin(), va.
end(), va2[
i]);
340 FO<B_t, arttest::AssnTestData> foBpv(pva, e,
inputLabel_);
341 BOOST_CHECK_EQUAL(foBpv.at(0), foB.at(0));
342 BOOST_CHECK_EQUAL(foBpv.data(0), foB.data(0));
343 BOOST_CHECK_EQUAL(foBpv.at(1), foB.at(2));
344 BOOST_CHECK_EQUAL(foBpv.data(1), foB.data(2));
350 FO<A_t, arttest::AssnTestData> foApv(pvb, e,
inputLabel_);
352 BOOST_CHECK_THROW(foApv.at(3), std::out_of_range);
353 BOOST_CHECK_THROW(foApv.data(3), std::out_of_range);
356 BOOST_CHECK_EQUAL(foApv.at(0), foA->at(0));
357 BOOST_CHECK_EQUAL(foApv.data(0), foA->data(0));
358 BOOST_CHECK_EQUAL(foApv.at(1), foA->at(2));
359 BOOST_CHECK_EQUAL(foApv.data(1), foA->data(2));
364 FO<B_t, arttest::AssnTestData> foBmv(hAcoll, e,
mapVecToken1_);
380 FO<A_t, arttest::AssnTestData> foAmvv(vmvb, e,
mapVecToken2_);
381 for (std::size_t
i = 0ul, sz = foAmvv.size();
i != sz; ++
i) {
388 template <
template <
typename,
typename =
void>
class FM>
392 static constexpr
bool isFMP[[gnu::unused]] =
393 std::is_same<typename FM<B_t>::value_type,
400 FM<B_t, arttest::AssnTestData> fmDead(hAcoll, e,
"noModule");
402 BOOST_REQUIRE_EXCEPTION(
405 e.
history().back() ==
"ProductNotFound";
407 BOOST_REQUIRE_EXCEPTION(
410 e.
history().back() ==
"ProductNotFound";
415 FM<B_t, arttest::AssnTestData> fmB(
417 art::Ptr<A_t> larry(hAcoll, 0), curly(hAcoll, 1), mo(hAcoll, 2);
418 FM<B_t, arttest::AssnTestData> fmB2(
420 for (
auto const&
f : {fmB, fmB2}) {
421 BOOST_REQUIRE_EQUAL(
f.size(), 3ul);
422 BOOST_CHECK_EQUAL(
f.at(0).size(), 1ul);
423 BOOST_CHECK_EQUAL(
f.at(1).size(), 2ul);
424 BOOST_CHECK_EQUAL(
f.at(2).size(), 1ul);
425 BOOST_CHECK_EQUAL(
f.data(0).size(), 1ul);
426 BOOST_CHECK_EQUAL(
f.data(1).size(), 2ul);
427 BOOST_CHECK_EQUAL(
f.data(2).size(), 1ul);
430 BOOST_CHECK_EQUAL(fmBV.at(0).size(), 1ul);
431 BOOST_CHECK_EQUAL(fmBV.at(1).size(), 2ul);
432 BOOST_CHECK_EQUAL(fmBV.at(2).size(), 1ul);
433 BOOST_CHECK_NO_THROW(check_get(fmB, fmBV));
440 auto va2 = va.
vals();
443 swap(*va2.begin(), *(va2.begin() + 1));
444 swap(*va2.begin(), *(va2.begin() + 2));
448 for (
size_t i = 0, e = fmBv2.size();
i !=
e; ++
i) {
450 auto it = find(va.
begin(), va.
end(), va2[
i]);
458 BOOST_CHECK_EQUAL(fmvBV.at(0).size(), 1ul);
459 BOOST_CHECK_EQUAL(fmvBV.at(1).size(), 2ul);
460 BOOST_CHECK_EQUAL(fmvBV.at(2).size(), 1ul);
461 BOOST_CHECK_NO_THROW(check_get(fmB, fmBV));
static const double second
art::Assns< B_t, size_t, arttest::AssnTestData > AssnsBA_t
void analyze(art::Event const &e) override
fhicl::Atom< bool > bCollMissing
art::Assns< A_t, B_t, arttest::AssnTestData > AssnsAB_t
art::Assns< A_t, B_t > AssnsABV_t
AssnsAnalyzer(Parameters const &p)
EDAnalyzer(fhicl::ParameterSet const &pset)
void fill(PtrVector< T > &pv) const
fhicl::Atom< std::string > input_label
details::dereference_class< T, details::has_dereference_class< T >::value >::reference_type dereference(T &v)
Returns the value pointed by the argument, or the argument itself.
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
#define DEFINE_ART_MODULE(klass)
History const & history() const
void swap(Handle< T > &a, Handle< T > &b)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
art::ProductToken< AssnsBA_t > mapVecToken2_
void testMany(art::Event const &e) const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
art::ProductToken< AssnsAB_t > mapVecToken1_
std::size_t getView(std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName, std::vector< ELEMENT const * > &result) const
void testOne(art::Event const &e) const
art::Assns< B_t, size_t > AssnsBAV_t
fhicl::Atom< bool > test_BA
fhicl::Atom< bool > test_AB