28#include <fairlogger/Logger.h>
33std::string ltrim(
const std::string& s,
const std::string& what =
"\" ' ")
35 auto start =
s.find_first_not_of(what);
36 if (
start == std::string::npos) {
43std::string rtrim(
const std::string& s,
const std::string& what =
"\"' ")
45 auto end =
s.find_last_not_of(what);
46 return s.substr(0,
end + 1);
49std::string
trim(
const std::string& s,
const std::string& what =
"\"' ")
51 return rtrim(ltrim(s, what), what);
93 std::stringstream s(filenames);
95 while (std::getline(s,
f,
',')) {
122 LOG(info) <<
"Command line to execute: \"" << cmd <<
"\"";
126 LOG(fatal) <<
"Failed to fork process: " << std::strerror(errno);
133 execl(
"/bin/sh",
"sh",
"-c", cmd.c_str(), (
char*)
nullptr);
135 LOG(fatal) <<
"Failed to execute command: " << std::strerror(errno);
140 LOG(info) <<
"Child spawned process group is running with PID: " <<
mCmdPid;
148 LOG(info) <<
"No command is currently running";
152 LOG(info) <<
"Terminating process ID group " <<
mCmdPid;
153 if (kill(-
mCmdPid, SIGKILL) == -1) {
154 LOG(fatal) <<
"Failed to kill process: " << std::strerror(errno);
160 if (waitpid(
mCmdPid, &status, 0) == -1) {
161 LOG(fatal) <<
"Failed to wait for process termination: " << std::strerror(errno);
173 LOG(fatal) <<
"No file names to make temporary file from";
176 LOG(warning) <<
"More than one file name to make temporary file from";
177 LOG(warning) <<
"Using the first one: " <<
mFileNames.front();
178 LOG(warning) <<
"Removing all the others";
183 std::ofstream ofs(
mFileNames.front().c_str());
185 LOG(fatal) <<
"Failed to create temporary file: " <<
mFileNames.front();
192 char buf[] =
"generatorFifoXXXXXX";
193 auto fp = mkstemp(
buf);
195 LOG(fatal) <<
"Failed to make temporary file: "
196 << std::strerror(errno);
209 LOG(info) <<
"Temporary file name empty, nothing to remove";
217 if (not std::filesystem::exists(p)) {
218 LOG(info) <<
"Temporary file " << p <<
" does not exist";
224 std::filesystem::remove(p, ec);
226 LOG(warn) <<
"When removing " << p <<
": " << ec.message();
241 int ret = mkfifo(fileName.c_str(), 0600);
243 LOG(fatal) <<
"Failed to make fifo \"" << fileName <<
"\": "
244 << std::strerror(errno);
255 auto c = std::filesystem::canonical(std::filesystem::path(
f));
258 }
catch (std::exception& e) {
259 LOG(error) << e.what();
267 using namespace std::chrono_literals;
272 LOG(
debug) <<
"Waiting for data on " << p;
275 while (not std::filesystem::exists(p)) {
276 std::this_thread::sleep_for(
mWait * 1ms);
281 while (std::filesystem::file_size(p) <= 256) {
282 std::this_thread::sleep_for(
mWait * 1ms);
286 LOG(
debug) <<
"Got data in " << p <<
", sleeping for a while";
287 std::this_thread::sleep_for(
mWait * 2ms);
Utility functions for MC particles.
ULong_t getStartSeed() const
unsigned int getNEvents() const
GLenum GLuint GLenum GLsizei const GLchar * buf
std::string trim(std::string const &str)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
void setCmdPid(const pid_t cmdPid)
virtual bool ensureFiles()
virtual bool terminateCmd()
void setBackgroundSwitch(const std::string &opt)
void setSeedSwitch(const std::string &opt)
void setFileNames(const std::string &filenames)
void setNEvents(unsigned int nev)
void setup(const GeneratorFileOrCmdParam ¶m, const conf::SimConfig &config)
std::list< std::string > mFileNames
void setSeed(unsigned long seed)
void setNEventsSwitch(const std::string &opt)
void setOutputSwitch(const std::string &opt)
std::string mNEventsSwitch
void setCmd(const std::string &cmd)
virtual std::string makeCmdLine() const
std::string mOutputSwitch
virtual void waitForData(const std::string &filename) const
virtual bool removeTemp() const
virtual bool executeCmdLine(const std::string &cmd)
virtual bool makeTemp(const bool &)
std::string mBackgroundSwitch
void setBmaxSwitch(const std::string &opt)
virtual bool makeFifo() const
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"