File indexing completed on 2024-04-06 12:12:24
0001
0002
0003
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
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 }
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(printHistory);
0109 CPPUNIT_TEST(deleteProduct);
0110 CPPUNIT_TEST_SUITE_END();
0111
0112 public:
0113 testEvent();
0114 ~testEvent();
0115 void setUp();
0116 void tearDown();
0117 void emptyEvent();
0118 void getByLabelFromEmpty();
0119 void getByTokenFromEmpty();
0120 void getHandleFromEmpty();
0121 void getFromEmpty();
0122 void putAnIntProduct();
0123 void putAndGetAnIntProduct();
0124 void putAndGetAnIntProductByToken();
0125 void emplaceAndGetAnIntProductByToken();
0126 void getByProductID();
0127 void transaction();
0128 void getByLabel();
0129 void getByToken();
0130 void getHandle();
0131 void get_product();
0132 void printHistory();
0133 void deleteProduct();
0134
0135 private:
0136 template <class T>
0137 void registerProduct(std::string const& tag,
0138 std::string const& moduleLabel,
0139 std::string const& moduleClassName,
0140 std::string const& processName,
0141 std::string const& productInstanceName);
0142
0143 template <class T>
0144 void registerProduct(std::string const& tag,
0145 std::string const& moduleLabel,
0146 std::string const& moduleClassName,
0147 std::string const& processName) {
0148 std::string productInstanceName;
0149 registerProduct<T>(tag, moduleLabel, moduleClassName, processName, productInstanceName);
0150 }
0151
0152 template <class T>
0153 ProductID addProduct(std::unique_ptr<T> product,
0154 std::string const& tag,
0155 std::string const& productLabel = std::string());
0156
0157 template <class T>
0158 std::unique_ptr<ProducerBase> putProduct(std::unique_ptr<T> product,
0159 std::string const& productInstanceLabel,
0160 bool doCommit = true);
0161 template <class T>
0162 std::unique_ptr<ProducerBase> putProductUsingToken(std::unique_ptr<T> product,
0163 std::string const& productInstanceLabel,
0164 bool doCommit = true);
0165 template <class T>
0166 std::unique_ptr<ProducerBase> emplaceProduct(T product,
0167 std::string const& productInstanceLabel,
0168 bool doCommit = true);
0169
0170 std::shared_ptr<ProductRegistry> availableProducts_;
0171 std::shared_ptr<BranchIDListHelper> branchIDListHelper_;
0172 std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper_;
0173 std::shared_ptr<edm::LuminosityBlockPrincipal> lbp_;
0174 std::shared_ptr<EventPrincipal> principal_;
0175 std::shared_ptr<Event> currentEvent_;
0176 std::shared_ptr<ModuleDescription> currentModuleDescription_;
0177 typedef std::map<std::string, ModuleDescription> modCache_t;
0178 typedef modCache_t::iterator iterator_t;
0179
0180 modCache_t moduleDescriptions_;
0181 ProcessHistoryRegistry processHistoryRegistry_;
0182 std::vector<std::shared_ptr<ProcessConfiguration>> processConfigurations_;
0183 HistoryAppender historyAppender_;
0184 };
0185
0186
0187 CPPUNIT_TEST_SUITE_REGISTRATION(testEvent);
0188
0189 EventID make_id() { return EventID(2112, 1, 25); }
0190 Timestamp make_timestamp() { return Timestamp(1); }
0191
0192 template <class T>
0193 void testEvent::registerProduct(std::string const& tag,
0194 std::string const& moduleLabel,
0195 std::string const& moduleClassName,
0196 std::string const& processName,
0197 std::string const& productInstanceName) {
0198 if (!availableProducts_)
0199 availableProducts_.reset(new ProductRegistry());
0200
0201 ParameterSet moduleParams;
0202 moduleParams.template addParameter<std::string>("@module_type", moduleClassName);
0203 moduleParams.template addParameter<std::string>("@module_label", moduleLabel);
0204 moduleParams.registerIt();
0205
0206 ParameterSet processParams;
0207 processParams.template addParameter<std::string>("@process_name", processName);
0208 processParams.template addParameter<ParameterSet>(moduleLabel, moduleParams);
0209 processParams.registerIt();
0210
0211 ProcessConfiguration process(processName, processParams.id(), getReleaseVersion(), getPassID());
0212
0213 auto processX = std::make_shared<ProcessConfiguration>(process);
0214 processConfigurations_.push_back(processX);
0215
0216 TypeWithDict product_type(typeid(T));
0217
0218 BranchDescription branch(InEvent,
0219 moduleLabel,
0220 processName,
0221 product_type.userClassName(),
0222 product_type.friendlyClassName(),
0223 productInstanceName,
0224 moduleClassName,
0225 moduleParams.id(),
0226 product_type);
0227
0228 moduleDescriptions_[tag] = ModuleDescription(
0229 moduleParams.id(), moduleClassName, moduleLabel, processX.get(), ModuleDescription::getUniqueID());
0230 availableProducts_->addProduct(branch);
0231 }
0232
0233
0234
0235 template <class T>
0236 ProductID testEvent::addProduct(std::unique_ptr<T> product, std::string const& tag, std::string const& productLabel) {
0237 iterator_t description = moduleDescriptions_.find(tag);
0238 if (description == moduleDescriptions_.end())
0239 throw edm::Exception(errors::LogicError) << "Failed to find a module description for tag: " << tag << '\n';
0240
0241 ModuleCallingContext mcc(&description->second);
0242 Event temporaryEvent(*principal_, description->second, &mcc);
0243 TestProducer<T> prod(productLabel);
0244 const_cast<std::vector<edm::ProductResolverIndex>&>(prod.putTokenIndexToProductResolverIndex())
0245 .push_back(principal_->productLookup().index(PRODUCT_TYPE,
0246 edm::TypeID(typeid(T)),
0247 description->second.moduleLabel().c_str(),
0248 productLabel.c_str(),
0249 description->second.processName().c_str()));
0250
0251 temporaryEvent.setProducer(&prod, nullptr);
0252 OrphanHandle<T> h = temporaryEvent.put(std::move(product), productLabel);
0253 ProductID id = h.id();
0254 temporaryEvent.commit_(std::vector<ProductResolverIndex>());
0255 return id;
0256 }
0257
0258 template <class T>
0259 std::unique_ptr<ProducerBase> testEvent::putProduct(std::unique_ptr<T> product,
0260 std::string const& productInstanceLabel,
0261 bool doCommit) {
0262 auto prod = std::make_unique<TestProducer<edmtest::IntProduct>>(productInstanceLabel);
0263 auto index = principal_->productLookup().index(PRODUCT_TYPE,
0264 edm::TypeID(typeid(T)),
0265 currentModuleDescription_->moduleLabel().c_str(),
0266 productInstanceLabel.c_str(),
0267 currentModuleDescription_->processName().c_str());
0268 CPPUNIT_ASSERT(index != std::numeric_limits<unsigned int>::max());
0269 const_cast<std::vector<edm::ProductResolverIndex>&>(prod->putTokenIndexToProductResolverIndex()).push_back(index);
0270 currentEvent_->setProducer(prod.get(), nullptr);
0271 currentEvent_->put(std::move(product), productInstanceLabel);
0272 if (doCommit) {
0273 currentEvent_->commit_(std::vector<ProductResolverIndex>());
0274 }
0275 return prod;
0276 }
0277
0278 template <class T>
0279 std::unique_ptr<ProducerBase> testEvent::putProductUsingToken(std::unique_ptr<T> product,
0280 std::string const& productInstanceLabel,
0281 bool doCommit) {
0282 auto prod = std::make_unique<TestProducer<edmtest::IntProduct>>(productInstanceLabel);
0283 EDPutTokenT<edmtest::IntProduct> token = prod->token_;
0284 auto index = principal_->productLookup().index(PRODUCT_TYPE,
0285 edm::TypeID(typeid(T)),
0286 currentModuleDescription_->moduleLabel().c_str(),
0287 productInstanceLabel.c_str(),
0288 currentModuleDescription_->processName().c_str());
0289 CPPUNIT_ASSERT(index != std::numeric_limits<unsigned int>::max());
0290 const_cast<std::vector<edm::ProductResolverIndex>&>(prod->putTokenIndexToProductResolverIndex()).push_back(index);
0291 currentEvent_->setProducer(prod.get(), nullptr);
0292 currentEvent_->put(token, std::move(product));
0293 if (doCommit) {
0294 currentEvent_->commit_(std::vector<ProductResolverIndex>());
0295 }
0296 return prod;
0297 }
0298
0299 template <class T>
0300 std::unique_ptr<ProducerBase> testEvent::emplaceProduct(T product,
0301 std::string const& productInstanceLabel,
0302 bool doCommit) {
0303 auto prod = std::make_unique<TestProducer<edmtest::IntProduct>>(productInstanceLabel);
0304 EDPutTokenT<edmtest::IntProduct> token = prod->token_;
0305 auto index = principal_->productLookup().index(PRODUCT_TYPE,
0306 edm::TypeID(typeid(T)),
0307 currentModuleDescription_->moduleLabel().c_str(),
0308 productInstanceLabel.c_str(),
0309 currentModuleDescription_->processName().c_str());
0310 CPPUNIT_ASSERT(index != std::numeric_limits<unsigned int>::max());
0311 const_cast<std::vector<edm::ProductResolverIndex>&>(prod->putTokenIndexToProductResolverIndex()).push_back(index);
0312 currentEvent_->setProducer(prod.get(), nullptr);
0313 currentEvent_->emplace(token, std::move(product));
0314 if (doCommit) {
0315 currentEvent_->commit_(std::vector<ProductResolverIndex>());
0316 }
0317 return prod;
0318 }
0319
0320 testEvent::testEvent()
0321 : availableProducts_(new ProductRegistry()),
0322 branchIDListHelper_(new BranchIDListHelper()),
0323 thinnedAssociationsHelper_(new ThinnedAssociationsHelper()),
0324 principal_(),
0325 currentEvent_(),
0326 currentModuleDescription_(),
0327 moduleDescriptions_(),
0328 processHistoryRegistry_(),
0329 processConfigurations_() {
0330 typedef edmtest::IntProduct prod_t;
0331 typedef std::vector<edmtest::Thing> vec_t;
0332
0333 registerProduct<prod_t>("nolabel_tag", "modOne", "IntProducer", "EARLY");
0334 registerProduct<prod_t>("int1_tag", "modMulti", "IntProducer", "EARLY", "int1");
0335 registerProduct<prod_t>("int1_tag_late", "modMulti", "IntProducer", "LATE", "int1");
0336 registerProduct<prod_t>("int2_tag", "modMulti", "IntProducer", "EARLY", "int2");
0337 registerProduct<prod_t>("int3_tag", "modMulti", "IntProducer", "EARLY");
0338 registerProduct<vec_t>("thing", "modthing", "ThingProducer", "LATE");
0339 registerProduct<vec_t>("thing2", "modthing", "ThingProducer", "LATE", "inst2");
0340
0341
0342
0343 ParameterSet moduleParams;
0344 std::string moduleLabel("modMulti");
0345 std::string moduleClassName("IntProducer");
0346 moduleParams.addParameter<std::string>("@module_type", moduleClassName);
0347 moduleParams.addParameter<std::string>("@module_label", moduleLabel);
0348 moduleParams.registerIt();
0349
0350 ParameterSet processParams;
0351 std::string processName("CURRENT");
0352 processParams.addParameter<std::string>("@process_name", processName);
0353 processParams.addParameter(moduleLabel, moduleParams);
0354 processParams.registerIt();
0355
0356 ProcessConfiguration process(processName, processParams.id(), getReleaseVersion(), getPassID());
0357
0358 TypeWithDict product_type(typeid(prod_t));
0359
0360 auto processX = std::make_shared<ProcessConfiguration>(process);
0361 processConfigurations_.push_back(processX);
0362 currentModuleDescription_.reset(new ModuleDescription(
0363 moduleParams.id(), moduleClassName, moduleLabel, processX.get(), ModuleDescription::getUniqueID()));
0364
0365 std::string productInstanceName("int1");
0366
0367 BranchDescription branch(InEvent,
0368 moduleLabel,
0369 processName,
0370 product_type.userClassName(),
0371 product_type.friendlyClassName(),
0372 productInstanceName,
0373 moduleClassName,
0374 moduleParams.id(),
0375 product_type);
0376
0377 availableProducts_->addProduct(branch);
0378
0379
0380 availableProducts_->setFrozen();
0381 branchIDListHelper_->updateFromRegistry(*availableProducts_);
0382 }
0383
0384 testEvent::~testEvent() {}
0385
0386 void testEvent::setUp() {
0387
0388
0389
0390
0391 ParameterSet moduleParamsEarly;
0392 std::string moduleLabelEarly("currentModule");
0393 std::string moduleClassNameEarly("IntProducer");
0394 moduleParamsEarly.addParameter<std::string>("@module_type", moduleClassNameEarly);
0395 moduleParamsEarly.addParameter<std::string>("@module_label", moduleLabelEarly);
0396 moduleParamsEarly.registerIt();
0397
0398 ParameterSet processParamsEarly;
0399 std::string processNameEarly("EARLY");
0400 processParamsEarly.addParameter<std::string>("@process_name", processNameEarly);
0401 processParamsEarly.addParameter(moduleLabelEarly, moduleParamsEarly);
0402 processParamsEarly.registerIt();
0403
0404 ProcessConfiguration processEarly("EARLY", processParamsEarly.id(), getReleaseVersion(), getPassID());
0405
0406 ParameterSet moduleParamsLate;
0407 std::string moduleLabelLate("currentModule");
0408 std::string moduleClassNameLate("IntProducer");
0409 moduleParamsLate.addParameter<std::string>("@module_type", moduleClassNameLate);
0410 moduleParamsLate.addParameter<std::string>("@module_label", moduleLabelLate);
0411 moduleParamsLate.registerIt();
0412
0413 ParameterSet processParamsLate;
0414 std::string processNameLate("LATE");
0415 processParamsLate.addParameter<std::string>("@process_name", processNameLate);
0416 processParamsLate.addParameter(moduleLabelLate, moduleParamsLate);
0417 processParamsLate.registerIt();
0418
0419 ProcessConfiguration processLate("LATE", processParamsLate.id(), getReleaseVersion(), getPassID());
0420
0421 auto processHistory = std::make_unique<ProcessHistory>();
0422 ProcessHistory& ph = *processHistory;
0423 processHistory->push_back(processEarly);
0424 processHistory->push_back(processLate);
0425
0426 processHistoryRegistry_.registerProcessHistory(ph);
0427
0428 ProcessHistoryID processHistoryID = ph.id();
0429
0430
0431
0432
0433
0434
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445 std::shared_ptr<ProductRegistry const> preg(availableProducts_);
0446 std::string uuid = createGlobalIdentifier();
0447 Timestamp time = make_timestamp();
0448 EventID id = make_id();
0449 ProcessConfiguration const& pc = currentModuleDescription_->processConfiguration();
0450 auto rp = std::make_shared<RunPrincipal>(preg, pc, &historyAppender_, 0);
0451 rp->setAux(RunAuxiliary(id.run(), time, time));
0452 lbp_ = std::make_shared<LuminosityBlockPrincipal>(preg, pc, &historyAppender_, 0);
0453 lbp_->setAux(LuminosityBlockAuxiliary(rp->run(), 1, time, time));
0454 lbp_->setRunPrincipal(rp);
0455 EventAuxiliary eventAux(id, uuid, time, true);
0456 const_cast<ProcessHistoryID&>(eventAux.processHistoryID()) = processHistoryID;
0457 principal_.reset(new edm::EventPrincipal(
0458 preg, branchIDListHelper_, thinnedAssociationsHelper_, pc, &historyAppender_, edm::StreamID::invalidStreamID()));
0459 principal_->fillEventPrincipal(eventAux, processHistoryRegistry_.getMapped(eventAux.processHistoryID()));
0460 principal_->setLuminosityBlockPrincipal(lbp_.get());
0461 ModuleCallingContext mcc(currentModuleDescription_.get());
0462 currentEvent_.reset(new Event(*principal_, *currentModuleDescription_, &mcc));
0463 }
0464
0465 void testEvent::tearDown() {
0466 currentEvent_.reset();
0467 principal_.reset();
0468 }
0469
0470 void testEvent::emptyEvent() {
0471 CPPUNIT_ASSERT(currentEvent_);
0472 CPPUNIT_ASSERT(currentEvent_->id() == make_id());
0473 CPPUNIT_ASSERT(currentEvent_->time() == make_timestamp());
0474 CPPUNIT_ASSERT(currentEvent_->size() == 0);
0475 }
0476
0477 void testEvent::getByLabelFromEmpty() {
0478 InputTag inputTag("moduleLabel", "instanceName");
0479 Handle<int> nonesuch;
0480 CPPUNIT_ASSERT(!nonesuch.isValid());
0481 CPPUNIT_ASSERT(!currentEvent_->getByLabel(inputTag, nonesuch));
0482 CPPUNIT_ASSERT(!nonesuch.isValid());
0483 CPPUNIT_ASSERT(nonesuch.failedToGet());
0484 CPPUNIT_ASSERT_THROW(*nonesuch, cms::Exception);
0485 }
0486
0487 void testEvent::getByTokenFromEmpty() {
0488 InputTag inputTag("moduleLabel", "instanceName");
0489
0490 IntConsumer consumer(std::vector<InputTag>{1, inputTag});
0491 consumer.updateLookup(InEvent, principal_->productLookup(), false);
0492 assert(1 == consumer.m_tokens.size());
0493 currentEvent_->setConsumer(&consumer);
0494 Handle<int> nonesuch;
0495 CPPUNIT_ASSERT(!nonesuch.isValid());
0496 CPPUNIT_ASSERT(!currentEvent_->getByToken(consumer.m_tokens[0], nonesuch));
0497 CPPUNIT_ASSERT(!nonesuch.isValid());
0498 CPPUNIT_ASSERT(nonesuch.failedToGet());
0499 CPPUNIT_ASSERT_THROW(*nonesuch, cms::Exception);
0500
0501 {
0502 edm::EventBase const* eb = currentEvent_.get();
0503 Handle<int> nonesuch;
0504 CPPUNIT_ASSERT(!nonesuch.isValid());
0505 CPPUNIT_ASSERT(!eb->getByToken(consumer.m_tokens[0], nonesuch));
0506 CPPUNIT_ASSERT(!nonesuch.isValid());
0507 CPPUNIT_ASSERT(nonesuch.failedToGet());
0508 CPPUNIT_ASSERT_THROW(*nonesuch, cms::Exception);
0509 }
0510 }
0511
0512 void testEvent::getHandleFromEmpty() {
0513 InputTag inputTag("moduleLabel", "instanceName");
0514
0515 IntConsumer consumer(std::vector<InputTag>{1, inputTag});
0516 consumer.updateLookup(InEvent, principal_->productLookup(), false);
0517 assert(1 == consumer.m_tokens.size());
0518 currentEvent_->setConsumer(&consumer);
0519 Handle<int> nonesuch;
0520 CPPUNIT_ASSERT(!(nonesuch = currentEvent_->getHandle(consumer.m_tokens[0])));
0521 CPPUNIT_ASSERT(!nonesuch.isValid());
0522 CPPUNIT_ASSERT(nonesuch.failedToGet());
0523 CPPUNIT_ASSERT_THROW(*nonesuch, cms::Exception);
0524 }
0525
0526 void testEvent::getFromEmpty() {
0527 InputTag inputTag("moduleLabel", "instanceName");
0528
0529 IntConsumer consumer(std::vector<InputTag>{1, inputTag});
0530 consumer.updateLookup(InEvent, principal_->productLookup(), false);
0531 assert(1 == consumer.m_tokens.size());
0532 currentEvent_->setConsumer(&consumer);
0533 CPPUNIT_ASSERT_THROW((void)currentEvent_->get(consumer.m_tokens[0]), cms::Exception);
0534 }
0535
0536 void testEvent::putAnIntProduct() {
0537 auto p = putProduct(std::make_unique<edmtest::IntProduct>(3), "int1", false);
0538 CPPUNIT_ASSERT(currentEvent_->size() == 1);
0539 currentEvent_->commit_(std::vector<ProductResolverIndex>());
0540 CPPUNIT_ASSERT(currentEvent_->size() == 1);
0541 }
0542
0543 void testEvent::putAndGetAnIntProduct() {
0544 auto p = putProduct(std::make_unique<edmtest::IntProduct>(4), "int1");
0545
0546 InputTag should_match("modMulti", "int1", "CURRENT");
0547 InputTag should_not_match("modMulti", "int1", "NONESUCH");
0548 Handle<edmtest::IntProduct> h;
0549 currentEvent_->getByLabel(should_match, h);
0550 CPPUNIT_ASSERT(h.isValid());
0551 CPPUNIT_ASSERT(!currentEvent_->getByLabel(should_not_match, h));
0552 CPPUNIT_ASSERT(!h.isValid());
0553 CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0554 }
0555
0556 void testEvent::putAndGetAnIntProductByToken() {
0557 auto p = putProductUsingToken(std::make_unique<edmtest::IntProduct>(4), "int1");
0558
0559 InputTag should_match("modMulti", "int1", "CURRENT");
0560 InputTag should_not_match("modMulti", "int1", "NONESUCH");
0561 Handle<edmtest::IntProduct> h;
0562 currentEvent_->getByLabel(should_match, h);
0563 CPPUNIT_ASSERT(h.isValid());
0564 CPPUNIT_ASSERT(!currentEvent_->getByLabel(should_not_match, h));
0565 CPPUNIT_ASSERT(!h.isValid());
0566 CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0567 }
0568
0569 void testEvent::emplaceAndGetAnIntProductByToken() {
0570 auto p = emplaceProduct(edmtest::IntProduct{4}, "int1");
0571
0572 InputTag should_match("modMulti", "int1", "CURRENT");
0573 InputTag should_not_match("modMulti", "int1", "NONESUCH");
0574 Handle<edmtest::IntProduct> h;
0575 currentEvent_->getByLabel(should_match, h);
0576 CPPUNIT_ASSERT(h.isValid());
0577 CPPUNIT_ASSERT(!currentEvent_->getByLabel(should_not_match, h));
0578 CPPUNIT_ASSERT(!h.isValid());
0579 CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0580 }
0581
0582 void testEvent::getByProductID() {
0583 typedef edmtest::IntProduct product_t;
0584 typedef std::unique_ptr<product_t> ap_t;
0585 typedef Handle<product_t> handle_t;
0586
0587 ProductID wanted;
0588
0589 {
0590 ap_t one(new product_t(1));
0591 ProductID id1 = addProduct(std::move(one), "int1_tag", "int1");
0592 CPPUNIT_ASSERT(id1 != ProductID());
0593 wanted = id1;
0594
0595 ap_t two(new product_t(2));
0596 ProductID id2 = addProduct(std::move(two), "int2_tag", "int2");
0597 CPPUNIT_ASSERT(id2 != ProductID());
0598 CPPUNIT_ASSERT(id2 != id1);
0599
0600 currentEvent_->commit_(std::vector<ProductResolverIndex>());
0601 CPPUNIT_ASSERT(currentEvent_->size() == 2);
0602 }
0603
0604 handle_t h;
0605 currentEvent_->get(wanted, h);
0606 CPPUNIT_ASSERT(h.isValid());
0607 CPPUNIT_ASSERT(h.id() == wanted);
0608 CPPUNIT_ASSERT(h->value == 1);
0609
0610 ProductID invalid;
0611 CPPUNIT_ASSERT_THROW(currentEvent_->get(invalid, h), cms::Exception);
0612 CPPUNIT_ASSERT(!h.isValid());
0613 ProductID notpresent(0, std::numeric_limits<unsigned short>::max());
0614 CPPUNIT_ASSERT(!currentEvent_->get(notpresent, h));
0615 CPPUNIT_ASSERT(!h.isValid());
0616 CPPUNIT_ASSERT(h.failedToGet());
0617 CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0618
0619 edm::EventBase* baseEvent = currentEvent_.get();
0620 handle_t h1;
0621 baseEvent->get(wanted, h1);
0622 CPPUNIT_ASSERT(h1.isValid());
0623 CPPUNIT_ASSERT(h1.id() == wanted);
0624 CPPUNIT_ASSERT(h1->value == 1);
0625
0626 CPPUNIT_ASSERT_THROW(baseEvent->get(invalid, h1), cms::Exception);
0627 CPPUNIT_ASSERT(!h1.isValid());
0628 CPPUNIT_ASSERT(!baseEvent->get(notpresent, h1));
0629 CPPUNIT_ASSERT(!h1.isValid());
0630 CPPUNIT_ASSERT(h1.failedToGet());
0631 CPPUNIT_ASSERT_THROW(*h1, cms::Exception);
0632 }
0633
0634 void testEvent::transaction() {
0635
0636
0637 CPPUNIT_ASSERT(principal_->size() == 0);
0638 {
0639 typedef edmtest::IntProduct product_t;
0640 typedef std::unique_ptr<product_t> ap_t;
0641
0642 ap_t three(new product_t(3));
0643 auto p = putProduct(std::move(three), "int1", false);
0644
0645 CPPUNIT_ASSERT(principal_->size() == 0);
0646 CPPUNIT_ASSERT(currentEvent_->size() == 1);
0647
0648 }
0649
0650
0651
0652 CPPUNIT_ASSERT(principal_->size() == 0);
0653 }
0654
0655 void testEvent::getByLabel() {
0656 typedef edmtest::IntProduct product_t;
0657 typedef std::unique_ptr<product_t> ap_t;
0658 typedef Handle<product_t> handle_t;
0659
0660 ap_t one(new product_t(1));
0661 ap_t two(new product_t(2));
0662 ap_t three(new product_t(3));
0663 ap_t four(new product_t(4));
0664 addProduct(std::move(one), "int1_tag", "int1");
0665 addProduct(std::move(two), "int2_tag", "int2");
0666 addProduct(std::move(three), "int3_tag");
0667 addProduct(std::move(four), "nolabel_tag");
0668
0669 auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0670 addProduct(std::move(ap_vthing), "thing", "");
0671
0672 ap_t oneHundred(new product_t(100));
0673 addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0674
0675 auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0676 putProduct(std::move(twoHundred), "int1");
0677
0678 CPPUNIT_ASSERT(currentEvent_->size() == 7);
0679
0680 handle_t h;
0681 CPPUNIT_ASSERT(currentEvent_->getByLabel("modMulti", h));
0682 CPPUNIT_ASSERT(h->value == 3);
0683
0684 CPPUNIT_ASSERT(currentEvent_->getByLabel("modMulti", "int1", h));
0685 CPPUNIT_ASSERT(h->value == 200);
0686
0687 CPPUNIT_ASSERT(!currentEvent_->getByLabel("modMulti", "nomatch", h));
0688 CPPUNIT_ASSERT(!h.isValid());
0689 CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0690
0691 InputTag inputTag("modMulti", "int1");
0692 CPPUNIT_ASSERT(currentEvent_->getByLabel(inputTag, h));
0693 CPPUNIT_ASSERT(h->value == 200);
0694
0695 CPPUNIT_ASSERT(currentEvent_->getByLabel("modMulti", "int1", h));
0696 CPPUNIT_ASSERT(h->value == 200);
0697
0698 InputTag tag1("modMulti", "int1", "EARLY");
0699 CPPUNIT_ASSERT(currentEvent_->getByLabel(tag1, h));
0700 CPPUNIT_ASSERT(h->value == 1);
0701
0702 InputTag tag2("modMulti", "int1", "LATE");
0703 CPPUNIT_ASSERT(currentEvent_->getByLabel(tag2, h));
0704 CPPUNIT_ASSERT(h->value == 100);
0705
0706 InputTag tag3("modMulti", "int1", "CURRENT");
0707 CPPUNIT_ASSERT(currentEvent_->getByLabel(tag3, h));
0708 CPPUNIT_ASSERT(h->value == 200);
0709
0710 InputTag tag4("modMulti", "int2", "EARLY");
0711 CPPUNIT_ASSERT(currentEvent_->getByLabel(tag4, h));
0712 CPPUNIT_ASSERT(h->value == 2);
0713
0714 InputTag tag5("modOne");
0715 CPPUNIT_ASSERT(currentEvent_->getByLabel(tag5, h));
0716 CPPUNIT_ASSERT(h->value == 4);
0717
0718 CPPUNIT_ASSERT(currentEvent_->getByLabel("modOne", h));
0719 CPPUNIT_ASSERT(h->value == 4);
0720
0721 {
0722 edm::EventBase* baseEvent = currentEvent_.get();
0723 CPPUNIT_ASSERT(baseEvent->getByLabel(inputTag, h));
0724 CPPUNIT_ASSERT(h->value == 200);
0725 }
0726
0727 BasicHandle bh = principal_->getByLabel(
0728 PRODUCT_TYPE, TypeID(typeid(edmtest::IntProduct)), "modMulti", "int1", "LATE", nullptr, nullptr, nullptr);
0729 h = convert_handle<product_t>(std::move(bh));
0730 CPPUNIT_ASSERT(h->value == 100);
0731 BasicHandle bh2(principal_->getByLabel(
0732 PRODUCT_TYPE, TypeID(typeid(edmtest::IntProduct)), "modMulti", "int1", "nomatch", nullptr, nullptr, nullptr));
0733 CPPUNIT_ASSERT(!bh2.isValid());
0734
0735 std::shared_ptr<Wrapper<edmtest::IntProduct> const> ptr =
0736 getProductByTag<edmtest::IntProduct>(*principal_, inputTag, nullptr);
0737 CPPUNIT_ASSERT(ptr->product()->value == 200);
0738 }
0739
0740 void testEvent::getByToken() {
0741 typedef edmtest::IntProduct product_t;
0742 typedef std::unique_ptr<product_t> ap_t;
0743 typedef Handle<product_t> handle_t;
0744
0745 ap_t one(new product_t(1));
0746 ap_t two(new product_t(2));
0747 ap_t three(new product_t(3));
0748 ap_t four(new product_t(4));
0749 addProduct(std::move(one), "int1_tag", "int1");
0750 addProduct(std::move(two), "int2_tag", "int2");
0751 addProduct(std::move(three), "int3_tag");
0752 addProduct(std::move(four), "nolabel_tag");
0753
0754 auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0755 addProduct(std::move(ap_vthing), "thing", "");
0756
0757 ap_t oneHundred(new product_t(100));
0758 addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0759
0760 auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0761 putProduct(std::move(twoHundred), "int1");
0762
0763 CPPUNIT_ASSERT(currentEvent_->size() == 7);
0764
0765 IntProductConsumer consumer(std::vector<InputTag>{InputTag("modMulti"),
0766 InputTag("modMulti", "int1"),
0767 InputTag("modMulti", "nomatch"),
0768 InputTag("modMulti", "int1", "EARLY"),
0769 InputTag("modMulti", "int1", "LATE"),
0770 InputTag("modMulti", "int1", "CURRENT"),
0771 InputTag("modMulti", "int2", "EARLY"),
0772 InputTag("modOne")});
0773 consumer.updateLookup(InEvent, principal_->productLookup(), false);
0774
0775 currentEvent_->setConsumer(&consumer);
0776 edm::EventBase const* eb = currentEvent_.get();
0777
0778 const auto modMultiToken = consumer.m_tokens[0];
0779 const auto modMultiInt1Token = consumer.m_tokens[1];
0780 const auto modMultinomatchToken = consumer.m_tokens[2];
0781 const auto modMultiInt1EarlyToken = consumer.m_tokens[3];
0782 const auto modMultiInt1LateToken = consumer.m_tokens[4];
0783 const auto modMultiInt1CurrentToken = consumer.m_tokens[5];
0784 const auto modMultiInt2EarlyToken = consumer.m_tokens[6];
0785 const auto modOneToken = consumer.m_tokens[7];
0786
0787 handle_t h;
0788 CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiToken, h));
0789 CPPUNIT_ASSERT(h->value == 3);
0790 CPPUNIT_ASSERT(eb->getByToken(modMultiToken, h));
0791 CPPUNIT_ASSERT(h->value == 3);
0792
0793 CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1Token, h));
0794 CPPUNIT_ASSERT(h->value == 200);
0795 CPPUNIT_ASSERT(eb->getByToken(modMultiInt1Token, h));
0796 CPPUNIT_ASSERT(h->value == 200);
0797
0798 CPPUNIT_ASSERT(!currentEvent_->getByToken(modMultinomatchToken, h));
0799 CPPUNIT_ASSERT(!h.isValid());
0800 CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0801
0802 CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1Token, h));
0803 CPPUNIT_ASSERT(h->value == 200);
0804 CPPUNIT_ASSERT(eb->getByToken(modMultiInt1Token, h));
0805 CPPUNIT_ASSERT(h->value == 200);
0806
0807 CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1EarlyToken, h));
0808 CPPUNIT_ASSERT(h->value == 1);
0809 CPPUNIT_ASSERT(eb->getByToken(modMultiInt1EarlyToken, h));
0810 CPPUNIT_ASSERT(h->value == 1);
0811
0812 CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1LateToken, h));
0813 CPPUNIT_ASSERT(h->value == 100);
0814 CPPUNIT_ASSERT(eb->getByToken(modMultiInt1LateToken, h));
0815 CPPUNIT_ASSERT(h->value == 100);
0816
0817 CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt1CurrentToken, h));
0818 CPPUNIT_ASSERT(h->value == 200);
0819 CPPUNIT_ASSERT(eb->getByToken(modMultiInt1CurrentToken, h));
0820 CPPUNIT_ASSERT(h->value == 200);
0821
0822 CPPUNIT_ASSERT(currentEvent_->getByToken(modMultiInt2EarlyToken, h));
0823 CPPUNIT_ASSERT(h->value == 2);
0824 CPPUNIT_ASSERT(eb->getByToken(modMultiInt2EarlyToken, h));
0825 CPPUNIT_ASSERT(h->value == 2);
0826
0827 CPPUNIT_ASSERT(currentEvent_->getByToken(modOneToken, h));
0828 CPPUNIT_ASSERT(h->value == 4);
0829 CPPUNIT_ASSERT(eb->getByToken(modOneToken, h));
0830 CPPUNIT_ASSERT(h->value == 4);
0831 }
0832
0833 void testEvent::getHandle() {
0834 typedef edmtest::IntProduct product_t;
0835 typedef std::unique_ptr<product_t> ap_t;
0836 typedef Handle<product_t> handle_t;
0837
0838 ap_t one(new product_t(1));
0839 ap_t two(new product_t(2));
0840 ap_t three(new product_t(3));
0841 ap_t four(new product_t(4));
0842 addProduct(std::move(one), "int1_tag", "int1");
0843 addProduct(std::move(two), "int2_tag", "int2");
0844 addProduct(std::move(three), "int3_tag");
0845 addProduct(std::move(four), "nolabel_tag");
0846
0847 auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0848 addProduct(std::move(ap_vthing), "thing", "");
0849
0850 ap_t oneHundred(new product_t(100));
0851 addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0852
0853 auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0854 putProduct(std::move(twoHundred), "int1");
0855
0856 CPPUNIT_ASSERT(currentEvent_->size() == 7);
0857
0858 IntProductConsumer consumer(std::vector<InputTag>{InputTag("modMulti"),
0859 InputTag("modMulti", "int1"),
0860 InputTag("modMulti", "nomatch"),
0861 InputTag("modMulti", "int1", "EARLY"),
0862 InputTag("modMulti", "int1", "LATE"),
0863 InputTag("modMulti", "int1", "CURRENT"),
0864 InputTag("modMulti", "int2", "EARLY"),
0865 InputTag("modOne")});
0866 consumer.updateLookup(InEvent, principal_->productLookup(), false);
0867
0868 currentEvent_->setConsumer(&consumer);
0869
0870 const auto modMultiToken = consumer.m_tokens[0];
0871 const auto modMultiInt1Token = consumer.m_tokens[1];
0872 const auto modMultinomatchToken = consumer.m_tokens[2];
0873 const auto modMultiInt1EarlyToken = consumer.m_tokens[3];
0874 const auto modMultiInt1LateToken = consumer.m_tokens[4];
0875 const auto modMultiInt1CurrentToken = consumer.m_tokens[5];
0876 const auto modMultiInt2EarlyToken = consumer.m_tokens[6];
0877 const auto modOneToken = consumer.m_tokens[7];
0878
0879 handle_t h;
0880 CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiToken));
0881 CPPUNIT_ASSERT(h->value == 3);
0882
0883 CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1Token));
0884 CPPUNIT_ASSERT(h->value == 200);
0885
0886 CPPUNIT_ASSERT(!(h = currentEvent_->getHandle(modMultinomatchToken)));
0887 CPPUNIT_ASSERT(!h.isValid());
0888 CPPUNIT_ASSERT_THROW(*h, cms::Exception);
0889
0890 CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1Token));
0891 CPPUNIT_ASSERT(h->value == 200);
0892
0893 CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1EarlyToken));
0894 CPPUNIT_ASSERT(h->value == 1);
0895
0896 CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1LateToken));
0897 CPPUNIT_ASSERT(h->value == 100);
0898
0899 CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt1CurrentToken));
0900 CPPUNIT_ASSERT(h->value == 200);
0901
0902 CPPUNIT_ASSERT(h = currentEvent_->getHandle(modMultiInt2EarlyToken));
0903 CPPUNIT_ASSERT(h->value == 2);
0904
0905 CPPUNIT_ASSERT(h = currentEvent_->getHandle(modOneToken));
0906 CPPUNIT_ASSERT(h->value == 4);
0907 }
0908
0909 void testEvent::get_product() {
0910 typedef edmtest::IntProduct product_t;
0911 typedef std::unique_ptr<product_t> ap_t;
0912 typedef Handle<product_t> handle_t;
0913
0914 ap_t one(new product_t(1));
0915 ap_t two(new product_t(2));
0916 ap_t three(new product_t(3));
0917 ap_t four(new product_t(4));
0918 addProduct(std::move(one), "int1_tag", "int1");
0919 addProduct(std::move(two), "int2_tag", "int2");
0920 addProduct(std::move(three), "int3_tag");
0921 addProduct(std::move(four), "nolabel_tag");
0922
0923 auto ap_vthing = std::make_unique<std::vector<edmtest::Thing>>();
0924 addProduct(std::move(ap_vthing), "thing", "");
0925
0926 ap_t oneHundred(new product_t(100));
0927 addProduct(std::move(oneHundred), "int1_tag_late", "int1");
0928
0929 auto twoHundred = std::make_unique<edmtest::IntProduct>(200);
0930 putProduct(std::move(twoHundred), "int1");
0931
0932 CPPUNIT_ASSERT(currentEvent_->size() == 7);
0933
0934 IntProductConsumer consumer(std::vector<InputTag>{InputTag("modMulti"),
0935 InputTag("modMulti", "int1"),
0936 InputTag("modMulti", "nomatch"),
0937 InputTag("modMulti", "int1", "EARLY"),
0938 InputTag("modMulti", "int1", "LATE"),
0939 InputTag("modMulti", "int1", "CURRENT"),
0940 InputTag("modMulti", "int2", "EARLY"),
0941 InputTag("modOne")});
0942 consumer.updateLookup(InEvent, principal_->productLookup(), false);
0943
0944 currentEvent_->setConsumer(&consumer);
0945
0946 const auto modMultiToken = consumer.m_tokens[0];
0947 const auto modMultiInt1Token = consumer.m_tokens[1];
0948 const auto modMultinomatchToken = consumer.m_tokens[2];
0949 const auto modMultiInt1EarlyToken = consumer.m_tokens[3];
0950 const auto modMultiInt1LateToken = consumer.m_tokens[4];
0951 const auto modMultiInt1CurrentToken = consumer.m_tokens[5];
0952 const auto modMultiInt2EarlyToken = consumer.m_tokens[6];
0953 const auto modOneToken = consumer.m_tokens[7];
0954
0955 CPPUNIT_ASSERT(currentEvent_->get(modMultiToken).value == 3);
0956
0957 CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1Token).value == 200);
0958
0959 CPPUNIT_ASSERT_THROW(currentEvent_->get(modMultinomatchToken), cms::Exception);
0960
0961 CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1Token).value == 200);
0962
0963 CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1EarlyToken).value == 1);
0964
0965 CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1LateToken).value == 100);
0966
0967 CPPUNIT_ASSERT(currentEvent_->get(modMultiInt1CurrentToken).value == 200);
0968
0969 CPPUNIT_ASSERT(currentEvent_->get(modMultiInt2EarlyToken).value == 2);
0970
0971 CPPUNIT_ASSERT(currentEvent_->get(modOneToken).value == 4);
0972 }
0973
0974 void testEvent::printHistory() {
0975 ProcessHistory const& history = currentEvent_->processHistory();
0976 std::ofstream out("history.log");
0977
0978 copy_all(history, std::ostream_iterator<ProcessHistory::const_iterator::value_type>(out, "\n"));
0979 }
0980
0981 void testEvent::deleteProduct() {
0982 typedef edmtest::IntProduct product_t;
0983 typedef std::unique_ptr<product_t> ap_t;
0984
0985 ap_t one(new product_t(1));
0986 addProduct(std::move(one), "int1_tag", "int1");
0987
0988 BranchID id;
0989
0990 availableProducts_->callForEachBranch([&id](const BranchDescription& iDesc) {
0991 if (iDesc.moduleLabel() == "modMulti" && iDesc.productInstanceName() == "int1") {
0992 id = iDesc.branchID();
0993 }
0994 });
0995
0996 const ProductResolverBase* phb = principal_->getProductResolver(id);
0997 CPPUNIT_ASSERT(phb != nullptr);
0998
0999 CPPUNIT_ASSERT(!phb->productWasDeleted());
1000 principal_->deleteProduct(id);
1001 CPPUNIT_ASSERT(phb->productWasDeleted());
1002 }