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  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 
172 template <typename HitType_t, typename OutputType_t>
173 inline 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 
182 template <typename HitType_t, typename OutputType_t>
183 inline 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
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:124
SG::HandleKeyArray
Definition: StoreGate/StoreGate/HandleKeyArray.h:38
ISF::CollectionMerger::m_outputsTGCHits
SG::WriteHandleKey< sTGCSimHitCollection > m_outputsTGCHits
Definition: CollectionMerger.h:134
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
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:173
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:76
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:228
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