Skip to content

Commit

Permalink
Merge pull request #20595 from Dr15Jones/putToken
Browse files Browse the repository at this point in the history
Add put interface using EDPutToken
  • Loading branch information
cmsbuild committed Sep 22, 2017
2 parents 92082ad + 1a84f55 commit 2ca3a4d
Show file tree
Hide file tree
Showing 25 changed files with 318 additions and 48 deletions.
24 changes: 24 additions & 0 deletions FWCore/Framework/interface/Event.h
Expand Up @@ -35,6 +35,7 @@ For its usage, see "FWCore/Framework/interface/PrincipalGetAdapter.h"
#include "FWCore/Framework/interface/PrincipalGetAdapter.h"
#include "FWCore/Utilities/interface/TypeID.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/EDPutToken.h"
#include "FWCore/Utilities/interface/ProductKindOfType.h"
#include "FWCore/Utilities/interface/StreamID.h"
#include "FWCore/Utilities/interface/propagate_const.h"
Expand All @@ -59,6 +60,7 @@ namespace edm {
class EDProductGetter;
class ProducerBase;
class SharedResourcesAcquirer;

namespace stream {
template< typename T> class ProducingModuleAdaptorBase;
}
Expand All @@ -73,6 +75,8 @@ namespace edm {
void setConsumer(EDConsumerBase const* iConsumer);

void setSharedResourcesAcquirer( SharedResourcesAcquirer* iResourceAcquirer);

void setProducer( ProducerBase const* iProd);

// AUX functions are defined in EventBase
EventAuxiliary const& eventAuxiliary() const override {return aux_;}
Expand Down Expand Up @@ -126,6 +130,14 @@ namespace edm {
OrphanHandle<PROD>
put(std::unique_ptr<PROD> product, std::string const& productInstanceName);

template<typename PROD>
OrphanHandle<PROD>
put(EDPutToken token, std::unique_ptr<PROD> product);

template<typename PROD>
OrphanHandle<PROD>
put(EDPutTokenT<PROD> token, std::unique_ptr<PROD> product);

///Returns a RefProd to a product before that product has been placed into the Event.
/// The RefProd (and any Ref's made from it) will no work properly until after the
/// Event has been committed (which happens after leaving the EDProducer::produce method)
Expand Down Expand Up @@ -400,6 +412,18 @@ namespace edm {
return(OrphanHandle<PROD>(prod, makeProductID(desc)));
}

template<typename PROD>
OrphanHandle<PROD>
Event::put(EDPutTokenT<PROD> token, std::unique_ptr<PROD> product) {
return put(std::move(product), provRecorder_.productInstanceLabel(token));
}

template<typename PROD>
OrphanHandle<PROD>
Event::put(EDPutToken token, std::unique_ptr<PROD> product) {
return put(std::move(product), provRecorder_.productInstanceLabel(token));
}

template<typename PROD>
RefProd<PROD>
Event::getRefBeforePut(std::string const& productInstanceName) {
Expand Down
23 changes: 23 additions & 0 deletions FWCore/Framework/interface/LuminosityBlock.h
Expand Up @@ -23,6 +23,7 @@ For its usage, see "FWCore/Framework/interface/PrincipalGetAdapter.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/PrincipalGetAdapter.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/EDPutToken.h"
#include "FWCore/Utilities/interface/ProductKindOfType.h"
#include "FWCore/Utilities/interface/LuminosityBlockIndex.h"
#include "FWCore/Utilities/interface/propagate_const.h"
Expand Down Expand Up @@ -70,6 +71,8 @@ namespace edm {

void setSharedResourcesAcquirer( SharedResourcesAcquirer* iResourceAcquirer);

void setProducer(ProducerBase const* iProducer);

template <typename PROD>
bool
getByLabel(std::string const& label, Handle<PROD>& result) const;
Expand Down Expand Up @@ -113,6 +116,14 @@ namespace edm {
void
put(std::unique_ptr<PROD> product, std::string const& productInstanceName);

template<typename PROD>
void
put(EDPutToken token, std::unique_ptr<PROD> product);

template<typename PROD>
void
put(EDPutTokenT<PROD> token, std::unique_ptr<PROD> product);

Provenance
getProvenance(BranchID const& theID) const;

Expand Down Expand Up @@ -185,6 +196,18 @@ namespace edm {
// The old copy must be deleted, so we cannot release ownership.
}

template<typename PROD>
void
LuminosityBlock::put(EDPutTokenT<PROD> token, std::unique_ptr<PROD> product) {
put(std::move(product), provRecorder_.productInstanceLabel(token));
}

template<typename PROD>
void
LuminosityBlock::put(EDPutToken token, std::unique_ptr<PROD> product) {
put(std::move(product), provRecorder_.productInstanceLabel(token));
}

template<typename PROD>
bool
LuminosityBlock::getByLabel(std::string const& label, Handle<PROD>& result) const {
Expand Down
7 changes: 7 additions & 0 deletions FWCore/Framework/interface/PrincipalGetAdapter.h
Expand Up @@ -102,6 +102,7 @@ edm::Ref<AppleCollection> ref(refApples, index);

#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/EDPutToken.h"
#include "FWCore/Utilities/interface/ProductKindOfType.h"
#include "FWCore/Utilities/interface/ProductLabels.h"
#include "FWCore/Utilities/interface/propagate_const.h"
Expand All @@ -111,6 +112,7 @@ namespace edm {

class ModuleCallingContext;
class SharedResourcesAcquirer;
class ProducerBase;

namespace principal_get_adapter_detail {
void
Expand Down Expand Up @@ -144,6 +146,9 @@ namespace edm {
resourcesAcquirer_ = iSra;
}

void setProducer(ProducerBase const* iProd) {
prodBase_ = iProd;
}

bool isComplete() const;

Expand All @@ -163,6 +168,7 @@ namespace edm {
BranchDescription const&
getBranchDescription(TypeID const& type, std::string const& productInstanceName) const;

std::string const& productInstanceLabel(EDPutToken) const;
typedef std::vector<BasicHandle> BasicHandleVec;

//------------------------------------------------------------
Expand Down Expand Up @@ -235,6 +241,7 @@ namespace edm {

EDConsumerBase const* consumer_;
SharedResourcesAcquirer* resourcesAcquirer_; // We do not use propagate_const because the acquirer is itself mutable.
ProducerBase const* prodBase_ = nullptr;
};

template <typename PROD>
Expand Down
75 changes: 55 additions & 20 deletions FWCore/Framework/interface/ProductRegistryHelper.h
Expand Up @@ -9,9 +9,10 @@

#include "FWCore/Utilities/interface/TypeID.h"
#include "FWCore/Utilities/interface/Transition.h"
#include "FWCore/Utilities/interface/EDPutToken.h"
#include "DataFormats/Provenance/interface/BranchType.h"
#include <string>
#include <list>
#include <vector>

namespace edm {
class ModuleDescription;
Expand All @@ -23,22 +24,54 @@ namespace edm {
~ProductRegistryHelper();

struct TypeLabelItem {
TypeLabelItem (Transition const& transition, TypeID const& tid, std::string const& pin) :
TypeLabelItem (Transition const& transition, TypeID const& tid, std::string pin) :
transition_(transition),
typeID_(tid),
productInstanceName_(pin),
productInstanceName_(std::move(pin)),
branchAlias_() {}
Transition transition_;
TypeID typeID_;
std::string productInstanceName_;
mutable std::string branchAlias_;
void setBranchAlias(std::string const& alias) const {branchAlias_ = alias;}
std::string branchAlias_;
};

typedef std::list<TypeLabelItem> TypeLabelList;
struct BranchAliasSetter {
BranchAliasSetter(TypeLabelItem& iItem, EDPutToken iToken):
value_(iItem), token_(std::move(iToken)) {}

BranchAliasSetter& setBranchAlias(std::string alias) {
value_.branchAlias_ = std::move(alias);
return *this;
}
TypeLabelItem& value_;
EDPutToken token_;

operator EDPutToken() { return token_;}
};

template <typename T>
struct BranchAliasSetterT {
BranchAliasSetterT(TypeLabelItem& iItem, EDPutTokenT<T> iToken):
value_(iItem), token_(std::move(iToken)) {}

BranchAliasSetterT( BranchAliasSetter&& iS):
value_(iS.value_), token_(iS.token_.index()) {}

BranchAliasSetterT<T>& setBranchAlias(std::string alias) {
value_.branchAlias_ = std::move(alias);
return *this;
}
TypeLabelItem& value_;
EDPutTokenT<T> token_;

operator EDPutTokenT<T>() { return token_;}
operator EDPutToken() { return EDPutToken(token_.index()); }
};

typedef std::vector<TypeLabelItem> TypeLabelList;

/// used by the fwk to register the list of products of this module
TypeLabelList & typeLabelList();
TypeLabelList const& typeLabelList() const;

static
void addToRegistry(TypeLabelList::const_iterator const& iBegin,
Expand All @@ -56,51 +89,53 @@ namespace edm {


template <class ProductType>
TypeLabelItem const& produces() {
BranchAliasSetterT<ProductType> produces() {
return produces<ProductType, InEvent>(std::string());
}

template <class ProductType>
TypeLabelItem const& produces(std::string const& instanceName) {
BranchAliasSetterT<ProductType> produces(std::string const& instanceName) {
return produces<ProductType, InEvent>(instanceName);
}

template <typename ProductType, BranchType B>
TypeLabelItem const& produces() {
BranchAliasSetterT<ProductType> produces() {
return produces<ProductType, B>(std::string());
}

template <typename ProductType, BranchType B>
TypeLabelItem const& produces(std::string const& instanceName) {
BranchAliasSetterT<ProductType> produces(std::string const& instanceName) {
TypeID tid(typeid(ProductType));
return produces<B>(tid,instanceName);
return BranchAliasSetterT<ProductType>{produces<B>(tid,instanceName)};
}

template <typename ProductType, Transition B>
TypeLabelItem const& produces() {
BranchAliasSetterT<ProductType> produces() {
return produces<ProductType, B>(std::string());
}

template <typename ProductType, Transition B>
TypeLabelItem const& produces(std::string const& instanceName) {
BranchAliasSetterT<ProductType> produces(std::string const& instanceName) {
TypeID tid(typeid(ProductType));
return produces<B>(tid,instanceName);
return BranchAliasSetterT<ProductType>{produces<B>(tid,instanceName)};
}


TypeLabelItem const& produces(const TypeID& id, std::string const& instanceName=std::string()) {
BranchAliasSetter produces(const TypeID& id, std::string const& instanceName=std::string()) {
return produces<Transition::Event>(id,instanceName);
}

template <BranchType B>
TypeLabelItem const& produces(const TypeID& id, std::string const& instanceName=std::string()) {
BranchAliasSetter produces(const TypeID& id, std::string const& instanceName=std::string()) {
unsigned int index =typeLabelList_.size();
typeLabelList_.emplace_back(convertToTransition(B), id, instanceName);
return *typeLabelList_.rbegin();
return BranchAliasSetter{typeLabelList_.back(),EDPutToken{static_cast<unsigned int>(index)}};
}
template <Transition B>
TypeLabelItem const& produces(const TypeID& id, std::string const& instanceName=std::string()) {
BranchAliasSetter produces(const TypeID& id, std::string const& instanceName=std::string()) {
unsigned int index =typeLabelList_.size();
typeLabelList_.emplace_back(B, id, instanceName);
return *typeLabelList_.rbegin();
return BranchAliasSetter{typeLabelList_.back(),EDPutToken{ index }};
}

private:
Expand Down
31 changes: 28 additions & 3 deletions FWCore/Framework/interface/Run.h
Expand Up @@ -22,6 +22,7 @@ For its usage, see "FWCore/Framework/interface/PrincipalGetAdapter.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Common/interface/RunBase.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/EDPutToken.h"
#include "FWCore/Utilities/interface/ProductKindOfType.h"
#include "FWCore/Utilities/interface/RunIndex.h"

Expand All @@ -43,7 +44,7 @@ namespace edm {
public:
Run(RunPrincipal const& rp, ModuleDescription const& md,
ModuleCallingContext const*);
~Run();
~Run() override;

//Used in conjunction with EDGetToken
void setConsumer(EDConsumerBase const* iConsumer) {
Expand All @@ -54,9 +55,13 @@ namespace edm {
provRecorder_.setSharedResourcesAcquirer(iResourceAcquirer);
}

void setProducer(ProducerBase const* iProducer) {
provRecorder_.setProducer(iProducer);
}

typedef PrincipalGetAdapter Base;
// AUX functions are defined in RunBase
RunAuxiliary const& runAuxiliary() const {return aux_;}
RunAuxiliary const& runAuxiliary() const override {return aux_;}
// AUX functions.
// RunID const& id() const {return aux_.id();}
// RunNumber_t run() const {return aux_.run();}
Expand Down Expand Up @@ -115,6 +120,14 @@ namespace edm {
void
put(std::unique_ptr<PROD> product, std::string const& productInstanceName);

template<typename PROD>
void
put(EDPutToken token, std::unique_ptr<PROD> product);

template<typename PROD>
void
put(EDPutTokenT<PROD> token, std::unique_ptr<PROD> product);

Provenance
getProvenance(BranchID const& theID) const;

Expand Down Expand Up @@ -145,7 +158,7 @@ namespace edm {
runPrincipal() const;

// Override version from RunBase class
virtual BasicHandle getByLabelImpl(std::type_info const& iWrapperType, std::type_info const& iProductType, InputTag const& iTag) const;
BasicHandle getByLabelImpl(std::type_info const& iWrapperType, std::type_info const& iProductType, InputTag const& iTag) const override;

typedef std::vector<std::pair<edm::propagate_const<std::unique_ptr<WrapperBase>>, BranchDescription const*>> ProductPtrVec;
ProductPtrVec& putProducts() {return putProducts_;}
Expand Down Expand Up @@ -196,6 +209,18 @@ namespace edm {
// The old copy must be deleted, so we cannot release ownership.
}

template<typename PROD>
void
Run::put(EDPutTokenT<PROD> token, std::unique_ptr<PROD> product) {
put(std::move(product), provRecorder_.productInstanceLabel(token));
}

template<typename PROD>
void
Run::put(EDPutToken token, std::unique_ptr<PROD> product) {
put(std::move(product), provRecorder_.productInstanceLabel(token));
}

template <typename PROD>
bool
Run::getByLabel(std::string const& label, Handle<PROD>& result) const {
Expand Down

0 comments on commit 2ca3a4d

Please sign in to comment.