ATLAS Offline Software
CscROD_Encoder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Implementation of CscROD_Encoder class
6 
7 #include "CscROD_Encoder.h"
8 
9 #include "CscRODReadOut.h"
10 #include "GaudiKernel/Bootstrap.h"
11 #include "GaudiKernel/IMessageSvc.h"
12 #include "GaudiKernel/ISvcLocator.h"
13 #include "GaudiKernel/MsgStream.h"
14 #include "GaudiKernel/StatusCode.h"
16 
19 CscROD_Encoder::CscROD_Encoder() : m_cscRdo(nullptr) {}
20 
23 StatusCode CscROD_Encoder::fillROD(std::vector<uint32_t>& v, MsgStream& mLog) {
24  mLog << MSG::DEBUG << " in CscROD_Encoder " << endmsg;
25 
26  // ROD readout structure : encoder/decoder
27  CscRODReadOut rodReadOut;
28 
29  // initialize the identifier helper
30  rodReadOut.set(m_cscIdHelper);
31 
32  // first group the pads into their RPUs
33  typedef std::vector<const CscRawData*> rpu;
34  std::map<uint16_t, rpu> mapRPU;
35 
39  uint16_t rpuID = 0x0;
40  for (; it != it_end; ++it) {
41  const CscRawData* rawData = (*it);
42  uint16_t spuID = rawData->rpuID();
43  if (spuID <= 4)
44  rpuID = 5;
45  else if (spuID > 4 && spuID <= 9)
46  rpuID = 11;
47  else {
48  mLog << MSG::ERROR << "CscROD_Encoder : RPU ID out of range for Initial Layout:: SPU ID = " << spuID << endmsg;
49  return StatusCode::FAILURE;
50  }
51  mLog << MSG::DEBUG << "CscROD_Encoder : SPU ID is " << spuID << " for RPU ID= " << rpuID << endmsg;
52  mapRPU[rpuID].push_back(rawData);
53  }
54 
56  rpu emptyVect;
57  emptyVect.clear();
58  const std::vector<uint16_t> rpus = m_cscRdo->rpuID();
59  if (rpus.size() == 1) {
60  uint16_t rId = rpus[0];
61  mLog << MSG::DEBUG << "CscROD_Encoder : Only one RPU with data in this ROD - RPU ID = " << rId << endmsg;
62  uint16_t emptyRPU = 5;
63  if (rId == emptyRPU) emptyRPU = 11;
64  mapRPU.insert(std::make_pair(emptyRPU, emptyVect));
65  }
66 
68  bool samplingPhase = m_cscRdo->samplingPhase();
70  uint8_t firstBitSummary = m_cscRdo->firstBitSummary();
71 
73  mLog << MSG::DEBUG << "Number of RPU in this ROD = " << mapRPU.size() << endmsg;
74 
75  unsigned int rpuIndex = 0;
76  for (std::pair<const uint16_t, rpu>& rpuPair : mapRPU) {
78  uint16_t rpuID = rpuPair.first;
79  mLog << MSG::DEBUG << "CscROD_Encoder : RPU id " << rpuID << endmsg;
80 
91  uint32_t spuSize[] = {0, 0, 0, 0, 0};
92  uint16_t numberOfDataWords = 0;
93  uint32_t sampleDataWords = 0;
94  for (const CscRawData* rawData : rpuPair.second) {
95  uint16_t spuID = rawData->rpuID();
96  mLog << MSG::DEBUG << "CscROD_Encoder : The SPU ID " << spuID << endmsg;
97  unsigned int i = 0x800;
98  if (spuID < 4)
99  i = spuID;
100  else if (spuID > 4 && spuID < 9)
101  i = spuID - 5;
102  else if (spuID == 4 || spuID == 9)
103  i = 4;
104  if (i > 4) {
105  mLog << MSG::ERROR << "CscROD_Encoder : SPU ID out of range - " << spuID << " Stop and fix it " << endmsg;
106  } else {
107  mLog << MSG::DEBUG << "CscROD_Encoder : SPU ID and Index = " << spuID << " " << i << endmsg;
108  uint16_t size = (rawData->samples()).size();
109  uint16_t unitSize = size / 2 + size % 2;
110  spuSize[i] += 1;
111  numberOfDataWords += 2 + unitSize;
112  sampleDataWords += unitSize;
113  }
114  }
115  mLog << MSG::DEBUG << "CscROD_Encoder : Total Sample size = " << sampleDataWords << endmsg;
116 
120  uint16_t rpuSize = numberOfDataWords + 4;
121 
122  mLog << MSG::DEBUG << "CscRDO_Encoder : RPU ID and size (in words) = " << rpuID << " " << rpuSize << endmsg;
123 
125  std::vector<uint8_t> dataType = m_cscRdo->dataType();
126  uint16_t type;
127  uint16_t typeSize = dataType.size();
128  if (typeSize > rpuIndex)
129  type = dataType[rpuIndex];
130  else if (typeSize == 1)
131  type = dataType[0];
132  else
133  type = 0x0;
134 
135  mLog << MSG::DEBUG << "CscROD_Encoder : data type = " << type << endmsg;
136 
139  uint32_t rpuHeader = (0xFFFF & rpuSize) | (0x000F & type) << 16 | (0x000F & rpuID) << 24;
140 
142  v.push_back(rpuHeader);
143 
144  mLog << MSG::DEBUG << "CscROD_Encoder : this rpuHeader = " << MSG::hex << rpuHeader << MSG::dec << endmsg;
145 
147  v.push_back(m_cscRdo->scaAddress());
148 
150  uint32_t precisionClusterWord = 0x0;
151  for (unsigned int i = 0; i < 4; ++i) {
152  precisionClusterWord = precisionClusterWord | (spuSize[i] << (24 - i * 8));
153  mLog << MSG::DEBUG << "CscROD_Encoder : SPU ID = " << (i + 1) << " cluster Counts " << spuSize[i] << endmsg;
154  }
155  v.push_back(precisionClusterWord);
156 
157  mLog << MSG::DEBUG << "CscROD_Encoder : Non-precision "
158  << " cluster Counts " << spuSize[4] << endmsg;
159 
160  mLog << MSG::DEBUG << "CscROD_Encoder:: number of Cluster Data Words " << numberOfDataWords << endmsg;
161 
163  uint32_t secondClusterWord = (0xFFFF & numberOfDataWords) | (0xF & firstBitSummary) << 16 | (0x1 & samplingPhase) << 17 |
164  (0x1 & triggerType) << 18 | (0xFF & spuSize[4]) << 24;
165  v.push_back(secondClusterWord);
166 
169  unsigned int check = 0;
170  for (const CscRawData* rawData : rpuPair.second) {
171  uint32_t address = rawData->address();
172  uint16_t time = rawData->time();
173  uint16_t width = rawData->width();
174  bool isTimeComputed = rawData->isTimeComputed();
175 
176  v.push_back(address);
177  check++;
178 
179  uint32_t secondWord = (0xFFF & width) | (0xFFFF & time) << 16 | (0x1 & isTimeComputed) << 28;
180 
181  v.push_back(secondWord);
182  check++;
183 
184  const std::vector<uint16_t> amplitude = rawData->samples();
185  std::vector<uint32_t> v32;
186  rodReadOut.encodeFragments(amplitude, v32);
187  unsigned int n = v32.size();
188  for (unsigned int i = 0; i < n; i++) { v.push_back(v32[i]); }
189  check += n;
190  mLog << MSG::DEBUG << "CscROD_Encoder : The with and the 32-bit sample words " << width << " " << n << endmsg;
191  }
192 
193  rpuIndex++;
194 
195  mLog << MSG::DEBUG << "CScROD_Encoder : Check and number of data words " << check << " " << numberOfDataWords << endmsg;
196  }
197 
200  return StatusCode::SUCCESS;
201 }
plotBeamSpotCompare.x1
x1
Definition: plotBeamSpotCompare.py:216
CscRawData::rpuID
uint16_t rpuID() const
data access methods
Definition: CscRawData.h:125
CscRawData::address
uint32_t address() const
Definition: CscRawData.h:131
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
skel.it
it
Definition: skel.GENtoEVGEN.py:396
CscRawData::isTimeComputed
bool isTimeComputed() const
Definition: CscRawData.h:129
downloadSingle.dataType
string dataType
Definition: downloadSingle.py:18
CscRawDataCollection::rpuID
const std::vector< uint16_t > & rpuID() const
Definition: CscRawDataCollection.h:115
CscRawDataCollection::samplingPhase
bool samplingPhase() const
Definition: CscRawDataCollection.h:117
CscRODReadOut.h
CscROD_Encoder::CscROD_Encoder
CscROD_Encoder()
constructor
Definition: CscROD_Encoder.cxx:19
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
CscRODReadOut::set
void set(const CscIdHelper *cscIdHelper)
Definition: CscRODReadOut.h:50
CscRawDataCollection::triggerType
bool triggerType() const
Definition: CscRawDataCollection.h:118
CscROD_Encoder.h
CscRODReadOut
Definition: CscRODReadOut.h:22
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
CscRawDataCollection::dataType
const std::vector< uint8_t > & dataType() const
Definition: CscRawDataCollection.h:116
lumiFormat.i
int i
Definition: lumiFormat.py:85
CscRawData::width
uint16_t width() const
Definition: CscRawData.h:128
CscRawDataCollection::firstBitSummary
uint8_t firstBitSummary() const
Definition: CscRawDataCollection.h:119
beamspotman.n
n
Definition: beamspotman.py:731
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
CscRawDataCollection::scaAddress
uint32_t scaAddress() const
Definition: CscRawDataCollection.h:123
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
CscROD_Encoder::fillROD
StatusCode fillROD(std::vector< uint32_t > &v, MsgStream &mLog)
convert all CscRawDataCollections in the current list to a vector of 32bit words
Definition: CscROD_Encoder.cxx:23
CscROD_Encoder::m_cscIdHelper
const CscIdHelper * m_cscIdHelper
Definition: CscROD_Encoder.h:48
CscRawDataCollection.h
CscRODReadOut::encodeFragments
void encodeFragments(const std::vector< uint16_t > &amplitude, std::vector< uint32_t > &v) const
Definition: CscRODReadOut.cxx:53
CscRawData::samples
const std::vector< uint16_t > & samples() const
Definition: CscRawData.h:130
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
LArNewCalib_Delay_OFC_Cali.check
check
Definition: LArNewCalib_Delay_OFC_Cali.py:258
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
CscRawData::time
uint16_t time() const
Definition: CscRawData.h:127
python.PyAthena.v
v
Definition: PyAthena.py:154
CscRawData
Class to hold the electronic output for a single CSC readout channel: n sampling ADC data + the addre...
Definition: CscRawData.h:21
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
CscROD_Encoder::m_cscRdo
const CscRawDataCollection * m_cscRdo
Definition: CscROD_Encoder.h:47
RunTileMonitoring.triggerType
triggerType
Definition: RunTileMonitoring.py:162
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.