-
Notifications
You must be signed in to change notification settings - Fork 3
/
SimTrackerHitsCollector.cpp
75 lines (65 loc) · 2.6 KB
/
SimTrackerHitsCollector.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright (C) 2022 Wouter Deconinck, Whitney Armstrong, Chao Peng
// Gaudi
#include "GaudiAlg/GaudiAlgorithm.h"
#include "Gaudi/Property.h"
#include "GaudiAlg/GaudiTool.h"
#include "GaudiAlg/Transformer.h"
#include "JugBase/DataHandle.h"
// Event Model related classes
#include "edm4hep/SimTrackerHitCollection.h"
namespace Jug::Digi {
/** Collect the tracking hits into a single collection.
*
* \param inputSimTrackerHits [in] vector of collection names
* \param outputSimTrackerHits [out] hits combined into one collection.
*
* \ingroup digi
*/
class SimTrackerHitsCollector : public GaudiAlgorithm {
private:
Gaudi::Property<std::vector<std::string>> m_inputSimTrackerHits{this, "inputSimTrackerHits", {},"Tracker hits to be aggregated"};
DataHandle<edm4hep::SimTrackerHitCollection> m_outputSimTrackerHits{"outputSimTrackerHits", Gaudi::DataHandle::Writer, this};
std::vector<DataHandle<edm4hep::SimTrackerHitCollection>*> m_hitCollections;
public:
SimTrackerHitsCollector(const std::string& name, ISvcLocator* svcLoc)
: GaudiAlgorithm(name, svcLoc)
{
declareProperty("outputSimTrackerHits", m_outputSimTrackerHits, "output hits combined into single collection");
}
~SimTrackerHitsCollector() {
for (auto* col : m_hitCollections) {
delete col;
}
}
StatusCode initialize() override {
if (GaudiAlgorithm::initialize().isFailure()) {
return StatusCode::FAILURE;
}
for (auto colname : m_inputSimTrackerHits) {
debug() << "initializing collection: " << colname << endmsg;
m_hitCollections.push_back(new DataHandle<edm4hep::SimTrackerHitCollection>{colname, Gaudi::DataHandle::Reader, this});
}
return StatusCode::SUCCESS;
}
StatusCode execute() override
{
auto* outputHits = m_outputSimTrackerHits.createAndPut();
if (msgLevel(MSG::DEBUG)) {
debug() << "execute collector" << endmsg;
}
for(const auto& hits: m_hitCollections) {
const edm4hep::SimTrackerHitCollection* hitCol = hits->get();
if (msgLevel(MSG::DEBUG)) {
debug() << "col n hits: " << hitCol->size() << endmsg;
}
for (const auto& ahit : *hitCol) {
outputHits->push_back(ahit.clone());
}
}
return StatusCode::SUCCESS;
}
};
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
DECLARE_COMPONENT(SimTrackerHitsCollector)
} // namespace Jug::Digi