51 {
53
54 SG::WriteCondHandle<PixelChargeCalibCondData> writeHandle(
m_writeKey, ctx);
55 if (writeHandle.isValid()) {
56 ATH_MSG_DEBUG(
"CondHandle " << writeHandle.fullKey() <<
" is already valid.. In theory this should not be called, but may happen if multiple concurrent events are being processed out of order.");
57 return StatusCode::SUCCESS;
58 }
59
60 SG::ReadCondHandle<InDetDD::SiDetectorElementCollection> pixelDetEleHandle(
m_pixelDetEleCollKey, ctx);
61 const InDetDD::SiDetectorElementCollection* elements(*pixelDetEleHandle);
62 if (not pixelDetEleHandle.isValid() or elements==nullptr) {
64 return StatusCode::FAILURE;
65 }
66
69
70 SG::ReadCondHandle<PixelModuleData> configDataHandle(
m_configKey, ctx);
71 const PixelModuleData *configData = *configDataHandle;
72
73
74
75 auto writeCdo = std::make_unique<PixelChargeCalibCondData>(
m_pixelID->wafer_hash_max());
76
77 const EventIDBase
start{EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, 0, 0, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
78 const EventIDBase
stop {EventIDBase::UNDEFNUM, EventIDBase::UNDEFEVT, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM-1, EventIDBase::UNDEFNUM, EventIDBase::UNDEFNUM};
80 unsigned int channel_warnings=0;
81 unsigned int max_channel_warnings=10;
82 unsigned int min_invalid_channel=std::numeric_limits<unsigned int>::max();
83 unsigned int max_invalid_channel=0;
85 SG::ReadCondHandle<CondAttrListCollection> readHandle(
m_readKey, ctx);
86 const CondAttrListCollection* readCdo = *readHandle;
87 if (readCdo==nullptr) {
89 return StatusCode::FAILURE;
90 }
91
92 if (not readHandle.range(rangeW)) {
93 ATH_MSG_FATAL(
"Failed to retrieve validity range for " << readHandle.key());
94 return StatusCode::FAILURE;
95 }
96 ATH_MSG_INFO(
"Size of CondAttrListCollection " << readHandle.fullKey() <<
" readCdo->size()= " << readCdo->
size());
98
99 std::unique_ptr<IChargeCalibrationParser> pParser{};
100 for (const auto & attrList : *readCdo) {
103
104 if (
payload.exists(
"data_array") and not payload[
"data_array"].isNull()) {
105 pParser = std::make_unique<Run3ChargeCalibParser>(configData, elements,
m_pixelID);
106 const nlohmann::json &jsonData = nlohmann::json::parse(payload[
"data_array"].
data<std::string>());
107 for (
const auto &[hash,
data] : jsonData.items()) {
108 const unsigned int moduleHash = std::stoul(hash);
109 const ChargeCalibrationBundle &
b = pParser->parse(moduleHash,
data);
112 return StatusCode::FAILURE;
113 }
114 writeCdo -> setAllFromBundle(moduleHash, b);
115 }
116 }
else if (
payload.exists(
"data") and not payload[
"data"].isNull()) {
117 pParser = std::make_unique<Run2ChargeCalibParser>(configData, elements,
m_pixelID);
118
119
120 if (channelNumber >=
m_pixelID->wafer_hash_max()) {
121 min_invalid_channel = std::min(min_invalid_channel,channelNumber);
122 max_invalid_channel = std::max(max_invalid_channel,channelNumber);
123 if (channel_warnings++ < max_channel_warnings) {
124 ATH_MSG_WARNING(
"Invalid module hash (COOL channel number: " << channelNumber <<
" !< " <<
m_pixelID->wafer_hash_max() <<
")."
125 << (channel_warnings==max_channel_warnings ? " Further such warnings will not be reported." : ""));
126 }
127 continue;
128 }
129 const unsigned int moduleHash = channelNumber;
130 std::string stringStatus =
payload[
"data"].data<std::string>();
131 const ChargeCalibrationBundle &
b = pParser->parse(moduleHash, stringStatus);
134 return StatusCode::FAILURE;
135 }
136 writeCdo -> setAllFromBundle(moduleHash, b);
137 } else {
138 ATH_MSG_ERROR(
"payload[\"data\"] does not exist for ChanNum " << channelNumber);
139 return StatusCode::FAILURE;
140 }
141 }
142 } else {
143 for (
unsigned int moduleHash{}; moduleHash <
m_pixelID->wafer_hash_max(); moduleHash++) {
144 IdentifierHash wafer_hash = IdentifierHash(moduleHash);
146 const InDetDD::SiDetectorElement *element = elements->getDetectorElement(wafer_hash);
150 const std::vector<Thresholds> allDefaultThresholds(numFE, defaultThreshold);
151
153 const std::vector<LegacyFitParameters> allDefaultFitParams(numFE, defaultParam);
154
155 const LinearFitParameters defaultLinParam{0.0f, 0.0f};
156 const std::vector<LinearFitParameters> allDefaultLinearParams(numFE, defaultLinParam);
157
159 writeCdo -> setThresholds(type, moduleHash, allDefaultThresholds);
160 writeCdo -> setLegacyFitParameters(type, moduleHash, allDefaultFitParams);
161 writeCdo -> setLinearFitParameters(type, moduleHash, allDefaultLinearParams);
162 }
163 writeCdo -> setTotResolutions(moduleHash, std::vector<Resolutions>(numFE, {0.f, 0.f}));
164 }
165 }
166 if (channel_warnings>max_channel_warnings) {
167 ATH_MSG_WARNING(
"Encountered " << channel_warnings <<
" invalid channel numbers (range " << min_invalid_channel <<
" .. "
168 << max_invalid_channel <<
" !< " <<
m_pixelID->wafer_hash_max() <<
")");
169 }
170
171
172
173 for (
unsigned int moduleHash{}; moduleHash <
m_pixelID->wafer_hash_max(); moduleHash++) {
174 IdentifierHash wafer_hash = IdentifierHash(moduleHash);
176 const InDetDD::SiDetectorElement *element = elements->getDetectorElement(wafer_hash);
182 writeCdo -> setThresholds(type, moduleHash, std::vector<Thresholds>(numFE, defaults));
183 }
184 }
185 }
186
187 if (writeHandle.record(rangeW, std::move(writeCdo)).isFailure()) {
188 ATH_MSG_FATAL(
"Could not record PixelChargeCalibCondData " << writeHandle.key() <<
" with EventRange " << rangeW <<
" into Conditions Store");
189 return StatusCode::FAILURE;
190 }
191 ATH_MSG_INFO(
"recorded new CDO " << writeHandle.key() <<
" with range " << rangeW <<
" into Conditions Store");
192
193 return StatusCode::SUCCESS;
194}
#define ATH_MSG_WARNING(x)
char data[hepevt_bytes_allocation_ATLAS]
constexpr std::size_t enum2uint(T n, std::string_view callingFunctionName="")
Convert an enum class to size_t for use as an array index.
size_type size() const
number of Chan/AttributeList pairs
coral::AttributeList AttributeList
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
SG::ReadCondHandleKey< PixelModuleData > m_configKey
SG::WriteCondHandleKey< PixelChargeCalibCondData > m_writeKey
const PixelID * m_pixelID
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
int getDefaultInTimeThreshold(int barrel_ec, int layer) const
int getDefaultAnalogThreshold(int barrel_ec, int layer) const
float getDefaultQ2TotA() const
int getDefaultAnalogThresholdNoise(int barrel_ec, int layer) const
float getDefaultQ2TotC() const
float getDefaultQ2TotE() const
int getDefaultAnalogThresholdSigma(int barrel_ec, int layer) const
std::pair< size_t, InDetDD::PixelReadoutTechnology > numChipsAndTechnology(const InDetDD::SiDetectorElement *element)
std::pair< int, int > getBecAndLayer(const PixelID *pPixelId, IdentifierHash hash)
static constexpr float defaultOverflow