CSPadPixCoords/include/CSPad2x2NDArrReshape.h

Go to the documentation of this file.
00001 #ifndef CSPADPIXCOORDS_CSPAD2X2NDARRRESHAPE_H
00002 #define CSPADPIXCOORDS_CSPAD2X2NDARRRESHAPE_H
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: CSPad2x2NDArrReshape.h 9169 2014-10-28 00:37:53Z dubrovin@SLAC.STANFORD.EDU $
00007 //
00008 // Description:
00009 //      Class CSPad2x2NDArrReshape.
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 CSPad2x2NDArrReshape 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: CSPad2x2NDArrReshape.h 9169 2014-10-28 00:37:53Z dubrovin@SLAC.STANFORD.EDU $
00064  *
00065  *  @author Mikhail S. Dubrovin
00066  */
00067 
00068 
00069 //struct KeysInOutStatus {
00070 //  std::string key_in;
00071 //  std::string key_out;
00072 //  bool is_found;
00073 //};
00074 
00075 
00076 class CSPad2x2NDArrReshape : public Module {
00077 public:
00078 
00079   //  typedef CSPadPixCoords::CSPad2x2ConfigPars CONFIG;
00080 
00081   const static uint32_t NRows2x1 = 185; 
00082   const static uint32_t NCols2x1 = 388; 
00083   const static uint32_t N2x1     = 2; 
00084 
00085   // Default constructor
00086   CSPad2x2NDArrReshape (const std::string& name) ;
00087 
00088   // Destructor
00089   virtual ~CSPad2x2NDArrReshape () ;
00090 
00091   /// Method which is called once at the beginning of the job
00092   virtual void beginJob(Event& evt, Env& env);
00093   
00094   /// Method which is called at the beginning of the run
00095   virtual void beginRun(Event& evt, Env& env);
00096   
00097   /// Method which is called at the beginning of the calibration cycle
00098   virtual void beginCalibCycle(Event& evt, Env& env);
00099   
00100   /// Method which is called with event data, this is the only required 
00101   /// method, all other methods are optional
00102   virtual void event(Event& evt, Env& env);
00103   
00104   /// Method which is called at the end of the calibration cycle
00105   virtual void endCalibCycle(Event& evt, Env& env);
00106 
00107   /// Method which is called at the end of the run
00108   virtual void endRun(Event& evt, Env& env);
00109 
00110   /// Method which is called once at the end of the job
00111   virtual void endJob(Event& evt, Env& env);
00112 
00113 
00114 protected:
00115 
00116   void printInputParameters();
00117   bool procEvent(Event& evt);
00118   bool procCalib(Env& env);
00119   void put_keys_in_vectors();
00120   void print_in_out_keys();
00121 
00122 private:
00123 
00124   Pds::Src    m_src;
00125   Source      m_source;
00126   std::string m_keys_in; 
00127   std::string m_keys_out;
00128   unsigned    m_print_bits;
00129   unsigned    m_count_evt;
00130   unsigned    m_count_clb;
00131   unsigned    m_count_msg;
00132 
00133   std::vector<std::string>     v_keys_in;
00134   std::vector<std::string>     v_keys_out;
00135 
00136 //-------------------
00137   /**
00138    * @brief Re-shape and save ndarray for CSPAD2x2 
00139    * Returns false if data is missing.
00140    */
00141   template <typename T>
00142   ndarray<T,3> reshape(const T* data_in) {
00143 
00144       //const ndarray<const T,3>& data_ndarr = *shp_const.get();
00145       ndarray<T,3> out_ndarr = make_ndarray<T>(N2x1, NRows2x1, NCols2x1);
00146 
00147       for(size_t r=0; r<NRows2x1; ++r) {
00148       for(size_t c=0; c<NCols2x1; ++c) {
00149       for(size_t n=0; n<N2x1; ++n) out_ndarr[n][r][c] = *data_in++;
00150       }
00151       }
00152 
00153       return out_ndarr;
00154   }
00155 
00156 
00157 //-------------------
00158   /**
00159    * @brief Process event for requested in/output type and re-shapes CSPAD2x2 from [185,388,2] to [2,185,388]
00160    * Returns false if data is missing.
00161    */
00162 
00163   template <typename T>
00164   bool procEventForType (Event& evt, size_t i) {
00165 
00166       // for CONST
00167       shared_ptr< ndarray<const T,3> > shp_const = evt.get(m_source, v_keys_in[i], &m_src); // get m_src here      
00168       if (shp_const) { save3DArrInEvent<T>(evt, m_src, v_keys_out[i], reshape<T>(shp_const->data())); return true; }
00169 
00170 
00171       // for NON-CONST
00172       shared_ptr< ndarray<T,3> > shp = evt.get(m_source, v_keys_in[i], &m_src); // get m_src here      
00173       if (shp) { save3DArrInEvent<T>(evt, m_src, v_keys_out[i], reshape<T>(shp->data())); return true; }
00174 
00175       return false;
00176   }
00177 
00178 
00179 //-------------------
00180   /**
00181    * @brief Process event for requested in/output type and re-shapes CSPAD2x2 from [185,388,2] to [2,185,388]
00182    * Returns false if data is missing.
00183    */
00184 
00185   template <typename T>
00186   bool procCalibForType (Env& env, size_t i) {
00187 
00188       // for CONST
00189       shared_ptr< ndarray<const T,3> > shp_const = env.calibStore().get(m_source, &m_src, v_keys_in[i]); // get m_src here      
00190       if (shp_const) { save3DArrayInEnv<T>(env, m_src, v_keys_out[i], reshape<T>(shp_const->data())); return true; }
00191 
00192 
00193       // for NON-CONST
00194       shared_ptr< ndarray<T,3> > shp = env.calibStore().get(m_source, &m_src, v_keys_in[i]); // get m_src here      
00195       if (shp) { save3DArrayInEnv<T>(env, m_src, v_keys_out[i], reshape<T>(shp->data())); return true; }
00196 
00197       return false;
00198   }
00199 
00200 
00201 //-------------------
00202 
00203 };
00204 
00205 } // namespace CSPadPixCoords
00206 
00207 #endif // CSPADPIXCOORDS_CSPAD2X2NDARRRESHAPE_H

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7