CSPadPixCoords/src/CSPad2x2NDArrProducer.cpp

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

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7