Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-23 03:25:08

0001 /*----------------------------------------------------------------------
0002 
0003 Test program for edm::Event.
0004 
0005 ----------------------------------------------------------------------*/
0006 
0007 #include "DataFormats/Common/interface/Handle.h"
0008 #include "DataFormats/Common/interface/OrphanHandle.h"
0009 #include "DataFormats/Common/interface/Wrapper.h"
0010 #include "DataFormats/Provenance/interface/BranchDescription.h"
0011 #include "DataFormats/Provenance/interface/BranchIDListHelper.h"
0012 #include "DataFormats/Provenance/interface/EventAuxiliary.h"
0013 #include "DataFormats/Provenance/interface/EventID.h"
0014 #include "DataFormats/Provenance/interface/LuminosityBlockAuxiliary.h"
0015 #include "DataFormats/Provenance/interface/ModuleDescription.h"
0016 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0017 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
0018 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0019 #include "DataFormats/Provenance/interface/RunAuxiliary.h"
0020 #include "DataFormats/Provenance/interface/ThinnedAssociationsHelper.h"
0021 #include "DataFormats/Provenance/interface/Timestamp.h"
0022 #include "DataFormats/Provenance/interface/ProductResolverIndexHelper.h"
0023 #include "DataFormats/TestObjects/interface/Thing.h"
0024 #include "DataFormats/TestObjects/interface/ToyProducts.h"
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/EventPrincipal.h"
0027 #include "FWCore/Framework/interface/HistoryAppender.h"
0028 #include "FWCore/Framework/interface/LuminosityBlockPrincipal.h"
0029 #include "FWCore/Framework/interface/RunPrincipal.h"
0030 #include "FWCore/Framework/interface/EDConsumerBase.h"
0031 #include "FWCore/Framework/interface/ProducerBase.h"
0032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0033 #include "FWCore/ServiceRegistry/interface/ModuleCallingContext.h"
0034 #include "FWCore/Utilities/interface/Algorithms.h"
0035 #include "FWCore/Utilities/interface/EDMException.h"
0036 #include "FWCore/Utilities/interface/GetPassID.h"
0037 #include "FWCore/Utilities/interface/GlobalIdentifier.h"
0038 #include "FWCore/Utilities/interface/InputTag.h"
0039 #include "FWCore/Utilities/interface/ProductKindOfType.h"
0040 #include "FWCore/Utilities/interface/TypeID.h"
0041 #include "FWCore/Reflection/interface/TypeWithDict.h"
0042 #include "FWCore/Version/interface/GetReleaseVersion.h"
0043 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0044 
0045 #include "cppunit/extensions/HelperMacros.h"
0046 
0047 #include <algorithm>
0048 #include <fstream>
0049 #include <iterator>
0050 #include <limits>
0051 #include <map>
0052 #include <memory>
0053 #include <string>
0054 #include <typeinfo>
0055 #include <vector>
0056 
0057 using namespace edm;
0058 
0059 // This is a gross hack, to allow us to test the event
0060 namespace {
0061   struct IntConsumer : public EDConsumerBase {
0062     IntConsumer(std::vector<InputTag> const& iTags) {
0063       m_tokens.reserve(iTags.size());
0064       for (auto const& tag : iTags) {
0065         m_tokens.push_back(consumes<int>(tag));
0066       }
0067     }
0068 
0069     std::vector<EDGetTokenT<int>> m_tokens;
0070   };
0071 
0072   struct IntProductConsumer : public EDConsumerBase {
0073     IntProductConsumer(std::vector<InputTag> const& iTags) {
0074       m_tokens.reserve(iTags.size());
0075       for (auto const& tag : iTags) {
0076         m_tokens.push_back(consumes<edmtest::IntProduct>(tag));
0077       }
0078     }
0079 
0080     std::vector<EDGetTokenT<edmtest::IntProduct>> m_tokens;
0081   };
0082 
0083   template <typename T>
0084   class TestProducer : public edm::ProducerBase {
0085   public:
0086     TestProducer(std::string const& productInstanceName) { token_ = produces(productInstanceName); }
0087     EDPutTokenT<T> token_;
0088   };
0089 }  // namespace
0090 
0091 class testEvent : public CppUnit::TestFixture {
0092   CPPUNIT_TEST_SUITE(testEvent);
0093   CPPUNIT_TEST(emptyEvent);
0094   CPPUNIT_TEST(getByLabelFromEmpty);
0095   CPPUNIT_TEST(getByTokenFromEmpty);
0096   CPPUNIT_TEST(getHandleFromEmpty);
0097   CPPUNIT_TEST(getFromEmpty);
0098   CPPUNIT_TEST(putAnIntProduct);
0099   CPPUNIT_TEST(putAndGetAnIntProduct);
0100   CPPUNIT_TEST(putAndGetAnIntProductByToken);
0101   CPPUNIT_TEST(emplaceAndGetAnIntProductByToken);
0102   CPPUNIT_TEST(getByProductID);
0103   CPPUNIT_TEST(transaction);
0104   CPPUNIT_TEST(getByLabel);
0105   CPPUNIT_TEST(getByToken);
0106   CPPUNIT_TEST(getHandle);
0107   CPPUNIT_TEST(get_product);
0108   CPPUNIT_TEST(getManyByType);
0109   CPPUNIT_TEST(printHistory);
0110   CPPUNIT_TEST(deleteProduct);
0111   CPPUNIT_TEST_SUITE_END();
0112 
0113 public:
0114   testEvent();
0115   ~testEvent();
0116   void setUp();
0117   void tearDown();
0118   void emptyEvent();
0119   void getByLabelFromEmpty();
0120   void getByTokenFromEmpty();
0121   void getHandleFromEmpty();
0122   void getFromEmpty();
0123   void putAnIntProduct();
0124   void putAndGetAnIntProduct();
0125   void putAndGetAnIntProductByToken();
0126   void emplaceAndGetAnIntProductByToken();
0127   void getByProductID();
0128   void transaction();
0129   void getByLabel();
0130   void getByToken();
0131   void getHandle();
0132   void get_product();
0133   void getManyByType();
0134   void printHistory();
0135   void deleteProduct();
0136 
0137 private:
0138   template <class T>
0139   void registerProduct(std::string const& tag,
0140                        std::string const& moduleLabel,
0141                        std::string const& moduleClassName,
0142                        std::string const& processName,
0143                        std::string const& productInstanceName);
0144 
0145   template <class T>
0146   void registerProduct(std::string const& tag,
0147                        std::string const& moduleLabel,
0148                        std::string const& moduleClassName,
0149                        std::string const& processName) {
0150     std::string productInstanceName;
0151     registerProduct<T>(tag, moduleLabel, moduleClassName, processName, productInstanceName);
0152   }
0153 
0154   template <class T>
0155   ProductID addProduct(std::unique_ptr<T> product,
0156                        std::string const& tag,
0157                        std::string const& productLabel = std::string());
0158 
0159   template <class T>
0160   std::unique_ptr<ProducerBase> putProduct(std::unique_ptr<T> product,
0161                                            std::string const& productInstanceLabel,
0162                                            bool doCommit = true);
0163   template <class T>
0164   std::unique_ptr<ProducerBase> putProductUsingToken(std::unique_ptr<T> product,
0165                                                      std::string const& productInstanceLabel,
0166                                                      bool doCommit = true);
0167   template <class T>
0168   std::unique_ptr<ProducerBase> emplaceProduct(T product,
0169                                                std::string const& productInstanceLabel,
0170                                                bool doCommit = true);
0171 
0172   std::shared_ptr<ProductRegistry> availableProducts_;
0173   std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
0174   std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
0175   std::shared_ptr<edm::LuminosityBlockPrincipal> lbp_;
0176   std::shared_ptr<EventPrincipal> principal_;
0177   std::shared_ptr<Event> currentEvent_;
0178   std::shared_ptr<ModuleDescription> currentModuleDescription_;
0179   typedef std::map<std::string, ModuleDescription> modCache_t;
0180   typedef modCache_t::iterator iterator_t;
0181 
0182   modCache_t moduleDescriptions_;
0183   ProcessHistoryRegistry processHistoryRegistry_;
0184   std::vector<std::shared_ptr<ProcessConfiguration>> processConfigurations_;
0185   HistoryAppender historyAppender_;
0186 };
0187 
0188 ///registration of the test so that the runner can find it
0189 CPPUNIT_TEST_SUITE_REGISTRATION(testEvent);
0190 
0191 EventID make_id() { return EventID(2112, 1, 25); }
0192 Timestamp make_timestamp() { return Timestamp(1); }
0193 
0194 template <class T>
0195 void testEvent::registerProduct(std::string const& tag,
0196                                 std::string const& moduleLabel,
0197                                 std::string const& moduleClassName,
0198                                 std::string const& processName,
0199                                 std::string const& productInstanceName) {
0200   if (!availableProducts_)
0201     availableProducts_.reset(new ProductRegistry());
0202 
0203   ParameterSet moduleParams;
0204   moduleParams.template addParameter<std::string>("@module_type", moduleClassName);
0205   moduleParams.template addParameter<std::string>("@module_label", moduleLabel);
0206   moduleParams.registerIt();
0207 
0208   ParameterSet processParams;
0209   processParams.template addParameter<std::string>("@process_name", processName);
0210   processParams.template addParameter<ParameterSet>(moduleLabel, moduleParams);
0211   processParams.registerIt();
0212 
0213   ProcessConfiguration process(processName, processParams.id(), getReleaseVersion(), getPassID());
0214 
0215   auto processX = std::make_shared<ProcessConfiguration>(process);
0216   processConfigurations_.push_back(processX);
0217 
0218   TypeWithDict product_type(typeid(T));
0219 
0220   BranchDescription branch(InEvent,
0221                            moduleLabel,
0222                            processName,
0223                            product_type.userClassName(),
0224                            product_type.friendlyClassName(),
0225                            productInstanceName,
0226                            moduleClassName,
0227                            moduleParams.id(),
0228                            product_type);
0229 
0230   moduleDescriptions_[tag] = ModuleDescription(
0231       moduleParams.id(), moduleClassName, moduleLabel, processX.get(), ModuleDescription::getUniqueID());
0232   availableProducts_->addProduct(branch);
0233 }
0234 
0235 // Add the given product, of type T, to the current event,
0236 // as if it came from the module specified by the given tag.
0237 template <class T>
0238 ProductID testEvent::addProduct(std::unique_ptr<T> product, std::string const& tag, std::string const& productLabel) {
0239   iterator_t description = moduleDescriptions_.find(tag);
0240   if (description == moduleDescriptions_.end())
0241     throw edm::Exception(errors::LogicError) << "Failed to find a module description for tag: " << tag << '\n';
0242 
0243   ModuleCallingContext mcc(&description->second);
0244   Event temporaryEvent(*principal_, description->second, &mcc);
0245   TestProducer<T> prod(productLabel);
0246   const_cast<std::vector<edm::ProductResolverIndex>&>(prod.putTokenIndexToProductResolverIndex())
0247       .push_back(principal_->productLookup().index(PRODUCT_TYPE,
0248                                                    edm::TypeID(typeid(T)),
0249                                                    description->second.moduleLabel().c_str(),
0250                                                    productLabel.c_str(),
0251                                                    description->second.processName().c_str()));
0252 
0253   temporaryEvent.setProducer(&prod, nullptr);
0254   OrphanHandle<T> h = temporaryEvent.put(std::move(product), productLabel);
0255   ProductID id = h.id();
0256   temporaryEvent.commit_(std::vector<ProductResolverIndex>());
0257   return id;
0258 }
0259 
0260 template <class T>
0261 std::unique_ptr<ProducerBase> testEvent::putProduct(std::unique_ptr<T> product,
0262                                                     std::string const& productInstanceLabel,
0263                                                     bool doCommit) {
0264   auto prod = std::make_unique<TestProducer<edmtest::IntProduct>>(productInstanceLabel);
0265   auto index = principal_->productLookup().index(PRODUCT_TYPE,
0266                                                  edm::TypeID(typeid(T)),
0267                                                  currentModuleDescription_->moduleLabel().c_str(),
0268                                                  productInstanceLabel.c_str(),
0269                                                  currentModuleDescription_->processName().c_str());
0270   CPPUNIT_ASSERT(index != std::numeric_limits<unsigned int>::max());
0271   const_cast<std::vector<edm::ProductResolverIndex>&>(prod->putTokenIndexToProductResolverIndex()).push_back(index);
0272   currentEvent_->setProducer(prod.get(), nullptr);
0273   currentEvent_->put(std::move(product), productInstanceLabel);
0274   if (doCommit) {
0275     currentEvent_->commit_(std::vector<ProductResolverIndex>());
0276   }
0277   return prod;
0278 }
0279 
0280 template <class T>
0281 std::unique_ptr<ProducerBase> testEvent::putProductUsingToken(std::unique_ptr<T> product,
0282                                                               std::string const& productInstanceLabel,
0283                                                               bool doCommit) {
0284   auto prod = std::make_unique<TestProducer<edmtest::IntProduct>>(productInstanceLabel);
0285   EDPutTokenT<edmtest::IntProduct> token = prod->token_;
0286   auto index = principal_->productLookup().index(PRODUCT_TYPE,
0287                                                  edm::TypeID(typeid(T)),
0288                                                  currentModuleDescription_->moduleLabel().c_str(),
0289                                                  productInstanceLabel.c_str(),
0290                                                  currentModuleDescription_->processName().c_str());
0291   CPPUNIT_ASSERT(index != std::numeric_limits<unsigned int>::max());
0292   const_cast<std::vector<edm::ProductResolverIndex>&>(prod->putTokenIndexToProductResolverIndex()).push_back(index);
0293   currentEvent_->setProducer(prod.get(), nullptr);
0294   currentEvent_->put(token, std::move(product));
0295   if (doCommit) {
0296     currentEvent_->commit_(std::vector<ProductResolverIndex>());
0297   }
0298   return prod;
0299 }
0300 
0301 template <class T>
0302 std::unique_ptr<ProducerBase> testEvent::emplaceProduct(T product,
0303                                                         std::string const& productInstanceLabel,
0304                                                         bool doCommit) {
0305   auto prod = std::make_unique<TestProducer<edmtest::IntProduct>>(productInstanceLabel);
0306   EDPutTokenT<edmtest::IntProduct> token = prod->token_;
0307   auto index = principal_->productLookup().index(PRODUCT_TYPE,
0308                                                  edm::TypeID(typeid(T)),
0309                                                  currentModuleDescription_->moduleLabel().c_str(),
0310                                                  productInstanceLabel.c_str(),
0311                                                  currentModuleDescription_->processName().c_str());
0312   CPPUNIT_ASSERT(index != std::numeric_limits<unsigned int>::max());
0313   const_cast<std::vector<edm::ProductResolverIndex>&>(prod->putTokenIndexToProductResolverIndex()).push_back(index);
0314   currentEvent_->setProducer(prod.get(), nullptr);
0315   currentEvent_->emplace(token, std::move(product));
0316   if (doCommit) {
0317     currentEvent_->commit_(std::vector<ProductResolverIndex>());
0318   }
0319   return prod;
0320 }
0321 
0322 testEvent::testEvent()
0323     : availableProducts_(new ProductRegistry()),
0324       branchIDListHelper_(new BranchIDListHelper()),
0325       thinnedAssociationsHelper_(new ThinnedAssociationsHelper()),
0326       principal_(),
0327       currentEvent_(),
0328       currentModuleDescription_(),
0329       moduleDescriptions_(),
0330       processHistoryRegistry_(),
0331       processConfigurations_() {
0332   typedef edmtest::IntProduct prod_t;
0333   typedef std::vector<edmtest::Thing> vec_t;
0334 
0335   registerProduct<prod_t>("nolabel_tag", "modOne", "IntProducer", "EARLY");
0336   registerProduct<prod_t>("int1_tag", "modMulti", "IntProducer", "EARLY", "int1");
0337   registerProduct<prod_t>("int1_tag_late", "modMulti", "IntProducer", "LATE", "int1");
0338   registerProduct<prod_t>("int2_tag", "modMulti", "IntProducer", "EARLY", "int2");
0339   registerProduct<prod_t>("int3_tag", "modMulti", "IntProducer", "EARLY");
0340   registerProduct<vec_t>("thing", "modthing", "ThingProducer", "LATE");
0341   registerProduct<vec_t>("thing2", "modthing", "ThingProducer", "LATE", "inst2");
0342 
0343   // Fake up the production of a single IntProduct from an IntProducer
0344   // module, run in the 'CURRENT' process.
0345   ParameterSet moduleParams;
0346   std::string moduleLabel("modMulti");
0347   std::string moduleClassName("IntProducer");
0348   moduleParams.addParameter<std::string>("@module_type", moduleClassName);
0349   moduleParams.addParameter<std::string>("@module_label", moduleLabel);
0350   moduleParams.registerIt();
0351 
0352   ParameterSet processParams;
0353   std::string processName("CURRENT");
0354   processParams.addParameter<std::string>("@process_name", processName);
0355   processParams.addParameter(moduleLabel, moduleParams);
0356   processParams.registerIt();
0357 
0358   ProcessConfiguration process(processName, processParams.id(), getReleaseVersion(), getPassID());
0359 
0360   TypeWithDict product_type(typeid(prod_t));
0361 
0362   auto processX = std::make_shared<ProcessConfiguration>(process);
0363   processConfigurations_.push_back(processX);
0364   currentModuleDescription_.reset(new ModuleDescription(
0365       moduleParams.id(), moduleClassName, moduleLabel, processX.get(), ModuleDescription::getUniqueID()));
0366 
0367   std::string productInstanceName("int1");
0368 
0369   BranchDescription branch(InEvent,
0370                            moduleLabel,
0371                            processName,
0372                            product_type.userClassName(),
0373                            product_type.friendlyClassName(),
0374                            productInstanceName,
0375                            moduleClassName,
0376                            moduleParams.id(),
0377                            product_type);
0378 
0379   availableProducts_->addProduct(branch);
0380 
0381   // Freeze the product registry before we make the Event.
0382   availableProducts_->setFrozen();
0383   branchIDListHelper_->updateFromRegistry(*availableProducts_);
0384 }
0385 
0386 testEvent::~testEvent() {}
0387 
0388 void testEvent::setUp() {
0389   // First build a fake process history, that says there
0390   // were previous processes named "EARLY" and "LATE".
0391   // This takes several lines of code but other than
0392   // the process names none of it is used or interesting.
0393   ParameterSet moduleParamsEarly;
0394   std::string moduleLabelEarly("currentModule");
0395   std::string moduleClassNameEarly("IntProducer");
0396   moduleParamsEarly.addParameter<std::string>("@module_type", moduleClassNameEarly);
0397   moduleParamsEarly.addParameter<std::string>("@module_label", moduleLabelEarly);
0398   moduleParamsEarly.registerIt();
0399 
0400   ParameterSet processParamsEarly;
0401   std::string processNameEarly("EARLY");
0402   processParamsEarly.addParameter<std::string>("@process_name", processNameEarly);
0403   processParamsEarly.addParameter(moduleLabelEarly, moduleParamsEarly);
0404   processParamsEarly.registerIt();
0405 
0406   ProcessConfiguration processEarly("EARLY", processParamsEarly.id(), getReleaseVersion(), getPassID());
0407 
0408   ParameterSet moduleParamsLate;
0409   std::string moduleLabelLate("currentModule");
0410   std::string moduleClassNameLate("IntProducer");
0411   moduleParamsLate.addParameter<std::string>("@module_type", moduleClassNameLate);
0412   moduleParamsLate.addParameter<std::string>("@module_label", moduleLabelLate);
0413   moduleParamsLate.registerIt();
0414 
0415   ParameterSet processParamsLate;
0416   std::string processNameLate("LATE");
0417   processParamsLate.addParameter<std::string>("@process_name", processNameLate);
0418   processParamsLate.addParameter(moduleLabelLate, moduleParamsLate);
0419   processParamsLate.registerIt();
0420 
0421   ProcessConfiguration processLate("LATE", processParamsLate.id(), getReleaseVersion(), getPassID());
0422 
0423   auto processHistory = std::make_unique<ProcessHistory>();
0424   ProcessHistory& ph = *processHistory;
0425   processHistory->push_back(processEarly);
0426   processHistory->push_back(processLate);
0427 
0428   processHistoryRegistry_.registerProcessHistory(ph);
0429 
0430   ProcessHistoryID processHistoryID = ph.id();
0431 
0432   // Finally done with making a fake process history
0433 
0434   // This is all a hack to make this test work, but here is some
0435   // detail as to what is going on.  (this does not happen in real
0436   // data processing).
0437   // When any new product is added to the event principal at
0438   // commit, the "CURRENT" process will go into the ProcessHistory
0439   // even if we have faked it that the new product is associated
0440   // with a previous process, because the process name comes from
0441   // the currentModuleDescription stored in the principal.  On the
0442   // other hand, when addProduct is called another event is created
0443   // with a fake moduleDescription containing the old process name
0444   // and that is used to create the product holder in the principal used to
0445   // look up the object.
0446 
0447   std::shared_ptr<ProductRegistry const> preg(availableProducts_);
0448   std::string uuid = createGlobalIdentifier();
0449   Timestamp time = make_timestamp();
0450   EventID id = make_id();
0451   ProcessConfiguration const& pc = currentModuleDescription_->processConfiguration();
0452   auto runAux = std::make_shared<RunAuxiliary>(id.run(), time, time);
0453   auto rp = std::make_shared<RunPrincipal>(runAux, preg, pc, &historyAppender_, 0);
0454   lbp_ = std::make_shared<LuminosityBlockPrincipal>(preg, pc, &historyAppender_, 0);
0455   lbp_->setAux(LuminosityBlockAuxiliary(rp->run(), 1, time, time));
0456   lbp_->setRunPrincipal(rp);
0457   EventAuxiliary eventAux(id, uuid, time, true);
0458   const_cast<ProcessHistoryID&>(eventAux.processHistoryID()) = processHistoryID;
0459   principal_.reset(new edm::EventPrincipal(
0460       preg, branchIDListHelper_, thinnedAssociationsHelper_, pc, &historyAppender_, edm::StreamID::invalidStreamID()));
0461   principal_->fillEventPrincipal(eventAux, processHistoryRegistry_.getMapped(eventAux.processHistoryID()));
0462   principal_->setLuminosityBlockPrincipal(lbp_.get());
0463   ModuleCallingContext mcc(currentModuleDescription_.get());
0464   currentEvent_.reset(new Event(*principal_, *currentModuleDescription_, &mcc));
0465 }
0466 
0467 void testEvent::tearDown() {
0468   currentEvent_.reset();
0469   principal_.reset();
0470 }
0471 
0472 void testEvent::emptyEvent() {
0473   CPPUNIT_ASSERT(currentEvent_);
0474   CPPUNIT_ASSERT(currentEvent_->id() == make_id());
0475   CPPUNIT_ASSERT(currentEvent_->time() == make_timestamp());
0476   CPPUNIT_ASSERT(currentEvent_->size() == 0);
0477 }
0478 
0479 void testEvent::getByLabelFromEmpty() {
0480   InputTag inputTag("moduleLabel", "instanceName");
0481   Handle<int> nonesuch;
0482   CPPUNIT_ASSERT(!nonesuch.isValid());
0483   CPPUNIT_ASSERT(!currentEvent_->getByLabel(inputTag, nonesuch));
0484   CPPUNIT_ASSERT(!nonesuch.isValid());
0485   CPPUNIT_ASSERT(nonesuch.failedToGet());
0486   CPPUNIT_ASSERT_THROW(*nonesuch, cms::Exception);
0487 }
0488 
0489 void testEvent::getByTokenFromEmpty() {
0490   InputTag inputTag("moduleLabel", "instanceName");
0491 
0492   IntConsumer consumer(std::vector<InputTag>{1, inputTag});
0493   consumer.updateLookup(InEvent, principal_->productLookup(), false);
0494   assert(1 == consumer.m_tokens.size());
0495   currentEvent_->setConsumer(&consumer);
0496   Handle<int> nonesuch;
0497   CPPUNIT_ASSERT(!nonesuch.isValid());
0498   CPPUNIT_ASSERT(!currentEvent_->getByToken(consumer.m_tokens[0], nonesuch));
0499   CPPUNIT_ASSERT(!nonesuch.isValid());
0500   CPPUNIT_ASSERT(nonesuch.failedToGet());
0501   CPPUNIT_ASSERT_THROW(*nonesuch, cms::Exception);
0502 }
0503 
0504 void testEvent::getHandleFromEmpty() {
0505   InputTag inputTag("moduleLabel", "instanceName");
0506 
0507   IntConsumer consumer(std::vector<InputTag>{1, inputTag});
0508   consumer.updateLookup(InEvent, principal_->productLookup(), false);
0509   assert(1 == consumer.m_tokens.size());
0510   currentEvent_->setConsumer(&consumer);
0511   Handle<int> nonesuch;
0512   CPPUNIT_ASSERT(!(nonesuch = currentEvent_->getHandle(consumer.m_tokens[0])));
0513   CPPUNIT_ASSERT(!nonesuch.isValid());
0514   CPPUNIT_ASSERT(nonesuch.failedToGet());
0515   CPPUNIT_ASSERT_THROW(*nonesuch, cms::Exception);
0516 }
0517 
0518 void testEvent::getFromEmpty() {
0519   InputTag inputTag("moduleLabel", "instanceName");
0520 
0521   IntConsumer consumer(std::vector<InputTag>{1, inputTag});
0522   consumer.updateLookup(InEvent, principal_->productLookup(), false);
0523   assert(1 == consumer.m_tokens.size());
0524   currentEvent_->setConsumer(&consumer);
0525   CPPUNIT_ASSERT_THROW((void)currentEvent_->get(consumer.m_tokens[0]), cms::Exception);
0526 }
0527 
0528 void testEvent::putAnIntProduct() {
0529   auto p = putProduct(std::make_unique<edmtest::IntProduct>(3), "int1", false);
0530   CPPUNIT_ASSERT(currentEvent_->size() == 1);
0531   currentEvent_->commit_(std::vector<ProductResolverIndex>());
0532   CPPUNIT_ASSERT(currentEvent_->size() == 1);
0533 }
0534 
0535 void testEvent::putAndGetAnIntProduct() {
0536   auto p = putProduct(std::make_unique<edmtest::IntProduct>(4), "int1");
0537 
0538   InputTag should_match("modMulti", "int1", "CURRENT");
0539   InputTag should_not_match("modMulti", "int1", "NONESUCH");
0540   Handle<edmtest::IntProduct> h;
0541   currentEvent_->getByLabel(should_match, h);
0542   CPPUNIT_ASSERT(h.isValid());
0543   CPPUNIT_ASSERT(!currentEvent_->getByLabel(should_not_match, h));
0544   CPPUNIT_ASSERT(!h.isValid());
0545   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0546 }
0547 
0548 void testEvent::putAndGetAnIntProductByToken() {
0549   auto p = putProductUsingToken(std::make_unique<edmtest::IntProduct>(4), "int1");
0550 
0551   InputTag should_match("modMulti", "int1", "CURRENT");
0552   InputTag should_not_match("modMulti", "int1", "NONESUCH");
0553   Handle<edmtest::IntProduct> h;
0554   currentEvent_->getByLabel(should_match, h);
0555   CPPUNIT_ASSERT(h.isValid());
0556   CPPUNIT_ASSERT(!currentEvent_->getByLabel(should_not_match, h));
0557   CPPUNIT_ASSERT(!h.isValid());
0558   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0559 }
0560 
0561 void testEvent::emplaceAndGetAnIntProductByToken() {
0562   auto p = emplaceProduct(edmtest::IntProduct{4}, "int1");
0563 
0564   InputTag should_match("modMulti", "int1", "CURRENT");
0565   InputTag should_not_match("modMulti", "int1", "NONESUCH");
0566   Handle<edmtest::IntProduct> h;
0567   currentEvent_->getByLabel(should_match, h);
0568   CPPUNIT_ASSERT(h.isValid());
0569   CPPUNIT_ASSERT(!currentEvent_->getByLabel(should_not_match, h));
0570   CPPUNIT_ASSERT(!h.isValid());
0571   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0572 }
0573 
0574 void testEvent::getByProductID() {
0575   typedef edmtest::IntProduct product_t;
0576   typedef std::unique_ptr<product_t> ap_t;
0577   typedef Handle<product_t> handle_t;
0578 
0579   ProductID wanted;
0580 
0581   {
0582     ap_t one(new product_t(1));
0583     ProductID id1 = addProduct(std::move(one), "int1_tag", "int1");
0584     CPPUNIT_ASSERT(id1 != ProductID());
0585     wanted = id1;
0586 
0587     ap_t two(new product_t(2));
0588     ProductID id2 = addProduct(std::move(two), "int2_tag", "int2");
0589     CPPUNIT_ASSERT(id2 != ProductID());
0590     CPPUNIT_ASSERT(id2 != id1);
0591 
0592     currentEvent_->commit_(std::vector<ProductResolverIndex>());
0593     CPPUNIT_ASSERT(currentEvent_->size() == 2);
0594   }
0595 
0596   handle_t h;
0597   currentEvent_->get(wanted, h);
0598   CPPUNIT_ASSERT(h.isValid());
0599   CPPUNIT_ASSERT(h.id() == wanted);
0600   CPPUNIT_ASSERT(h->value == 1);
0601 
0602   ProductID invalid;
0603   CPPUNIT_ASSERT_THROW(currentEvent_->get(invalid, h), cms::Exception);
0604   CPPUNIT_ASSERT(!h.isValid());
0605   ProductID notpresent(0, std::numeric_limits<unsigned short>::max());
0606   CPPUNIT_ASSERT(!currentEvent_->get(notpresent, h));
0607   CPPUNIT_ASSERT(!h.isValid());
0608   CPPUNIT_ASSERT(h.failedToGet());
0609   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0610 
0611   edm::EventBase* baseEvent = currentEvent_.get();
0612   handle_t h1;
0613   baseEvent->get(wanted, h1);
0614   CPPUNIT_ASSERT(h1.isValid());
0615   CPPUNIT_ASSERT(h1.id() == wanted);
0616   CPPUNIT_ASSERT(h1->value == 1);
0617 
0618   CPPUNIT_ASSERT_THROW(baseEvent->get(invalid, h1), cms::Exception);
0619   CPPUNIT_ASSERT(!h1.isValid());
0620   CPPUNIT_ASSERT(!baseEvent->get(notpresent, h1));
0621   CPPUNIT_ASSERT(!h1.isValid());
0622   CPPUNIT_ASSERT(h1.failedToGet());
0623   CPPUNIT_ASSERT_THROW(*h1, cms::Exception);
0624 }
0625 
0626 void testEvent::transaction() {
0627   // Put a product into an Event, and make sure that if we don't
0628   // commit, there is no product in the EventPrincipal afterwards.
0629   CPPUNIT_ASSERT(principal_->size() == 0);
0630   {
0631     typedef edmtest::IntProduct product_t;
0632     typedef std::unique_ptr<product_t> ap_t;
0633 
0634     ap_t three(new product_t(3));
0635     auto p = putProduct(std::move(three), "int1", false);
0636 
0637     CPPUNIT_ASSERT(principal_->size() == 0);
0638     CPPUNIT_ASSERT(currentEvent_->size() == 1);
0639     // DO NOT COMMIT!
0640   }
0641 
0642   // The Event has been destroyed without a commit -- we should not
0643   // have any products in the EventPrincipal.
0644   CPPUNIT_ASSERT(principal_->size() == 0);
0645 }
0646 
0647 void testEvent::getByLabel() {
0648   typedef edmtest::IntProduct product_t;
0649   typedef std::unique_ptr<product_t> ap_t;
0650   typedef Handle<product_t> handle_t;
0651 
0652   ap_t one(new product_t(1));
0653   ap_t two(new product_t(2));
0654   ap_t three(new product_t(3));
0655   ap_t four(new product_t(4));
0656   addProduct(std::move(one), "int1_tag", "int1");
0657   addProduct(std::move(two), "int2_tag", "int2");
0658   addProduct(std::move(three), "int3_tag");
0659   addProduct(std::move(four), "nolabel_tag");
0660 
0661   auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0662   addProduct(std::move(ap_vthing), "thing", "");
0663 
0664   ap_t oneHundred(new product_t(100));
0665   addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0666 
0667   auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0668   putProduct(std::move(twoHundred), "int1");
0669 
0670   CPPUNIT_ASSERT(currentEvent_->size() == 7);
0671 
0672   handle_t h;
0673   CPPUNIT_ASSERT(currentEvent_->getByLabel("modMulti", h));
0674   CPPUNIT_ASSERT(h->value == 3);
0675 
0676   CPPUNIT_ASSERT(currentEvent_->getByLabel("modMulti", "int1", h));
0677   CPPUNIT_ASSERT(h->value == 200);
0678 
0679   CPPUNIT_ASSERT(!currentEvent_->getByLabel("modMulti", "nomatch", h));
0680   CPPUNIT_ASSERT(!h.isValid());
0681   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0682 
0683   InputTag inputTag("modMulti", "int1");
0684   CPPUNIT_ASSERT(currentEvent_->getByLabel(inputTag, h));
0685   CPPUNIT_ASSERT(h->value == 200);
0686 
0687   CPPUNIT_ASSERT(currentEvent_->getByLabel("modMulti", "int1", h));
0688   CPPUNIT_ASSERT(h->value == 200);
0689 
0690   InputTag tag1("modMulti", "int1", "EARLY");
0691   CPPUNIT_ASSERT(currentEvent_->getByLabel(tag1, h));
0692   CPPUNIT_ASSERT(h->value == 1);
0693 
0694   InputTag tag2("modMulti", "int1", "LATE");
0695   CPPUNIT_ASSERT(currentEvent_->getByLabel(tag2, h));
0696   CPPUNIT_ASSERT(h->value == 100);
0697 
0698   InputTag tag3("modMulti", "int1", "CURRENT");
0699   CPPUNIT_ASSERT(currentEvent_->getByLabel(tag3, h));
0700   CPPUNIT_ASSERT(h->value == 200);
0701 
0702   InputTag tag4("modMulti", "int2", "EARLY");
0703   CPPUNIT_ASSERT(currentEvent_->getByLabel(tag4, h));
0704   CPPUNIT_ASSERT(h->value == 2);
0705 
0706   InputTag tag5("modOne");
0707   CPPUNIT_ASSERT(currentEvent_->getByLabel(tag5, h));
0708   CPPUNIT_ASSERT(h->value == 4);
0709 
0710   CPPUNIT_ASSERT(currentEvent_->getByLabel("modOne", h));
0711   CPPUNIT_ASSERT(h->value == 4);
0712 
0713   {
0714     edm::EventBase* baseEvent = currentEvent_.get();
0715     CPPUNIT_ASSERT(baseEvent->getByLabel(inputTag, h));
0716     CPPUNIT_ASSERT(h->value == 200);
0717   }
0718 
0719   BasicHandle bh = principal_->getByLabel(
0720       PRODUCT_TYPE, TypeID(typeid(edmtest::IntProduct)), "modMulti", "int1", "LATE", nullptr, nullptr, nullptr);
0721   h = convert_handle<product_t>(std::move(bh));
0722   CPPUNIT_ASSERT(h->value == 100);
0723   BasicHandle bh2(principal_->getByLabel(
0724       PRODUCT_TYPE, TypeID(typeid(edmtest::IntProduct)), "modMulti", "int1", "nomatch", nullptr, nullptr, nullptr));
0725   CPPUNIT_ASSERT(!bh2.isValid());
0726 
0727   std::shared_ptr<Wrapper<edmtest::IntProduct> const> ptr =
0728       getProductByTag<edmtest::IntProduct>(*principal_, inputTag, nullptr);
0729   CPPUNIT_ASSERT(ptr->product()->value == 200);
0730 }
0731 
0732 void testEvent::getByToken() {
0733   typedef edmtest::IntProduct product_t;
0734   typedef std::unique_ptr<product_t> ap_t;
0735   typedef Handle<product_t> handle_t;
0736 
0737   ap_t one(new product_t(1));
0738   ap_t two(new product_t(2));
0739   ap_t three(new product_t(3));
0740   ap_t four(new product_t(4));
0741   addProduct(std::move(one), "int1_tag", "int1");
0742   addProduct(std::move(two), "int2_tag", "int2");
0743   addProduct(std::move(three), "int3_tag");
0744   addProduct(std::move(four), "nolabel_tag");
0745 
0746   auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0747   addProduct(std::move(ap_vthing), "thing", "");
0748 
0749   ap_t oneHundred(new product_t(100));
0750   addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0751 
0752   auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0753   putProduct(std::move(twoHundred), "int1");
0754 
0755   CPPUNIT_ASSERT(currentEvent_->size() == 7);
0756 
0757   IntProductConsumer consumer(std::vector<InputTag>{InputTag("modMulti"),
0758                                                     InputTag("modMulti", "int1"),
0759                                                     InputTag("modMulti", "nomatch"),
0760                                                     InputTag("modMulti", "int1", "EARLY"),
0761                                                     InputTag("modMulti", "int1", "LATE"),
0762                                                     InputTag("modMulti", "int1", "CURRENT"),
0763                                                     InputTag("modMulti", "int2", "EARLY"),
0764                                                     InputTag("modOne")});
0765   consumer.updateLookup(InEvent, principal_->productLookup(), false);
0766 
0767   currentEvent_->setConsumer(&consumer);
0768 
0769   const auto modMultiToken = consumer.m_tokens[0];
0770   const auto modMultiInt1Token = consumer.m_tokens[1];
0771   const auto modMultinomatchToken = consumer.m_tokens[2];
0772   const auto modMultiInt1EarlyToken = consumer.m_tokens[3];
0773   const auto modMultiInt1LateToken = consumer.m_tokens[4];
0774   const auto modMultiInt1CurrentToken = consumer.m_tokens[5];
0775   const auto modMultiInt2EarlyToken = consumer.m_tokens[6];
0776   const auto modOneToken = consumer.m_tokens[7];
0777 
0778   handle_t h;
0779   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiToken, h));
0780   CPPUNIT_ASSERT(h->value == 3);
0781 
0782   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1Token, h));
0783   CPPUNIT_ASSERT(h->value == 200);
0784 
0785   CPPUNIT_ASSERT(!currentEvent_->getByToken(modMultinomatchToken, h));
0786   CPPUNIT_ASSERT(!h.isValid());
0787   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0788 
0789   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1Token, h));
0790   CPPUNIT_ASSERT(h->value == 200);
0791 
0792   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1EarlyToken, h));
0793   CPPUNIT_ASSERT(h->value == 1);
0794 
0795   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1LateToken, h));
0796   CPPUNIT_ASSERT(h->value == 100);
0797 
0798   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1CurrentToken, h));
0799   CPPUNIT_ASSERT(h->value == 200);
0800 
0801   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt2EarlyToken, h));
0802   CPPUNIT_ASSERT(h->value == 2);
0803 
0804   CPPUNIT_ASSERT(currentEvent_->getByToken(modOneToken, h));
0805   CPPUNIT_ASSERT(h->value == 4);
0806 }
0807 
0808 void testEvent::getHandle() {
0809   typedef edmtest::IntProduct product_t;
0810   typedef std::unique_ptr<product_t> ap_t;
0811   typedef Handle<product_t> handle_t;
0812 
0813   ap_t one(new product_t(1));
0814   ap_t two(new product_t(2));
0815   ap_t three(new product_t(3));
0816   ap_t four(new product_t(4));
0817   addProduct(std::move(one), "int1_tag", "int1");
0818   addProduct(std::move(two), "int2_tag", "int2");
0819   addProduct(std::move(three), "int3_tag");
0820   addProduct(std::move(four), "nolabel_tag");
0821 
0822   auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0823   addProduct(std::move(ap_vthing), "thing", "");
0824 
0825   ap_t oneHundred(new product_t(100));
0826   addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0827 
0828   auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0829   putProduct(std::move(twoHundred), "int1");
0830 
0831   CPPUNIT_ASSERT(currentEvent_->size() == 7);
0832 
0833   IntProductConsumer consumer(std::vector<InputTag>{InputTag("modMulti"),
0834                                                     InputTag("modMulti", "int1"),
0835                                                     InputTag("modMulti", "nomatch"),
0836                                                     InputTag("modMulti", "int1", "EARLY"),
0837                                                     InputTag("modMulti", "int1", "LATE"),
0838                                                     InputTag("modMulti", "int1", "CURRENT"),
0839                                                     InputTag("modMulti", "int2", "EARLY"),
0840                                                     InputTag("modOne")});
0841   consumer.updateLookup(InEvent, principal_->productLookup(), false);
0842 
0843   currentEvent_->setConsumer(&consumer);
0844 
0845   const auto modMultiToken = consumer.m_tokens[0];
0846   const auto modMultiInt1Token = consumer.m_tokens[1];
0847   const auto modMultinomatchToken = consumer.m_tokens[2];
0848   const auto modMultiInt1EarlyToken = consumer.m_tokens[3];
0849   const auto modMultiInt1LateToken = consumer.m_tokens[4];
0850   const auto modMultiInt1CurrentToken = consumer.m_tokens[5];
0851   const auto modMultiInt2EarlyToken = consumer.m_tokens[6];
0852   const auto modOneToken = consumer.m_tokens[7];
0853 
0854   handle_t h;
0855   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiToken));
0856   CPPUNIT_ASSERT(h->value == 3);
0857 
0858   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1Token));
0859   CPPUNIT_ASSERT(h->value == 200);
0860 
0861   CPPUNIT_ASSERT(!(h = currentEvent_->getHandle(modMultinomatchToken)));
0862   CPPUNIT_ASSERT(!h.isValid());
0863   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0864 
0865   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1Token));
0866   CPPUNIT_ASSERT(h->value == 200);
0867 
0868   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1EarlyToken));
0869   CPPUNIT_ASSERT(h->value == 1);
0870 
0871   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1LateToken));
0872   CPPUNIT_ASSERT(h->value == 100);
0873 
0874   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1CurrentToken));
0875   CPPUNIT_ASSERT(h->value == 200);
0876 
0877   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt2EarlyToken));
0878   CPPUNIT_ASSERT(h->value == 2);
0879 
0880   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modOneToken));
0881   CPPUNIT_ASSERT(h->value == 4);
0882 }
0883 
0884 void testEvent::get_product() {
0885   typedef edmtest::IntProduct product_t;
0886   typedef std::unique_ptr<product_t> ap_t;
0887   typedef Handle<product_t> handle_t;
0888 
0889   ap_t one(new product_t(1));
0890   ap_t two(new product_t(2));
0891   ap_t three(new product_t(3));
0892   ap_t four(new product_t(4));
0893   addProduct(std::move(one), "int1_tag", "int1");
0894   addProduct(std::move(two), "int2_tag", "int2");
0895   addProduct(std::move(three), "int3_tag");
0896   addProduct(std::move(four), "nolabel_tag");
0897 
0898   auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0899   addProduct(std::move(ap_vthing), "thing", "");
0900 
0901   ap_t oneHundred(new product_t(100));
0902   addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0903 
0904   auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0905   putProduct(std::move(twoHundred), "int1");
0906 
0907   CPPUNIT_ASSERT(currentEvent_->size() == 7);
0908 
0909   IntProductConsumer consumer(std::vector<InputTag>{InputTag("modMulti"),
0910                                                     InputTag("modMulti", "int1"),
0911                                                     InputTag("modMulti", "nomatch"),
0912                                                     InputTag("modMulti", "int1", "EARLY"),
0913                                                     InputTag("modMulti", "int1", "LATE"),
0914                                                     InputTag("modMulti", "int1", "CURRENT"),
0915                                                     InputTag("modMulti", "int2", "EARLY"),
0916                                                     InputTag("modOne")});
0917   consumer.updateLookup(InEvent, principal_->productLookup(), false);
0918 
0919   currentEvent_->setConsumer(&consumer);
0920 
0921   const auto modMultiToken = consumer.m_tokens[0];
0922   const auto modMultiInt1Token = consumer.m_tokens[1];
0923   const auto modMultinomatchToken = consumer.m_tokens[2];
0924   const auto modMultiInt1EarlyToken = consumer.m_tokens[3];
0925   const auto modMultiInt1LateToken = consumer.m_tokens[4];
0926   const auto modMultiInt1CurrentToken = consumer.m_tokens[5];
0927   const auto modMultiInt2EarlyToken = consumer.m_tokens[6];
0928   const auto modOneToken = consumer.m_tokens[7];
0929 
0930   CPPUNIT_ASSERT(currentEvent_->get(modMultiToken).value == 3);
0931 
0932   CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1Token).value == 200);
0933 
0934   CPPUNIT_ASSERT_THROW(currentEvent_->get(modMultinomatchToken), cms::Exception);
0935 
0936   CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1Token).value == 200);
0937 
0938   CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1EarlyToken).value == 1);
0939 
0940   CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1LateToken).value == 100);
0941 
0942   CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1CurrentToken).value == 200);
0943 
0944   CPPUNIT_ASSERT(currentEvent_->get(modMultiInt2EarlyToken).value == 2);
0945 
0946   CPPUNIT_ASSERT(currentEvent_->get(modOneToken).value == 4);
0947 }
0948 
0949 void testEvent::getManyByType() {
0950   typedef edmtest::IntProduct product_t;
0951   typedef std::unique_ptr<product_t> ap_t;
0952   typedef Handle<product_t> handle_t;
0953   typedef std::vector<handle_t> handle_vec;
0954 
0955   ap_t one(new product_t(1));
0956   ap_t two(new product_t(2));
0957   ap_t three(new product_t(3));
0958   ap_t four(new product_t(4));
0959   addProduct(std::move(one), "int1_tag", "int1");
0960   addProduct(std::move(two), "int2_tag", "int2");
0961   addProduct(std::move(three), "int3_tag");
0962   addProduct(std::move(four), "nolabel_tag");
0963 
0964   auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0965   addProduct(std::move(ap_vthing), "thing", "");
0966 
0967   auto ap_vthing2 = std::make_unique<std::vector<edmtest::Thing>>();
0968   addProduct(std::move(ap_vthing2), "thing2", "inst2");
0969 
0970   ap_t oneHundred(new product_t(100));
0971   addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0972 
0973   auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0974   putProduct(std::move(twoHundred), "int1");
0975 
0976   CPPUNIT_ASSERT(currentEvent_->size() == 8);
0977 
0978   handle_vec handles;
0979   currentEvent_->getManyByType(handles);
0980   CPPUNIT_ASSERT(handles.size() == 6);
0981   int sum = 0;
0982   for (int k = 0; k < 6; ++k)
0983     sum += handles[k]->value;
0984   CPPUNIT_ASSERT(sum == 310);
0985 }
0986 
0987 void testEvent::printHistory() {
0988   ProcessHistory const& history = currentEvent_->processHistory();
0989   std::ofstream out("history.log");
0990 
0991   copy_all(history, std::ostream_iterator<ProcessHistory::const_iterator::value_type>(out, "\n"));
0992 }
0993 
0994 void testEvent::deleteProduct() {
0995   typedef edmtest::IntProduct product_t;
0996   typedef std::unique_ptr<product_t> ap_t;
0997 
0998   ap_t one(new product_t(1));
0999   addProduct(std::move(one), "int1_tag", "int1");
1000 
1001   BranchID id;
1002 
1003   availableProducts_->callForEachBranch([&id](const BranchDescription& iDesc) {
1004     if (iDesc.moduleLabel() == "modMulti" && iDesc.productInstanceName() == "int1") {
1005       id = iDesc.branchID();
1006     }
1007   });
1008 
1009   const ProductResolverBase* phb = principal_->getProductResolver(id);
1010   CPPUNIT_ASSERT(phb != nullptr);
1011 
1012   CPPUNIT_ASSERT(!phb->productWasDeleted());
1013   principal_->deleteProduct(id);
1014   CPPUNIT_ASSERT(phb->productWasDeleted());
1015 }