Skip to content

Commit

Permalink
Fix GeneratorPythia8 construction
Browse files Browse the repository at this point in the history
Fixes smaller issues introduced with the hybrid generator
refactoring:

- Make sure that internal configuration object is never null;
  In fact, it does not need to be a pointer.

- Make sure the internal configuration struct is initialized
  from the GeneratorPythia8Param configurable when using the
  default constructor.

This commit fixes an issue/segfault when running the following command

o2-sim-dpl-eventgen --generator external --nEvents 200 --aggregate-timeframe 10000 --configFile ${O2DPG_ROOT}/MC/config/ALICE3/ini/pythia8_pp_136tev.ini -b

(which defaults constructs a Pythia8 generator)
  • Loading branch information
sawenzel committed Nov 21, 2024
1 parent c3ffb66 commit 929bb79
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Generators/include/Generators/GeneratorPythia8.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class GeneratorPythia8 : public Generator
/** default constructor **/
GeneratorPythia8();
/** constructor **/
GeneratorPythia8(Pythia8GenConfig const& pars);
GeneratorPythia8(Pythia8GenConfig const&);
/** constructor **/
GeneratorPythia8(const Char_t* name, const Char_t* title = "ALICEo2 Pythia8 Generator");
/** destructor **/
Expand Down Expand Up @@ -285,7 +285,7 @@ class GeneratorPythia8 : public Generator
long mInitialRNGSeed = -1; // initial seed for Pythia random number state;
// will be transported to Pythia in the Init function through the Pythia::readString("Random:seed") mechanism.
// Value of -1 means unitialized; 0 will be time-dependent and values >1 <= MAX_SEED concrete reproducible seeding
std::unique_ptr<Pythia8GenConfig> mGenConfig; // configuration object
Pythia8GenConfig mGenConfig; // configuration object

constexpr static long MAX_SEED = 900000000;

Expand Down
37 changes: 21 additions & 16 deletions Generators/src/GeneratorPythia8.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,39 @@ GeneratorPythia8::GeneratorPythia8() : Generator("ALICEo2", "ALICEo2 Pythia8 Gen
mInterfaceName = "pythia8";

auto& param = GeneratorPythia8Param::Instance();
LOG(info) << "Instance \'Pythia8\' generator with following parameters";
LOG(info) << "Default Instance \'Pythia8\' generator with following parameters";
LOG(info) << param;

setConfig(param.config);
setHooksFileName(param.hooksFileName);
setHooksFuncName(param.hooksFuncName);
// convert the outside singleton config to the internally used one
o2::eventgen::Pythia8GenConfig config{param.config,
param.hooksFileName, param.hooksFuncName, param.includePartonEvent, param.particleFilter, param.verbose};
mGenConfig = config;

setConfig(config.config);
setHooksFileName(config.hooksFileName);
setHooksFuncName(config.hooksFuncName);
// TODO: use constructor delegation to other interface
}

/*****************************************************************/

GeneratorPythia8::GeneratorPythia8(Pythia8GenConfig const& pars) : Generator("ALICEo2", "ALICEo2 Pythia8 Generator")
GeneratorPythia8::GeneratorPythia8(Pythia8GenConfig const& config) : Generator("ALICEo2", "ALICEo2 Pythia8 Generator")
{
/** constructor **/

mInterface = reinterpret_cast<void*>(&mPythia);
mInterfaceName = "pythia8";

LOG(info) << "Instance \'Pythia8\' generator with following parameters";
LOG(info) << "config: " << pars.config;
LOG(info) << "hooksFileName: " << pars.hooksFileName;
LOG(info) << "hooksFuncName: " << pars.hooksFuncName;
LOG(info) << "config: " << config.config;
LOG(info) << "hooksFileName: " << config.hooksFileName;
LOG(info) << "hooksFuncName: " << config.hooksFuncName;

mGenConfig = std::make_unique<Pythia8GenConfig>(pars);
mGenConfig = config;

setConfig(pars.config);
setHooksFileName(pars.hooksFileName);
setHooksFuncName(pars.hooksFuncName);
setConfig(mGenConfig.config);
setHooksFileName(mGenConfig.hooksFileName);
setHooksFuncName(mGenConfig.hooksFuncName);
}

/*****************************************************************/
Expand Down Expand Up @@ -578,8 +584,7 @@ void GeneratorPythia8::pruneEvent(Pythia8::Event& event, Select select)
}
}
}
int verbose = mGenConfig->verbose;
if (verbose) {
if (mGenConfig.verbose) {
LOG(info) << "Pythia event was pruned from " << event.size()
<< " to " << pruned.size() << " particles";
}
Expand All @@ -592,7 +597,7 @@ void GeneratorPythia8::initUserFilterCallback()
{
mUserFilterFcn = [](Pythia8::Particle const&) -> bool { return true; };

std::string filter = mGenConfig->particleFilter;
std::string filter = mGenConfig.particleFilter;
if (filter.size() > 0) {
LOG(info) << "Initializing the callback for user-based particle pruning " << filter;
auto expandedFileName = o2::utils::expandShellVarsInFileName(filter);
Expand Down Expand Up @@ -621,7 +626,7 @@ Bool_t
// event record in the AOD.

std::function<bool(const Pythia8::Particle&)> partonSelect = [](const Pythia8::Particle&) { return true; };
bool includeParton = mGenConfig->includePartonEvent;
bool includeParton = mGenConfig.includePartonEvent;
if (not includeParton) {

// Select pythia particles
Expand Down

0 comments on commit 929bb79

Please sign in to comment.