1 #include "otsdaq/ProgressBar/ProgressBar.h"
2 #include "otsdaq/Macros/CoutMacros.h"
3 #include "otsdaq/Macros/StringMacros.h"
4 #include "otsdaq/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 __SS__ <<
"Service directory creation failed: " << path << std::endl;
41 void ProgressBar::reset(std::string file, std::string lineNumber,
int id)
43 std::lock_guard<std::mutex> lock(theMutex_);
50 sprintf(fn,
"%s_%s_%d", file.c_str(), lineNumber.c_str(),
id);
52 for(
unsigned int c = 0; c < strlen(fn); ++c)
53 if(!((fn[c] >=
'0' && fn[c] <=
'9') || (fn[c] >=
'a' && fn[c] <=
'z') ||
54 (fn[c] >=
'A' && fn[c] <=
'Z')))
56 totalStepsFileName_ = cProgressBarFilePath_ + fn + cProgressBarFileExtension_;
57 __COUTVS__(10, totalStepsFileName_);
59 FILE* fp = fopen(totalStepsFileName_.c_str(),
"r");
62 fscanf(fp,
"%d", &stepsToComplete_);
64 __COUT_TYPE__(TLVL_DEBUG + 10)
65 << __COUT_HDR__ <<
"File Found - stepsToComplete = " << stepsToComplete_
69 __COUTT__ <<
"File Not there: " << totalStepsFileName_ << __E__;
77 std::lock_guard<std::mutex> lock(theMutex_);
81 if(stepsToComplete_ && stepCount_ >= stepsToComplete_)
82 stepsToComplete_ = stepCount_ + 1;
84 __COUT_TYPE__(TLVL_DEBUG + 10) << __COUT_HDR__ << totalStepsFileName_ <<
" "
91 std::lock_guard<std::mutex> lock(theMutex_);
100 std::lock_guard<std::mutex> lock(theMutex_);
102 stepsToComplete_ = stepCount_;
107 __COUT_TYPE__(TLVL_DEBUG + 10) << __COUT_HDR__ << totalStepsFileName_ << std::endl;
109 FILE* fp = fopen(totalStepsFileName_.c_str(),
"w");
112 fprintf(fp,
"%d", stepsToComplete_);
116 __COUT_ERR__ <<
"Critical ERROR!" << std::endl;
123 std::lock_guard<std::mutex> lock(theMutex_);
129 return stepCount_ * 100.0 / stepsToComplete_;
131 return stepCount_ ? 50 : 0;
139 sprintf(pct,
"%d",
read());
std::string readPercentageString()
return percentage complete as std::string
bool isComplete()
get functions
int read()
if stepsToComplete==0, then define any progress as 50%, thread safe
void complete()
declare complete, thread safe