Skip to content

Commit

Permalink
returning nan for invalid 3vectors instead of bool
Browse files Browse the repository at this point in the history
  • Loading branch information
jstrube committed Nov 28, 2020
1 parent d0841c0 commit e28132b
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .ci/build_tarballs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ julia_version = v"1.5.3"
name = "LCIO_Julia_Wrapper"
version = get(ENV, "TRAVIS_TAG", "")
if version == ""
version = v"0.13.0-alpha4"
version = v"0.13.1-alpha1"
else
version = VersionNumber(version)
end
Expand Down
15 changes: 12 additions & 3 deletions src/CalorimeterHitTypes.icc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ lciowrap.add_type<EVENT::SimCalorimeterHit>("SimCalorimeterHit")
// returns a bool to indicate whether this was a nullptr
lciowrap.method("getPosition3", [](const EVENT::SimCalorimeterHit* hit, ArrayRef<double> x)->bool {
const float* p = hit->getPosition();
if (not p) return false;
if (not p) {
x[0] = nan("");
x[1] = nan("");
x[2] = nan("");
return false;
}
x[0] = p[0];
x[1] = p[1];
x[2] = p[2];
Expand All @@ -42,7 +47,12 @@ lciowrap.add_type<EVENT::CalorimeterHit>("CalorimeterHit", jlcxx::julia_base_typ
.method("getType", &EVENT::CalorimeterHit::getType);
lciowrap.method("getPosition3", [](const EVENT::CalorimeterHit* hit, ArrayRef<double> x)->bool {
const float* p = hit->getPosition();
if (not p) return false;
if (not p) {
x[0] = nan("");
x[1] = nan("");
x[2] = nan("");
return false;
}
x[0] = p[0];
x[1] = p[1];
x[2] = p[2];
Expand All @@ -53,7 +63,6 @@ lciowrap.method("_getPosition", [](const EVENT::CalorimeterHit* hit) {
if (not p) {
return make_tuple(nanf(""), nanf(""), nanf(""));
}

return make_tuple(p[0], p[1], p[2]);
});

Expand Down
7 changes: 6 additions & 1 deletion src/Cluster.icc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ lciowrap.method("getClusters", [](const EVENT::Cluster* c)->const std::vector<Cl

lciowrap.method("getPosition3", [](const EVENT::Cluster* c, ArrayRef<double> x)->bool {
const float* p3 = c->getPosition();
if (not p3) return false;
if (not p3) {
x[0] = nan("");
x[1] = nan("");
x[2] = nan("");
return false;
}
x[0] = p3[0];
x[1] = p3[1];
x[2] = p3[2];
Expand Down
28 changes: 24 additions & 4 deletions src/MCParticle.icc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ lciowrap.method("getDaughters", [](const EVENT::MCParticle* p)->const std::vecto
// returns a bool to indicate whether this was a nullptr
lciowrap.method("getVertex3", [](const EVENT::MCParticle* p, ArrayRef<double> v)->bool {
const double* vtx = p->getVertex();
if (not vtx) return false;
if (not vtx) {
v[0] = nan("");
v[1] = nan("");
v[2] = nan("");
return false;
}
v[0] = vtx[0];
v[1] = vtx[1];
v[2] = vtx[2];
Expand All @@ -49,7 +54,12 @@ lciowrap.method("_getVertex", [](const EVENT::MCParticle* p) {
// returns a bool to indicate whether this was a nullptr
lciowrap.method("getEndpoint3", [](const EVENT::MCParticle* p, ArrayRef<double> pos)->bool {
const double* endp = p->getEndpoint();
if (not endp) return false;
if (not endp) {
pos[0] = nan("");
pos[1] = nan("");
pos[2] = nan("");
return false;
}
pos[0] = endp[0];
pos[1] = endp[1];
pos[2] = endp[2];
Expand All @@ -66,7 +76,12 @@ lciowrap.method("_getEndpoint", [](const EVENT::MCParticle* p) {
// returns a bool to indicate whether this was a nullptr
lciowrap.method("getMomentum3", [](const EVENT::MCParticle* p, ArrayRef<double> p3)->bool {
const double* mom = p->getMomentum();
if (not mom) return false;
if (not mom) {
p3[0] = nan("");
p3[1] = nan("");
p3[2] = nan("");
return false;
}
p3[0] = mom[0];
p3[1] = mom[1];
p3[2] = mom[2];
Expand All @@ -83,7 +98,12 @@ lciowrap.method("_getMomentum", [](const EVENT::MCParticle* p) {
// returns a bool to indicate whether this was a nullptr
lciowrap.method("getMomentumAtEndpoint3", [](const EVENT::MCParticle* p, ArrayRef<double> p3)->bool {
const double* mom = p->getMomentumAtEndpoint();
if (not mom) return false;
if (not mom) {
p3[0] = nan("");
p3[1] = nan("");
p3[2] = nan("");
return false;
}
p3[0] = mom[0];
p3[1] = mom[1];
p3[2] = mom[2];
Expand Down
14 changes: 12 additions & 2 deletions src/ReconstructedParticle.icc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ lciowrap.add_type<EVENT::ReconstructedParticle>("ReconstructedParticle", jlcxx::

lciowrap.method("getMomentum3", [](const EVENT::ReconstructedParticle* p, ArrayRef<double> mom)->bool {
const double* p3 = p->getMomentum();
if (not p3) return false;
if (not p3) {
mom[0] = nan("");
mom[1] = nan("");
mom[2] = nan("");
return false;
}
mom[0] = p3[0];
mom[1] = p3[1];
mom[2] = p3[2];
Expand All @@ -32,7 +37,12 @@ lciowrap.method("_getMomentum", [](const EVENT::ReconstructedParticle* p) {

lciowrap.method("getReferencePoint3", [](const EVENT::ReconstructedParticle* p, ArrayRef<double> point)->bool {
const float* x = p->getReferencePoint();
if (not x) return false;
if (not x) {
point[0] = nan("");
point[1] = nan("");
point[2] = nan("");
return false;
}
point[0] = x[0];
point[1] = x[1];
point[2] = x[2];
Expand Down
14 changes: 12 additions & 2 deletions src/Track.icc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ jlcxx::stl::apply_stl<EVENT::TrackState*>(lciowrap);

lciowrap.method("getReferencePoint3", [](const EVENT::TrackState* t, ArrayRef<double> x)->bool {
const float* p3 = t->getReferencePoint();
if (not p3) return false;
if (not p3) {
x[0] = nan("");
x[1] = nan("");
x[2] = nan("");
return false;
}
x[0] = p3[0];
x[1] = p3[1];
x[2] = p3[2];
Expand Down Expand Up @@ -78,7 +83,12 @@ jlcxx::stl::apply_stl<EVENT::Track*>(lciowrap);

lciowrap.method("getReferencePoint3", [](const EVENT::Track* t, ArrayRef<double> x)->bool {
const float* p3 = t->getReferencePoint();
if (not p3) return false;
if (not p3) {
x[0] = nan("");
x[1] = nan("");
x[2] = nan("");
return false;
}
x[0] = p3[0];
x[1] = p3[1];
x[2] = p3[2];
Expand Down
21 changes: 18 additions & 3 deletions src/TrackerHitTypes.icc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ jlcxx::stl::apply_stl<EVENT::SimTrackerHit*>(lciowrap);
// returns a bool to indicate whether this was a nullptr
lciowrap.method("getPosition3", [](const EVENT::SimTrackerHit* hit, ArrayRef<double> x)->bool {
const double* p = hit->getPosition();
if (not p) return false;
if (not p) {
x[0] = nan("");
x[1] = nan("");
x[2] = nan("");
return false;
}
x[0] = p[0];
x[1] = p[1];
x[2] = p[2];
Expand All @@ -34,7 +39,12 @@ lciowrap.method("_getPosition", [](const EVENT::SimTrackerHit* hit) {
// returns a bool to indicate whether this was a nusllptr
lciowrap.method("getMomentum3", [](const EVENT::SimTrackerHit* hit, ArrayRef<double> x)->bool {
const float* p = hit->getMomentum();
if (not p) return false;
if (not p) {
x[0] = nan("");
x[1] = nan("");
x[2] = nan("");
return false;
}
x[0] = p[0];
x[1] = p[1];
x[2] = p[2];
Expand Down Expand Up @@ -62,7 +72,12 @@ lciowrap.add_type<EVENT::TrackerHit>("TrackerHit", jlcxx::julia_base_type<LCObje
// returns a bool to indicate whether this was a nullptr
lciowrap.method("getPosition3", [](const EVENT::TrackerHit* hit, ArrayRef<double> x)->bool {
const double* p = hit->getPosition();
if (not p) return false;
if (not p) {
x[0] = nan("");
x[1] = nan("");
x[2] = nan("");
return false;
}
x[0] = p[0];
x[1] = p[1];
x[2] = p[2];
Expand Down
7 changes: 6 additions & 1 deletion src/lciowrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ JLCXX_MODULE define_julia_module(jlcxx::Module& lciowrap)
.method("getParameters", &Vertex::getParameters);
lciowrap.method("getPosition3", [](const Vertex* v, ArrayRef<double> x)->bool {
const float* p3 = v->getPosition();
if (not p3) return false;
if (not p3) {
x[0] = nan("");
x[1] = nan("");
x[2] = nan("");
return false;
}
x[0] = p3[0];
x[1] = p3[1];
x[2] = p3[2];
Expand Down

0 comments on commit e28132b

Please sign in to comment.