Skip to content

Commit

Permalink
fix macos compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
tkittel committed Feb 10, 2024
1 parent ebb7d41 commit acaa671
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

#include "G4Interfaces/GeoConstructPyExport.hh"

class GeoEmptyWorld : public G4Interfaces::GeoConstructBase
class GeoEmptyWorld final : public G4Interfaces::GeoConstructBase
{
public:
GeoEmptyWorld();
virtual ~GeoEmptyWorld(){}
G4VPhysicalVolume* Construct();
G4VPhysicalVolume* Construct() override;
};

PYTHON_MODULE( mod ) { GeoConstructPyExport::exportGeo<GeoEmptyWorld>(mod, "GeoEmptyWorld"); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

#include "G4Interfaces/GeoConstructPyExport.hh"

class GeoSlab : public G4Interfaces::GeoConstructBase
class GeoSlab final : public G4Interfaces::GeoConstructBase
{
public:
GeoSlab();
virtual ~GeoSlab(){}
G4VPhysicalVolume* Construct();
G4VPhysicalVolume* Construct() override;
bool validateParameters() override;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ namespace G4Interfaces {

//NB: Very important for python export that first listed base-class is GeoBase!

class GeoConstructBase : public GeoBase, public G4VUserDetectorConstruction
{
class GeoConstructBase : public GeoBase, public G4VUserDetectorConstruction {
public:
//Derived classes must:
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
namespace PhysicsListPyExport {

template <class T>
class Provider : public G4Interfaces::PhysListProviderBase {
class Provider final : public G4Interfaces::PhysListProviderBase {
public:
Provider(const char*name) : G4Interfaces::PhysListProviderBase(name) {}
virtual ~Provider(){}
virtual G4VUserPhysicsList * construct() {
G4VUserPhysicsList * construct() override {
return new T;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,32 @@
#include "G4UIterminal.hh"
#include "G4UItcsh.hh"

class DummyGeo : public G4Interfaces::GeoConstructBase {
public:

DummyGeo() : GeoConstructBase("DummyGeo")
{
addParameterDouble("boxThickness",1*Units::um,0.01*Units::um,300*Units::cm);
}

G4VPhysicalVolume* Construct()
{
G4Material* mat_galactic = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic",true);
G4Material* mat_boroncarbide = G4NistManager::Instance()->FindOrBuildMaterial("G4_BORON_CARBIDE",true);
G4Box* solidWorld = new G4Box("World", 10*Units::meter,10*Units::meter,10*Units::meter);
G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, mat_galactic, "World");
auto pv_world = new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), logicWorld, "World", 0, false, 0);
G4Box* solidBox = new G4Box("SldSomeBox", 5*Units::meter,5*Units::meter,getParameterDouble("boxThickness")*0.5);
auto logicBox= new G4LogicalVolume(solidBox, mat_boroncarbide, "LVSomeBox");
new G4PVPlacement(0, G4ThreeVector(0.0,0.0,0.0),"PVSomeBox", logicBox, pv_world, false, 0, true);

logicWorld -> SetVisAttributes (G4VisAttributes::GetInvisible());

return pv_world;
}
};
namespace {
class DummyGeo final : public G4Interfaces::GeoConstructBase {
public:

DummyGeo() : GeoConstructBase("DummyGeo")
{
addParameterDouble("boxThickness",1*Units::um,0.01*Units::um,300*Units::cm);
}

G4VPhysicalVolume* Construct() override
{
G4Material* mat_galactic = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic",true);
G4Material* mat_boroncarbide = G4NistManager::Instance()->FindOrBuildMaterial("G4_BORON_CARBIDE",true);
G4Box* solidWorld = new G4Box("World", 10*Units::meter,10*Units::meter,10*Units::meter);
G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, mat_galactic, "World");
auto pv_world = new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), logicWorld, "World", 0, false, 0);
G4Box* solidBox = new G4Box("SldSomeBox", 5*Units::meter,5*Units::meter,getParameterDouble("boxThickness")*0.5);
auto logicBox= new G4LogicalVolume(solidBox, mat_boroncarbide, "LVSomeBox");
new G4PVPlacement(0, G4ThreeVector(0.0,0.0,0.0),"PVSomeBox", logicBox, pv_world, false, 0, true);

logicWorld -> SetVisAttributes (G4VisAttributes::GetInvisible());

return pv_world;
}
};
}

int main(int,char**) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

#include "G4Interfaces/GeoConstructPyExport.hh"

class GeoSkeletonSP : public G4Interfaces::GeoConstructBase
class GeoSkeletonSP final : public G4Interfaces::GeoConstructBase
{
public:
GeoSkeletonSP();
virtual ~GeoSkeletonSP(){}
virtual G4VPhysicalVolume* Construct();
G4VPhysicalVolume* Construct() override;
//(add more member functions and data here if needed)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,69 +11,74 @@
#include "G4UserSteppingAction.hh"
#include <functional>

class DummyGeo : public G4Interfaces::GeoConstructBase {
public:
namespace {
class DummyGeo final : public G4Interfaces::GeoConstructBase {
public:

DummyGeo() : GeoConstructBase("DummyGeo")
{
addParameterDouble("boxThickness",1*Units::um,0.01*Units::um,300*Units::cm);
}
DummyGeo() : GeoConstructBase("DummyGeo")
{
addParameterDouble("boxThickness",1*Units::um,0.01*Units::um,300*Units::cm);
}

G4VPhysicalVolume* Construct() override
{
G4Material* mat_galactic = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic",true);
G4Material* mat_boroncarbide = G4NistManager::Instance()->FindOrBuildMaterial("G4_BORON_CARBIDE",true);
G4Box* solidWorld = new G4Box("World", 10*Units::meter,10*Units::meter,10*Units::meter);
G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, mat_galactic, "World");
auto pv_world = new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), logicWorld, "World", 0, false, 0);
G4Box* solidBox = new G4Box("SldSomeBox", 5*Units::meter,5*Units::meter,getParameterDouble("boxThickness")*0.5);
auto logicBox= new G4LogicalVolume(solidBox, mat_boroncarbide, "LVSomeBox");
new G4PVPlacement(0, G4ThreeVector(0.0,0.0,0.0),"PVSomeBox", logicBox, pv_world, false, 0, true);

return pv_world;
}
};

G4VPhysicalVolume* Construct()
std::function<bool(const G4Step*)> createG4StepFilter_opt1(const char * expr)
{
G4Material* mat_galactic = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic",true);
G4Material* mat_boroncarbide = G4NistManager::Instance()->FindOrBuildMaterial("G4_BORON_CARBIDE",true);
G4Box* solidWorld = new G4Box("World", 10*Units::meter,10*Units::meter,10*Units::meter);
G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, mat_galactic, "World");
auto pv_world = new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), logicWorld, "World", 0, false, 0);
G4Box* solidBox = new G4Box("SldSomeBox", 5*Units::meter,5*Units::meter,getParameterDouble("boxThickness")*0.5);
auto logicBox= new G4LogicalVolume(solidBox, mat_boroncarbide, "LVSomeBox");
new G4PVPlacement(0, G4ThreeVector(0.0,0.0,0.0),"PVSomeBox", logicBox, pv_world, false, 0, true);

return pv_world;
}
};

