diff --git a/application/include/geant4/DataModel.h b/application/include/geant4/DataModel.h index 745740d..b6f7ae7 100644 --- a/application/include/geant4/DataModel.h +++ b/application/include/geant4/DataModel.h @@ -135,8 +135,12 @@ Builder MakeBuilder(); void InsertEventBegin(const G4Event* event, Builder& builder); void InsertEventEnd(const G4Event* event, Builder& builder); + void InsertTrackBegin(const G4Track* track, Builder& builder); void InsertTrackEnd(const G4Track* track, Builder& builder); + +void InsertEvent(const G4Event* event, Builder& builder); +void InsertTrack(const G4Track* track, Builder& builder); void InsertStep(const G4Step* step, Builder& builder); py::object SnapshotBuilder(Builder& builder); diff --git a/application/src/geant4/DataModel.cpp b/application/src/geant4/DataModel.cpp index 67e2efa..7199105 100644 --- a/application/src/geant4/DataModel.cpp +++ b/application/src/geant4/DataModel.cpp @@ -21,61 +21,38 @@ using namespace std; namespace geant4::data { -void InsertEventBegin(const G4Event* event, Builder& builder) { +void InsertEvent(const G4Event* event, Builder& builder) { builder.content().append(G4RunManager::GetRunManager()->GetCurrentRun()->GetRunID()); builder.content().append(event->GetEventID()); - // - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - // - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - builder.content().begin_list(); - - // builder.content().begin_list(); +} + +template +void InsertEventBeginHelper(Builder& builder) { + (builder.content().begin_list(), ...); +} + +void InsertEventBegin(const G4Event* event, Builder& builder) { + InsertEventBeginHelper(builder); +} + +template +void InsertEventEndHelper(Builder& builder) { + (builder.content().end_list(), ...); } void InsertEventEnd(const G4Event*, Builder& builder) { - builder.content().end_list(); - builder.content().end_list(); - builder.content().end_list(); - builder.content().end_list(); - builder.content().end_list(); - // builder.content().end_list(); - // builder.content().end_list(); - builder.content().end_list(); - builder.content().end_list(); - builder.content().end_list(); - builder.content().end_list(); - builder.content().end_list(); - builder.content().end_list(); - builder.content().end_list(); - // - builder.content().end_list(); - builder.content().end_list(); - // builder.content().end_list(); - // builder.content().end_list(); - // builder.content().end_list(); - builder.content().end_list(); - builder.content().end_list(); - builder.content().end_list(); - builder.content().end_list(); + InsertEventEndHelper(builder); } -void InsertTrackBegin(const G4Track* track, Builder& builder) { +void InsertTrack(const G4Track* track, Builder& builder) { builder.content().content().append(track->GetTrackID()); builder.content().content().append(track->GetParentID()); builder.content().content().append({}); @@ -90,30 +67,26 @@ void InsertTrackBegin(const G4Track* track, Builder& builder) { builder.content().content().append(track->GetMomentum().y() / units::momentum); builder.content().content().append(track->GetMomentum().z() / units::momentum); builder.content().content().append(track->GetWeight()); - // - builder.content().content().begin_list(); - builder.content().content().begin_list(); - // builder.content().content().begin_list(); - // builder.content().content().begin_list(); - // builder.content().content().begin_list(); - builder.content().content().begin_list(); - builder.content().content().begin_list(); - builder.content().content().begin_list(); - builder.content().content().begin_list(); - - // we should probably insert a step here to mark the beginning of the track / use stepping verbose +} + +template +void InsertTrackBeginHelper(Builder& builder) { + (builder.content().content().begin_list(), ...); +} + +void InsertTrackBegin(const G4Track* track, Builder& builder) { + InsertTrackBeginHelper(builder); +} + +template +void InsertTrackEndHelper(Builder& builder) { + (builder.content().content().end_list(), ...); } void InsertTrackEnd(const G4Track*, Builder& builder) { - builder.content().content().end_list(); - builder.content().content().end_list(); - // builder.content().content().end_list(); - // builder.content().content().end_list(); - // builder.content().content().end_list(); - builder.content().content().end_list(); - builder.content().content().end_list(); - builder.content().content().end_list(); - builder.content().content().end_list(); + InsertTrackEndHelper(builder); } void InsertStep(const G4Step* step, Builder& builder) { diff --git a/application/src/geant4/EventAction.cpp b/application/src/geant4/EventAction.cpp index d46567b..9dc1cce 100644 --- a/application/src/geant4/EventAction.cpp +++ b/application/src/geant4/EventAction.cpp @@ -11,6 +11,7 @@ EventAction::EventAction() : G4UserEventAction() {} void EventAction::BeginOfEventAction(const G4Event* event) { geant4::data::InsertEventBegin(event, RunAction::GetBuilder()); + geant4::data::InsertEvent(event, RunAction::GetBuilder()); } void EventAction::EndOfEventAction(const G4Event* event) { diff --git a/application/src/geant4/TrackingAction.cpp b/application/src/geant4/TrackingAction.cpp index 732a00e..5333cd0 100644 --- a/application/src/geant4/TrackingAction.cpp +++ b/application/src/geant4/TrackingAction.cpp @@ -16,6 +16,7 @@ TrackingAction::TrackingAction() : G4UserTrackingAction() {} void TrackingAction::PreUserTrackingAction(const G4Track* track) { geant4::data::InsertTrackBegin(track, RunAction::GetBuilder()); + geant4::data::InsertTrack(track, RunAction::GetBuilder()); } void TrackingAction::PostUserTrackingAction(const G4Track* track) { diff --git a/tests/test_application.py b/tests/test_application.py index 7d850d4..b463264 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -11,7 +11,8 @@ def test_setup_and_run(): app.setup_physics() app.setup_action() app.initialize() - app.run() + events = app.run(100) + assert len(events) == 100 def test_missing_setup(): @@ -28,6 +29,7 @@ def test_missing_manager(): app.setup_detector() +@pytest.mark.skip(reason="TODO") def test_multiple_apps(): # Could this work somehow? with pytest.raises(RuntimeError):