Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
ana::Progress Class Reference

A simple ascii-art progress bar. More...

#include "/cvmfs/nova.opensciencegrid.org/externals/cafanacore/v01.11/src/CAFAna/Core/Progress.h"

Inheritance diagram for ana::Progress:
ana::ThreadPool::ThreadsafeProgress

Public Member Functions

 Progress (const std::string &title)
 Create and draw the progress bar. More...
 
 ~Progress ()
 
void SetProgress (double frac)
 Update the progress fraction between zero and one. More...
 
void Done ()
 Call this when action is completed. More...
 

Protected Member Functions

std::string FormatTime (double sec) const
 

Protected Attributes

bool fDone
 Has Done been called? More...
 
int fIFrac
 What character are we on? Prevents unnecessary redraws. More...
 
time_t fStart
 
time_t fPrevCall
 
bool fLive
 Is this bar live (drawable?) More...
 

Static Protected Attributes

static bool fAnyLive = false
 Are any bars live? More...
 

Detailed Description

A simple ascii-art progress bar.

Definition at line 9 of file Progress.h.

Constructor & Destructor Documentation

ana::Progress::Progress ( const std::string title)

Create and draw the progress bar.

Definition at line 18 of file Progress.cxx.

References om::cout, allTimeWatchdog::endl, fAnyLive, fLive, and SetProgress().

19  : fDone(false), fIFrac(-1), fStart(time(0)), fPrevCall(time(0)), fLive(false)
20  {
21  // If no else is drawing, we can
22  if(!fAnyLive){
23  fLive = true;
24  fAnyLive = true;
25  }
26 
27  if(!fLive) return;
28 
29  std::cout << title << "..." << std::endl;
30  SetProgress(0); // Draw the initial bar
31  }
::xsd::cxx::tree::time< char, simple_type > time
Definition: Database.h:194
bool fDone
Has Done been called?
Definition: Progress.h:22
time_t fStart
Definition: Progress.h:25
static bool fAnyLive
Are any bars live?
Definition: Progress.h:30
int fIFrac
What character are we on? Prevents unnecessary redraws.
Definition: Progress.h:23
time_t fPrevCall
Definition: Progress.h:26
OStream cout
Definition: OStream.cxx:6
void SetProgress(double frac)
Update the progress fraction between zero and one.
Definition: Progress.cxx:41
bool fLive
Is this bar live (drawable?)
Definition: Progress.h:29
ana::Progress::~Progress ( )

Definition at line 34 of file Progress.cxx.

References Done().

35  {
36  // Finish up in case the user forgot to call Done()
37  Done();
38  }
void Done()
Call this when action is completed.
Definition: Progress.cxx:90

Member Function Documentation

void ana::Progress::Done ( )

Call this when action is completed.

Definition at line 90 of file Progress.cxx.

References fDone, fLive, and SetProgress().

Referenced by ana::FCSurface::Add(), ana::covmx::CovarianceMatrix::BuildFullCovMx(), ana::CovMxSurface::CovMxSurface(), DrawCCOscillations(), DrawSurface(), ana::FrequentistSurface::FillSurface(), ana::CovMxManager::GetCovarianceMatrix(), ana::SpectrumLoader::Go(), ana::FileReducer::Go(), ana::NuWROSyst::InitializeHistograms(), MakeCovMx(), MakeFakeData(), MakePlots(), MakeSystsPDF(), nue_data_mc_validation(), nue_fd_mc_validation(), numu_data_mc_validation(), ana::Profile(), reach_2018_dCPfractions(), tree_maker_simple(), trimmubarid(), trimvar(), useBDTG(), and ~Progress().

91  {
92  if(!fLive) return;
93 
94  if(fDone) return; // Can easily be called multiple times
95 
96  SetProgress(1); // Make sure the bar shows 100%
97 
98  fDone = true;
99  }
bool fDone
Has Done been called?
Definition: Progress.h:22
void SetProgress(double frac)
Update the progress fraction between zero and one.
Definition: Progress.cxx:41
bool fLive
Is this bar live (drawable?)
Definition: Progress.h:29
std::string ana::Progress::FormatTime ( double  sec) const
protected

Definition at line 102 of file Progress.cxx.

References genie::utils::style::Format(), runNovaSAM::ret, and string.

Referenced by SetProgress().

103  {
104  // Yes, I'm sure there's a standard way to do this, but this was easy, and
105  // lets me print exactly what I want.
107  if(sec >= 60*60-.5){
108  ret += TString::Format("%dh", (int(sec+.5)/(60*60))).Data();
109  }
110  if(sec >= 60-.5){
111  ret += TString::Format("%dm", (int(sec+.5)/60)%60).Data();
112  }
113  if(sec < 60*60){ // don't clutter if still measured in hours
114  ret += TString::Format("%ds", (int(sec+.5)%60)).Data();
115  }
116  return ret;
117  }
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
enum BeamMode string
void ana::Progress::SetProgress ( double  frac)

