diff --git a/.gitignore b/.gitignore index f7e304cea..ac9e1b3e7 100644 --- a/.gitignore +++ b/.gitignore @@ -22,8 +22,6 @@ efficiency/bin/createEffNumDenPlots efficiency/bin/createPerfNumDenHists efficiency/compare efficiency/summary -efficiency/misc/compare -efficiency/misc/summary *.txt *.pyc output* diff --git a/bin/sdl.h b/bin/sdl.h index f2f5772bd..dec3f9801 100644 --- a/bin/sdl.h +++ b/bin/sdl.h @@ -8,7 +8,6 @@ #include #include #include -#include #include #include "trktree.h" diff --git a/code/core/Hit.cc b/code/core/Hit.cc deleted file mode 100644 index 019f2f906..000000000 --- a/code/core/Hit.cc +++ /dev/null @@ -1,232 +0,0 @@ -#include "Hit.h" - -SDL::CPU::Hit::Hit(): x_(0), y_(0), z_(0) -{ - setDerivedQuantities(); -} - -SDL::CPU::Hit::Hit(float x, float y, float z, int idx): x_(x), y_(y), z_(z), idx_(idx) -{ - setDerivedQuantities(); -} - -SDL::CPU::Hit::Hit(const Hit& hit): x_(hit.x()), y_(hit.y()), z_(hit.z()), idx_(hit.idx()) -{ - setDerivedQuantities(); -} - -SDL::CPU::Hit::~Hit() -{ -} - -void SDL::CPU::Hit::setX(float x) -{ - x_ = x; - setDerivedQuantities(); -} - -void SDL::CPU::Hit::setY(float y) -{ - y_ = y; - setDerivedQuantities(); -} - -void SDL::CPU::Hit::setZ(float z) -{ - z_ = z; - setDerivedQuantities(); -} - -void SDL::CPU::Hit::setXYZ(float x, float y, float z) -{ - x_ = x; - y_ = y; - z_ = z; - setDerivedQuantities(); -} - -void SDL::CPU::Hit::setIdx(int idx) -{ - idx_ = idx; -} - -void SDL::CPU::Hit::setHitHighEdgePtr(SDL::CPU::Hit* hit) -{ - hit_high_edge_ = hit; -} - -void SDL::CPU::Hit::setHitLowEdgePtr(SDL::CPU::Hit* hit) -{ - hit_low_edge_ = hit; -} - -void SDL::CPU::Hit::setDerivedQuantities() -{ - - // Setting r3 - r3_ = sqrt(x_ * x_ + y_ * y_ + z_ * z_); - - // Setting rt - rt_ = sqrt(x_ * x_ + y_ * y_); - - // Setting phi - phi_ = SDL::CPU::MathUtil::Phi_mpi_pi(M_PI + SDL::CPU::MathUtil::ATan2(-y_, -x_)); - - // Setting eta - eta_ = ((z_ > 0) - ( z_ < 0)) * std::acosh(r3_ / rt_); - -} - -const float& SDL::CPU::Hit::x() const -{ - return x_; -} - -const float& SDL::CPU::Hit::y() const -{ - return y_; -} - -const float& SDL::CPU::Hit::z() const -{ - return z_; -} - -const float& SDL::CPU::Hit::r3() const -{ - return r3_; -} - -const float& SDL::CPU::Hit::rt() const -{ - return rt_; -} - -const float& SDL::CPU::Hit::phi() const -{ - return phi_; -} - -const float& SDL::CPU::Hit::eta() const -{ - return eta_; -} - -const int& SDL::CPU::Hit::idx() const -{ - return idx_; -} - -// Set the boundary hits where the hits are shifted -const SDL::CPU::Hit* SDL::CPU::Hit::getHitHighEdgePtr() const -{ - return hit_high_edge_; -} - -const SDL::CPU::Hit* SDL::CPU::Hit::getHitLowEdgePtr() const -{ - return hit_low_edge_; -} - -float SDL::CPU::Hit::deltaPhi(const SDL::CPU::Hit& hit) const -{ - return SDL::CPU::MathUtil::Phi_mpi_pi(hit.phi() - phi_); -} - -float SDL::CPU::Hit::deltaPhiChange(const SDL::CPU::Hit& hit) const -{ - /* - Compute the change in phi going from point *this -> *hit - - \ o <-- *hit - \ / - \ f / - \^/ - o <-- *this - \ - \ - \ - x - - */ - - return this->deltaPhi(hit - (*this)); - -} - -bool SDL::CPU::Hit::isIdxMatched(const SDL::CPU::Hit& hit) const -{ - if (hit.idx() == idx()) - return true; - return false; -} - -// operators -bool SDL::CPU::Hit::operator !=(const Hit& hit) const -{ - return ((hit.x() != x_ or hit.y() != y_ or hit.z() != z_) ? true : false); -} - -bool SDL::CPU::Hit::operator ==(const Hit& hit) const -{ - return ((hit.x() == x_ and hit.y() == y_ and hit.z() == z_) ? true : false); -} - -SDL::CPU::Hit SDL::CPU::Hit::operator - (const Hit& hit) const -{ - return Hit(x_-hit.x(), y_-hit.y(), z_-hit.z()); -} - -SDL::CPU::Hit& SDL::CPU::Hit::operator = (const Hit& hit) -{ - x_ = hit.x(); - y_ = hit.y(); - z_ = hit.z(); - setDerivedQuantities(); - return *this; -} - -SDL::CPU::Hit& SDL::CPU::Hit::operator -=(const Hit& hit) -{ - x_ -= hit.x(); - y_ -= hit.y(); - z_ -= hit.z(); - setDerivedQuantities(); - return *this; -} - -SDL::CPU::Hit& SDL::CPU::Hit::operator +=(const Hit& hit) -{ - x_ += hit.x(); - y_ += hit.y(); - z_ += hit.z(); - setDerivedQuantities(); - return *this; -} - -SDL::CPU::Hit& SDL::CPU::Hit::operator /=(const float& denom) -{ - x_ /= denom; - y_ /= denom; - z_ /= denom; - setDerivedQuantities(); - return *this; -} - -namespace SDL -{ - namespace CPU - { - std::ostream& operator<<(std::ostream& out, const Hit& hit) - { - out << "Hit(x=" << hit.x() << ", y=" << hit.y() << ", z=" << hit.z() << ", r3=" << hit.r3() << ", rt=" << hit.rt() << ", phi=" << hit.phi() << ", eta=" << hit.eta() << ")"; - return out; - } - - std::ostream& operator<<(std::ostream& out, const Hit* hit) - { - out << *hit; - return out; - } - } -} diff --git a/code/core/Hit.h b/code/core/Hit.h deleted file mode 100644 index 617050d32..000000000 --- a/code/core/Hit.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef Hit_h -#define Hit_h - -#include -#include -#include - -#include "MathUtil.h" - -namespace SDL -{ - - namespace CPU - { - - class Hit - { - private: - - float x_; - float y_; - float z_; - float r3_; // 3d distance from origin - float rt_; // transverse distance - float phi_; - float eta_; - int idx_; // unique index to the hit index in the ntuple - - Hit* hit_high_edge_; - Hit* hit_low_edge_; - - void setDerivedQuantities(); - - public: - - // cnstr/destr - Hit(); - Hit(float x, float y, float z, int idx=-1); - Hit(const Hit&); - ~Hit(); - - // modifying class content - void setX(float x); - void setY(float y); - void setZ(float z); - void setXYZ(float x, float y, float z); - void setIdx(int idx); - - // Set the boundary hits where the hits are shifted - void setHitHighEdgePtr(Hit* hit); - void setHitLowEdgePtr(Hit* hit); - - // accessor functions - const float& x() const; - const float& y() const; - const float& z() const; - const float& rt() const; - const float& r3() const; - const float& phi() const; - const float& eta() const; - const int& idx() const; - - // Set the boundary hits where the hits are shifted - const Hit* getHitHighEdgePtr() const; - const Hit* getHitLowEdgePtr() const; - - // variable computation between two hits - float deltaPhi(const Hit&) const; - float deltaPhiChange(const Hit&) const; - bool isIdxMatched(const Hit&) const; - - // operator overloading - bool operator !=(const Hit&) const; - bool operator ==(const Hit&) const; - Hit operator - (const Hit&) const; - Hit& operator = (const Hit&); - Hit& operator -=(const Hit&); - Hit& operator +=(const Hit&); - Hit& operator /=(const float&); - - // cout printing - friend std::ostream& operator<<(std::ostream& out, const Hit& hit); - friend std::ostream& operator<<(std::ostream& out, const Hit* hit); - - }; - } - -} - -#endif diff --git a/code/core/MathUtil.cc b/code/core/MathUtil.cc deleted file mode 100644 index a6726daa9..000000000 --- a/code/core/MathUtil.cc +++ /dev/null @@ -1,116 +0,0 @@ -#include "MathUtil.h" - -float SDL::CPU::MathUtil::Phi_mpi_pi(float x) -{ - if (std::isnan(x)) - { - std::cout << "SDL::CPU::MathUtil::Phi_mpi_pi() function called with NaN" << std::endl; - return x; - } - - while (x >= M_PI) - x -= 2. * M_PI; - - while (x < -M_PI) - x += 2. * M_PI; - - return x; - -} - -float SDL::CPU::MathUtil::ATan2(float y, float x) -{ - if (x != 0) return atan2(y, x); - if (y == 0) return 0; - if (y > 0) return M_PI / 2; - else return -M_PI / 2; -} - -float SDL::CPU::MathUtil::ptEstimateFromDeltaPhiChangeAndRt(float dPhiChange, float rt) -{ - return rt * 2.99792458e-3 * 3.8 / 2. / std::sin(dPhiChange); -} - -float SDL::CPU::MathUtil::ptEstimateFromRadius(float radius) -{ - return 2.99792458e-3 * 3.8 * radius; -} - -float SDL::CPU::MathUtil::dphiEstimateFromPtAndRt(float pt, float rt) -{ - return std::asin(rt / (2 * pt / (2.99792458e-3 * 3.8))); -} - -SDL::CPU::Hit SDL::CPU::MathUtil::getCenterFromThreePoints(SDL::CPU::Hit& hitA, SDL::CPU::Hit& hitB, SDL::CPU::Hit& hitC) -{ - - // C - // - // - // - // B d <-- find this point that makes the arc that goes throw a b c - // - // - // A - - // Steps: - // 1. Calculate mid-points of lines AB and BC - // 2. Find slopes of line AB and BC - // 3. construct a perpendicular line between AB and BC - // 4. set the two equations equal to each other and solve to find intersection - - float xA = hitA.x(); - float yA = hitA.y(); - float xB = hitB.x(); - float yB = hitB.y(); - float xC = hitC.x(); - float yC = hitC.y(); - - float x_mid_AB = (xA + xB) / 2.; - float y_mid_AB = (yA + yB) / 2.; - - //float x_mid_BC = (xB + xC) / 2.; - //float y_mid_BC = (yB + yC) / 2.; - - bool slope_AB_inf = (xB - xA) == 0; - bool slope_BC_inf = (xC - xB) == 0; - - bool slope_AB_zero = (yB - yA) == 0; - bool slope_BC_zero = (yC - yB) == 0; - - float slope_AB = slope_AB_inf ? 0 : (yB - yA) / (xB - xA); - float slope_BC = slope_BC_inf ? 0 : (yC - yB) / (xC - xB); - - float slope_perp_AB = slope_AB_inf or slope_AB_zero ? 0. : -1. / (slope_AB); - //float slope_perp_BC = slope_BC_inf or slope_BC_zero ? 0. : -1. / (slope_BC); - - if ((slope_AB - slope_BC) == 0) - { - std::cout << " slope_AB_zero: " << slope_AB_zero << std::endl; - std::cout << " slope_BC_zero: " << slope_BC_zero << std::endl; - std::cout << " slope_AB_inf: " << slope_AB_inf << std::endl; - std::cout << " slope_BC_inf: " << slope_BC_inf << std::endl; - std::cout << " slope_AB: " << slope_AB << std::endl; - std::cout << " slope_BC: " << slope_BC << std::endl; - std::cout << hitA << std::endl; - std::cout << hitB << std::endl; - std::cout << hitC << std::endl; - std::cout << "SDL::CPU::MathUtil::getCenterFromThreePoints() function the three points are in straight line!" << std::endl; - return SDL::CPU::Hit(); - } - - float x = (slope_AB * slope_BC * (yA - yC) + slope_BC * (xA + xB) - slope_AB * (xB + xC)) / (2. * (slope_BC - slope_AB)); - float y = slope_perp_AB * (x - x_mid_AB) + y_mid_AB; - - return SDL::CPU::Hit(x, y, 0); - -} - -float SDL::CPU::MathUtil::angleCorr(float dr, float pt, float angle) -{ - const float kRinv1GeVf = (2.99792458e-3 * 3.8); - const float k2Rinv1GeVf = kRinv1GeVf / 2.; - const float sinAlphaMax = 0.95; - return copysign(std::asin(std::min(dr * k2Rinv1GeVf / std::abs(pt), sinAlphaMax)), angle); -} - diff --git a/code/core/MathUtil.h b/code/core/MathUtil.h deleted file mode 100644 index 7a6fc6051..000000000 --- a/code/core/MathUtil.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef SDL_MathUtil_h -#define SDL_MathUtil_h - -#include -#include - -#include "Hit.h" - -namespace SDL -{ - namespace CPU - { - class Hit; - } -} - -namespace SDL -{ - namespace CPU - { - // functions for math related operations - namespace MathUtil - { - - float Phi_mpi_pi(float phi); - float ATan2(float y, float x); - float ptEstimateFromDeltaPhiChangeAndRt(float dphiChange, float rt); - float ptEstimateFromRadius(float radius); - float dphiEstimateFromPtAndRt(float pt, float rt); - SDL::CPU::Hit getCenterFromThreePoints(SDL::CPU::Hit& hit1, SDL::CPU::Hit& hit2, SDL::CPU::Hit& hit3); - float angleCorr(float dr, float pt, float angle); - - } - } -} - -#endif diff --git a/code/core/SDLMath.h b/code/core/SDLMath.h index 6be480e2f..718727026 100644 --- a/code/core/SDLMath.h +++ b/code/core/SDLMath.h @@ -2,9 +2,40 @@ #define SDLMath_h #include #include +#include namespace SDLMath { + inline float Phi_mpi_pi(float x) + { + if (std::isnan(x)) + { + std::cout << "MathUtil::Phi_mpi_pi() function called with NaN" << std::endl; + return x; + } + + while (x >= M_PI) + x -= 2. * M_PI; + + while (x < -M_PI) + x += 2. * M_PI; + + return x; + }; + + inline float ATan2(float y, float x) + { + if (x != 0) return atan2(y, x); + if (y == 0) return 0; + if (y > 0) return M_PI / 2; + else return -M_PI / 2; + }; + + inline float ptEstimateFromRadius(float radius) + { + return 2.99792458e-3 * 3.8 * radius; + }; + class Helix { public: @@ -58,14 +89,6 @@ namespace SDLMath const float lam() { return lam_; } const float charge() { return charge_; } - float Phi_mpi_pi(float phi) - { - float f = phi; - while (f >= M_PI) f -= 2. * M_PI; - while (f < -M_PI) f += 2. * M_PI; - return f; - } - std::tuple get_helix_point(float t) { float x = center()[0] - charge() * radius() * sin(phi() - (charge()) * t); @@ -100,5 +123,111 @@ namespace SDLMath }; + class Hit + { + public: + float x_, y_, z_; + // Derived quantities + float r3_, rt_, phi_, eta_; + int idx_; + + // Default constructor + Hit() : x_(0), y_(0), z_(0), idx_(-1) { + setDerivedQuantities(); + } + + // Parameterized constructor + Hit(float x, float y, float z, int idx = -1) : x_(x), y_(y), z_(z), idx_(idx) { + setDerivedQuantities(); + } + + // Copy constructor + Hit(const Hit& hit) : x_(hit.x_), y_(hit.y_), z_(hit.z_), idx_(hit.idx_) { + setDerivedQuantities(); + } + + // Getters for derived quantities + float phi() const { return phi_; } + float eta() const { return eta_; } + float rt() const { return rt_; } + float x() const { return x_; } + float y() const { return y_; } + + private: + void setDerivedQuantities() { + // Setting r3 + r3_ = sqrt(x_ * x_ + y_ * y_ + z_ * z_); + + // Setting rt + rt_ = sqrt(x_ * x_ + y_ * y_); + + // Setting phi + phi_ = Phi_mpi_pi(M_PI + ATan2(-y_, -x_)); + + // Setting eta + eta_ = ((z_ > 0) - ( z_ < 0)) * std::acosh(r3_ / rt_); + } + }; + + inline Hit getCenterFromThreePoints(Hit& hitA, Hit& hitB, Hit& hitC) + { + + // C + // + // + // + // B d <-- find this point that makes the arc that goes throw a b c + // + // + // A + + // Steps: + // 1. Calculate mid-points of lines AB and BC + // 2. Find slopes of line AB and BC + // 3. construct a perpendicular line between AB and BC + // 4. set the two equations equal to each other and solve to find intersection + + float xA = hitA.x(); + float yA = hitA.y(); + float xB = hitB.x(); + float yB = hitB.y(); + float xC = hitC.x(); + float yC = hitC.y(); + + float x_mid_AB = (xA + xB) / 2.; + float y_mid_AB = (yA + yB) / 2.; + + //float x_mid_BC = (xB + xC) / 2.; + //float y_mid_BC = (yB + yC) / 2.; + + bool slope_AB_inf = (xB - xA) == 0; + bool slope_BC_inf = (xC - xB) == 0; + + bool slope_AB_zero = (yB - yA) == 0; + bool slope_BC_zero = (yC - yB) == 0; + + float slope_AB = slope_AB_inf ? 0 : (yB - yA) / (xB - xA); + float slope_BC = slope_BC_inf ? 0 : (yC - yB) / (xC - xB); + + float slope_perp_AB = slope_AB_inf or slope_AB_zero ? 0. : -1. / (slope_AB); + //float slope_perp_BC = slope_BC_inf or slope_BC_zero ? 0. : -1. / (slope_BC); + + if ((slope_AB - slope_BC) == 0) + { + std::cout << " slope_AB_zero: " << slope_AB_zero << std::endl; + std::cout << " slope_BC_zero: " << slope_BC_zero << std::endl; + std::cout << " slope_AB_inf: " << slope_AB_inf << std::endl; + std::cout << " slope_BC_inf: " << slope_BC_inf << std::endl; + std::cout << " slope_AB: " << slope_AB << std::endl; + std::cout << " slope_BC: " << slope_BC << std::endl; + std::cout << "MathUtil::getCenterFromThreePoints() function the three points are in straight line!" << std::endl; + return Hit(); + } + + float x = (slope_AB * slope_BC * (yA - yC) + slope_BC * (xA + xB) - slope_AB * (xB + xC)) / (2. * (slope_BC - slope_AB)); + float y = slope_perp_AB * (x - x_mid_AB) + y_mid_AB; + + return Hit(x, y, 0); + }; } #endif diff --git a/code/core/trkCore.cc b/code/core/trkCore.cc index b0bac6410..971855740 100644 --- a/code/core/trkCore.cc +++ b/code/core/trkCore.cc @@ -278,9 +278,9 @@ std::vector matchedSimTrkIdxs(std::vector hitidxs, std::vecto } std::vector> to_check_duplicate; - for (auto &&[ihit, ihitdata] : iter::enumerate(iter::zip(hitidxs, hittypes))) - { - auto &&[hitidx, hittype] = ihitdata; + for (size_t i = 0; i < hitidxs.size(); ++i) { + auto hitidx = hitidxs[i]; + auto hittype = hittypes[i]; auto item = std::make_pair(hitidx, hittype); if (std::find(to_check_duplicate.begin(), to_check_duplicate.end(), item) == to_check_duplicate.end()) { @@ -299,8 +299,8 @@ std::vector matchedSimTrkIdxs(std::vector hitidxs, std::vecto << "------------------------" << std::endl; } - for (auto &&[ihit, ihitdata] : iter::enumerate(to_check_duplicate)) - { + for (size_t ihit = 0; ihit < to_check_duplicate.size(); ++ihit) { + auto ihitdata = to_check_duplicate[ihit]; auto &&[hitidx, hittype] = ihitdata; if (verbose) @@ -680,7 +680,7 @@ void addInputsToLineSegmentTrackingPreLoad(std::vector> &out_ std::iota(hitIdxs.begin(), hitIdxs.end(), 0); const int hit_size = trkX.size(); - for (auto &&[iSeed, _] : iter::enumerate(trk.see_stateTrajGlbPx())) + for (size_t iSeed = 0; iSeed < trk.see_stateTrajGlbPx().size(); ++iSeed) { //// track algorithm; partial copy from TrackBase.h @@ -849,7 +849,7 @@ void addInputsToLineSegmentTrackingPreLoad(std::vector> &out_ isQuad_vec.push_back(isQuad); } - } // iter::enumerate(trk.see_stateTrajGlbPx + } out_trkX.push_back(trkX); out_trkY.push_back(trkY); @@ -970,8 +970,9 @@ void printTimingInformation(std::vector>& timing_information, std::vector timing_sum_information(timing_information[0].size()); std::vector timing_shortlist; std::vector timing_list; - for (auto &&[ievt, timing] : iter::enumerate(timing_information)) + for (size_t ievt = 0; ievt < timing_information.size(); ++ievt) { + auto timing = timing_information[ievt]; float timing_total = 0.f; float timing_total_short = 0.f; timing_total += timing[0] * 1000; // Hits @@ -1247,7 +1248,7 @@ float addInputsToLineSegmentTracking(SDL::Event &event, bool useOMP) std::iota(hitIdxs.begin(), hitIdxs.end(), 0); const int hit_size = trkX.size(); - for (auto &&[iSeed, _] : iter::enumerate(trk.see_stateTrajGlbPx())) + for (size_t iSeed = 0; iSeed < trk.see_stateTrajGlbPx().size(); ++iSeed) { bool good_seed_type = false; if (trk.see_algo()[iSeed] == 4) good_seed_type = true; diff --git a/code/core/trkCore.h b/code/core/trkCore.h index 934648173..36fb6c107 100644 --- a/code/core/trkCore.h +++ b/code/core/trkCore.h @@ -8,8 +8,6 @@ #include "SDL/ModuleConnectionMap.h" #include "SDLMath.h" #include "SDL/Event.h" -#include -#include #include #include diff --git a/code/core/write_sdl_ntuple.cc b/code/core/write_sdl_ntuple.cc index 359fa4a50..56f956388 100644 --- a/code/core/write_sdl_ntuple.cc +++ b/code/core/write_sdl_ntuple.cc @@ -648,11 +648,11 @@ void setGnnNtupleBranches(SDL::Event* event) std::vector hits = getHitsFromLS(event, sgIdx); // Computing line segment pt estimate (assuming beam spot is at zero) - SDL::CPU::Hit hitA(0, 0, 0); - SDL::CPU::Hit hitB(hitsInGPU.xs[hits[0]], hitsInGPU.ys[hits[0]], hitsInGPU.zs[hits[0]]); - SDL::CPU::Hit hitC(hitsInGPU.xs[hits[2]], hitsInGPU.ys[hits[2]], hitsInGPU.zs[hits[2]]); - SDL::CPU::Hit center = SDL::CPU::MathUtil::getCenterFromThreePoints(hitA, hitB, hitC); - float pt = SDL::CPU::MathUtil::ptEstimateFromRadius(center.rt()); + SDLMath::Hit hitA(0, 0, 0); + SDLMath::Hit hitB(hitsInGPU.xs[hits[0]], hitsInGPU.ys[hits[0]], hitsInGPU.zs[hits[0]]); + SDLMath::Hit hitC(hitsInGPU.xs[hits[2]], hitsInGPU.ys[hits[2]], hitsInGPU.zs[hits[2]]); + SDLMath::Hit center = SDLMath::getCenterFromThreePoints(hitA, hitB, hitC); + float pt = SDLMath::ptEstimateFromRadius(center.rt()); float eta = hitC.eta(); float phi = hitB.phi(); @@ -685,7 +685,7 @@ void setGnnNtupleBranches(SDL::Event* event) sg_index_map[sgIdx] = ana.tx->getBranch>("LS_isFake").size() - 1; // // T5 eta and phi are computed using outer and innermost hits - // SDL::CPU::Hit hitA(trk.ph2_x()[anchitidx], trk.ph2_y()[anchitidx], trk.ph2_z()[anchitidx]); + // SDLMath::Hit hitA(trk.ph2_x()[anchitidx], trk.ph2_y()[anchitidx], trk.ph2_z()[anchitidx]); // const float phi = hitA.phi(); // const float eta = hitA.eta(); @@ -751,7 +751,7 @@ void setGnnNtupleMiniDoublet(SDL::Event* event, unsigned int MD) float pt = hit0_r * k2Rinv1GeVf / sin(dphichange); // T5 eta and phi are computed using outer and innermost hits - SDL::CPU::Hit hitA(trk.ph2_x()[anchitidx], trk.ph2_y()[anchitidx], trk.ph2_z()[anchitidx]); + SDLMath::Hit hitA(trk.ph2_x()[anchitidx], trk.ph2_y()[anchitidx], trk.ph2_z()[anchitidx]); const float phi = hitA.phi(); const float eta = hitA.eta(); @@ -1038,8 +1038,8 @@ std::tuple, vector> pars const float pt = (ptAv_in + ptAv_out) / 2.; // T5 eta and phi are computed using outer and innermost hits - SDL::CPU::Hit hitA(trk.ph2_x()[Hit_0], trk.ph2_y()[Hit_0], trk.ph2_z()[Hit_0]); - SDL::CPU::Hit hitB(trk.ph2_x()[Hit_8], trk.ph2_y()[Hit_8], trk.ph2_z()[Hit_8]); + SDLMath::Hit hitA(trk.ph2_x()[Hit_0], trk.ph2_y()[Hit_0], trk.ph2_z()[Hit_0]); + SDLMath::Hit hitB(trk.ph2_x()[Hit_8], trk.ph2_y()[Hit_8], trk.ph2_z()[Hit_8]); const float phi = hitA.phi(); const float eta = hitB.eta(); diff --git a/code/core/write_sdl_ntuple.h b/code/core/write_sdl_ntuple.h index 100b9948c..080788073 100644 --- a/code/core/write_sdl_ntuple.h +++ b/code/core/write_sdl_ntuple.h @@ -3,9 +3,8 @@ #include #include -#include -#include "MathUtil.h" +#include "SDLMath.h" #include "SDL/Event.h" #include "AnalysisConfig.h" diff --git a/code/cppitertools/.clang-format b/code/cppitertools/.clang-format deleted file mode 100644 index 650739d33..000000000 --- a/code/cppitertools/.clang-format +++ /dev/null @@ -1,12 +0,0 @@ ---- -Language: Cpp -BasedOnStyle: Google -AlignAfterOpenBracket: false -AllowShortFunctionsOnASingleLine: Empty -AllowShortLoopsOnASingleLine: false -BreakBeforeBinaryOperators: NonAssignment -DerivePointerAlignment: false -NamespaceIndentation: All -FixNamespaceComments: false -... - diff --git a/code/cppitertools/.gitignore b/code/cppitertools/.gitignore deleted file mode 100644 index ac51a054d..000000000 --- a/code/cppitertools/.gitignore +++ /dev/null @@ -1 +0,0 @@ -bazel-* diff --git a/code/cppitertools/.install-libcxx-travis.sh b/code/cppitertools/.install-libcxx-travis.sh deleted file mode 100644 index 98b18fb03..000000000 --- a/code/cppitertools/.install-libcxx-travis.sh +++ /dev/null @@ -1,12 +0,0 @@ -sudo apt-get install -y dpkg -wget -c http://launchpadlibrarian.net/360656578/libc++-helpers_6.0-2_all.deb -sudo dpkg -i libc++-helpers_6.0-2_all.deb -wget -c http://launchpadlibrarian.net/360656583/libc++abi1_6.0-2_amd64.deb -sudo dpkg -i libc++abi1_6.0-2_amd64.deb -wget -c http://launchpadlibrarian.net/360656580/libc++1_6.0-2_amd64.deb -sudo dpkg -i libc++1_6.0-2_amd64.deb -wget -c http://launchpadlibrarian.net/360656576/libc++-dev_6.0-2_amd64.deb -sudo dpkg -i libc++-dev_6.0-2_amd64.deb -wget -c http://launchpadlibrarian.net/360656581/libc++abi-dev_6.0-2_amd64.deb -sudo dpkg -i libc++abi-dev_6.0-2_amd64.deb -sudo apt-get install -f diff --git a/code/cppitertools/.travis.yml b/code/cppitertools/.travis.yml deleted file mode 100644 index 349a41d20..000000000 --- a/code/cppitertools/.travis.yml +++ /dev/null @@ -1,146 +0,0 @@ -language: cpp -dist: xenial -sudo: require - -matrix: - include: - - os: linux - compiler: clang - addons: - apt: - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-xenial - packages: - - clang-5.0 - - clang++-5.0 - - valgrind - - gcc-8-base - - libc6 - - libgcc1 - - scons - env: - - COMPILER=clang++-5.0 - - USE_LIBCXX=1 - - os: linux - compiler: clang - addons: - apt: - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-xenial - packages: - - clang-6.0 - - clang++-6.0 - - valgrind - - gcc-8-base - - libc6 - - libgcc1 - - scons - env: - - COMPILER=clang++-6.0 - - USE_LIBCXX=1 - - os: linux - compiler: clang - addons: - apt: - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-xenial-7 - packages: - - clang-7 - - clang++-7 - - valgrind - - gcc-8-base - - libc6 - - libgcc1 - - scons - env: - - COMPILER=clang++-7 - - USE_LIBCXX=1 - - os: linux - compiler: clang - addons: - apt: - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-xenial-8 - packages: - - clang-8 - - clang++-8 - - valgrind - - gcc-8-base - - libc6 - - libgcc1 - - scons - env: - - COMPILER=clang++-8 - - USE_LIBCXX=1 - - os: linux - compiler: clang - addons: - apt: - sources: - - ubuntu-toolchain-r-test - # travis complains about an unlisted source here if I do it with a plain - # llvm-toolchain-xenial-9 - - sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main' - key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' - packages: - - clang-9 - - clang++-9 - - valgrind - - gcc-8-base - - libc6 - - libgcc1 - - scons - env: - - COMPILER=clang++-9 - - USE_LIBCXX=1 - - os: linux - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-7 - - valgrind - - scons - env: - - COMPILER=g++-7 - - os: linux - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-8 - - valgrind - - scons - env: - - COMPILER=g++-8 - - os: linux - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-9 - - valgrind - - scons - env: - - COMPILER=g++-9 - -script: - - ${COMPILER} --version - - CXX="${COMPILER}" scons - - ./test_all - - valgrind ./test_all - - -before_script: - - if [ -n "${USE_LIBCXX}" ]; then - bash .install-libcxx-travis.sh; - fi - - cd test - - ./download_catch.sh diff --git a/code/cppitertools/enumerate.hpp b/code/cppitertools/enumerate.hpp deleted file mode 100644 index 6580b783d..000000000 --- a/code/cppitertools/enumerate.hpp +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef ITER_ENUMERATE_H_ -#define ITER_ENUMERATE_H_ - -#include "internal/iterator_wrapper.hpp" -#include "internal/iterbase.hpp" - -#include -#include -#include -#include -#include -#include - -namespace iter { - namespace impl { - template - using EnumBasePair = std::pair; - - // "yielded" by the Enumerable::Iterator. Has a .index, and a - // .element referencing the value yielded by the subiterator - template - class EnumIterYield : public EnumBasePair { - using BasePair = EnumBasePair; - using BasePair::BasePair; - - public: - typename BasePair::first_type index = BasePair::first; - typename BasePair::second_type element = BasePair::second; - }; - - template - class Enumerable; - - using EnumerateFn = IterToolFnOptionalBindSecond; - } - constexpr impl::EnumerateFn enumerate{}; -} - -namespace std { - template - class tuple_size> - : public tuple_size> {}; - - template - class tuple_element> - : public tuple_element> {}; -} - -template -class iter::impl::Enumerable { - private: - Container container_; - const Index start_; - - friend EnumerateFn; - - // Value constructor for use only in the enumerate function - Enumerable(Container&& container, Index start) - : container_(std::forward(container)), start_{start} {} - - public: - Enumerable(Enumerable&&) = default; - - template - using IterYield = EnumIterYield>; - - // Holds an iterator of the contained type and an Index for the - // index_. Each call to ++ increments both of these data members. - // Each dereference returns an IterYield. - template - class Iterator { - private: - template - friend class Iterator; - IteratorWrapper sub_iter_; - Index index_; - - public: - using iterator_category = std::input_iterator_tag; - using value_type = IterYield; - using difference_type = std::ptrdiff_t; - using pointer = value_type*; - using reference = value_type&; - - Iterator(IteratorWrapper&& sub_iter, Index start) - : sub_iter_{std::move(sub_iter)}, index_{start} {} - - IterYield operator*() { - return {index_, *sub_iter_}; - } - - ArrowProxy> operator->() { - return {**this}; - } - - Iterator& operator++() { - ++sub_iter_; - ++index_; - return *this; - } - - Iterator operator++(int) { - auto ret = *this; - ++*this; - return ret; - } - - template - bool operator!=(const Iterator& other) const { - return sub_iter_ != other.sub_iter_; - } - - template - bool operator==(const Iterator& other) const { - return !(*this != other); - } - }; - - Iterator begin() { - return {get_begin(container_), start_}; - } - - Iterator end() { - return {get_end(container_), start_}; - } - - Iterator> begin() const { - return {get_begin(std::as_const(container_)), start_}; - } - - Iterator> end() const { - return {get_end(std::as_const(container_)), start_}; - } -}; -#endif diff --git a/code/cppitertools/internal/iter_tuples.hpp b/code/cppitertools/internal/iter_tuples.hpp deleted file mode 100644 index c71f8dee5..000000000 --- a/code/cppitertools/internal/iter_tuples.hpp +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef ITERTOOLS_ITER_TUPLES_HPP_ -#define ITERTOOLS_ITER_TUPLES_HPP_ - -#include "iterator_wrapper.hpp" -#include "iterbase.hpp" - -#include - -namespace iter { - namespace impl { - namespace detail { - template - std::tuple...> iterator_tuple_deref_helper( - const std::tuple&); - - template - std::tuple...> iterator_tuple_type_helper( - const std::tuple&); - - template - std::tuple>...> - const_iterator_tuple_deref_helper(const std::tuple&); - - template - std::tuple>...> - const_iterator_tuple_type_helper(const std::tuple&); - } - // Given a tuple template argument, evaluates to a tuple of iterators - // for the template argument's contained types. - template - using iterator_tuple_type = - decltype(detail::iterator_tuple_type_helper(std::declval())); - - template - using const_iterator_tuple_type = decltype( - detail::const_iterator_tuple_type_helper(std::declval())); - - // Given a tuple template argument, evaluates to a tuple of - // what the iterators for the template argument's contained types - // dereference to - template - using iterator_deref_tuple = decltype( - detail::iterator_tuple_deref_helper(std::declval())); - - template - using const_iterator_deref_tuple = decltype( - detail::const_iterator_tuple_deref_helper(std::declval())); - - // function absorbing all arguments passed to it. used when - // applying a function to a parameter pack but not passing the evaluated - // results anywhere - template - void absorb(Ts&&...) {} - } -} - -#endif diff --git a/code/cppitertools/internal/iterator_wrapper.hpp b/code/cppitertools/internal/iterator_wrapper.hpp deleted file mode 100644 index f068da975..000000000 --- a/code/cppitertools/internal/iterator_wrapper.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef ITERTOOLS_ITERATOR_WRAPPER_HPP_ -#define ITERTOOLS_ITERATOR_WRAPPER_HPP_ - -#include -#include -#include -#include "iterbase.hpp" - -namespace iter { - namespace impl { - // iterator_end_type is the type of C's end iterator - template - using iterator_end_type = decltype(get_end(std::declval())); - - template - class IteratorWrapperImpl; - - // If begin and end return the same type, type will be - // iterator_type - // If begin and end return different types, type will be IteratorWrapperImpl - template - struct IteratorWrapperImplType; - - template - struct IteratorWrapperImplType - : type_is> {}; - - template - struct IteratorWrapperImplType - : type_is, - iterator_end_type>> {}; - - template - using IteratorWrapper = typename IteratorWrapperImplType, - impl::iterator_end_type>>::type; - } -} - -template -class iter::impl::IteratorWrapperImpl { - private: - static_assert(!std::is_same_v); - SubIter& sub_iter() { - auto* sub = std::get_if(&sub_iter_or_end_); - assert(sub); - return *sub; - } - - const SubIter& sub_iter() const { - auto* sub = std::get_if(&sub_iter_or_end_); - assert(sub); - return *sub; - } - - std::variant sub_iter_or_end_; - - public: - IteratorWrapperImpl() : IteratorWrapperImpl(SubIter{}) {} - - IteratorWrapperImpl(SubIter&& it) : sub_iter_or_end_{std::move(it)} {} - - IteratorWrapperImpl(SubEnd&& it) : sub_iter_or_end_(std::move(it)) {} - - IteratorWrapperImpl& operator++() { - ++sub_iter(); - return *this; - } - - decltype(auto) operator*() { - return *sub_iter(); - } - - decltype(auto) operator*() const { - return *sub_iter(); - } - - decltype(auto) operator-> () { - return apply_arrow(sub_iter()); - } - - decltype(auto) operator-> () const { - return apply_arrow(sub_iter()); - } - - bool operator!=(const IteratorWrapperImpl& other) const { - constexpr static struct : std::not_equal_to { - // specially compare Ends because rangev3 sentinels are not equality - // comparable - bool operator()(const SubEnd&, const SubEnd&) const { - return false; - } - using std::not_equal_to::operator(); - } not_equal; - return std::visit(not_equal, sub_iter_or_end_, other.sub_iter_or_end_); - } - - bool operator==(const IteratorWrapperImpl& other) const { - return !(*this != other); - } -}; - -#endif diff --git a/code/cppitertools/internal/iteratoriterator.hpp b/code/cppitertools/internal/iteratoriterator.hpp deleted file mode 100644 index 3993a4d0d..000000000 --- a/code/cppitertools/internal/iteratoriterator.hpp +++ /dev/null @@ -1,274 +0,0 @@ -#ifndef ITERATOR_ITERATOR_HPP_ -#define ITERATOR_ITERATOR_HPP_ - -#include -#include -#include -#include "iterbase.hpp" - -// IterIterWrapper and IteratorIterator provide a means to have a container -// of iterators act like a container of the pointed to objects. This is useful -// for combinatorics and similar itertools which need to keep track of -// more than one element at a time. -// an IterIterWrapper::iterator>> -// behave like some_collection when iterated over or indexed - -namespace iter { - namespace impl { - template - struct HasConstDeref : std::false_type {}; - - template - struct HasConstDeref())>> - : std::true_type {}; - - template - class IteratorIterator { - template friend class IteratorIterator; - using Diff = std::ptrdiff_t; - static_assert( - std::is_same< - typename std::iterator_traits::iterator_category, - std::random_access_iterator_tag>::value, - "IteratorIterator only works with random access iterators"); - - private: - TopIter sub_iter; - - public: - using iterator_category = std::random_access_iterator_tag; - using value_type = std::remove_reference_t())>; - using difference_type = std::ptrdiff_t; - using pointer = value_type*; - using reference = value_type&; - IteratorIterator() = default; - IteratorIterator(const TopIter& it) : sub_iter{it} {} - - const TopIter& get() const { - return sub_iter; - } - - template - bool operator==(const IteratorIterator& other) const { - return !(*this != other); - } - - template - bool operator!=(const IteratorIterator& other) const { - return this->sub_iter != other.sub_iter; - } - - IteratorIterator& operator++() { - ++this->sub_iter; - return *this; - } - - IteratorIterator operator++(int) { - auto ret = *this; - ++*this; - return ret; - } - - IteratorIterator& operator--() { - --this->sub_iter; - return *this; - } - - IteratorIterator operator--(int) { - auto ret = *this; - --*this; - return ret; - } - - auto operator*() const -> decltype(**sub_iter) { - return **this->sub_iter; - } - - auto operator-> () const -> decltype(*sub_iter) { - return *this->sub_iter; - } - - IteratorIterator& operator+=(Diff n) { - this->sub_iter += n; - return *this; - } - - IteratorIterator operator+(Diff n) const { - auto it = *this; - it += n; - return it; - } - - friend IteratorIterator operator+(Diff n, IteratorIterator it) { - it += n; - return it; - } - - IteratorIterator& operator-=(Diff n) { - this->sub_iter -= n; - return *this; - } - - IteratorIterator operator-(Diff n) const { - auto it = *this; - it -= n; - return it; - } - - Diff operator-(const IteratorIterator& rhs) const { - return this->sub_iter - rhs.sub_iter; - } - - auto operator[](Diff idx) const -> decltype(*sub_iter[idx]) { - return *sub_iter[idx]; - } - - bool operator<(const IteratorIterator& rhs) const { - return this->sub_iter < rhs.sub_iter; - } - - bool operator>(const IteratorIterator& rhs) const { - return this->sub_iter > rhs.sub_iter; - } - - bool operator<=(const IteratorIterator& rhs) const { - return this->sub_iter <= rhs.sub_iter; - } - - bool operator>=(const IteratorIterator& rhs) const { - return this->sub_iter >= rhs.sub_iter; - } - }; - - template - class IterIterWrapper { - private: - Container container; - - using contained_iter = typename Container::value_type; - using size_type = typename Container::size_type; - using iterator = IteratorIterator; - using const_iterator = - IteratorIterator; - using reverse_iterator = - IteratorIterator; - using const_reverse_iterator = - IteratorIterator; - - template - struct ConstAtTypeOrVoid : type_is {}; - - template - struct ConstAtTypeOrVoid().at(0))>> - : type_is().at(0))> {}; - - using const_at_type_or_void_t = typename ConstAtTypeOrVoid<>::type; - - template - struct ConstIndexTypeOrVoid : type_is {}; - - template - struct ConstIndexTypeOrVoid()[0])>> - : type_is()[0])> {}; - - using const_index_type_or_void_t = typename ConstIndexTypeOrVoid<>::type; - - public: - IterIterWrapper() = default; - - explicit IterIterWrapper(size_type sz) : container(sz) {} - - IterIterWrapper(size_type sz, const contained_iter& val) - : container(sz, val) {} - - auto at(size_type pos) -> decltype(*container.at(pos)) { - return *container.at(pos); - } - - auto at(size_type pos) const -> const_at_type_or_void_t { - return *container.at(pos); - } - - auto operator[](size_type pos) noexcept(noexcept(*container[pos])) - -> decltype(*container[pos]) { - return *container[pos]; - } - - auto operator[](size_type pos) const noexcept(noexcept(*container[pos])) - -> const_index_type_or_void_t { - return *container[pos]; - } - - bool empty() const noexcept { - return container.empty(); - } - - size_type size() const noexcept { - return container.size(); - } - - iterator begin() noexcept { - return {container.begin()}; - } - - iterator end() noexcept { - return {container.end()}; - } - - const_iterator begin() const noexcept { - return {container.begin()}; - } - - const_iterator end() const noexcept { - return {container.end()}; - } - - const_iterator cbegin() const noexcept { - return {container.cbegin()}; - } - - const_iterator cend() const noexcept { - return {container.cend()}; - } - - reverse_iterator rbegin() noexcept { - return {container.rbegin()}; - } - - reverse_iterator rend() noexcept { - return {container.rend()}; - } - - const_reverse_iterator rbegin() const noexcept { - return {container.rbegin()}; - } - - const_reverse_iterator rend() const noexcept { - return {container.rend()}; - } - - const_reverse_iterator crbegin() const noexcept { - return {container.rbegin()}; - } - - const_reverse_iterator crend() const noexcept { - return {container.rend()}; - } - - // get() exposes the underlying container. this allows the - // itertools to manipulate the iterators in the container - // and should not be depended on anywhere else. - Container& get() noexcept { - return container; - } - - const Container& get() const noexcept { - return container; - } - }; - } -} - -#endif diff --git a/code/cppitertools/internal/iterbase.hpp b/code/cppitertools/internal/iterbase.hpp deleted file mode 100644 index 57cc1b78c..000000000 --- a/code/cppitertools/internal/iterbase.hpp +++ /dev/null @@ -1,487 +0,0 @@ -#ifndef ITERBASE_HPP_ -#define ITERBASE_HPP_ - -// This file consists of utilities used for the generic nature of the -// iterable wrapper classes. As such, the contents of this file should be -// considered UNDOCUMENTED and is subject to change without warning. This -// also applies to the name of the file. No user code should include -// this file directly. - -#include -#include -#include -#include -#include -#include -#include -#include - -// see gcc bug 87651 -// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87651 -#ifdef __GNUC__ -#define NO_GCC_FRIEND_ERROR __GNUC__ < 8 -#else -#define NO_GCC_FRIEND_ERROR 1 -#endif - -namespace iter { - namespace impl { - namespace get_iters { - // begin() for C arrays - template - T* get_begin_impl(T (&array)[N], int) { - return array; - } - - // Prefer member begin(). - template ().begin())> - I get_begin_impl(T& r, int) { - return r.begin(); - } - - // Use ADL otherwises. - template ()))> - I get_begin_impl(T& r, long) { - return begin(r); - } - - template - auto get_begin(T& t) -> decltype(get_begin_impl(std::declval(), 42)) { - return get_begin_impl(t, 42); - } - - // end() for C arrays - template - T* get_end_impl(T (&array)[N], int) { - return array + N; - } - - // Prefer member end(). - template ().end())> - I get_end_impl(T& r, int) { - return r.end(); - } - - // Use ADL otherwise. - template ()))> - I get_end_impl(T& r, long) { - return end(r); - } - - template - auto get_end(T& t) -> decltype(get_end_impl(std::declval(), 42)) { - return get_end_impl(t, 42); - } - } - using get_iters::get_begin; - using get_iters::get_end; - - template - struct type_is { - using type = T; - }; - - template - using AsConst = decltype(std::as_const(std::declval())); - - // iterator_type is the type of C's iterator - // TODO: See bug - // https://developercommunity.visualstudio.com/content/problem/252157/sfinae-error-depends-on-name-of-template-parameter.html - // for why we use T instead of Container. Should be - // changed back to Container when that bug is fixed in - // MSVC. - template - using iterator_type = decltype(get_begin(std::declval())); - - // iterator_type is the type of C's iterator - template - using const_iterator_type = decltype( - get_begin(std::declval&>())); - - // iterator_deref is the type obtained by dereferencing an iterator - // to an object of type C - template - using iterator_deref = decltype(*std::declval&>()); - - // const_iteator_deref is the type obtained through dereferencing - // a const iterator& (note: not a const_iterator). ie: the result - // of Container::iterator::operator*() const - template - using const_iterator_deref = - decltype(*std::declval&>()); - - // the type of dereferencing a const_iterator - template - using const_iterator_type_deref = - decltype(*std::declval&>()); - - template - using iterator_traits_deref = - std::remove_reference_t>; - - template - struct IsIterable : std::false_type {}; - - // Assuming that if a type works with begin, it is an iterable. - template - struct IsIterable>> : std::true_type {}; - - template - constexpr bool is_iterable = IsIterable::value; - - namespace detail { - template - struct ArrowHelper { - using type = void; - void operator()(T&) const noexcept {} - }; - - template - struct ArrowHelper { - using type = T*; - constexpr type operator()(T* t) const noexcept { - return t; - } - }; - - template - struct ArrowHelper().operator->())>> { - using type = decltype(std::declval().operator->()); - type operator()(T& t) const { - return t.operator->(); - } - }; - - template - using arrow = typename detail::ArrowHelper::type; - } - - // type of C::iterator::operator->, also works with pointers - // void if the iterator has no operator-> - template - using iterator_arrow = detail::arrow>; - - // applys the -> operator to an object, if the object is a pointer, - // it returns the pointer - template - detail::arrow apply_arrow(T& t) { - return detail::ArrowHelper{}(t); - } - - // For iterators that have an operator* which returns a value - // they can return this type from their operator-> instead, which will - // wrap an object and allow it to be used with arrow - template - class ArrowProxy { - private: - using TPlain = typename std::remove_reference::type; - T obj; - - public: - constexpr ArrowProxy(T&& in_obj) : obj(std::forward(in_obj)) {} - - TPlain* operator->() { - return &obj; - } - }; - - template - struct is_random_access_iter : std::false_type {}; - - template - struct is_random_access_iter::iterator_category, - std::random_access_iterator_tag>::value>> : std::true_type {}; - - template - using has_random_access_iter = is_random_access_iter>; - // because std::advance assumes a lot and is actually smart, I need a dumb - - // version that will work with most things - template - void dumb_advance_unsafe(InputIt& iter, Distance distance) { - for (Distance i(0); i < distance; ++i) { - ++iter; - } - } - - template - void dumb_advance_impl( - Iter& iter, const EndIter& end, Distance distance, std::false_type) { - for (Distance i(0); i < distance && iter != end; ++i) { - ++iter; - } - } - - template - void dumb_advance_impl( - Iter& iter, const EndIter& end, Distance distance, std::true_type) { - if (static_cast(end - iter) < distance) { - iter = end; - } else { - iter += distance; - } - } - - // iter will not be incremented past end - template - void dumb_advance(Iter& iter, const EndIter& end, Distance distance) { - dumb_advance_impl(iter, end, distance, is_random_access_iter{}); - } - - template - ForwardIt dumb_next(ForwardIt it, Distance distance = 1) { - dumb_advance_unsafe(it, distance); - return it; - } - - template - ForwardIt dumb_next( - ForwardIt it, const ForwardIt& end, Distance distance = 1) { - dumb_advance(it, end, distance); - return it; - } - - template - Distance dumb_size(Container&& container) { - Distance d{0}; - auto end_it = get_end(container); - for (auto it = get_begin(container); it != end_it; ++it) { - ++d; - } - return d; - } - - template - struct are_same : std::true_type {}; - - template - struct are_same - : std::integral_constant::value && are_same::value> {}; - - // DerefHolder holds the value gotten from an iterator dereference - // if the iterate dereferences to an lvalue references, a pointer to the - // element is stored - // if it does not, a value is stored instead - // get() returns a reference to the held item - // get_ptr() returns a pointer to the held item - // reset() replaces the currently held item - template - class DerefHolder { - private: - static_assert(!std::is_lvalue_reference::value, - "Non-lvalue-ref specialization used for lvalue ref type"); - // it could still be an rvalue reference - using TPlain = std::remove_reference_t; - - std::optional item_p_; - - public: - using reference = TPlain&; - using pointer = TPlain*; - - static constexpr bool stores_value = true; - - DerefHolder() = default; - - reference get() { - assert(item_p_.has_value()); - return *item_p_; - } - - pointer get_ptr() { - assert(item_p_.has_value()); - return &item_p_.value(); - } - - void reset(T&& item) { - item_p_.emplace(std::move(item)); - } - - explicit operator bool() const { - return static_cast(item_p_); - } - }; - - // Specialization for when T is an lvalue ref - template - class DerefHolder { - public: - using reference = T&; - using pointer = T*; - - private: - pointer item_p_{}; - - public: - static constexpr bool stores_value = false; - - DerefHolder() = default; - - reference get() { - assert(item_p_); - return *item_p_; - } - - pointer get_ptr() { - assert(item_p_); - return item_p_; - } - - void reset(reference item) { - item_p_ = &item; - } - - explicit operator bool() const { - return item_p_ != nullptr; - } - }; - - // allows f(x) to be 'called' as x | f - // let the record show I dislike adding yet another syntactical mess to - // this clown car of a language. - template - struct Pipeable { - template - friend decltype(auto) operator|(T&& x, const Pipeable& p) { - return static_cast(p)(std::forward(x)); - } - }; - - // Pipeable Callable generator, where ItImpl is templated on the first - // argument to the call. - template