ATLAS Offline Software
Loading...
Searching...
No Matches
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());
11 ATH_CHECK(m_stgcRdoKey.initialize());
12 ATH_CHECK(m_stgcDigitKey.initialize());
13 return StatusCode::SUCCESS;
14}
15
16StatusCode 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
41StatusCode 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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
unsigned bcTag(unsigned bcBitMap)
#define ATLAS_THREAD_SAFE
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
size_type begin_index() const
Definition IdContext.h:45
size_type end_index() const
Definition IdContext.h:46
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,...
size_t size() const
Duplicate of fullSize for backwards compatability.
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,...
This is a "hash" representation of an Identifier.
void show() const
Print out in hex form.
Identifier identify() const
Definition MuonDigit.h:30
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
virtual StatusCode initialize() override final
StatusCode decodeSTGC(const EventContext &ctx, const Muon::STGC_RawDataCollection *, sTgcDigitContainer *, sTgcDigitCollection *&, Identifier &) const
virtual StatusCode execute(const EventContext &ctx) const override final
ToolHandle< Muon::ISTGC_RDO_Decoder > m_stgcRdoDecoderTool
SG::WriteHandleKey< sTgcDigitContainer > m_stgcDigitKey
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::ReadHandleKey< Muon::STGC_RawDataContainer > m_stgcRdoKey
Use IdentifiableContainer with sTgcDigitCollection.
void set_bcTag(uint16_t newbcTag)
Definition sTgcDigit.cxx:66
uint16_t bcTag() const
Definition sTgcDigit.cxx:34