Skip to content

Conversation

@Ciorolla
Copy link
Collaborator

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Geant4 parser code into a more modular architecture by decomposing the monolithic Geant4MacroGenerator class and parser methods into separate builder and parser modules. The refactoring improves code organization and maintainability.

Key Changes:

  • Extracted GDML generation logic into separate gdml/ module with dedicated builders for materials, solids, and structure
  • Decomposed macro generation into separate parsers for beam, scoring, histograms, run, and results in macro/ module
  • Moved particle and quantity mappings to a centralized constants.py file

Reviewed changes

Copilot reviewed 13 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
converter/geant4/parser.py Simplified to delegate GDML and macro generation to new builder classes
converter/geant4/constants.py Centralized GEANT4_PARTICLE_MAP and GEANT4_QUANTITY_MAP constants
converter/geant4/gdml/builder.py Main GDML generation orchestrator with XML prettification
converter/geant4/gdml/materials.py Material collection and emission logic
converter/geant4/gdml/solids.py Solid geometry element generation
converter/geant4/gdml/structure.py Structure and volume hierarchy generation
converter/geant4/macro/builder.py Main macro generation orchestrator
converter/geant4/macro/beam_parser.py Beam configuration parsing
converter/geant4/macro/scoring_parser.py Scoring detector and quantity parsing
converter/geant4/macro/histogram_parser.py Histogram output generation for probes
converter/geant4/macro/run_parser.py Run command generation
converter/geant4/macro/result_parser.py Result collection commands
converter/geant4/Geant4MacroGenerator.py Removed in favor of modular parsers

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Ciorolla Ciorolla requested a review from kmichalikk November 23, 2025 21:36
low = beam.get("energyLowCutoff", 0) * scale

return [
f"/gps/direction {direction[0]} {direction[1]} {direction[2]}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line doesn't belong here

@grzanka
Copy link
Contributor

grzanka commented Nov 24, 2025

A general remark - why a simple code, like in Geant4GDMLBuilder is not a method ?
That class doesn't keep a state.

def build_gdml_from_json( world_json: Optional[dict]) -> str

should do the job as well.

The same applies to MaterialCollector and other classes.

The code looks very weird and not pythonic :/

@Ciorolla
Copy link
Collaborator Author

Ciorolla commented Nov 24, 2025

A general remark - why a simple code, like in Geant4GDMLBuilder is not a method ? That class doesn't keep a state.

def build_gdml_from_json( world_json: Optional[dict]) -> str

should do the job as well.

The same applies to MaterialCollector and other classes.

The code looks very weird and not pythonic :/

Fair enough, on daily basis i write in java so the code could have some OOP similarities,. Do you want more method base approach ?

@grzanka
Copy link
Contributor

grzanka commented Nov 25, 2025

A general remark - why a simple code, like in Geant4GDMLBuilder is not a method ? That class doesn't keep a state.
def build_gdml_from_json( world_json: Optional[dict]) -> str
should do the job as well.
The same applies to MaterialCollector and other classes.
The code looks very weird and not pythonic :/

Fair enough, on daily basis i write in java so the code could have some OOP similarities,. Do you want more method base approach ?

Yes, Python is not a Java. I ran quick copilot survey on this code which generated guidelines which I strongly support:
image

In python we don't care much about private/public stuff (everything is public anyway). We don't inherit much as well.

What requires more attention that many methods/function in this code have way too many lines and should be splitted into smaller pieces.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 16 changed files in this pull request and generated 14 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@grzanka grzanka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to avoid as much as possible a coding style where you have a function which modify the parameters they take.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 18 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@grzanka grzanka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you convert all of your codes into simple functions, with meaningful names, which do not modify its arguments. Good idea would be also to completely get rid of classes.
We don't need a polymorphism here, nor any need to keep a state of some object. The logic here is simple transformation from one state to another which can be achieved by set of testable functions scattered among couple of modules.

@Ciorolla
Copy link
Collaborator Author

Ciorolla commented Jan 6, 2026

Can you convert all of your codes into simple functions, with meaningful names, which do not modify its arguments. Good idea would be also to completely get rid of classes. We don't need a polymorphism here, nor any need to keep a state of some object. The logic here is simple transformation from one state to another which can be achieved by set of testable functions scattered among couple of modules.

we have only one class that is absolutely needed, ( extends class parser as every other converter )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants