Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:29

0001 #include "FWCore/Integration/test/OtherThingAlgorithm.h"
0002 #include "FWCore/Framework/interface/Event.h"
0003 #include "DataFormats/TestObjects/interface/OtherThing.h"
0004 #include "DataFormats/Common/interface/Handle.h"
0005 #include "DataFormats/Common/interface/RefToPtr.h"
0006 
0007 namespace edmtest {
0008   void OtherThingAlgorithm::run(edm::Handle<ThingCollection> const& parentHandle,
0009                                 OtherThingCollection& result,
0010                                 bool useRefs,
0011                                 bool refsAreTransient) const {
0012     const size_t numToMake = 20;
0013     result.reserve(numToMake);
0014     ThingCollection const* null = 0;
0015     ThingCollection const* parent = nullptr;
0016     if (useRefs) {
0017       parent = parentHandle.product();
0018     }
0019     for (size_t i = 0; i < numToMake; ++i) {
0020       OtherThing element;
0021       if (!useRefs) {
0022         element.a = i;
0023       } else if (refsAreTransient) {
0024         element.a = i;
0025         element.refProd = edm::RefProd<ThingCollection>(parent);
0026         element.ref = edm::Ref<ThingCollection>(element.refProd, i);
0027         element.refVec.push_back(element.ref);
0028         element.refVec.push_back(element.ref);
0029         element.refVec.push_back(edm::Ref<ThingCollection>(parent, 19 - i));
0030         edm::RefVector<ThingCollection>::iterator ri = element.refVec.begin();
0031         element.refVec.erase(ri);
0032         element.oneNullOneNot.push_back(edm::Ref<ThingCollection>(null, 0));
0033         element.oneNullOneNot.push_back(edm::Ref<ThingCollection>(parent, 0));
0034         assert(element.oneNullOneNot.size() == 2);  // we'll check this in our tests
0035         element.ptr = edm::Ptr<Thing>(&parent->at(i), i);
0036         assert(element.ptr == edm::refToPtr(element.ref));
0037         element.ptrVec.push_back(element.ptr);
0038         element.ptrVec.push_back(edm::Ptr<Thing>(&parent->at(19 - i), 19 - i));
0039         element.ptrOneNullOneNot.push_back(edm::Ptr<Thing>(nullptr, 0ul));
0040         element.ptrOneNullOneNot.push_back(edm::Ptr<Thing>(&parent->at(0), 0ul));
0041         assert(element.ptrOneNullOneNot.size() == 2);  // we'll check this in our tests
0042         edm::RefProd<ThingCollection> refProd = edm::RefProd<ThingCollection>(parentHandle);
0043         edm::Ref<ThingCollection> ref = edm::Ref<ThingCollection>(refProd, i);
0044         element.refToBaseProd = edm::RefToBaseProd<Thing>(refProd);
0045         element.refToBase = edm::RefToBase<Thing>(ref);
0046       } else {
0047         element.a = i;
0048         element.refProd = edm::RefProd<ThingCollection>(parentHandle);
0049         element.ref = edm::Ref<ThingCollection>(element.refProd, i);
0050         element.refVec.push_back(element.ref);
0051         element.refVec.push_back(element.ref);
0052         element.refVec.push_back(edm::Ref<ThingCollection>(parentHandle, 19 - i));
0053         edm::RefVector<ThingCollection>::iterator ri = element.refVec.begin();
0054         element.refVec.erase(ri);
0055         element.oneNullOneNot.push_back(edm::Ref<ThingCollection>(parentHandle.id()));
0056         element.oneNullOneNot.push_back(edm::Ref<ThingCollection>(parentHandle, 0));
0057         assert(element.oneNullOneNot.size() == 2);  // we'll check this in our tests
0058         element.ptr = edm::Ptr<Thing>(parentHandle, i);
0059         assert(element.ptr == edm::refToPtr(element.ref));
0060         element.ptrVec.push_back(element.ptr);
0061         element.ptrVec.push_back(edm::Ptr<Thing>(parentHandle, 19 - i));
0062         element.ptrOneNullOneNot.push_back(edm::Ptr<Thing>(parentHandle.id()));
0063         element.ptrOneNullOneNot.push_back(edm::Ptr<Thing>(parentHandle, 0));
0064         assert(element.ptrOneNullOneNot.size() == 2);  // we'll check this in our tests
0065         edm::RefProd<ThingCollection> refProd = edm::RefProd<ThingCollection>(parentHandle);
0066         edm::Ref<ThingCollection> ref = edm::Ref<ThingCollection>(refProd, i);
0067         element.refToBaseProd = edm::RefToBaseProd<Thing>(element.refProd);
0068         element.refToBase = edm::RefToBase<Thing>(element.ref);
0069       }
0070       result.push_back(element);
0071       //      element.refVec.clear(); // no need to clear; 'element' is created anew on every loop
0072     }
0073   }
0074 }  // namespace edmtest