Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update StarGenerator and starsim codes in preparation for geant4star integration #103

Merged
merged 37 commits into from
Aug 25, 2021

Conversation

klendathu2k
Copy link
Contributor

@klendathu2k klendathu2k commented Aug 13, 2021

Changes to the StarGenerator and starsim codes in preparation for geant4star integration.

  • Introduce ageventread_() as a callback from starsim (agzio.age) triggering event generation. This allows existing workflows with St_geant_maker to remain untouched.
  • Goal was to remove the dependency between StarGenerator and the starsim codes. It will be difficult to eliminate the dependence on the agseventread_ (&etc...) methods in StarGenerator. We will need to supply these dummy symbols in geant4star at integration.
  • Introduce BFC chain options to load StarGenerator framework, and some select concrete generators
  • Several code cleanups identified in review
  • StarParticleData no longer created at library load (static instance of object vs dynamically instanstantiated)
  • "usestarsim" attribute added (default) for StarPrimaryMaker.
  • Introduced trivial test macro.

klendathu2k and others added 20 commits June 11, 2021 15:23
Point is well taken.

Co-authored-by: Dmitri Smirnov <dmixsmi@gmail.com>
on the starsim libraries out of the event generator framework.

The AgStarReader framework  is moved into St_geant_Maker.  Initialization
of the reader presents a small problem.  Most of our example macros have
delayed initialization of the generator framework until *after* the
initialization of the full chain.  So we don't have a guarenteed hook
to setup the connection between the event generator and the starsim
package.  Thus, the only place we can do this is on the first call to
St_geant_Maker::Make.  It is somewaht ugly, but the alternative is to
change the initialization scheme, change all of the production and example
macros, AND handle the fallout of breaking *users* macros.
Should resolve the compiler error due to the moved file:

StRoot/StarGenerator/BASE/AgStarReader.h -> StRoot/St_geant_Maker/AgStarReader.h
StRoot/StarGenerator/FILT/StarFilterMaker.cxx does not depend on anything in StRoot/StarGenerator/BASE/AgStarReader.h
@plexoos
Copy link
Member

plexoos commented Aug 14, 2021

cons seems to work fine when I compile on rcf.

That is exactly the problem with the environment on rcf. You move/rename a file in your local directory but cons can still pick up the old header files from the central location pointed by $STAR

Comment on lines 1189 to 1190
if ( stack != 0 ) AgStarReader::Instance().SetStack( (StarParticleStack*)stack->GetObject() );
if ( data != 0 ) AgStarReader::Instance().SetParticleData( (StarParticleData*)data->GetObject() );
Copy link
Member

Choose a reason for hiding this comment

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

Per STAR coding guidelines C-style type casting should be avoided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one of those cases where it is hard to avoid. If I use static / dynamic casts, then the dynamic linker complains that StarParticleStack / Data are not completely defined when I load the St_geant_Maker library. Same result if I push the cast down into the AgStarReader class. The crime against good coding style is not the use of the c-style cast, but rather the use of the singleton pattern for AgStarReader. Would prefer to keep the c-style cast here, rather than re-engineer the fortran interface.

Copy link
Member

Choose a reason for hiding this comment

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

Are you trying to avoid #include "StarGenerator/UTIL/StarParticleData.h" and #include "StarGenerator/BASE/StarParticleStack.h" from StRoot/St_geant_Maker/St_geant_Maker.cxx?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Also trying to avoid any run time dependence between the two libraries, so that
St_geant_Maker can be loaded without StarGenerator, and StarGenerator can be loaded w/out
loading St_geant_Maker.

(Also, not sure if replying in email gets logged as part of the discussion on github? If so, this may be redundant.)

StRoot/St_geant_Maker/St_geant_Maker.cxx Outdated Show resolved Hide resolved
StRoot/StarGenerator/UTIL/StarParticleData.cxx Outdated Show resolved Hide resolved
Comment on lines 2 to 5
import datetime, os
import ROOT
import subprocess, shlex
import sys
Copy link
Member

Choose a reason for hiding this comment

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

datetime, ROOT, and sys are not used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed... will push shortly.

StRoot/St_geant_Maker/St_geant_Maker.cxx Outdated Show resolved Hide resolved
For clarity

Co-authored-by: Dmitri Smirnov <dmixsmi@gmail.com>
@klendathu2k
Copy link
Contributor Author

klendathu2k commented Aug 16, 2021 via email

@plexoos
Copy link
Member

plexoos commented Aug 17, 2021

Jason, Can you illustrate with a macro what you are trying to achieve. It is not very clear, how you expect to avoid a run time dependence if one library makes use of the other one. As far as I know, a dynamic loader does not complain about unresolved symbols but if you try to call something that depends on the second library the process will definitely crash.

@klendathu2k
Copy link
Contributor Author

Any (most) of the macros under StRoot/StarGenerator/macros will demonstrate... e.g.

$ ln -s StRoot/StarGenerator/macros/starsim.pythia6.C starsim.C
$ root4star -q -b starsim.C
...
As implemented, code runs. To add a static or dynamic cast requires that I include the StarParticleStack and Data headers. Including those... I get this when I run starsim.C...

