Skip to content

Commit

Permalink
Merge CMSSW_10_5_X into CMSSW_10_5_DEVEL_X.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmsbuild committed Feb 7, 2019
2 parents cbe1e7f + 87494bc commit 747d8e0
Show file tree
Hide file tree
Showing 24 changed files with 776 additions and 82 deletions.
8 changes: 1 addition & 7 deletions FWCore/Framework/interface/EDConsumerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,7 @@ namespace edm {
template <typename ESProduct, typename ESRecord, Transition Tr = Transition::Event>
auto esConsumes(ESInputTag const& tag)
{
return ESGetTokenT<ESProduct>{tag};
}

template <typename ESProduct, Transition Tr = Transition::Event>
auto esConsumes(eventsetup::EventSetupRecordKey const&, ESInputTag const& tag)
{
return ESGetTokenT<ESProduct>{tag};
return ESGetToken<ESProduct, ESRecord>{tag};
}

private:
Expand Down
49 changes: 33 additions & 16 deletions FWCore/Framework/interface/ESConsumesCollector.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,49 @@ namespace edm {
ESConsumesCollector& operator=(ESConsumesCollector&&) = default;

// ---------- member functions ---------------------------
template <typename Product>
auto consumes(ESInputTag const& tag) {
return ESGetTokenT<Product>{tag};
}

template <typename Product, typename Record>
auto consumes(ESInputTag const& tag) {
return ESGetTokenT<Product>{tag};
auto consumesFrom(ESInputTag const& tag) {
return ESGetToken<Product,Record>{tag};
}

protected:
explicit ESConsumesCollector(ESProducer* const iConsumer) :
m_consumer{iConsumer}
{}

private:

// ---------- member data --------------------------------
edm::propagate_const<ESProducer*> m_consumer{nullptr};
};

template<typename RECORD>
class ESConsumesCollectorT : public ESConsumesCollector {
public:

ESConsumesCollectorT() = delete;
ESConsumesCollectorT(ESConsumesCollectorT<RECORD> const&) = default;
ESConsumesCollectorT(ESConsumesCollectorT<RECORD>&&) = default;
ESConsumesCollectorT<RECORD>& operator=(ESConsumesCollectorT<RECORD> const&) = default;
ESConsumesCollectorT<RECORD>& operator=(ESConsumesCollectorT<RECORD>&&) = default;

// ---------- member functions ---------------------------

template <typename Product>
auto consumes(eventsetup::EventSetupRecordKey const&, ESInputTag const& tag) {
return ESGetTokenT<Product>{tag};
auto consumes(ESInputTag const& tag) {
return consumesFrom<Product, RECORD>(tag);
}

private:
//only ESProducer is allowed to make an instance of this class
friend class ESProducer;

explicit ESConsumesCollector(ESProducer* const iConsumer) :
m_consumer{iConsumer}
explicit ESConsumesCollectorT(ESProducer* const iConsumer) :
ESConsumesCollector(iConsumer)
{}

// ---------- member data --------------------------------
edm::propagate_const<ESProducer*> m_consumer{nullptr};

};

}


Expand Down
8 changes: 8 additions & 0 deletions FWCore/Framework/interface/ESHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class ESHandleBase {

bool failedToGet() const { return bool(whyFailedFactory_); }

explicit operator bool () const {
return isValid();
}

bool operator!() const {
return not isValid();
}

void swap(ESHandleBase& iOther) {
std::swap(data_, iOther.data_);
std::swap(description_, iOther.description_);
Expand Down
4 changes: 2 additions & 2 deletions FWCore/Framework/interface/ESProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace edm {
method in order to do the registration with the EventSetup
*/
template<typename T, typename TReturn, typename TRecord, typename TArg>
ESConsumesCollector setWhatProduced(T* iThis,
ESConsumesCollectorT<TRecord> setWhatProduced(T* iThis,
TReturn (T ::* iMethod)(const TRecord&),
const TArg& iDec,
const es::Label& iLabel = {}) {
Expand All @@ -164,7 +164,7 @@ namespace edm {
static_cast<const typename eventsetup::produce::product_traits<TReturn>::type *>(nullptr),
static_cast<const TRecord*>(nullptr),
iLabel);
return ESConsumesCollector{iThis};
return ESConsumesCollectorT<TRecord>{iThis};
}

ESProducer(const ESProducer&) = delete; // stop default
Expand Down
78 changes: 78 additions & 0 deletions FWCore/Framework/interface/ESValidHandle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#ifndef FWCore_Framework_ESValidHandle_h
#define FWCore_Framework_ESValidHandle_h
// -*- C++ -*-
//
// Package: Framework
// Class : ESValidHandle
//
/**\class ESValidHandle ESValidHandle.h FWCore/Framework/interface/ESValidHandle.h
Description: <one line class summary>
Usage:
<usage>
*/
//
// Author: Chris Jones
// Created: Tue Feb 5 14:47:35 EST 2019
//

// system include files

// user include files
#include "FWCore/Framework/interface/ComponentDescription.h"

#include <exception>
#include <memory>
#include <utility>

namespace edm {

namespace esvhhelper {
void throwIfNotValid(const void*) noexcept(false);
}

template<typename T>
class ESValidHandle {
public:
typedef T value_type;

ESValidHandle() = delete;
ESValidHandle(T const& iData, edm::eventsetup::ComponentDescription const* desc) noexcept :
data_{&iData},
description_{desc} {}

ESValidHandle(ESValidHandle<T> const&) = default;
ESValidHandle(ESValidHandle<T>&&) = default;
ESValidHandle& operator=(ESValidHandle<T> const&) = default;
ESValidHandle& operator=(ESValidHandle<T>&&) = default;

// ---------- const member functions ---------------------
T const* product() const noexcept { return data_; }
T const* operator->() const noexcept { return product(); }
T const& operator*() const noexcept { return *product(); }
// ---------- static member functions --------------------
static constexpr bool transientAccessOnly = false;

// ---------- member functions ---------------------------
private:
T const* data_{nullptr};
edm::eventsetup::ComponentDescription const* description_{nullptr};

};

/** Take a handle (e.g. edm::ESHandle<T>) and
create a edm::ESValidHandle<T>. If the argument is an invalid handle,
an exception will be thrown.
*/
template<typename U>
auto
makeESValid(const U& iOtherHandleType) noexcept(false) {
esvhhelper::throwIfNotValid(iOtherHandleType.product());
//because of the check, we know this is valid and do not have to check again
return ESValidHandle<typename U::value_type>(*iOtherHandleType.product(), iOtherHandleType.description());
}

}
#endif
27 changes: 22 additions & 5 deletions FWCore/Framework/interface/EventSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
namespace edm {
class ActivityRegistry;
class ESInputTag;
template <class T>
class ESGetTokenT;
template <class T, class R>
class ESGetToken;
class PileUp;

namespace eventsetup {
Expand Down Expand Up @@ -97,9 +97,26 @@ namespace edm {
return rec.get(iTag, iHolder);
}

template <typename T>
bool getData(const ESGetTokenT<T>& iToken, ESHandle<T>& iHolder) const {
return getData(iToken.m_tag, iHolder);
template< typename T, typename R>
T const& getData(const ESGetToken<T, R>& iToken) const noexcept(false) {
return this->get<std::conditional_t<std::is_same_v<R, edm::DefaultRecord>,
eventsetup::default_record_t<ESHandle<T>>,
R>>().get(iToken);
}
template< typename T, typename R>
T const& getData(ESGetToken<T, R>& iToken) const noexcept(false) {
return this->getData( const_cast<const ESGetToken<T,R>&>(iToken));
}

template <typename T, typename R>
ESHandle<T> getHandle(const ESGetToken<T, R>& iToken) const {
if constexpr ( std::is_same_v<R, edm::DefaultRecord> ) {
auto const& rec = this->get<eventsetup::default_record_t<ESHandle<T>>>();
return rec.getHandle(iToken);
} else {
auto const& rec = this->get<R>();
return rec.getHandle(iToken);
}
}

std::optional<eventsetup::EventSetupRecordGeneric> find(const eventsetup::EventSetupRecordKey& iKey) const {
Expand Down
13 changes: 8 additions & 5 deletions FWCore/Framework/interface/EventSetupRecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ namespace edm {
}
}

template<typename T>
bool get(ESGetTokenT<T> const& iToken, ESHandle<T>& iHandle) const {
return get(iToken.m_tag, iHandle);
}

///returns false if no data available for key
bool doGet(DataKey const& aKey, bool aGetTransiently = false) const;

Expand Down Expand Up @@ -188,6 +183,14 @@ namespace edm {
}
protected:

template<typename T, typename R>
ESHandle<T> getHandleImpl(ESGetToken<T,R> const& iToken) const {
ESHandle<T> h;
(void) get(iToken.m_tag, h);
return h;
}


DataProxy const* find(DataKey const& aKey) const ;

EventSetupImpl const& eventSetup() const {
Expand Down
34 changes: 34 additions & 0 deletions FWCore/Framework/interface/EventSetupRecordImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

#include "FWCore/Framework/interface/EventSetupRecord.h"
#include "FWCore/Framework/interface/EventSetupRecordKey.h"
#include "FWCore/Framework/interface/data_default_record_trait.h"
#include "FWCore/Utilities/interface/ESGetToken.h"

// system include files

Expand All @@ -44,6 +46,38 @@ namespace edm {
return EventSetupRecordKey::makeKey<T>();
}

template<typename PRODUCT>
ESHandle<PRODUCT> getHandle(ESGetToken<PRODUCT,T> const& iToken) const {
return getHandleImpl(iToken);
}

template<typename PRODUCT>
ESHandle<PRODUCT> getHandle(ESGetToken<PRODUCT,edm::DefaultRecord> const& iToken) const {
static_assert(std::is_same_v<T, eventsetup::default_record_t<ESHandle<PRODUCT>>>, "The Record being used to retrieve the product is not the default record for the product type");
return getHandleImpl(iToken);
}

using EventSetupRecord::get;

template<typename PRODUCT>
PRODUCT const& get(ESGetToken<PRODUCT,T> const& iToken) const {
return *getHandleImpl(iToken);
}
template<typename PRODUCT>
PRODUCT const& get(ESGetToken<PRODUCT,T>& iToken) const {
return *getHandleImpl(const_cast<const ESGetToken<PRODUCT,T>&>(iToken));
}

template<typename PRODUCT>
PRODUCT const& get(ESGetToken<PRODUCT,edm::DefaultRecord> const& iToken) const {
static_assert(std::is_same_v<T, eventsetup::default_record_t<ESHandle<PRODUCT>>>, "The Record being used to retrieve the product is not the default record for the product type");
return *getHandleImpl(iToken);
}
template<typename PRODUCT>
PRODUCT const& get(ESGetToken<PRODUCT,edm::DefaultRecord>& iToken) const {
return get(const_cast<const ESGetToken<PRODUCT,edm::DefaultRecord>&>(iToken) );
}

// ---------- static member functions --------------------
static EventSetupRecordKey keyForClass() {
return EventSetupRecordKey::makeKey<T>();
Expand Down
11 changes: 11 additions & 0 deletions FWCore/Framework/src/ESValidHandle.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "FWCore/Framework/interface/ESValidHandle.h"
#include "FWCore/Utilities/interface/Exception.h"

namespace edm::esvhhelper {
void
throwIfNotValid(const void* iProduct) noexcept(false) {
if(nullptr == iProduct) {
throw cms::Exception("Invalid Product")<<"Attempted to fill a edm::ESValidHandle with an invalid product";
}
}
}
Loading

0 comments on commit 747d8e0

Please sign in to comment.