File tree 8 files changed +114
-26
lines changed
8 files changed +114
-26
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ IndentPPDirectives: None
41
41
IndentWidth : 4
42
42
KeepEmptyLinesAtTheStartOfBlocks : true
43
43
MaxEmptyLinesToKeep : 2
44
- NamespaceIndentation : All
44
+ NamespaceIndentation : None
45
45
ObjCSpaceAfterProperty : false
46
46
ObjCSpaceBeforeProtocolList : true
47
47
PointerAlignment : Left
Original file line number Diff line number Diff line change 13
13
14
14
namespace geant4 {
15
15
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
+ };
36
36
37
37
}// namespace geant4
38
38
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 2
2
#ifndef GEANT4_APPLICATION_RUNACTION_H
3
3
#define GEANT4_APPLICATION_RUNACTION_H
4
4
5
+ #include < G4RunManager.hh>
5
6
#include < G4UserRunAction.hh>
6
7
7
- #include " awkward/LayoutBuilder .h"
8
+ #include " geant4/DataModel .h"
8
9
9
10
class RunAction : public G4UserRunAction {
10
11
public:
@@ -13,6 +14,11 @@ class RunAction : public G4UserRunAction {
13
14
void BeginOfRunAction (const G4Run*) override ;
14
15
15
16
void EndOfRunAction (const G4Run*) override ;
17
+
18
+ geant4::data::Builder& GetBuilder () { return builder; }
19
+
20
+ private:
21
+ geant4::data::Builder builder;
16
22
};
17
23
18
24
#endif // GEANT4_APPLICATION_RUNACTION_H
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
2
2
#include " geant4/RunAction.h"
3
- #include < G4Threading.hh>
4
3
#include < iostream>
5
4
6
5
using namespace std ;
7
6
8
7
RunAction::RunAction () : G4UserRunAction() {}
9
8
10
9
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
+ }
12
16
}
13
17
14
18
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
+ }
16
28
}
Original file line number Diff line number Diff line change 3
3
//
4
4
5
5
#include " geant4/TrackingAction.h"
6
+ #include " geant4/RunAction.h"
6
7
7
8
#include < G4ParticleDefinition.hh>
8
9
#include < G4ParticleTypes.hh>
@@ -17,6 +18,8 @@ using namespace std;
17
18
TrackingAction::TrackingAction () : G4UserTrackingAction() {}
18
19
19
20
void TrackingAction::PreUserTrackingAction (const G4Track* track) {
21
+ auto runAction = dynamic_cast <RunAction*>(const_cast <G4UserRunAction*>(G4RunManager::GetRunManager ()->GetUserRunAction ()));
22
+ // auto& builder = runAction->GetBuilder();
20
23
}
21
24
22
25
void TrackingAction::PostUserTrackingAction (const G4Track* track) {
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ const std::string gdml = R"(
49
49
TEST (Application, Run) {
50
50
Application app;
51
51
EXPECT_FALSE (app.IsSetup ());
52
- app.SetupManager ();
52
+ app.SetupManager (4 );
53
53
EXPECT_FALSE (app.IsSetup ());
54
54
app.SetupDetector (gdml);
55
55
EXPECT_FALSE (app.IsSetup ());
You can’t perform that action at this time.
0 commit comments