File indexing completed on 2025-08-05 08:18:05
0001 #include "InttDeadMap.h"
0002
0003 #include <g4detectors/PHG4CellDefs.h>
0004
0005 #include <cassert>
0006 #include <iostream>
0007 #include <limits>
0008
0009 int InttDeadMap::s_wildCardID = -1;
0010
0011 const InttDeadMap::Map&
0012 InttDeadMap::getDeadChannels() const
0013 {
0014 static Map tmp_map;
0015 return tmp_map;
0016 }
0017
0018 InttDeadMap::Map&
0019 InttDeadMap::getDeadChannels()
0020 {
0021 static Map tmp_map;
0022 return tmp_map;
0023 }
0024
0025 void InttDeadMap::addDeadChannelIntt(const int layer,
0026 const int ladder_phi, const int ladder_z,
0027 const int strip_z, const int strip_phi)
0028 {
0029 addDeadChannel(getInttKey(layer,
0030 ladder_phi, ladder_z,
0031 strip_z, strip_phi));
0032 }
0033
0034 bool InttDeadMap::isDeadChannelIntt(const int layer,
0035 const int ladder_phi, const int ladder_z,
0036 const int strip_z, const int strip_phi) const
0037 {
0038 if (isDeadChannel(getInttKey(layer, ladder_phi, ladder_z, strip_z, strip_phi)) ||
0039 isDeadChannel(getInttKey(layer, ladder_phi, ladder_z, strip_z, s_wildCardID)) ||
0040 isDeadChannel(getInttKey(layer, ladder_phi, ladder_z, s_wildCardID, s_wildCardID)) ||
0041 isDeadChannel(getInttKey(layer, ladder_phi, s_wildCardID, s_wildCardID, s_wildCardID)) ||
0042 isDeadChannel(getInttKey(layer, s_wildCardID, s_wildCardID, s_wildCardID, s_wildCardID)))
0043 {
0044 return true;
0045 }
0046 return false;
0047 }
0048
0049 int InttDeadMap::isValid() const
0050 {
0051 return size() > 0;
0052 }
0053
0054 void InttDeadMap::identify(std::ostream& os) const
0055 {
0056 os << "InttDeadMap base class" << std::endl;
0057 }
0058
0059 PHG4CellDefs::keytype InttDeadMap::getInttKey(int layer,
0060 int ladder_phi, int ladder_z,
0061 int strip_z, int strip_phi)
0062 {
0063 static const unsigned int layer_bit{8};
0064 static const unsigned int ladder_phi_bit{16};
0065 static const unsigned int ladder_z_bit{8};
0066 static const unsigned int strip_z_bit{16};
0067 static const unsigned int strip_phi_bit{16};
0068
0069 bool wildcard = false;
0070
0071 if (layer == s_wildCardID)
0072 {
0073 wildcard = true;
0074 }
0075 if (wildcard)
0076 {
0077 layer = (1U << layer_bit) - 1;
0078 }
0079
0080 if (ladder_phi == s_wildCardID)
0081 {
0082 wildcard = true;
0083 }
0084 if (wildcard)
0085 {
0086 ladder_phi = (1U << ladder_phi_bit) - 1;
0087 }
0088
0089 if (ladder_z == s_wildCardID)
0090 {
0091 wildcard = true;
0092 }
0093 if (wildcard)
0094 {
0095 ladder_z = (1U << ladder_z_bit) - 1;
0096 }
0097
0098 if (strip_z == s_wildCardID)
0099 {
0100 wildcard = true;
0101 }
0102 if (wildcard)
0103 {
0104 strip_z = (1U << strip_z_bit) - 1;
0105 }
0106
0107 if (strip_phi == s_wildCardID)
0108 {
0109 wildcard = true;
0110 }
0111 if (wildcard)
0112 {
0113 strip_phi = (1U << strip_phi_bit) - 1;
0114 }
0115
0116
0117 static_assert(layer_bit + ladder_phi_bit + ladder_z_bit + strip_z_bit + strip_phi_bit == std::numeric_limits<PHG4CellDefs::keytype>::digits);
0118
0119
0120 assert(layer < (int) (1U << layer_bit));
0121 assert(ladder_phi < (int) (1U << ladder_phi_bit));
0122 assert(ladder_z < (int) (1U << ladder_z_bit));
0123 assert(strip_z < (int) (1U << strip_z_bit));
0124 assert(strip_phi < (int) (1U << strip_phi_bit));
0125
0126
0127 assert(layer >= 0);
0128 assert(ladder_phi >= 0);
0129 assert(ladder_z >= 0);
0130 assert(strip_z >= 0);
0131 assert(strip_phi >= 0);
0132
0133 PHG4CellDefs::keytype key = 0;
0134
0135 key += layer;
0136
0137 key <<= ladder_phi_bit;
0138 key += ladder_phi;
0139
0140 key <<= ladder_z_bit;
0141 key += ladder_z;
0142
0143 key <<= strip_z_bit;
0144 key += strip_z;
0145
0146 key <<= strip_phi_bit;
0147 key += strip_phi;
0148
0149 return key;
0150 }