dlopen error: /gpfs/mnt/gpfs01/star/simu/simu/jwebb/STAR/.sl73_gcc485/lib/libSt_geant_Maker.so: undefined symbol: _ZTI16StarParticleData
Load Error: Failed to load Dynamic link library /gpfs/mnt/gpfs01/star/simu/simu/jwebb/STAR/.sl73_gcc485/lib/libSt_geant_Maker.so

$ c++filt _ZTI16StarParticleData
typeinfo for StarParticleData

@plexoos
Copy link
Member

plexoos commented Aug 17, 2021

As implemented, code runs.

I could not reproduce this. When run from the current main your test goes through and produces an fzd file but from G4star it seg faults.

@klendathu2k
Copy link
Contributor Author

I get a segmentation fault if I compile star-sw without compiling star-mcgen. Otherwise it worked (to be confirmed again...)

…cular

dependency, meaning that it will not be simple to remove the starsim dependency
in StarGenerator.  We have two (or more) choices here.  Either create an interface
class and a separate library for the concrete starsim reader, or provide a set
of dummy symbols in geant4 maker in order to satisfy the generator dependencies.
Final choice will be defered, but I am leaning towards a set of dummy symbols
in geant4mk.
@klendathu2k
Copy link
Contributor Author

Decided on a different path. Instead of removing the dependence on starsim functions from StarGenerator (agsvert, agskine, etc...), the plan will be to satisfy these with dummy symbols inserted into the geant4 maker. Alternatively I could create an interface base class, and a plugin library to support starsim (but this seems like overkill).

@@ -1363,6 +1363,15 @@ Bfc_st BFC[] = { // standard chains
{"gstarLib","","","" ,"","gstar","Load gstar lib",kFALSE},
{"flux" ,"","","simu" ,"","flux","Load flux lib",kFALSE},
{"------------","-----------","-----------","------------------------------------------","","","",kFALSE},
{"Generators ","-----------","-----------","------------------------------------------","","","",kFALSE},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

DId not intend to commit this, but it is a harmless addition to our list of chain options (and will be utilized as we merge in the G4star codes).

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, if you update the branch from which you are making the PR not to have this line, then it will drop off the list of changed files. Then you can re-apply this change later when it is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clarify if it is only the single "Generators" line that isn't needed for this commit, or all the BigFullChain.h line changes in this PR that aren't really needed for this PR? git makes my approval mandatory for the whole shebang of this PR because I'm a code owner for a small part of it :-(

@klendathu2k
Copy link
Contributor Author

klendathu2k commented Aug 18, 2021 via email

@klendathu2k
Copy link
Contributor Author

klendathu2k commented Aug 18, 2021 via email

@klendathu2k
Copy link
Contributor Author

Just pinging this. Are there any other recommendations to push these changes?

@genevb
Copy link
Contributor

genevb commented Aug 23, 2021

Just pinging this. Are there any other recommendations to push these changes?

As long as your other pull request (for which these chain options matter) and this one point to each other, I'm not too particular.

Copy link
Contributor

@genevb genevb left a comment

Choose a reason for hiding this comment

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

No opposition.

@plexoos
Copy link
Member

plexoos commented Aug 23, 2021

The description states that "This removes from StarGenerator the dependence on code in the starsim library." I don't see how the submitted changes do anything to achieve this. The original intention to move the code that depends on St_geant_Maker from StarGenerator/ looked more like the move in the right direction but it was reverted.

Please update the description and title to reflect what is really being changed.

@plexoos
Copy link
Member

plexoos commented Aug 23, 2021

Thanks for updating the description Jason.

It will be difficult to eliminate the dependence on the agseventread_ (&etc...) methods in StarGenerator.

This one is still confusing because ageventread is defined in StarGenerator... I am probably missing something but where is ageventread called from?

@klendathu2k
Copy link
Contributor Author

klendathu2k commented Aug 24, 2021 via email

@plexoos
Copy link
Member

plexoos commented Aug 24, 2021

Without tests it is very hard to judge whether these changes will break anything or not...
For example, I can't tell if it is safe to remove the definition of agusread https://github.com/star-bnl/star-sw/pull/103/files#diff-dcecc0e93bbe5fcf050ef4b946135b831eec3686ed0b1606a8355c62fca004e0L30 when there seems to be another one defined in https://github.com/star-bnl/star-sw/blob/main/pams/sim/gstar/gstar_input.g#L84

Anyway, if you are confident about these changes we can merge... or maybe it can wait until introduction of geant4star when these preparatory changes will be actually used.

@klendathu2k
Copy link
Contributor Author

Yes I am confident that the code functions and is correct. agusread --> agusevent is simply a renaming of a subroutine, plus a branch under a switch statement to enable the different path. The code runs. stargentest.py confirms that events are produced.

Copy link
Member

@plexoos plexoos left a comment

Choose a reason for hiding this comment

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

The author claims that all changes are necessary for Geant4 integration and have been tested

@plexoos plexoos changed the title G4star Update StarGenerator and starsim codes in preparation for geant4star integration Aug 25, 2021
@plexoos plexoos merged commit 63d4d8f into star-bnl:main Aug 25, 2021
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.

None yet

5 participants