psddl_pds2psana/src/TimepixDataV1ToV2.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: TimepixDataV1ToV2.cpp 6820 2013-09-24 21:02:05Z salnikov@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class TimepixDataV1ToV2...
00007 //
00008 // Author List:
00009 //      Andy Salnikov
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "psddl_pds2psana/TimepixDataV1ToV2.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 
00022 //-------------------------------
00023 // Collaborating Class Headers --
00024 //-------------------------------
00025 
00026 //-----------------------------------------------------------------------
00027 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00028 //-----------------------------------------------------------------------
00029 
00030 //              ----------------------------------------
00031 //              -- Public Function Member Definitions --
00032 //              ----------------------------------------
00033 
00034 namespace psddl_pds2psana {
00035 
00036 //----------------
00037 // Constructors --
00038 //----------------
00039 TimepixDataV1ToV2::TimepixDataV1ToV2(const boost::shared_ptr<const XtcType>& xtcPtr)
00040   : Psana::Timepix::DataV2()
00041   , m_xtcObj(xtcPtr)
00042   , m_data(0)
00043 {
00044 }
00045 
00046 //--------------
00047 // Destructor --
00048 //--------------
00049 TimepixDataV1ToV2::~TimepixDataV1ToV2 ()
00050 {
00051   delete [] m_data;
00052 }
00053 
00054 uint16_t
00055 TimepixDataV1ToV2::width() const
00056 {
00057   return m_xtcObj->width();
00058 }
00059 
00060 uint16_t
00061 TimepixDataV1ToV2::height() const {
00062   return m_xtcObj->height();
00063 }
00064 
00065 uint32_t
00066 TimepixDataV1ToV2::timestamp() const
00067 {
00068   return m_xtcObj->timestamp();
00069 }
00070 
00071 uint16_t
00072 TimepixDataV1ToV2::frameCounter() const
00073 {
00074   return m_xtcObj->frameCounter();
00075 }
00076 
00077 uint16_t
00078 TimepixDataV1ToV2::lostRows() const
00079 {
00080   return m_xtcObj->lostRows();
00081 }
00082 
00083 ndarray<const uint16_t, 2>
00084 TimepixDataV1ToV2::data() const
00085 {
00086   uint16_t width = m_xtcObj->width();
00087   uint16_t height = m_xtcObj->height();
00088 
00089   if (not m_data) {
00090 
00091     // get DataV1 data
00092     ndarray<const uint16_t, 2> data1 = m_xtcObj->data();
00093 
00094     // allocate enough space
00095     m_data = new uint16_t[data1.size()];
00096 
00097     // this is stolen from pdsdata/timepix/src/DataV2.cc
00098     // convert data
00099     unsigned destX, destY;
00100     const uint16_t *src = data1.data();
00101 
00102     for (unsigned iy=0; iy < height * 2u; iy++) {
00103       for (unsigned ix=0; ix < width / 2u; ix++) {
00104         // map pixels from 256x1024 to 512x512
00105         switch (iy / 256) {
00106           case 0:
00107             destX = iy;
00108             destY = 511 - ix;
00109             break;
00110           case 1:
00111             destX = iy - 256;
00112             destY = 255 - ix;
00113             break;
00114           case 2:
00115             destX = 1023 - iy;
00116             destY = ix;
00117             break;
00118           case 3:
00119             destX = 1023 + 256 - iy;
00120             destY = ix + 256;
00121             break;
00122           default:
00123             // error
00124             destX = destY = 0;
00125             break;
00126         }
00127         m_data[(destY * width) + destX] = src[(iy * width / 2) + ix];
00128       }
00129     }
00130 
00131   }
00132 
00133   return make_ndarray(m_data, height, width);
00134 }
00135 
00136 uint32_t
00137 TimepixDataV1ToV2::depth() const
00138 {
00139   return m_xtcObj->depth();
00140 }
00141 
00142 uint32_t
00143 TimepixDataV1ToV2::depth_bytes() const
00144 {
00145   return m_xtcObj->depth_bytes();
00146 }
00147 
00148 uint32_t
00149 TimepixDataV1ToV2::data_size() const
00150 {
00151   return m_xtcObj->data_size();
00152 }
00153 
00154 } // namespace psddl_pds2psana

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7