Belle II Software  release-08-01-10
Belle2::Utils Namespace Reference

General utility functions. More...

Classes

struct  VisitOverload
 Helper struct for the C++17 std::visit overload pattern to allow simple use of variants. More...
 
class  Timer
 Small helper class that prints its lifetime when destroyed. More...
 

Functions

template<class... Ts>
 VisitOverload (Ts...) -> VisitOverload< Ts... >
 Function for the C++17 std::visit overload pattern to allow simple use of variants.
 
template<class T >
reduceTBranch (TBranch *branch, const std::function< T(T, T)> &f, T reduced=T())
 Reduce a branch of a TTree. More...
 
double getClock ()
 Return current value of the real-time clock. More...
 
double getCPUClock ()
 Return current value of the per-thread CPU clock. More...
 
unsigned long getVirtualMemoryKB ()
 Returns currently used virtual memory in KB, includes swapped and not occupied memory pages and memory-mapped files.
 
unsigned long getRssMemoryKB ()
 Returns the amount of memory the process actually occupies in the physical RAM of the machine.
 
std::string getCommandOutput (const std::string &command, const std::vector< std::string > &arguments={}, bool searchPath=true)
 Execute a shell command and return its output.
 

Detailed Description

General utility functions.

Function Documentation

◆ getClock()

double getClock ( )

Return current value of the real-time clock.

The returned value is meant to measure relative times and does not show absolute time values.

Note
See getCPUClock() for a higher-resolution clock unaffected by wait times.
Returns
Clock value in default time unit (ns)

Definition at line 66 of file Utils.cc.

67  {
68  timespec ts;
69  clock_gettime(CLOCK_REALTIME, &ts);
70  return (ts.tv_sec * Unit::s) + (ts.tv_nsec * Unit::ns);
71  }

◆ getCPUClock()

double getCPUClock ( )

Return current value of the per-thread CPU clock.

Returns
CPU clock value in default time unit (ns)

Definition at line 72 of file Utils.cc.

◆ reduceTBranch()

T Belle2::Utils::reduceTBranch ( TBranch *  branch,
const std::function< T(T, T)> &  f,
reduced = T() 
)

Reduce a branch of a TTree.

Returns
reduced branch

Definition at line 35 of file Utils.h.

36  {
37  T object;
38  branch->SetAddress(&object);
39  int nevents = branch->GetEntries();
40  for (int i = 0; i < nevents; ++i) {
41  branch->GetEvent(i);
42  reduced = f(reduced, object);
43  }
44  return reduced;
45  }