diff --git a/Generators/include/Generators/GeneratorFactory.h b/Generators/include/Generators/GeneratorFactory.h index 9f4dfb5514582..d4704d04b29b3 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,6 +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; }; } // end namespace eventgen diff --git a/Generators/include/Generators/GeneratorFileOrCmd.h b/Generators/include/Generators/GeneratorFileOrCmd.h index f0cc54613f3d2..5a8f3411e883c 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 @@ -141,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. * @@ -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/include/Generators/GeneratorService.h b/Generators/include/Generators/GeneratorService.h index a0037707bcdd6..58de17c609042 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 { diff --git a/Generators/src/GeneratorFactory.cxx b/Generators/src/GeneratorFactory.cxx index dc2f4f2159b4d..f1305a4312526 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) { @@ -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; - 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); + 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"; - auto boxGen = makeBoxGen(13, 1, -4, -2.5, 50., 50., 0., 360); - primGen->AddGenerator(boxGen); + 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"; - auto boxGen = makeBoxGen(-211, 100, -0.5, -0.5, 2, 5, -5, 60); - primGen->AddGenerator(boxGen); + 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"; - auto boxGen = makeBoxGen(-211, 10, -4, -2.5, 7, 7, 0, 360); - primGen->AddGenerator(boxGen); + 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"; - auto boxGen = makeBoxGen(0, 1, -4, -2.5, 1, 5, 0, 360); - primGen->AddGenerator(boxGen); + 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"; - 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); + 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 - auto elecgen = makeBoxGen(11, 1, -0.67, 0.67, 15, 15, 80, 187); - primGen->AddGenerator(elecgen); + 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"; - auto photongen = makeBoxGen(22, 1, -0.67, 0.67, 15, 15, 80, 187); - primGen->AddGenerator(photongen); + 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"; - 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); + 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 - auto extGen = new o2::eventgen::GeneratorFromFile(conf.getExtKinematicsFileName().c_str()); - extGen->SetStartEvent(conf.getStartEvent()); - primGen->AddGenerator(extGen); + 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()}; - auto extGen = new o2::eventgen::GeneratorFromO2Kine(pars); - extGen->SetStartEvent(conf.getStartEvent()); - primGen->AddGenerator(extGen); + 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; - auto tgen = new o2::eventgen::GeneratorTParticle(); - tgen->setup(param0, param, conf); - primGen->AddGenerator(tgen); + 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; - auto hepmcGen = new o2::eventgen::GeneratorHepMC(); - hepmcGen->setup(param0, param, conf); - primGen->AddGenerator(hepmcGen); + 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"; - auto py8 = makePythia8Gen(py8config); - primGen->AddGenerator(py8); + mPythia8GenPtr = makePythia8Gen(py8config); + primGen->AddGenerator(mPythia8GenPtr); // 2) forward muons - auto muon = makeBoxGen(13, 100, -2.5, -4.0, 100, 100, 0., 360); - primGen->AddGenerator(muon); + 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(); - auto py8 = makePythia8Gen(py8config); - primGen->AddGenerator(py8); + 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"; - auto py8 = makePythia8Gen(py8config); - primGen->AddGenerator(py8); + 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"; - auto py8 = makePythia8Gen(py8config); - primGen->AddGenerator(py8); + 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"; - auto py8 = makePythia8Gen(py8config); - primGen->AddGenerator(py8); + 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"; - auto py8 = makePythia8Gen(py8config); - primGen->AddGenerator(py8); + 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; - auto extgen = o2::conf::GetFromMacro(extgen_filename, extgen_func, "FairGenerator*", "extgen"); - if (!extgen) { + mExtGenPtr = o2::conf::GetFromMacro(extgen_filename, extgen_func, "FairGenerator*", "extgen"); + if (!mExtGenPtr) { LOG(fatal) << "Failed to retrieve \'extgen\': problem with configuration "; } - primGen->AddGenerator(extgen); + 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++) { - 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); + 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,9 +279,9 @@ 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); - hybrid->setNEvents(conf.getNEvents()); - primGen->AddGenerator(hybrid); + mHybridGenPtr = new o2::eventgen::GeneratorHybrid(config); + mHybridGenPtr->setNEvents(conf.getNEvents()); + primGen->AddGenerator(mHybridGenPtr); #endif } else { LOG(fatal) << "Invalid generator"; diff --git a/Generators/src/GeneratorFileOrCmd.cxx b/Generators/src/GeneratorFileOrCmd.cxx index f1fd8ade60d0b..3baf9681159b2 100644 --- a/Generators/src/GeneratorFileOrCmd.cxx +++ b/Generators/src/GeneratorFileOrCmd.cxx @@ -16,7 +16,9 @@ // For fifo's and system call #include #include // POSIX only -#include // POISX only +#include // POSIX only +#include +#include #include // For filesystem operations #include @@ -115,30 +117,89 @@ 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::makeTemp() +bool GeneratorFileOrCmd::terminateCmd() { - mFileNames.clear(); - char buf[] = "generatorFifoXXXXXX"; - auto fp = mkstemp(buf); - if (fp < 0) { - LOG(fatal) << "Failed to make temporary file: " - << std::strerror(errno); + 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; } - mTemporary = std::string(buf); - mFileNames.push_back(mTemporary); - close(fp); + + mCmdPid = -1; // Reset the process ID + return true; +} +// ----------------------------------------------------------------- +bool GeneratorFileOrCmd::makeTemp(const bool& fromName) +{ + 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); + } return true; } // ----------------------------------------------------------------- diff --git a/Generators/src/GeneratorHepMC.cxx b/Generators/src/GeneratorHepMC.cxx index 2076910b2bf5f..371e0cf1acce1 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(); } @@ -575,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..598f19a1b9f80 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(); } + delete mPrimGen; } catch (...) { } }