From e81a76f289ad90f3465b56b8a7d4a49aa24ef0ed Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Thu, 12 Dec 2024 16:50:35 +0100 Subject: [PATCH] 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 (...) { } }