CSPadPixCoords/src/CSPadNDArrProducer.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id$
00004 //
00005 // Description:
00006 //      Class CSPadNDArrProducer...
00007 //
00008 // Author List:
00009 //      Mikhail S. Dubrovin
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "CSPadPixCoords/CSPadNDArrProducer.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 #include <time.h>
00022 
00023 //-------------------------------
00024 // Collaborating Class Headers --
00025 //-------------------------------
00026 #include "MsgLogger/MsgLogger.h"
00027 #include "PSEvt/EventId.h"
00028 
00029 //-----------------------------------------------------------------------
00030 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00031 //-----------------------------------------------------------------------
00032 //#include <boost/lexical_cast.hpp>
00033 
00034 // This declares this class as psana module
00035 using namespace CSPadPixCoords;
00036 PSANA_MODULE_FACTORY(CSPadNDArrProducer)
00037 
00038 using namespace std;
00039 
00040 //              ----------------------------------------
00041 //              -- Public Function Member Definitions --
00042 //              ----------------------------------------
00043 
00044 namespace CSPadPixCoords {
00045 
00046 //----------------
00047 // Constructors --
00048 //----------------
00049 
00050 CSPadNDArrProducer::CSPadNDArrProducer (const std::string& name)
00051   : Module(name)
00052   , m_source()
00053   , m_inkey()
00054   , m_outkey()
00055   , m_outtype()
00056   , m_is_fullsize()  
00057   , m_is_2darray()  
00058   , m_print_bits()
00059   , m_count(0)
00060 {
00061   // get the values from configuration or use defaults
00062   m_source        = configSrc("source",       ":Cspad.0");
00063   m_inkey         = configStr("inkey",        "");
00064   m_outkey        = configStr("outkey",       "cspad_ndarr");
00065   m_outtype       = configStr("outtype",      "float");
00066   m_is_fullsize   = config   ("is_fullsize",  false);
00067   m_is_2darray    = config   ("is_2darray",   false);
00068   m_print_bits    = config   ("print_bits",   0);
00069 
00070   checkTypeImplementation();
00071   m_config = new CONFIG ( m_source );
00072 }
00073 
00074 //--------------
00075 // Destructor --
00076 //--------------
00077 
00078 CSPadNDArrProducer::~CSPadNDArrProducer ()
00079 {
00080 }
00081 
00082 //--------------------
00083 
00084 /// Print input parameters
00085 void 
00086 CSPadNDArrProducer::printInputParameters()
00087 {
00088   WithMsgLog(name(), info, log) {
00089     log << "\nInput parameters:"
00090         << "\nsource        : "     << m_source      
00091         << "\ninkey         : "     << m_inkey        
00092         << "\noutkey        : "     << m_outkey       
00093         << "\nouttype       : "     << m_outtype
00094         << "\ndtype         : "     << m_dtype
00095         << "\nis_fullsize   : "     << m_is_fullsize
00096         << "\nis_2darray    : "     << m_is_2darray
00097         << "\nprint_bits    : "     << m_print_bits
00098         << "\n";
00099   }
00100 }
00101 
00102 //--------------------
00103 
00104 /// Method which is called once at the beginning of the job
00105 void 
00106 CSPadNDArrProducer::beginJob(Event& evt, Env& env)
00107 {
00108   if( m_print_bits & 1 ) printInputParameters();
00109   if( m_print_bits & 16) printSizeOfTypes();
00110 }
00111 
00112 //--------------------
00113 
00114 /// Method which is called with event data, this is the only required 
00115 /// method, all other methods are optional
00116 void 
00117 CSPadNDArrProducer::event(Event& evt, Env& env)
00118 {
00119   ++m_count;
00120 
00121   if( ! m_config -> isSet() ) m_config -> setCSPadConfigPars(evt, env);
00122   if( m_count==1 && m_print_bits & 2 ) m_config -> printCSPadConfigPars();
00123 
00124   struct timespec start, stop;
00125   int status = clock_gettime( CLOCK_REALTIME, &start ); // Get LOCAL time
00126 
00127   procEvent(evt, env);
00128 
00129   if( m_print_bits & 4 ) {
00130     status = clock_gettime( CLOCK_REALTIME, &stop ); // Get LOCAL time
00131     cout << "  Time to produce cspad ndarray is " 
00132          << stop.tv_sec - start.tv_sec + 1e-9*(stop.tv_nsec - start.tv_nsec) 
00133          << " sec" << endl;
00134   }
00135 }
00136 
00137 //--------------------
00138 
00139 void CSPadNDArrProducer::beginRun(Event& evt, Env& env) {}
00140 void CSPadNDArrProducer::beginCalibCycle(Event& evt, Env& env) {}
00141 void CSPadNDArrProducer::endCalibCycle(Event& evt, Env& env) {}
00142 void CSPadNDArrProducer::endRun(Event& evt, Env& env) {}
00143 void CSPadNDArrProducer::endJob(Event& evt, Env& env) {}
00144   
00145 //--------------------
00146 
00147 void 
00148 CSPadNDArrProducer::procEvent(Event& evt, Env& env)
00149 {  
00150   // proc event  for one of the supported data types
00151   if ( m_dtype == FLOAT   and procEventForOutputType<float>   (evt) ) return; 
00152   if ( m_dtype == DOUBLE  and procEventForOutputType<double>  (evt) ) return; 
00153   if ( m_dtype == INT     and procEventForOutputType<int>     (evt) ) return; 
00154   if ( m_dtype == INT16   and procEventForOutputType<int16_t> (evt) ) return; 
00155 }
00156 
00157 //--------------------
00158 
00159 void 
00160 CSPadNDArrProducer::checkTypeImplementation()
00161 {  
00162   if ( m_outtype == "float"   ) { m_dtype = FLOAT;  return; }
00163   if ( m_outtype == "double"  ) { m_dtype = DOUBLE; return; } 
00164   if ( m_outtype == "int"     ) { m_dtype = INT;    return; } 
00165   if ( m_outtype == "int16"   ) { m_dtype = INT16;  return; } 
00166   if ( m_outtype == "int16_t" ) { m_dtype = INT16;  return; } 
00167 
00168   const std::string msg = "The requested data type: " + m_outtype + " is not implemented";
00169   MsgLog(name(), warning, msg );
00170   throw std::runtime_error(msg);
00171 }
00172 
00173 //--------------------
00174 
00175 } // namespace CSPadPixCoords

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7