Skip to content

Commit

Permalink
Make upcoming renaming of TrackerHit to TrackerHit3D transparent (#45)
Browse files Browse the repository at this point in the history
* Rename TrackerHit -> TrackerHit3D

* Make switch to TrackerHit3D transparent
  • Loading branch information
tmadlener authored Feb 7, 2024
1 parent 88085ef commit 1996007
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 27 deletions.
14 changes: 11 additions & 3 deletions k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
#include <edm4hep/SimTrackerHitCollection.h>
#include <edm4hep/RawTimeSeriesCollection.h>
#include <edm4hep/TrackCollection.h>
#include <edm4hep/TrackerHitCollection.h>
#if __has_include("edm4hep/TrackerHit3DCollection.h")
#include "edm4hep/TrackerHit3DCollection.h"
#else
#include "edm4hep/TrackerHitCollection.h"
namespace edm4hep {
using TrackerHit3DCollection = edm4hep::TrackerHitCollection;
using TrackerHit3D = edm4hep::TrackerHit;
} // namespace edm4hep
#endif
#include <edm4hep/TrackerHitPlaneCollection.h>
#include <edm4hep/VertexCollection.h>

Expand Down Expand Up @@ -66,7 +74,7 @@ namespace EDM4hep2LCIOConv {

struct CollectionsPairVectors {
ObjectMapT<lcio::TrackImpl*, edm4hep::Track> tracks {};
ObjectMapT<lcio::TrackerHitImpl*, edm4hep::TrackerHit> trackerHits {};
ObjectMapT<lcio::TrackerHitImpl*, edm4hep::TrackerHit3D> trackerHits {};
ObjectMapT<lcio::TrackerHitPlaneImpl*, edm4hep::TrackerHitPlane> trackerHitPlanes {};
ObjectMapT<lcio::SimTrackerHitImpl*, edm4hep::SimTrackerHit> simTrackerHits {};
ObjectMapT<lcio::CalorimeterHitImpl*, edm4hep::CalorimeterHit> caloHits {};
Expand All @@ -87,7 +95,7 @@ namespace EDM4hep2LCIOConv {

template<typename TrackerHitMapT>
lcio::LCCollectionVec* convTrackerHits(
const edm4hep::TrackerHitCollection* const trackerhits_coll,
const edm4hep::TrackerHit3DCollection* const trackerhits_coll,
const std::string& cellIDstr,
TrackerHitMapT& trackerhits_vec);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace EDM4hep2LCIOConv {
// Add LCIO Collection Vector to LCIO event
template<typename TrackerHitMapT>
lcio::LCCollectionVec* convTrackerHits(
const edm4hep::TrackerHitCollection* const trackerhits_coll,
const edm4hep::TrackerHit3DCollection* const trackerhits_coll,
const std::string& cellIDstr,
TrackerHitMapT& trackerhits_vec)
{
Expand Down
12 changes: 10 additions & 2 deletions k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@
#include "edm4hep/SimTrackerHitCollection.h"
#include "edm4hep/RawTimeSeriesCollection.h"
#include "edm4hep/TrackCollection.h"
#if __has_include("edm4hep/TrackerHit3DCollection.h")
#include "edm4hep/TrackerHit3DCollection.h"
#else
#include "edm4hep/TrackerHitCollection.h"
namespace edm4hep {
using TrackerHit3DCollection = edm4hep::TrackerHitCollection;
using MutableTrackerHit3D = edm4hep::TrackerHit;
} // namespace edm4hep
#endif
#include "edm4hep/TrackerHitPlaneCollection.h"
#include "edm4hep/VertexCollection.h"

Expand Down Expand Up @@ -71,7 +79,7 @@ namespace LCIO2EDM4hepConv {
*/
struct LcioEdmTypeMapping {
ObjectMapT<lcio::Track*, edm4hep::MutableTrack> tracks {};
ObjectMapT<lcio::TrackerHit*, edm4hep::MutableTrackerHit> trackerHits {};
ObjectMapT<lcio::TrackerHit*, edm4hep::MutableTrackerHit3D> trackerHits {};
ObjectMapT<lcio::SimTrackerHit*, edm4hep::MutableSimTrackerHit> simTrackerHits {};
ObjectMapT<lcio::CalorimeterHit*, edm4hep::MutableCalorimeterHit> caloHits {};
ObjectMapT<lcio::RawCalorimeterHit*, edm4hep::MutableRawCalorimeterHit> rawCaloHits {};
Expand Down Expand Up @@ -232,7 +240,7 @@ namespace LCIO2EDM4hepConv {
* Simultaneously populates the mapping from LCIO to EDM4hep objects.
*/
template<typename HitMapT>
std::unique_ptr<edm4hep::TrackerHitCollection>
std::unique_ptr<edm4hep::TrackerHit3DCollection>
convertTrackerHits(const std::string& name, EVENT::LCCollection* LCCollection, HitMapT& TrackerHitMap);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ namespace LCIO2EDM4hepConv {
}

template<typename HitMapT>
std::unique_ptr<edm4hep::TrackerHitCollection>
std::unique_ptr<edm4hep::TrackerHit3DCollection>
convertTrackerHits(const std::string& name, EVENT::LCCollection* LCCollection, HitMapT& TrackerHitMap)
{
auto dest = std::make_unique<edm4hep::TrackerHitCollection>();
auto dest = std::make_unique<edm4hep::TrackerHit3DCollection>();
for (unsigned i = 0, N = LCCollection->getNumberOfElements(); i < N; ++i) {
auto* rval = static_cast<EVENT::TrackerHit*>(LCCollection->getElementAt(i));
auto lval = dest->create();
Expand Down Expand Up @@ -1067,7 +1067,7 @@ namespace LCIO2EDM4hepConv {
return handleSubsetColl<edm4hep::RawTimeSeriesCollection>(LCCollection, typeMapping.tpcHits);
}
else if (type == "TrackerHit") {
return handleSubsetColl<edm4hep::TrackerHitCollection>(LCCollection, typeMapping.trackerHits);
return handleSubsetColl<edm4hep::TrackerHit3DCollection>(LCCollection, typeMapping.trackerHits);
}
else if (type == "TrackerHitPlane") {
return handleSubsetColl<edm4hep::TrackerHitPlaneCollection>(LCCollection, typeMapping.trackerHitPlanes);
Expand Down
2 changes: 1 addition & 1 deletion k4EDM4hep2LcioConv/src/k4EDM4hep2LcioConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace EDM4hep2LCIOConv {
auto lcColl = convTracks(coll, objectMappings.tracks, objectMappings.trackerHits);
lcioEvent->addCollection(lcColl, name);
}
else if (auto coll = dynamic_cast<const edm4hep::TrackerHitCollection*>(edmCollection)) {
else if (auto coll = dynamic_cast<const edm4hep::TrackerHit3DCollection*>(edmCollection)) {
auto lcColl = convTrackerHits(coll, cellIDStr, objectMappings.trackerHits);
lcioEvent->addCollection(lcColl, name);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/compare_contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int main(int argc, char* argv[])
ASSERT_COMPARE_OR_EXIT(edm4hep::MCParticleCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::ReconstructedParticleCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::TrackCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::TrackerHitCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::TrackerHit3DCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::TrackerHitPlaneCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::SimTrackerHitCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::CalorimeterHitCollection)
Expand Down
2 changes: 1 addition & 1 deletion tests/edm4hep_roundtrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main()
ASSERT_SAME_OR_ABORT(edm4hep::MCParticleCollection, "mcParticles");
ASSERT_SAME_OR_ABORT(edm4hep::SimCalorimeterHitCollection, "simCaloHits");
ASSERT_SAME_OR_ABORT(edm4hep::TrackCollection, "tracks");
ASSERT_SAME_OR_ABORT(edm4hep::TrackerHitCollection, "trackerHits");
ASSERT_SAME_OR_ABORT(edm4hep::TrackerHit3DCollection, "trackerHits");
ASSERT_SAME_OR_ABORT(edm4hep::TrackerHitPlaneCollection, "trackerHitPlanes");
ASSERT_SAME_OR_ABORT(edm4hep::ClusterCollection, "clusters");

Expand Down
2 changes: 1 addition & 1 deletion tests/edm4hep_to_lcio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main()
ASSERT_COMPARE_OR_EXIT(edm4hep::MCParticleCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::ReconstructedParticleCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::TrackCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::TrackerHitCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::TrackerHit3DCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::TrackerHitPlaneCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::SimTrackerHitCollection)
ASSERT_COMPARE_OR_EXIT(edm4hep::CalorimeterHitCollection)
Expand Down
3 changes: 1 addition & 2 deletions tests/src/CompareEDM4hepEDM4hep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/SimCalorimeterHitCollection.h"
#include "edm4hep/TrackCollection.h"
#include "edm4hep/TrackerHitCollection.h"
#include "edm4hep/TrackerHitPlaneCollection.h"
#include "edm4hep/ClusterCollection.h"

Expand Down Expand Up @@ -199,7 +198,7 @@ bool compare(const edm4hep::TrackCollection& origColl, const edm4hep::TrackColle
return true;
}

bool compare(const edm4hep::TrackerHitCollection& origColl, const edm4hep::TrackerHitCollection& roundtripColl)
bool compare(const edm4hep::TrackerHit3DCollection& origColl, const edm4hep::TrackerHit3DCollection& roundtripColl)
{
REQUIRE_SAME(origColl.size(), roundtripColl.size(), "collection sizes");
for (size_t i = 0; i < origColl.size(); ++i) {
Expand Down
2 changes: 1 addition & 1 deletion tests/src/CompareEDM4hepEDM4hep.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bool compare(

bool compare(const edm4hep::TrackCollection& origColl, const edm4hep::TrackCollection& roundtripColl);

bool compare(const edm4hep::TrackerHitCollection& origColl, const edm4hep::TrackerHitCollection& roundtripColl);
bool compare(const edm4hep::TrackerHit3DCollection& origColl, const edm4hep::TrackerHit3DCollection& roundtripColl);

bool compare(
const edm4hep::TrackerHitPlaneCollection& origColl,
Expand Down
4 changes: 2 additions & 2 deletions tests/src/CompareEDM4hepLCIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ bool compare(

bool compare(
const EVENT::TrackerHit* lcioElem,
const edm4hep::TrackerHit& edm4hepElem,
const edm4hep::TrackerHit3D& edm4hepElem,
const ObjectMappings& objectMaps)
{
const auto lcioCellID = to64BitCellID(lcioElem);
Expand All @@ -432,7 +432,7 @@ bool compare(

bool compare(
const lcio::LCCollection* lcioCollection,
const edm4hep::TrackerHitCollection& edm4hepCollection,
const edm4hep::TrackerHit3DCollection& edm4hepCollection,
const ObjectMappings& objectMaps)
{
return compareCollection<EVENT::TrackerHit>(lcioCollection, edm4hepCollection, objectMaps);
Expand Down
12 changes: 10 additions & 2 deletions tests/src/CompareEDM4hepLCIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@
#include "edm4hep/SimTrackerHitCollection.h"
#include "edm4hep/RawTimeSeriesCollection.h"
#include "edm4hep/TrackCollection.h"
#if __has_include("edm4hep/TrackerHit3DCollection.h")
#include "edm4hep/TrackerHit3DCollection.h"
#else
#include "edm4hep/TrackerHitCollection.h"
namespace edm4hep {
using TrackerHit3DCollection = edm4hep::TrackerHitCollection;
using TrackerHit3D = edm4hep::TrackerHit;
} // namespace edm4hep
#endif
#include "edm4hep/TrackerHitPlaneCollection.h"
#include "edm4hep/VertexCollection.h"
#include "podio/Frame.h"
Expand Down Expand Up @@ -107,10 +115,10 @@ bool compare(
const edm4hep::RawTimeSeriesCollection& edm4hepCollection,
const ObjectMappings& objectMaps);

bool compare(const EVENT::TrackerHit* lcio, const edm4hep::TrackerHit& edm4hep, const ObjectMappings& objectMaps);
bool compare(const EVENT::TrackerHit* lcio, const edm4hep::TrackerHit3D& edm4hep, const ObjectMappings& objectMaps);
bool compare(
const lcio::LCCollection* lcioCollection,
const edm4hep::TrackerHitCollection& edm4hepCollection,
const edm4hep::TrackerHit3DCollection& edm4hepCollection,
const ObjectMappings& objectMaps);

bool compare(
Expand Down
13 changes: 10 additions & 3 deletions tests/src/EDM4hep2LCIOUtilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
#include "edm4hep/MCParticleCollection.h"
#include "edm4hep/RawCalorimeterHitCollection.h"
#include "edm4hep/SimCalorimeterHitCollection.h"
#if __has_include("edm4hep/TrackerHit3DCollection.h")
#include "edm4hep/TrackerHit3DCollection.h"
#else
#include "edm4hep/TrackerHitCollection.h"
namespace edm4hep {
using TrackerHit3DCollection = edm4hep::TrackerHitCollection;
} // namespace edm4hep
#endif
#include <edm4hep/TrackerHitPlaneCollection.h>
#include <edm4hep/EventHeaderCollection.h>
#include <edm4hep/RawTimeSeriesCollection.h>
Expand Down Expand Up @@ -142,9 +149,9 @@ edm4hep::RawTimeSeriesCollection createTPCHits(const int num_elements, const int
return coll;
}

edm4hep::TrackerHitCollection createTrackerHits(const int num_elements)
edm4hep::TrackerHit3DCollection createTrackerHits(const int num_elements)
{
edm4hep::TrackerHitCollection coll {};
edm4hep::TrackerHit3DCollection coll {};

for (int i = 0; i < num_elements; ++i) {
auto elem = coll.create();
Expand Down Expand Up @@ -187,7 +194,7 @@ edm4hep::TrackCollection createTracks(
const int num_elements,
const int subdetectorhitnumbers,
const int num_track_states,
const edm4hep::TrackerHitCollection& trackerHits,
const edm4hep::TrackerHit3DCollection& trackerHits,
const std::vector<std::size_t>& link_trackerhit_idcs,
const std::vector<test_config::IdxPair>& track_link_tracks_idcs)
{
Expand Down
14 changes: 11 additions & 3 deletions tests/src/EDM4hep2LCIOUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
#include <vector>
#include <tuple>

#if __has_include("edm4hep/TrackerHit3DCollection.h")
#include "edm4hep/TrackerHit3DCollection.h"
#else
#include "edm4hep/TrackerHitCollection.h"
namespace edm4hep {
using TrackerHit3DCollection = edm4hep::TrackerHitCollection;
} // namespace edm4hep
#endif

namespace edm4hep {
class CalorimeterHitCollection;
class MCParticleCollection;
class RawCalorimeterHitCollection;
class RawTimeSeriesCollection;
class TrackerHitCollection;
class TrackerHitPlaneCollection;
class TrackCollection;
class SimCalorimeterHitCollection;
Expand Down Expand Up @@ -110,7 +118,7 @@ edm4hep::RawTimeSeriesCollection createTPCHits(const int num_elements, const int
/**
* Create a TrackerHit collection
*/
edm4hep::TrackerHitCollection createTrackerHits(const int num_elements);
edm4hep::TrackerHit3DCollection createTrackerHits(const int num_elements);

/**
* Create a track collection with tracks that have links to other tracks (in the
Expand All @@ -120,7 +128,7 @@ edm4hep::TrackCollection createTracks(
const int num_elements,
const int subdetectorhitnumbers,
const int num_track_states,
const edm4hep::TrackerHitCollection& trackerHits,
const edm4hep::TrackerHit3DCollection& trackerHits,
const std::vector<std::size_t>& link_trackerhit_idcs,
const std::vector<test_config::IdxPair>& track_link_tracks_idcs);

Expand Down
12 changes: 11 additions & 1 deletion tests/src/ObjectMapping.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
#include "UTIL/LCIterator.h"

#include "edm4hep/TrackCollection.h"
#if __has_include("edm4hep/TrackerHit3DCollection.h")
#include "edm4hep/TrackerHit3DCollection.h"
#else
#include "edm4hep/TrackerHitCollection.h"
namespace edm4hep {
using TrackerHit3DCollection = edm4hep::TrackerHitCollection;
} // namespace edm4hep
#endif
#include "edm4hep/TrackerHitPlaneCollection.h"
#include "edm4hep/SimTrackerHitCollection.h"
#include "edm4hep/ClusterCollection.h"
Expand Down Expand Up @@ -67,7 +74,6 @@ ObjectMappings ObjectMappings::fromEvent(EVENT::LCEvent* lcEvt, const podio::Fra
continue;
}
FILL_MAP(Track, mapping.tracks);
FILL_MAP(TrackerHit, mapping.trackerHits);
FILL_MAP(TrackerHitPlane, mapping.trackerHitPlanes);
FILL_MAP(SimTrackerHit, mapping.simTrackerHits);
FILL_MAP(Cluster, mapping.clusters);
Expand All @@ -82,6 +88,10 @@ ObjectMappings ObjectMappings::fromEvent(EVENT::LCEvent* lcEvt, const podio::Fra
auto& edm4hepColl = edmEvt.get<edm4hep::RawTimeSeriesCollection>(name);
fillMap<EVENT::TPCHit>(mapping.tpcHits, lcioColl, edm4hepColl);
}
if (type == "TrackerHit") {
auto& edm4hepColl = edmEvt.get<edm4hep::TrackerHit3DCollection>(name);
fillMap<EVENT::TrackerHit>(mapping.trackerHits, lcioColl, edm4hepColl);
}
}

return mapping;
Expand Down

0 comments on commit 1996007

Please sign in to comment.