ATLAS Offline Software
Loading...
Searching...
No Matches
TGC_RawDataProviderTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9//================ Initialisation =================================================
10namespace Muon{
12 ATH_CHECK(m_idHelperSvc.retrieve());
13
14 ATH_CHECK(m_decoder.retrieve());
15 ATH_MSG_DEBUG( "Retrieved tool " << m_decoder );
16
17 // Get ROBDataProviderSvc
18 ATH_CHECK(m_robDataProvider.retrieve());
19 ATH_MSG_DEBUG( "Retrieved service " << m_robDataProvider );
20
21 m_maxhashtoUse = m_idHelperSvc->tgcIdHelper().module_hash_max();
22
23 ATH_CHECK(m_rdoContainerKey.initialize());
24
25 //try to configure the cabling service
26 if (!getCabling()) {
27 // ??? Is deferred initialization still needed here?
28 ATH_MSG_INFO( "TGCCablingServerSvc not yet configured; postpone TGCcabling initialization at first event. " );
29 }
30
31 m_hid2re.fillAllRobIds();
32 // Initialise the container cache if available
33 ATH_CHECK( m_rdoContainerCacheKey.initialize( !m_rdoContainerCacheKey.key().empty() ) );
34
35 ATH_MSG_INFO( "initialize() successful in " << name() );
36 return StatusCode::SUCCESS;
37}
38
39StatusCode TGC_RawDataProviderTool::convertIntoContainer(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vecRobs, TgcRdoContainer& tgcRdoContainer) const
40{
41
43 static thread_local int DecodeErrCount = 0;
44
45 // Update to range based loop
46 for(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment* fragment : vecRobs){
47 if(m_decoder->fillCollection(*fragment, tgcRdoContainer).isFailure()) {
48 if(DecodeErrCount < 100) {
49 ATH_MSG_INFO( "Problem with TGC ByteStream Decoding!" );
50 DecodeErrCount++;
51 }
52 else if(100 == DecodeErrCount) {
53 ATH_MSG_INFO( "Too many Problems with TGC Decoding messages. Turning message off." );
54 DecodeErrCount++;
55 }
56 }
57 }
58 ATH_MSG_DEBUG("Size of TgcRdoContainer is " << tgcRdoContainer.size());
59 return StatusCode::SUCCESS;
60}
61
63{
64 const MuonTGC_CablingSvc* cabling = m_cabling.get();
65 if (cabling) {
66 return cabling;
67 }
68
69 ServiceHandle<MuonTGC_CablingSvc> TgcCabGet("MuonTGC_CablingSvc", name());
70 if (TgcCabGet.retrieve().isFailure()) {
71 ATH_MSG_FATAL( "Could not get MuonTGC_CablingSvc !" );
72 return nullptr;
73 }
74
75 m_cabling.set(TgcCabGet.get());
76
77 return m_cabling.get();
78}
79
80
81std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> TGC_RawDataProviderTool::getROBData(const std::vector<IdentifierHash>& rdoIdhVect, const EventContext& ctx) const
82{
83 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> vecOfRobf;
84 const MuonTGC_CablingSvc* cabling = getCabling();
85 if(!cabling) {
86 ATH_MSG_ERROR("Could not get cabling, return empty vector of ROB fragments");
87 return vecOfRobf;
88 }
89
90 IdContext tgcContext = m_idHelperSvc->tgcIdHelper().module_context();
91
92 std::vector<uint32_t> robIds;
93
94 unsigned int size = rdoIdhVect.size();
95 for(unsigned int i=0; i<size; ++i) {
96 Identifier Id;
97 if(m_idHelperSvc->tgcIdHelper().get_id(rdoIdhVect[i], Id, &tgcContext)) {
98 ATH_MSG_WARNING( "Unable to get TGC Identifier from collection hash id " );
99 continue;
100 }
101 const Identifier tgcId = Id;
102 uint32_t rodId = m_hid2re.getRodID(tgcId, cabling);
103 uint32_t robId = m_hid2re.getRobID(rodId);
104 std::vector<uint32_t>::iterator it_robId = std::find(robIds.begin(), robIds.end(), robId);
105 if(it_robId==robIds.end()) {
106 robIds.push_back(robId);
107 }
108 }
109 m_robDataProvider->getROBData(ctx, robIds, vecOfRobf);
110 ATH_MSG_VERBOSE( "Number of ROB fragments " << vecOfRobf.size() );
111 return vecOfRobf;
112}
113
114
115//============================================================================================
116
117StatusCode TGC_RawDataProviderTool::convert(const ROBFragmentList& vecRobs) const {
118 return convert( vecRobs, Gaudi::Hive::currentContext() );
119}
120
121
122StatusCode TGC_RawDataProviderTool::convert(const ROBFragmentList& vecRobs, const EventContext& ctx) const
123{
124
125 SG::WriteHandle<TgcRdoContainer> rdoContainerHandle(m_rdoContainerKey, ctx);
126
127 // Split the methods to have one where we use the cache and one where we just setup the container
128 const bool externalCacheRDO = !m_rdoContainerCacheKey.key().empty();
129 if(!externalCacheRDO){
130 ATH_CHECK( rdoContainerHandle.record( std::make_unique<TgcRdoContainer> (m_maxhashtoUse) ) );
131 ATH_MSG_DEBUG( "Created TGC container" );
132 }
133 else{
135 ATH_CHECK(update.isValid());
136 ATH_CHECK(rdoContainerHandle.record (std::make_unique<TgcRdoContainer>( update.ptr() )));
137 ATH_MSG_DEBUG("Created container using cache for " << m_rdoContainerCacheKey.key());
138 }
139
140 TgcRdoContainer* rdoContainer = rdoContainerHandle.ptr();
141
142 // this should never happen, but since we dereference the pointer, we should check
143 if(!rdoContainer) {
144 ATH_MSG_ERROR("TGC RDO Container is null, cannot decode TGC data");
145 return StatusCode::FAILURE;
146 }
147
148 return convertIntoContainer(vecRobs, *rdoContainer);
149}
150
151StatusCode TGC_RawDataProviderTool::convert(const ROBFragmentList& vecRobs, const std::vector<IdentifierHash>&) const {
152 // This function does not use the IdentifierHash so we pass to the EventContext function which also does not use it
153 return convert( vecRobs, Gaudi::Hive::currentContext() );
154}
155
156StatusCode TGC_RawDataProviderTool::convert(const ROBFragmentList& vecRobs, const std::vector<IdentifierHash>& /*ids*/, const EventContext& ctx) const
157{
158 return convert(vecRobs, ctx);
159}
160
162 return convert( Gaudi::Hive::currentContext() );
163}
164
165StatusCode TGC_RawDataProviderTool::convert(const EventContext& ctx) const
166{
167 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> vecOfRobf;
168 const std::vector<uint32_t>& robIds = m_hid2re.allRobIds();
169
170 m_robDataProvider->getROBData(ctx, robIds, vecOfRobf);
171
172 return convert(vecOfRobf, ctx);
173}
174
175StatusCode TGC_RawDataProviderTool::convert(const std::vector<IdentifierHash>& rdoIdhVect) const {
176 return convert( rdoIdhVect, Gaudi::Hive::currentContext() );
177}
178
179StatusCode TGC_RawDataProviderTool::convert(const std::vector<IdentifierHash>& rdoIdhVect, const EventContext& ctx) const
180{
181 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> vecOfRobf = getROBData(rdoIdhVect, ctx);
182
183 return convert(vecOfRobf, rdoIdhVect, ctx);
184}
185
186}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
size_t size() const
Duplicate of fullSize for backwards compatability.
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Rob Data Provider handle.
virtual StatusCode convert() const override
New decoding methods which do not use IROBDataProviderSvc in TgcRdoToPrepDataTool.
ToolHandle< ITGC_RodDecoder > m_decoder
Decoder for ROB fragment RDO conversion.
CxxUtils::CachedPointer< const MuonTGC_CablingSvc > m_cabling
TGC cabling Svc.
SG::WriteHandleKey< TgcRdoContainer > m_rdoContainerKey
RDO container key.
SG::UpdateHandleKey< TgcRdo_Cache > m_rdoContainerCacheKey
std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > getROBData(const std::vector< IdentifierHash > &rdoIdhVect, const EventContext &ctx) const
Function to get the ROB data from a vector of IdentifierHash.
const MuonTGC_CablingSvc * getCabling() const
TGC_Hid2RESrcID m_hid2re
ID converter.
virtual StatusCode initialize() override
Standard AlgTool method.
StatusCode convertIntoContainer(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vecRobs, TgcRdoContainer &tgcRdoContainer) const
Method that converts the ROBFragments into the passed container.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
eformat::ROBFragment< PointerType > ROBFragment
Definition RawEvent.h:27