Skip to content

Commit 6eabab5

Browse files
committed
filling some arrays
1 parent cd7563f commit 6eabab5

File tree

8 files changed

+114
-26
lines changed

8 files changed

+114
-26
lines changed

application/.clang-format .clang-format

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ IndentPPDirectives: None
4141
IndentWidth: 4
4242
KeepEmptyLinesAtTheStartOfBlocks: true
4343
MaxEmptyLinesToKeep: 2
44-
NamespaceIndentation: All
44+
NamespaceIndentation: None
4545
ObjCSpaceAfterProperty: false
4646
ObjCSpaceBeforeProtocolList: true
4747
PointerAlignment: Left

application/include/geant4/Application.h

+20-20
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@
1313

1414
namespace geant4 {
1515

16-
class Application {
17-
private:
18-
std::unique_ptr<G4RunManager> runManager = nullptr;
19-
bool isInitialized = false;
20-
21-
public:
22-
Application();
23-
~Application() = default;
24-
25-
void SetupManager(unsigned short nThreads = 0);
26-
void SetupDetector(std::string gdml, const std::set<std::string>& sensitiveVolumes = {});
27-
void SetupPhysics();
28-
void SetupAction();
29-
30-
void Initialize();
31-
void Run(int nEvents);
32-
33-
bool IsSetup() const;
34-
bool IsInitialized() const;
35-
};
16+
class Application {
17+
private:
18+
std::unique_ptr<G4RunManager> runManager = nullptr;
19+
bool isInitialized = false;
20+
21+
public:
22+
Application();
23+
~Application() = default;
24+
25+
void SetupManager(unsigned short nThreads = 0);
26+
void SetupDetector(std::string gdml, const std::set<std::string>& sensitiveVolumes = {});
27+
void SetupPhysics();
28+
void SetupAction();
29+
30+
void Initialize();
31+
void Run(int nEvents);
32+
33+
bool IsSetup() const;
34+
bool IsInitialized() const;
35+
};
3636

3737
}// namespace geant4
3838

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef GEANT4PYTHONICAPPLICATION_DATAMODEL_H
2+
#define GEANT4PYTHONICAPPLICATION_DATAMODEL_H
3+
4+
#include "awkward/LayoutBuilder.h"
5+
6+
class G4Event;
7+
class G4Track;
8+
class G4Step;
9+
10+
namespace geant4::data {
11+
12+
// Enum to represent fields
13+
enum Field : std::size_t { energy,
14+
time };
15+
16+
using UserDefinedMap = std::map<std::size_t, std::string>;
17+
18+
19+
template<std::size_t field_name, class BUILDER>
20+
using RecordField = awkward::LayoutBuilder::Field<field_name, BUILDER>;
21+
22+
template<class... BUILDERS>
23+
using RecordBuilder = awkward::LayoutBuilder::Record<UserDefinedMap, BUILDERS...>;
24+
25+
template<class PRIMITIVE>
26+
using NumpyBuilder = awkward::LayoutBuilder::Numpy<PRIMITIVE>;
27+
28+
using Builder = RecordBuilder<RecordField<static_cast<std::size_t>(Field::energy), NumpyBuilder<double>>,
29+
RecordField<static_cast<std::size_t>(Field::time), NumpyBuilder<double>>>;
30+
31+
32+
void InsertEvent(const G4Event* track, Builder& builder);
33+
void InsertTrack(const G4Track* track, Builder& builder);
34+
void InsertStep(const G4Event* track, Builder& builder);
35+
36+
}// namespace geant4::data
37+
38+
39+
#endif// GEANT4PYTHONICAPPLICATION_DATAMODEL_H

application/include/geant4/RunAction.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#ifndef GEANT4_APPLICATION_RUNACTION_H
33
#define GEANT4_APPLICATION_RUNACTION_H
44

5+
#include <G4RunManager.hh>
56
#include <G4UserRunAction.hh>
67

