1 #include "otsdaq-core/ProgressBar/ProgressBar.h"
2 #include "otsdaq-core/Macros/CoutMacros.h"
3 #include "otsdaq-core/Macros/StringMacros.h"
4 #include "otsdaq-core/MessageFacility/MessageFacility.h"
17 ProgressBar::ProgressBar()
18 : cProgressBarFilePath_(std::string(__ENV__(
"SERVICE_DATA_PATH")) +
20 , cProgressBarFileExtension_(
".txt")
21 , totalStepsFileName_(
"")
26 std::string path = cProgressBarFilePath_;
27 DIR* dir = opendir(path.c_str());
30 else if(-1 == mkdir(path.c_str(), 0755))
33 std::cout << __COUT_HDR_FL__ <<
"Service directory creation failed: " << path
42 void ProgressBar::reset(std::string file, std::string lineNumber,
int id)
49 sprintf(fn,
"%s_%s_%d", file.c_str(), lineNumber.c_str(), id);
51 for(
unsigned int c = 0; c < strlen(fn); ++c)
52 if(!((fn[c] >=
'0' && fn[c] <=
'9') || (fn[c] >=
'a' && fn[c] <=
'z') ||
53 (fn[c] >=
'A' && fn[c] <=
'Z')))
55 totalStepsFileName_ = cProgressBarFilePath_ + fn + cProgressBarFileExtension_;
58 FILE* fp = fopen(totalStepsFileName_.c_str(),
"r");
61 fscanf(fp,
"%d", &stepsToComplete_);
67 std::cout << __COUT_HDR_FL__ <<
"File Not there" << std::endl;
73 void ProgressBar::step()
75 std::lock_guard<std::mutex> lock(theMutex_);
82 void ProgressBar::complete()
85 stepsToComplete_ = stepCount_;
92 FILE* fp = fopen(totalStepsFileName_.c_str(),
"w");
95 fprintf(fp,
"%d", stepsToComplete_);
99 std::cout << __COUT_HDR_FL__ <<
"Critical ERROR!" << std::endl;
104 int ProgressBar::read()
109 std::lock_guard<std::mutex> lock(theMutex_);
111 return stepCount_ * 100.0 / stepsToComplete_;
113 return stepCount_ ? 50 : 0;
118 std::string ProgressBar::readPercentageString()
121 sprintf(pct,
"%d", read());