Skip to content

Commit

Permalink
Replace Link datatypes with type defs
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Sep 23, 2024
1 parent 2d62fb8 commit bd767db
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 209 deletions.
190 changes: 0 additions & 190 deletions edm4hep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -619,196 +619,6 @@ datatypes:
void setCovMatrix(float value, edm4hep::FourMomCoords dimI, edm4hep::FourMomCoords dimJ) { getCovMatrix().setValue(value, dimI, dimJ); }\n
"

edm4hep::RecoMCParticleLink:
Description: "Link between a ReconstructedParticle and the corresponding MCParticle"
Author: "EDM4hep authors"
Members:
- float weight // weight of this link
OneToOneRelations:
- edm4hep::ReconstructedParticle from // reference to the reconstructed particle
- edm4hep::MCParticle to // reference to the Monte-Carlo particle
ExtraCode:
declaration: "
[[deprecated(\"use getFrom instead\")]] edm4hep::ReconstructedParticle getRec() const;\n
[[deprecated(\"use getTo instead\")]] edm4hep::MCParticle getSim() const;\n"
implementation: "
edm4hep::ReconstructedParticle {name}::getRec() const { return getFrom(); }\n
edm4hep::MCParticle {name}::getSim() const { return getTo(); }\n"
MutableExtraCode:
declaration: "
[[deprecated(\"use setFrom instead\")]]\n
void setRec(const edm4hep::ReconstructedParticle& rec);\n
[[deprecated(\"use setTo instead\")]]\n
void setSim(const edm4hep::MCParticle& sim);\n
"
implementation: "
void {name}::setSim(const edm4hep::MCParticle& sim) { setTo(sim); }\n
void {name}::setRec(const edm4hep::ReconstructedParticle& rec) { setFrom(rec); }\n
"

edm4hep::CaloHitSimCaloHitLink:
Description: "Link between a CalorimeterHit and the corresponding SimCalorimeterHit"
Author: "EDM4hep authors"
Members:
- float weight // weight of this link
OneToOneRelations:
- edm4hep::CalorimeterHit from // reference to the reconstructed hit
- edm4hep::SimCalorimeterHit to // reference to the simulated hit
ExtraCode:
declaration: "
[[deprecated(\"use getFrom instead\")]] edm4hep::CalorimeterHit getRec() const;\n
[[deprecated(\"use getTo instead\")]] edm4hep::SimCalorimeterHit getSim() const;\n"
implementation: "
edm4hep::CalorimeterHit {name}::getRec() const { return getFrom(); }\n
edm4hep::SimCalorimeterHit {name}::getSim() const { return getTo(); }\n"
MutableExtraCode:
declaration: "
[[deprecated(\"use setFrom instead\")]]\n
void setRec(const edm4hep::CalorimeterHit& rec);\n
[[deprecated(\"use setTo instead\")]]\n
void setSim(const edm4hep::SimCalorimeterHit& sim);\n
"
implementation: "
void {name}::setSim(const edm4hep::SimCalorimeterHit& sim) { setTo(sim); }\n
void {name}::setRec(const edm4hep::CalorimeterHit& rec) { setFrom(rec); }\n
"


edm4hep::TrackerHitSimTrackerHitLink:
Description: "Link between a TrackerHit and the corresponding SimTrackerHit"
Author: "EDM4hep authors"
Members:
- float weight // weight of this link
OneToOneRelations:
- edm4hep::TrackerHit from // reference to the reconstructed hit
- edm4hep::SimTrackerHit to // reference to the simulated hit
ExtraCode:
declaration: "
[[deprecated(\"use getFrom instead\")]] edm4hep::TrackerHit getRec() const;\n
[[deprecated(\"use getTo instead\")]] edm4hep::SimTrackerHit getSim() const;\n"
implementation: "
edm4hep::TrackerHit {name}::getRec() const { return getFrom(); }\n
edm4hep::SimTrackerHit {name}::getSim() const { return getTo(); }\n"
MutableExtraCode:
declaration: "
[[deprecated(\"use setFrom instead\")]]\n
void setRec(const edm4hep::TrackerHit& rec);\n
[[deprecated(\"use setTo instead\")]]\n
void setSim(const edm4hep::SimTrackerHit& sim);\n
"
implementation: "
void {name}::setSim(const edm4hep::SimTrackerHit& sim) { setTo(sim); }\n
void {name}::setRec(const edm4hep::TrackerHit& rec) { setFrom(rec); }\n
"

edm4hep::CaloHitMCParticleLink:
Description: "Link between a CalorimeterHit and the corresponding MCParticle"
Author: "EDM4hep authors"
Members:
- float weight // weight of this link
OneToOneRelations:
- edm4hep::CalorimeterHit from // reference to the reconstructed hit
- edm4hep::MCParticle to // reference to the Monte-Carlo particle
ExtraCode:
declaration: "
[[deprecated(\"use getFrom instead\")]] edm4hep::CalorimeterHit getRec() const;\n
[[deprecated(\"use getTo instead\")]] edm4hep::MCParticle getSim() const;\n"
implementation: "
edm4hep::CalorimeterHit {name}::getRec() const { return getFrom(); }\n
edm4hep::MCParticle {name}::getSim() const { return getTo(); }\n"
MutableExtraCode:
declaration: "
[[deprecated(\"use setFrom instead\")]]\n
void setRec(const edm4hep::CalorimeterHit& rec);\n
[[deprecated(\"use setTo instead\")]]\n
void setSim(const edm4hep::MCParticle& sim);\n
"
implementation: "
void {name}::setSim(const edm4hep::MCParticle& sim) { setTo(sim); }\n
void {name}::setRec(const edm4hep::CalorimeterHit& rec) { setFrom(rec); }\n
"

edm4hep::ClusterMCParticleLink:
Description: "Link between a Cluster and the corresponding MCParticle"
Author: "EDM4hep authors"
Members:
- float weight // weight of this link
OneToOneRelations:
- edm4hep::Cluster from // reference to the cluster
- edm4hep::MCParticle to // reference to the Monte-Carlo particle
ExtraCode:
declaration: "
[[deprecated(\"use getFrom instead\")]] edm4hep::Cluster getRec() const;\n
[[deprecated(\"use getTo instead\")]] edm4hep::MCParticle getSim() const;\n"
implementation: "
edm4hep::Cluster {name}::getRec() const { return getFrom(); }\n
edm4hep::MCParticle {name}::getSim() const { return getTo(); }\n"
MutableExtraCode:
declaration: "
[[deprecated(\"use setFrom instead\")]]\n
void setRec(const edm4hep::Cluster& rec);\n
[[deprecated(\"use setTo instead\")]]\n
void setSim(const edm4hep::MCParticle& sim);\n
"
implementation: "
void {name}::setSim(const edm4hep::MCParticle& sim) { setTo(sim); }\n
void {name}::setRec(const edm4hep::Cluster& rec) { setFrom(rec); }\n
"

edm4hep::TrackMCParticleLink:
Description: "Link between a Track and the corresponding MCParticle"
Author: "EDM4hep authors"
Members:
- float weight // weight of this link
OneToOneRelations:
- edm4hep::Track from // reference to the track
- edm4hep::MCParticle to // reference to the Monte-Carlo particle
ExtraCode:
declaration: "
[[deprecated(\"use getFrom instead\")]] edm4hep::Track getRec() const;\n
[[deprecated(\"use getTo instead\")]] edm4hep::MCParticle getSim() const;\n"
implementation: "
edm4hep::Track {name}::getRec() const { return getFrom(); }\n
edm4hep::MCParticle {name}::getSim() const { return getTo(); }\n"
MutableExtraCode:
declaration: "
[[deprecated(\"use setFrom instead\")]]\n
void setRec(const edm4hep::Track& rec);\n
[[deprecated(\"use setTo instead\")]]\n
void setSim(const edm4hep::MCParticle& sim);\n
"
implementation: "
void {name}::setSim(const edm4hep::MCParticle& sim) { setTo(sim); }\n
void {name}::setRec(const edm4hep::Track& rec) { setFrom(rec); }\n
"

edm4hep::VertexRecoParticleLink:
Description: "Link between a Vertex and a ReconstructedParticle"
Author: "EDM4hep authors"
Members:
- float weight // weight of this link
OneToOneRelations:
- edm4hep::ReconstructedParticle to // reference to the reconstructed particle
- edm4hep::Vertex from // reference to the vertex
ExtraCode:
declaration: "
[[deprecated(\"use getTo instead\")]] edm4hep::ReconstructedParticle getRec() const;\n
[[deprecated(\"use getFrom instead\")]] edm4hep::Vertex getVertex() const;\n"
implementation: "
edm4hep::ReconstructedParticle {name}::getRec() const { return getTo(); }\n
edm4hep::Vertex {name}::getVertex() const { return getFrom(); }\n"
MutableExtraCode:
declaration: "
[[deprecated(\"use setFrom instead\")]]\n
void setVertex(const edm4hep::Vertex& rec);\n
[[deprecated(\"use setTo instead\")]]\n
void setRec(const edm4hep::ReconstructedParticle& sim);\n
"
implementation: "
void {name}::setVertex(const edm4hep::Vertex& vertex) { setFrom(vertex); }\n
void {name}::setRec(const edm4hep::ReconstructedParticle& rec) { setTo(rec); }\n
"


edm4hep::TimeSeries:
Description: "Calibrated Detector Data"
Expand Down
1 change: 1 addition & 0 deletions edm4hep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PODIO_GENERATE_DATAMODEL(edm4hep ../edm4hep.yaml headers sources
DEPENDS ${extra_code}
VERSION ${${PROJECT_NAME}_VERSION}
)
list(APPEND sources src/LinkCollectionDeclarations.cc)

PODIO_ADD_DATAMODEL_CORE_LIB(edm4hep "${headers}" "${sources}")
target_include_directories(edm4hep PUBLIC
Expand Down
15 changes: 15 additions & 0 deletions edm4hep/src/LinkCollectionDeclarations.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "edm4hep/CaloHitMCParticleLinkCollection.h"
#include "edm4hep/CaloHitSimCaloHitLinkCollection.h"
#include "edm4hep/ClusterMCParticleLinkCollection.h"
#include "edm4hep/RecoMCParticleLinkCollection.h"
#include "edm4hep/TrackMCParticleLinkCollection.h"
#include "edm4hep/TrackerHitSimTrackerHitLinkCollection.h"
#include "edm4hep/VertexRecoParticleLinkCollection.h"

PODIO_DECLARE_LINK(edm4hep::ReconstructedParticle, edm4hep::MCParticle)
PODIO_DECLARE_LINK(edm4hep::TrackerHit, edm4hep::SimTrackerHit)
PODIO_DECLARE_LINK(edm4hep::Track, edm4hep::MCParticle)
PODIO_DECLARE_LINK(edm4hep::Cluster, edm4hep::MCParticle)
PODIO_DECLARE_LINK(edm4hep::CalorimeterHit, edm4hep::SimCalorimeterHit)
PODIO_DECLARE_LINK(edm4hep::CalorimeterHit, edm4hep::MCParticle)
PODIO_DECLARE_LINK(edm4hep::Vertex, edm4hep::ReconstructedParticle)
13 changes: 13 additions & 0 deletions include/edm4hep/CaloHitMCParticleLinkCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef EDM4HEP_CALOHITMCPARTICLELINKCOLLECTION_H
#define EDM4HEP_CALOHITMCPARTICLELINKCOLLECTION_H

#include <podio/LinkCollection.h>

#include <edm4hep/CalorimeterHitCollection.h>
#include <edm4hep/MCParticleCollection.h>

namespace edm4hep {
using CaloHitMCParticleLinkCollection = podio::LinkCollection<edm4hep::CalorimeterHit, edm4hep::MCParticle>;
} // namespace edm4hep

#endif // EDM4HEP_CALOHITMCPARTICLELINKCOLLECTION_H
13 changes: 13 additions & 0 deletions include/edm4hep/CaloHitSimCaloHitLinkCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef EDM4HEP_CALOHITSIMCALOHITLINKCOLLECTION_H
#define EDM4HEP_CALOHITSIMCALOHITLINKCOLLECTION_H

#include <podio/LinkCollection.h>

#include <edm4hep/CalorimeterHitCollection.h>
#include <edm4hep/SimCalorimeterHitCollection.h>

namespace edm4hep {
using CaloHitSimCaloHitLinkCollection = podio::LinkCollection<edm4hep::CalorimeterHit, edm4hep::SimCalorimeterHit>;
} // namespace edm4hep

#endif // EDM4HEP_CALOHITSIMCALOHITLINKCOLLECTION_H
13 changes: 13 additions & 0 deletions include/edm4hep/ClusterMCParticleLinkCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef EDM4HEP_CLUSTERMCPARTICLELINKCOLLECTION_H
#define EDM4HEP_CLUSTERMCPARTICLELINKCOLLECTION_H

#include <podio/LinkCollection.h>

#include <edm4hep/ClusterCollection.h>
#include <edm4hep/MCParticleCollection.h>

namespace edm4hep {
using ClusterMCParticleLinkCollection = podio::LinkCollection<edm4hep::Cluster, edm4hep::MCParticle>;
} // namespace edm4hep

#endif // EDM4HEP_CLUSTERMCPARTICLELINKCOLLECTION_H
13 changes: 13 additions & 0 deletions include/edm4hep/RecoMCParticleLinkCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef EDM4HEP_RECOMCPARTICLELINKCOLLECTION_H
#define EDM4HEP_RECOMCPARTICLELINKCOLLECTION_H

#include <podio/LinkCollection.h>

#include <edm4hep/MCParticleCollection.h>
#include <edm4hep/ReconstructedParticleCollection.h>

namespace edm4hep {
using RecoMCParticleLinkCollection = podio::LinkCollection<edm4hep::ReconstructedParticle, edm4hep::MCParticle>;
} // namespace edm4hep

#endif // EDM4HEP_RECOMCPARTICLELINKCOLLECTION_H
13 changes: 13 additions & 0 deletions include/edm4hep/TrackMCParticleLinkCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef EDM4HEP_TRACKMCPARTICLELINKCOLLECTION_H
#define EDM4HEP_TRACKMCPARTICLELINKCOLLECTION_H

#include <podio/LinkCollection.h>

#include <edm4hep/MCParticleCollection.h>
#include <edm4hep/TrackCollection.h>

namespace edm4hep {
using TrackMCParticleLinkCollection = podio::LinkCollection<edm4hep::Track, edm4hep::MCParticle>;
} // namespace edm4hep

#endif // EDM4HEP_CLUSTERMCPARTICLELINKCOLLECTION_H
13 changes: 13 additions & 0 deletions include/edm4hep/TrackerHitSimTrackerHitLinkCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef EDM4HEP_TRACKERHITSIMTRACKERHITLINKCOLLECTION_H
#define EDM4HEP_TRACKERHITSIMTRACKERHITLINKCOLLECTION_H

#include <podio/LinkCollection.h>

#include <edm4hep/SimTrackerHitCollection.h>
#include <edm4hep/TrackerHit.h>

namespace edm4hep {
using TrackerHitSimTrackerHitLinkCollection = podio::LinkCollection<edm4hep::TrackerHit, edm4hep::SimTrackerHit>;
} // namespace edm4hep

#endif // EDM4HEP_TRACKERHITSIMTRACKERHITLINKCOLLECTION_H
13 changes: 13 additions & 0 deletions include/edm4hep/VertexRecoParticleLinkCollection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef EDM4HEP_CLUSTERRECONSTRUCTEDPARTICLELINKCOLLECTION_H
#define EDM4HEP_CLUSTERRECONSTRUCTEDPARTICLELINKCOLLECTION_H

#include <podio/LinkCollection.h>

#include <edm4hep/ReconstructedParticleCollection.h>
#include <edm4hep/VertexCollection.h>

namespace edm4hep {
using VertexRecoParticleLinkCollection = podio::LinkCollection<edm4hep::Vertex, edm4hep::ReconstructedParticle>;
} // namespace edm4hep

#endif // EDM4HEP_CLUSTERRECONSTRUCTEDPARTICLELINKCOLLECTION_H
40 changes: 28 additions & 12 deletions python/edm4hep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,48 @@

from .__version__ import __version__
import ROOT
res = ROOT.gSystem.Load('libedm4hepDict')

res = ROOT.gSystem.Load("libedm4hepDict")
if res < 0:
raise RuntimeError('Failed to load libedm4hepDict')
raise RuntimeError("Failed to load libedm4hepDict")

res = ROOT.gSystem.Load('libedm4hepRDF')
res = ROOT.gSystem.Load("libedm4hepRDF")
if res < 0:
raise RuntimeError('Failed to load libedm4hepRDF')
raise RuntimeError("Failed to load libedm4hepRDF")

res = ROOT.gInterpreter.LoadFile('edm4hep/utils/kinematics.h')
res = ROOT.gInterpreter.LoadFile("edm4hep/utils/kinematics.h")
if res != 0:
raise RuntimeError('Failed to load kinematics.h')
raise RuntimeError("Failed to load kinematics.h")

res = ROOT.gInterpreter.LoadFile('edm4hep/utils/dataframe.h')
res = ROOT.gInterpreter.LoadFile("edm4hep/utils/dataframe.h")
if res != 0:
raise RuntimeError('Failed to load dataframe.h')
raise RuntimeError("Failed to load dataframe.h")

res = ROOT.gInterpreter.LoadFile('edm4hep/Constants.h')
res = ROOT.gInterpreter.LoadFile("edm4hep/Constants.h")
if res != 0:
raise RuntimeError('Failed to load Constants.h')
raise RuntimeError("Failed to load Constants.h")

_LINK_COLLS = [
"RecoMCParticle",
"CaloHitMCParticle",
"CaloHitSimCaloHit",
"ClusterMCParticle",
"TrackMCParticle",
"TrackerHitSimTrackerHit",
"VertexRecoParticle",
]

for lc in _LINK_COLLS:
if ROOT.gInterpreter.LoadFile(f"edm4hep/{lc}LinkCollection.h") != 0:
raise RuntimeError(f"Failed to load {lc}LinkCollection.h")

from ROOT import edm4hep

from podio.pythonizations import load_pythonizations
load_pythonizations('edm4hep')

# Make TAB completion work for utils
setattr(edm4hep, 'utils', edm4hep.utils)
setattr(edm4hep, "utils", edm4hep.utils)

# set package attributes for edm4hep
edm4hep.__version__ = __version__
Expand All @@ -38,4 +54,4 @@
edm4hep.__file__ = __file__

# Make `import edm4hep` work
sys.modules['edm4hep'] = edm4hep
sys.modules["edm4hep"] = edm4hep
Loading

0 comments on commit bd767db

Please sign in to comment.