ImgAlgos/src/Tahometer.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id$
00004 //
00005 // Description:
00006 //      Class Tahometer...
00007 //
00008 // Author List:
00009 //      Mikhail S. Dubrovin
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "ImgAlgos/Tahometer.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 #define _USE_MATH_DEFINES // for M_PI
00022 #include <cmath> // for sqrt, atan2
00023 //#include <math.h> // for exp, M_PI
00024 #include <fstream> // for ofstream
00025 
00026 //-------------------------------
00027 // Collaborating Class Headers --
00028 //-------------------------------
00029 #include "MsgLogger/MsgLogger.h"
00030 #include "PSEvt/EventId.h"
00031 #include "ImgAlgos/GlobalMethods.h"
00032 //#include "PSTime/Time.h"
00033 
00034 //-----------------------------------------------------------------------
00035 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00036 //-----------------------------------------------------------------------
00037 #include <iomanip> // for setw, setfill
00038 #include <sstream> // for stringstream
00039 #include <iostream>// for setf
00040 
00041 // This declares this class as psana module
00042 using namespace std;
00043 using namespace ImgAlgos;
00044 PSANA_MODULE_FACTORY(Tahometer)
00045 
00046 //              ----------------------------------------
00047 //              -- Public Function Member Definitions --
00048 //              ----------------------------------------
00049 
00050 namespace ImgAlgos {
00051 
00052 //----------------
00053 // Constructors --
00054 //----------------
00055 Tahometer::Tahometer (const std::string& name)
00056   : Module(name)
00057   , m_print_bits()
00058   , m_dn()
00059   , m_count_dn(0)
00060   , m_count(0)
00061 {
00062   m_dn         = config   ("dn",       100);
00063   m_print_bits = config   ("print_bits", 2);
00064 }
00065 
00066 //--------------
00067 // Destructor --
00068 //--------------
00069 Tahometer::~Tahometer ()
00070 {
00071 }
00072 
00073 /// Method which is called once at the beginning of the job
00074 void 
00075 Tahometer::beginJob(Event& evt, Env& env)
00076 {
00077   m_time    = new TimeInterval();
00078   m_time_dn = new TimeInterval();
00079 }
00080 
00081 /// Method which is called at the beginning of the run
00082 void 
00083 Tahometer::beginRun(Event& evt, Env& env)
00084 {
00085   if( m_print_bits & 1 ) printInputParameters();
00086   m_str_runnum = stringRunNumber(evt);
00087 }
00088 
00089 /// Method which is called at the beginning of the calibration cycle
00090 void 
00091 Tahometer::beginCalibCycle(Event& evt, Env& env)
00092 {
00093 }
00094 
00095 /// Method which is called with event data, this is the only required 
00096 /// method, all other methods are optional
00097 void 
00098 Tahometer::event(Event& evt, Env& env)
00099 {
00100   procEvent(evt,env);
00101 }
00102   
00103 /// Method which is called at the end of the calibration cycle
00104 void 
00105 Tahometer::endCalibCycle(Event& evt, Env& env)
00106 {
00107 }
00108 
00109 /// Method which is called at the end of the run
00110 void 
00111 Tahometer::endRun(Event& evt, Env& env)
00112 {
00113 }
00114 
00115 /// Method which is called once at the end of the job
00116 void 
00117 Tahometer::endJob(Event& evt, Env& env)
00118 {
00119   double dt_sec = m_time -> getCurrentTimeInterval();
00120 
00121   if( m_print_bits & 2 ) {
00122     MsgLog(name(), info, "===== Summary for " << m_count << " processed events =====");
00123     //m_time -> stopTime(m_count);
00124     printTimeIntervalSummary(evt, dt_sec, m_count);
00125   }
00126 
00127   if( m_print_bits & 8 ) printSummaryForParser(evt, dt_sec, m_count);
00128 }
00129 
00130 //--------------------
00131 //--------------------
00132 //--------------------
00133 // Print input parameters
00134 void 
00135 Tahometer::procEvent(Event& evt, Env& env)
00136 {
00137   if(m_count < 1) {
00138     m_time    -> startTime();
00139     m_time_dn -> startTime();
00140     if( m_print_bits & 2 ) MsgLog(name(), info, "===== Start Tahometer: " << m_time -> strStartTime().c_str() << " =====");
00141   }
00142 
00143   ++ m_count;
00144 
00145   if( !(m_print_bits & 4)) return;
00146   if (++m_count_dn < m_dn) return;
00147 
00148   //m_time_dn -> stopTime(m_count_dn, false);
00149   double dt_sec = m_time_dn -> getCurrentTimeInterval();
00150   printTimeIntervalSummary(evt, dt_sec, m_count_dn);
00151 
00152   m_time_dn -> startTime();
00153   m_count_dn = 0;
00154 }
00155 
00156 //--------------------
00157 // Print input parameters
00158 void 
00159 Tahometer::printInputParameters()
00160 {
00161   WithMsgLog(name(), info, log) {
00162     log << "\n Input parameters:"
00163         << "\n dn         : " << m_dn
00164         << "\n print_bits : " << m_print_bits
00165         << "\n";     
00166   }
00167 }
00168 
00169 //--------------------
00170 void 
00171 Tahometer::printTimeIntervalSummary(Event& evt, double dt_sec, long counter)
00172 {
00173   MsgLog( name(), info,  "Run="             << m_str_runnum 
00174                      << " Evt="             << stringFromUint(m_count) 
00175                      << " Time to process " << stringFromUint(counter) 
00176                      << " events is "       << dt_sec 
00177                      << " sec, or "         << dt_sec/counter << " sec/event" 
00178                    //<< " Time="   << stringTimeStamp(evt)
00179                    //<< comment.c_str() 
00180   );
00181 }
00182 
00183 //--------------------
00184 
00185 void 
00186 Tahometer::printSummaryForParser(Event& evt, double dt_sec, long counter)
00187 {
00188   cout << "Tahometer: Summary for parser" << endl;
00189   cout << "BATCH_PROCESSING_TIME  " << dt_sec  << endl;
00190   cout << "BATCH_NUMBER_OF_EVENTS " << counter << endl;
00191   if (counter>0)
00192     cout << "BATCH_SEC_PER_EVENT    " << dt_sec/counter << endl;
00193   if (dt_sec>0)
00194     cout << "BATCH_EVENTS_PER_SEC   " << counter/dt_sec << endl;
00195 }
00196 
00197 //--------------------
00198 //--------------------
00199 //--------------------
00200 
00201 } // namespace ImgAlgos
00202 
00203 //---------EOF--------

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7