std::function<bool(const G4Step*)> createG4StepFilter_opt1(const char * expr)
{
//Test implementation of how to create a self-contained filter function based
//on an expression containing G4Step related variables, including proper
//lifetime management of instantiated objects (leaving it here, just for a
//compilation check):

//Using shared rather than unique ptr here, since we can't capture-by-move until c++14:
auto builder = std::make_shared<G4ExprParser::G4SteppingASTBuilder>();
auto evaluator = builder->createEvaluator<bool>(expr);
return [builder,evaluator](const G4Step* step) mutable->bool { builder->setCurrentStep(step); return evaluator(); };
}
class CustomStepAct : public G4UserSteppingAction {

G4ExprParser::G4SteppingASTBuilder m_builder;
ExprParser::Evaluator<ExprParser::float_type> m_eval_value;
ExprParser::Evaluator<bool> m_eval_filter;
public:

CustomStepAct(const char * filter_expr, const char * value_expr) : G4UserSteppingAction() {
m_eval_filter = m_builder.createEvaluator<bool>(filter_expr);
m_eval_value = m_builder.createEvaluator<ExprParser::float_type>(value_expr);
printf("-------------------------------------------------------\n");
ExprParser::printTree(m_eval_filter.arg()," |",false);
printf("-------------------------------------------------------\n");
ExprParser::printTree(m_eval_value.arg()," |",false);
printf("-------------------------------------------------------\n");
}
~CustomStepAct(){}
//Test implementation of how to create a self-contained filter function based
//on an expression containing G4Step related variables, including proper
//lifetime management of instantiated objects (leaving it here, just for a
//compilation check):

virtual void UserSteppingAction( const G4Step* step ) {
m_builder.setCurrentStep(step);//Must set before attempting to evaluate filter or value!
printf("Test - filter: %i\n",(int)m_eval_filter());
printf("Test - value : %g\n",m_eval_value());
//Using shared rather than unique ptr here, since we can't capture-by-move until c++14:
auto builder = std::make_shared<G4ExprParser::G4SteppingASTBuilder>();
auto evaluator = builder->createEvaluator<bool>(expr);
return [builder,evaluator](const G4Step* step) mutable->bool { builder->setCurrentStep(step); return evaluator(); };
}

};
class CustomStepAct final : public G4UserSteppingAction {

G4ExprParser::G4SteppingASTBuilder m_builder;
ExprParser::Evaluator<ExprParser::float_type> m_eval_value;
ExprParser::Evaluator<bool> m_eval_filter;
public:

CustomStepAct(const char * filter_expr, const char * value_expr) : G4UserSteppingAction() {
m_eval_filter = m_builder.createEvaluator<bool>(filter_expr);
m_eval_value = m_builder.createEvaluator<ExprParser::float_type>(value_expr);
printf("-------------------------------------------------------\n");
ExprParser::printTree(m_eval_filter.arg()," |",false);
printf("-------------------------------------------------------\n");
ExprParser::printTree(m_eval_value.arg()," |",false);
printf("-------------------------------------------------------\n");
}
~CustomStepAct(){}

void UserSteppingAction( const G4Step* step ) override {
m_builder.setCurrentStep(step);//Must set before attempting to evaluate filter or value!
printf("Test - filter: %i\n",(int)m_eval_filter());
printf("Test - value : %g\n",m_eval_value());
}

};
}

