24 Debug::Debug(__PRETTY_FUNCTION__,
"progress", progress, max);
28 std::cout <<
'\r' <<
'[';
29 for (
unsigned i = 0; i < max; i++) {
32 else if (i == progress)
37 std::cout << "] " << progress * 100/max << '%
'; 38 std::flush(std::cout); 41 throw std::runtime_error{"Nothing to run over."}; 49 Types::strings tokenize(const std::string& str) {
50 std::istringstream ss {str};
51 Types::strings output {
52 std::istream_iterator<std::string>{ss},
53 std::istream_iterator<std::string>{}
59 Types::strings split(const std::string& str, const std::string& delim = "\n") {
60 Types::strings output;
61 std::string::size_type prev = 0;
62 for(auto pos = str.find(delim);
63 pos != std::string::npos;
64 prev = pos + delim.size(), pos = str.find(delim, prev))
65 output.push_back(str.substr(prev, pos - prev));
67 auto last = str.substr(prev);
69 output.push_back(last);
71 Debug::Debug(__PRETTY_FUNCTION__, output.size());
77 std::string shell(const std::string& cmd) {
78 std::array<char, 128> buffer;
80 std::shared_ptr<FILE> pipe(popen(cmd.data(), "r"), pclose);
82 throw std::runtime_error("popen() failed");
83 while(not feof(pipe.get())) {
84 if (fgets(buffer.data(), 128, pipe.get()))
85 output += buffer.data();
87 Debug::Debug(__PRETTY_FUNCTION__, cmd, "---", output);
92 std::string env(const std::string& variable, const std::string& fallback = "") {
93 if (variable == "nthreads")
94 ROOT::EnableThreadSafety();
96 auto* output = getenv(variable.data());
98 return std::string(output);
99 if (not fallback.size())
100 throw std::runtime_error(std::string("Requesting non-existent variable '
") + variable + "' with no fallback"); 101 return std::string(fallback); 104 template<typename O, typename C, typename F> 105 std::vector<O> comprehension (const C& container, const F& func) { 106 std::vector<O> output {}; 107 for (auto& iter : container) 108 output.push_back(func(iter));