ATLAS Offline Software
STGC_RdoToDigit.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "STGC_RdoToDigit.h"
6 
7 
9  ATH_CHECK(m_idHelperSvc.retrieve());
10  ATH_CHECK(m_stgcRdoDecoderTool.retrieve());
13  return StatusCode::SUCCESS;
14 }
15 
16 StatusCode STGC_RdoToDigit::execute(const EventContext& ctx) const {
17  ATH_MSG_DEBUG("in execute()");
19  if (!rdoRH.isValid()) {
20  ATH_MSG_ERROR("No STGC RDO container found!");
21  return StatusCode::FAILURE;
22  }
23  const Muon::STGC_RawDataContainer* rdoContainer = rdoRH.cptr();
24  ATH_MSG_DEBUG("Retrieved " << rdoContainer->size() << " sTGC RDOs.");
25 
27  ATH_CHECK(wh_stgcDigit.record(std::make_unique<sTgcDigitContainer>(m_idHelperSvc->stgcIdHelper().detectorElement_hash_max())));
28  ATH_MSG_DEBUG("Decoding sTGC RDO into sTGC Digit");
29 
30  // retrieve the collection of RDO
31  Identifier oldId;
32  sTgcDigitCollection* collection = nullptr;
33  // now decode RDO into digits
34  for (const Muon::STGC_RawDataCollection* coll : *rdoContainer) {
35  ATH_CHECK(this->decodeSTGC(ctx, coll, wh_stgcDigit.ptr(), collection, oldId));
36  }
37 
38  return StatusCode::SUCCESS;
39 }
40 
41 StatusCode STGC_RdoToDigit::decodeSTGC(const EventContext& ctx, const Muon::STGC_RawDataCollection* rdoColl, sTgcDigitContainer* stgcContainer,
42  sTgcDigitCollection*& collection, Identifier& oldId) const {
43  const IdContext stgcContext = m_idHelperSvc->stgcIdHelper().module_context();
44 
45  if (!rdoColl->empty()) {
46  ATH_MSG_DEBUG(" Number of RawData in this rdo " << rdoColl->size());
47 
48  // for each RDO, loop over RawData, converter RawData to digit
49  // retrieve/create digit collection, and insert digit into collection
50  for (const Muon::STGC_RawData* data : *rdoColl) {
51  sTgcDigit* newDigit = m_stgcRdoDecoderTool->getDigit(ctx, data);
52  if (!newDigit) {
53  ATH_MSG_ERROR("Error in sTGC RDO decoder");
54  continue;
55  }
56 
57  uint16_t relBcid = newDigit->bcTag();
58  uint16_t bcTag = 0;
59  // Triggering bunch crossing is set to relative_BCID = 3
60  if (relBcid == 3)
61  bcTag = 0;
62  else if (relBcid < 3)
63  bcTag = ~(3 - relBcid);
64  else if (relBcid > 3)
65  bcTag = (relBcid - 3);
66  newDigit->set_bcTag(bcTag);
67 
68  // find here the Proper Digit Collection identifier, using the rdo-hit id
69  // (since RDO collections are not in a 1-to-1 relation with digit collections)
70  const Identifier elementId = m_idHelperSvc->stgcIdHelper().elementID(newDigit->identify());
71  IdentifierHash coll_hash;
72  if (m_idHelperSvc->stgcIdHelper().get_hash(elementId, coll_hash, &stgcContext)) {
73  ATH_MSG_WARNING("Unable to get STGC digit collection hash id "
74  << "context begin_index = " << stgcContext.begin_index()
75  << " context end_index = " << stgcContext.end_index() << " the identifier is ");
76  elementId.show();
77  }
78 
79  if (oldId != elementId) {
80  const sTgcDigitCollection* coll = stgcContainer->indexFindPtr(coll_hash);
81  if (nullptr == coll) {
82  sTgcDigitCollection* newCollection = new sTgcDigitCollection(elementId, coll_hash);
83  newCollection->push_back(newDigit);
84  collection = newCollection;
85  if (stgcContainer->addCollection(newCollection, coll_hash).isFailure())
86  ATH_MSG_WARNING("Couldn't record sTgcDigitCollection with key=" << coll_hash << " in StoreGate!");
87  } else {
88  sTgcDigitCollection* oldCollection ATLAS_THREAD_SAFE = const_cast<sTgcDigitCollection*>(coll); // FIXME
89  oldCollection->push_back(newDigit);
90  collection = oldCollection;
91  }
92  oldId = elementId;
93  } else {
94  collection->push_back(newDigit);
95  }
96  }
97  }
98  return StatusCode::SUCCESS;
99 }
sTgcDigitContainer
Use IdentifiableContainer with sTgcDigitCollection.
Definition: sTgcDigitContainer.h:50
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
sTgcDigit::set_bcTag
void set_bcTag(uint16_t newbcTag)
Definition: sTgcDigit.cxx:66
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
IdentifiableContainerMT::addCollection
virtual StatusCode addCollection(const T *coll, IdentifierHash hashId) override final
insert collection into container with id hash if IDC should not take ownership of collection,...
Definition: IdentifiableContainerMT.h:297
STGC_RdoToDigit::initialize
virtual StatusCode initialize() override final
Definition: STGC_RdoToDigit.cxx:8
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:67
IdContext::end_index
size_type end_index() const
Definition: IdContext.h:46
IdentifiableContainerMT::size
size_t size() const
Duplicate of fullSize for backwards compatability.
Definition: IdentifiableContainerMT.h:206
Muon::STGC_RawDataContainer
Definition: STGC_RawDataContainer.h:18
sTgcDigit::bcTag
uint16_t bcTag() const
Definition: sTgcDigit.cxx:34
STGC_RdoToDigit.h
sTgcDigit
Definition: sTgcDigit.h:20
IdContext::begin_index
size_type begin_index() const
Definition: IdContext.h:45
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
Muon::STGC_RawData
Definition: STGC_RawData.h:14
sTgcDigitCollection
Definition: sTgcDigitCollection.h:18
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
Identifier::show
void show() const
Print out in hex form.
Definition: Identifier.cxx:30
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
STGC_RdoToDigit::m_stgcDigitKey
SG::WriteHandleKey< sTgcDigitContainer > m_stgcDigitKey
Definition: STGC_RdoToDigit.h:29
STGC_RdoToDigit::m_stgcRdoKey
SG::ReadHandleKey< Muon::STGC_RawDataContainer > m_stgcRdoKey
Definition: STGC_RdoToDigit.h:28
STGC_RdoToDigit::m_stgcRdoDecoderTool
ToolHandle< Muon::ISTGC_RDO_Decoder > m_stgcRdoDecoderTool
Definition: STGC_RdoToDigit.h:26
STGC_RdoToDigit::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: STGC_RdoToDigit.h:27
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
IdentifiableContainerMT::indexFindPtr
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
Definition: IdentifiableContainerMT.h:289
MuonDigit::identify
Identifier identify() const
Definition: MuonDigit.h:30
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
bcTag
unsigned bcTag(unsigned bcBitMap)
Definition: TgcByteStreamData.h:359
Muon::STGC_RawDataCollection
Definition: STGC_RawDataCollection.h:18
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
STGC_RdoToDigit::decodeSTGC
StatusCode decodeSTGC(const EventContext &ctx, const Muon::STGC_RawDataCollection *, sTgcDigitContainer *, sTgcDigitCollection *&, Identifier &) const
Definition: STGC_RdoToDigit.cxx:41
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
STGC_RdoToDigit::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: STGC_RdoToDigit.cxx:16
IdContext
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition: IdContext.h:26
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
Identifier
Definition: IdentifierFieldParser.cxx:14