130 std::vector<SG::WriteHandle<xAOD::MuonRoIContainer>> roiHandles =
m_roiWriteKeys.makeHandles(eventContext);
131 for (
auto& roiHandle : roiHandles) {
132 ATH_CHECK(roiHandle.record(std::make_unique<xAOD::MuonRoIContainer>(),
133 std::make_unique<xAOD::MuonRoIAuxContainer>()));
134 ATH_MSG_DEBUG(
"Recorded MuonRoIContainer with key " << roiHandle.key());
138 std::vector<SG::WriteHandle<xAOD::MuonRoIContainer>> topoHandles;
141 for (
auto& topoHandle : topoHandles) {
142 ATH_CHECK(topoHandle.record(std::make_unique<xAOD::MuonRoIContainer>(),
143 std::make_unique<xAOD::MuonRoIAuxContainer>()));
144 ATH_MSG_DEBUG(
"Recorded MuCTPIL1Topo with key " << topoHandle.key());
149 const eformat::helper::SourceIdentifier sid(
m_robIds.value().at(0));
150 auto it = std::find_if(vrobf.begin(), vrobf.end(), [&sid](
const ROBF* rob){return rob->rob_source_id() == sid.code();});
151 if (
it == vrobf.end()) {
152 ATH_MSG_DEBUG(
"No MUCTPI ROB fragment with ID 0x" << std::hex << sid.code() << std::dec
153 <<
" was found, MuonRoIContainer will be empty");
154 return StatusCode::SUCCESS;
160 const uint32_t ndata = rob->rod_ndata();
168 std::vector<int> bcidOffsetsWrtROB;
173 ATH_MSG_ERROR(
"Empty ROD data in MUCTPI ROB 0x" << std::hex << sid.code() << std::dec);
175 return StatusCode::FAILURE;
177 ATH_MSG_DEBUG(
"Starting to decode " << ndata <<
" ROD words");
181 std::vector<std::pair<size_t,size_t>> roiSlices;
182 std::vector<std::pair<size_t,size_t>> topoSlices;
187 ATH_MSG_DEBUG(
"MUCTPI raw word " << iWord <<
": 0x" << std::hex << word << std::dec);
189 ++wordTypeCounts[
static_cast<size_t>(wordType)];
195 <<
", NTOB=" <<
header.tobCount <<
", NCAND=" <<
header.candCount);
197 roiSlices.emplace_back(0,0);
199 topoSlices.emplace_back(0,0);
201 bcidOffsetsWrtROB.push_back(bcidDiff(
header.bcid, rob->rod_bc_id()));
211 if (roiSlices.empty()) {
212 ATH_MSG_ERROR(
"Unexpected data format - found candidate word before any timeslice header");
214 return StatusCode::FAILURE;
217 std::pair<size_t,size_t>&
slice = roiSlices.back();
225 if (topoSlices.empty()) {
226 ATH_MSG_ERROR(
"Unexpected data format - found Topo TOB word before any timeslice header");
227 return StatusCode::FAILURE;
230 std::pair<size_t,size_t>&
slice = topoSlices.back();
239 if (!errorBits.empty()) {
240 ATH_MSG_DEBUG(
"MUCTPI ROD data flagged with errors. The data status word is 0x" << std::hex << word << std::dec);
241 for (
size_t bit : errorBits) {
242 ATH_MSG_DEBUG(
"Error bit " << bit <<
": " << LVL1::MuCTPIBits::DataStatusWordErrors.at(bit));
250 ATH_MSG_ERROR(
"The MUCTPI word 0x" << std::hex << word << std::dec <<
" does not match any known word type");
252 return StatusCode::FAILURE;
262 const size_t nSlices{roiSlices.size()};
264 if (nSlices > nOutputSlices) {
266 return StatusCode::FAILURE;
267 }
else if (nSlices !=
static_cast<size_t>(rob->rod_detev_type())) {
268 ATH_MSG_ERROR(
"Found " << nSlices <<
" time slices, but Detector Event Type word indicates there should be "
269 << rob->rod_detev_type());
270 return StatusCode::FAILURE;
271 }
else if (nSlices!=1 && nSlices!=3 && nSlices!=5) {
272 ATH_MSG_ERROR(
"Expected 1, 3 or 5 time slices but found " << nSlices);
273 return StatusCode::FAILURE;
275 const size_t outputOffset = nOutputSlices/2 - nSlices/2;
280 const size_t nTopoSlices{topoSlices.size()};
282 if (nTopoSlices > nTopoOutputSlices) {
284 return StatusCode::FAILURE;
285 }
else if (nTopoSlices !=
static_cast<size_t>(rob->rod_detev_type())) {
286 ATH_MSG_ERROR(
"Found " << nTopoSlices <<
" time slices, but Detector Event Type word indicates there should be "
287 << rob->rod_detev_type());
288 return StatusCode::FAILURE;
289 }
else if (nTopoSlices!=1 && nTopoSlices!=3 && nTopoSlices!=5) {
290 ATH_MSG_ERROR(
"Expected 1, 3 or 5 time slices but found " << nTopoSlices);
291 return StatusCode::FAILURE;
293 const size_t topoOutputOffset = nTopoOutputSlices/2 - nTopoSlices/2;
299 auto topoHandleIt = topoHandles.begin();
300 for (
auto& roiHandle : roiHandles) {
301 auto& topoHandle = *topoHandleIt;
306 Monitored::Scalar<int> monNumDiff{
"NumOutputDiffRoITopo",
static_cast<int>(monNumRoIs)-
static_cast<int>(monNumTopo)};
307 ATH_MSG_DEBUG(
"Decoded " << monNumRoIs <<
" RoIs into the " << roiHandle.key() <<
" container "
308 "and " << monNumTopo <<
" Topo TOBs into the " << topoHandle.key() <<
" container");
312 ATH_MSG_DEBUG(
"Decoded " << monNumRoIs <<
" RoIs into the " << roiHandle.key() <<
" container");
318 return StatusCode::SUCCESS;