Skip to content

Commit

Permalink
fix python to python3 syntax
Browse files Browse the repository at this point in the history
Include commit from fw_synch_210611 (#86)

* Fixes to remove unused TPROJ memory and fix problem with VMR LUT in L6

* apply code-formats and code-checks

Co-authored-by: Anders <aryd@cern.ch>

Update Settings.h (#89)

TE truncation reduced from 108 to 107, as requested in cms-L1TK#85

Update geometry and MC files (#91)

L1 tk dev 12 0 0 pre4 hph (#94)

* First Commit

* Code Format

* Fix Typo

* Naming Rule

* Chris' 2nd Comment

Co-authored-by: Jack Li <jingyan.li@cern.ch>

Reduced configuration (#87)

* Modified code to support a reduced config (the summer chain)

* Updates from running code checker.

* Reverted to standard configuration options.

* Reverted to standard configuration options.

* Settings used to make TV for event 1912

* Reverted to default settings for PR.

* Made some of the TV changes in issue 85, and created output TVs 2021-08-04-TTbar-SimpleFWHarmonization.

* Clarified comments

* Include commit from fw_synch_210611 (#86)

* Fixes to remove unused TPROJ memory and fix problem with VMR LUT in L6

* apply code-formats and code-checks

Co-authored-by: Anders <aryd@cern.ch>

* Returning to standard config.

* Returning to standard config.

* Returning to standard config.

* Update geometry and MC files (#91)

* Included reduced variable in non-reduced setups for consistency.

* Updated settings to match default configuration rather than HLS compatibility

* Added comment about reduced config files

Co-authored-by: Tova Holmes <tholmes@cern.ch>
Co-authored-by: Louise Skinnari <louise.skinnari@cern.ch>
Co-authored-by: Anders <aryd@cern.ch>
Co-authored-by: Ian Tomalin <ian.tomalin@stfc.ac.uk>

Revert "L1 tk dev 12 0 0 pre4 hph (#94)" (#95)

This reverts commit 3b2f139.

fix getPhiRes function (#97)

New KF (hand merged with L1TK-dev-12_0_0_pre4) (#88)

* initial commit.

* renamed KFout producer to TT producer

* KFout producer and analyzer added. Producer is so far only a skeleton.

* small includings fix.

* quick TTTypes fix

* comments for ian

* initial commit.

* renamed KFout producer to TT producer

* KFout producer and analyzer added. Producer is so far only a skeleton.

* small includings fix.

* quick TTTypes fix

* comments for ian

* small script modifications

* little ntuple maker mod.

* readding fake fit config interface.

* track tigger association added, not in the best way.

* tttrack associator added as it should be.

* option to use TTStubAssMap to associate TTTracks with TPs removed and output module cleaned up.

* Added Hybrid_NewKF

* Added comment

* Update L1TrackNtupleMaker_cfg.py

fix typo made by Ian

* added tmtt costumization and fakefit option to tracklet config

* data format fix

* README filled and Configuration.StandardSequences.L1TrackTrigger_cff removed from run scripts.

* associateFinal added to StubAssociation.

* Update README.md

English corrections

* minor changes in various comments.

* KF 7 layer tracking debugged and defaulted.

* turned supported geometry white list into a black list.

* Cbrown kfout (#93)

* Initial Commit for Kfout emulator

* with ttTrackRefMap back in

* Correct link structure and eta routing

* No more print statements

* Remove print statements

* Merge changes in kfout producer

* Thomas' comments #1

* Thomas' comments #2

* Change dphi/dz LUT scaling to num of bits

* Fix bug to phi sector correction

* sync with FW fix

* Commit of distribution server for clock accuracy

* Fix to undefined operation on numLinkTracks

* Fix to numLinkTracks #2

Co-authored-by: Ian Tomalin <ian.tomalin@stfc.ac.uk>
Co-authored-by: Chriisbrown <41648127+Chriisbrown@users.noreply.github.com>

fix of KFin EnableTruncation option. (#99)

* quick fix of KFin EnableTruncation option.

* both, enable and disabel truncation fixed.

Fix to KF out for multiple KF workers (#100)

code-format, llvm-ccdb and clang-tidy (#103)

Fixed clang errors (#104)

several bug fixes. (#108)

* bug fixes.

* code format

* GlobalTag update.

* forgot a bug fix in AnalyzerDemonstrator.

add number of TTCluster to DTC analzyer end job summary (#109)

* count of TTCluster added to endjob summary printout.

* rebase to L1TK-dev-12_0_0_pre4 and code format.

Added git CI (#106)

* Added git CI

* Run CI on PR to any branch

* Make L1TRKALGO configurable

* tweak

* Added script to skim MC datasets for git CI

* Remove L1TRKALGO option

* Gave CI more sensible name

Update github_CI.yml

temporary debug check

Memory cleanup (#98)

* Cleanup of writing leading 0x in memories

* Cleanup of obsolote comment

* Change order of input links to match VMRouter expectation

* Add support for debugging

* Remove one pipelining step to match HLS

* Determine the PS vs 2S in disks same way as we do in HLS

* Some cleanup

* Correction to LUT code

* Comment out printout

* Ran scram build code-format

* Update comment about IR steps

* Cleanup of obsolote comment

* Remove one pipelining step to match HLS

* Determine the PS vs 2S in disks same way as we do in HLS

* Correction to LUT code

* Ran scram build code-format

phiprojder bug fix (#116)

Channel Assignment TrackBuilder output Tracks + Stubs and InputRouter input Stubs (#110)

* track builder channel upgraded to assign stubs to channel.

* code format

* readded missing pieces.

* renamed TrackBuilderChannel to ChannelAssignment now also containing DTC to IR mapping

* name change in L1Trigger/TrackFindingTracklet/python/ProducerKF_cff.py

* bug fix

* name change of config parameter

* code-format

* namespace change and consitency check added.

* addressing ians comments

* addressing ians comments

TP_minPt and binning fix (#118)

Updated VMR maxstep to 107 (originally 108) to match firmware (#119)

Minor improvements (#120)

* Minor improvements

* Added comments

Dropped MC to 104 iterations (#123)

- Full agreement with HLS

Fixing integer range check in FPGAWord. (#125)

* fixing integer range check in FPGAWord.

* Fixing `zmatchcut_` for L1 and L2

* Undo the -0.06 in Settings.h as there is a cleaner fix to the overflows

* Slight rewerite to use <= instead < and not do subtracktion

* Fix < to <= to avoid overflow by one

Co-authored-by: Brent R. Yates <brentRyates@gmail.com>
Co-authored-by: Anders <aryd@cern.ch>

Fix KF Track Parameter Digitization (#127)

* Fix KF Track Parameter Digitization

* Add comments to Track.h

summer chain demonstrator (#111)

* track builder channel upgraded to assign stubs to channel.

* renamed TrackBuilderChannel to ChannelAssignment now also containing DTC to IR mapping

* ProducerIRin and ProducerTBout added, Demonstrator configured by default to use them.

* rebase with tschuh_TrackBuilder and code format

* StreamsStub added as EDProduct of L1FPGATrackProducer

* code format.

* convert only finally accepted Tracklets to StreamsStub.

* undo last commit, adding trackword ed product and adding gaps to stubs and tracks to get clock accurate emulation.

* swap bugfix.

* rebased and name change of TrackBuilderChannel adopted.

* fixing rebase errors.

* fixing more rebase errors.

* fixing even more rebase errors.

* first comments from Ian.

* code format

* second comments from Ian.

* code format

* Ians third comments.

* Ians 4th comments.

* small merge error fix

* Added comment

* Refine comment

* miniscule comment change

Co-authored-by: Ian Tomalin <ian.tomalin@stfc.ac.uk>

Fixed comparisons to avoid overflow. (#128)

MP HLS agreement fixes (#126)

* Fixing `zmatchcut_` for L1 and L2

* Undo the -0.06 in Settings.h as there is a cleaner fix to the overflows

* Fixes to get agreement with HLS code

* fixing integer range check in FPGAWord.

* Fixing `zmatchcut_` for L1 and L2

* Undo the -0.06 in Settings.h as there is a cleaner fix to the overflows

* Slight rewerite to use <= instead < and not do subtracktion

Co-authored-by: Brent R. Yates <brentRyates@gmail.com>
Co-authored-by: Thomas Schuh <thomas.schuh@stfc.ac.uk>

Update Settings.h (#130)

Fix "storeTrackBuilderOutput_" typo

Update Setup.cc (#129)

Change trackerDTC::Setup to tt::Setup . (Bug fix)

Update LayerEncoding.h (#131)

* Update LayerEncoding.h

Add function to access layer corresponding to given DTC channel. (Needed by L1Trk Future CMSSW code).

* Update LayerEncoding.h

response to comment + fix to previous commit

* Update LayerEncoding.cc

Initialize data member numDTCsPerRegion_

* Update LayerEncoding.h

added comment

* Update LayerEncoding.h

clarified comment

Test vector fixes (#132)

* Made eventProcessor a member of the producer.

* Output TC tables in the reduced config.

MP cleanup 220208 + MC fix (#133)

* fixing integer range check in FPGAWord.

* Fixing `zmatchcut_` for L1 and L2

* Undo the -0.06 in Settings.h as there is a cleaner fix to the overflows

* Slight rewerite to use <= instead < and not do subtracktion

* Fixing `zmatchcut_` for L1 and L2

* Undo the -0.06 in Settings.h as there is a cleaner fix to the overflows

* Some updates to MP to converge with HLS code

* Further clenup of the MP code

* More cleanup -removal of hardcoded numbers

* Further cleanup

* Fixing `zmatchcut_` for L1 and L2

* Undo the -0.06 in Settings.h as there is a cleaner fix to the overflows

* fixing integer range check in FPGAWord.

* Fixing `zmatchcut_` for L1 and L2

* Undo the -0.06 in Settings.h as there is a cleaner fix to the overflows

* Slight rewerite to use <= instead < and not do subtracktion

* Some updates to MP to converge with HLS code

* Further clenup of the MP code

* More cleanup -removal of hardcoded numbers

* Further cleanup

* Fixes to the MC to allow full agreement with HLS

* Added a comment header and pipeline description

* Added comment about MC iterations

Co-authored-by: Thomas Schuh <thomas.schuh@stfc.ac.uk>
Co-authored-by: Anders <aryd@cern.ch>

customize L1FPGATrackProducer (#112)

* track builder channel upgraded to assign stubs to channel.

* renamed TrackBuilderChannel to ChannelAssignment now also containing DTC to IR mapping

* StreamsStub added as EDProduct of L1FPGATrackProducer

* code format.

* convert only finally accepted Tracklets to StreamsStub.

* undo last commit, adding trackword ed product and adding gaps to stubs and tracks to get clock accurate emulation.

* swap bugfix.

* rebased and name change of TrackBuilderChannel adopted.

* fixing rebase errors.

* fixing more rebase errors.

* fixing even more rebase errors.

* track builder channel upgraded to assign stubs to channel.

* renamed TrackBuilderChannel to ChannelAssignment now also containing DTC to IR mapping

* StreamsStub added as EDProduct of L1FPGATrackProducer

* rebased and name change of TrackBuilderChannel adopted.

* criteria to build track updated, TBout works now for all seed types.

* StreamsStub added as EDProduct of L1FPGATrackProducer

* use customize function to manipulate L1FPGATrackProducer configuration

* rebase to tschuh_SummerChain, customize updated to set EmulateTB, demonstrator counts now the amount of passed events.

* initial counter values fixed.

* rebase and reduce config customize function extended

* fixing merge errors.

* Ians first comments.

* rebase and Ians secodn comments.

* Update ChannelAssignment_cfi.py

* Ians third comments.

* Ians fourth comments.

Co-authored-by: Ian Tomalin <ian.tomalin@stfc.ac.uk>

Update Customize_cff.py (#135)

TBout analyzer (#114)

* Reviewed.

* one merge error fixed, but a problem remains

* fixed second error.

* Update AnalyzerTBout.cc

Co-authored-by: Ian Tomalin <ian.tomalin@stfc.ac.uk>

Fix d0 bias (#124)

* Fix d0 bias

* Documented KF maths and variables

Ian tidy up (#137)

* Added function to convert ATCA slot to DTC name

* Moved dtcname to Settings.h and put underscore at end of settings

* Declared functions const if dont change data members

* Added comments to clarify params overridden by python cfg

* Added comment

* Removed duplicate function TCNAme

disable truncation for displaced tracking (#142)

DTC phi range hard-wired constants removed (#141)

* Added function to get num ATCA slots

* Added comment

* Automatically calc DTC phi ranges

* Improved comments

* Added comment

* Simplified phi offset calc

* Fixed missing half-sector rotation bug

* Added comments

* Changed dtcphirange.txt to numbers instead of C++ code

Displaced tracking phi fix (#147)

* usephiapprox on modify NtupleMaker cfg for grid jobs

* added displaced terms to phi calculation in TrackletCalculatorDisplaced

* reverting changes unrelated to phi correction

Jack hph (#146)

* First Commit

* Code Format

* Fix Typo

* Naming Rule

* Chris' 2nd Comment

* Fixing Bug

* Ian's 1st Comments

* Ian's 2nd Comment: Remove SensorModule Class

* Ian's 3rd comment: Get rid of magic numbers

* Ian's 4th Comment: Add more clarification

* Code-check

Co-authored-by: Jack Li <jingyan.li@cern.ch>

Adding new features to ntuplemaker (#148)

Co-authored-by: Jack Li <jingyan.li@cern.ch>

Update StubAssociation.cc (#145)

as requested a separate PR.

Update github_CI.yml

Fixed incorrect comment

KFin emulator (#143)

* initial commit.

* move ProducerTBout.cc from test to plugins

* KFin fully debugged.

* Producer TBout added to NTupleMaker

* chriss change to KFout

* Louises first comments.

* fixing rebase errors.

* KF reintegrated, stub residuals are not bit accurate yet.

* code format.

* added 1k ttbar@0PU events for internal kf maths tuning.

* Track builder r residual debug and KF digi function corrected.

* bug in z residual base fixed.

* Ians first comments.

* Ians secodn comments.

* recalculate z ressid from TTStubRefs, use TTStubRefs for seed stubs instead of fake stubs.

* Ians third comment.

* fixed comments TTDTC::Frames -> tt::Frames

* old stub uncertainty caclulation re-enabled.

* Ians 4th comments.

* code-checks.

* tilted stub z uncertainty fixed. not yet debugged against f/w.

* set max layers a kff adds to a track to 7 as we did in the past, no clue why it is 4 again ...

* agrrement with f/w, ready to merge.

Fix rare crash in KF (#151)

* Fix rare crash in KF

* Fixed line break

Removed obsolete parameter. (#152)

quick ntuple fix (#153)

* L1TrackNtupleMaker_cfg.py updated reduced workflow.

* further cleaning.

Update L1TrackNtupleMaker_cfg.py

fixed typo

Removal of dependencies of ChannelAssignement (#144)

* This code includes a new implementation of the Track and Stub Streams generation. The old code is still running in parallel.

* Remove code for old calculation of stream data - keeping the debug print out in this commit

* Remove debud printout

* added numSeedTypes function

* rebased Anders branch

* rebased Anders branch

* tidied up Anders branch

* tidied up Anders branch

* ran scram b code-format

* Thomas PR review comments

* max num of proj layers added to channel assignment.

* merge with Thomas commit

Co-authored-by: Ian Tomalin <ian.tomalin@stfc.ac.uk>
Co-authored-by: Thomas Schuh <thomas.schuh@stfc.ac.uk>

Ran second auto formatter tool (#154)

* Ran second auto formatter tool

* tweak

Update ProducerSetup_cfi.py

correct comment in code

Update Customize_cff.py

add comment in code

Tracklet Processor Displaced (#159)

* Tracklet Processor Displaced

* code-format

* code-format again

* remove unnecessary comments and add explanation for header file

* implement more comments

* remove more magic numbers

Update track quality chi2 bins (#161)

* update chi2 bins

* change chi2 variables to be per dof

Ian L1TStub bug fix (#160)

* Ran second auto formatter tool

* tweak

* Fixed bug in L1TStub::isTilted function

* Update L1TrackNtupleMaker_cfg.py

Removed unnecessary line

* Update L1FPGATrackProducer.cc

Fix incorrect tiltedBarrel variable in endcap

rebase and scram b code-format

ran formatter tool 2

tweak

Update chi2 tq bins (#165)

* change binning method used by track quality

* clean TrackQuality class to only create features used by default classifier

* ran scram b -j8 clang-format

Added tilted and endcap module ring no. to L1TStub (#166)

* Added tilted and endcap module ring no. to L1TStub

* auto formatting

Fix stub order bug (#164)

* fix to stub order bug

* fix to stub order bug

* Updated to one::EDAnalyzer

* ran scram b code format

* Fixed bug for combined modules

Update MatchCalculator.cc

Added comment.

rebase git conflict resolution

rebase git conflict resolution

rebase git conflict resolution

Remove obsolete FWCore functions (#168)

Updated data/ files

tweak

Reduce L1 tracking CPU (#172)

* Reduce CPU use

* Reduce CPU

* Reduce CPU

* Added track quality plots

* updated geom

* Trivial variable renames

* Moved RunTime call to constructor to save CPU

* Removed debug calcs from VarBase::calculate

* Optimised a bit more VarBase::calculate

* optimise CPU further

* auto format

Update L1TrackNtupleMaker.cc

Restored consumes<TrackingVertex>. Not required, but keeps CPU expensive loading of TrackingVertexCollection where it was to make CPU comparisons easier.

Removed CI .yml files & data/ directory to allow PR to central CMSSW
  • Loading branch information
skinnari committed Sep 20, 2022
1 parent a35549c commit 4457a9b
Show file tree
Hide file tree
Showing 256 changed files with 18,916 additions and 2,543 deletions.
172 changes: 132 additions & 40 deletions DataFormats/L1TrackTrigger/interface/TTBV.h
Expand Up @@ -7,29 +7,31 @@
#include <algorithm>
#include <cmath>
#include <utility>
#include <vector>
#include <iostream>

/*!
* \class TTBV
* \brief Bit vector used by Track Trigger emulators. Mainly used to convert
* integers into arbitrary (within margin) sized two's complement string.
* integers into arbitrary (within margin) sized two's complement strings.
* \author Thomas Schuh
* \date 2020, Jan
*/
class TTBV {
public:
static constexpr int S = 64; // Frame width of emp infrastructure f/w, max number of bits a TTBV can handle
static constexpr int S_ = 64; // Frame width of emp infrastructure f/w, max number of bits a TTBV can handle

private:
bool twos_; // Two's complement (true) or binary (false)
int size_; // number or bits
std::bitset<S> bs_; // underlying storage
bool twos_; // Two's complement (true) or binary (false)
int size_; // number or bits
std::bitset<S_> bs_; // underlying storage

public:
// constructor: default
TTBV() : twos_(false), size_(S), bs_(std::bitset<S>(0)) {}
TTBV() : twos_(false), size_(0), bs_() {}

// constructor: double precision (IEEE 754); from most to least significant bit: 1 bit sign + 11 bit binary exponent + 52 bit binary mantisse
TTBV(const double d) : twos_(false), size_(S) {
TTBV(const double d) : twos_(false), size_(S_) {
int index(0);
const char* c = reinterpret_cast<const char*>(&d);
for (int iByte = 0; iByte < (int)sizeof(d); iByte++) {
Expand All @@ -40,45 +42,58 @@ class TTBV {
}

// constructor: unsigned int value
TTBV(unsigned long long int value, int size) : twos_(false), size_(size), bs_(std::bitset<S>(value)) {}
TTBV(unsigned long long int value, int size) : twos_(false), size_(size), bs_(value) {}

// constructor: int value
TTBV(int value, int size, bool Signed = false)
: twos_(Signed), size_(size), bs_(std::bitset<S>((!Signed || value >= 0) ? value : value + iMax())) {}
TTBV(int value, int size, bool twos = false)
: twos_(twos), size_(size), bs_((!twos || value >= 0) ? value : value + iMax()) {}

// constructor: double value + precision, biased (floor) representation
TTBV(double value, double base, int size, bool Signed = false) : TTBV((int)std::floor(value / base), size, Signed) {}
TTBV(double value, double base, int size, bool twos = false) : TTBV((int)std::floor(value / base), size, twos) {}

// constructor: string
TTBV(const std::string& str, bool Signed = false) : twos_(Signed), size_(str.size()), bs_(std::bitset<S>(str)) {}
TTBV(const std::string& str, bool twos = false) : twos_(twos), size_(str.size()), bs_(str) {}

// constructor: bitset
TTBV(const std::bitset<S>& bs, bool Signed = false) : twos_(Signed), size_(S), bs_(std::bitset<S>(bs)) {}
TTBV(const std::bitset<S_>& bs, bool twos = false) : twos_(twos), size_(S_), bs_(bs) {}

// access: data members
// constructor: slice reinterpret sign
TTBV(const TTBV& ttBV, int begin, int end = 0, bool twos = false) : twos_(twos), size_(begin - end), bs_(ttBV.bs_) {
bs_ <<= S_ - begin;
bs_ >>= S_ - begin + end;
}

// Two's complement (true) or binary (false)
bool twos() const { return twos_; }
// number or bits
int size() const { return size_; }
std::bitset<S> bs() const { return bs_; }
// underlying storage
const std::bitset<S_>& bs() const { return bs_; }

// access: single bit
bool operator[](int pos) const { return bs_[pos]; }
std::bitset<S>::reference operator[](int pos) { return bs_[pos]; }
std::bitset<S_>::reference operator[](int pos) { return bs_[pos]; }

// access: most significant bit
// access: most significant bit copy
bool msb() const { return bs_[size_ - 1]; }
std::bitset<S>::reference msb() { return bs_[size_ - 1]; }

// access: most significant bit reference
std::bitset<S_>::reference msb() { return bs_[size_ - 1]; }

// access: members of underlying bitset

bool all() const { return bs_.all(); }
bool any() const { return bs_.any(); }
bool none() const { return bs_.none(); }
int count() const { return bs_.count(); }

// operator: comparisons
// operator: comparisons equal
bool operator==(const TTBV& rhs) const { return bs_ == rhs.bs_; }

// operator: comparisons not equal
bool operator!=(const TTBV& rhs) const { return bs_ != rhs.bs_; }

// operator: boolean and, or, xor, not
// operator: boolean and
TTBV& operator&=(const TTBV& rhs) {
const int m(std::max(size_, rhs.size()));
this->resize(m);
Expand All @@ -87,6 +102,8 @@ class TTBV {
bs_ &= bv.bs_;
return *this;
}

// operator: boolean or
TTBV& operator|=(const TTBV& rhs) {
const int m(std::max(size_, rhs.size()));
this->resize(m);
Expand All @@ -95,6 +112,8 @@ class TTBV {
bs_ |= bv.bs_;
return *this;
}

// operator: boolean xor
TTBV& operator^=(const TTBV& rhs) {
const int m(std::max(size_, rhs.size()));
this->resize(m);
Expand All @@ -103,89 +122,112 @@ class TTBV {
bs_ ^= bv.bs_;
return *this;
}

// operator: not
TTBV operator~() const {
TTBV bv(*this);
return bv.flip();
}

// operator: bit shifts
// reference operator: bit remove right
TTBV& operator>>=(int pos) {
bs_ >>= pos;
size_ -= pos;
return *this;
}

// reference operator: bit remove left
TTBV& operator<<=(int pos) {
bs_ <<= S - size_ + pos;
bs_ >>= S - size_ + pos;
bs_ <<= S_ - size_ + pos;
bs_ >>= S_ - size_ + pos;
size_ -= pos;
return *this;
}

// operator: bit remove left copy
TTBV operator<<(int pos) const {
TTBV bv(*this);
return bv >>= pos;
return bv <<= pos;
}

// operator: bit remove right copy
TTBV operator>>(int pos) const {
TTBV bv(*this);
return bv <<= pos;
return bv >>= pos;
}

// operator: concatenation
// reference operator: concatenation
TTBV& operator+=(const TTBV& rhs) {
bs_ <<= rhs.size();
bs_ |= rhs.bs_;
size_ += rhs.size();
return *this;
}

// operator: concatenation copy
TTBV operator+(const TTBV& rhs) const {
TTBV lhs(*this);
return lhs += rhs;
}

// operator: value increment, overflow protected
TTBV& operator++() {
bs_ = std::bitset<S>(bs_.to_ullong() + 1);
bs_ = std::bitset<S_>(bs_.to_ullong() + 1);
this->resize(size_);
return *this;
}

// manipulation: all bits
// manipulation: all bits set to 0
TTBV& reset() {
bs_.reset();
return *this;
}

// manipulation: all bits set to 1
TTBV& set() {
for (int n = 0; n < size_; n++)
bs_.set(n);
return *this;
}

// manipulation: all bits flip 1 to 0 and vice versa
TTBV& flip() {
for (int n = 0; n < size_; n++)
bs_.flip(n);
return *this;
}

// manipulation: single bit
// manipulation: single bit set to 0
TTBV& reset(int pos) {
bs_.reset(pos);
return *this;
}

// manipulation: single bit set to 1
TTBV& set(int pos) {
bs_.set(pos);
return *this;
}

// manipulation: multiple bit set to 1
TTBV& set(std::vector<int> vpos) {
for (int pos : vpos)
bs_.set(pos);
return *this;
}

// manipulation: single bit flip 1 to 0 and vice versa
TTBV& flip(int pos) {
bs_.flip(pos);
return *this;
}

// manipulation: biased absolute value
// manipulation: absolute value of biased twos' complement. Converts twos' complenet into binary.
TTBV& abs() {
if (twos_) {
twos_ = false;
if (this->msb()) {
if (this->msb())
this->flip();
this->operator++();
}
size_--;
}
return *this;
Expand All @@ -208,7 +250,7 @@ class TTBV {
}

// conversion: to string
std::string str() const { return bs_.to_string().substr(S - size_, S); }
std::string str() const { return bs_.to_string().substr(S_ - size_, S_); }

// conversion: range based to string
std::string str(int start, int end = 0) const { return this->str().substr(size_ - start, size_ - end); }
Expand All @@ -217,14 +259,40 @@ class TTBV {
int val() const { return (twos_ && this->msb()) ? (int)bs_.to_ullong() - iMax() : bs_.to_ullong(); }

// conversion: to int, reinterpret sign
int val(bool Signed) const { return (Signed && this->msb()) ? (int)bs_.to_ullong() - iMax() : bs_.to_ullong(); }
int val(bool twos) const { return (twos && this->msb()) ? (int)bs_.to_ullong() - iMax() : bs_.to_ullong(); }

// conversion: range based to int, reinterpret sign
int val(int start, int end = 0, bool Signed = false) const { return TTBV(this->str(start, end), Signed).val(); }
int val(int start, int end = 0, bool twos = false) const { return TTBV(*this, start, end).val(twos); }

// conversion: to double for given precision assuming biased (floor) representation
double val(double base) const { return (this->val() + .5) * base; }

// conversion: range based to double for given precision assuming biased (floor) representation, reinterpret sign
double val(double base, int start, int end = 0, bool twos = false) const {
return (this->val(start, end, twos) + .5) * base;
}

// maniplulation and conversion: extracts range based to double reinterpret sign and removes these bits
double extract(double base, int size, bool twos = false) {
double val = this->val(base, size, 0, twos);
this->operator>>=(size);
return val;
}

// maniplulation and conversion: extracts range based to int reinterpret sign and removes these bits
int extract(int size, bool twos = false) {
double val = this->val(size, 0, twos);
this->operator>>=(size);
return val;
}

// manipulation: extracts slice and removes these bits
TTBV slice(int size, bool twos = false) {
TTBV ttBV(*this, size, 0, twos);
this->operator>>=(size);
return ttBV;
}

// range based count of '1's or '0's
int count(int begin, int end, bool b = true) const {
int c(0);
Expand All @@ -250,18 +318,42 @@ class TTBV {
return size_;
}

// position for n'th '1' or '0' counted from least to most significant bit
int encode(int n, bool b = true) const {
int sum(0);
for (int e = 0; e < size_; e++) {
if (bs_[e] == b) {
sum++;
if (sum == n)
return e;
}
}
return size_;
}

std::vector<int> ids(bool b = true, bool singed = false) const {
std::vector<int> v;
v.reserve(bs_.count());
for (int i = 0; i < size_; i++)
if (bs_[i] == b)
v.push_back(singed ? i + size_ / 2 : i);
return v;
}

friend std::ostream& operator<<(std::ostream& os, const TTBV& ttBV) { return os << ttBV.str(); }

private:
// look up table initializer for powers of 2
constexpr std::array<unsigned long long int, S> powersOfTwo() const {
std::array<unsigned long long int, S> lut = {};
for (int i = 0; i < S; i++)
constexpr std::array<unsigned long long int, S_> powersOfTwo() const {
std::array<unsigned long long int, S_> lut = {};
for (int i = 0; i < S_; i++)
lut[i] = std::pow(2, i);
return lut;
}

// returns 2 ** size_
unsigned long long int iMax() const {
static const std::array<unsigned long long int, S> lut = powersOfTwo();
static const std::array<unsigned long long int, S_> lut = powersOfTwo();
return lut[size_];
}
};
Expand Down
15 changes: 3 additions & 12 deletions DataFormats/L1TrackTrigger/interface/TTDTC.h
Expand Up @@ -16,15 +16,6 @@
*/
class TTDTC {
public:
// bit accurate Stub
typedef std::bitset<TTBV::S> BV;
// TTStub with bit accurate Stub
typedef std::pair<TTStubRef, BV> Frame;
// stub collection transported over an optical link between DTC and TFP
typedef std::vector<Frame> Stream;
// collection of optical links
typedef std::vector<Stream> Streams;

TTDTC() {}
TTDTC(int numRegions, int numOverlappingRegions, int numDTCsPerRegion);
~TTDTC() {}
Expand All @@ -35,10 +26,10 @@ class TTDTC {
const std::vector<int>& tfpChannels() const { return channels_; }
// write one specific stream of TTStubRefs using DTC identifier (region[0-8], board[0-23], channel[0-1])
// dtcRegions aka detector regions are defined by tk layout
void setStream(int dtcRegion, int dtcBoard, int dtcChannel, const Stream& stream);
void setStream(int dtcRegion, int dtcBoard, int dtcChannel, const tt::StreamStub& stream);
// read one specific stream of TTStubRefs using TFP identifier (region[0-8], channel[0-47])
// tfpRegions aka processing regions are rotated by -0.5 region width w.r.t detector regions
const Stream& stream(int tfpRegion, int tfpChannel) const;
const tt::StreamStub& stream(int tfpRegion, int tfpChannel) const;
// total number of frames
int size() const;
// total number of stubs
Expand All @@ -64,7 +55,7 @@ class TTDTC {
// all TFP channel [default 0..47]
std::vector<int> channels_;
// collection of all optical links between DTC and TFP [default 432 links]
Streams streams_;
tt::StreamsStub streams_;
};

#endif

0 comments on commit 4457a9b

Please sign in to comment.