Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-11-04 01:57:06

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 rp = std::make_shared<RunPrincipal>(preg, pc, &historyAppender_, 0);
0453   rp->setAux(RunAuxiliary(id.run(), time, time));
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     edm::EventBase const* eb = currentEvent_.get();
0505     Handle<int> nonesuch;
0506     CPPUNIT_ASSERT(!nonesuch.isValid());
0507     CPPUNIT_ASSERT(!eb->getByToken(consumer.m_tokens[0], nonesuch));
0508     CPPUNIT_ASSERT(!nonesuch.isValid());
0509     CPPUNIT_ASSERT(nonesuch.failedToGet());
0510     CPPUNIT_ASSERT_THROW(*nonesuch, cms::Exception);
0511   }
0512 }
0513 
0514 void testEvent::getHandleFromEmpty() {
0515   InputTag inputTag("moduleLabel", "instanceName");
0516 
0517   IntConsumer consumer(std::vector<InputTag>{1, inputTag});
0518   consumer.updateLookup(InEvent, principal_->productLookup(), false);
0519   assert(1 == consumer.m_tokens.size());
0520   currentEvent_->setConsumer(&consumer);
0521   Handle<int> nonesuch;
0522   CPPUNIT_ASSERT(!(nonesuch = currentEvent_->getHandle(consumer.m_tokens[0])));
0523   CPPUNIT_ASSERT(!nonesuch.isValid());
0524   CPPUNIT_ASSERT(nonesuch.failedToGet());
0525   CPPUNIT_ASSERT_THROW(*nonesuch, cms::Exception);
0526 }
0527 
0528 void testEvent::getFromEmpty() {
0529   InputTag inputTag("moduleLabel", "instanceName");
0530 
0531   IntConsumer consumer(std::vector<InputTag>{1, inputTag});
0532   consumer.updateLookup(InEvent, principal_->productLookup(), false);
0533   assert(1 == consumer.m_tokens.size());
0534   currentEvent_->setConsumer(&consumer);
0535   CPPUNIT_ASSERT_THROW((void)currentEvent_->get(consumer.m_tokens[0]), cms::Exception);
0536 }
0537 
0538 void testEvent::putAnIntProduct() {
0539   auto p = putProduct(std::make_unique<edmtest::IntProduct>(3), "int1", false);
0540   CPPUNIT_ASSERT(currentEvent_->size() == 1);
0541   currentEvent_->commit_(std::vector<ProductResolverIndex>());
0542   CPPUNIT_ASSERT(currentEvent_->size() == 1);
0543 }
0544 
0545 void testEvent::putAndGetAnIntProduct() {
0546   auto p = putProduct(std::make_unique<edmtest::IntProduct>(4), "int1");
0547 
0548   InputTag should_match("modMulti", "int1", "CURRENT");
0549   InputTag should_not_match("modMulti", "int1", "NONESUCH");
0550   Handle<edmtest::IntProduct> h;
0551   currentEvent_->getByLabel(should_match, h);
0552   CPPUNIT_ASSERT(h.isValid());
0553   CPPUNIT_ASSERT(!currentEvent_->getByLabel(should_not_match, h));
0554   CPPUNIT_ASSERT(!h.isValid());
0555   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0556 }
0557 
0558 void testEvent::putAndGetAnIntProductByToken() {
0559   auto p = putProductUsingToken(std::make_unique<edmtest::IntProduct>(4), "int1");
0560 
0561   InputTag should_match("modMulti", "int1", "CURRENT");
0562   InputTag should_not_match("modMulti", "int1", "NONESUCH");
0563   Handle<edmtest::IntProduct> h;
0564   currentEvent_->getByLabel(should_match, h);
0565   CPPUNIT_ASSERT(h.isValid());
0566   CPPUNIT_ASSERT(!currentEvent_->getByLabel(should_not_match, h));
0567   CPPUNIT_ASSERT(!h.isValid());
0568   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0569 }
0570 
0571 void testEvent::emplaceAndGetAnIntProductByToken() {
0572   auto p = emplaceProduct(edmtest::IntProduct{4}, "int1");
0573 
0574   InputTag should_match("modMulti", "int1", "CURRENT");
0575   InputTag should_not_match("modMulti", "int1", "NONESUCH");
0576   Handle<edmtest::IntProduct> h;
0577   currentEvent_->getByLabel(should_match, h);
0578   CPPUNIT_ASSERT(h.isValid());
0579   CPPUNIT_ASSERT(!currentEvent_->getByLabel(should_not_match, h));
0580   CPPUNIT_ASSERT(!h.isValid());
0581   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0582 }
0583 
0584 void testEvent::getByProductID() {
0585   typedef edmtest::IntProduct product_t;
0586   typedef std::unique_ptr<product_t> ap_t;
0587   typedef Handle<product_t> handle_t;
0588 
0589   ProductID wanted;
0590 
0591   {
0592     ap_t one(new product_t(1));
0593     ProductID id1 = addProduct(std::move(one), "int1_tag", "int1");
0594     CPPUNIT_ASSERT(id1 != ProductID());
0595     wanted = id1;
0596 
0597     ap_t two(new product_t(2));
0598     ProductID id2 = addProduct(std::move(two), "int2_tag", "int2");
0599     CPPUNIT_ASSERT(id2 != ProductID());
0600     CPPUNIT_ASSERT(id2 != id1);
0601 
0602     currentEvent_->commit_(std::vector<ProductResolverIndex>());
0603     CPPUNIT_ASSERT(currentEvent_->size() == 2);
0604   }
0605 
0606   handle_t h;
0607   currentEvent_->get(wanted, h);
0608   CPPUNIT_ASSERT(h.isValid());
0609   CPPUNIT_ASSERT(h.id() == wanted);
0610   CPPUNIT_ASSERT(h->value == 1);
0611 
0612   ProductID invalid;
0613   CPPUNIT_ASSERT_THROW(currentEvent_->get(invalid, h), cms::Exception);
0614   CPPUNIT_ASSERT(!h.isValid());
0615   ProductID notpresent(0, std::numeric_limits<unsigned short>::max());
0616   CPPUNIT_ASSERT(!currentEvent_->get(notpresent, h));
0617   CPPUNIT_ASSERT(!h.isValid());
0618   CPPUNIT_ASSERT(h.failedToGet());
0619   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0620 
0621   edm::EventBase* baseEvent = currentEvent_.get();
0622   handle_t h1;
0623   baseEvent->get(wanted, h1);
0624   CPPUNIT_ASSERT(h1.isValid());
0625   CPPUNIT_ASSERT(h1.id() == wanted);
0626   CPPUNIT_ASSERT(h1->value == 1);
0627 
0628   CPPUNIT_ASSERT_THROW(baseEvent->get(invalid, h1), cms::Exception);
0629   CPPUNIT_ASSERT(!h1.isValid());
0630   CPPUNIT_ASSERT(!baseEvent->get(notpresent, h1));
0631   CPPUNIT_ASSERT(!h1.isValid());
0632   CPPUNIT_ASSERT(h1.failedToGet());
0633   CPPUNIT_ASSERT_THROW(*h1, cms::Exception);
0634 }
0635 
0636 void testEvent::transaction() {
0637   // Put a product into an Event, and make sure that if we don't
0638   // commit, there is no product in the EventPrincipal afterwards.
0639   CPPUNIT_ASSERT(principal_->size() == 0);
0640   {
0641     typedef edmtest::IntProduct product_t;
0642     typedef std::unique_ptr<product_t> ap_t;
0643 
0644     ap_t three(new product_t(3));
0645     auto p = putProduct(std::move(three), "int1", false);
0646 
0647     CPPUNIT_ASSERT(principal_->size() == 0);
0648     CPPUNIT_ASSERT(currentEvent_->size() == 1);
0649     // DO NOT COMMIT!
0650   }
0651 
0652   // The Event has been destroyed without a commit -- we should not
0653   // have any products in the EventPrincipal.
0654   CPPUNIT_ASSERT(principal_->size() == 0);
0655 }
0656 
0657 void testEvent::getByLabel() {
0658   typedef edmtest::IntProduct product_t;
0659   typedef std::unique_ptr<product_t> ap_t;
0660   typedef Handle<product_t> handle_t;
0661 
0662   ap_t one(new product_t(1));
0663   ap_t two(new product_t(2));
0664   ap_t three(new product_t(3));
0665   ap_t four(new product_t(4));
0666   addProduct(std::move(one), "int1_tag", "int1");
0667   addProduct(std::move(two), "int2_tag", "int2");
0668   addProduct(std::move(three), "int3_tag");
0669   addProduct(std::move(four), "nolabel_tag");
0670 
0671   auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0672   addProduct(std::move(ap_vthing), "thing", "");
0673 
0674   ap_t oneHundred(new product_t(100));
0675   addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0676 
0677   auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0678   putProduct(std::move(twoHundred), "int1");
0679 
0680   CPPUNIT_ASSERT(currentEvent_->size() == 7);
0681 
0682   handle_t h;
0683   CPPUNIT_ASSERT(currentEvent_->getByLabel("modMulti", h));
0684   CPPUNIT_ASSERT(h->value == 3);
0685 
0686   CPPUNIT_ASSERT(currentEvent_->getByLabel("modMulti", "int1", h));
0687   CPPUNIT_ASSERT(h->value == 200);
0688 
0689   CPPUNIT_ASSERT(!currentEvent_->getByLabel("modMulti", "nomatch", h));
0690   CPPUNIT_ASSERT(!h.isValid());
0691   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0692 
0693   InputTag inputTag("modMulti", "int1");
0694   CPPUNIT_ASSERT(currentEvent_->getByLabel(inputTag, h));
0695   CPPUNIT_ASSERT(h->value == 200);
0696 
0697   CPPUNIT_ASSERT(currentEvent_->getByLabel("modMulti", "int1", h));
0698   CPPUNIT_ASSERT(h->value == 200);
0699 
0700   InputTag tag1("modMulti", "int1", "EARLY");
0701   CPPUNIT_ASSERT(currentEvent_->getByLabel(tag1, h));
0702   CPPUNIT_ASSERT(h->value == 1);
0703 
0704   InputTag tag2("modMulti", "int1", "LATE");
0705   CPPUNIT_ASSERT(currentEvent_->getByLabel(tag2, h));
0706   CPPUNIT_ASSERT(h->value == 100);
0707 
0708   InputTag tag3("modMulti", "int1", "CURRENT");
0709   CPPUNIT_ASSERT(currentEvent_->getByLabel(tag3, h));
0710   CPPUNIT_ASSERT(h->value == 200);
0711 
0712   InputTag tag4("modMulti", "int2", "EARLY");
0713   CPPUNIT_ASSERT(currentEvent_->getByLabel(tag4, h));
0714   CPPUNIT_ASSERT(h->value == 2);
0715 
0716   InputTag tag5("modOne");
0717   CPPUNIT_ASSERT(currentEvent_->getByLabel(tag5, h));
0718   CPPUNIT_ASSERT(h->value == 4);
0719 
0720   CPPUNIT_ASSERT(currentEvent_->getByLabel("modOne", h));
0721   CPPUNIT_ASSERT(h->value == 4);
0722 
0723   {
0724     edm::EventBase* baseEvent = currentEvent_.get();
0725     CPPUNIT_ASSERT(baseEvent->getByLabel(inputTag, h));
0726     CPPUNIT_ASSERT(h->value == 200);
0727   }
0728 
0729   BasicHandle bh = principal_->getByLabel(
0730       PRODUCT_TYPE, TypeID(typeid(edmtest::IntProduct)), "modMulti", "int1", "LATE", nullptr, nullptr, nullptr);
0731   h = convert_handle<product_t>(std::move(bh));
0732   CPPUNIT_ASSERT(h->value == 100);
0733   BasicHandle bh2(principal_->getByLabel(
0734       PRODUCT_TYPE, TypeID(typeid(edmtest::IntProduct)), "modMulti", "int1", "nomatch", nullptr, nullptr, nullptr));
0735   CPPUNIT_ASSERT(!bh2.isValid());
0736 
0737   std::shared_ptr<Wrapper<edmtest::IntProduct> const> ptr =
0738       getProductByTag<edmtest::IntProduct>(*principal_, inputTag, nullptr);
0739   CPPUNIT_ASSERT(ptr->product()->value == 200);
0740 }
0741 
0742 void testEvent::getByToken() {
0743   typedef edmtest::IntProduct product_t;
0744   typedef std::unique_ptr<product_t> ap_t;
0745   typedef Handle<product_t> handle_t;
0746 
0747   ap_t one(new product_t(1));
0748   ap_t two(new product_t(2));
0749   ap_t three(new product_t(3));
0750   ap_t four(new product_t(4));
0751   addProduct(std::move(one), "int1_tag", "int1");
0752   addProduct(std::move(two), "int2_tag", "int2");
0753   addProduct(std::move(three), "int3_tag");
0754   addProduct(std::move(four), "nolabel_tag");
0755 
0756   auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0757   addProduct(std::move(ap_vthing), "thing", "");
0758 
0759   ap_t oneHundred(new product_t(100));
0760   addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0761 
0762   auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0763   putProduct(std::move(twoHundred), "int1");
0764 
0765   CPPUNIT_ASSERT(currentEvent_->size() == 7);
0766 
0767   IntProductConsumer consumer(std::vector<InputTag>{InputTag("modMulti"),
0768                                                     InputTag("modMulti", "int1"),
0769                                                     InputTag("modMulti", "nomatch"),
0770                                                     InputTag("modMulti", "int1", "EARLY"),
0771                                                     InputTag("modMulti", "int1", "LATE"),
0772                                                     InputTag("modMulti", "int1", "CURRENT"),
0773                                                     InputTag("modMulti", "int2", "EARLY"),
0774                                                     InputTag("modOne")});
0775   consumer.updateLookup(InEvent, principal_->productLookup(), false);
0776 
0777   currentEvent_->setConsumer(&consumer);
0778   edm::EventBase const* eb = currentEvent_.get();
0779 
0780   const auto modMultiToken = consumer.m_tokens[0];
0781   const auto modMultiInt1Token = consumer.m_tokens[1];
0782   const auto modMultinomatchToken = consumer.m_tokens[2];
0783   const auto modMultiInt1EarlyToken = consumer.m_tokens[3];
0784   const auto modMultiInt1LateToken = consumer.m_tokens[4];
0785   const auto modMultiInt1CurrentToken = consumer.m_tokens[5];
0786   const auto modMultiInt2EarlyToken = consumer.m_tokens[6];
0787   const auto modOneToken = consumer.m_tokens[7];
0788 
0789   handle_t h;
0790   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiToken, h));
0791   CPPUNIT_ASSERT(h->value == 3);
0792   CPPUNIT_ASSERT(eb->getByToken(modMultiToken, h));
0793   CPPUNIT_ASSERT(h->value == 3);
0794 
0795   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1Token, h));
0796   CPPUNIT_ASSERT(h->value == 200);
0797   CPPUNIT_ASSERT(eb->getByToken(modMultiInt1Token, h));
0798   CPPUNIT_ASSERT(h->value == 200);
0799 
0800   CPPUNIT_ASSERT(!currentEvent_->getByToken(modMultinomatchToken, h));
0801   CPPUNIT_ASSERT(!h.isValid());
0802   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0803 
0804   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1Token, h));
0805   CPPUNIT_ASSERT(h->value == 200);
0806   CPPUNIT_ASSERT(eb->getByToken(modMultiInt1Token, h));
0807   CPPUNIT_ASSERT(h->value == 200);
0808 
0809   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1EarlyToken, h));
0810   CPPUNIT_ASSERT(h->value == 1);
0811   CPPUNIT_ASSERT(eb->getByToken(modMultiInt1EarlyToken, h));
0812   CPPUNIT_ASSERT(h->value == 1);
0813 
0814   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1LateToken, h));
0815   CPPUNIT_ASSERT(h->value == 100);
0816   CPPUNIT_ASSERT(eb->getByToken(modMultiInt1LateToken, h));
0817   CPPUNIT_ASSERT(h->value == 100);
0818 
0819   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1CurrentToken, h));
0820   CPPUNIT_ASSERT(h->value == 200);
0821   CPPUNIT_ASSERT(eb->getByToken(modMultiInt1CurrentToken, h));
0822   CPPUNIT_ASSERT(h->value == 200);
0823 
0824   CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt2EarlyToken, h));
0825   CPPUNIT_ASSERT(h->value == 2);
0826   CPPUNIT_ASSERT(eb->getByToken(modMultiInt2EarlyToken, h));
0827   CPPUNIT_ASSERT(h->value == 2);
0828 
0829   CPPUNIT_ASSERT(currentEvent_->getByToken(modOneToken, h));
0830   CPPUNIT_ASSERT(h->value == 4);
0831   CPPUNIT_ASSERT(eb->getByToken(modOneToken, h));
0832   CPPUNIT_ASSERT(h->value == 4);
0833 }
0834 
0835 void testEvent::getHandle() {
0836   typedef edmtest::IntProduct product_t;
0837   typedef std::unique_ptr<product_t> ap_t;
0838   typedef Handle<product_t> handle_t;
0839 
0840   ap_t one(new product_t(1));
0841   ap_t two(new product_t(2));
0842   ap_t three(new product_t(3));
0843   ap_t four(new product_t(4));
0844   addProduct(std::move(one), "int1_tag", "int1");
0845   addProduct(std::move(two), "int2_tag", "int2");
0846   addProduct(std::move(three), "int3_tag");
0847   addProduct(std::move(four), "nolabel_tag");
0848 
0849   auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0850   addProduct(std::move(ap_vthing), "thing", "");
0851 
0852   ap_t oneHundred(new product_t(100));
0853   addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0854 
0855   auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0856   putProduct(std::move(twoHundred), "int1");
0857 
0858   CPPUNIT_ASSERT(currentEvent_->size() == 7);
0859 
0860   IntProductConsumer consumer(std::vector<InputTag>{InputTag("modMulti"),
0861                                                     InputTag("modMulti", "int1"),
0862                                                     InputTag("modMulti", "nomatch"),
0863                                                     InputTag("modMulti", "int1", "EARLY"),
0864                                                     InputTag("modMulti", "int1", "LATE"),
0865                                                     InputTag("modMulti", "int1", "CURRENT"),
0866                                                     InputTag("modMulti", "int2", "EARLY"),
0867                                                     InputTag("modOne")});
0868   consumer.updateLookup(InEvent, principal_->productLookup(), false);
0869 
0870   currentEvent_->setConsumer(&consumer);
0871 
0872   const auto modMultiToken = consumer.m_tokens[0];
0873   const auto modMultiInt1Token = consumer.m_tokens[1];
0874   const auto modMultinomatchToken = consumer.m_tokens[2];
0875   const auto modMultiInt1EarlyToken = consumer.m_tokens[3];
0876   const auto modMultiInt1LateToken = consumer.m_tokens[4];
0877   const auto modMultiInt1CurrentToken = consumer.m_tokens[5];
0878   const auto modMultiInt2EarlyToken = consumer.m_tokens[6];
0879   const auto modOneToken = consumer.m_tokens[7];
0880 
0881   handle_t h;
0882   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiToken));
0883   CPPUNIT_ASSERT(h->value == 3);
0884 
0885   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1Token));
0886   CPPUNIT_ASSERT(h->value == 200);
0887 
0888   CPPUNIT_ASSERT(!(h = currentEvent_->getHandle(modMultinomatchToken)));
0889   CPPUNIT_ASSERT(!h.isValid());
0890   CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0891 
0892   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1Token));
0893   CPPUNIT_ASSERT(h->value == 200);
0894 
0895   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1EarlyToken));
0896   CPPUNIT_ASSERT(h->value == 1);
0897 
0898   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1LateToken));
0899   CPPUNIT_ASSERT(h->value == 100);
0900 
0901   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1CurrentToken));
0902   CPPUNIT_ASSERT(h->value == 200);
0903 
0904   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt2EarlyToken));
0905   CPPUNIT_ASSERT(h->value == 2);
0906 
0907   CPPUNIT_ASSERT(h = currentEvent_->getHandle(modOneToken));
0908   CPPUNIT_ASSERT(h->value == 4);
0909 }
0910 
0911 void testEvent::get_product() {
0912   typedef edmtest::IntProduct product_t;
0913   typedef std::unique_ptr<product_t> ap_t;
0914   typedef Handle<product_t> handle_t;
0915 
0916   ap_t one(new product_t(1));
0917   ap_t two(new product_t(2));
0918   ap_t three(new product_t(3));
0919   ap_t four(new product_t(4));
0920   addProduct(std::move(one), "int1_tag", "int1");
0921   addProduct(std::move(two), "int2_tag", "int2");
0922   addProduct(std::move(three), "int3_tag");
0923   addProduct(std::move(four), "nolabel_tag");
0924 
0925   auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0926   addProduct(std::move(ap_vthing), "thing", "");
0927 
0928   ap_t oneHundred(new product_t(100));
0929   addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0930 
0931   auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0932   putProduct(std::move(twoHundred), "int1");
0933 
0934   CPPUNIT_ASSERT(currentEvent_->size() == 7);
0935 
0936   IntProductConsumer consumer(std::vector<InputTag>{InputTag("modMulti"),
0937                                                     InputTag("modMulti", "int1"),
0938                                                     InputTag("modMulti", "nomatch"),
0939                                                     InputTag("modMulti", "int1", "EARLY"),
0940                                                     InputTag("modMulti", "int1", "LATE"),
0941                                                     InputTag("modMulti", "int1", "CURRENT"),
0942                                                     InputTag("modMulti", "int2", "EARLY"),
0943                                                     InputTag("modOne")});
0944   consumer.updateLookup(InEvent, principal_->productLookup(), false);
0945 
0946   currentEvent_->setConsumer(&consumer);
0947 
0948   const auto modMultiToken = consumer.m_tokens[0];
0949   const auto modMultiInt1Token = consumer.m_tokens[1];
0950   const auto modMultinomatchToken = consumer.m_tokens[2];
0951   const auto modMultiInt1EarlyToken = consumer.m_tokens[3];
0952   const auto modMultiInt1LateToken = consumer.m_tokens[4];
0953   const auto modMultiInt1CurrentToken = consumer.m_tokens[5];
0954   const auto modMultiInt2EarlyToken = consumer.m_tokens[6];
0955   const auto modOneToken = consumer.m_tokens[7];
0956 
0957   CPPUNIT_ASSERT(currentEvent_->get(modMultiToken).value == 3);
0958 
0959   CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1Token).value == 200);
0960 
0961   CPPUNIT_ASSERT_THROW(currentEvent_->get(modMultinomatchToken), cms::Exception);
0962 
0963   CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1Token).value == 200);
0964 
0965   CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1EarlyToken).value == 1);
0966 
0967   CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1LateToken).value == 100);
0968 
0969   CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1CurrentToken).value == 200);
0970 
0971   CPPUNIT_ASSERT(currentEvent_->get(modMultiInt2EarlyToken).value == 2);
0972 
0973   CPPUNIT_ASSERT(currentEvent_->get(modOneToken).value == 4);
0974 }
0975 
0976 void testEvent::getManyByType() {
0977   typedef edmtest::IntProduct product_t;
0978   typedef std::unique_ptr<product_t> ap_t;
0979   typedef Handle<product_t> handle_t;
0980   typedef std::vector<handle_t> handle_vec;
0981 
0982   ap_t one(new product_t(1));
0983   ap_t two(new product_t(2));
0984   ap_t three(new product_t(3));
0985   ap_t four(new product_t(4));
0986   addProduct(std::move(one), "int1_tag", "int1");
0987   addProduct(std::move(two), "int2_tag", "int2");
0988   addProduct(std::move(three), "int3_tag");
0989   addProduct(std::move(four), "nolabel_tag");
0990 
0991   auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0992   addProduct(std::move(ap_vthing), "thing", "");
0993 
0994   auto ap_vthing2 = std::make_unique<std::vector<edmtest::Thing>>();
0995   addProduct(std::move(ap_vthing2), "thing2", "inst2");
0996 
0997   ap_t oneHundred(new product_t(100));
0998   addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0999 
1000   auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
1001   putProduct(std::move(twoHundred), "int1");
1002 
1003   CPPUNIT_ASSERT(currentEvent_->size() == 8);
1004 
1005   handle_vec handles;
1006   currentEvent_->getManyByType(handles);
1007   CPPUNIT_ASSERT(handles.size() == 6);
1008   int sum = 0;
1009   for (int k = 0; k < 6; ++k)
1010     sum += handles[k]->value;
1011   CPPUNIT_ASSERT(sum == 310);
1012 }
1013 
1014 void testEvent::printHistory() {
1015   ProcessHistory const& history = currentEvent_->processHistory();
1016   std::ofstream out("history.log");
1017 
1018   copy_all(history, std::ostream_iterator<ProcessHistory::const_iterator::value_type>(out, "\n"));
1019 }
1020 
1021 void testEvent::deleteProduct() {
1022   typedef edmtest::IntProduct product_t;
1023   typedef std::unique_ptr<product_t> ap_t;
1024 
1025   ap_t one(new product_t(1));
1026   addProduct(std::move(one), "int1_tag", "int1");
1027 
1028   BranchID id;
1029 
1030   availableProducts_->callForEachBranch([&id](const BranchDescription& iDesc) {
1031     if (iDesc.moduleLabel() == "modMulti" && iDesc.productInstanceName() == "int1") {
1032       id = iDesc.branchID();
1033     }
1034   });
1035 
1036   const ProductResolverBase* phb = principal_->getProductResolver(id);
1037   CPPUNIT_ASSERT(phb != nullptr);
1038 
1039   CPPUNIT_ASSERT(!phb->productWasDeleted());
1040   principal_->deleteProduct(id);
1041   CPPUNIT_ASSERT(phb->productWasDeleted());
1042 }