-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42545 from mmusich/mm_ApproxCluster_dataformat_13…
…_2_X [13.2.X] Add `SiStripApproximateClusterCollection` as a simple format for RAW
- Loading branch information
Showing
9 changed files
with
141 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollection.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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->clusters_.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 |
13 changes: 13 additions & 0 deletions
13
DataFormats/SiStripCluster/src/SiStripApproximateClusterCollection.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters