30 ATH_CHECK(detStore()->retrieve(itkStripsDetManager,
"ITkStrip"));
33 if (element->swapPhiReadoutDirection()) {
38 return StatusCode::SUCCESS;
46 const EventContext& ctx,
47 const std::vector<IdentifierHash>* vecHash)
const
51 const uint32_t robID=robFrag.rod_source_id();
53 StatusCode
sc = StatusCode::SUCCESS;
59 cache.vecHash = vecHash;
62 const unsigned long int vecROBDataSize{robFrag.rod_ndata()};
63 if (vecROBDataSize > robFrag.payload_size_word()) {
64 ATH_MSG_WARNING(
"The ROB data does not seem to fit in the payload. Rejecting fragment (ndata size " << vecROBDataSize <<
" !< payload size " << robFrag.payload_size_word()
65 <<
" header size: " << robFrag.rod_header_size_word()
66 <<
" trailer size: " << robFrag.rod_trailer_size_word()
67 <<
" fragment size: " << robFrag.rod_fragment_size_word()
69 return StatusCode::RECOVERABLE;
71 robFrag.rod_data(vecROBData);
76 for (uint32_t i=0; i<vecROBDataSize; i++) {
81 const uint8_t* vecROBData_8bits =
reinterpret_cast<const uint8_t*
>(vecROBData);
82 const size_t total_bytes = vecROBDataSize *
sizeof(uint32_t);
84 uint32_t nclusters = 0;
85 uint8_t isHCCHeader = 0;
87 uint16_t hccword1 = 0;
89 uint8_t HccHeadFound = 0;
90 uint16_t packetSize = 0;
91 bool noClusterTag =
false;
93 for (
size_t i=0; i < total_bytes; i+=2) {
95 bool hasError =
false;
96 bool breakNow =
false;
97 uint16_t psize=packetSize/4;
98 uint16_t word16 = (vecROBData_8bits[i] << 8) | vecROBData_8bits[i + 1];
99 ATH_MSG_DEBUG(
" 16-bit word: " << std::bitset<16>(word16) <<
" " << (uint32_t)i <<
" " << total_bytes );
101 if(i==total_bytes-2)
ATH_MSG_DEBUG(
"nClusters found (this): " << (uint32_t)nclusters);
102 ATH_MSG_DEBUG(
"Check: " << nPacket <<
" Packets: " << packetSize/4 <<
" isHCCHeader: " << (uint32_t)isHCCHeader <<
" " << nPacket);
104 if(psize != 0 && nPacket != 0){
106 if((nPacket+1) % (packetSize/2)==0) nPacket=-1;
109 if(word16 == 0 && noClusterTag && nPacket != 0){
112 }
else if((vecROBData_8bits[i] == 0 || isHCCHeader == 1) && HccHeadFound == 0 && nPacket<2){
114 ATH_MSG_DEBUG(
"HCC header found, will decode the next three 8-bit words: " <<(uint32_t)isHCCHeader);
115 if(isHCCHeader == 0){
116 hccword1 = (vecROBData_8bits[i + 1] << 8) | vecROBData_8bits[i+2];
118 }
else if(isHCCHeader == 1){
119 word8 = vecROBData_8bits[i + 1];
122 ATH_CHECK(
processHccHeader(hccword1, word8, isHCCHeader, robID, data, rdoIDCont, dataItemsPool, cache, errs, hasError, breakNow,ctx));
123 if(isHCCHeader==0) HccHeadFound = 1;
126 }
else if((HccHeadFound==1 && vecROBData_8bits[i] == 0) || HccHeadFound==2){
127 if(HccHeadFound==1) HccHeadFound=2;
128 else if(HccHeadFound==2){
134 }
else if(packetSize!=0 && ((vecROBData_8bits[i] & 0xF8) == 0x18) && (((nPacket+1) % (packetSize/2)) == 5)){
138 ATH_CHECK(
processHeader(word16, robID, data, rdoIDCont, dataItemsPool, cache, errs, hasError, breakNow,ctx));
141 if(word16 == 0xed6f){
147 ATH_CHECK(
processHits(word16, robID, data, rdoIDCont, dataItemsPool, cache, errs, hasError, ctx));
152 for (
auto& [hash, rdoColl] : data.rdoCollMap) {
153 if (rdoColl==
nullptr)
continue;
155 if (rdoColl->empty()) {
161 ATH_CHECK(data.writeHandleMap[hash].addOrDelete(std::move(rdoColl)));
164 if (
sc.isFailure())
ATH_MSG_DEBUG(
"One or more ByteStream errors found ");
176 if (rdoColl==
nullptr) {
177 ATH_MSG_WARNING(
"Null rdoCollection pointer found for linkIDHash: " << (uint32_t)data.linkIDHash);
181 int strip = data.strip;
182 if (((
strip & 0x7F) + (data.groupSize-1) >= 9999) or (
strip<0) or (
strip>=9999)) {
184 <<
" in collection " << data.linkIDHash <<
" out of range. Will not make RDO");
190 if (data.linkIDHash == cache.skipHash) {
194 else if (data.linkIDHash != cache.lastHash) {
195 cache.lastHash = data.linkIDHash;
197 std::vector<IdentifierHash>::const_iterator hashIDIterator{
find(cache.vecHash->begin(),
198 cache.vecHash->end(),
200 if (hashIDIterator == cache.vecHash->end()) {
203 cache.skipHash = data.linkIDHash;
216 const unsigned int rawDataWord{
static_cast<unsigned int>(data.groupSize | (
strip << 11) | (data.timeBin <<22) | (data.errors << 25))};
218 ATH_MSG_DEBUG(
"Output Raw Data " << std::hex <<
" Coll " << data.collID.getString()
219 <<
":-> " <<
m_itkStripsID->print_to_string(digitID) << std::dec);
226 (*sct_rdo) =
SCT3_RawData(digitID, rawDataWord, &(data.errorHit));
229 rdoColl->
push_back(std::make_unique<SCT3_RawData>(digitID, rawDataWord, &(data.errorHit)));
238 const std::unordered_set<IdentifierHash>* )
const
240 return StatusCode::SUCCESS;
249 return StatusCode::SUCCESS;
255 uint8_t &isHCCHeader,
264 const EventContext& )
const
267 StatusCode
sc{StatusCode::SUCCESS};
269 if(isHCCHeader == 1){
276 uint8_t
barrel = ((hccword1 >> 8) & 0x80);
277 ATH_MSG_DEBUG(
"is barrel: " << std::bitset<16>(hccword1 >> 8) <<
" " << std::bitset<8>(
barrel));
278 uint8_t side = ((hccword1 >> 5) & 0x80);
279 ATH_MSG_DEBUG(
"side : " << std::bitset<16>(hccword1 >> 5) <<
" " << std::bitset<8>(side));
280 uint8_t disk = ((hccword1 >> 9) & 0x7);
281 ATH_MSG_DEBUG(
"disk : " << std::bitset<16>((hccword1 >> 9) & 0x7) <<
" " << std::bitset<8>(disk));
282 uint8_t inout = ((hccword1 >> 8) & 0x1);
283 ATH_MSG_DEBUG(
"inout : " << std::bitset<16>((hccword1 >> 8) & 0x1) <<
" " << std::bitset<8>(inout));
284 uint8_t phi_petal = ((hccword1 >> 7) & 0x1);
285 ATH_MSG_DEBUG(
"phi petal: " << std::bitset<16>((hccword1 >> 7) & 0x1) <<
" " << std::bitset<8>(phi_petal));
286 uint8_t phihcc = hccword1 & 0x7F;
287 ATH_MSG_DEBUG(
"phihcc : " << std::bitset<16>(hccword1 & 0x7F) <<
" " << std::bitset<8>(phihcc));
288 uint8_t hccnum = word8 & 0x80;
289 ATH_MSG_DEBUG(
"hccnum : " << std::bitset<16>(word8 & 0x80) <<
" " << std::bitset<8>(hccnum));
290 uint8_t eta_amod = word8 & 0x3F;
291 ATH_MSG_DEBUG(
"eta amod: " << std::bitset<16>(word8 & 0x3F) <<
" " << std::bitset<8>(eta_amod));
293 bool isbarrel = (
barrel != 0x0);
294 bool issideA = (side != 0x0);
295 bool isinout = (inout == 0x1);
296 bool ispetal = (
barrel == 0x0);
297 uint8_t hccN = (hccnum == 0x80) ? 2 : 1;
299 uint8_t phi_mod = (!isbarrel && eta_amod > 9) ? 2 * phihcc + phi_petal : phihcc;
300 int eta_module = isbarrel ? (issideA ?
static_cast<int>(eta_amod) : -
static_cast<int>(eta_amod)) :
static_cast<int>(eta_amod);
302 ATH_MSG_DEBUG(
"isBarrel: " << isbarrel <<
" isSideA: " << issideA <<
" disk: " << (uint32_t)disk);
303 ATH_MSG_DEBUG(
"isInOut: " << isinout <<
" isPetal: " << ispetal <<
" phimod: " << (uint32_t)phi_mod);
304 ATH_MSG_DEBUG(
"HCCNum: " << (uint32_t)hccN <<
" etamod: " << (
int)eta_module);
306 int barrel_ec = isbarrel ? 0 : (issideA ? 2 : -2);
310 data.setCollection(
m_itkStripsID, offlinehash, rdoIDCont, dataItemsPool, errs);
314 ATH_MSG_DEBUG(
"hccheader " << isbarrel <<
" " << issideA <<
" " << (uint32_t)disk <<
" "
315 << (uint32_t)inout <<
" " << (uint32_t)phi_mod <<
" " << (uint32_t)eta_module <<
" " << (uint32_t)hccN );
324 const uint32_t robID,
332 const EventContext& ctx)
const
334 StatusCode
sc = StatusCode::SUCCESS;
336 data.foundHeader =
true;
339 uint8_t
type = (word16 >> 12) & 0xF;
341 uint8_t l0tag = (word16 >> 4) & 0x7F;
342 uint8_t bcid_low = (word16 >> 1) & 0x7;
343 uint8_t bcid_xor = word16 & 0x1;
345 ATH_MSG_DEBUG(
"l0tag: " << (uint32_t)l0tag <<
" bcid_low: " << (uint32_t)bcid_low <<
" bcid_xor: " << (uint32_t)bcid_xor
346 <<
" type: " << (uint32_t)
type <<
" word16: " << std::bitset<16>(word16));
349 constexpr bool breakHere{
false};
351 if (hasError)
sc = StatusCode::RECOVERABLE;
352 if (breakHere)
return sc;
362 const int rodlinkNumber{
static_cast<int>(word16 & 0x7F)};
365 data.linkNumber = (((rodlinkNumber >>4)&0x7)*12+(rodlinkNumber &0xF));
366 const uint32_t onlineID{(robID & 0xFFFFFF) | (data.linkNumber << 24)};
367 ATH_MSG_DEBUG(
"OnlineID: " << (uint32_t)onlineID <<
" Link number: " << data.linkNumber);
369 if ((onlineID ==0) or (data.linkNumber > 95)) {
372 ATH_MSG_DEBUG(
"Header: xxx Link number out of range (skipping following data)"
373 << std::dec << data.linkNumber);
378 hash =
m_cabling->getHashFromOnlineId(onlineID, ctx);
379 if (hash.is_valid()) {
384 std::stringstream
msg;
385 msg <<std::hex << onlineID;
386 ATH_MSG_WARNING(
"Rob fragment (rob=" << robID <<
") with invalid onlineID " <<
msg.str() <<
" -> " << hash <<
".");
389 if (!hasError and not hash.is_valid()) {
390 std::stringstream
msg;
391 msg <<std::hex << onlineID;
392 ATH_MSG_WARNING(
"Rob fragment (rob=" << robID <<
") with invalid onlineID " <<
msg.str() <<
" -> " << hash <<
".");
396 data.condensedMode =
static_cast<bool>(word16 & 0x100);
409 const EventContext& )
const
411 StatusCode
sc = StatusCode::SUCCESS;
413 uint nchip = (word16 >> 11) & 0xF;
414 bool isSecondRow = (word16 >> 10) & 0x01;
415 uint8_t address = (word16 >> 3) & 0x7F;
418 uint8_t firsthit = (word16 >> 2) & 0x1;
419 uint8_t secondhit = (word16 >> 1) & 0x1;
420 uint8_t thirdhit = (word16) & 0x1;
426 uint8_t stripN1 = 0,stripN2 = 0,stripN3=0;
431 stripN1 = 2*addr + (isSecondRow ? 1 : 0);
435 stripN2 = 2*addr + (isSecondRow ? 1 : 0);
439 stripN3 = 2*addr + (isSecondRow ? 1 : 0);
442 ATH_MSG_DEBUG(
"Consecutive strips: " << (uint32_t)stripN1 <<
" " << (uint32_t)stripN2 <<
" " << (uint32_t)stripN3);
443 const std::array<bool, 4> hits_n = {true ,
static_cast<bool>(firsthit),
444 static_cast<bool>(secondhit),
445 static_cast<bool>(thirdhit)};
448 for (
int i = 0; i < 4; i++){
452 data.strip = nchip * 128 + (address + i);
454 ATH_MSG_DEBUG(
"abcclusters " << (uint32_t)nchip <<
" " << (uint32_t)data.strip);
458 const int rdoMade =
makeRDO(data, cache, dataItemsPool);
463 data.setSaved(rdoMade);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
InDetRawDataCollection< SCT_RDORawData > SCT_RDO_Collection
InDetRawDataContainer< InDetRawDataCollection< SCT_RDORawData > > SCT_RDO_Container
a typed memory pool that saves time spent allocation small object.
pointer nextElementPtr()
obtain the next available element in pool by pointer pool is resized if its limit has been reached On...
value_type push_back(value_type pElem)
IDC like storage for BS errors, TODO, customise implementation further so that we store int rather th...
StatusCode addSingleError(const IdentifierHash &hashID, SCT_ByteStreamErrors::ErrorType error, SCT_RodDecoderErrorsHelper &errs) const
Add single eror.
std::atomic_uint m_headNumber
Total number of decoded header data.
int makeRDO(SharedData &data, CacheHelper &cache, DataPool< SCT3_RawData > *dataItemsPool) const
Builds RawData RDO and adds to RDO container.
StatusCode processHeader(const uint16_t inData, const uint32_t robID, SharedData &data, SCT_RDO_Container &rdoIDCont, DataPool< SCT3_RawData > *dataItemsPool, CacheHelper &cache, SCT_RodDecoderErrorsHelper &errs, bool &hasError, bool &breakNow, const EventContext &ctx) const
Process header word.
StatusCode processHits(const uint16_t inData, const uint32_t robID, SharedData &data, SCT_RDO_Container &rdoIDCont, DataPool< SCT3_RawData > *dataItemsPool, CacheHelper &cache, SCT_RodDecoderErrorsHelper &errs, bool &hasError, const EventContext &ctx) const
Process raw data word.
virtual StatusCode initialize() override
Initialize.
std::atomic_uint m_nRDOs
Total number of SCT RDOs created.
ToolHandle< IITkStripCablingTool > m_cabling
Providing mappings of online and offline identifiers and also serial numbers.
const SCT_ID * m_itkStripsID
Identifier helper class for the SCT subdetector that creates compact Identifier objects and Identifie...
StatusCode processHccHeader(const uint16_t inData, const uint8_t data8, uint8_t &isHCCHeader, const uint32_t robID, SharedData &data, SCT_RDO_Container &rdoIDCont, DataPool< SCT3_RawData > *dataItemsPool, CacheHelper &cache, SCT_RodDecoderErrorsHelper &errs, bool &hasError, bool &breakNow, const EventContext &ctx) const
Process header word.
virtual StatusCode fillCollection(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment &robFrag, SCT_RDO_Container &rdoIDCont, IDCInDetBSErrContainer &errs, DataPool< SCT3_RawData > *dataItemsPool, const EventContext &ctx, const std::vector< IdentifierHash > *vecHash=nullptr) const override
Fill SCT RDO Collection with decoded ROB data.
IdContext m_contextITk
"Context" of an expanded identifier (ExpandedIdentifier) for compact or hash versions (Identifier32 o...
std::vector< bool > m_swapPhiReadoutDirection
Swap phi readout direction.
StatusCode addRODError(uint32_t rodID, SCT_ByteStreamErrors::ErrorType error, SCT_RodDecoderErrorsHelper &errs, const std::unordered_set< IdentifierHash > *foundHashes=nullptr) const
Add an error for each wafer in the problematic ROD.
This is a "hash" representation of an Identifier.
Dedicated detector manager extending the functionality of the SiDetectorManager with dedicated SCT in...
virtual const SiDetectorElementCollection * getDetectorElementCollection() const override
access to whole collectiom
Class to hold the SiDetectorElement objects to be put in the detector store.
Class to hold geometrical description of a silicon detector element.
allows to accumulate errors in one fillColection call
void removeIfEmpty(const IdentifierHash id)
std::string find(const std::string &s)
return a remapped string
const DataType * PointerType
eformat::ROBFragment< PointerType > ROBFragment
ErrorType
SCT byte stream error type enums used in SCT_RodDecoder, SCT_ByteStreamErrorsTool,...
Temp object to help with trigger caching.
Struct to hold data shared in methods used in fillCollection method.