Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-06-29 07:05:31

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 Whitney Armstrong, Sylvester Joosten, Wouter Deconinck
0003 
0004 // Gaudi
0005 #include "GaudiAlg/GaudiAlgorithm.h"
0006 #include "Gaudi/Property.h"
0007 #include "GaudiAlg/GaudiTool.h"
0008 #include "GaudiAlg/Transformer.h"
0009 
0010 #include "JugBase/DataHandle.h"
0011 
0012 // Event Model related classes
0013 #include "edm4eic/TrackerHitCollection.h"
0014 
0015 namespace Jug::Reco {
0016 
0017     /** Collect the tracking hits into a single collection.
0018      *
0019      * \param inputTrackingHits [in] vector of collection names
0020      * \param trackingHits [out] hits combined into one collection.
0021      *
0022      * \ingroup reco
0023      */
0024     class TrackingHitsCollector2 : public GaudiAlgorithm {
0025     private:
0026       Gaudi::Property<std::vector<std::string>> m_inputTrackingHits{this, "inputTrackingHits", {},"Tracker hits to be aggregated"};
0027       DataHandle<edm4eic::TrackerHitCollection> m_trackingHits{"trackingHits", Gaudi::DataHandle::Writer, this};
0028 
0029       std::vector<DataHandle<edm4eic::TrackerHitCollection>*> m_hitCollections;
0030 
0031     public:
0032       TrackingHitsCollector2(const std::string& name, ISvcLocator* svcLoc)
0033           : GaudiAlgorithm(name, svcLoc)
0034       {
0035         declareProperty("trackingHits", m_trackingHits, "output hits combined into single collection");
0036       }
0037       ~TrackingHitsCollector2() {
0038         for (auto* col : m_hitCollections) {
0039           delete col;
0040         }
0041       }
0042 
0043       StatusCode initialize() override {
0044         if (GaudiAlgorithm::initialize().isFailure()) {
0045           return StatusCode::FAILURE;
0046         }
0047         for (auto colname : m_inputTrackingHits) {
0048           debug() << "initializing collection: " << colname  << endmsg;
0049           m_hitCollections.push_back(new DataHandle<edm4eic::TrackerHitCollection>{colname, Gaudi::DataHandle::Reader, this});
0050         }
0051         return StatusCode::SUCCESS;
0052       }
0053 
0054       StatusCode execute() override
0055       {
0056         auto* outputHits = m_trackingHits.createAndPut();
0057         if (msgLevel(MSG::DEBUG)) {
0058           debug() << "execute collector" << endmsg;
0059         }
0060         for(const auto& hits: m_hitCollections) {
0061           const edm4eic::TrackerHitCollection* hitCol = hits->get();
0062           if (msgLevel(MSG::DEBUG)) {
0063             debug() << "col n hits: " << hitCol->size() << endmsg;
0064           }
0065           for (const auto& ahit : *hitCol) {
0066             outputHits->push_back(ahit.clone());
0067           }
0068         }
0069 
0070         return StatusCode::SUCCESS;
0071       }
0072     };
0073     // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
0074     DECLARE_COMPONENT(TrackingHitsCollector2)
0075 
0076 } // namespace Jug::Reco