Skip to content

Proper(?) modification to avoid cppyy.ll.SegmentationViolation in angel2root.py - #16

Open
furutaka wants to merge 10 commits into
kbat:masterfrom
furutaka:master
Open

Proper(?) modification to avoid cppyy.ll.SegmentationViolation in angel2root.py#16
furutaka wants to merge 10 commits into
kbat:masterfrom
furutaka:master

Conversation

@furutaka

@furutaka furutaka commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Hi.

I must apologize that the previous PR I made was wrong; the script still SEGVs in case there are multiple plots in an angel file. We must use the way I described in this comment.
Further, the modification which can avoid SEGV for TH1 is not enough for TGraphErros; we have to explicitly release the ownership by using ROOT.SetOwnership().
In addition to the above, I changed the loop to scan the 1st page from for to `while, to process some lines as a group.

The present modifications also include

  • the addition of a lot of debug-print lines,
  • the change of naming schemes for TH1 and TGraphErrors to differentiate multiple plots,
  • the change of variable name from numPlots to numPlotPages,
  • introduction of multiple DEBUG levels (integer).

I have checked the function of the script by converting many angel files coming with PHITS v.3.36.
Many of them could be successfully converted, some failed (later I'll investigate the reasons).
I'd like to ask you to carefully review the modification: I have one criminal record!

TODOs:

  • Refine the criteria to distinguish the type of a plot; phits developers do not tightly fix the format of the histogram header line, e.g. the number of whitespaces between h: and n/x.
  • Modify to properly process angel files which contains geometry drawing statements starting with # gshow.

Kazuyoshi Furutaka (work) added 7 commits July 10, 2026 14:32
…Write()"

The "fix" in PR#14 was completely wrong; it didn't work for
multiple plots in a file.
We had to take the modification described in
kbat#14 (comment)
There may be multiple plots in a page.
In the 1st page, there're lines which should be processed
as a group, e.g. "mesh = reg" and "multiplier = " and so on.
To process groups of lines, `for` loop is not convenient,
because one has to advance the line pointer the fixed amount
according to the kind of group the lines belong.
Therefore, the type of loop for use to scan the 1st header
page was changed from `for` to `while`.

To check the working, many debug-prints were added, and
multiple DEBUG levels were introduced (more verbose with
larger DEBUG).
To differentiate multiple TH1 histograms.

Added more debug-prints.
For unknown reasons (to K.F), in order for TGraphErrors
to avoid cppyy.ll.SegmentationViolation, you need one more
effort to release the ownership.

For this, now we don't import ROOT from ROOT, because
ROOT is regarded as an object when the import is done.

Similarly as histograms, now the names of graphs (may)
depend on the page numbers as well as the comments.
There are cases in which the string between a pair of parentheses
in a  "h:" line, "y(...)", includes whitespaces.
  e.g. "h: n            x            y(zmin  0.000E+00),hh0l n ..."
    in PHITS/recommendation/ParticleTherapy/y-distribution.out

In those cases, the subtitle of a histogram would become an empty
string, and mulitple histograms have all the same name, and a
warning is issued such as:
  TFile::Append:0: RuntimeWarning: Replacing existing TH1: ... \
    (Potential memory leak).

The cause of the problem is the splitting of "h:" line by whitespaces.
To properly split the line, splitHline() was added for use
in GetNhist().
To do so, the corresponding regular expression has been
changed from "^h[2dc]:" to "^h([2d]|c2?):" (although the
plot type, "hc2:", seems NOT to be mentioned in the manuals
of PHITS v.3.36 or v4.53).

Do NOT `continue` processing the page after returning from
Read2DHist(); `break` to proceed to the next plot page:
we don't have to read color-palette data etc.
@furutaka

Copy link
Copy Markdown
Collaborator Author

Well... I noticed my terribly bad language in the commit message of my last commit. Tomorrow I will fix it at work, so please wait for the fix.... Thanks.

Kazuyoshi Furutaka (work) added 3 commits July 17, 2026 14:15
PHITS manual reads "There are 8 kinds of mesh definition..."
https://phits.jaea.go.jp/manual/PHITS-en/chapters/tally-format.html#mesh-definition
but 'l' definition (for LET?) was overlooked.

This modification enables the conversion of the following
angel files:
  PHITS/lecture/old-lecture/ex023/let.out
  PHITS/lecture/old-lecture/ex023/letr.out
  PHITS/recommendation/ParticleTherapy/let-distribution.out
To do this, a Boolean argument, `tet` is added to
Read1DGraphErrors().  If tet = True, the column to start
reading the data is shifted right by 2 ("tetra" and "volume"
columns are skipped):
  "#    num    tetra   volume       all         r.err ..."

There seems to be only one "mesh = tet" angel file included
with phits v.3.36: utility/FLUENT/PHITS/Tetra_test1_deposit.out
…ns added by "sangel = ..."

In that case, the tally data is preceded by the additiona
angel instruction (which may be other plot(s) of data).
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

💡 Need a hand with PR review? Try Gitar by Sonar!

@furutaka

Copy link
Copy Markdown
Collaborator Author

FYI: I'm not sure whether we need this or not...

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.

1 participant