-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New version of RawPrime (SiStripApproximateCluster) #49013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
111 changes: 111 additions & 0 deletions
111
DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollectionV2.h
This file contains hidden or 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,111 @@ | ||
| #ifndef DataFormats_SiStripCluster_SiStripApproximateClusterCollectionV2_v1_h | ||
| #define DataFormats_SiStripCluster_SiStripApproximateClusterCollectionV2_v1_h | ||
|
|
||
| #include <vector> | ||
|
|
||
| #include "DataFormats/SiStripCluster/interface/SiStripApproximateCluster.h" | ||
| #include <iostream> | ||
| #include <numeric> | ||
| /** | ||
| * 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 SiStripApproximateClusterCollectionV2 { | ||
| public: | ||
| // Helper classes to make creation and iteration easier | ||
| class Filler { | ||
| public: | ||
| void push_back(SiStripApproximateCluster const& cluster) { clusters_.push_back(cluster); } | ||
|
|
||
| private: | ||
| friend SiStripApproximateClusterCollectionV2; | ||
| 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 std::accumulate(coll_->detIds_.cbegin(), coll_->detIds_.cbegin() + detIndex_ + 1, 0); | ||
| } | ||
|
|
||
| void move(unsigned int clusBegin) const { clusBegin_ = clusBegin; } | ||
| 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 SiStripApproximateClusterCollectionV2::const_iterator; | ||
| DetSet(SiStripApproximateClusterCollectionV2 const* coll, unsigned int detIndex) | ||
| : coll_(coll), | ||
| detIndex_(detIndex), | ||
| clusEnd_(coll->clusters_.size()) | ||
| //clusBegin_(coll_->beginIndices_[detIndex]), | ||
| //clusEnd_(detIndex == coll_->beginIndices_.size() - 1 ? coll->clusters_.size() | ||
| //: coll_->beginIndices_[detIndex + 1]) {} | ||
| {} | ||
|
|
||
| SiStripApproximateClusterCollectionV2 const* const coll_; | ||
| unsigned int const detIndex_; | ||
| mutable unsigned int clusBegin_ = 0; | ||
| 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 SiStripApproximateClusterCollectionV2; | ||
| // default-constructed object acts as the sentinel | ||
| const_iterator() = default; | ||
| const_iterator(SiStripApproximateClusterCollectionV2 const* coll) : coll_(coll) {} | ||
|
|
||
| SiStripApproximateClusterCollectionV2 const* coll_ = nullptr; | ||
| unsigned int index_ = 0; | ||
| }; | ||
|
|
||
| // Actual public interface | ||
| SiStripApproximateClusterCollectionV2() = default; | ||
|
|
||
| void reserve(std::size_t dets, std::size_t clusters); | ||
| Filler beginDet(unsigned int detId); | ||
|
|
||
| const_iterator begin() const { return clusters_.empty() ? end() : 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<SiStripApproximateCluster> clusters_; | ||
| }; | ||
| #endif |
This file contains hidden or 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 hidden or 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
10 changes: 10 additions & 0 deletions
10
DataFormats/SiStripCluster/src/SiStripApproximateClusterCollectionV2.cc
This file contains hidden or 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,10 @@ | ||
| #include "DataFormats/SiStripCluster/interface/SiStripApproximateClusterCollectionV2.h" | ||
| void SiStripApproximateClusterCollectionV2::reserve(std::size_t dets, std::size_t clusters) { | ||
| detIds_.reserve(dets); | ||
| clusters_.reserve(clusters); | ||
| } | ||
|
|
||
| SiStripApproximateClusterCollectionV2::Filler SiStripApproximateClusterCollectionV2::beginDet(unsigned int detId) { | ||
| detIds_.push_back((detIds_.empty()) ? detId : detId - (std::accumulate(detIds_.cbegin(), detIds_.cend(), 0))); | ||
| return Filler(clusters_); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't those bitmasks be a constant somewhere, so it's more readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I've changed it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks! :)