1 #include "otsdaq-core/ProgressBar/ProgressBar.h"
2 #include "otsdaq-core/Macros/CoutMacros.h"
3 #include "otsdaq-core/MessageFacility/MessageFacility.h"
16 ProgressBar::ProgressBar()
17 : cProgressBarFilePath_(std::string(getenv(
"SERVICE_DATA_PATH")) +
19 , cProgressBarFileExtension_(
".txt")
20 , totalStepsFileName_(
"")
25 std::string path = cProgressBarFilePath_;
26 DIR* dir = opendir(path.c_str());
29 else if(-1 == mkdir(path.c_str(), 0755))
32 std::cout << __COUT_HDR_FL__ <<
"Service directory creation failed: " << path
41 void ProgressBar::reset(std::string file, std::string lineNumber,
int id)
48 sprintf(fn,
"%s_%s_%d", file.c_str(), lineNumber.c_str(), id);
50 for(
unsigned int c = 0; c < strlen(fn); ++c)
51 if(!((fn[c] >=
'0' && fn[c] <=
'9') || (fn[c] >=
'a' && fn[c] <=
'z') ||
52 (fn[c] >=
'A' && fn[c] <=
'Z')))
54 totalStepsFileName_ = cProgressBarFilePath_ + fn + cProgressBarFileExtension_;
57 FILE* fp = fopen(totalStepsFileName_.c_str(),
"r");
60 fscanf(fp,
"%d", &stepsToComplete_);
66 std::cout << __COUT_HDR_FL__ <<
"File Not there" << std::endl;
72 void ProgressBar::step()
74 std::lock_guard<std::mutex> lock(theMutex_);
81 void ProgressBar::complete()
84 stepsToComplete_ = stepCount_;
91 FILE* fp = fopen(totalStepsFileName_.c_str(),
"w");
94 fprintf(fp,
"%d", stepsToComplete_);
98 std::cout << __COUT_HDR_FL__ <<
"Critical ERROR!" << std::endl;
103 int ProgressBar::read()
108 std::lock_guard<std::mutex> lock(theMutex_);
110 return stepCount_ * 100.0 / stepsToComplete_;
112 return stepCount_ ? 50 : 0;
117 std::string ProgressBar::readPercentageString()
120 sprintf(pct,
"%d", read());