CSPadPixCoords/include/CSPad2x2NDArrProducer.h

Go to the documentation of this file.
00001 #ifndef CSPADPIXCOORDS_CSPAD2X2NDARRPRODUCER_H
00002 #define CSPADPIXCOORDS_CSPAD2X2NDARRPRODUCER_H
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: CSPad2x2NDArrProducer.h 8040 2014-04-19 01:00:36Z dubrovin@SLAC.STANFORD.EDU $
00007 //
00008 // Description:
00009 //      Class CSPad2x2NDArrProducer.
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------
00014 // C/C++ Headers --
00015 //-----------------
00016 
00017 //----------------------
00018 // Base Class Headers --
00019 //----------------------
00020 #include "psana/Module.h"
00021 
00022 //-------------------------------
00023 // Collaborating Class Headers --
00024 //-------------------------------
00025 #include "CSPadPixCoords/GlobalMethods.h"
00026 #include "CSPadPixCoords/CSPad2x2ConfigPars.h"
00027 
00028 //------------------------------------
00029 // Collaborating Class Declarations --
00030 //------------------------------------
00031 #include "PSEvt/Source.h"
00032 #include "psddl_psana/cspad2x2.ddl.h"
00033 
00034 
00035 //              ---------------------
00036 //              -- Class Interface --
00037 //              ---------------------
00038 
00039 using namespace std;
00040 
00041 namespace CSPadPixCoords {
00042 
00043 /// @addtogroup CSPadPixCoords
00044 
00045 /**
00046  *  @ingroup CSPadPixCoords
00047  *
00048  *  @brief CSPad2x2NDArrProducer produces the CSPad data ndarray<T,3> array for each event and add it to the event in psana framework.
00049  *
00050  *  1) get cspad configuration and data from the event,
00051  *  2) produce the CSPad data ndarray<T,3> array,
00052  *  3) save array in the event for further modules.
00053  *
00054  *  This class should not be used directly in the code of users modules. 
00055  *  Instead, it should be added as a module in the psana.cfg file with appropriate parameters.
00056  *  Then, the produced Image2D object can be extracted from event and used in other modules.
00057  *
00058  *  This software was developed for the LCLS project.  If you use all or 
00059  *  part of it, please give an appropriate acknowledgment.
00060  *
00061  *  @see PixCoords2x1, PixCoordsQuad, PixCoordsCSPad, CSPadImageGetTest
00062  *
00063  *  @version \$Id: CSPad2x2NDArrProducer.h 8040 2014-04-19 01:00:36Z dubrovin@SLAC.STANFORD.EDU $
00064  *
00065  *  @author Mikhail S. Dubrovin
00066  */
00067 
00068 class CSPad2x2NDArrProducer : public Module {
00069 public:
00070 
00071   typedef CSPadPixCoords::CSPad2x2ConfigPars CONFIG;
00072 
00073   const static uint32_t NRows2x1 = 185; 
00074   const static uint32_t NCols2x1 = 388; 
00075   const static uint32_t N2x1     = 2; 
00076 
00077   // Default constructor
00078   CSPad2x2NDArrProducer (const std::string& name) ;
00079 
00080   // Destructor
00081   virtual ~CSPad2x2NDArrProducer () ;
00082 
00083   /// Method which is called once at the beginning of the job
00084   virtual void beginJob(Event& evt, Env& env);
00085   
00086   /// Method which is called at the beginning of the run
00087   virtual void beginRun(Event& evt, Env& env);
00088   
00089   /// Method which is called at the beginning of the calibration cycle
00090   virtual void beginCalibCycle(Event& evt, Env& env);
00091   
00092   /// Method which is called with event data, this is the only required 
00093   /// method, all other methods are optional
00094   virtual void event(Event& evt, Env& env);
00095   
00096   /// Method which is called at the end of the calibration cycle
00097   virtual void endCalibCycle(Event& evt, Env& env);
00098 
00099   /// Method which is called at the end of the run
00100   virtual void endRun(Event& evt, Env& env);
00101 
00102   /// Method which is called once at the end of the job
00103   virtual void endJob(Event& evt, Env& env);
00104 
00105 
00106 protected:
00107 
00108   void printInputParameters();
00109   void procEvent(Event& evt, Env& env);
00110   void checkTypeImplementation();
00111 
00112 private:
00113 
00114   // Data members, this is for example purposes only
00115 
00116   Pds::Src    m_src;
00117   Source      m_source;         // Data source set from config file
00118   std::string m_inkey; 
00119   std::string m_outkey;
00120   std::string m_outtype;
00121   bool        m_is_2darray;
00122   unsigned    m_print_bits;
00123   long        m_count;
00124 
00125   DATA_TYPE   m_dtype;
00126   CONFIG*     m_config;
00127 
00128   // Parameters form Psana::CsPad2x2::ConfigV# object
00129   uint32_t m_roiMask;
00130   uint32_t m_numAsicsStored;
00131 
00132   // Parameters form Psana::CsPad2x2::DataV# and Psana::CsPad::ElementV# object
00133   //uint32_t m_num2x1_actual;
00134 
00135 //-------------------
00136   /**
00137    * @brief For requested m_source and m_inkey process Psana::CsPad::DataV1, or V2
00138    * Returns false if data is missing.
00139    */
00140 
00141   template <typename TELEMENT, typename TOUT>
00142   bool procCSPad2x2DataForType (Event& evt) {
00143 
00144       typedef int16_t data_cspad_t;
00145 
00146       shared_ptr<TELEMENT> elem = evt.get(m_source, m_inkey, &m_src); // get m_src here
00147       
00148       if (elem) {
00149 
00150         const ndarray<const data_cspad_t,3>& data_ndarr = elem->data();
00151  
00152         // Create and initialize the array of the same shape as data, for all 2x1...
00153         //const unsigned shape[] = {NRows2x1, NCols2x1, N2x1};
00154         //const unsigned* shape = data_ndarr.shape();
00155         //ndarray<TOUT,3> out_ndarr(shape);
00156         //std::fill(out_ndarr.begin(), out_ndarr.end(), TOUT(0));  
00157 
00158         if (m_is_2darray) {
00159 
00160             //unsigned int shape[2] = {NRows2x1, NCols2x1*N2x1};
00161             //ndarray<TOUT,2> arr2d(out_ndarr.data(), shape);
00162             ndarray<TOUT,2> out_ndarr = make_ndarray<TOUT>(NRows2x1, NCols2x1 * N2x1);
00163             typename ndarray<TOUT,2>::iterator it_out = out_ndarr.begin(); 
00164             for ( ndarray<const data_cspad_t,3>::iterator it=data_ndarr.begin(); it!=data_ndarr.end(); ++it, ++it_out) {
00165                 *it_out = (TOUT)*it;
00166             }
00167             save2DArrayInEvent<TOUT>(evt, m_src, m_outkey, out_ndarr);
00168         }
00169         else {
00170 
00171             ndarray<TOUT,3> out_ndarr = make_ndarray<TOUT>(NRows2x1, NCols2x1, N2x1);
00172             typename ndarray<TOUT,3>::iterator it_out = out_ndarr.begin(); 
00173             for ( ndarray<const data_cspad_t,3>::iterator it=data_ndarr.begin(); it!=data_ndarr.end(); ++it, ++it_out) {
00174                 *it_out = (TOUT)*it;
00175             }
00176 
00177             save3DArrInEvent<TOUT>(evt, m_src, m_outkey, out_ndarr);
00178         }
00179 
00180         return true;
00181       } // if (shp.get())
00182       return false;
00183   }
00184 
00185 //--------------------
00186   /**
00187    * @brief Process event for requested output type TOUT
00188    * Returns false if data is missing.
00189    */
00190 
00191   template <typename TOUT>
00192   bool procEventForOutputType (Event& evt) {
00193 
00194     // proc event for available type Psana::CsPad2x2::ElementV1 
00195       if ( procCSPad2x2DataForType  <Psana::CsPad2x2::ElementV1, TOUT> (evt) ) return true;
00196     //if ( procCSPad2x2DataForType  <Psana::CsPad2x2::ElementV2, TOUT> (evt) ) return true;
00197     return false;
00198   }
00199 
00200 //-------------------
00201 
00202 };
00203 
00204 } // namespace CSPadPixCoords
00205 
00206 #endif // CSPADPIXCOORDS_CSPAD2X2NDARRPRODUCER_H

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7