7-
#include "awkward/LayoutBuilder.h"
8+
#include "geant4/DataModel.h"
89

910
class RunAction : public G4UserRunAction {
1011
public:
@@ -13,6 +14,11 @@ class RunAction : public G4UserRunAction {
1314
void BeginOfRunAction(const G4Run*) override;
1415

1516
void EndOfRunAction(const G4Run*) override;
17+
18+
geant4::data::Builder& GetBuilder() { return builder; }
19+
20+
private:
21+
geant4::data::Builder builder;
1622
};
1723

1824
#endif// GEANT4_APPLICATION_RUNACTION_H

application/src/geant4/DataModel.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
#include "geant4/DataModel.h"
3+
4+
#include <G4Event.hh>
5+
#include <G4ParticleDefinition.hh>
6+
#include <G4ParticleTypes.hh>
7+
#include <G4Step.hh>
8+
#include <G4SystemOfUnits.hh>
9+
#include <G4Track.hh>
10+
#include <G4UnitsTable.hh>
11+
#include <iostream>
12+
13+
14+
using namespace geant4::data;
15+
16+
void InsertEvent(const G4Event* event, Builder& builder) {
17+
}
18+
19+
void InsertTrack(const G4Track* track, Builder& builder) {
20+
auto& energyBuilder = builder.content<Field::energy>();
21+
auto& timeBuilder = builder.content<Field::time>();
22+
23+
energyBuilder.append(track->GetKineticEnergy());
24+
timeBuilder.append(track->GetGlobalTime());
25+
}
26+
27+
void InsertStep(const G4Step* step, Builder& builder) {
28+
}

application/src/geant4/RunAction.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11

22
#include "geant4/RunAction.h"
3-
#include <G4Threading.hh>
43
#include <iostream>
54

65
using namespace std;
76

87
RunAction::RunAction() : G4UserRunAction() {}
98

109
void RunAction::BeginOfRunAction(const G4Run*) {
11-
cout << "Begin of run for thread " << G4Threading::G4GetThreadId() << endl;
10+
11+
if (IsMaster()) {
12+
cout << "RunAction::BeginOfRunAction" << endl;
13+
} else {
14+
cout << "RunAction::BeginOfRunAction (worker)" << endl;
15+
}
1216
}
1317

1418
void RunAction::EndOfRunAction(const G4Run*) {
15-
G4cout << "END OF RUN" << G4endl;
19+
if (IsMaster()) {
20+
cout << "RunAction::EndOfRunAction" << endl;
21+
} else {
22+
cout << "RunAction::EndOfRunAction (worker)" << endl;
23+
string error;
24+
if (!builder.is_valid(error)) {
25+
throw std::runtime_error("Builder is not valid: " + error);
26+
}
27+
}
1628
}

application/src/geant4/TrackingAction.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//
44

55
#include "geant4/TrackingAction.h"
6+
#include "geant4/RunAction.h"
67

78
#include <G4ParticleDefinition.hh>
89
#include <G4ParticleTypes.hh>
@@ -17,6 +18,8 @@ using namespace std;
1718
TrackingAction::TrackingAction() : G4UserTrackingAction() {}
1819

1920
void TrackingAction::PreUserTrackingAction(const G4Track* track) {
21+
auto runAction = dynamic_cast<RunAction*>(const_cast<G4UserRunAction*>(G4RunManager::GetRunManager()->GetUserRunAction()));
22+
// auto& builder = runAction->GetBuilder();
2023
}
2124

2225
void TrackingAction::PostUserTrackingAction(const G4Track* track) {

application/tests/testApplication.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const std::string gdml = R"(
4949
TEST(Application, Run) {
5050
Application app;
5151
EXPECT_FALSE(app.IsSetup());
52-
app.SetupManager();
52+
app.SetupManager(4);
5353
EXPECT_FALSE(app.IsSetup());
5454
app.SetupDetector(gdml);
5555
EXPECT_FALSE(app.IsSetup());

0 commit comments

Comments
 (0)