14 static bool MaCh3WelcomeInitialised =
false;
16 if(MaCh3WelcomeInitialised)
return;
40 MaCh3WelcomeInitialised =
true;
48 std::string MaCh3_VERSION =
"";
50 if(std::getenv(
"MaCh3_ROOT") ==
nullptr){
51 throw MaCh3Exception(__FILE__, __LINE__,
"Error: you haven't sourced setup.MaCh3.sh in core!");
54 std::string file = std::string(std::getenv(
"MaCh3_ROOT")) +
"/version.h";
56 std::ifstream versionFile(file);
59 if (!versionFile.is_open()) {
65 const std::string searchKey =
"MaCh3_VERSION=";
68 while (std::getline(versionFile, line)) {
70 auto pos = line.find(searchKey);
71 if (pos != std::string::npos) {
73 MaCh3_VERSION = line.substr(pos + searchKey.length());
74 MaCh3_VERSION.erase(0, MaCh3_VERSION.find_first_not_of(
"\""));
75 MaCh3_VERSION.erase(MaCh3_VERSION.find_last_not_of(
"\";") + 1);
124 if (std::getenv(
"OMP_NUM_THREADS") !=
nullptr)
return;
127 constexpr int MaxAllowedThreads = 16;
128 constexpr int RecommendedThreads = 8;
130 if (nThreads > MaxAllowedThreads) {
131 MACH3LOG_CRITICAL(
"You specified more than {} threads ({})", MaxAllowedThreads, nThreads);
179 std::array<char, 128> buffer;
181 std::unique_ptr<FILE,
decltype(&pclose)> pipe(popen(cmd.c_str(),
"r"), pclose);
185 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr) {
186 result += buffer.data();
189 result.erase(std::remove(result.begin(), result.end(),
'\n'), result.end());
200 Int_t bytesProcessed{ chain->GetEntry(entry) };
204 Double_t timeInSeconds = timer.RealTime();
205 Double_t dataRateMBps = (double(bytesProcessed) / (1024.0 * 1024.0)) / timeInSeconds;
207 MACH3LOG_INFO(
"Data transfer: {} B, rate: {:.2f} MB/s", bytesProcessed, dataRateMBps);
214 double progress = double(Done)/double(All);
215 const int barWidth = 20;
216 std::ostringstream progressBar;
219 int pos = int(barWidth * progress);
220 for (
int i = 0; i < barWidth; ++i) {
229 progressBar <<
"] " << std::setw(3) << Done <<
"/"<< All<<
" ("<<
static_cast<int>(progress * 100.0)<<
"%)\r";
237 std::ifstream file(
"/proc/self/status");
241 if (Type ==
"VmSize")
243 while (std::getline(file, line))
245 if (line.compare(0, 7,
"VmSize:") == 0)
252 else if (Type ==
"VmRSS")
254 while (std::getline(file, line))
256 if (line.compare(0, 6,
"VmRSS:") == 0)
263 else if (Type ==
"MemTotal")
265 std::ifstream meminfo(
"/proc/meminfo");
266 while (std::getline(meminfo, line))
268 if (line.find(
"MemTotal:") != std::string::npos) {
286 std::istringstream iss(line);
296 std::stringstream ss;
298 std::string yamlString = ss.str();
300 std::istringstream iss(yamlString);
302 while (std::getline(iss, line)) {
314 MACH3LOG_ERROR(
"Where config.yaml is a valid config file, compatible with the manager class (manager/manager.cpp/h)");
325 return omp_get_max_threads();
#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 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 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.