ATLAS Offline Software
Loading...
Searching...
No Matches
MM_RawDataProviderToolCore.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5
8#include <atomic>
9#include <memory> //for unique_ptr
10#include <unordered_map>
11
13
14//================ Constructor =================================================
15Muon::MM_RawDataProviderToolCore::MM_RawDataProviderToolCore(const std::string& t, const std::string& n, const IInterface* p)
16: AthAlgTool(t, n, p)
17, m_robDataProvider("ROBDataProviderSvc",n)
18{ }
19
20//================ Initialisation ==============================================
21StatusCode
23{
24 ATH_CHECK(AthAlgTool::initialize());
25 ATH_CHECK(m_idHelperSvc.retrieve());
26 ATH_CHECK(m_decoder.retrieve());
27 ATH_CHECK(m_robDataProvider.retrieve());
28 ATH_CHECK(m_rdoContainerKey.initialize());
29
30 m_maxhashtoUse = m_idHelperSvc->mmIdHelper().module_hash_max();
31
32 return StatusCode::SUCCESS;
33}
34
35//==============================================================================
36StatusCode
37Muon::MM_RawDataProviderToolCore::convertIntoContainer(const EventContext& ctx, const std::vector<const ROBFragment*>& vecRobs, const std::vector<IdentifierHash>& rdoIdhVect, MM_RawDataContainer& mmRdoContainer) const
38{
39 // Since there can be multiple ROBFragments contributing to the same RDO collection a temporary cache is setup and passed to fillCollection by reference. Once all ROBFragments are processed the collections are added into the rdo container
40
41
42 std::unordered_map<IdentifierHash, std::unique_ptr<MM_RawDataCollection>> rdo_map;
43
44
45 // Loop on the passed ROB fragments, and call the decoder for each one to fill the RDO container.
46 for (const ROBFragment* fragment : vecRobs)
47 ATH_CHECK( m_decoder->fillCollection(ctx, *fragment, rdoIdhVect, rdo_map) ); // always returns StatusCode::SUCCESS
48
49 // error counters
50 int nerr_duplicate{0}, nerr_rdo{0};
51
52 // add the RDO collections created from the data of this ROB into the identifiable container.
53 for (auto& [hash, collection]: rdo_map) {
54
55 if ((!collection) or collection->empty()) continue; // skip empty collections
56
57 MM_RawDataContainer::IDC_WriteHandle lock = mmRdoContainer.getWriteHandle(hash);
58
59 if (lock.alreadyPresent()) {
60 ++nerr_duplicate;
61 } else if (!lock.addOrDelete(std::move(collection)).isSuccess()) {
62 // since we prevent duplicates above, this error should never happen.
63 ++nerr_rdo;
64 }
65 }
66
67
68 // error summary (to reduce the number of messages)
69 if (nerr_duplicate) ATH_MSG_WARNING(nerr_duplicate << " elinks skipped since the same module hash has been added by a previous ROB fragment");
70 if (nerr_rdo){
71 ATH_MSG_ERROR("Failed to add "<<nerr_rdo<<" RDOs into the identifiable container");
72 return StatusCode::FAILURE;
73 }
74
75 ATH_MSG_DEBUG("Size of mmRdoContainer is " << mmRdoContainer.size());
76 return StatusCode::SUCCESS;
77}
78
#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)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
StatusCode addOrDelete(std::unique_ptr< T > ptr)
IDC_WriteHandle getWriteHandle(IdentifierHash hash)
size_t size() const
Duplicate of fullSize for backwards compatability.
virtual StatusCode initialize() override
Standard AlgTool method.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
The ID helper.
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Rob Data Provider handle.
virtual StatusCode convertIntoContainer(const EventContext &ctx, const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &, const std::vector< IdentifierHash > &, MM_RawDataContainer &) const
Method that converts the ROBFragments into the passed container.
ToolHandle< IMM_ROD_Decoder > m_decoder
Decoder for ROB fragment RDO conversion.
MM_RawDataProviderToolCore(const std::string &t, const std::string &n, const IInterface *p)
Default constructor.
SG::WriteHandleKey< MM_RawDataContainer > m_rdoContainerKey
RDO container key.
eformat::ROBFragment< PointerType > ROBFragment
Definition RawEvent.h:27