16 static bool MaCh3WelcomeInitialised =
false;
18 if(MaCh3WelcomeInitialised)
return;
42 MaCh3WelcomeInitialised =
true;
50 std::string MaCh3_VERSION =
"";
52 if(std::getenv(
"MaCh3_ROOT") ==
nullptr){
53 throw MaCh3Exception(__FILE__, __LINE__,
"Error: you haven't sourced setup.MaCh3.sh in core!");
56 std::string file = std::string(std::getenv(
"MaCh3_ROOT")) +
"/version.h";
58 std::ifstream versionFile(file);
61 if (!versionFile.is_open()) {
67 const std::string searchKey =
"MaCh3_VERSION=";
70 while (std::getline(versionFile, line)) {
72 auto pos = line.find(searchKey);
73 if (pos != std::string::npos) {
75 MaCh3_VERSION = line.substr(pos + searchKey.length());
76 MaCh3_VERSION.erase(0, MaCh3_VERSION.find_first_not_of(
"\""));
77 MaCh3_VERSION.erase(MaCh3_VERSION.find_last_not_of(
"\";") + 1);
126 if (std::getenv(
"OMP_NUM_THREADS") !=
nullptr)
return;
129 constexpr
int MaxAllowedThreads = 16;
130 constexpr
int RecommendedThreads = 8;
132 if (nThreads > MaxAllowedThreads) {
133 MACH3LOG_CRITICAL(
"You specified more than {} threads ({})", MaxAllowedThreads, nThreads);
148 cudaGetDeviceCount(&nDevices);
150 MACH3LOG_CRITICAL(
"MaCh3 compiled with CUDA support (for GPU acceleration) but could not find GPU");
151 MACH3LOG_CRITICAL(
"Either allocate GPU for your job or recompile MaCh3 without GPU support");
189 std::array<char, 128> buffer;
192 struct PCloseDeleter {
193 void operator()(FILE* f)
const {
197 std::unique_ptr<FILE, PCloseDeleter> pipe(popen(cmd.c_str(),
"r"));
202 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr) {
203 result += buffer.data();
206 result.erase(std::remove(result.begin(), result.end(),
'\n'), result.end());
217 Int_t bytesProcessed{ chain->GetEntry(entry) };
221 Double_t timeInSeconds = timer.RealTime();
222 Double_t dataRateMBps = (double(bytesProcessed) / (1024.0 * 1024.0)) / timeInSeconds;
224 MACH3LOG_INFO(
"Data transfer: {} B, rate: {:.2f} MB/s", bytesProcessed, dataRateMBps);
231 double progress = double(Done)/double(All);
232 const int barWidth = 20;
233 std::ostringstream progressBar;
236 int pos = int(barWidth * progress);
237 for (
int i = 0; i < barWidth; ++i) {
246 progressBar <<
"] " << std::setw(3) << Done <<
"/"<< All<<
" ("<<
static_cast<int>(progress * 100.0)<<
"%)\r";
254 std::ifstream file(
"/proc/self/status");
258 if (Type ==
"VmSize")
260 while (std::getline(file, line))
262 if (line.compare(0, 7,
"VmSize:") == 0)
269 else if (Type ==
"VmRSS")
271 while (std::getline(file, line))
273 if (line.compare(0, 6,
"VmRSS:") == 0)
280 else if (Type ==
"MemTotal")
282 std::ifstream meminfo(
"/proc/meminfo");
283 while (std::getline(meminfo, line))
285 if (line.find(
"MemTotal:") != std::string::npos) {
303 std::istringstream iss(line);
313 std::stringstream ss;
315 std::string yamlString = ss.str();
317 std::istringstream iss(yamlString);
319 while (std::getline(iss, line)) {
331 FILE* tmpFile = tmpfile();
332 if (!tmpFile)
return;
335 int oldStdout = dup(fileno(stdout));
337 dup2(fileno(tmpFile), fileno(stdout));
343 dup2(oldStdout, fileno(stdout));
347 fseek(tmpFile, 0, SEEK_SET);
349 while (fgets(buffer,
sizeof(buffer), tmpFile)) {
350 std::string line(buffer);
351 if (!line.empty() && line.back() ==
'\n') line.pop_back();
365 MACH3LOG_ERROR(
"Where config.yaml is a valid config file, compatible with the manager class (manager/manager.cpp/h)");
375 return omp_get_max_threads();
385 if (std::getenv(
"MACH3") ==
nullptr) {
388 MACH3LOG_ERROR(
"Read more: https://mach3-software.github.io/MaCh3/FAQ.html");
392 std::string MaCh3Path = std::string(std::getenv(
"MACH3")) +
"/";
394 if (FilePath.find(MaCh3Path) != 0) {
395 FilePath.insert(0, MaCh3Path);
#define MACH3LOG_CRITICAL
System and monitoring utilities for printing system information and status updates.
Custom exception class used throughout MaCh3.
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.
void GetGPUInfo()
KS: Check what GPU you are using.
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 EstimateDataTransferRate(TChain *chain, const Long64_t entry)
KS: Check what CPU you are using.
int parseLine(const std::string &line)
CW: Get memory, which is probably silly.
void PrintConfig(const YAML::Node &node)
KS: Print Yaml config using logger.
int getValue(const std::string &Type)
CW: Get info like RAM.
void PrintProgressBar(const Long64_t Done, const Long64_t All)
KS: Simply print progress bar.
void MaCh3Welcome()
KS: Prints welcome message with MaCh3 logo.
void Print(const TTree *tree)
void MaCh3Usage(int argc, char **argv)
KS: Almost all MaCh3 executables have the same usage, prepare simple printer.
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 GetCPUInfo()
KS: Check what CPU you are using.
std::string GetMaCh3Version()
KS: Get version of MaCh3.
Main namespace for MaCh3 software.
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.