ATLAS Offline Software
Loading...
Searching...
No Matches
MdtROD_Encoder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Implementation of MdtROD_Encoder class
6
7#include "MdtROD_Encoder.h"
8
9#include <cmath>
10
11#include <algorithm>
12#include <map>
13
14#include "MDT_Hid2RESrcID.h"
15#include "MdtAmtReadOut.h"
16#include "MdtCsmReadOut.h"
17#include "MdtHptdcReadOut.h"
20
22 if (!m_mdtIdHelper.retrieve().isSuccess()) { throw std::runtime_error("MdtROD_Encoder -- Failed to initialize the IdHelperSvc"); }
23}
24// Add a CSM
25void MdtROD_Encoder::add(const MdtCsm* csm) { m_vMdtCsm.push_back(csm); }
26
27// Clear the vector of CSMs
28void MdtROD_Encoder::clear() { m_vMdtCsm.erase(m_vMdtCsm.begin(), m_vMdtCsm.end()); }
29
33
34void MdtROD_Encoder::fillROD(std::vector<uint32_t>& v) {
35 MdtAmtReadOut amtReadOut{};
36 MdtHptdcReadOut hptdcReadOut{};
37 MdtCsmReadOut csmReadOut{};
38
39 uint32_t mrod_wcnt{0};
40
41 using hit_vector = std::vector<const MdtAmtHit*>;
42 using tdc_map = std::map<uint16_t, hit_vector>;
43 using masked_map = std::map<uint16_t, uint32_t>;
44
45 tdc_map tdcMap;
46 masked_map maskedMap;
47
48 // Insert the Beginning of Block Word (Lvl1ID not set yet)
49 uint32_t lvl1Id = 0;
50 v.push_back(csmReadOut.makeBOB(lvl1Id));
51
52 // make the body of the ROD
53 // Loop on the CSMs
54 for (const MdtCsm* csm : m_vMdtCsm) {
55 const bool isHPTDC = m_mdtIdHelper->hasHPTDC(csm->identify());
56
57 uint16_t ctwc = 0; // Trailer word count initialized
58
59 v.push_back(csmReadOut.makeLWC(0)); // Link Word Count
60 v.push_back(csmReadOut.makeBOL(csm->MrodId(), csm->CsmId())); // Beginning of link
61
62 v.push_back(csmReadOut.makeTLP(0));
63 ++ctwc; // Trailer word count starts from TLP
64
65 // Group the hits of this CSM according to the TDC number
66 tdcMap.clear();
67 maskedMap.clear();
68 for (const MdtAmtHit* amt : *csm) {
69 uint16_t tdcNum = amt->tdcId();
70
71 if (!amt->isMasked()) {
72 tdcMap[tdcNum].push_back(amt);
73 } else {
74 maskedMap[tdcNum] = maskedMap[tdcNum] | (int)pow(2, amt->channelId());
75 }
76 }
77
78 // Loop on the TDCs and build the corresponding MROD blocks
79 uint16_t jt = 0;
80 tdc_map::const_iterator it_tdc = tdcMap.begin();
81 for (; it_tdc != tdcMap.end(); ++it_tdc) {
82 // Beginning of TDC header word
83 // Need to fix event counter and bcid
84 v.push_back((isHPTDC ? hptdcReadOut.makeBOT((*it_tdc).first, 0, 0) : amtReadOut.makeBOT((*it_tdc).first, 0, 0)));
85 ++ctwc;
86
87 uint32_t maskedFlags = maskedMap[(*it_tdc).first];
88 uint16_t wcnt = 0; // TDC word count
89
90 // Masked channels flags
91 if (maskedFlags != 0) {
92 v.push_back((isHPTDC ? 0 : amtReadOut.makeTMC(jt, maskedFlags)));
93 ++ctwc;
94 ++wcnt;
95 }
96
97 // Loop on the hits for this TDC
98 hit_vector::const_iterator it_amtvec = (*it_tdc).second.begin();
99 for (; it_amtvec != (*it_tdc).second.end(); ++it_amtvec) {
100 uint16_t chan = (*it_amtvec)->channelId();
101
102 uint16_t coarse = (*it_amtvec)->coarse();
103 uint16_t fine = (*it_amtvec)->fine();
104 uint16_t width = (*it_amtvec)->width();
105 uint16_t tdcId = (*it_amtvec)->tdcId();
106
107 // Add a "Single Measurement" word
108 // v.push_back( isHPTDC ? hptdcReadOut.makeTSM(tdcId, chan, leading, coarse, fine)
109 // : amtReadOut.makeTSM(jt, chan, leading, errflag, coarse, fine) );
110
111 // Add a combined measurement data word
112 v.push_back(
113 (isHPTDC ? hptdcReadOut.makeTCM(tdcId, chan, width, coarse, fine) : amtReadOut.makeTCM(jt, chan, width, coarse, fine)));
114
115 ++ctwc; // CSM word count
116 ++wcnt; // TDC word count
117 }
118
119 uint16_t jt{0}, tdcId{0}, ecnt{0}; // Event counter
120 // End of TDC trailer
121 v.push_back((isHPTDC ? hptdcReadOut.makeEOT(tdcId, ecnt, wcnt + 2) : amtReadOut.makeEOT(jt, ecnt, wcnt + 2)));
122 ++ctwc;
123 }
124
125 // Last word of each csm: TWC trailer word count
126 uint16_t ecnt = 0;
127 v.push_back(csmReadOut.makeTWC(ecnt, ctwc));
128
129 // Update the MROD word count
130 mrod_wcnt += ctwc;
131 mrod_wcnt += 2;
132 }
133
134 // Close the MROD: MROD word count in EOB
135 v.push_back(csmReadOut.makeEOB(mrod_wcnt));
136}
const double width
constexpr int pow(int base, int exp) noexcept
MDT RDO's : data from a single channel of an AMT Atlas Muon TDC.
Definition MdtAmtHit.h:20
uint32_t makeTMC(uint16_t jt, uint32_t masked)
uint32_t makeEOT(uint16_t jt, uint16_t ecnt, uint16_t wcnt)
uint32_t makeTCM(uint16_t jt, uint16_t channel, uint16_t width, uint16_t coarse, uint16_t fine)
uint32_t makeBOT(uint16_t tdcId, uint16_t ecnt, uint16_t bcid)
uint32_t makeEOB(uint32_t wcnt)
uint32_t makeBOB(uint32_t lvl1Id)
uint32_t makeTLP(uint32_t flags)
uint32_t makeLWC(uint32_t clwc)
uint32_t makeBOL(uint16_t mrodId, uint16_t csmId)
uint32_t makeTWC(uint16_t ecnt, uint16_t ctwc)
MDT RDOs : Chamber Service Module, container of AmtHits of a single Mdt chamber.
Definition MdtCsm.h:19
uint32_t makeBOT(uint16_t tdcId, uint16_t ecnt, uint16_t bcid)
uint32_t makeEOT(uint16_t tdcId, uint16_t ecnt, uint16_t wcnt)
uint32_t makeTCM(uint16_t tdcId, uint16_t channel, uint16_t width, uint16_t coarse, uint16_t fine)
ServiceHandle< Muon::IMuonIdHelperSvc > m_mdtIdHelper
MdtROD_Encoder()
constructor
std::vector< const MdtCsm * > m_vMdtCsm
void add(const MdtCsm *csm)
initialize the map
void clear()
clear the current csm list
void fillROD(std::vector< uint32_t > &v)
convert all Csm in the current list to a vector of 32bit words