ATLAS Offline Software
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
37 namespace ISFTesting {
38  class CollectionMerger_test;
39 }
40 
41 
42 namespace ISF {
43 
51  class CollectionMerger final : public AthReentrantAlgorithm {
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 
111  SG::WriteHandleKey<SiHitCollection> m_outputBCMHits{this, "OutputBCMHits", "", ""};
112  SG::WriteHandleKey<SiHitCollection> m_outputBLMHits{this, "OutputBLMHits", "", ""};
113  SG::WriteHandleKey<SiHitCollection> m_outputPixelHits{this, "OutputPixelHits", "", ""};
114  SG::WriteHandleKey<SiHitCollection> m_outputSCTHits{this, "OutputSCTHits", "", ""};
116 
117  SG::WriteHandleKey<SiHitCollection> m_outputITkPixelHits{this, "OutputITkPixelHits", "", ""};
118  SG::WriteHandleKey<SiHitCollection> m_outputITkStripHits{this, "OutputITkStripHits", "", ""};
119  SG::WriteHandleKey<SiHitCollection> m_outputPLRHits{this, "OutputPLRHits", "", ""};
120  SG::WriteHandleKey<SiHitCollection> m_outputHGTDHits{this, "OutputHGTDHits", "", ""};
121 
122  SG::WriteHandleKey<LArHitContainer> m_outputLArEMBHits{this, "OutputLArEMBHits", "", ""};
123  SG::WriteHandleKey<LArHitContainer> m_outputLArEMECHits{this, "OutputLArEMECHits", "", ""};
124  SG::WriteHandleKey<LArHitContainer> m_outputLArFCALHits{this, "OutputLArFCALHits", "", ""};
125  SG::WriteHandleKey<LArHitContainer> m_outputLArHECHits{this, "OutputLArHECHits", "", ""};
126 
127  SG::WriteHandleKey<TileHitVector> m_outputTileHits{this, "OutputTileHits", "", ""};
128  SG::WriteHandleKey<TileHitVector> m_outputMBTSHits{this, "OutputMBTSHits", "", ""};
129 
136  };
137 
138 
139 //
140 // templated methods below
141 //
142 
144 template <typename T>
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  SG::WriteHandle<T> outputHandle{outputWriteHandleKey, ctx};
155  ATH_CHECK( outputHandle.record(std::make_unique<T>()) );
156 
157  for ( const auto& collKey: inputReadHandleKeys ) {
158  SG::ReadHandle<T> inputHandle{collKey, ctx};
159 
160  for ( const auto& hit: *inputHandle ) {
161  this->insertCopy(hit, outputHandle);
162  }
163  }
164 
165  return StatusCode::SUCCESS;
166 }
167 
168 
170 template <typename HitType_t, typename OutputType_t>
171 inline void ISF::CollectionMerger::insertCopy(const HitType_t& hit,
172  OutputType_t& outputHandle) const {
173  static_assert(!std::is_pointer<HitType_t>::value,
174  "The hit provided to ISF::CollectionMerger::insertCopy(..) must not be a pointer!");
175  outputHandle->Emplace( hit );
176 }
177 
178 
180 template <typename HitType_t, typename OutputType_t>
181 inline void ISF::CollectionMerger::insertCopy(HitType_t * const hit,
182  OutputType_t& outputHandle) const {
183  auto&& hitCopy = std::make_unique<std::remove_const_t<HitType_t> >(*hit);
184  outputHandle->push_back( hitCopy.release() );
185 }
186 
187 
188 }
189 
190 #endif //> !ISF_ALGS_COLLECTIONMERGER_H
ReadHandleKeyArray.h
ISF::CollectionMerger::m_inputBCMHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputBCMHits
Input collection ReadHandleKeys.
Definition: CollectionMerger.h:84
ISF::CollectionMerger::CollectionMerger
CollectionMerger(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition: CollectionMerger.cxx:8
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
ISF::CollectionMerger::m_outputTRTUncompressedHits
SG::WriteHandleKey< TRTUncompressedHitCollection > m_outputTRTUncompressedHits
Definition: CollectionMerger.h:115
ISF::CollectionMerger::m_inputLArEMECHits
SG::ReadHandleKeyArray< LArHitContainer > m_inputLArEMECHits
Definition: CollectionMerger.h:96
ISF::CollectionMerger::m_inputLArFCALHits
SG::ReadHandleKeyArray< LArHitContainer > m_inputLArFCALHits
Definition: CollectionMerger.h:97
ISF::CollectionMerger::m_inputTileHits
SG::ReadHandleKeyArray< TileHitVector > m_inputTileHits
Definition: CollectionMerger.h:100
ISF::CollectionMerger::m_inputTRTUncompressedHits
SG::ReadHandleKeyArray< TRTUncompressedHitCollection > m_inputTRTUncompressedHits
Definition: CollectionMerger.h:88
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CSCSimHitCollection.h
AtlasHitsVector
Definition: AtlasHitsVector.h:33
taskman.template
dictionary template
Definition: taskman.py:317
sTGCSimHitCollection.h
athena.value
value
Definition: athena.py:122
SG::HandleKeyArray
Definition: StoreGate/StoreGate/HandleKeyArray.h:38
ISF::CollectionMerger::m_outputsTGCHits
SG::WriteHandleKey< sTGCSimHitCollection > m_outputsTGCHits
Definition: CollectionMerger.h:134
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:562
ISF::CollectionMerger::m_inputMBTSHits
SG::ReadHandleKeyArray< TileHitVector > m_inputMBTSHits
Definition: CollectionMerger.h:101
ISF::CollectionMerger::m_inputMDTHits
SG::ReadHandleKeyArray< MDTSimHitCollection > m_inputMDTHits
Definition: CollectionMerger.h:104
ISF::CollectionMerger::m_inputITkStripHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputITkStripHits
Definition: CollectionMerger.h:91
ISF::CollectionMerger::m_outputTileHits
SG::WriteHandleKey< TileHitVector > m_outputTileHits
Definition: CollectionMerger.h:127
ISF::CollectionMerger::m_inputPixelHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputPixelHits
Definition: CollectionMerger.h:86
ISF::CollectionMerger::insertCopy
void insertCopy(const HitType_t &hit, OutputType_t &outputHandle) const
Copy the given hit into the given output collection, container or DataHandle.
Definition: CollectionMerger.h:171
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
ISF::CollectionMerger::m_inputCSCHits
SG::ReadHandleKeyArray< CSCSimHitCollection > m_inputCSCHits
Definition: CollectionMerger.h:103
ISF::CollectionMerger::m_outputLArFCALHits
SG::WriteHandleKey< LArHitContainer > m_outputLArFCALHits
Definition: CollectionMerger.h:124
ISF::CollectionMerger::m_outputSCTHits
SG::WriteHandleKey< SiHitCollection > m_outputSCTHits
Definition: CollectionMerger.h:114
ISF::CollectionMerger::m_outputBCMHits
SG::WriteHandleKey< SiHitCollection > m_outputBCMHits
Output collection WriteHandleKeys.
Definition: CollectionMerger.h:111
ISF::CollectionMerger::CollectionMerger_test
friend class ISFTesting::CollectionMerger_test
Allow the test class access to all methods.
Definition: CollectionMerger.h:54
ISF::CollectionMerger::m_outputITkPixelHits
SG::WriteHandleKey< SiHitCollection > m_outputITkPixelHits
Definition: CollectionMerger.h:117
ISF::CollectionMerger::m_inputLArEMBHits
SG::ReadHandleKeyArray< LArHitContainer > m_inputLArEMBHits
Definition: CollectionMerger.h:95
SG::WriteHandleKey
Property holding a SG store/key/clid from which a WriteHandle is made.
Definition: StoreGate/StoreGate/WriteHandleKey.h:40
ISF::CollectionMerger::m_outputBLMHits
SG::WriteHandleKey< SiHitCollection > m_outputBLMHits
Definition: CollectionMerger.h:112
ISF::CollectionMerger::m_inputTGCHits
SG::ReadHandleKeyArray< TGCSimHitCollection > m_inputTGCHits
Definition: CollectionMerger.h:106
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ISF::CollectionMerger::m_outputRPCHits
SG::WriteHandleKey< RPCSimHitCollection > m_outputRPCHits
Definition: CollectionMerger.h:132
ISF::CollectionMerger::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Athena Algorithm execute.
Definition: CollectionMerger.cxx:75
ISF::CollectionMerger::m_outputTGCHits
SG::WriteHandleKey< TGCSimHitCollection > m_outputTGCHits
Definition: CollectionMerger.h:133
SG::ReadHandleKeyArray
HandleKeyArray< ReadHandle< T >, ReadHandleKey< T >, Gaudi::DataHandle::Reader > ReadHandleKeyArray
Definition: StoreGate/StoreGate/ReadHandleKeyArray.h:32
ISF::CollectionMerger::m_outputMDTHits
SG::WriteHandleKey< MDTSimHitCollection > m_outputMDTHits
Definition: CollectionMerger.h:131
ISF::CollectionMerger::m_inputITkPixelHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputITkPixelHits
Definition: CollectionMerger.h:90
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ISF::CollectionMerger::m_outputMMHits
SG::WriteHandleKey< MMSimHitCollection > m_outputMMHits
Definition: CollectionMerger.h:135
ISF::CollectionMerger
Athena Algorithm that merges a given set of StoreGate collections in one final collection.
Definition: CollectionMerger.h:51
RPCSimHitCollection.h
ISF::CollectionMerger::m_inputHGTDHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputHGTDHits
Definition: CollectionMerger.h:93
ISF::CollectionMerger::m_inputBLMHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputBLMHits
Definition: CollectionMerger.h:85
ISF::CollectionMerger::m_inputsTGCHits
SG::ReadHandleKeyArray< sTGCSimHitCollection > m_inputsTGCHits
Definition: CollectionMerger.h:107
ISF::CollectionMerger::initialize
virtual StatusCode initialize() override final
Athena algorithm's interface methods.
Definition: CollectionMerger.cxx:15
AthReentrantAlgorithm.h
WriteHandleKey.h
Property holding a SG store/key/clid from which a WriteHandle is made.
MDTSimHitCollection.h
TileHitVector.h
ISF::CollectionMerger::m_outputLArEMECHits
SG::WriteHandleKey< LArHitContainer > m_outputLArEMECHits
Definition: CollectionMerger.h:123
ISF::CollectionMerger::~CollectionMerger
virtual ~CollectionMerger()=default
Destructor.
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MMSimHitCollection.h
ISF::CollectionMerger::m_outputLArEMBHits
SG::WriteHandleKey< LArHitContainer > m_outputLArEMBHits
Definition: CollectionMerger.h:122
python.Dumpers.typename
def typename(t)
Definition: Dumpers.py:194
TGCSimHitCollection.h
ISF::CollectionMerger::m_outputITkStripHits
SG::WriteHandleKey< SiHitCollection > m_outputITkStripHits
Definition: CollectionMerger.h:118
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
ISF::CollectionMerger::m_inputSCTHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputSCTHits
Definition: CollectionMerger.h:87
ISF::CollectionMerger::m_inputPLRHits
SG::ReadHandleKeyArray< SiHitCollection > m_inputPLRHits
Definition: CollectionMerger.h:92
TRTUncompressedHitCollection.h
ISF
ISFParticleOrderedQueue.
Definition: PrimaryParticleInformation.h:13
ISF::CollectionMerger::m_outputCSCHits
SG::WriteHandleKey< CSCSimHitCollection > m_outputCSCHits
Definition: CollectionMerger.h:130
LArHitContainer.h
ISF::CollectionMerger::m_outputPixelHits
SG::WriteHandleKey< SiHitCollection > m_outputPixelHits
Definition: CollectionMerger.h:113
ISF::CollectionMerger::m_outputLArHECHits
SG::WriteHandleKey< LArHitContainer > m_outputLArHECHits
Definition: CollectionMerger.h:125
ISF::CollectionMerger::m_outputHGTDHits
SG::WriteHandleKey< SiHitCollection > m_outputHGTDHits
Definition: CollectionMerger.h:120
ISF::CollectionMerger::mergeCollections
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.
Definition: CollectionMerger.h:145
ISF::CollectionMerger::m_inputLArHECHits
SG::ReadHandleKeyArray< LArHitContainer > m_inputLArHECHits
Definition: CollectionMerger.h:98
ISFTesting
Core Athena algorithm for the Integrated Simulation Framework.
Definition: CollectionMerger.h:37
ISF::CollectionMerger::m_inputMMHits
SG::ReadHandleKeyArray< MMSimHitCollection > m_inputMMHits
Definition: CollectionMerger.h:108
ISF::CollectionMerger::m_inputRPCHits
SG::ReadHandleKeyArray< RPCSimHitCollection > m_inputRPCHits
Definition: CollectionMerger.h:105
ISF::CollectionMerger::m_outputMBTSHits
SG::WriteHandleKey< TileHitVector > m_outputMBTSHits
Definition: CollectionMerger.h:128
ISF::CollectionMerger::m_outputPLRHits
SG::WriteHandleKey< SiHitCollection > m_outputPLRHits
Definition: CollectionMerger.h:119
SiHitCollection.h