ATLAS Offline Software
Loading...
Searching...
No Matches
TgcPrepDataReplicationTool3BCtoAllBC.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
8
11
12//================ Constructor =================================================
14 (const std::string& t, const std::string& n, const IInterface* p)
15 : base_class(t, n, p) {}
16
17//================ Initialization ==============================================
19{
20 ATH_CHECK(AthAlgTool::initialize());
21 ATH_CHECK(m_idHelperSvc.retrieve());
22
23 for(int ibc = 0; ibc < BC_ALL; ibc++) {
24 std::ostringstream location;
25 location << "TGC_Measurements"
26 << (ibc == BC_PREVIOUS ? "PriorBC" : "")
27 << (ibc == BC_NEXT ? "NextBC" : "");
28 m_3BCKeys.at(ibc) = location.str();
29 }
30
31 ATH_CHECK(m_3BCKeys.initialize());
32
33
34 return StatusCode::SUCCESS;
35}
36
37StatusCode Muon::TgcPrepDataReplicationTool3BCtoAllBC::replicate(const EventContext& ctx) const
38{
39 return convert3BCtoAllBC(ctx);
40}
41
42StatusCode Muon::TgcPrepDataReplicationTool3BCtoAllBC::convert3BCtoAllBC(const EventContext& ctx) const {
43
44 SG::WriteHandle<TgcPrepDataContainer> tgcPrepDataContainerAll(m_AllBCKey, ctx);
45 ATH_CHECK(tgcPrepDataContainerAll.record(std::make_unique<TgcPrepDataContainer>(m_idHelperSvc->tgcIdHelper().module_hash_max()) ));
46
47 auto tgc3BCs = m_3BCKeys.makeHandles(ctx);
48
49 // convert
50 int ibc{0};
51 for (SG::ReadHandle<TgcPrepDataContainer>& handle : m_3BCKeys.makeHandles(ctx)) {
52 uint16_t bcBitMap = 0;
53 if (ibc == BC_PREVIOUS) bcBitMap = TgcPrepData::BCBIT_PREVIOUS;
54 else if (ibc == BC_CURRENT) bcBitMap = TgcPrepData::BCBIT_CURRENT;
55 else if (ibc == BC_NEXT) bcBitMap = TgcPrepData::BCBIT_NEXT;
56 ++ibc;
57
58 if(!handle.isValid()) {
59 ATH_MSG_FATAL("Cannot retrieve " << handle.key());
60 return StatusCode::FAILURE;
61 }
62 for (const Muon::TgcPrepDataCollection* coll : *handle) {
63
64 for (const Muon::TgcPrepData* to_copy : *coll) {
65 const Identifier channelId = to_copy->identify();
66 const Identifier elementId = m_idHelperSvc->tgcIdHelper().elementID(channelId);
67
68 Muon::TgcPrepDataCollection* collection = Muon::IDC_Helper::getCollection<TgcPrepDataContainer, TgcIdHelper>
69 (elementId, tgcPrepDataContainerAll.ptr(), m_idHelperSvc->tgcIdHelper(), msg());
70
71 Muon::TgcPrepDataCollection::iterator duplicateInAllBCs =
72 std::find_if(collection->begin(),collection->end(),[&channelId](const TgcPrepData* duplicate){
73 return channelId == duplicate->identify();
74 });
75 if(duplicateInAllBCs != collection->end()) {
76 TgcPrepData *prd = *duplicateInAllBCs;
77 prd->setBcBitMap(prd->getBcBitMap() | bcBitMap);
78 } else {
80 newPrepData->setHashAndIndex(collection->identifyHash(), collection->size());
81 collection->push_back(newPrepData);
82 }
83 }
84 }
85 }
86
87 return StatusCode::SUCCESS;
88}
89
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
value_type push_back(value_type pElem)
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
const_iterator end() const noexcept
const_iterator begin() const noexcept
size_type size() const noexcept
virtual IdentifierHash identifyHash() const override final
virtual StatusCode replicate(const EventContext &ctx) const override
TgcPrepDataReplicationTool3BCtoAllBC(const std::string &t, const std::string &n, const IInterface *p)
Constructor.
StatusCode convert3BCtoAllBC(const EventContext &ctx) const
SG::WriteHandleKey< TgcPrepDataContainer > m_AllBCKey
SG::ReadHandleKeyArray< TgcPrepDataContainer > m_3BCKeys
static TgcPrepData * makeTgcPrepData(const TgcPrepData *to_copy, uint16_t bcBitMap)
Make new TgcPrepData.
Class to represent TGC measurements.
Definition TgcPrepData.h:32
void setBcBitMap(const uint16_t)
set the bcBitMap for this PRD
uint16_t getBcBitMap() const
Returns the bcBitMap of this PRD bit2 for Previous BC, bit1 for Current BC, bit0 for Next BC.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
void setHashAndIndex(unsigned short collHash, unsigned short objIndex)
TEMP for testing: might make some classes friends later ...
MuonPrepDataCollection< TgcPrepData > TgcPrepDataCollection
MsgStream & msg
Definition testRead.cxx:32