Update the progress fraction between zero and one.

Definition at line 41 of file Progress.cxx.

References om::cout, allTimeWatchdog::endl, fAnyLive, fDone, fIFrac, fileno, fLive, FormatTime(), fPrevCall, fStart, MECModelEnuComparisons::i, make_template_knob_config::stdout, submit_syst::str, and string.

Referenced by ana::FCSurface::Add(), ana::covmx::CovarianceMatrix::BuildFullCovMx(), ana::CovMxSurface::CovMxSurface(), Done(), DrawCCOscillations(), DrawSurface(), FCTutorial2020(), fill_col(), ana::SurfaceKrige::FillSurface(), ana::FrequentistSurface::FillSurface(), ana::CovMxManager::GetCovarianceMatrix(), ana::SpectrumLoaderBase::GetNextFile(), ana::SpectrumLoader::Go(), ana::FileReducer::Go(), ana::SpectrumLoader::HandleFile(), ana::NuWROSyst::InitializeHistograms(), MakeCovMx(), MakeFakeData(), makeMatrixElementSurface(), MakePlots(), MakeSystsPDF(), nue_data_mc_validation(), nue_fd_mc_validation(), numu_data_mc_validation(), ProducingSA(), ana::Profile(), Progress(), reach_2018_dCPfractions(), ana::ThreadPool::ThreadsafeProgress::SetProgress(), tree_maker_simple(), trimmubarid(), trimvar(), and useBDTG().

42  {
43  if(!fLive || fDone) return;
44 
45  const time_t t_now = time(0);
46  const int ifrac = (kBarWidth-1)*frac;
47 
48  // Don't repaint unnecessarily
49  if(ifrac == fIFrac && t_now - fPrevCall < 2) return;
50 
51  fIFrac = ifrac;
52  fPrevCall = t_now;
53 
54  // Check if we're outputting to a file. If so don't bother showing off
55  // with the progress bar, it won't work.
56  struct stat buf;
57  fstat(fileno(stdout), &buf);
58  const bool isFile = (buf.st_mode & S_IFREG) || (buf.st_mode & S_IFIFO);
59  if(isFile) return;
60 
61  std::string str(kBarWidth, ' ');
62  for(int i = 0; i < ifrac; ++i) str[i] = '=';
63  str[ifrac] = '>';
64  str[0] = '[';
65  str[kBarWidth-1] = ']';
66 
67  if(frac > 0){
68  const int elapse = t_now - fStart;
69  if(elapse > 2){ // Don't show for very short steps
70  if(frac < 1)
71  str += " "+FormatTime(elapse*(1-frac)/frac);
72  else
73  str += " "+FormatTime(elapse);
74  str += " "; // Enough to cover up any previous version
75  }
76  }
77 
78  std::cout << "\r" << str << std::flush;
79 
80  if(frac == 1){
81  fDone = true;
83 
84  // If we were the ones drawing, we're not anymore
85  if(fLive) fLive = fAnyLive = false;
86  }
87  }
::xsd::cxx::tree::time< char, simple_type > time
Definition: Database.h:194
bool fDone
Has Done been called?
Definition: Progress.h:22
time_t fStart
Definition: Progress.h:25
static bool fAnyLive
Are any bars live?
Definition: Progress.h:30
double frac(double x)
Fractional part.
int fIFrac
What character are we on? Prevents unnecessary redraws.
Definition: Progress.h:23
time_t fPrevCall
Definition: Progress.h:26
OStream cout
Definition: OStream.cxx:6
unsigned int fileno
Definition: runWimpSim.h:102
bool fLive
Is this bar live (drawable?)
Definition: Progress.h:29
std::string FormatTime(double sec) const
Definition: Progress.cxx:102
enum BeamMode string

Member Data Documentation

bool ana::Progress::fAnyLive = false
staticprotected

Are any bars live?

Definition at line 30 of file Progress.h.

Referenced by Progress(), and SetProgress().

bool ana::Progress::fDone
protected

Has Done been called?

Definition at line 22 of file Progress.h.

Referenced by Done(), and SetProgress().

int ana::Progress::fIFrac
protected

What character are we on? Prevents unnecessary redraws.

Definition at line 23 of file Progress.h.

Referenced by SetProgress().

bool ana::Progress::fLive
protected

Is this bar live (drawable?)

Definition at line 29 of file Progress.h.

Referenced by Done(), Progress(), and SetProgress().

time_t ana::Progress::fPrevCall
protected

Definition at line 26 of file Progress.h.

Referenced by SetProgress().

time_t ana::Progress::fStart
protected

Definition at line 25 of file Progress.h.

Referenced by SetProgress().


The documentation for this class was generated from the following files: