Skip to content

Commit

Permalink
Merge pull request #20 from ktf/tagset-133089
Browse files Browse the repository at this point in the history
Add edm::ConsumesCollector class
  • Loading branch information
ktf committed Jul 2, 2013
2 parents 214ab73 + 9903e35 commit 2e1ca89
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 4 deletions.
104 changes: 104 additions & 0 deletions FWCore/Framework/interface/ConsumesCollector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#ifndef FWCore_Framework_ConsumesCollector_h
#define FWCore_Framework_ConsumesCollector_h
// -*- C++ -*-
//
// Package: FWCore/Framework
// Class : edm::ConsumesCollector
//
/**\class edm::ConsumesCollector ConsumesCollector.h "FWCore/Framework/interface/ConsumesCollector.h"
Description: Helper class to gather consumes information for EDConsumerBase class.
Usage:
The constructor of a module can get an instance of edm::ConsumesCollector by calling its
consumesCollector() method. This instance can then be passed to helper classes in order to register
the data the helper will request from an Event, LuminosityBlock or Run on behalf of the module.
*/
//
// Original Author: Chris Jones
// Created: Fri, 07 Jun 2013 12:44:47 GMT
//

// system include files

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

// forward declarations
namespace edm {
class EDConsumerBase;

class ConsumesCollector
{

public:
//virtual ~ConsumesCollector();
ConsumesCollector(ConsumesCollector&& iOther): m_consumer(iOther.m_consumer){}

// ---------- member functions ---------------------------
template <typename ProductType, BranchType B=InEvent>
EDGetTokenT<ProductType> consumes(edm::InputTag const& tag) {
return m_consumer->consumes<ProductType,B>(tag);
}

EDGetToken consumes(const TypeToGet& id, edm::InputTag const& tag) {
return m_consumer->consumes(id,tag);
}

template <BranchType B>
EDGetToken consumes(TypeToGet const& id, edm::InputTag const& tag) {
return m_consumer->consumes<B>(id,tag);
}

template <typename ProductType, BranchType B=InEvent>
EDGetTokenT<ProductType> mayConsume(edm::InputTag const& tag) {
return m_consumer->mayConsume<ProductType,B>(tag);
}


EDGetToken mayConsume(const TypeToGet& id, edm::InputTag const& tag) {
return m_consumer->mayConsume(id,tag);
}

template <BranchType B>
EDGetToken mayConsume(const TypeToGet& id, edm::InputTag const& tag) {
return m_consumer->mayConsume<B>(id,tag);
}

template <typename ProductType, BranchType B=InEvent>
void consumesMany() {
m_consumer->consumesMany<ProductType,B>();
}


void consumesMany(const TypeToGet& id) {
m_consumer->consumesMany(id);
}

template <BranchType B>
void consumesMany(const TypeToGet& id) {
m_consumer->consumesMany<B>(id);
}


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

ConsumesCollector(EDConsumerBase* iConsumer):
m_consumer(iConsumer) {}

ConsumesCollector() = delete;
ConsumesCollector(const ConsumesCollector&) = delete; // stop default

const ConsumesCollector& operator=(const ConsumesCollector&) = delete; // stop default

// ---------- member data --------------------------------
EDConsumerBase* m_consumer;

};
}


#endif
6 changes: 5 additions & 1 deletion FWCore/Framework/interface/EDConsumerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
// Original Author: Chris Jones
// Created: Tue, 02 Apr 2013 21:35:53 GMT
// $Id: EDConsumerBase.h,v 1.5 2013/06/04 14:59:02 wdd Exp $
// $Id: EDConsumerBase.h,v 1.6 2013/06/07 17:58:31 chrjones Exp $
//

// system include files
Expand All @@ -37,6 +37,7 @@

