LDMX Software
SiStripChannelMap.h
1#ifndef TRACKING_RECO_SISTRIPCHANNELMAP_H_
2#define TRACKING_RECO_SISTRIPCHANNELMAP_H_
3
4#include <cstdint>
5#include <cstdio>
6#include <string>
7
8namespace tracking::reco {
9
18namespace channelmap {
19
21inline constexpr int K_CHANNELS_PER_APV = 128;
23inline constexpr int K_APVS_PER_HYBRID = 5;
25inline constexpr int K_CHANNELS_PER_HYBRID =
28inline constexpr int K_SAMPLES_PER_APV_TRIGGER = 3;
29
38inline constexpr int16_t pchannel(uint8_t apv_id, uint8_t channel) {
39 return static_cast<int16_t>(
41 (apv_id * K_CHANNELS_PER_APV + (K_CHANNELS_PER_APV - 1) - channel));
42}
43
45inline std::string channelKey(uint8_t feb, uint8_t hybrid, uint8_t apv,
46 uint8_t channel) {
47 return std::to_string(feb) + ":" + std::to_string(hybrid) + ":" +
48 std::to_string(apv) + ":" + std::to_string(channel);
49}
50
53inline constexpr uint32_t channelId(uint8_t feb, uint8_t hybrid, uint8_t apv,
54 uint8_t channel) {
55 return (static_cast<uint32_t>(feb) << 24) |
56 (static_cast<uint32_t>(hybrid) << 16) |
57 (static_cast<uint32_t>(apv) << 8) | static_cast<uint32_t>(channel);
58}
59
62inline bool parseChannelKey(const std::string& key, uint8_t& feb,
63 uint8_t& hybrid, uint8_t& apv, uint8_t& channel) {
64 unsigned f, h, a, c;
65 if (std::sscanf(key.c_str(), "%u:%u:%u:%u", &f, &h, &a, &c) != 4)
66 return false;
67 feb = static_cast<uint8_t>(f);
68 hybrid = static_cast<uint8_t>(h);
69 apv = static_cast<uint8_t>(a);
70 channel = static_cast<uint8_t>(c);
71 return true;
72}
73
75inline constexpr uint32_t groupKey(uint8_t feb, uint8_t hybrid,
76 int16_t pchannel) {
77 return (static_cast<uint32_t>(feb) << 24) |
78 (static_cast<uint32_t>(hybrid) << 16) |
79 static_cast<uint32_t>(static_cast<uint16_t>(pchannel));
80}
81
83inline constexpr int16_t pchannelFromGroupKey(uint32_t key) {
84 return static_cast<int16_t>(key & 0xFFFF);
85}
86
87} // namespace channelmap
88} // namespace tracking::reco
89
90#endif // TRACKING_RECO_SISTRIPCHANNELMAP_H_
bool parseChannelKey(const std::string &key, uint8_t &feb, uint8_t &hybrid, uint8_t &apv, uint8_t &channel)
Parse a "feb:hybrid:apv:channel" key (as produced by channelKey()) back into its electronics fields.
std::string channelKey(uint8_t feb, uint8_t hybrid, uint8_t apv, uint8_t channel)
Build the per-channel pedestal-map key "feb:hybrid:apv:channel".
constexpr uint32_t channelId(uint8_t feb, uint8_t hybrid, uint8_t apv, uint8_t channel)
Pack the full electronics address (feb, hybrid, apv, channel) into a single 32-bit id,...
constexpr int K_CHANNELS_PER_HYBRID
Number of physical strips per hybrid (kApvsPerHybrid * kChannelsPerApv).
constexpr int K_SAMPLES_PER_APV_TRIGGER
Number of ADC samples the APV25 reads out per channel per trigger.
constexpr int16_t pchannelFromGroupKey(uint32_t key)
Extract the pchannel back out of a key produced by groupKey().
constexpr int K_CHANNELS_PER_APV
Number of readout channels per APV25 chip.
constexpr uint32_t groupKey(uint8_t feb, uint8_t hybrid, int16_t pchannel)
Pack (feb, hybrid, pchannel) into a single 32-bit waveform-grouping key.
constexpr int16_t pchannel(uint8_t apv_id, uint8_t channel)
Convert an (APV id, APV channel) pair into the physical strip number (pchannel) within a hybrid,...
constexpr int K_APVS_PER_HYBRID
Number of APV25 chips per hybrid.