Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#ifndef DataFormats_SiStripCluster_SiStripApproximateClusterCollection_h
#define DataFormats_SiStripCluster_SiStripApproximateClusterCollection_h

#include <vector>

#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"

/**
* This class provides a minimal interface that resembles
* edmNew::DetSetVector, but is crafted such that we are comfortable
* to provide an infinite backwards compatibility guarantee for it
* (like all RAW data). Any modifications need to be made with care.
* Please consult core software group if in doubt.
**/
class SiStripApproximateClusterCollection {
public:
// Helper classes to make creation and iteration easier
class Filler {
public:
void push_back(SiStripApproximateCluster const& cluster) { clusters_.push_back(cluster); }

private:
friend SiStripApproximateClusterCollection;
Filler(std::vector<SiStripApproximateCluster>& clusters) : clusters_(clusters) {}

std::vector<SiStripApproximateCluster>& clusters_;
};

class const_iterator;
class DetSet {
public:
using const_iterator = std::vector<SiStripApproximateCluster>::const_iterator;

unsigned int id() const { return coll_->detIds_[detIndex_]; }

const_iterator begin() const { return coll_->clusters_.begin() + clusBegin_; }
const_iterator cbegin() const { return begin(); }
const_iterator end() const { return coll_->clusters_.begin() + clusEnd_; }
const_iterator cend() const { return end(); }

private:
friend SiStripApproximateClusterCollection::const_iterator;
DetSet(SiStripApproximateClusterCollection const* coll, unsigned int detIndex)
: coll_(coll),
detIndex_(detIndex),
clusBegin_(coll_->beginIndices_[detIndex]),
clusEnd_(detIndex == coll_->beginIndices_.size() - 1 ? coll_->beginIndices_.size()
: coll_->beginIndices_[detIndex + 1]) {}

SiStripApproximateClusterCollection const* const coll_;
unsigned int const detIndex_;
unsigned int const clusBegin_;
unsigned int const clusEnd_;
};

class const_iterator {
public:
DetSet operator*() const { return DetSet(coll_, index_); }

const_iterator& operator++() {
++index_;
if (index_ == coll_->detIds_.size()) {
*this = const_iterator();
}
return *this;
}

const_iterator operator++(int) {
const_iterator clone = *this;
++(*this);
return clone;
}

bool operator==(const_iterator const& other) const { return coll_ == other.coll_ and index_ == other.index_; }
bool operator!=(const_iterator const& other) const { return not operator==(other); }

private:
friend SiStripApproximateClusterCollection;
// default-constructed object acts as the sentinel
const_iterator() = default;
const_iterator(SiStripApproximateClusterCollection const* coll) : coll_(coll) {}

SiStripApproximateClusterCollection const* coll_ = nullptr;
unsigned int index_ = 0;
};

// Actual public interface
SiStripApproximateClusterCollection() = default;

void reserve(std::size_t dets, std::size_t clusters);
Filler beginDet(unsigned int detId);

const_iterator begin() const { return const_iterator(this); }
const_iterator cbegin() const { return begin(); }
const_iterator end() const { return const_iterator(); }
const_iterator cend() const { return end(); }

private:
// The detIds_ and beginIndices_ have one element for each Det. An
// element of beginIndices_ points to the first cluster of the Det
// in clusters_.
std::vector<unsigned int> detIds_; // DetId for the Det
std::vector<unsigned int> beginIndices_;
std::vector<SiStripApproximateCluster> clusters_;
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection.h"

void SiStripApproximateClusterCollection::reserve(std::size_t dets, std::size_t clusters) {
detIds_.reserve(dets);
beginIndices_.reserve(dets);
clusters_.reserve(clusters);
}

SiStripApproximateClusterCollection::Filler SiStripApproximateClusterCollection::beginDet(unsigned int detId) {
detIds_.push_back(detId);
beginIndices_.push_back(clusters_.size());
return Filler(clusters_);
}
1 change: 1 addition & 0 deletions DataFormats/SiStripCluster/src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "DataFormats/SiStripCluster/interface/SiStripClustersSOA.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection.h"
#include "DataFormats/Common/interface/ContainerMask.h"

#endif // SISTRIPCLUSTER_CLASSES_H
4 changes: 4 additions & 0 deletions DataFormats/SiStripCluster/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<version ClassVersion="4" checksum="2854791577"/>
<version ClassVersion="3" checksum="2041370183"/>
</class>
<class name="SiStripApproximateClusterCollection" ClassVersion="3">
<version ClassVersion="3" checksum="3101417750"/>
</class>
<class name="edm::Wrapper<SiStripApproximateClusterCollection>"/>

<class name="edmNew::DetSetVector<SiStripApproximateCluster>"/>
<class name="edm::Wrapper<edmNew::DetSetVector<SiStripApproximateCluster>>"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection.h"
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
Expand All @@ -25,13 +25,12 @@ class SiStripApprox2Clusters : public edm::global::EDProducer<> {
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
edm::EDGetTokenT<edmNew::DetSetVector<SiStripApproximateCluster>> clusterToken_;
edm::EDGetTokenT<SiStripApproximateClusterCollection> clusterToken_;
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
};

SiStripApprox2Clusters::SiStripApprox2Clusters(const edm::ParameterSet& conf) {
clusterToken_ = consumes<edmNew::DetSetVector<SiStripApproximateCluster>>(
conf.getParameter<edm::InputTag>("inputApproxClusters"));
clusterToken_ = consumes(conf.getParameter<edm::InputTag>("inputApproxClusters"));
tkGeomToken_ = esConsumes();
produces<edmNew::DetSetVector<SiStripCluster>>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include "FWCore/ParameterSet/interface/FileInPath.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection.h"
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"
Comment on lines +23 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection.h"
#include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
#include "DataFormats/Common/interface/DetSetVectorNew.h"
#include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection.h"

Three includes are duplicated of the already included ones.
And please move up together the other DataFormats includes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, since only DetSetVectorNew seems to be used, I think you can remove the includes of "DataFormats/Common/interface/DetSetVector.h"

#include "FWCore/Utilities/interface/ESInputTag.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
Expand Down Expand Up @@ -84,12 +88,13 @@ SiStripClusters2ApproxClusters::SiStripClusters2ApproxClusters(const edm::Parame

stripNoiseToken_ = esConsumes();

produces<edmNew::DetSetVector<SiStripApproximateCluster> >();
produces<SiStripApproximateClusterCollection>();
}

void SiStripClusters2ApproxClusters::produce(edm::Event& event, edm::EventSetup const& iSetup) {
auto result = std::make_unique<edmNew::DetSetVector<SiStripApproximateCluster> >();
const auto& clusterCollection = event.get(clusterToken);
auto result = std::make_unique<SiStripApproximateClusterCollection>();
result->reserve(clusterCollection.size(), clusterCollection.dataSize());

auto const beamSpotHandle = event.getHandle(beamSpotToken_);
auto const& bs = beamSpotHandle.isValid() ? *beamSpotHandle : reco::BeamSpot();
Expand All @@ -103,7 +108,7 @@ void SiStripClusters2ApproxClusters::produce(edm::Event& event, edm::EventSetup
const auto& theNoise_ = &iSetup.getData(stripNoiseToken_);

for (const auto& detClusters : clusterCollection) {
edmNew::DetSetVector<SiStripApproximateCluster>::FastFiller ff{*result, detClusters.id()};
auto ff = result->beginDet(detClusters.id());

unsigned int detId = detClusters.id();
const GeomDet* det = tkGeom->idToDet(detId);
Expand Down