namespace edm {
class ProductHolderIndexHelper;
class ConsumesCollector;

class EDConsumerBase
{
Expand Down Expand Up @@ -65,6 +66,9 @@ namespace edm {
void labelsForToken(EDGetToken iToken, Labels& oLabels) const;

protected:
friend class ConsumesCollector;
///Use a ConsumesCollector to gather consumes information from helper functions
ConsumesCollector consumesCollector();

template <typename ProductType, BranchType B=InEvent>
EDGetTokenT<ProductType> consumes(edm::InputTag const& tag) {
Expand Down
10 changes: 9 additions & 1 deletion FWCore/Framework/src/EDConsumerBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
//
// Original Author: Chris Jones
// Created: Tue, 02 Apr 2013 21:36:06 GMT
// $Id: EDConsumerBase.cc,v 1.5 2013/06/04 14:59:02 wdd Exp $
// $Id: EDConsumerBase.cc,v 1.6 2013/06/07 17:58:32 chrjones Exp $
//

// system include files
#include <cassert>
#include <utility>

// user include files
#include "FWCore/Framework/interface/EDConsumerBase.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Utilities/interface/Likely.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "DataFormats/Provenance/interface/ProductHolderIndexHelper.h"
Expand Down Expand Up @@ -61,6 +63,12 @@ EDConsumerBase::~EDConsumerBase()
//
// member functions
//
ConsumesCollector
EDConsumerBase::consumesCollector() {
ConsumesCollector c{this};
return std::move(c);
}


unsigned int
EDConsumerBase::recordConsumes(BranchType iBranch, TypeToGet const& iType, edm::InputTag const& iTag, bool iAlwaysGets) {
Expand Down
64 changes: 62 additions & 2 deletions FWCore/Framework/test/edconsumerbase_t.cppunit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
// Original Author: Chris Jones
// Created: Sat, 06 Apr 2013 16:39:12 GMT
// $Id: edconsumerbase_t.cppunit.cc,v 1.4 2013/06/04 14:59:02 wdd Exp $
// $Id: edconsumerbase_t.cppunit.cc,v 1.5 2013/06/07 17:58:32 chrjones Exp $
//

// system include files
Expand All @@ -18,6 +18,7 @@
// user include files
#include <cppunit/extensions/HelperMacros.h>
#include "FWCore/Framework/interface/EDConsumerBase.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"

#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Utilities/interface/TypeToGet.h"
Expand Down Expand Up @@ -110,8 +111,22 @@ namespace {

std::vector<edm::EDGetToken> m_tokens;
};
}

class IntsConsumesCollectorConsumer : public edm::EDConsumerBase {
public:
IntsConsumesCollectorConsumer(std::vector<edm::InputTag> const& iTags) {
m_tokens.reserve(iTags.size());
edm::ConsumesCollector c{ consumesCollector() };
for(auto const& tag : iTags) {
m_tokens.push_back(c.consumes<std::vector<int>>(tag));
}
}

std::vector<edm::EDGetTokenT<std::vector<int>>> m_tokens;
};

}

void
TestEDConsumerBase::testRegularType()
{
Expand Down Expand Up @@ -169,6 +184,29 @@ TestEDConsumerBase::testRegularType()
intConsumer.itemsMayGet(edm::InEvent,indicesMay);
CPPUNIT_ASSERT(0 == indicesMay.size());

}
{
std::vector<edm::InputTag> vTags={ {"label","instance","process"}, {"labelC","instanceC","processC"} };
IntsConsumesCollectorConsumer intConsumer{vTags};
intConsumer.updateLookup(edm::InEvent,helper);

CPPUNIT_ASSERT(intConsumer.m_tokens[0].index()==0);
CPPUNIT_ASSERT(intConsumer.m_tokens[1].index()==1);

CPPUNIT_ASSERT(vint_c == intConsumer.indexFrom(intConsumer.m_tokens[1],edm::InEvent,typeID_vint));
CPPUNIT_ASSERT(vint_blank == intConsumer.indexFrom(intConsumer.m_tokens[0],edm::InEvent,typeID_vint));

std::vector<edm::ProductHolderIndex> indices;
intConsumer.itemsToGet(edm::InEvent,indices);

CPPUNIT_ASSERT(2 == indices.size());
CPPUNIT_ASSERT(indices.end() != std::find(indices.begin(),indices.end(), vint_c));
CPPUNIT_ASSERT(indices.end() != std::find(indices.begin(),indices.end(), vint_blank));

std::vector<edm::ProductHolderIndex> indicesMay;
intConsumer.itemsMayGet(edm::InEvent,indicesMay);
CPPUNIT_ASSERT(0 == indicesMay.size());

}
{
std::vector<edm::InputTag> vTagsRev={ {"labelC","instanceC","processC"},{"label","instance","process"} };
Expand All @@ -192,6 +230,28 @@ TestEDConsumerBase::testRegularType()
intConsumerRev.itemsMayGet(edm::InEvent,indicesMay);
CPPUNIT_ASSERT(0 == indicesMay.size());
}
{
std::vector<edm::InputTag> vTagsRev={ {"labelC","instanceC","processC"},{"label","instance","process"} };
IntsConsumesCollectorConsumer intConsumerRev{vTagsRev};
intConsumerRev.updateLookup(edm::InEvent,helper);

CPPUNIT_ASSERT(intConsumerRev.m_tokens[0].index()==0);
CPPUNIT_ASSERT(intConsumerRev.m_tokens[1].index()==1);

CPPUNIT_ASSERT(vint_c == intConsumerRev.indexFrom(intConsumerRev.m_tokens[0],edm::InEvent,typeID_vint));
CPPUNIT_ASSERT(vint_blank == intConsumerRev.indexFrom(intConsumerRev.m_tokens[1],edm::InEvent,typeID_vint));

std::vector<edm::ProductHolderIndex> indices;
intConsumerRev.itemsToGet(edm::InEvent,indices);

CPPUNIT_ASSERT(2 == indices.size());
CPPUNIT_ASSERT(indices.end() != std::find(indices.begin(),indices.end(), vint_c));
CPPUNIT_ASSERT(indices.end() != std::find(indices.begin(),indices.end(), vint_blank));

std::vector<edm::ProductHolderIndex> indicesMay;
intConsumerRev.itemsMayGet(edm::InEvent,indicesMay);
CPPUNIT_ASSERT(0 == indicesMay.size());
}
{
//test default process
std::vector<edm::InputTag> vTags={ {"label","instance"}, {"labelC","instanceC","@skipCurrentProcess"} };
Expand Down

0 comments on commit 2e1ca89

Please sign in to comment.