int main(int,char**) {

(void)createG4StepFilter_opt1;

DummyGeo * geo = new DummyGeo();
geo->setParameterDouble("boxThickness",20*Units::cm);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
#include "QGSP_BIC_HP.hh"
#include <string>

struct DummyDetectorConstruction : public G4VUserDetectorConstruction
{
G4VPhysicalVolume* Construct()
{
G4Box* solidWorld = new G4Box("World", 1,1,1);
G4Material* mat = new G4Material("some_dummy_material", 1, 1, 1);
G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, mat, "World");
return new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), logicWorld, "World", 0, false, 0);
}
};
namespace {
class DummyDetectorConstruction final : public G4VUserDetectorConstruction {
public:
G4VPhysicalVolume* Construct() override
{
G4Box* solidWorld = new G4Box("World", 1,1,1);
G4Material* mat = new G4Material("some_dummy_material", 1, 1, 1);
G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, mat, "World");
return new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), logicWorld, "World", 0, false, 0);
}
};
}

int main(int argc,char**argv) {
auto rm = new G4RunManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "G4SDManager.hh"
#include "G4StepPoint.hh"

class MySD : public G4VSensitiveDetector {
class MySD final : public G4VSensitiveDetector {
//////////////////////////////////////////////////////////////////////////////
// Sensitive detector for monitoring neutron hits in the spherical detector
// volume and printing out the "detected" scattering angle.
Expand All @@ -31,7 +31,7 @@ class MySD : public G4VSensitiveDetector {
MySD() : G4VSensitiveDetector("MySD") {}
virtual ~MySD(){}

virtual G4bool ProcessHits(G4Step* step, G4TouchableHistory*)
G4bool ProcessHits(G4Step* step, G4TouchableHistory*) override
{
if (step->GetPreStepPoint()->GetStepStatus() != fGeomBoundary)
return true;//must have just entered the volume
Expand All @@ -46,7 +46,7 @@ class MySD : public G4VSensitiveDetector {
}
};

class MyGeo : public G4VUserDetectorConstruction {
class MyGeo final : public G4VUserDetectorConstruction {
//////////////////////////////////////////////////////////////////////////////
// Constructs an r=1*mm spherical sample of polycrystalline Aluminium inside an
// r=100*cm spherical vacuum inside a 1*mm thick spherical counting volume,
Expand All @@ -58,7 +58,7 @@ class MyGeo : public G4VUserDetectorConstruction {
public:
MyGeo(){}
virtual ~MyGeo(){}
virtual G4VPhysicalVolume* Construct()
G4VPhysicalVolume* Construct() override
{
G4Material * mat_vacuum = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic",true);
//G4Material * mat_sample = G4NCrystalRel::createMaterial("Al_sg225.ncmat;bkgd=0");
Expand All @@ -84,7 +84,7 @@ class MyGeo : public G4VUserDetectorConstruction {
}
};

class MyGun : public G4VUserPrimaryGeneratorAction {
class MyGun final : public G4VUserPrimaryGeneratorAction {
//////////////////////////////////////////////////////////////////////////////
// Setup monochromatic source of neutrons, hitting the sample with initial direction (0,0,1)
//////////////////////////////////////////////////////////////////////////////
Expand All @@ -103,7 +103,7 @@ class MyGun : public G4VUserPrimaryGeneratorAction {
delete m_particleGun;
}

void GeneratePrimaries(G4Event* evt)
void GeneratePrimaries(G4Event* evt) override
{
m_particleGun->GeneratePrimaryVertex(evt);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
#include "G4Interfaces/PhysListProviderBase.hh"

//More work to do this from the C++ side:
class Empty_Provider : public G4Interfaces::PhysListProviderBase {
public:
Empty_Provider() : G4Interfaces::PhysListProviderBase("PL_Empty") {}
virtual ~Empty_Provider(){}
virtual G4VUserPhysicsList * construct() { return new PhysicsListEmpty; }
};
namespace {
class Empty_Provider final : public G4Interfaces::PhysListProviderBase {
public:
Empty_Provider() : G4Interfaces::PhysListProviderBase("PL_Empty") {}
G4VUserPhysicsList * construct() override { return new PhysicsListEmpty; }
};
}

class DummyGeo : public G4Interfaces::GeoConstructBase {
public:
Expand All @@ -25,7 +26,7 @@ class DummyGeo : public G4Interfaces::GeoConstructBase {
addParameterDouble("boxThickness",1*Units::um,0.01*Units::um,10*Units::um);
}

G4VPhysicalVolume* Construct()
G4VPhysicalVolume* Construct() override
{
G4Material* mat_galactic = G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic",true);
G4Material* mat_boroncarbide = G4NistManager::Instance()->FindOrBuildMaterial("G4_BORON_CARBIDE",true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
#include "G4PVPlacement.hh"
#include "QGSP_BERT.hh"

struct DummyDetectorConstruction : public G4VUserDetectorConstruction
{
G4VPhysicalVolume* Construct()
{
G4Box* solidWorld = new G4Box("World", 1,1,1);
G4Material* mat = new G4Material("some_dummy_material", 1, 1, 1);
G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, mat, "World");
return new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), logicWorld, "World", 0, false, 0);
}
};
namespace {
class DummyDetectorConstruction final : public G4VUserDetectorConstruction {
G4VPhysicalVolume* Construct() override
{
G4Box* solidWorld = new G4Box("World", 1,1,1);
G4Material* mat = new G4Material("some_dummy_material", 1, 1, 1);
G4LogicalVolume* logicWorld = new G4LogicalVolume(solidWorld, mat, "World");
return new G4PVPlacement(0, G4ThreeVector(0.0, 0.0, 0.0), logicWorld, "World", 0, false, 0);
}
};
}

void init_dummy_geant4() {
auto rm = new G4RunManager;
Expand Down
Loading

0 comments on commit acaa671

Please sign in to comment.