Skip to content

Commit 929bb79

Browse files
committed
Fix GeneratorPythia8 construction
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)
1 parent c3ffb66 commit 929bb79

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

Generators/include/Generators/GeneratorPythia8.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class GeneratorPythia8 : public Generator
9090
/** default constructor **/
9191
GeneratorPythia8();
9292
/** constructor **/
93-
GeneratorPythia8(Pythia8GenConfig const& pars);
93+
GeneratorPythia8(Pythia8GenConfig const&);
9494
/** constructor **/
9595
GeneratorPythia8(const Char_t* name, const Char_t* title = "ALICEo2 Pythia8 Generator");
9696
/** destructor **/
@@ -285,7 +285,7 @@ class GeneratorPythia8 : public Generator
285285
long mInitialRNGSeed = -1; // initial seed for Pythia random number state;
286286
// will be transported to Pythia in the Init function through the Pythia::readString("Random:seed") mechanism.
287287
// Value of -1 means unitialized; 0 will be time-dependent and values >1 <= MAX_SEED concrete reproducible seeding
288-
std::unique_ptr<Pythia8GenConfig> mGenConfig; // configuration object
288+
Pythia8GenConfig mGenConfig; // configuration object
289289

290290
constexpr static long MAX_SEED = 900000000;
291291

Generators/src/GeneratorPythia8.cxx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,33 +53,39 @@ GeneratorPythia8::GeneratorPythia8() : Generator("ALICEo2", "ALICEo2 Pythia8 Gen
5353
mInterfaceName = "pythia8";
5454

5555
auto& param = GeneratorPythia8Param::Instance();
56-
LOG(info) << "Instance \'Pythia8\' generator with following parameters";
56+
LOG(info) << "Default Instance \'Pythia8\' generator with following parameters";
5757
LOG(info) << param;
5858

59-
setConfig(param.config);
60-
setHooksFileName(param.hooksFileName);
61-
setHooksFuncName(param.hooksFuncName);
59+
// convert the outside singleton config to the internally used one
60+
o2::eventgen::Pythia8GenConfig config{param.config,
61+
param.hooksFileName, param.hooksFuncName, param.includePartonEvent, param.particleFilter, param.verbose};
62+
mGenConfig = config;
63+
64+
setConfig(config.config);
65+
setHooksFileName(config.hooksFileName);
66+
setHooksFuncName(config.hooksFuncName);
67+
// TODO: use constructor delegation to other interface
6268
}
6369

6470
/*****************************************************************/
6571

66-
GeneratorPythia8::GeneratorPythia8(Pythia8GenConfig const& pars) : Generator("ALICEo2", "ALICEo2 Pythia8 Generator")
72+
GeneratorPythia8::GeneratorPythia8(Pythia8GenConfig const& config) : Generator("ALICEo2", "ALICEo2 Pythia8 Generator")
6773
{
6874
/** constructor **/
6975

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

7379
LOG(info) << "Instance \'Pythia8\' generator with following parameters";
74-
LOG(info) << "config: " << pars.config;
75-
LOG(info) << "hooksFileName: " << pars.hooksFileName;
76-
LOG(info) << "hooksFuncName: " << pars.hooksFuncName;
80+
LOG(info) << "config: " << config.config;
81+
LOG(info) << "hooksFileName: " << config.hooksFileName;
82+
LOG(info) << "hooksFuncName: " << config.hooksFuncName;
7783

78-
mGenConfig = std::make_unique<Pythia8GenConfig>(pars);
84+
mGenConfig = config;
7985

80-
setConfig(pars.config);
81-
setHooksFileName(pars.hooksFileName);
82-
setHooksFuncName(pars.hooksFuncName);
86+
setConfig(mGenConfig.config);
87+
setHooksFileName(mGenConfig.hooksFileName);
88+
setHooksFuncName(mGenConfig.hooksFuncName);
8389
}
8490

8591
/*****************************************************************/
@@ -578,8 +584,7 @@ void GeneratorPythia8::pruneEvent(Pythia8::Event& event, Select select)
578584
}
579585
}
580586
}
581-
int verbose = mGenConfig->verbose;
582-
if (verbose) {
587+
if (mGenConfig.verbose) {
583588
LOG(info) << "Pythia event was pruned from " << event.size()
584589
<< " to " << pruned.size() << " particles";
585590
}
@@ -592,7 +597,7 @@ void GeneratorPythia8::initUserFilterCallback()
592597
{
593598
mUserFilterFcn = [](Pythia8::Particle const&) -> bool { return true; };
594599

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

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

627632
// Select pythia particles

0 commit comments

Comments
 (0)