Skip to content

Commit

Permalink
Merge pull request cms-sw#49 from jbsauvan/geometry-in-fecodec
Browse files Browse the repository at this point in the history
Add pointer to the geometry in FE codec and BE algos
  • Loading branch information
jbsauvan authored Sep 23, 2016
2 parents 509ce9a + 0d6c335 commit c7b741d
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 90 deletions.
16 changes: 9 additions & 7 deletions L1Trigger/L1THGCal/interface/HGCalTriggerBackendAlgorithmBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@

class HGCalTriggerBackendAlgorithmBase {
public:
HGCalTriggerBackendAlgorithmBase(const edm::ParameterSet& conf) :
HGCalTriggerBackendAlgorithmBase(const edm::ParameterSet& conf, const HGCalTriggerGeometryBase* const geom) :
geometry_(geom),
name_(conf.getParameter<std::string>("AlgorithmName"))
{}
virtual ~HGCalTriggerBackendAlgorithmBase() {}
Expand All @@ -39,13 +40,14 @@ class HGCalTriggerBackendAlgorithmBase {
//runs the trigger algorithm, storing internally the results
virtual void setProduces(edm::EDProducer& prod) const = 0;

virtual void run(const l1t::HGCFETriggerDigiCollection& coll,
const std::unique_ptr<HGCalTriggerGeometryBase>& geom) = 0;
virtual void run(const l1t::HGCFETriggerDigiCollection& coll) = 0;

virtual void putInEvent(edm::Event& evt) = 0;

virtual void reset() = 0;

protected:
const HGCalTriggerGeometryBase* const geometry_;

private:
const std::string name_;
Expand All @@ -57,16 +59,16 @@ namespace HGCalTriggerBackend {
template<typename FECODEC>
class Algorithm : public HGCalTriggerBackendAlgorithmBase {
public:
Algorithm(const edm::ParameterSet& conf) :
HGCalTriggerBackendAlgorithmBase(conf),
codec_(conf.getParameterSet("FECodec")){ }
Algorithm(const edm::ParameterSet& conf, const HGCalTriggerGeometryBase* const geom) :
HGCalTriggerBackendAlgorithmBase(conf,geom),
codec_(conf.getParameterSet("FECodec"),geom){ }

protected:
FECODEC codec_;
};
}

#include "FWCore/PluginManager/interface/PluginFactory.h"
typedef edmplugin::PluginFactory< HGCalTriggerBackendAlgorithmBase* (const edm::ParameterSet&) > HGCalTriggerBackendAlgorithmFactory;
typedef edmplugin::PluginFactory< HGCalTriggerBackendAlgorithmBase* (const edm::ParameterSet&, const HGCalTriggerGeometryBase* const) > HGCalTriggerBackendAlgorithmFactory;

#endif
5 changes: 2 additions & 3 deletions L1Trigger/L1THGCal/interface/HGCalTriggerBackendProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ class HGCalTriggerBackendProcessor {
public:
typedef std::unique_ptr<HGCalTriggerBackendAlgorithmBase> algo_ptr;

HGCalTriggerBackendProcessor(const edm::ParameterSet& conf);
HGCalTriggerBackendProcessor(const edm::ParameterSet& conf, const HGCalTriggerGeometryBase* const geom);

void setProduces(edm::EDProducer& prod) const;

void run(const l1t::HGCFETriggerDigiCollection& coll,
const std::unique_ptr<HGCalTriggerGeometryBase>& geom);
void run(const l1t::HGCFETriggerDigiCollection& coll);

void putInEvent(edm::Event& evt);

Expand Down
28 changes: 14 additions & 14 deletions L1Trigger/L1THGCal/interface/HGCalTriggerFECodecBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

class HGCalTriggerFECodecBase {
public:
HGCalTriggerFECodecBase(const edm::ParameterSet& conf) :
HGCalTriggerFECodecBase(const edm::ParameterSet& conf, const HGCalTriggerGeometryBase* const geom) :
geometry_(geom),
name_(conf.getParameter<std::string>("CodecName")),
codec_idx_(static_cast<unsigned char>(conf.getParameter<uint32_t>("CodecIndex")))
{}
Expand All @@ -37,12 +38,10 @@ class HGCalTriggerFECodecBase {

// give the FECodec the trigger geometry + input digis and it sets itself
// with the approprate data
virtual void setDataPayload(const HGCalTriggerGeometryBase&,
const HGCEEDigiCollection&,
virtual void setDataPayload(const HGCEEDigiCollection&,
const HGCHEDigiCollection&,
const HGCHEDigiCollection& ) = 0;
virtual void setDataPayload(const HGCalTriggerGeometryBase& ,
const l1t::HGCFETriggerDigi&) = 0;
virtual void setDataPayload(const l1t::HGCFETriggerDigi&) = 0;
virtual void unSetDataPayload() = 0;
// get the set data out for your own enjoyment
virtual std::vector<bool> getDataPayload() const = 0;
Expand All @@ -54,6 +53,9 @@ class HGCalTriggerFECodecBase {
virtual void print(const l1t::HGCFETriggerDigi& digi,
std::ostream& out = std::cout) const = 0;

protected:
const HGCalTriggerGeometryBase* const geometry_;

private:
const std::string name_;
unsigned char codec_idx_; // I hope we never come to having 256 FE codecs :-)
Expand All @@ -65,8 +67,8 @@ namespace HGCalTriggerFE {
template<typename Impl,typename DATA>
class Codec : public HGCalTriggerFECodecBase {
public:
Codec(const edm::ParameterSet& conf) :
HGCalTriggerFECodecBase(conf),
Codec(const edm::ParameterSet& conf, const HGCalTriggerGeometryBase* const geom) :
HGCalTriggerFECodecBase(conf, geom),
dataIsSet_(false) {
}

Expand All @@ -90,27 +92,25 @@ namespace HGCalTriggerFE {
dataIsSet_ = true;
}

virtual void setDataPayload(const HGCalTriggerGeometryBase& geom,
const HGCEEDigiCollection& ee,
virtual void setDataPayload(const HGCEEDigiCollection& ee,
const HGCHEDigiCollection& fh,
const HGCHEDigiCollection& bh ) override final {
if( dataIsSet_ ) {
edm::LogWarning("HGCalTriggerFECodec|OverwritePayload")
<< "Data payload was already set for HGCTriggerFECodec: "
<< this->name() << " overwriting current data!";
}
static_cast<Impl&>(*this).setDataPayloadImpl(geom,ee,fh,bh);
static_cast<Impl&>(*this).setDataPayloadImpl(ee,fh,bh);
dataIsSet_ = true;
}

virtual void setDataPayload(const HGCalTriggerGeometryBase& geom,
const l1t::HGCFETriggerDigi& digi) override final {
virtual void setDataPayload(const l1t::HGCFETriggerDigi& digi) override final {
if( dataIsSet_ ) {
edm::LogWarning("HGCalTriggerFECodec|OverwritePayload")
<< "Data payload was already set for HGCTriggerFECodec: "
<< this->name() << " overwriting current data!";
}
static_cast<Impl&>(*this).setDataPayloadImpl(geom,digi);
static_cast<Impl&>(*this).setDataPayloadImpl(digi);
dataIsSet_ = true;
}

Expand Down Expand Up @@ -143,6 +143,6 @@ namespace HGCalTriggerFE {
}

#include "FWCore/PluginManager/interface/PluginFactory.h"
typedef edmplugin::PluginFactory< HGCalTriggerFECodecBase* (const edm::ParameterSet&) > HGCalTriggerFECodecFactory;
typedef edmplugin::PluginFactory< HGCalTriggerFECodecBase* (const edm::ParameterSet&, const HGCalTriggerGeometryBase* const) > HGCalTriggerFECodecFactory;

#endif
10 changes: 4 additions & 6 deletions L1Trigger/L1THGCal/interface/fe_codecs/HGCal64BitRandomCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ class HGCal64BitRandomCodec : public HGCalTriggerFE::Codec<HGCal64BitRandomCodec
public:
typedef HGCal64BitRandomDataPayload data_type;

HGCal64BitRandomCodec(const edm::ParameterSet& conf) :
Codec(conf),
HGCal64BitRandomCodec(const edm::ParameterSet& conf, const HGCalTriggerGeometryBase* const geom) :
Codec(conf,geom),
codecImpl_(conf) {
data_.payload = std::numeric_limits<uint64_t>::max();
}

void setDataPayloadImpl(const HGCalTriggerGeometryBase& geom,
const HGCEEDigiCollection& ee,
void setDataPayloadImpl(const HGCEEDigiCollection& ee,
const HGCHEDigiCollection& fh,
const HGCHEDigiCollection& bh );

void setDataPayloadImpl(const HGCalTriggerGeometryBase& geom,
const l1t::HGCFETriggerDigi& digi);
void setDataPayloadImpl(const l1t::HGCFETriggerDigi& digi);

std::vector<bool> encodeImpl(const data_type&) const ;
data_type decodeImpl(const std::vector<bool>&) const;
Expand Down
8 changes: 3 additions & 5 deletions L1Trigger/L1THGCal/interface/fe_codecs/HGCalBestChoiceCodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ class HGCalBestChoiceCodec : public HGCalTriggerFE::Codec<HGCalBestChoiceCodec,H
public:
typedef HGCalBestChoiceDataPayload data_type;

HGCalBestChoiceCodec(const edm::ParameterSet& conf);
HGCalBestChoiceCodec(const edm::ParameterSet& conf, const HGCalTriggerGeometryBase* const geom);

void setDataPayloadImpl(const HGCalTriggerGeometryBase& geom,
const HGCEEDigiCollection& ee,
void setDataPayloadImpl(const HGCEEDigiCollection& ee,
const HGCHEDigiCollection& fh,
const HGCHEDigiCollection& bh );

void setDataPayloadImpl(const HGCalTriggerGeometryBase& geom,
const l1t::HGCFETriggerDigi& digi);
void setDataPayloadImpl(const l1t::HGCFETriggerDigi& digi);

std::vector<bool> encodeImpl(const data_type&) const ;
data_type decodeImpl(const std::vector<bool>&) const;
Expand Down
19 changes: 10 additions & 9 deletions L1Trigger/L1THGCal/plugins/HGCalTriggerDigiFEReproducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ class HGCalTriggerDigiFEReproducer : public edm::EDProducer
// algorithm containers
std::unique_ptr<HGCalTriggerGeometryBase> triggerGeometry_;
std::unique_ptr<HGCalTriggerFECodecBase> codec_;
HGCalTriggerBackendProcessor backEndProcessor_;
std::unique_ptr<HGCalTriggerBackendProcessor> backEndProcessor_;
};

DEFINE_FWK_MODULE(HGCalTriggerDigiFEReproducer);


/*****************************************************************/
HGCalTriggerDigiFEReproducer::HGCalTriggerDigiFEReproducer(const edm::ParameterSet& conf):
inputdigi_(consumes<l1t::HGCFETriggerDigiCollection>(conf.getParameter<edm::InputTag>("feDigis"))),
backEndProcessor_(conf.getParameterSet("BEConfiguration"))
inputdigi_(consumes<l1t::HGCFETriggerDigiCollection>(conf.getParameter<edm::InputTag>("feDigis")))
/*****************************************************************/
{
//setup geometry configuration
Expand All @@ -52,13 +51,15 @@ HGCalTriggerDigiFEReproducer::HGCalTriggerDigiFEReproducer(const edm::ParameterS
//setup FE codec
const edm::ParameterSet& feCodecConfig = conf.getParameterSet("FECodec");
const std::string& feCodecName = feCodecConfig.getParameter<std::string>("CodecName");
HGCalTriggerFECodecBase* codec = HGCalTriggerFECodecFactory::get()->create(feCodecName,feCodecConfig);
HGCalTriggerFECodecBase* codec = HGCalTriggerFECodecFactory::get()->create(feCodecName,feCodecConfig,triggerGeometry_.get());
codec_.reset(codec);
codec_->unSetDataPayload();

produces<l1t::HGCFETriggerDigiCollection>();
//setup BE processor
backEndProcessor_ = std::make_unique<HGCalTriggerBackendProcessor>(conf.getParameterSet("BEConfiguration"), triggerGeometry_.get());
// register backend processor products
backEndProcessor_.setProduces(*this);
backEndProcessor_->setProduces(*this);
}

/*****************************************************************/
Expand Down Expand Up @@ -97,7 +98,7 @@ void HGCalTriggerDigiFEReproducer::produce(edm::Event& e, const edm::EventSetup&
{
fe_output->push_back(l1t::HGCFETriggerDigi());
l1t::HGCFETriggerDigi& digi_out = fe_output->back();
codec_->setDataPayload(*triggerGeometry_, digi_in);
codec_->setDataPayload(digi_in);
codec_->encode(digi_out);
digi_out.setDetId( digi_in.getDetId<HGCalDetId>() );
codec_->print(digi_out,output);
Expand All @@ -113,7 +114,7 @@ void HGCalTriggerDigiFEReproducer::produce(edm::Event& e, const edm::EventSetup&
auto fe_digis_coll = *fe_digis_handle;

//now we run the emulation of the back-end processor
backEndProcessor_.run(fe_digis_coll,triggerGeometry_);
backEndProcessor_.putInEvent(e);
backEndProcessor_.reset();
backEndProcessor_->run(fe_digis_coll);
backEndProcessor_->putInEvent(e);
backEndProcessor_->reset();
}
24 changes: 13 additions & 11 deletions L1Trigger/L1THGCal/plugins/HGCalTriggerDigiProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ class HGCalTriggerDigiProducer : public edm::EDProducer {
// algorithm containers
std::unique_ptr<HGCalTriggerGeometryBase> triggerGeometry_;
std::unique_ptr<HGCalTriggerFECodecBase> codec_;
HGCalTriggerBackendProcessor backEndProcessor_;
std::unique_ptr<HGCalTriggerBackendProcessor> backEndProcessor_;
};

DEFINE_FWK_MODULE(HGCalTriggerDigiProducer);

HGCalTriggerDigiProducer::
HGCalTriggerDigiProducer(const edm::ParameterSet& conf):
inputee_(consumes<HGCEEDigiCollection>(conf.getParameter<edm::InputTag>("eeDigis"))),
inputfh_(consumes<HGCHEDigiCollection>(conf.getParameter<edm::InputTag>("fhDigis"))),
//inputbh_(consumes<HGCHEDigiCollection>(conf.getParameter<edm::InputTag>("bhDigis"))),
backEndProcessor_(conf.getParameterSet("BEConfiguration")) {
inputfh_(consumes<HGCHEDigiCollection>(conf.getParameter<edm::InputTag>("fhDigis")))
//inputbh_(consumes<HGCHEDigiCollection>(conf.getParameter<edm::InputTag>("bhDigis")))
{

//setup geometry configuration
const edm::ParameterSet& geometryConfig =
Expand All @@ -57,13 +57,15 @@ HGCalTriggerDigiProducer(const edm::ParameterSet& conf):
const std::string& feCodecName =
feCodecConfig.getParameter<std::string>("CodecName");
HGCalTriggerFECodecBase* codec =
HGCalTriggerFECodecFactory::get()->create(feCodecName,feCodecConfig);
HGCalTriggerFECodecFactory::get()->create(feCodecName,feCodecConfig,triggerGeometry_.get());
codec_.reset(codec);
codec_->unSetDataPayload();

produces<l1t::HGCFETriggerDigiCollection>();
//setup BE processor
backEndProcessor_ = std::make_unique<HGCalTriggerBackendProcessor>(conf.getParameterSet("BEConfiguration"), triggerGeometry_.get());
// register backend processor products
backEndProcessor_.setProduces(*this);
backEndProcessor_->setProduces(*this);
}

void HGCalTriggerDigiProducer::beginRun(const edm::Run& /*run*/,
Expand Down Expand Up @@ -117,7 +119,7 @@ void HGCalTriggerDigiProducer::produce(edm::Event& e, const edm::EventSetup& es)
for( const auto& module_hits : hit_modules_ee ) {
fe_output->push_back(l1t::HGCFETriggerDigi());
l1t::HGCFETriggerDigi& digi = fe_output->back();
codec_->setDataPayload(*triggerGeometry_, module_hits.second,HGCHEDigiCollection(),HGCHEDigiCollection());
codec_->setDataPayload(module_hits.second,HGCHEDigiCollection(),HGCHEDigiCollection());
codec_->encode(digi);
digi.setDetId( DetId(module_hits.first) );
codec_->print(digi,output);
Expand All @@ -130,7 +132,7 @@ void HGCalTriggerDigiProducer::produce(edm::Event& e, const edm::EventSetup& es)
for( const auto& module_hits : hit_modules_fh ) {
fe_output->push_back(l1t::HGCFETriggerDigi());
l1t::HGCFETriggerDigi& digi = fe_output->back();
codec_->setDataPayload(*triggerGeometry_,HGCEEDigiCollection(),module_hits.second,HGCHEDigiCollection());
codec_->setDataPayload(HGCEEDigiCollection(),module_hits.second,HGCHEDigiCollection());
codec_->encode(digi);
digi.setDetId( DetId(module_hits.first) );
codec_->print(digi,output);
Expand All @@ -147,7 +149,7 @@ void HGCalTriggerDigiProducer::produce(edm::Event& e, const edm::EventSetup& es)
auto fe_digis_coll = *fe_digis_handle;

//now we run the emulation of the back-end processor
backEndProcessor_.run(fe_digis_coll,triggerGeometry_);
backEndProcessor_.putInEvent(e);
backEndProcessor_.reset();
backEndProcessor_->run(fe_digis_coll);
backEndProcessor_->putInEvent(e);
backEndProcessor_->reset();
}
10 changes: 4 additions & 6 deletions L1Trigger/L1THGCal/plugins/be_algorithms/FullModuleSumAlgo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ class FullModuleSumAlgo : public Algorithm<HGCalBestChoiceCodec>
{
public:

FullModuleSumAlgo(const edm::ParameterSet& conf):
Algorithm<HGCalBestChoiceCodec>(conf),
FullModuleSumAlgo(const edm::ParameterSet& conf, const HGCalTriggerGeometryBase* const geom):
Algorithm<HGCalBestChoiceCodec>(conf,geom),
cluster_product_( new l1t::HGCalClusterBxCollection ){}

virtual void setProduces(edm::EDProducer& prod) const override final
{
prod.produces<l1t::HGCalClusterBxCollection>(name());
}

virtual void run(const l1t::HGCFETriggerDigiCollection& coll,
const std::unique_ptr<HGCalTriggerGeometryBase>& geom) override final;
virtual void run(const l1t::HGCFETriggerDigiCollection& coll) override final;

virtual void putInEvent(edm::Event& evt) override final
{
Expand All @@ -38,8 +37,7 @@ class FullModuleSumAlgo : public Algorithm<HGCalBestChoiceCodec>
};

/*****************************************************************/
void FullModuleSumAlgo::run(const l1t::HGCFETriggerDigiCollection& coll,
const std::unique_ptr<HGCalTriggerGeometryBase>& geom)
void FullModuleSumAlgo::run(const l1t::HGCFETriggerDigiCollection& coll)
/*****************************************************************/
{
for( const auto& digi : coll )
Expand Down
10 changes: 4 additions & 6 deletions L1Trigger/L1THGCal/plugins/be_algorithms/RandomClusterAlgo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ using namespace HGCalTriggerBackend;
class RandomClusterAlgo : public Algorithm<HGCal64BitRandomCodec> {
public:

RandomClusterAlgo(const edm::ParameterSet& conf):
Algorithm<HGCal64BitRandomCodec>(conf),
RandomClusterAlgo(const edm::ParameterSet& conf, const HGCalTriggerGeometryBase* const geom):
Algorithm<HGCal64BitRandomCodec>(conf,geom),
cluster_product_( new l1t::HGCalClusterBxCollection ){
}

virtual void setProduces(edm::EDProducer& prod) const override final {
prod.produces<l1t::HGCalClusterBxCollection>(name());
}

virtual void run(const l1t::HGCFETriggerDigiCollection& coll,
const std::unique_ptr<HGCalTriggerGeometryBase>& geom) override final;
virtual void run(const l1t::HGCFETriggerDigiCollection& coll) override final;

virtual void putInEvent(edm::Event& evt) override final {
evt.put(std::move(cluster_product_),name());
Expand All @@ -33,8 +32,7 @@ class RandomClusterAlgo : public Algorithm<HGCal64BitRandomCodec> {

};

void RandomClusterAlgo::run(const l1t::HGCFETriggerDigiCollection& coll,
const std::unique_ptr<HGCalTriggerGeometryBase>& geom) {
void RandomClusterAlgo::run(const l1t::HGCFETriggerDigiCollection& coll) {
for( const auto& digi : coll ) {
HGCal64BitRandomCodec::data_type my_data;
digi.decode(codec_,my_data);
Expand Down
Loading

0 comments on commit c7b741d

Please sign in to comment.