ATLAS Offline Software
STGC_RdoToDigit.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "STGC_RdoToDigit.h"
6 
7 STGC_RdoToDigit::STGC_RdoToDigit(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
8 
10  ATH_CHECK(m_idHelperSvc.retrieve());
11  ATH_CHECK(m_stgcRdoDecoderTool.retrieve());
14  return StatusCode::SUCCESS;
15 }
16 
17 StatusCode STGC_RdoToDigit::execute(const EventContext& ctx) const {
18  ATH_MSG_DEBUG("in execute()");
20  if (!rdoRH.isValid()) {
21  ATH_MSG_ERROR("No STGC RDO container found!");
22  return StatusCode::FAILURE;
23  }
24  const Muon::STGC_RawDataContainer* rdoContainer = rdoRH.cptr();
25  ATH_MSG_DEBUG("Retrieved " << rdoContainer->size() << " sTGC RDOs.");
26 
28  ATH_CHECK(wh_stgcDigit.record(std::make_unique<sTgcDigitContainer>(m_idHelperSvc->stgcIdHelper().detectorElement_hash_max())));
29  ATH_MSG_DEBUG("Decoding sTGC RDO into sTGC Digit");
30 
31  // retrieve the collection of RDO
32  Identifier oldId;
33  sTgcDigitCollection* collection = nullptr;
34  // now decode RDO into digits
35  for (const Muon::STGC_RawDataCollection* coll : *rdoContainer) {
36  ATH_CHECK(this->decodeSTGC(coll, wh_stgcDigit.ptr(), collection, oldId));
37  }
38 
39  return StatusCode::SUCCESS;
40 }
41 
43  sTgcDigitCollection*& collection, Identifier& oldId) const {
44  const IdContext stgcContext = m_idHelperSvc->stgcIdHelper().module_context();
45 
46  if (!rdoColl->empty()) {
47  ATH_MSG_DEBUG(" Number of RawData in this rdo " << rdoColl->size());
48 
49  // for each RDO, loop over RawData, converter RawData to digit
50  // retrieve/create digit collection, and insert digit into collection
51  for (const Muon::STGC_RawData* data : *rdoColl) {
52  sTgcDigit* newDigit = m_stgcRdoDecoderTool->getDigit(data);
53  if (!newDigit) {
54  ATH_MSG_ERROR("Error in sTGC RDO decoder");
55  continue;
56  }
57 
58  uint16_t relBcid = newDigit->bcTag();
59  uint16_t bcTag = 0;
60  // Triggering bunch crossing is set to relative_BCID = 3
61  if (relBcid == 3)
62  bcTag = 0;
63  else if (relBcid < 3)
64  bcTag = ~(3 - relBcid);
65  else if (relBcid > 3)
66  bcTag = (relBcid - 3);
67  newDigit->set_bcTag(bcTag);
68 
69  // find here the Proper Digit Collection identifier, using the rdo-hit id
70  // (since RDO collections are not in a 1-to-1 relation with digit collections)
71  const Identifier elementId = m_idHelperSvc->stgcIdHelper().elementID(newDigit->identify());
72  IdentifierHash coll_hash;
73  if (m_idHelperSvc->stgcIdHelper().get_hash(elementId, coll_hash, &stgcContext)) {
74  ATH_MSG_WARNING("Unable to get STGC digit collection hash id "
75  << "context begin_index = " << stgcContext.begin_index()
76  << " context end_index = " << stgcContext.end_index() << " the identifier is ");
77  elementId.show();
78  }
79 
80  if (oldId != elementId) {
81  const sTgcDigitCollection* coll = stgcContainer->indexFindPtr(coll_hash);
82  if (nullptr == coll) {
83  sTgcDigitCollection* newCollection = new sTgcDigitCollection(elementId, coll_hash);
84  newCollection->push_back(newDigit);
85  collection = newCollection;
86  if (stgcContainer->addCollection(newCollection, coll_hash).isFailure())
87  ATH_MSG_WARNING("Couldn't record sTgcDigitCollection with key=" << coll_hash << " in StoreGate!");
88  } else {
89  sTgcDigitCollection* oldCollection ATLAS_THREAD_SAFE = const_cast<sTgcDigitCollection*>(coll); // FIXME
90  oldCollection->push_back(newDigit);
91  collection = oldCollection;
92  }
93  oldId = elementId;
94  } else {
95  collection->push_back(newDigit);
96  }
97  }
98  }
99  return StatusCode::SUCCESS;
100 }
sTgcDigitContainer
Use IdentifiableContainer with sTgcDigitCollection.
Definition: sTgcDigitContainer.h:50
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
STGC_RdoToDigit::STGC_RdoToDigit
STGC_RdoToDigit(const std::string &name, ISvcLocator *pSvcLocator)
Definition: STGC_RdoToDigit.cxx:7
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:9
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
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
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
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:76
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
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:17
STGC_RdoToDigit::decodeSTGC
StatusCode decodeSTGC(const Muon::STGC_RawDataCollection *, sTgcDigitContainer *, sTgcDigitCollection *&, Identifier &) const
Definition: STGC_RdoToDigit.cxx:42
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