CMS 3D CMS Logo

OtherThingAlgorithm.cc
Go to the documentation of this file.
1 #include "OtherThingAlgorithm.h"
3 #include "DataFormats/TestObjects/interface/OtherThing.h"
6 
7 namespace edmtest {
9  OtherThingCollection& result,
10  bool useRefs,
11  bool refsAreTransient) const {
12  const size_t numToMake = 20;
13  result.reserve(numToMake);
14  ThingCollection const* null = nullptr;
15  ThingCollection const* parent = nullptr;
16  if (useRefs) {
17  parent = parentHandle.product();
18  }
19  for (size_t i = 0; i < numToMake; ++i) {
20  OtherThing element;
21  if (!useRefs) {
22  element.a = i;
23  } else if (refsAreTransient) {
24  element.a = i;
25  element.refProd = edm::RefProd<ThingCollection>(parent);
26  element.ref = edm::Ref<ThingCollection>(element.refProd, i);
27  element.refVec.push_back(element.ref);
28  element.refVec.push_back(element.ref);
29  element.refVec.push_back(edm::Ref<ThingCollection>(parent, 19 - i));
30  edm::RefVector<ThingCollection>::iterator ri = element.refVec.begin();
31  element.refVec.erase(ri);
32  element.oneNullOneNot.push_back(edm::Ref<ThingCollection>(null, 0));
33  element.oneNullOneNot.push_back(edm::Ref<ThingCollection>(parent, 0));
34  assert(element.oneNullOneNot.size() == 2); // we'll check this in our tests
35  element.ptr = edm::Ptr<Thing>(&parent->at(i), i);
36  assert(element.ptr == edm::refToPtr(element.ref));
37  element.ptrVec.push_back(element.ptr);
38  element.ptrVec.push_back(edm::Ptr<Thing>(&parent->at(19 - i), 19 - i));
39  element.ptrOneNullOneNot.push_back(edm::Ptr<Thing>(nullptr, 0ul));
40  element.ptrOneNullOneNot.push_back(edm::Ptr<Thing>(&parent->at(0), 0ul));
41  assert(element.ptrOneNullOneNot.size() == 2); // we'll check this in our tests
44  element.refToBaseProd = edm::RefToBaseProd<Thing>(refProd);
45  element.refToBase = edm::RefToBase<Thing>(ref);
46  } else {
47  element.a = i;
48  element.refProd = edm::RefProd<ThingCollection>(parentHandle);
49  element.ref = edm::Ref<ThingCollection>(element.refProd, i);
50  element.refVec.push_back(element.ref);
51  element.refVec.push_back(element.ref);
52  element.refVec.push_back(edm::Ref<ThingCollection>(parentHandle, 19 - i));
53  edm::RefVector<ThingCollection>::iterator ri = element.refVec.begin();
54  element.refVec.erase(ri);
55  element.oneNullOneNot.push_back(edm::Ref<ThingCollection>(parentHandle.id()));
56  element.oneNullOneNot.push_back(edm::Ref<ThingCollection>(parentHandle, 0));
57  assert(element.oneNullOneNot.size() == 2); // we'll check this in our tests
58  element.ptr = edm::Ptr<Thing>(parentHandle, i);
59  assert(element.ptr == edm::refToPtr(element.ref));
60  element.ptrVec.push_back(element.ptr);
61  element.ptrVec.push_back(edm::Ptr<Thing>(parentHandle, 19 - i));
62  element.ptrOneNullOneNot.push_back(edm::Ptr<Thing>(parentHandle.id()));
63  element.ptrOneNullOneNot.push_back(edm::Ptr<Thing>(parentHandle, 0));
64  assert(element.ptrOneNullOneNot.size() == 2); // we'll check this in our tests
67  element.refToBaseProd = edm::RefToBaseProd<Thing>(element.refProd);
68  element.refToBase = edm::RefToBase<Thing>(element.ref);
69  }
70  result.push_back(element);
71  // element.refVec.clear(); // no need to clear; 'element' is created anew on every loop
72  }
73  }
74 } // namespace edmtest
Ptr< typename C::value_type > refToPtr(Ref< C, typename C::value_type, refhelper::FindUsingAdvance< C, typename C::value_type > > const &ref)
Definition: RefToPtr.h:18
ProductID id() const
Definition: HandleBase.cc:29
void run(edm::Handle< ThingCollection > const &iThingHandle, OtherThingCollection &otherThingCollection, bool useRefs=true, bool refsAreTransient=false) const
ProductID id() const
Accessor for product ID.
Definition: Ptr.h:158
T const * product() const
Definition: Handle.h:70
assert(be >=bs)