From f2f0f1b2a7d23b922846d0d3def72b18c92d8818 Mon Sep 17 00:00:00 2001 From: Chengdong Fu Date: Sat, 3 Feb 2024 18:48:47 +0800 Subject: [PATCH 1/2] edm4hep version control for ObjectID --- .../include/DataHelper/Navigation.h | 15 ++++++++++++ Utilities/DataHelper/src/Navigation.cpp | 23 ++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Utilities/DataHelper/include/DataHelper/Navigation.h b/Utilities/DataHelper/include/DataHelper/Navigation.h index 87ca762b9..768201a67 100644 --- a/Utilities/DataHelper/include/DataHelper/Navigation.h +++ b/Utilities/DataHelper/include/DataHelper/Navigation.h @@ -5,6 +5,15 @@ #include "edm4hep/TrackerHitCollection.h" #include +#if __has_include("edm4hep/EDM4hepVersion.h") +#include "edm4hep/EDM4hepVersion.h" +#else +// Copy the necessary parts from the header above to make whatever we need to work here +#define EDM4HEP_VERSION(major, minor, patch) ((UINT64_C(major) << 32) | (UINT64_C(minor) << 16) | (UINT64_C(patch))) +// v00-09 is the last version without the capitalization change of the track vector members +#define EDM4HEP_BUILD_VERSION EDM4HEP_VERSION(0, 9, 0) +#endif + class Navigation{ public: static Navigation* Instance(); @@ -17,9 +26,15 @@ class Navigation{ void AddTrackerHitCollection(const edm4hep::TrackerHitCollection* col){m_hitColVec.push_back(col);}; void AddTrackerAssociationCollection(const edm4hep::MCRecoTrackerAssociationCollection* col){m_assColVec.push_back(col);}; +#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 2) edm4hep::TrackerHit GetTrackerHit(const edm4hep::ObjectID& id, bool delete_by_caller=true); std::vector GetRelatedTrackerHit(const edm4hep::ObjectID& id); +#else + edm4hep::TrackerHit GetTrackerHit(const podio::ObjectID& id, bool delete_by_caller=true); + std::vector GetRelatedTrackerHit(const podio::ObjectID& id); +#endif std::vector GetRelatedTrackerHit(const edm4hep::TrackerHit& hit); + std::vector GetRelatedTrackerHit(const edm4hep::TrackerHit& hit, const edm4hep::MCRecoTrackerAssociationCollection* col); //static Navigation* m_fNavigation; private: diff --git a/Utilities/DataHelper/src/Navigation.cpp b/Utilities/DataHelper/src/Navigation.cpp index cc81b7f0e..98c65022d 100644 --- a/Utilities/DataHelper/src/Navigation.cpp +++ b/Utilities/DataHelper/src/Navigation.cpp @@ -25,7 +25,11 @@ void Navigation::Initialize(){ m_trkHits.clear(); } +#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 2) edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, bool delete_by_caller){ +#else +edm4hep::TrackerHit Navigation::GetTrackerHit(const podio::ObjectID& obj_id, bool delete_by_caller){ +#endif int id = obj_id.collectionID * 10000000 + obj_id.index; if(!delete_by_caller){ if(m_trkHits.find(id)!=m_trkHits.end()) return m_trkHits[id]; @@ -33,7 +37,7 @@ edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, b /* for(int i=0;i Navigation::GetRelatedTrackerHit(const edm4hep::ObjectID& id){ +#else +std::vector Navigation::GetRelatedTrackerHit(const podio::ObjectID& id){ +#endif std::vector hits; for(int i=0;i Navigation::GetRelatedTrackerHit(const edm4h } return hits; } + +std::vector Navigation::GetRelatedTrackerHit(const edm4hep::TrackerHit& hit, const edm4hep::MCRecoTrackerAssociationCollection* col){ + std::vector hits; + for(auto ass : *col){ + if(ass.getRec().getObjectID().collectionID != hit.getObjectID().collectionID) break; + else if(ass.getRec()==hit) hits.push_back(ass.getSim()); + } + return hits; +} From 6630fea3bb35bc1a3ea8fcbdc49b5c04ae5669dc Mon Sep 17 00:00:00 2001 From: Chengdong Fu Date: Sun, 4 Feb 2024 14:17:58 +0800 Subject: [PATCH 2/2] switch version more than 0.10.4 --- Utilities/DataHelper/include/DataHelper/Navigation.h | 2 +- Utilities/DataHelper/src/Navigation.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Utilities/DataHelper/include/DataHelper/Navigation.h b/Utilities/DataHelper/include/DataHelper/Navigation.h index 768201a67..6d641a1c0 100644 --- a/Utilities/DataHelper/include/DataHelper/Navigation.h +++ b/Utilities/DataHelper/include/DataHelper/Navigation.h @@ -26,7 +26,7 @@ class Navigation{ void AddTrackerHitCollection(const edm4hep::TrackerHitCollection* col){m_hitColVec.push_back(col);}; void AddTrackerAssociationCollection(const edm4hep::MCRecoTrackerAssociationCollection* col){m_assColVec.push_back(col);}; -#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 2) +#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 4) edm4hep::TrackerHit GetTrackerHit(const edm4hep::ObjectID& id, bool delete_by_caller=true); std::vector GetRelatedTrackerHit(const edm4hep::ObjectID& id); #else diff --git a/Utilities/DataHelper/src/Navigation.cpp b/Utilities/DataHelper/src/Navigation.cpp index 98c65022d..ff86af1f4 100644 --- a/Utilities/DataHelper/src/Navigation.cpp +++ b/Utilities/DataHelper/src/Navigation.cpp @@ -25,7 +25,7 @@ void Navigation::Initialize(){ m_trkHits.clear(); } -#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 2) +#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 4) edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, bool delete_by_caller){ #else edm4hep::TrackerHit Navigation::GetTrackerHit(const podio::ObjectID& obj_id, bool delete_by_caller){ @@ -61,7 +61,7 @@ edm4hep::TrackerHit Navigation::GetTrackerHit(const podio::ObjectID& obj_id, boo throw std::runtime_error("Not found TrackerHit"); } -#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 2) +#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 4) std::vector Navigation::GetRelatedTrackerHit(const edm4hep::ObjectID& id){ #else std::vector Navigation::GetRelatedTrackerHit(const podio::ObjectID& id){