ATLAS Offline Software
Loading...
Searching...
No Matches
CollectionMerger.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ISF_ALGS_COLLECTIONMERGER_H
6#define ISF_ALGS_COLLECTIONMERGER_H 1
7
8// STL includes
9#include <string>
10#include <type_traits>
11
12// base class header
14
15// Framework includes
18
19// ATLAS C++
20
21// SimHit EDM includes
22// InnerDetector
25// Calorimeter
28// Muon Spectrometer
35
36// forward declarations
37namespace ISFTesting {
38 class CollectionMerger_test;
39}
40
41
42namespace ISF {
43
52
55
56 public:
58 CollectionMerger( const std::string& name, ISvcLocator* pSvcLocator );
59
61 virtual ~CollectionMerger() = default;
62
64 virtual StatusCode initialize() override final;
65 virtual StatusCode execute(const EventContext& ctx) const override final;
66
67 private:
69 template <typename T>
70 StatusCode mergeCollections( const SG::ReadHandleKeyArray<T>& inputReadHandleKeys,
71 const SG::WriteHandleKey<T>& outputWriteHandleKey,
72 const EventContext& ctx ) const;
73
75 template <typename HitType_t, typename OutputType_t>
76 void insertCopy(const HitType_t& hit, OutputType_t& outputHandle) const;
77
80 template <typename HitType_t, typename OutputType_t>
81 void insertCopy(HitType_t * const hit, OutputType_t& outputHandle) const;
82
84 SG::ReadHandleKeyArray<SiHitCollection> m_inputBCMHits{this, "InputBCMHits", {}, ""};
89
94
99
102
109
116
121
126
129
136 };
137
138
139//
140// templated methods below
141//
142
144template <typename T>
145inline StatusCode ISF::CollectionMerger::mergeCollections( const SG::ReadHandleKeyArray<T>& inputReadHandleKeys,
146 const SG::WriteHandleKey<T>& outputWriteHandleKey,
147 const EventContext& ctx ) const {
148 // skip if not input collection
149 if ( inputReadHandleKeys.empty() ) {
150 return StatusCode::SUCCESS;
151 }
152 // TODO: is there a way to conveniently get the total number of hits in all inputReadHandleKeys
153 // and reserve the corresponding size in the outputHandle
154 ATH_MSG_VERBOSE("Create new output container "<<outputWriteHandleKey.fullKey());
155 SG::WriteHandle<T> outputHandle{outputWriteHandleKey, ctx};
156 ATH_CHECK( outputHandle.record(std::make_unique<T>()) );
157
158 for ( const auto& collKey: inputReadHandleKeys ) {
159 ATH_MSG_VERBOSE("Read-in collection "<<collKey.fullKey());
160 SG::ReadHandle<T> inputHandle{collKey, ctx};
161
162 for ( const auto& hit: *inputHandle ) {
163 this->insertCopy(hit, outputHandle);
164 }
165 }
166
167 return StatusCode::SUCCESS;
168}
169
170
172template <typename HitType_t, typename OutputType_t>
173inline void ISF::CollectionMerger::insertCopy(const HitType_t& hit,
174 OutputType_t& outputHandle) const {
175 static_assert(!std::is_pointer<HitType_t>::value,
176 "The hit provided to ISF::CollectionMerger::insertCopy(..) must not be a pointer!");
177 outputHandle->Emplace( hit );
178}
179
180
182template <typename HitType_t, typename OutputType_t>
183inline void ISF::CollectionMerger::insertCopy(HitType_t * const hit,
184 OutputType_t& outputHandle) const {
185 auto&& hitCopy = std::make_unique<std::remove_const_t<HitType_t> >(*hit);
186 outputHandle->push_back( hitCopy.release() );
187}
188
189
190}
191
192#endif //> !ISF_ALGS_COLLECTIONMERGER_H
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
AtlasHitsVector< SiHit > SiHitCollection
Property holding a SG store/key/clid from which a WriteHandle is made.
An algorithm that can be simultaneously executed in multiple threads.
SG::WriteHandleKey< SiHitCollection > m_outputBLMHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputPixelHits
SG::WriteHandleKey< SiHitCollection > m_outputPixelHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputITkStripHits
void insertCopy(const HitType_t &hit, OutputType_t &outputHandle) const
Copy the given hit into the given output collection, container or DataHandle.
SG::WriteHandleKey< LArHitContainer > m_outputLArEMBHits
SG::WriteHandleKey< SiHitCollection > m_outputHGTDHits
CollectionMerger(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
SG::ReadHandleKeyArray< MDTSimHitCollection > m_inputMDTHits
SG::ReadHandleKeyArray< TGCSimHitCollection > m_inputTGCHits
SG::WriteHandleKey< MMSimHitCollection > m_outputMMHits
SG::ReadHandleKeyArray< LArHitContainer > m_inputLArEMECHits
virtual StatusCode initialize() override final
Athena algorithm's interface methods.
SG::ReadHandleKeyArray< SiHitCollection > m_inputSCTHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputBLMHits
SG::WriteHandleKey< sTGCSimHitCollection > m_outputsTGCHits
SG::ReadHandleKeyArray< MMSimHitCollection > m_inputMMHits
SG::ReadHandleKeyArray< LArHitContainer > m_inputLArEMBHits
SG::WriteHandleKey< TileHitVector > m_outputMBTSHits
SG::ReadHandleKeyArray< sTGCSimHitCollection > m_inputsTGCHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputHGTDHits
virtual StatusCode execute(const EventContext &ctx) const override final
Athena Algorithm execute.
SG::WriteHandleKey< LArHitContainer > m_outputLArHECHits
friend class ISFTesting::CollectionMerger_test
Allow the test class access to all methods.
SG::WriteHandleKey< RPCSimHitCollection > m_outputRPCHits
SG::WriteHandleKey< MDTSimHitCollection > m_outputMDTHits
SG::WriteHandleKey< TRTUncompressedHitCollection > m_outputTRTUncompressedHits
SG::ReadHandleKeyArray< TileHitVector > m_inputTileHits
virtual ~CollectionMerger()=default
Destructor.
SG::ReadHandleKeyArray< TRTUncompressedHitCollection > m_inputTRTUncompressedHits
SG::ReadHandleKeyArray< LArHitContainer > m_inputLArFCALHits
StatusCode mergeCollections(const SG::ReadHandleKeyArray< T > &inputReadHandleKeys, const SG::WriteHandleKey< T > &outputWriteHandleKey, const EventContext &ctx) const
Merge all hits of inputReadHandleKeys's collections into outputWriteHandleKey.
SG::WriteHandleKey< SiHitCollection > m_outputBCMHits
Output collection WriteHandleKeys.
SG::ReadHandleKeyArray< SiHitCollection > m_inputBCMHits
Input collection ReadHandleKeys.
SG::ReadHandleKeyArray< LArHitContainer > m_inputLArHECHits
SG::WriteHandleKey< LArHitContainer > m_outputLArEMECHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputPLRHits
SG::WriteHandleKey< SiHitCollection > m_outputITkPixelHits
SG::WriteHandleKey< SiHitCollection > m_outputPLRHits
SG::ReadHandleKeyArray< TileHitVector > m_inputMBTSHits
SG::ReadHandleKeyArray< RPCSimHitCollection > m_inputRPCHits
SG::WriteHandleKey< TGCSimHitCollection > m_outputTGCHits
SG::WriteHandleKey< SiHitCollection > m_outputITkStripHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputITkPixelHits
SG::WriteHandleKey< CSCSimHitCollection > m_outputCSCHits
SG::WriteHandleKey< TileHitVector > m_outputTileHits
SG::ReadHandleKeyArray< CSCSimHitCollection > m_inputCSCHits
SG::WriteHandleKey< LArHitContainer > m_outputLArFCALHits
SG::WriteHandleKey< SiHitCollection > m_outputSCTHits
Property holding a SG store/key/clid from which a WriteHandle is made.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Core Athena algorithm for the Integrated Simulation Framework.
ISFParticleOrderedQueue.
Forward declaration.
HandleKeyArray< ReadHandle< T >, ReadHandleKey< T >, Gaudi::DataHandle::Reader > ReadHandleKeyArray
#define private