BioDynaMo  v1.03.58-27764645
io.cc
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #include <fstream>
16 #include <iostream>
17 
18 #include "core/util/io.h"
19 #include "core/util/log.h"
20 
21 namespace bdm {
22 
23 RuntimeVariables::RuntimeVariables() { gSystem->GetSysInfo(&sysinfo_); }
24 
25 RuntimeVariables::RuntimeVariables(TRootIOCtor* io_ctor) {}
26 
27 SysInfo_t RuntimeVariables::GetSystemInfo() const { return sysinfo_; }
28 
29 void RuntimeVariables::SetSystemInfo(const SysInfo_t& other) {
30  sysinfo_ = other;
31 }
32 
34  // clang-format off
35  Log::Info("RuntimeVariables", "OS:\t", sysinfo_.fOS, "\n",
36  "Model:\t", sysinfo_.fModel, "\n",
37  "Arch:\t", sysinfo_.fCpuType, "\n",
38  "#CPUs:\t", sysinfo_.fCpus, "\n",
39  "RAM:\t", sysinfo_.fPhysRam, "MB", "\n");
40  // clang-format on
41 }
42 
44  if (sysinfo_.fOS != other.GetSystemInfo().fOS) {
45  return false;
46  }
47  if (sysinfo_.fModel != other.GetSystemInfo().fModel) {
48  return false;
49  }
50  if (sysinfo_.fCpuType != other.GetSystemInfo().fCpuType) {
51  return false;
52  }
53  if (sysinfo_.fCpus != other.GetSystemInfo().fCpus) {
54  return false;
55  }
56  if (sysinfo_.fPhysRam != other.GetSystemInfo().fPhysRam) {
57  return false;
58  }
59  return true;
60 }
61 
63  return !(*this == other);
64 }
65 
66 TFileRaii::TFileRaii(const std::string& filename, const char* mode)
67  : file_(new TFile(filename.c_str(), mode)) {}
68 
69 TFileRaii::TFileRaii(TFile* file) : file_(file) {}
70 
72  file_->Close();
73  delete file_;
74 }
75 
76 TFile* TFileRaii::Get() { return file_; }
77 
78 bool FileExists(const std::string& file_name) {
79  std::ifstream infile(file_name);
80  return infile.good();
81 }
82 
83 void WriteToFile(const std::string& filename, const std::string& content) {
84  std::ofstream ofs(filename);
85  ofs << content;
86  ofs.close();
87 }
88 
89 } // namespace bdm
bdm::RuntimeVariables::PrintSystemInfo
void PrintSystemInfo()
Definition: io.cc:33
bdm::RuntimeVariables
Definition: io.h:29
bdm::TFileRaii::Get
TFile * Get()
Definition: io.cc:76
bdm
Definition: agent.cc:39
bdm::TFileRaii::file_
TFile * file_
Definition: io.h:58
bdm::RuntimeVariables::operator==
bool operator==(const RuntimeVariables &other) const
Definition: io.cc:43
bdm::RuntimeVariables::RuntimeVariables
RuntimeVariables()
Definition: io.cc:23
bdm::RuntimeVariables::operator!=
bool operator!=(const RuntimeVariables &other) const
Definition: io.cc:62
bdm::TFileRaii::~TFileRaii
~TFileRaii()
Definition: io.cc:71
bdm::RuntimeVariables::SetSystemInfo
void SetSystemInfo(const SysInfo_t &other)
Definition: io.cc:29
bdm::RuntimeVariables::sysinfo_
SysInfo_t sysinfo_
Definition: io.h:45
bdm::Log::Info
static void Info(const std::string &location, const Args &... parts)
Prints information message.
Definition: log.h:55
bdm::WriteToFile
void WriteToFile(const std::string &filename, const std::string &content)
Definition: io.cc:83
bdm::FileExists
bool FileExists(const std::string &file_name)
Definition: io.cc:78
log.h
io.h
bdm::TFileRaii::TFileRaii
TFileRaii(const std::string &filename, const char *mode)
Definition: io.cc:66
bdm::RuntimeVariables::GetSystemInfo
SysInfo_t GetSystemInfo() const
Definition: io.cc:27