Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edm4hep version control for ObjectID #262

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Utilities/DataHelper/include/DataHelper/Navigation.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
#include "edm4hep/TrackerHitCollection.h"
#include <map>

#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();
Expand All @@ -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, 4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should have been (0, 10, 5), because the mentioned PR has not yet landed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmadlener and @jmcarcell sorry, I will create a new tag based one the new MR: #265

edm4hep::TrackerHit GetTrackerHit(const edm4hep::ObjectID& id, bool delete_by_caller=true);
std::vector<edm4hep::SimTrackerHit> GetRelatedTrackerHit(const edm4hep::ObjectID& id);
#else
edm4hep::TrackerHit GetTrackerHit(const podio::ObjectID& id, bool delete_by_caller=true);
std::vector<edm4hep::SimTrackerHit> GetRelatedTrackerHit(const podio::ObjectID& id);
#endif
std::vector<edm4hep::SimTrackerHit> GetRelatedTrackerHit(const edm4hep::TrackerHit& hit);
std::vector<edm4hep::SimTrackerHit> GetRelatedTrackerHit(const edm4hep::TrackerHit& hit, const edm4hep::MCRecoTrackerAssociationCollection* col);

//static Navigation* m_fNavigation;
private:
Expand Down
23 changes: 20 additions & 3 deletions Utilities/DataHelper/src/Navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,19 @@ void Navigation::Initialize(){
m_trkHits.clear();
}

#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){
#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];
}
/*
for(int i=0;i<m_assColVec.size();i++){
for(auto ass : *m_assColVec[i]){
edm4hep::ObjectID rec_id = ass.getRec().getObjectID();
auto rec_id = ass.getRec().getObjectID();
if(rec_id.collectionID!=id.collectionID)break;
else if(rec_id.index==id.index){
m_trkHits.push_back(ass.getRec());
Expand All @@ -44,7 +48,7 @@ edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, b
*/
for(int i=0;i<m_hitColVec.size();i++){
for(auto hit : *m_hitColVec[i]){
edm4hep::ObjectID this_id = hit.getObjectID();
auto this_id = hit.getObjectID();
if(this_id.collectionID!=obj_id.collectionID)break;
else if(this_id.index==obj_id.index){
edm4hep::TrackerHit hit_copy = edm4hep::TrackerHit(hit);
Expand All @@ -57,11 +61,15 @@ edm4hep::TrackerHit Navigation::GetTrackerHit(const edm4hep::ObjectID& obj_id, b
throw std::runtime_error("Not found TrackerHit");
}

#if EDM4HEP_BUILD_VERSION <= EDM4HEP_VERSION(0, 10, 4)
std::vector<edm4hep::SimTrackerHit> Navigation::GetRelatedTrackerHit(const edm4hep::ObjectID& id){
#else
std::vector<edm4hep::SimTrackerHit> Navigation::GetRelatedTrackerHit(const podio::ObjectID& id){
#endif
std::vector<edm4hep::SimTrackerHit> hits;
for(int i=0;i<m_assColVec.size();i++){
for(auto ass : *m_assColVec[i]){
edm4hep::ObjectID this_id = ass.getRec().getObjectID();
auto this_id = ass.getRec().getObjectID();
if(this_id.collectionID!=id.collectionID)break;
else if(this_id.index==id.index) hits.push_back(ass.getSim());
}
Expand All @@ -79,3 +87,12 @@ std::vector<edm4hep::SimTrackerHit> Navigation::GetRelatedTrackerHit(const edm4h
}
return hits;
}

std::vector<edm4hep::SimTrackerHit> Navigation::GetRelatedTrackerHit(const edm4hep::TrackerHit& hit, const edm4hep::MCRecoTrackerAssociationCollection* col){
std::vector<edm4hep::SimTrackerHit> 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;
}
Loading