15 static bool MaCh3WelcomeInitialised =
false;
17 if(MaCh3WelcomeInitialised)
return;
41 MaCh3WelcomeInitialised =
true;
49 std::string MaCh3_VERSION =
"";
51 if(std::getenv(
"MaCh3_ROOT") ==
nullptr){
52 throw MaCh3Exception(__FILE__, __LINE__,
"Error: you haven't sourced setup.MaCh3.sh in core!");
55 std::string file = std::string(std::getenv(
"MaCh3_ROOT")) +
"/version.h";
57 std::ifstream versionFile(file);
60 if (!versionFile.is_open()) {
66 const std::string searchKey =
"MaCh3_VERSION=";
69 while (std::getline(versionFile, line)) {
71 auto pos = line.find(searchKey);
72 if (pos != std::string::npos) {
74 MaCh3_VERSION = line.substr(pos + searchKey.length());
75 MaCh3_VERSION.erase(0, MaCh3_VERSION.find_first_not_of(
"\""));
76 MaCh3_VERSION.erase(MaCh3_VERSION.find_last_not_of(
"\";") + 1);
125 if (std::getenv(
"OMP_NUM_THREADS") !=
nullptr)
return;
128 constexpr
int MaxAllowedThreads = 16;
129 constexpr
int RecommendedThreads = 8;
131 if (nThreads > MaxAllowedThreads) {
132 MACH3LOG_CRITICAL(
"You specified more than {} threads ({})", MaxAllowedThreads, nThreads);
180 std::array<char, 128> buffer;
182 std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(),
"r"), pclose);
186 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr) {
187 result += buffer.data();
190 result.erase(std::remove(result.begin(), result.end(),
'\n'), result.end());
201 Int_t bytesProcessed{ chain->GetEntry(entry) };
205 Double_t timeInSeconds = timer.RealTime();
206 Double_t dataRateMBps = (double(bytesProcessed) / (1024.0 * 1024.0)) / timeInSeconds;
208 MACH3LOG_INFO(
"Data transfer: {} B, rate: {:.2f} MB/s", bytesProcessed, dataRateMBps);
215 double progress = double(Done)/double(All);
216 const int barWidth = 20;
217 std::ostringstream progressBar;
220 int pos = int(barWidth * progress);
221 for (
int i = 0; i < barWidth; ++i) {
230 progressBar <<
"] " << std::setw(3) << Done <<
"/"<< All<<
" ("<<
static_cast<int>(progress * 100.0)<<
"%)\r";
238 std::ifstream file(
"/proc/self/status");
242 if (Type ==
"VmSize")
244 while (std::getline(file, line))
246 if (line.compare(0, 7,
"VmSize:") == 0)
253 else if (Type ==
"VmRSS")
255 while (std::getline(file, line))
257 if (line.compare(0, 6,
"VmRSS:") == 0)
264 else if (Type ==
"MemTotal")
266 std::ifstream meminfo(
"/proc/meminfo");
267 while (std::getline(meminfo, line))
269 if (line.find(
"MemTotal:") != std::string::npos) {
287 std::istringstream iss(line);
297 std::stringstream ss;
299 std::string yamlString = ss.str();
301 std::istringstream iss(yamlString);
303 while (std::getline(iss, line)) {
315 FILE* tmpFile = tmpfile();
316 if (!tmpFile)
return;
319 int oldStdout = dup(fileno(stdout));
321 dup2(fileno(tmpFile), fileno(stdout));
327 dup2(oldStdout, fileno(stdout));
331 fseek(tmpFile, 0, SEEK_SET);
333 while (fgets(buffer,
sizeof(buffer), tmpFile)) {
334 std::string line(buffer);
335 if (!line.empty() && line.back() ==
'\n') line.pop_back();
349 MACH3LOG_ERROR(
"Where config.yaml is a valid config file, compatible with the manager class (manager/manager.cpp/h)");
360 return omp_get_max_threads();
370 if (std::getenv(
"MACH3") ==
nullptr) {
373 MACH3LOG_ERROR(
"Read more: https://github.com/mach3-software/MaCh3/wiki/0.-FAQ#error-need-mach3-environment-variable");
377 std::string MaCh3Path = std::string(std::getenv(
"MACH3")) +
"/";
379 if (FilePath.find(MaCh3Path) != 0) {
380 FilePath.insert(0, MaCh3Path);
#define MACH3LOG_CRITICAL
System and monitoring utilities for printing system information and status updates.
Custom exception class for MaCh3 errors.
size_t GetMaxTexture1DSize(const int device)
KS: Get the maximum size for 1D textures on the specified GPU device.
int GetNumGPUThreads(const int Device)
KS: Get number of GPU threads for currently used GPU.
size_t GetL2CacheSize(const int device)
KS: Get L2 cache size (in bytes) for the specified GPU device.
size_t GetSharedMemoryPerBlock(const int device)
KS: Returns the maximum shared memory per block for a given GPU device.
Common CUDA utilities and definitions for shared GPU functionality.
int GetNThreads()
number of threads which we need for example for TRandom3
void AddPath(std::string &FilePath)
Prepends the MACH3 environment path to FilePath if it is not already present.
void GetOSInfo()
KS: Find out more about operational system.
std::string TerminalToString(std::string cmd)
KS: Convoluted code to grab output from terminal to string.
void PrintProgressBar(const Long64_t Done, const Long64_t All)
KS: Simply print progress bar.
std::string GetMaCh3Version()
KS: Get version of MaCh3.
void Print(const TTree *tree)
void GetDiskUsage()
KS: Find out about Disk usage.
void NThreadsSanity()
KS: Check if user is not using huge number of threads and throw error.
void GetCPUInfo()
KS: Check what CPU you are using.
void GetGPUInfo()
KS: Check what GPU you are using.
int getValue(const std::string &Type)
CW: Get info like RAM.
void PrintConfig(const YAML::Node &node)
KS: Print Yaml config using logger.
void MaCh3Usage(int argc, char **argv)
KS: Almost all MaCh3 executables have the same usage, prepare simple printer.
void MaCh3Welcome()
KS: Prints welcome message with MaCh3 logo.
int parseLine(const std::string &line)
CW: Get memory, which is probably silly.
void EstimateDataTransferRate(TChain *chain, const Long64_t entry)
KS: Check what CPU you are using.