Skip to content

Commit

Permalink
[pre-commit.ci] Automatic python and c++ formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Mar 6, 2024
1 parent 82e7f2a commit ae0beb7
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 202 deletions.
58 changes: 30 additions & 28 deletions core/opengate_core/g4_bindings/chemistryadaptator.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,45 @@

class G4DNAMolecularReactionTable;

template<typename C>
class ChemistryAdaptator: public C {
template <typename C> class ChemistryAdaptator : public C {
public:
using ConstructReactionTableHook = std::function<void(G4DNAMolecularReactionTable*)>;
using ConstructReactionTableHook =
std::function<void(G4DNAMolecularReactionTable *)>;

public:
ChemistryAdaptator(int verbosity) {
C::SetVerboseLevel(verbosity);
_chemistryLists.push_back(this);
}

void ConstructTimeStepModel(G4DNAMolecularReactionTable* reactionTable) override {
C::ConstructTimeStepModel(reactionTable);
}

void ConstructReactionTable(G4DNAMolecularReactionTable* reactionTable) override {
C::ConstructReactionTable(reactionTable);
if(_constructReactionTableHook)
ChemistryAdaptator(int verbosity) {
C::SetVerboseLevel(verbosity);
_chemistryLists.push_back(this);
}

void
ConstructTimeStepModel(G4DNAMolecularReactionTable *reactionTable) override {
C::ConstructTimeStepModel(reactionTable);
}

void
ConstructReactionTable(G4DNAMolecularReactionTable *reactionTable) override {
C::ConstructReactionTable(reactionTable);
if (_constructReactionTableHook)
_constructReactionTableHook(reactionTable);
}

static C* getChemistryList() {
for(auto* chemistryList: _chemistryLists) {
auto* ptr = dynamic_cast<C*>(chemistryList);
if(ptr != nullptr) return ptr;
}
return nullptr;
}

template<typename T>
static void setConstructReactionTableHook(T fn) {
}

static C *getChemistryList() {
for (auto *chemistryList : _chemistryLists) {
auto *ptr = dynamic_cast<C *>(chemistryList);
if (ptr != nullptr)
return ptr;
}
return nullptr;
}

template <typename T> static void setConstructReactionTableHook(T fn) {
_constructReactionTableHook = fn;
}

private:
inline static ConstructReactionTableHook _constructReactionTableHook;
inline static std::vector<G4VUserChemistryList*> _chemistryLists;
inline static std::vector<G4VUserChemistryList *> _chemistryLists;
};

#endif
3 changes: 2 additions & 1 deletion core/opengate_core/g4_bindings/pyG4UserStackingAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class PyG4UserStackingAction : public G4UserStackingAction {

void init_G4UserStackingAction(py::module &m) {

py::class_<G4UserStackingAction, PyG4UserStackingAction>(m, "G4UserStackingAction")
py::class_<G4UserStackingAction, PyG4UserStackingAction>(
m, "G4UserStackingAction")
.def(py::init())
.def("NewStage", &G4UserStackingAction::NewStage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace py = pybind11;
#include "G4SteppingVerbose.hh"
#include "G4UserEventAction.hh"
#include "G4UserRunAction.hh"
#include "G4UserStackingAction.hh"
#include "G4UserSteppingAction.hh"
#include "G4UserTrackingAction.hh"
#include "G4UserStackingAction.hh"
#include "G4VUserActionInitialization.hh"
#include "G4VUserPrimaryGeneratorAction.hh"

Expand Down
7 changes: 4 additions & 3 deletions core/opengate_core/g4_bindings/pyPhysicsLists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ namespace py = pybind11;
.def(py::init<G4int>());

// copied from ADD_PHYSICS_CONSTRUCTOR, adapted to chemistry
#define ADD_CHEMISTRY_CONSTRUCTOR(clname) \
py::class_<ChemistryAdaptator<clname>, G4VPhysicsConstructor, \
std::unique_ptr<ChemistryAdaptator<clname>, py::nodelete>>(m, #clname) \
#define ADD_CHEMISTRY_CONSTRUCTOR(clname) \
py::class_<ChemistryAdaptator<clname>, G4VPhysicsConstructor, \
std::unique_ptr<ChemistryAdaptator<clname>, py::nodelete>>( \
m, #clname) \
.def(py::init<G4int>());

namespace pyPhysicsLists {
Expand Down
Loading

0 comments on commit ae0beb7

Please sign in to comment.