1 #include "otsdaq-core/ProgressBar/ProgressBar.h"
2 #include "otsdaq-core/MessageFacility/MessageFacility.h"
3 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
17 ProgressBar::ProgressBar()
18 : cProgressBarFilePath_ (std::string(getenv(
"SERVICE_DATA_PATH")) +
"/ProgressBarData/")
19 , cProgressBarFileExtension_(
".txt")
20 , totalStepsFileName_ (
"")
22 , stepsToComplete_ (0)
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: " <<
41 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)
53 (fn[c] >=
'0' && fn[c] <=
'9') ||
54 (fn[c] >=
'a' && fn[c] <=
'z') ||
55 (fn[c] >=
'A' && fn[c] <=
'Z')
58 totalStepsFileName_ = cProgressBarFilePath_ + fn + cProgressBarFileExtension_;
61 FILE *fp = fopen(totalStepsFileName_.c_str(),
"r");
64 fscanf(fp,
"%d",&stepsToComplete_);
69 std::cout << __COUT_HDR_FL__ <<
"File Not there" << std::endl;
75 void ProgressBar::step()
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()
110 return stepCount_*100.0/stepsToComplete_;
112 return stepCount_?50:0;
117 std::string ProgressBar::readPercentageString()
120 sprintf(pct,
"%d",read());