From e5532f59d895c98765ce5e3cf4137452e2650925 Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Mon, 2 Dec 2024 15:12:22 +0100 Subject: [PATCH 1/5] Compilable version of fix, tests needed --- .../include/Generators/GeneratorFactory.h | 3 + Generators/src/GeneratorFactory.cxx | 122 +++++++++--------- 2 files changed, 64 insertions(+), 61 deletions(-) diff --git a/Generators/include/Generators/GeneratorFactory.h b/Generators/include/Generators/GeneratorFactory.h index 9f4dfb5514582..f7b013f4ceef0 100644 --- a/Generators/include/Generators/GeneratorFactory.h +++ b/Generators/include/Generators/GeneratorFactory.h @@ -34,6 +34,9 @@ struct GeneratorFactory { static void setPrimaryGenerator(o2::conf::SimConfig const&, FairPrimaryGenerator*); }; +template +std::vector> genptr; + } // end namespace eventgen } // end namespace o2 diff --git a/Generators/src/GeneratorFactory.cxx b/Generators/src/GeneratorFactory.cxx index 8233024a4c2d7..f163db1a29831 100644 --- a/Generators/src/GeneratorFactory.cxx +++ b/Generators/src/GeneratorFactory.cxx @@ -61,7 +61,7 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair auto primGenO2 = dynamic_cast(primGen); auto makeBoxGen = [](int pdgid, int mult, double etamin, double etamax, double pmin, double pmax, double phimin, double phimax, bool debug = false) { - auto gen = new FairBoxGenerator(pdgid, mult); + auto gen = std::make_unique(pdgid, mult); gen->SetEtaRange(etamin, etamax); gen->SetPRange(pmin, pmax); gen->SetPhiRange(phimin, phimax); @@ -80,7 +80,7 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair .particleFilter = singleton.particleFilter, .verbose = singleton.verbose, }; - auto gen = new o2::eventgen::GeneratorPythia8(pars); + auto gen = std::make_unique(pars); if (!config.empty()) { LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; gen->setConfig(config); // assign config; will be executed in Init function @@ -99,58 +99,58 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair auto& boxparam = BoxGunParam::Instance(); LOG(info) << "Init generic box generator with following parameters"; LOG(info) << boxparam; - auto boxGen = makeBoxGen(boxparam.pdg, boxparam.number, boxparam.eta[0], boxparam.eta[1], boxparam.prange[0], boxparam.prange[1], boxparam.phirange[0], boxparam.phirange[1], boxparam.debug); - primGen->AddGenerator(boxGen); + genptr.push_back(makeBoxGen(boxparam.pdg, boxparam.number, boxparam.eta[0], boxparam.eta[1], boxparam.prange[0], boxparam.prange[1], boxparam.phirange[0], boxparam.phirange[1], boxparam.debug)); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("fwmugen") == 0) { // a simple "box" generator for forward muons LOG(info) << "Init box forward muons generator"; - auto boxGen = makeBoxGen(13, 1, -4, -2.5, 50., 50., 0., 360); - primGen->AddGenerator(boxGen); + genptr.push_back(makeBoxGen(13, 1, -4, -2.5, 50., 50., 0., 360)); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("hmpidgun") == 0) { // a simple "box" generator for forward muons LOG(info) << "Init hmpid gun generator"; - auto boxGen = makeBoxGen(-211, 100, -0.5, -0.5, 2, 5, -5, 60); - primGen->AddGenerator(boxGen); + genptr.push_back(makeBoxGen(-211, 100, -0.5, -0.5, 2, 5, -5, 60)); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("fwpigen") == 0) { // a simple "box" generator for forward pions LOG(info) << "Init box forward pions generator"; - auto boxGen = makeBoxGen(-211, 10, -4, -2.5, 7, 7, 0, 360); - primGen->AddGenerator(boxGen); + genptr.push_back(makeBoxGen(-211, 10, -4, -2.5, 7, 7, 0, 360)); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("fwrootino") == 0) { // a simple "box" generator for forward rootinos LOG(info) << "Init box forward rootinos generator"; - auto boxGen = makeBoxGen(0, 1, -4, -2.5, 1, 5, 0, 360); - primGen->AddGenerator(boxGen); + genptr.push_back(makeBoxGen(0, 1, -4, -2.5, 1, 5, 0, 360)); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("zdcgen") == 0) { // a simple "box" generator for forward neutrons LOG(info) << "Init box forward/backward zdc generator"; - auto boxGenC = makeBoxGen(2112 /*neutrons*/, 1, -8, -9999, 500, 1000, 0., 360.); - auto boxGenA = makeBoxGen(2112 /*neutrons*/, 1, 8, 9999, 500, 1000, 0., 360.); - primGen->AddGenerator(boxGenC); - primGen->AddGenerator(boxGenA); + genptr.push_back(makeBoxGen(2112 /*neutrons*/, 1, -8, -9999, 500, 1000, 0., 360.)); + genptr.push_back(makeBoxGen(2112 /*neutrons*/, 1, 8, 9999, 500, 1000, 0., 360.)); + primGen->AddGenerator(genptr.back().get()); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("emcgenele") == 0) { // box generator with one electron per event LOG(info) << "Init box generator for electrons in EMCAL"; // using phi range of emcal - auto elecgen = makeBoxGen(11, 1, -0.67, 0.67, 15, 15, 80, 187); - primGen->AddGenerator(elecgen); + genptr.push_back(makeBoxGen(11, 1, -0.67, 0.67, 15, 15, 80, 187)); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("emcgenphoton") == 0) { LOG(info) << "Init box generator for photons in EMCAL"; - auto photongen = makeBoxGen(22, 1, -0.67, 0.67, 15, 15, 80, 187); - primGen->AddGenerator(photongen); + genptr.push_back(makeBoxGen(22, 1, -0.67, 0.67, 15, 15, 80, 187)); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("fddgen") == 0) { LOG(info) << "Init box FDD generator"; - auto boxGenFDC = makeBoxGen(13, 1000, -7, -4.8, 10, 500, 0, 360.); - auto boxGenFDA = makeBoxGen(13, 1000, 4.9, 6.3, 10, 500, 0., 360); - primGen->AddGenerator(boxGenFDA); - primGen->AddGenerator(boxGenFDC); + genptr.push_back(makeBoxGen(13, 1000, -7, -4.8, 10, 500, 0, 360.)); + genptr.push_back(makeBoxGen(13, 1000, 4.9, 6.3, 10, 500, 0., 360)); + primGen->AddGenerator(genptr.back().get()); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("extkin") == 0) { // external kinematics // needs precense of a kinematics file "Kinematics.root" // TODO: make this configurable and check for presence - auto extGen = new o2::eventgen::GeneratorFromFile(conf.getExtKinematicsFileName().c_str()); - extGen->SetStartEvent(conf.getStartEvent()); - primGen->AddGenerator(extGen); + genptr.push_back(std::make_unique(conf.getExtKinematicsFileName().c_str())); + genptr.back()->SetStartEvent(conf.getStartEvent()); + primGen->AddGenerator(genptr.back().get()); LOG(info) << "using external kinematics"; } else if (genconfig.compare("extkinO2") == 0) { // external kinematics from previous O2 output @@ -165,9 +165,9 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair .rngseed = singleton.rngseed, .randomphi = singleton.randomphi, .fileName = name1.size() > 0 ? name1.c_str() : name2.c_str()}; - auto extGen = new o2::eventgen::GeneratorFromO2Kine(pars); - extGen->SetStartEvent(conf.getStartEvent()); - primGen->AddGenerator(extGen); + genptr.push_back(std::make_unique(pars)); + genptr.back()->SetStartEvent(conf.getStartEvent()); + primGen->AddGenerator(genptr.back().get()); if (pars.continueMode) { auto o2PrimGen = dynamic_cast(primGen); if (o2PrimGen) { @@ -183,9 +183,9 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair LOG(info) << "Init 'GeneratorTParticle' with the following parameters"; LOG(info) << param0; LOG(info) << param; - auto tgen = new o2::eventgen::GeneratorTParticle(); - tgen->setup(param0, param, conf); - primGen->AddGenerator(tgen); + genptr.push_back(std::make_unique()); + genptr.back()->setup(param0, param, conf); + primGen->AddGenerator(genptr.back().get()); #ifdef GENERATORS_WITH_HEPMC3 } else if (genconfig.compare("hepmc") == 0) { // external HepMC file, or external program writing HepMC event @@ -195,9 +195,9 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair LOG(info) << "Init \'GeneratorHepMC\' with following parameters"; LOG(info) << param0; LOG(info) << param; - auto hepmcGen = new o2::eventgen::GeneratorHepMC(); - hepmcGen->setup(param0, param, conf); - primGen->AddGenerator(hepmcGen); + genptr.push_back(std::make_unique()); + genptr.back()->setup(param0, param, conf); + primGen->AddGenerator(genptr.back().get()); #endif #ifdef GENERATORS_WITH_PYTHIA8 } else if (genconfig.compare("alldets") == 0) { @@ -206,37 +206,37 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair // I compose it of: // 1) pythia8 auto py8config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_inel.cfg"; - auto py8 = makePythia8Gen(py8config); - primGen->AddGenerator(py8); + genptr.push_back(makePythia8Gen(py8config)); + primGen->AddGenerator(genptr.back().get()); // 2) forward muons - auto muon = makeBoxGen(13, 100, -2.5, -4.0, 100, 100, 0., 360); - primGen->AddGenerator(muon); + genptr.push_back(makeBoxGen(13, 100, -2.5, -4.0, 100, 100, 0., 360)); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("pythia8") == 0) { auto py8config = std::string(); - auto py8 = makePythia8Gen(py8config); - primGen->AddGenerator(py8); + genptr.push_back(makePythia8Gen(py8config)); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("pythia8pp") == 0) { auto py8config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_inel.cfg"; - auto py8 = makePythia8Gen(py8config); - primGen->AddGenerator(py8); + genptr.push_back(makePythia8Gen(py8config)); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("pythia8hf") == 0) { // pythia8 pp (HF production) // configures pythia for HF production in pp collisions at 14 TeV auto py8config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_hf.cfg"; - auto py8 = makePythia8Gen(py8config); - primGen->AddGenerator(py8); + genptr.push_back(makePythia8Gen(py8config)); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("pythia8hi") == 0) { // pythia8 heavy-ion // exploits pythia8 heavy-ion machinery (available from v8.230) // configures pythia for min.bias Pb-Pb collisions at 5.52 TeV auto py8config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_hi.cfg"; - auto py8 = makePythia8Gen(py8config); - primGen->AddGenerator(py8); + genptr.push_back(makePythia8Gen(py8config)); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("pythia8powheg") == 0) { // pythia8 with powheg auto py8config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_powheg.cfg"; - auto py8 = makePythia8Gen(py8config); - primGen->AddGenerator(py8); + genptr.push_back(makePythia8Gen(py8config)); + primGen->AddGenerator(genptr.back().get()); #endif } else if (genconfig.compare("external") == 0 || genconfig.compare("extgen") == 0) { // external generator via configuration macro @@ -245,21 +245,21 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair LOG(info) << params; auto extgen_filename = params.fileName; auto extgen_func = params.funcName; - auto extgen = o2::conf::GetFromMacro(extgen_filename, extgen_func, "FairGenerator*", "extgen"); - if (!extgen) { + genptr.push_back(std::unique_ptr(o2::conf::GetFromMacro(extgen_filename, extgen_func, "FairGenerator*", "extgen"))); + if (!genptr.back()) { LOG(fatal) << "Failed to retrieve \'extgen\': problem with configuration "; } - primGen->AddGenerator(extgen); + primGen->AddGenerator(genptr.back().get()); } else if (genconfig.compare("toftest") == 0) { // 1 muon per sector and per module LOG(info) << "Init tof test generator -> 1 muon per sector and per module"; for (int i = 0; i < 18; i++) { for (int j = 0; j < 5; j++) { - auto boxGen = new FairBoxGenerator(13, 1); /*protons*/ - boxGen->SetEtaRange(-0.8 + 0.32 * j + 0.15, -0.8 + 0.32 * j + 0.17); - boxGen->SetPRange(9, 10); - boxGen->SetPhiRange(10 + 20. * i - 1, 10 + 20. * i + 1); - boxGen->SetDebug(kTRUE); - primGen->AddGenerator(boxGen); + genptr.push_back(std::make_unique(13, 1)); /*protons*/ + genptr.back()->SetEtaRange(-0.8 + 0.32 * j + 0.15, -0.8 + 0.32 * j + 0.17); + genptr.back()->SetPRange(9, 10); + genptr.back()->SetPhiRange(10 + 20. * i - 1, 10 + 20. * i + 1); + genptr.back()->SetDebug(kTRUE); + primGen->AddGenerator(genptr.back().get()); } } #if defined(GENERATORS_WITH_PYTHIA8) && defined(GENERATORS_WITH_HEPMC3) @@ -277,8 +277,8 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair LOG(fatal) << "Configuration file for hybrid generator does not exist"; return; } - auto hybrid = new o2::eventgen::GeneratorHybrid(config); - primGen->AddGenerator(hybrid); + genptr.push_back(std::make_unique(config)); + primGen->AddGenerator(genptr.back().get()); #endif } else { LOG(fatal) << "Invalid generator"; From 03913e49067914264eb226027c847e02815071ee Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Wed, 4 Dec 2024 16:29:03 +0100 Subject: [PATCH 2/5] Changed child process spawning mechanism Fundamental to be able to kill the child process spawned by CMD functionality of GeneratorFileOrCmd generator. This was not so useful when the destructors were not called at the end of the simulation --- .../include/Generators/GeneratorFileOrCmd.h | 19 +++++++- Generators/src/GeneratorFileOrCmd.cxx | 48 +++++++++++++++++-- Generators/src/GeneratorHepMC.cxx | 6 +++ 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/Generators/include/Generators/GeneratorFileOrCmd.h b/Generators/include/Generators/GeneratorFileOrCmd.h index f0cc54613f3d2..cabdec58c4ee6 100644 --- a/Generators/include/Generators/GeneratorFileOrCmd.h +++ b/Generators/include/Generators/GeneratorFileOrCmd.h @@ -46,6 +46,12 @@ struct GeneratorFileOrCmd { * execute, but should not include pipes. */ void setCmd(const std::string& cmd) { mCmd = cmd; } + /** + * Set command child process PID + * + * @param cmdPid child process PID. + */ + void setCmdPid(const pid_t cmdPid) { mCmdPid = cmdPid; } /** * Set the number of events that a background command should * generate. This should come from @c SimConfig::getNEents. @@ -132,7 +138,14 @@ struct GeneratorFileOrCmd { * @return true if the background command line was executed, false * otherwise. */ - virtual bool executeCmdLine(const std::string& cmd) const; + virtual bool executeCmdLine(const std::string& cmd); + /** + * Terminates the background command using PID of the child + * process generated by fork. + * + * @return true if the process was terminated successfully + */ + virtual bool terminateCmd(); /** * Create a temporary file (and close it immediately). On success, * the list of file names is cleared and the name of the temporary @@ -236,6 +249,10 @@ struct GeneratorFileOrCmd { * Time in miliseconds between each wait for data */ int mWait = 500; + /** + * PID of the background command + */ + int mCmdPid = -1; }; } // namespace eventgen diff --git a/Generators/src/GeneratorFileOrCmd.cxx b/Generators/src/GeneratorFileOrCmd.cxx index f1fd8ade60d0b..b42544e305325 100644 --- a/Generators/src/GeneratorFileOrCmd.cxx +++ b/Generators/src/GeneratorFileOrCmd.cxx @@ -17,6 +17,8 @@ #include #include // POSIX only #include // POISX only +#include +#include #include // For filesystem operations #include @@ -115,14 +117,52 @@ std::string GeneratorFileOrCmd::makeCmdLine() const return s.str(); } // ----------------------------------------------------------------- -bool GeneratorFileOrCmd::executeCmdLine(const std::string& cmd) const +bool GeneratorFileOrCmd::executeCmdLine(const std::string& cmd) { LOG(info) << "Command line to execute: \"" << cmd << "\""; - int ret = std::system(cmd.c_str()); - if (ret != 0) { - LOG(fatal) << "Failed to spawn \"" << cmd << "\""; + // Fork a new process + pid_t pid = fork(); + if (pid == -1) { + LOG(fatal) << "Failed to fork process: " << std::strerror(errno); + return false; + } + + if (pid == 0) { + // Child process + setsid(); + execl("/bin/sh", "sh", "-c", cmd.c_str(), (char*)nullptr); + // If execl returns, there was an error, otherwise following lines will not be executed + LOG(fatal) << "Failed to execute command: " << std::strerror(errno); + _exit(EXIT_FAILURE); + } else { + // Parent process + setCmdPid(pid); + LOG(info) << "Child spawned process group is running with PID: " << mCmdPid; + } + return true; +} +// ----------------------------------------------------------------- +bool GeneratorFileOrCmd::terminateCmd() +{ + if (mCmdPid == -1) { + LOG(info) << "No command is currently running"; + return false; + } + + LOG(info) << "Terminating process ID group " << mCmdPid; + if (kill(-mCmdPid, SIGKILL) == -1) { + LOG(fatal) << "Failed to kill process: " << std::strerror(errno); return false; } + + // Wait for the process to terminate + int status; + if (waitpid(mCmdPid, &status, 0) == -1) { + LOG(fatal) << "Failed to wait for process termination: " << std::strerror(errno); + return false; + } + + mCmdPid = -1; // Reset the process ID return true; } // ----------------------------------------------------------------- diff --git a/Generators/src/GeneratorHepMC.cxx b/Generators/src/GeneratorHepMC.cxx index 4f38b01811f98..cf4451f9e3bb1 100644 --- a/Generators/src/GeneratorHepMC.cxx +++ b/Generators/src/GeneratorHepMC.cxx @@ -65,6 +65,12 @@ GeneratorHepMC::~GeneratorHepMC() if (mEvent) { delete mEvent; } + if (not mCmd.empty()) { + // Must be executed before removing the temporary file + // otherwise the current child process might still be writing on it + // causing unwanted stdout messages which could slow down the system + terminateCmd(); + } removeTemp(); } From e81a76f289ad90f3465b56b8a7d4a49aa24ef0ed Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Thu, 12 Dec 2024 16:50:35 +0100 Subject: [PATCH 3/5] Working version without smart pointers Cleanup function called manually in main simulation programs --- .../include/Generators/GeneratorFactory.h | 41 ++++- .../include/Generators/GeneratorFileOrCmd.h | 2 +- .../include/Generators/GeneratorService.h | 6 + Generators/src/GeneratorFactory.cxx | 145 +++++++++--------- Generators/src/GeneratorFileOrCmd.cxx | 45 ++++-- Generators/src/GeneratorHepMC.cxx | 13 +- Generators/src/GeneratorService.cxx | 1 - Generators/src/GeneratorTParticle.cxx | 13 +- macro/o2sim.C | 1 + run/O2PrimaryServerDevice.h | 1 + 10 files changed, 170 insertions(+), 98 deletions(-) diff --git a/Generators/include/Generators/GeneratorFactory.h b/Generators/include/Generators/GeneratorFactory.h index f7b013f4ceef0..0c53504226600 100644 --- a/Generators/include/Generators/GeneratorFactory.h +++ b/Generators/include/Generators/GeneratorFactory.h @@ -14,6 +14,20 @@ #ifndef ALICEO2_GENERATORFACTORY_H_ #define ALICEO2_GENERATORFACTORY_H_ +#include "FairGenerator.h" +#include "FairBoxGenerator.h" +#include +#include +#ifdef GENERATORS_WITH_HEPMC3 +#include +#endif +#if defined(GENERATORS_WITH_PYTHIA8) && defined(GENERATORS_WITH_HEPMC3) +#include +#endif +#ifdef GENERATORS_WITH_PYTHIA8 +#include +#endif + class FairPrimaryGenerator; namespace o2 { @@ -32,11 +46,32 @@ namespace eventgen // main purpose is to init a FairPrimGen given some (Sim)Config struct GeneratorFactory { static void setPrimaryGenerator(o2::conf::SimConfig const&, FairPrimaryGenerator*); + //Make destructor to delete all the pointers + ~GeneratorFactory() { + cleanup(); + } + static void cleanup() { + for (auto& gen : mBoxGenPtr) { + delete gen; + } + delete mPythia8GenPtr; + delete mHybridGenPtr; + delete mHepMCGenPtr; + delete mExtGenPtr; + delete mFileGenPtr; + delete mO2KineGenPtr; + delete mTParticleGenPtr; + } + static std::vector mBoxGenPtr; + static o2::eventgen::GeneratorPythia8* mPythia8GenPtr; + static o2::eventgen::GeneratorHybrid* mHybridGenPtr; + static o2::eventgen::GeneratorHepMC* mHepMCGenPtr; + static FairGenerator* mExtGenPtr; + static o2::eventgen::GeneratorFromFile* mFileGenPtr; + static o2::eventgen::GeneratorFromO2Kine* mO2KineGenPtr; + static o2::eventgen::GeneratorTParticle* mTParticleGenPtr; }; -template -std::vector> genptr; - } // end namespace eventgen } // end namespace o2 diff --git a/Generators/include/Generators/GeneratorFileOrCmd.h b/Generators/include/Generators/GeneratorFileOrCmd.h index cabdec58c4ee6..5a8f3411e883c 100644 --- a/Generators/include/Generators/GeneratorFileOrCmd.h +++ b/Generators/include/Generators/GeneratorFileOrCmd.h @@ -154,7 +154,7 @@ struct GeneratorFileOrCmd { * @return true if the temporary file name was generated * successfully. */ - virtual bool makeTemp(); + virtual bool makeTemp(const bool&); /** * Remove the temporary file if it was set and it exists. * diff --git a/Generators/include/Generators/GeneratorService.h b/Generators/include/Generators/GeneratorService.h index a0037707bcdd6..49b0208a9375f 100644 --- a/Generators/include/Generators/GeneratorService.h +++ b/Generators/include/Generators/GeneratorService.h @@ -20,6 +20,7 @@ #include #include // could be forward declaration #include +#include "Generators/GeneratorFactory.h" namespace o2 { @@ -59,6 +60,11 @@ class GeneratorService { public: + + ~GeneratorService() { + o2::eventgen::GeneratorFactory::cleanup(); + }; + void initService(std::string const& generatorName, std::string const& triggerName, VertexOption const& vtxOption); diff --git a/Generators/src/GeneratorFactory.cxx b/Generators/src/GeneratorFactory.cxx index 39be08fe18d57..f567446b34f04 100644 --- a/Generators/src/GeneratorFactory.cxx +++ b/Generators/src/GeneratorFactory.cxx @@ -13,26 +13,19 @@ #include #include -#include "FairGenerator.h" -#include "FairBoxGenerator.h" #include #include -#include -#include #include #ifdef GENERATORS_WITH_PYTHIA8 -#include #include #endif #include #include #include "Generators/GeneratorFromO2KineParam.h" #ifdef GENERATORS_WITH_HEPMC3 -#include #include #endif #if defined(GENERATORS_WITH_PYTHIA8) && defined(GENERATORS_WITH_HEPMC3) -#include #include #endif #include @@ -49,8 +42,17 @@ namespace o2 namespace eventgen { +std::vector GeneratorFactory::mBoxGenPtr; +o2::eventgen::GeneratorPythia8* GeneratorFactory::mPythia8GenPtr; +o2::eventgen::GeneratorHybrid* GeneratorFactory::mHybridGenPtr; +o2::eventgen::GeneratorHepMC* GeneratorFactory::mHepMCGenPtr; +FairGenerator* GeneratorFactory::mExtGenPtr; +o2::eventgen::GeneratorFromFile* GeneratorFactory::mFileGenPtr; +o2::eventgen::GeneratorFromO2Kine* GeneratorFactory::mO2KineGenPtr; +o2::eventgen::GeneratorTParticle* GeneratorFactory::mTParticleGenPtr; // reusable helper class // main purpose is to init a FairPrimGen given some (Sim)Config + void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, FairPrimaryGenerator* primGen) { if (!primGen) { @@ -61,7 +63,7 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair auto primGenO2 = dynamic_cast(primGen); auto makeBoxGen = [](int pdgid, int mult, double etamin, double etamax, double pmin, double pmax, double phimin, double phimax, bool debug = false) { - auto gen = std::make_unique(pdgid, mult); + auto gen = new FairBoxGenerator(pdgid, mult); gen->SetEtaRange(etamin, etamax); gen->SetPRange(pmin, pmax); gen->SetPhiRange(phimin, phimax); @@ -80,7 +82,7 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair .particleFilter = singleton.particleFilter, .verbose = singleton.verbose, }; - auto gen = std::make_unique(pars); + auto gen = new o2::eventgen::GeneratorPythia8(pars); if (!config.empty()) { LOG(info) << "Setting \'Pythia8\' base configuration: " << config << std::endl; gen->setConfig(config); // assign config; will be executed in Init function @@ -99,58 +101,58 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair auto& boxparam = BoxGunParam::Instance(); LOG(info) << "Init generic box generator with following parameters"; LOG(info) << boxparam; - genptr.push_back(makeBoxGen(boxparam.pdg, boxparam.number, boxparam.eta[0], boxparam.eta[1], boxparam.prange[0], boxparam.prange[1], boxparam.phirange[0], boxparam.phirange[1], boxparam.debug)); - primGen->AddGenerator(genptr.back().get()); + mBoxGenPtr.push_back(makeBoxGen(boxparam.pdg, boxparam.number, boxparam.eta[0], boxparam.eta[1], boxparam.prange[0], boxparam.prange[1], boxparam.phirange[0], boxparam.phirange[1], boxparam.debug)); + primGen->AddGenerator(mBoxGenPtr.back()); } else if (genconfig.compare("fwmugen") == 0) { // a simple "box" generator for forward muons LOG(info) << "Init box forward muons generator"; - genptr.push_back(makeBoxGen(13, 1, -4, -2.5, 50., 50., 0., 360)); - primGen->AddGenerator(genptr.back().get()); + mBoxGenPtr.push_back(makeBoxGen(13, 1, -4, -2.5, 50., 50., 0., 360)); + primGen->AddGenerator(mBoxGenPtr.back()); } else if (genconfig.compare("hmpidgun") == 0) { // a simple "box" generator for forward muons LOG(info) << "Init hmpid gun generator"; - genptr.push_back(makeBoxGen(-211, 100, -0.5, -0.5, 2, 5, -5, 60)); - primGen->AddGenerator(genptr.back().get()); + mBoxGenPtr.push_back(makeBoxGen(-211, 100, -0.5, -0.5, 2, 5, -5, 60)); + primGen->AddGenerator(mBoxGenPtr.back()); } else if (genconfig.compare("fwpigen") == 0) { // a simple "box" generator for forward pions LOG(info) << "Init box forward pions generator"; - genptr.push_back(makeBoxGen(-211, 10, -4, -2.5, 7, 7, 0, 360)); - primGen->AddGenerator(genptr.back().get()); + mBoxGenPtr.push_back(makeBoxGen(-211, 10, -4, -2.5, 7, 7, 0, 360)); + primGen->AddGenerator(mBoxGenPtr.back()); } else if (genconfig.compare("fwrootino") == 0) { // a simple "box" generator for forward rootinos LOG(info) << "Init box forward rootinos generator"; - genptr.push_back(makeBoxGen(0, 1, -4, -2.5, 1, 5, 0, 360)); - primGen->AddGenerator(genptr.back().get()); + mBoxGenPtr.push_back(makeBoxGen(0, 1, -4, -2.5, 1, 5, 0, 360)); + primGen->AddGenerator(mBoxGenPtr.back()); } else if (genconfig.compare("zdcgen") == 0) { // a simple "box" generator for forward neutrons LOG(info) << "Init box forward/backward zdc generator"; - genptr.push_back(makeBoxGen(2112 /*neutrons*/, 1, -8, -9999, 500, 1000, 0., 360.)); - genptr.push_back(makeBoxGen(2112 /*neutrons*/, 1, 8, 9999, 500, 1000, 0., 360.)); - primGen->AddGenerator(genptr.back().get()); - primGen->AddGenerator(genptr.back().get()); + mBoxGenPtr.push_back(makeBoxGen(2112 /*neutrons*/, 1, -8, -9999, 500, 1000, 0., 360.)); + primGen->AddGenerator(mBoxGenPtr.back()); + mBoxGenPtr.push_back(makeBoxGen(2112 /*neutrons*/, 1, 8, 9999, 500, 1000, 0., 360.)); + primGen->AddGenerator(mBoxGenPtr.back()); } else if (genconfig.compare("emcgenele") == 0) { // box generator with one electron per event LOG(info) << "Init box generator for electrons in EMCAL"; // using phi range of emcal - genptr.push_back(makeBoxGen(11, 1, -0.67, 0.67, 15, 15, 80, 187)); - primGen->AddGenerator(genptr.back().get()); + mBoxGenPtr.push_back(makeBoxGen(11, 1, -0.67, 0.67, 15, 15, 80, 187)); + primGen->AddGenerator(mBoxGenPtr.back()); } else if (genconfig.compare("emcgenphoton") == 0) { LOG(info) << "Init box generator for photons in EMCAL"; - genptr.push_back(makeBoxGen(22, 1, -0.67, 0.67, 15, 15, 80, 187)); - primGen->AddGenerator(genptr.back().get()); + mBoxGenPtr.push_back(makeBoxGen(22, 1, -0.67, 0.67, 15, 15, 80, 187)); + primGen->AddGenerator(mBoxGenPtr.back()); } else if (genconfig.compare("fddgen") == 0) { LOG(info) << "Init box FDD generator"; - genptr.push_back(makeBoxGen(13, 1000, -7, -4.8, 10, 500, 0, 360.)); - genptr.push_back(makeBoxGen(13, 1000, 4.9, 6.3, 10, 500, 0., 360)); - primGen->AddGenerator(genptr.back().get()); - primGen->AddGenerator(genptr.back().get()); + mBoxGenPtr.push_back(makeBoxGen(13, 1000, -7, -4.8, 10, 500, 0, 360.)); + primGen->AddGenerator(mBoxGenPtr.back()); + mBoxGenPtr.push_back(makeBoxGen(13, 1000, 4.9, 6.3, 10, 500, 0., 360)); + primGen->AddGenerator(mBoxGenPtr.back()); } else if (genconfig.compare("extkin") == 0) { // external kinematics // needs precense of a kinematics file "Kinematics.root" // TODO: make this configurable and check for presence - genptr.push_back(std::make_unique(conf.getExtKinematicsFileName().c_str())); - genptr.back()->SetStartEvent(conf.getStartEvent()); - primGen->AddGenerator(genptr.back().get()); + mFileGenPtr = new o2::eventgen::GeneratorFromFile(conf.getExtKinematicsFileName().c_str()); + mFileGenPtr->SetStartEvent(conf.getStartEvent()); + primGen->AddGenerator(mFileGenPtr); LOG(info) << "using external kinematics"; } else if (genconfig.compare("extkinO2") == 0) { // external kinematics from previous O2 output @@ -165,9 +167,9 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair .rngseed = singleton.rngseed, .randomphi = singleton.randomphi, .fileName = name1.size() > 0 ? name1.c_str() : name2.c_str()}; - genptr.push_back(std::make_unique(pars)); - genptr.back()->SetStartEvent(conf.getStartEvent()); - primGen->AddGenerator(genptr.back().get()); + mO2KineGenPtr = new o2::eventgen::GeneratorFromO2Kine(pars); + mO2KineGenPtr->SetStartEvent(conf.getStartEvent()); + primGen->AddGenerator(mO2KineGenPtr); if (pars.continueMode) { auto o2PrimGen = dynamic_cast(primGen); if (o2PrimGen) { @@ -175,13 +177,6 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair } } LOG(info) << "using external O2 kinematics"; - } else if (genconfig.compare("evtpool") == 0) { - // case of an "event-pool" which is a specialization of extkinO2 - // with some additional logic in file management and less configurability - // and not features such as "continue transport" - auto extGen = new o2::eventgen::GeneratorFromEventPool(o2::eventgen::GeneratorEventPoolParam::Instance().detach()); - primGen->AddGenerator(extGen); - LOG(info) << "using the eventpool generator"; } else if (genconfig.compare("tparticle") == 0) { // External ROOT file(s) with tree of TParticle in clones array, // or external program generating such a file @@ -190,9 +185,9 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair LOG(info) << "Init 'GeneratorTParticle' with the following parameters"; LOG(info) << param0; LOG(info) << param; - genptr.push_back(std::make_unique()); - genptr.back()->setup(param0, param, conf); - primGen->AddGenerator(genptr.back().get()); + mTParticleGenPtr = new o2::eventgen::GeneratorTParticle(); + mTParticleGenPtr->setup(param0, param, conf); + primGen->AddGenerator(mTParticleGenPtr); #ifdef GENERATORS_WITH_HEPMC3 } else if (genconfig.compare("hepmc") == 0) { // external HepMC file, or external program writing HepMC event @@ -202,9 +197,9 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair LOG(info) << "Init \'GeneratorHepMC\' with following parameters"; LOG(info) << param0; LOG(info) << param; - genptr.push_back(std::make_unique()); - genptr.back()->setup(param0, param, conf); - primGen->AddGenerator(genptr.back().get()); + mHepMCGenPtr = new o2::eventgen::GeneratorHepMC(); + mHepMCGenPtr->setup(param0, param, conf); + primGen->AddGenerator(mHepMCGenPtr); #endif #ifdef GENERATORS_WITH_PYTHIA8 } else if (genconfig.compare("alldets") == 0) { @@ -213,37 +208,37 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair // I compose it of: // 1) pythia8 auto py8config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_inel.cfg"; - genptr.push_back(makePythia8Gen(py8config)); - primGen->AddGenerator(genptr.back().get()); + mPythia8GenPtr = makePythia8Gen(py8config); + primGen->AddGenerator(mPythia8GenPtr); // 2) forward muons - genptr.push_back(makeBoxGen(13, 100, -2.5, -4.0, 100, 100, 0., 360)); - primGen->AddGenerator(genptr.back().get()); + mBoxGenPtr.push_back(makeBoxGen(13, 100, -2.5, -4.0, 100, 100, 0., 360)); + primGen->AddGenerator(mBoxGenPtr.back()); } else if (genconfig.compare("pythia8") == 0) { auto py8config = std::string(); - genptr.push_back(makePythia8Gen(py8config)); - primGen->AddGenerator(genptr.back().get()); + mPythia8GenPtr = makePythia8Gen(py8config); + primGen->AddGenerator(mPythia8GenPtr); } else if (genconfig.compare("pythia8pp") == 0) { auto py8config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_inel.cfg"; - genptr.push_back(makePythia8Gen(py8config)); - primGen->AddGenerator(genptr.back().get()); + mPythia8GenPtr = makePythia8Gen(py8config); + primGen->AddGenerator(mPythia8GenPtr); } else if (genconfig.compare("pythia8hf") == 0) { // pythia8 pp (HF production) // configures pythia for HF production in pp collisions at 14 TeV auto py8config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_hf.cfg"; - genptr.push_back(makePythia8Gen(py8config)); - primGen->AddGenerator(genptr.back().get()); + mPythia8GenPtr = makePythia8Gen(py8config); + primGen->AddGenerator(mPythia8GenPtr); } else if (genconfig.compare("pythia8hi") == 0) { // pythia8 heavy-ion // exploits pythia8 heavy-ion machinery (available from v8.230) // configures pythia for min.bias Pb-Pb collisions at 5.52 TeV auto py8config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_hi.cfg"; - genptr.push_back(makePythia8Gen(py8config)); - primGen->AddGenerator(genptr.back().get()); + mPythia8GenPtr = makePythia8Gen(py8config); + primGen->AddGenerator(mPythia8GenPtr); } else if (genconfig.compare("pythia8powheg") == 0) { // pythia8 with powheg auto py8config = std::string(std::getenv("O2_ROOT")) + "/share/Generators/egconfig/pythia8_powheg.cfg"; - genptr.push_back(makePythia8Gen(py8config)); - primGen->AddGenerator(genptr.back().get()); + mPythia8GenPtr = makePythia8Gen(py8config); + primGen->AddGenerator(mPythia8GenPtr); #endif } else if (genconfig.compare("external") == 0 || genconfig.compare("extgen") == 0) { // external generator via configuration macro @@ -252,21 +247,21 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair LOG(info) << params; auto extgen_filename = params.fileName; auto extgen_func = params.funcName; - genptr.push_back(std::unique_ptr(o2::conf::GetFromMacro(extgen_filename, extgen_func, "FairGenerator*", "extgen"))); - if (!genptr.back()) { + mExtGenPtr = o2::conf::GetFromMacro(extgen_filename, extgen_func, "FairGenerator*", "extgen"); + if (!mExtGenPtr) { LOG(fatal) << "Failed to retrieve \'extgen\': problem with configuration "; } - primGen->AddGenerator(genptr.back().get()); + primGen->AddGenerator(mExtGenPtr); } else if (genconfig.compare("toftest") == 0) { // 1 muon per sector and per module LOG(info) << "Init tof test generator -> 1 muon per sector and per module"; for (int i = 0; i < 18; i++) { for (int j = 0; j < 5; j++) { - genptr.push_back(std::make_unique(13, 1)); /*protons*/ - genptr.back()->SetEtaRange(-0.8 + 0.32 * j + 0.15, -0.8 + 0.32 * j + 0.17); - genptr.back()->SetPRange(9, 10); - genptr.back()->SetPhiRange(10 + 20. * i - 1, 10 + 20. * i + 1); - genptr.back()->SetDebug(kTRUE); - primGen->AddGenerator(genptr.back().get()); + mBoxGenPtr.push_back(new FairBoxGenerator(13, 1)); /*protons*/ + mBoxGenPtr.back()->SetEtaRange(-0.8 + 0.32 * j + 0.15, -0.8 + 0.32 * j + 0.17); + mBoxGenPtr.back()->SetPRange(9, 10); + mBoxGenPtr.back()->SetPhiRange(10 + 20. * i - 1, 10 + 20. * i + 1); + mBoxGenPtr.back()->SetDebug(kTRUE); + primGen->AddGenerator(mBoxGenPtr.back()); } } #if defined(GENERATORS_WITH_PYTHIA8) && defined(GENERATORS_WITH_HEPMC3) @@ -284,8 +279,8 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair LOG(fatal) << "Configuration file for hybrid generator does not exist"; return; } - genptr.push_back(std::make_unique(config)); - primGen->AddGenerator(genptr.back().get()); + mHybridGenPtr = new o2::eventgen::GeneratorHybrid(config); + primGen->AddGenerator(mHybridGenPtr); #endif } else { LOG(fatal) << "Invalid generator"; diff --git a/Generators/src/GeneratorFileOrCmd.cxx b/Generators/src/GeneratorFileOrCmd.cxx index b42544e305325..3baf9681159b2 100644 --- a/Generators/src/GeneratorFileOrCmd.cxx +++ b/Generators/src/GeneratorFileOrCmd.cxx @@ -16,7 +16,7 @@ // For fifo's and system call #include #include // POSIX only -#include // POISX only +#include // POSIX only #include #include #include @@ -166,19 +166,40 @@ bool GeneratorFileOrCmd::terminateCmd() return true; } // ----------------------------------------------------------------- -bool GeneratorFileOrCmd::makeTemp() +bool GeneratorFileOrCmd::makeTemp(const bool& fromName) { - mFileNames.clear(); - char buf[] = "generatorFifoXXXXXX"; - auto fp = mkstemp(buf); - if (fp < 0) { - LOG(fatal) << "Failed to make temporary file: " - << std::strerror(errno); - return false; + if (fromName) { + if (mFileNames.empty()) { + LOG(fatal) << "No file names to make temporary file from"; + return false; + } else if (mFileNames.size() > 1) { + LOG(warning) << "More than one file name to make temporary file from"; + LOG(warning) << "Using the first one: " << mFileNames.front(); + LOG(warning) << "Removing all the others"; + mFileNames.erase(++mFileNames.begin(), mFileNames.end()); + } else { + LOG(debug) << "Making temporary file from: " << mFileNames.front(); + } + std::ofstream ofs(mFileNames.front().c_str()); + if (!ofs) { + LOG(fatal) << "Failed to create temporary file: " << mFileNames.front(); + return false; + } + mTemporary = std::string(mFileNames.front()); + ofs.close(); + } else { + mFileNames.clear(); + char buf[] = "generatorFifoXXXXXX"; + auto fp = mkstemp(buf); + if (fp < 0) { + LOG(fatal) << "Failed to make temporary file: " + << std::strerror(errno); + return false; + } + mTemporary = std::string(buf); + mFileNames.push_back(mTemporary); + close(fp); } - mTemporary = std::string(buf); - mFileNames.push_back(mTemporary); - close(fp); return true; } // ----------------------------------------------------------------- diff --git a/Generators/src/GeneratorHepMC.cxx b/Generators/src/GeneratorHepMC.cxx index ccff8d12db274..371e0cf1acce1 100644 --- a/Generators/src/GeneratorHepMC.cxx +++ b/Generators/src/GeneratorHepMC.cxx @@ -581,9 +581,16 @@ Bool_t GeneratorHepMC::Init() // All of this can conviniently be achieved via a wrapper script // around the actual EG program. if (not mCmd.empty()) { - // Set filename to be a temporary name - if (not makeTemp()) { - return false; + if (mFileNames.empty()) { + // Set filename to be a temporary name + if (not makeTemp(false)) { + return false; + } + } else { + // Use the first filename as output for cmd line + if (not makeTemp(true)) { + return false; + } } // Make a fifo diff --git a/Generators/src/GeneratorService.cxx b/Generators/src/GeneratorService.cxx index 21c25aeb73720..cd0a462a45a6c 100644 --- a/Generators/src/GeneratorService.cxx +++ b/Generators/src/GeneratorService.cxx @@ -10,7 +10,6 @@ // or submit itself to any jurisdiction. #include "Generators/GeneratorService.h" -#include "Generators/GeneratorFactory.h" #include "SimConfig/SimConfig.h" #include "DataFormatsCalibration/MeanVertexObject.h" diff --git a/Generators/src/GeneratorTParticle.cxx b/Generators/src/GeneratorTParticle.cxx index ab68f7f39b1bf..06b4cbc147fca 100644 --- a/Generators/src/GeneratorTParticle.cxx +++ b/Generators/src/GeneratorTParticle.cxx @@ -54,9 +54,16 @@ Bool_t GeneratorTParticle::Init() mChain->SetBranchAddress(mBranchName.c_str(), &mTParticles); if (not mCmd.empty()) { - // Set filename to be a temporary name - if (not makeTemp()) { - return false; + if (mFileNames.empty()) { + // Set filename to be a temporary name + if (not makeTemp(false)) { + return false; + } + } else { + // Use the first filename as output for cmd line + if (not makeTemp(true)) { + return false; + } } // Build command line, Assumes command line parameter diff --git a/macro/o2sim.C b/macro/o2sim.C index 4bd2ff4e4d9cb..da0075fcef48f 100644 --- a/macro/o2sim.C +++ b/macro/o2sim.C @@ -325,4 +325,5 @@ void o2sim(bool asservice = false, bool evalmat = false) auto run = o2sim_init(asservice, evalmat); o2sim_run(run, asservice); delete run; + o2::eventgen::GeneratorFactory::cleanup(); } diff --git a/run/O2PrimaryServerDevice.h b/run/O2PrimaryServerDevice.h index 53b86d1f23591..c4f40442316ad 100644 --- a/run/O2PrimaryServerDevice.h +++ b/run/O2PrimaryServerDevice.h @@ -73,6 +73,7 @@ class O2PrimaryServerDevice final : public fair::mq::Device if (mControlThread.joinable()) { mControlThread.join(); } + o2::eventgen::GeneratorFactory::cleanup(); } catch (...) { } } From d32b4d1da77a3b5089070986cbd2ed1b4936a387 Mon Sep 17 00:00:00 2001 From: ALICE Action Bot Date: Thu, 12 Dec 2024 15:51:24 +0000 Subject: [PATCH 4/5] Please consider the following formatting changes --- Generators/include/Generators/GeneratorFactory.h | 8 +++++--- Generators/include/Generators/GeneratorService.h | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Generators/include/Generators/GeneratorFactory.h b/Generators/include/Generators/GeneratorFactory.h index 0c53504226600..d4704d04b29b3 100644 --- a/Generators/include/Generators/GeneratorFactory.h +++ b/Generators/include/Generators/GeneratorFactory.h @@ -46,11 +46,13 @@ namespace eventgen // main purpose is to init a FairPrimGen given some (Sim)Config struct GeneratorFactory { static void setPrimaryGenerator(o2::conf::SimConfig const&, FairPrimaryGenerator*); - //Make destructor to delete all the pointers - ~GeneratorFactory() { + // Make destructor to delete all the pointers + ~GeneratorFactory() + { cleanup(); } - static void cleanup() { + static void cleanup() + { for (auto& gen : mBoxGenPtr) { delete gen; } diff --git a/Generators/include/Generators/GeneratorService.h b/Generators/include/Generators/GeneratorService.h index 49b0208a9375f..f65a0a84f15e6 100644 --- a/Generators/include/Generators/GeneratorService.h +++ b/Generators/include/Generators/GeneratorService.h @@ -60,8 +60,8 @@ class GeneratorService { public: - - ~GeneratorService() { + ~GeneratorService() + { o2::eventgen::GeneratorFactory::cleanup(); }; From 47747497bbe9fcfaee488d0a77fc9e82a79cf8c1 Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Fri, 13 Dec 2024 12:04:30 +0100 Subject: [PATCH 5/5] Added PrimaryGenerator pointer deletion in destructor --- Generators/include/Generators/GeneratorService.h | 5 ----- run/O2PrimaryServerDevice.h | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Generators/include/Generators/GeneratorService.h b/Generators/include/Generators/GeneratorService.h index f65a0a84f15e6..58de17c609042 100644 --- a/Generators/include/Generators/GeneratorService.h +++ b/Generators/include/Generators/GeneratorService.h @@ -60,11 +60,6 @@ class GeneratorService { public: - ~GeneratorService() - { - o2::eventgen::GeneratorFactory::cleanup(); - }; - void initService(std::string const& generatorName, std::string const& triggerName, VertexOption const& vtxOption); diff --git a/run/O2PrimaryServerDevice.h b/run/O2PrimaryServerDevice.h index c4f40442316ad..598f19a1b9f80 100644 --- a/run/O2PrimaryServerDevice.h +++ b/run/O2PrimaryServerDevice.h @@ -73,7 +73,7 @@ class O2PrimaryServerDevice final : public fair::mq::Device if (mControlThread.joinable()) { mControlThread.join(); } - o2::eventgen::GeneratorFactory::cleanup(); + delete mPrimGen; } catch (...) { } }