Skip to content

Commit

Permalink
refactor: Improve Python import helpers (#1316)
Browse files Browse the repository at this point in the history
after my recent changes hepmc3 test will only run if the environment is sourced. this refactors the import helpers in order to fix that
  • Loading branch information
andiwand committed Jul 12, 2022
1 parent 4f7c265 commit 0717e5b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class EDM4hepSimHitReader final : public IReader {
std::vector<std::string> m_collections;

const edm4hep::MCParticleCollection* m_mcParticleCollection;

const Acts::Logger& logger() const { return *m_logger; }
};

} // namespace ActsExamples
3 changes: 1 addition & 2 deletions Examples/Io/EDM4hep/src/EDM4hepSimHitReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ ProcessCode EDM4hepSimHitReader::read(const AlgorithmContext& ctx) {
});
unordered.push_back(std::move(hit));
} catch (...) {
m_logger->log(Acts::Logging::Level::ERROR,
"EDM4hepSimHitReader: failed to convert SimTrackerHit");
ACTS_ERROR("EDM4hepSimHitReader: failed to convert SimTrackerHit");
continue;
}
}
Expand Down
3 changes: 3 additions & 0 deletions Examples/Python/python/acts/examples/edm4hep.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from acts._adapter import _patch_config
from acts import ActsPythonBindings

if not hasattr(ActsPythonBindings._examples, "_edm4hep"):
raise ImportError("ActsPythonBindings._examples._edm4hep not found")

_patch_config(ActsPythonBindings._examples._edm4hep)

from acts.ActsPythonBindings._examples._edm4hep import *
3 changes: 3 additions & 0 deletions Examples/Python/python/acts/examples/hepmc3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from acts._adapter import _patch_config
from acts import ActsPythonBindings

if not hasattr(ActsPythonBindings._examples, "_hepmc3"):
raise ImportError("ActsPythonBindings._examples._hepmc3 not found")

_patch_config(ActsPythonBindings._examples._hepmc3)

from acts.ActsPythonBindings._examples._hepmc3 import *
24 changes: 12 additions & 12 deletions Examples/Python/tests/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@
except ImportError:
dd4hepEnabled = False

hepmc3Enabled = "HepMC3_DIR" in os.environ
if hepmc3Enabled:
try:
import acts.examples.hepmc3
except ImportError:
hepmc3Enabled = False
try:
import acts.examples.hepmc3

edm4hepEnabled = "EDM4HEP_DIR" in os.environ
if edm4hepEnabled:
try:
import acts.examples.edm4hep
except ImportError:
edm4hepEnabled = False
hepmc3Enabled = True
except ImportError:
hepmc3Enabled = False

try:
import acts.examples.edm4hep

edm4hepEnabled = True
except ImportError:
edm4hepEnabled = False

isCI = os.environ.get("CI", "false") == "true"

Expand Down
2 changes: 1 addition & 1 deletion Examples/Python/tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def test_edm4hep_simhit_reader(tmp_path):

assert os.path.exists(tmp_file)

detector, _, _ = getOpenDataDetector()
detector, trackingGeometry, decorators = getOpenDataDetector()

s = Sequencer(numThreads=1)

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/OpenDataDetector
Submodule OpenDataDetector updated from 93277c to ef5718

0 comments on commit 0717e5b

Please sign in to comment.