88#include " Display.h"
99#include " Utility.h"
1010
11+ // /Default constructor
12+ MCA::MCA (PixieInterface *pif) : _pif(pif){
13+ time (&start_time);
14+ }
15+
16+ // /Return the length of time the MCA has been running.
17+ double MCA::GetRunTime (){
18+ time (&stop_time);
19+ return difftime (stop_time, start_time);
20+ }
21+
1122/* *The MCA is initialized and run for the specified duration or until a
1223 * stop command is received. At specific intervals the MCA output is
1324 * updated via MCA::StoreData(). Will continue until external bool (stop)
@@ -20,17 +31,17 @@ void MCA::Run(float duration, bool *stop) {
2031 // Start the pixie histogram
2132 _pif->StartHistogramRun ();
2233
23- float runTime = 0 ;
34+ time (&start_time) ;
2435
2536 // Loop until we reach the run duration or a stop is received.
2637 while (true ) {
2738 if (stop != NULL && *stop){ break ; }
28- else if (duration > 0.0 && (runTime >= duration)){ break ; } // Adds support for infinite MCA runs
39+ else if (duration > 0.0 && (difftime (stop_time, start_time) >= duration)){ break ; } // Adds support for infinite MCA runs
2940
3041 sleep (2 );
42+
3143 // Update run time
32- runTime += usGetDTime () / 1.0e6 ;
33- std::cout << " |" << std::fixed << std::setprecision (2 ) << runTime << " s |\r " << std::flush;
44+ std::cout << " |" << std::fixed << std::setprecision (2 ) << GetRunTime () << " s |\r " << std::flush;
3445
3546 // Check if run is still ok
3647 if (!_pif->CheckRunStatus ()) {
@@ -44,23 +55,43 @@ void MCA::Run(float duration, bool *stop) {
4455 StoreData (mod, ch);
4556 }
4657 }
58+
4759 // Flush the data to disk.
4860 Flush ();
61+
62+ // Update the timer.
63+ time (&stop_time);
4964 }
5065
5166 // End the run
5267 _pif->EndRun ();
5368
5469 // Display run completion information.
55- runTime += usGetDTime () / 1.0e6 ;
5670 std::cout << std::endl;
5771 Display::LeaderPrint (" Run finished" );
5872 std::cout << Display::OkayStr () << std::endl;
5973 Display::LeaderPrint (" Total running time:" );
60- std::cout << std::fixed << std::setprecision (2 ) << runTime << " s" << std::endl;
74+ std::cout << std::fixed << std::setprecision (2 ) << GetRunTime () << " s" << std::endl;
6175
6276 // Uset cout flags
6377 std::cout.unsetf (std::ios_base::floatfield);
6478 std::cout.precision (6 );
79+ }
80+
81+ bool MCA::Step (){
82+ if (!_pif || !_pif->CheckRunStatus ()){ return false ; }
6583
84+ // Store the MCA data via the inherited method StoreData()
85+ for (int mod = 0 ; mod < _pif->GetNumberCards (); mod++) {
86+ for (unsigned int ch = 0 ; ch < _pif->GetNumberChannels (); ch++) {
87+ StoreData (mod, ch);
88+ }
89+ }
90+
91+ // Flush the data to disk.
92+ Flush ();
93+
94+ time (&stop_time);
95+
96+ return true ;
6697}
0 commit comments