$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef _ots_Utilities_ProgressBar_h_ 00002 #define _ots_Utilities_ProgressBar_h_ 00003 00004 #include "otsdaq-core/Macros/CoutMacros.h" 00005 #include "otsdaq-core/MessageFacility/MessageFacility.h" 00006 00007 #include <mutex> 00008 #include <string> 00009 00010 namespace ots 00011 { 00012 // ProgressBar 00013 // class by Ryan Rivera ( rrivera @ fnal.gov ), July 2013 00014 // 00015 // The are 4 public member function that should matter to the user: 00016 // 00017 // resetProgressBar(int id) ~~ 00018 // Resets progress bar to 0% complete, id does not have to be unique in your 00019 // code, read NOTE 2. 00020 // 00021 // step() ~~ 00022 // Marks that incremental progress has been made. user should place step() 00023 // freely throughout the code each time a jump in the progress bar is desired. 00024 // Thread safe. 00025 // 00026 // complete() ~~ 00027 // Indicate the progress bar is to be 100% at this point. 00028 // 00029 // read() ~~ 00030 // Returns the % complete. Thread safe. 00031 // 00032 // USE: User places resetProgressBar(id) at the start of sequence of events, as many 00033 // step()'s as desired within the sequence, and complete() at the end of the sequence 00034 // of events. The first time the code is run ever the class determines the total 00035 // number of steps, so the 00036 // progress % will be defined to be 0% with no steps complete, 50% with at least one 00037 // step complete, and 100% once complete. Each run thereafter will always use the 00038 // number of steps in the previous sequence to calculate the proper %. 00039 // 00040 // NOTE 1: Since the code uses the previous execution's number of steps to calculate the 00041 //%, avoid 00042 // placing step() calls in code that is run conditionally. It is best practice to 00043 // place them at checkpoints that must always be reached. 00044 // 00045 // NOTE 2: The class uses the filename and line # of the resetProgressBar(id) call to 00046 // store the baseline number of steps for a given sequence. So if using a single 00047 // resetProgressBar(id) call to govern more than one sequence of events, you must 00048 // assign an integer to the sequence you want to reset. Below is an example for two 00049 // sequences sharing a resetProgressBar(id): 00050 // 00051 // ProgressBar myProgressBar; 00052 // void setupProgress(int i) 00053 // { 00054 // myProgressBar.resetProgressBar(i); //this reset is shared by 00055 // sequence one and 00056 // //two so must identify with 00057 // integer 00058 // 00059 // if(i==0) sequenceOne(); 00060 // else if(i==1) sequenceTwo(); 00061 // myProgressBar.complete(); 00062 // } 00063 // 00064 // void sequenceOne() 00065 // { 00066 // //do things 00067 // myProgressBar.step(); 00068 // //do more things 00069 // myProgressBar.step(); 00070 // } 00071 // 00072 // void sequenceTwo() 00073 // { 00074 // //do other things 00075 // myProgressBar.step(); 00076 // } 00077 // 00078 00079 class ProgressBar 00080 { 00081 public: 00082 ProgressBar(); 00083 00084 //********************************************************************// 00085 // NOTE!!! don't call reset. Call resetProgressBar(id) as though 00086 // the function was this: 00087 // void resetProgressBar(int id) 00088 // 00089 // then the pre-compiler directive: 00090 #define resetProgressBar(x) reset(__FILE__, S_(__LINE__), x) 00091 // will call this reset: 00092 void reset(std::string file, std::string lineNumber, int id = 0); 00093 //********************************************************************// 00094 00095 // remaining member functions are called normal 00096 void step(); // thread safe 00097 void complete(); 00098 int read(); // if stepsToComplete==0, then define any progress as 50%, thread safe 00099 std::string readPercentageString(); // if stepsToComplete==0, then define any 00100 // progress as 50%, thread safe 00101 00102 private: 00103 const std::string cProgressBarFilePath_; 00104 const std::string cProgressBarFileExtension_; 00105 std::string totalStepsFileName_; 00106 int stepCount_; 00107 int stepsToComplete_; 00108 bool started_; 00109 std::mutex theMutex_; 00110 }; 00111 00112 } // namespace ots 00113 00114 #endif