Skip to content

Commit

Permalink
Merge pull request #41931 from makortel/refToBaseProdIsAvailable_131x
Browse files Browse the repository at this point in the history
[13_1_X] Add isAvailable() function to RefToBaseProd
  • Loading branch information
cmsbuild authored Jun 13, 2023
2 parents f590b17 + 25cd6c8 commit 3ca1052
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions DataFormats/Common/interface/Ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ namespace edm {

/// Checks if collection is in memory or available
/// in the event. No type checking is done.
/// This function is potentially costly as it might cause a disk
/// read (note that it does not cause the data to be cached locally)
bool isAvailable() const;

/// Checks if this Ptr is transient (i.e. not persistable).
Expand Down
4 changes: 4 additions & 0 deletions DataFormats/Common/interface/Ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ namespace edm {

/// Checks if collection is in memory or available
/// in the Event. No type checking is done.
/// This function is potentially costly as it might cause a disk
/// read (note that it does not cause the data to be cached locally)
bool isAvailable() const;

/// Checks if this ref is transient (i.e. not persistable).
Expand Down Expand Up @@ -404,6 +406,8 @@ namespace edm {

/// Checks if collection is in memory or available
/// in the Event. No type checking is done.
/// This function is potentially costly as it might cause a disk
/// read (note that it does not cause the data to be cached locally)
bool isAvailable() const;

/// Checks if this ref is transient (i.e. not persistable).
Expand Down
3 changes: 2 additions & 1 deletion DataFormats/Common/interface/RefCoreWithIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ namespace edm {

// Checks if collection is in memory or available
// in the Event. No type checking is done.

// This function is potentially costly as it might cause a disk
// read (note that it does not cause the data to be cached locally)
bool isAvailable() const { return toRefCore().isAvailable(); }

//Convert to an equivalent RefCore. Needed for Ref specialization.
Expand Down
2 changes: 2 additions & 0 deletions DataFormats/Common/interface/RefProd.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ namespace edm {

/// Checks if collection is in memory or available
/// in the Event. No type checking is done.
/// This function is potentially costly as it might cause a disk
/// read (note that it does not cause the data to be cached locally)
bool isAvailable() const { return product_.isAvailable(); }

/// Checks if this RefProd is transient (i.e. not persistable).
Expand Down
2 changes: 2 additions & 0 deletions DataFormats/Common/interface/RefToBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ namespace edm {

/// Checks if collection is in memory or available
/// in the Event. No type checking is done.
/// This function is potentially costly as it might cause a disk
/// read (note that it does not cause the data to be cached locally)
bool isAvailable() const { return holder_ ? holder_->isAvailable() : false; }

bool isTransient() const { return holder_ ? holder_->isTransient() : false; }
Expand Down
6 changes: 6 additions & 0 deletions DataFormats/Common/interface/RefToBaseProd.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ namespace edm {
/// Checks for non-null
bool isNonnull() const { return product_.isNonnull(); }

/// Checks if collection is in memory or available
/// in the Event. No type checking is done.
/// This function is potentially costly as it might cause a disk
/// read (note that it does not cause the data to be cached locally)
bool isAvailable() const { return product_.isAvailable(); }

/// Checks for null
bool operator!() const { return isNull(); }

Expand Down
11 changes: 11 additions & 0 deletions DataFormats/Common/test/reftobaseprod_t.cppunit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ void testRefToBaseProd::constructTest() {
CPPUNIT_ASSERT(!nulled);
CPPUNIT_ASSERT(nulled.isNull());
CPPUNIT_ASSERT(!nulled.isNonnull());
CPPUNIT_ASSERT(!nulled.isAvailable());

RefToBaseProd<Dummy> nulledP;
CPPUNIT_ASSERT(!nulledP);
CPPUNIT_ASSERT(nulledP.isNull());
CPPUNIT_ASSERT(!nulledP.isNonnull());
CPPUNIT_ASSERT(!nulledP.isAvailable());

ProductID const pid(1, 1);

Expand All @@ -110,6 +112,9 @@ void testRefToBaseProd::constructTest() {
OrphanHandle<DummyCollection> handle(&dummyContainer, pid);
RefToBaseProd<Dummy> dummyPtr(handle);

CPPUNIT_ASSERT(!dummyPtr.isNull());
CPPUNIT_ASSERT(dummyPtr.isNonnull());
CPPUNIT_ASSERT(dummyPtr.isAvailable());
CPPUNIT_ASSERT(dummyPtr.id() == pid);
compareTo(dummyPtr, dummyContainer);
}
Expand Down Expand Up @@ -218,9 +223,15 @@ void testRefToBaseProd::getTest() {

RefCore core(pid, nullptr, &tester, false);
RefToBaseProd<IntValue>& prod = reinterpret_cast<RefToBaseProd<IntValue>&>(core);
CPPUNIT_ASSERT(!prod.isNull());
CPPUNIT_ASSERT(prod.isNonnull());
CPPUNIT_ASSERT(prod.isAvailable());

//previously making a copy before reading back would cause seg fault
RefToBaseProd<IntValue> prodCopy(prod);
CPPUNIT_ASSERT(!prodCopy.isNull());
CPPUNIT_ASSERT(prodCopy.isNonnull());
CPPUNIT_ASSERT(prodCopy.isAvailable());

CPPUNIT_ASSERT(!prod.hasCache());

Expand Down

0 comments on commit 3ca1052

Please sign in to comment.