Skip to content

Commit

Permalink
Merge pull request #109 from cerminar/eg_datatypes_125X_v0
Browse files Browse the repository at this point in the history
Add unpacking methods for e/g objects in GT format
  • Loading branch information
gpetruc authored Feb 4, 2023
2 parents 2adc96a + ba1a3b8 commit 1340dc6
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion DataFormats/L1TParticleFlow/interface/gt_datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,36 @@ namespace l1gt {
pack_into_bits(ret, start, z0);
return ret;
}

inline void initFromBits(const ap_uint<BITWIDTH> &src) {
unsigned int start = 0;
unpack_from_bits(src, start, valid);
unpack_from_bits(src, start, v3.pt);
unpack_from_bits(src, start, v3.phi);
unpack_from_bits(src, start, v3.eta);
unpack_from_bits(src, start, quality);
unpack_from_bits(src, start, isolation);
unpack_from_bits(src, start, charge);
unpack_from_bits(src, start, z0);
}

inline static Electron unpack_ap(const ap_uint<BITWIDTH> &src) {
Electron ret;
ret.initFromBits(src);
return ret;
}

inline static Electron unpack(const std::array<uint64_t, 2> &src, int parity) {
ap_uint<BITWIDTH> bits;
if (parity == 0) {
bits(63, 0) = src[0];
bits(95, 64) = src[1];
} else {
bits(63, 0) = src[1];
bits(95, 64) = (src[0] >> 32);
}
return unpack_ap(bits);
}
};

struct Photon {
Expand All @@ -234,7 +264,8 @@ namespace l1gt {
egquality_t quality;
iso_t isolation;

inline ap_uint<96> pack() const {
static const int BITWIDTH = 96;
inline ap_uint<BITWIDTH> pack() const {
ap_uint<96> ret(0);
unsigned int start = 0;
pack_into_bits(ret, start, valid);
Expand All @@ -243,6 +274,34 @@ namespace l1gt {
pack_into_bits(ret, start, isolation);
return ret;
}

inline void initFromBits(const ap_uint<BITWIDTH> &src) {
unsigned int start = 0;
unpack_from_bits(src, start, valid);
unpack_from_bits(src, start, v3.pt);
unpack_from_bits(src, start, v3.phi);
unpack_from_bits(src, start, v3.eta);
unpack_from_bits(src, start, quality);
unpack_from_bits(src, start, isolation);
}

inline static Photon unpack_ap(const ap_uint<BITWIDTH> &src) {
Photon ret;
ret.initFromBits(src);
return ret;
}

inline static Photon unpack(const std::array<uint64_t, 2> &src, int parity) {
ap_uint<BITWIDTH> bits;
if (parity == 0) {
bits(63, 0) = src[0];
bits(95, 64) = src[1];
} else {
bits(63, 0) = src[1];
bits(95, 64) = (src[0] >> 32);
}
return unpack_ap(bits);
}
};

} // namespace l1gt
Expand Down

0 comments on commit 1340dc6

Please sign in to comment.