BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnSimpleProgressBar.h
Go to the documentation of this file.
1
/*
2
BM@N alignment routine
3
BM@N experiment at NICA complex, JINR, 2025
4
5
Department: Math & Soft Group of HEP lab
6
Author: Igor Polev, polev@jinr.ru
7
8
BmnSimpleProgressBar class header-only implementation
9
Primitive progress bar with some thread-safety
10
*/
11
12
#ifndef BMNSIMPLEPROGRESSBAR_H
13
#define BMNSIMPLEPROGRESSBAR_H
14
15
#include <iostream>
16
#include <mutex>
17
#include <string>
18
19
class
BmnSimpleProgressBar
20
{
21
private
:
22
bool
show
{
false
};
23
int
done
{0};
24
std::string
bar
{
"\r [ ] "
};
// with 50 spaces
25
std::mutex
mtx
;
26
27
inline
void
Print
() { std::cout <<
bar
<<
done
<<
"%\r"
<< std::flush; }
28
29
public
:
30
inline
BmnSimpleProgressBar
() =
default
;
31
inline
void
Init
();
32
inline
void
Tick
();
33
inline
void
Clear
();
34
};
35
36
inline
void
BmnSimpleProgressBar::Clear
()
37
{
38
show
=
false
;
39
std::cout <<
"\r \r"
<< std::flush;
40
}
41
42
inline
void
BmnSimpleProgressBar::Init
()
43
{
44
done
= 0;
45
for
(
int
i
= 3;
i
< 53;
i
++)
46
bar
[
i
] =
' '
;
47
Clear
();
48
Print
();
49
show
=
true
;
50
}
51
52
inline
void
BmnSimpleProgressBar::Tick
()
53
{
54
if
(!
show
)
55
return
;
56
57
std::lock_guard<std::mutex> lock{
mtx
};
58
if
(
done
>= 100) {
59
show
=
false
;
60
return
;
61
}
62
if
(
done
% 2)
63
bar
[
done
/ 2 + 3] =
'='
;
64
else
65
bar
[
done
/ 2 + 3] =
'-'
;
66
Print
();
67
done
++;
68
}
69
70
#endif
// BMNSIMPLEPROGRESSBAR_H
i
int i
Definition
P4_F32vec4.h:22
BmnSimpleProgressBar::Print
void Print()
Definition
BmnSimpleProgressBar.h:27
BmnSimpleProgressBar::Tick
void Tick()
Definition
BmnSimpleProgressBar.h:52
BmnSimpleProgressBar::Init
void Init()
Definition
BmnSimpleProgressBar.h:42
BmnSimpleProgressBar::mtx
std::mutex mtx
Definition
BmnSimpleProgressBar.h:25
BmnSimpleProgressBar::BmnSimpleProgressBar
BmnSimpleProgressBar()=default
BmnSimpleProgressBar::show
bool show
Definition
BmnSimpleProgressBar.h:22
BmnSimpleProgressBar::done
int done
Definition
BmnSimpleProgressBar.h:23
BmnSimpleProgressBar::bar
std::string bar
Definition
BmnSimpleProgressBar.h:24
BmnSimpleProgressBar::Clear
void Clear()
Definition
BmnSimpleProgressBar.h:36
align_new
src
BmnSimpleProgressBar.h
Generated on
for BmnRoot by
1.17.0