ImgAlgos/src/CameraImageProducer.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id$
00004 //
00005 // Description:
00006 //      Class CameraImageProducer...
00007 //
00008 // Author List:
00009 //      Mikhail S. Dubrovin
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "ImgAlgos/CameraImageProducer.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 //#include <iomanip> // for setw, setfill
00022 //#include <sstream> // for stringstream
00023 //#include <iostream>// for setf
00024 
00025 //-------------------------------
00026 // Collaborating Class Headers --
00027 //-------------------------------
00028 
00029 //-----------------------------------------------------------------------
00030 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00031 //-----------------------------------------------------------------------
00032 
00033 // This declares this class as psana module
00034 using namespace ImgAlgos;
00035 PSANA_MODULE_FACTORY(CameraImageProducer)
00036 
00037 //              ----------------------------------------
00038 //              -- Public Function Member Definitions --
00039 //              ----------------------------------------
00040 
00041 namespace {
00042   
00043   void
00044   printFrameCoord(std::ostream& str, const Psana::Camera::FrameCoord& coord) 
00045   {
00046     str << "(" << coord.column() << ", " << coord.row() << ")";
00047   }
00048   
00049 }
00050 
00051 //--------------------
00052 
00053 namespace ImgAlgos {
00054 
00055 //----------------
00056 // Constructors --
00057 //----------------
00058 CameraImageProducer::CameraImageProducer (const std::string& name)
00059   : Module(name)
00060   , m_str_src()
00061   , m_key_in()
00062   , m_key_out() 
00063   , m_outtype()
00064   , m_subtract_offset()
00065   , m_print_bits()
00066   , m_count(0)
00067   , m_count_msg(0)
00068 {
00069   // get the values from configuration or use defaults
00070   m_str_src           = configSrc("source", "DetInfo(:Camera)");
00071   m_key_in            = configStr("key_in",                 "");
00072   m_key_out           = configStr("key_out",           "image");
00073   m_outtype           = configStr("outtype",          "asdata");
00074   m_subtract_offset   = config   ("subtract_offset",      true);
00075   m_print_bits        = config   ("print_bits",             0 );
00076 
00077   m_detector = detectorTypeForSource(m_str_src);
00078 
00079   checkTypeImplementation();
00080   
00081 }
00082 
00083 //--------------------
00084 
00085 void 
00086 CameraImageProducer::printInputParameters()
00087 {
00088   WithMsgLog(name(), info, log) {
00089     log << "\n Input parameters :"
00090         << "\n source           : " << m_str_src
00091         << "\n key_in           : " << m_key_in      
00092         << "\n key_out          : " << m_key_out
00093         << "\n outtype          : " << m_outtype
00094         << "\n subtract_offset  : " << m_subtract_offset     
00095         << "\n print_bits       : " << m_print_bits
00096         << "\n\n Derived enum parameters:"
00097         << "\n dtype            : " << m_dtype    
00098         << "\n detector         : " << m_detector    
00099         << "\n";     
00100   }
00101 }
00102 
00103 //--------------------
00104 
00105 //--------------
00106 // Destructor --
00107 //--------------
00108 CameraImageProducer::~CameraImageProducer ()
00109 {
00110 }
00111 
00112 /// Method which is called once at the beginning of the job
00113 void 
00114 CameraImageProducer::beginJob(Event& evt, Env& env)
00115 {
00116   if( m_print_bits & 1 ) printInputParameters();
00117 }
00118 
00119 /// Method which is called at the beginning of the run
00120 void CameraImageProducer::beginRun(Event& evt, Env& env) {}
00121 
00122 /// Method which is called at the beginning of the calibration cycle
00123 void 
00124 CameraImageProducer::beginCalibCycle(Event& evt, Env& env) 
00125 {
00126   if( m_print_bits & 16 ) {
00127 
00128       MsgLog(name(), info, "in beginCalibCycle()");
00129       
00130       shared_ptr<Psana::Camera::FrameFexConfigV1> config1 = env.configStore().get(m_src);
00131       if (config1) {
00132         WithMsgLog(name(), info, str) {
00133           str << "Camera::FrameFexConfigV1:";
00134           str << "\n  forwarding = " << config1->forwarding();
00135           str << "\n  forward_prescale = " << config1->forward_prescale();
00136           str << "\n  processing = " << config1->processing();
00137           str << "\n  roiBegin = ";
00138           ::printFrameCoord(str, config1->roiBegin());
00139           str << "\n  roiEnd = ";
00140           ::printFrameCoord(str, config1->roiEnd());
00141           str << "\n  threshold = " << config1->threshold();
00142           str << "\n  number_of_masked_pixels = " << config1->number_of_masked_pixels();
00143           const ndarray<const Psana::Camera::FrameCoord, 1>& masked_pixels = config1->masked_pixel_coordinates();
00144           for (unsigned i = 0; i < masked_pixels.shape()[0]; ++ i) {
00145             str << "\n    ";
00146             ::printFrameCoord(str, masked_pixels[i]);
00147           }
00148         }     
00149       
00150       } else {
00151         MsgLog(name(), info, "Camera::FrameFexConfigV1 not found");    
00152       }
00153 
00154   }
00155 }
00156 
00157 /// Method which is called with event data, this is the only required 
00158 /// method, all other methods are optional
00159 void 
00160 CameraImageProducer::event(Event& evt, Env& env)
00161 {
00162   ++ m_count;
00163   if( m_print_bits & 2 ) printEventRecord(evt);
00164   procEvent(evt,env);
00165 }
00166   
00167 /// Method which is called at the end of the calibration cycle
00168 void CameraImageProducer::endCalibCycle(Event& evt, Env& env) {}
00169 
00170 /// Method which is called at the end of the run
00171 void CameraImageProducer::endRun(Event& evt, Env& env) {}
00172 
00173 /// Method which is called once at the end of the job
00174 void CameraImageProducer::endJob(Event& evt, Env& env)
00175 {
00176   if( m_print_bits & 4 ) printSummary(evt);
00177 }
00178 
00179 //--------------------
00180 //--------------------
00181 
00182 void 
00183 CameraImageProducer::procEvent(Event& evt, Env& env)
00184 {
00185   // proc event  for one of the supported data types
00186   if ( m_dtype == ASDATA  and procEventForOutputType<data_t>  (evt) ) return; 
00187   if ( m_dtype == FLOAT   and procEventForOutputType<float>   (evt) ) return; 
00188   if ( m_dtype == DOUBLE  and procEventForOutputType<double>  (evt) ) return; 
00189   if ( m_dtype == INT     and procEventForOutputType<int>     (evt) ) return; 
00190   if ( m_dtype == INT16   and procEventForOutputType<int16_t> (evt) ) return; 
00191 }
00192 
00193 //--------------------
00194 
00195 void 
00196 CameraImageProducer::printEventRecord(Event& evt, std::string comment)
00197 {
00198   MsgLog( name(), info,  "Run="    << stringRunNumber(evt) 
00199                      << " Evt="    << stringFromUint(m_count) 
00200                      << " Time="   << stringTimeStamp(evt) 
00201                      << comment.c_str() 
00202   );
00203 }
00204 
00205 //--------------------
00206 
00207 void 
00208 CameraImageProducer::printSummary(Event& evt, std::string comment)
00209 {
00210   MsgLog( name(), info, "Run=" << stringRunNumber(evt) 
00211                         << "Number of processed events=" << stringFromUint(m_count)
00212                         << comment.c_str() );
00213 }
00214 
00215 //--------------------
00216 
00217 void 
00218 CameraImageProducer::checkTypeImplementation()
00219 {  
00220   if ( m_outtype == "asdata" ) { m_dtype = ASDATA; return; }
00221   if ( m_outtype == "float"  ) { m_dtype = FLOAT;  return; }
00222   if ( m_outtype == "double" ) { m_dtype = DOUBLE; return; } 
00223   if ( m_outtype == "int"    ) { m_dtype = INT;    return; } 
00224   if ( m_outtype == "int16"  ) { m_dtype = INT16;  return; } 
00225 
00226   const std::string msg = "The requested data type: " + m_outtype + " is not implemented";
00227   MsgLog(name(), warning, msg );
00228   throw std::runtime_error(msg);
00229 }
00230 
00231 //--------------------
00232 } // namespace ImgAlgos
00233 //--------------------

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7