ATLAS Offline Software
ITkStripsRodEncoder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "ITkStripsRodEncoder.h"
6 
12 
13 #include "Identifier/Identifier.h"
15 
16 namespace { // Anonymous namespace
17  int
18  rodLinkFromOnlineID(const SCT_OnlineId onlineID){
19  const uint32_t fibre{onlineID.fibre()};
20  const int formatter{static_cast<int>((fibre/12) & 0x7)};
21  const int linkNum{static_cast<int>((fibre - (formatter*12)) & 0xF)};
22  const int rodLink{(formatter << 4) | linkNum};
23  return rodLink;
24  }
25  bool
26  isOdd(const int someNumber){
27  return static_cast<bool>(someNumber & 1);
28  }
29 
30 
31 } // End of anonymous namespace
32 
33 // Constructor
34 
35 ITkStripsRodEncoder::ITkStripsRodEncoder(const std::string& type, const std::string& name,
36  const IInterface* parent) :
37  base_class(type, name, parent){
38  //nop
39 }
40 
41 // Initialize
42 
45  ATH_MSG_DEBUG("ITkStripsRodEncoder::initialize()");
46 
47  // Retrieve cabling tool
48  ATH_CHECK(m_cabling.retrieve());
49  ATH_MSG_DEBUG("Retrieved tool " << m_cabling);
51  const InDetDD::SCT_DetectorManager* itkStripsDetManager{nullptr};
52  ATH_CHECK(detStore()->retrieve(itkStripsDetManager, "SCT"));
53  const InDetDD::SiDetectorElementCollection* sctDetElementColl{itkStripsDetManager->getDetectorElementCollection()};
54  for (const InDetDD::SiDetectorElement* sctDetElement : *sctDetElementColl) {
55  if (sctDetElement->swapPhiReadoutDirection()) {
56  m_swapModuleID.insert(sctDetElement->identify());
57  }
58  }
59  return StatusCode::SUCCESS;
60 }
61 
62 
64  return StatusCode::SUCCESS;
65 }
66 
67 void
68 ITkStripsRodEncoder::fillROD(std::vector<uint32_t>& /*vec32Data*/, const uint32_t& /*robID*/,
69  const std::vector<const SCT_RDORawData*>& /*vecRDOs*/) const {
70  //code to be filled here
71  return;
72 }
73 
74 //NOTE: For ITkStrips there is not 'group size' but a mask instead
75 void
76 ITkStripsRodEncoder::encodeData(const std::vector<int>& /*vecTimeBins*/, std::vector<uint16_t>& /*vec16Words*/,
77  const SCT_RDORawData* /*rdo*/, const int& /*groupSize*/, const int& /*strip*/) const {
79  return;
80 }
81 
82 //not sure whether this will be needed for ITkStrips
83 void
84 ITkStripsRodEncoder::packFragments(std::vector<uint16_t>& vec16Words,
85  std::vector<uint32_t>& vec32Words) const {
86  int num16Words{static_cast<int>(vec16Words.size())};
87  if (isOdd(num16Words)) {
88  // Just add an additional 16bit words to make even size v16 to in the 32 bits word 0x40004000
89  vec16Words.push_back(0x4000);
90  num16Words++;
91  }
92  // Now merge 2 consecutive 16 bit words in 32 bit words
93  const unsigned short int numWords{2};
94  const unsigned short int position[numWords]{0, 16};
95  unsigned short int arr16Words[numWords]{0, 0};
96  for (int i{0}; i<num16Words; i += numWords) {
97  arr16Words[i%numWords] = vec16Words[i+1];
98  arr16Words[(i+1)%numWords] = vec16Words[i];
99  const uint32_t uint32Word{set32Bits(arr16Words, position, numWords)};
100  vec32Words.push_back(uint32Word);
101 #ifdef ITkStripsDEBUG
102  ATH_MSG_INFO("SCT encoder -> PackFragments: Output rod 0x"<<std::hex<<uint32Word<<std::dec);
103 #endif
104  }
105  return;
106 }
107 
108 
109 uint32_t
110 ITkStripsRodEncoder::set32Bits(const unsigned short int* arr16Words,
111  const unsigned short int* position,
112  const unsigned short int& numWords) const {
113  uint32_t uint32Word{0};
114  uint32_t pos{0};
115  uint32_t uint16Word{0};
116  for (uint16_t i{0}; i<numWords; i++) {
117  uint16Word = static_cast<uint32_t>(*(arr16Words+i));
118  pos = static_cast<uint32_t>(*(position+i));
119  uint32Word |= (uint16Word<<pos);
120  }
121  return uint32Word;
122 }
123 
124 // Get RDO info functions
125 int
127  const Identifier rdoID{rdo->identify()};
128  return m_itkStripsID->strip(rdoID);
129 }
130 
131 Identifier
133  const Identifier rdoId{rdo->identify()};
134  return m_itkStripsID->wafer_id(rdoId);
135 }
136 
137 uint32_t
139  const Identifier waferID{offlineID(rdo)};
140  const IdentifierHash offlineIDHash{m_itkStripsID->wafer_hash(waferID)};
141  return static_cast<uint32_t>(m_cabling->getOnlineIdFromHash(offlineIDHash));
142 }
143 
144 int
146  return rodLinkFromOnlineID(onlineID(rdo));
147 }
148 
149 int
151  const Identifier rdoID{rdo->identify()};
152  int itkSide{m_itkStripsID->side(rdoID)};
153  return itkSide;
154 }
155 
156 
157 
158 //the following may be needed for ITkStrips, but must have different implementation
159 uint16_t
161  const int rodLink{getRODLink(rdo)};
162  const uint16_t linkHeader{static_cast<uint16_t>(0x2000 | (m_condensed.value() << 8) | rodLink)};
163  return linkHeader;
164 }
165 
166 uint16_t
167 ITkStripsRodEncoder::getHeaderUsingHash(const IdentifierHash& linkHash, const int& errorWord) const {
168  const int rodLink{rodLinkFromOnlineID(m_cabling->getOnlineIdFromHash(linkHash))};
169  const uint16_t linkHeader{static_cast<uint16_t>(0x2000 | errorWord | (m_condensed.value() << 8) | rodLink)};
170  return linkHeader;
171 }
172 
173 uint16_t
174 ITkStripsRodEncoder::getTrailer(const int& errorWord) const {
175  const uint16_t linkTrailer{static_cast<uint16_t>(0x4000 | errorWord)};
176  return linkTrailer;
177 }
178 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
ITkStripsRodEncoder::initialize
virtual StatusCode initialize() override
Initialize.
Definition: ITkStripsRodEncoder.cxx:44
InDetDD::SCT_DetectorManager
Definition: SCT_DetectorManager.h:49
ITkStripsRodEncoder::set32Bits
uint32_t set32Bits(const unsigned short int *arr16Words, const unsigned short int *position, const unsigned short int &numWords) const
@breif Method to set pairs of 16 bit words to a 32 bit word.
Definition: ITkStripsRodEncoder.cxx:110
ITkStripsRodEncoder::packFragments
void packFragments(std::vector< uint16_t > &vec16Words, std::vector< uint32_t > &vec32Words) const
Method to pack vector of 16 bit words intto a vector of 32 bit words.
Definition: ITkStripsRodEncoder.cxx:84
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
ITkStripsRodEncoder.h
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SCT_OnlineId
Definition: SCT_OnlineId.h:22
ITkStripsRodEncoder::ITkStripsRodEncoder
ITkStripsRodEncoder(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
Definition: ITkStripsRodEncoder.cxx:35
ITkStripsRodEncoder::m_swapModuleID
std::set< Identifier > m_swapModuleID
Swap Module identifier, set by SCTRawContByteStreamTool.
Definition: ITkStripsRodEncoder.h:142
SCT_RDORawData
Definition: SCT_RDORawData.h:24
ITkStripsRodEncoder::finalize
virtual StatusCode finalize() override
Finalize.
Definition: ITkStripsRodEncoder.cxx:63
ITkStripsRodEncoder::onlineID
uint32_t onlineID(const SCT_RDORawData *rdo) const
Get the online Identifier from the RDO.
Definition: ITkStripsRodEncoder.cxx:138
ITkStripsRodEncoder::getHeaderUsingHash
uint16_t getHeaderUsingHash(const IdentifierHash &linkHash, const int &errorWord) const
Get the 16-bit word for a header for a link with a ByteStream error.
Definition: ITkStripsRodEncoder.cxx:167
ITkStripsRodEncoder::m_condensed
BooleanProperty m_condensed
Example Boolean used to determine decoding mode, maybe unused finally.
Definition: ITkStripsRodEncoder.h:139
ITkStripsRodEncoder::getRODLink
int getRODLink(const SCT_RDORawData *rdo) const
Get the ROD link number info in the RDO header data.
Definition: ITkStripsRodEncoder.cxx:145
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
lumiFormat.i
int i
Definition: lumiFormat.py:85
ITkStripsRodEncoder::offlineID
Identifier offlineID(const SCT_RDORawData *rdo) const
Get the offline Identifier from the RDO.
Definition: ITkStripsRodEncoder.cxx:132
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SCT_ID::wafer_hash
IdentifierHash wafer_hash(const Identifier &wafer_id) const
wafer hash from id - optimized
Definition: SCT_ID.h:492
SCT_RDORawData.h
ITkStripsRodEncoder::getHeaderUsingRDO
uint16_t getHeaderUsingRDO(const SCT_RDORawData *rdo) const
Get the 16-bit word for a header for a hit.
Definition: ITkStripsRodEncoder.cxx:160
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ITkStripsRodEncoder::fillROD
virtual void fillROD(std::vector< uint32_t > &vec32Data, const uint32_t &robID, const std::vector< const SCT_RDORawData * > &vecRDOs) const override
Main Convert method.
Definition: ITkStripsRodEncoder.cxx:68
IdentifierHash.h
vtune_athena.formatter
formatter
Definition: vtune_athena.py:19
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SiDetectorElementCollection.h
SiDetectorElement.h
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ITkStripsRodEncoder::side
int side(const SCT_RDORawData *rdo) const
Get the side info from the RDO.
Definition: ITkStripsRodEncoder.cxx:150
ITkStripsRodEncoder::getStrip
int getStrip(const SCT_RDORawData *rdo) const
Get the strip number info from the RDO.
Definition: ITkStripsRodEncoder.cxx:126
ITkStripsRodEncoder::getTrailer
uint16_t getTrailer(const int &errorWord) const
Get the 16-bit word for a trailer, with or without ByteStream errors.
Definition: ITkStripsRodEncoder.cxx:174
SCT_ID::strip
int strip(const Identifier &id) const
Definition: SCT_ID.h:764
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SCT_OnlineId::fibre
std::uint32_t fibre() const
Return the fibre.
Definition: SCT_OnlineId.cxx:65
SCT_ID::side
int side(const Identifier &id) const
Definition: SCT_ID.h:752
ITkStripsRodEncoder::encodeData
void encodeData(const std::vector< int > &vecTimeBins, std::vector< uint16_t > &vec16Words, const SCT_RDORawData *rdo, const int &groupSize, const int &strip) const
Method to encode RDO data to vector of 16 bin words.
Definition: ITkStripsRodEncoder.cxx:76
InDetRawData::identify
virtual Identifier identify() const override final
Definition: InDetRawData.h:41
SCT_ID::wafer_id
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition: SCT_ID.h:464
SCT_DetectorManager.h
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
ITkStripsRodEncoder::m_itkStripsID
const SCT_ID * m_itkStripsID
Identifier helper class for the ITkStrips subdetector that creates compact Identifier objects and Ide...
Definition: ITkStripsRodEncoder.h:136
ITkStripsRodEncoder::m_cabling
ToolHandle< ISCT_CablingTool > m_cabling
Providing mappings of online and offline identifiers and also serial numbers.
Definition: ITkStripsRodEncoder.h:129
Identifier
Definition: IdentifierFieldParser.cxx:14