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);
147 cudaGetDeviceCount(&nDevices);
149 MACH3LOG_CRITICAL(
"MaCh3 compiled with CUDA support (for GPU acceleration) but could not find GPU");
150 MACH3LOG_CRITICAL(
"Either allocate GPU for your job or recompile MaCh3 without GPU support");
188 std::array<char, 128> buffer;
191 struct PCloseDeleter {
192 void operator()(FILE* f)
const {
196 std::unique_ptr<FILE, PCloseDeleter> pipe(popen(cmd.c_str(),
"r"));
201 while (fgets(buffer.data(), buffer.size(), pipe.get()) !=
nullptr) {
202 result += buffer.data();
205 result.erase(std::remove(result.begin(), result.end(),
'\n'), result.end());
216 Int_t bytesProcessed{ chain->GetEntry(entry) };
220 Double_t timeInSeconds = timer.RealTime();
221 Double_t dataRateMBps = (double(bytesProcessed) / (1024.0 * 1024.0)) / timeInSeconds;
223 MACH3LOG_INFO(
"Data transfer: {} B, rate: {:.2f} MB/s", bytesProcessed, dataRateMBps);
230 double progress = double(Done)/double(All);
231 const int barWidth = 20;
232 std::ostringstream progressBar;
235 int pos = int(barWidth * progress);
236 for (
int i = 0; i < barWidth; ++i) {
245 progressBar <<
"] " << std::setw(3) << Done <<
"/"<< All<<
" ("<<
static_cast<int>(progress * 100.0)<<
"%)\r";
253 std::ifstream file(
"/proc/self/status");
257 if (Type ==
"VmSize")
259 while (std::getline(file, line))
261 if (line.compare(0, 7,
"VmSize:") == 0)
268 else if (Type ==
"VmRSS")
270 while (std::getline(file, line))
272 if (line.compare(0, 6,
"VmRSS:") == 0)
279 else if (Type ==
"MemTotal")
281 std::ifstream meminfo(
"/proc/meminfo");
282 while (std::getline(meminfo, line))
284 if (line.find(
"MemTotal:") != std::string::npos) {
302 std::istringstream iss(line);
312 std::stringstream ss;
314 std::string yamlString = ss.str();
316 std::istringstream iss(yamlString);
318 while (std::getline(iss, line)) {
330 FILE* tmpFile = tmpfile();
331 if (!tmpFile)
return;
334 int oldStdout = dup(fileno(stdout));
336 dup2(fileno(tmpFile), fileno(stdout));
342 dup2(oldStdout, fileno(stdout));
346 fseek(tmpFile, 0, SEEK_SET);
348 while (fgets(buffer,
sizeof(buffer), tmpFile)) {
349 std::string line(buffer);
350 if (!line.empty() && line.back() ==
'\n') line.pop_back();
364 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://github.com/mach3-software/MaCh3/wiki/0.-FAQ#error-need-mach3-environment-variable");
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.
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.
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.