psddl_hdf2psana/src/cspad2x2.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: cspad2x2.cpp 7035 2013-10-31 19:57:40Z salnikov@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class cspad2x2...
00007 //
00008 // Author List:
00009 //      Andy Salnikov
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "psddl_hdf2psana/cspad2x2.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 
00022 //-------------------------------
00023 // Collaborating Class Headers --
00024 //-------------------------------
00025 #include "hdf5pp/ArrayType.h"
00026 #include "hdf5pp/CompoundType.h"
00027 #include "hdf5pp/Utils.h"
00028 
00029 //-----------------------------------------------------------------------
00030 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00031 //-----------------------------------------------------------------------
00032 
00033 //              ----------------------------------------
00034 //              -- Public Function Member Definitions --
00035 //              ----------------------------------------
00036 
00037 namespace psddl_hdf2psana {
00038 namespace CsPad2x2 {
00039 
00040 hdf5pp::Type
00041 ns_ElementV1_v0_dataset_element_stored_type()
00042 {
00043   typedef ns_ElementV1_v0::dataset_element DsType;
00044   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00045   type.insert("virtual_channel", offsetof(DsType, virtual_channel), hdf5pp::TypeTraits<uint32_t>::stored_type());
00046   type.insert("lane", offsetof(DsType, lane), hdf5pp::TypeTraits<uint32_t>::stored_type());
00047   type.insert("tid", offsetof(DsType, tid), hdf5pp::TypeTraits<uint32_t>::stored_type());
00048   type.insert("acq_count", offsetof(DsType, acq_count), hdf5pp::TypeTraits<uint32_t>::stored_type());
00049   type.insert("op_code", offsetof(DsType, op_code), hdf5pp::TypeTraits<uint32_t>::stored_type());
00050   type.insert("quad", offsetof(DsType, quad), hdf5pp::TypeTraits<uint32_t>::stored_type());
00051   type.insert("seq_count", offsetof(DsType, seq_count), hdf5pp::TypeTraits<uint32_t>::stored_type());
00052   type.insert("ticks", offsetof(DsType, ticks), hdf5pp::TypeTraits<uint32_t>::stored_type());
00053   type.insert("fiducials", offsetof(DsType, fiducials), hdf5pp::TypeTraits<uint32_t>::stored_type());
00054   type.insert("frame_type", offsetof(DsType, frame_type), hdf5pp::TypeTraits<uint32_t>::stored_type());
00055   hsize_t _array_type_sb_temp_shape[] = { 4 };
00056   hdf5pp::ArrayType _array_type_sb_temp = hdf5pp::ArrayType::arrayType(hdf5pp::TypeTraits<uint16_t>::stored_type(), 1, _array_type_sb_temp_shape);
00057   type.insert("sb_temp", offsetof(DsType, sb_temp), _array_type_sb_temp);
00058   return type;
00059 }
00060 
00061 hdf5pp::Type
00062 ns_ElementV1_v0::dataset_element::stored_type()
00063 {
00064   static hdf5pp::Type type = ns_ElementV1_v0_dataset_element_stored_type();
00065   return type;
00066 }
00067 
00068 hdf5pp::Type
00069 ns_ElementV1_v0_dataset_element_native_type()
00070 {
00071   typedef ns_ElementV1_v0::dataset_element DsType;
00072   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00073   type.insert("virtual_channel", offsetof(DsType, virtual_channel), hdf5pp::TypeTraits<uint32_t>::native_type());
00074   type.insert("lane", offsetof(DsType, lane), hdf5pp::TypeTraits<uint32_t>::native_type());
00075   type.insert("tid", offsetof(DsType, tid), hdf5pp::TypeTraits<uint32_t>::native_type());
00076   type.insert("acq_count", offsetof(DsType, acq_count), hdf5pp::TypeTraits<uint32_t>::native_type());
00077   type.insert("op_code", offsetof(DsType, op_code), hdf5pp::TypeTraits<uint32_t>::native_type());
00078   type.insert("quad", offsetof(DsType, quad), hdf5pp::TypeTraits<uint32_t>::native_type());
00079   type.insert("seq_count", offsetof(DsType, seq_count), hdf5pp::TypeTraits<uint32_t>::native_type());
00080   type.insert("ticks", offsetof(DsType, ticks), hdf5pp::TypeTraits<uint32_t>::native_type());
00081   type.insert("fiducials", offsetof(DsType, fiducials), hdf5pp::TypeTraits<uint32_t>::native_type());
00082   type.insert("frame_type", offsetof(DsType, frame_type), hdf5pp::TypeTraits<uint32_t>::native_type());
00083   hsize_t _array_type_sb_temp_shape[] = { 4 };
00084   hdf5pp::ArrayType _array_type_sb_temp = hdf5pp::ArrayType::arrayType(hdf5pp::TypeTraits<uint16_t>::native_type(), 1, _array_type_sb_temp_shape);
00085   type.insert("sb_temp", offsetof(DsType, sb_temp), _array_type_sb_temp);
00086   return type;
00087 }
00088 
00089 hdf5pp::Type
00090 ns_ElementV1_v0::dataset_element::native_type()
00091 {
00092   static hdf5pp::Type type = ns_ElementV1_v0_dataset_element_native_type();
00093   return type;
00094 }
00095 
00096 ns_ElementV1_v0::dataset_element::dataset_element()
00097 {
00098 }
00099 
00100 ns_ElementV1_v0::dataset_element::dataset_element(const Psana::CsPad2x2::ElementV1& psanaobj)
00101   : virtual_channel(psanaobj.virtual_channel())
00102   , lane(psanaobj.lane())
00103   , tid(psanaobj.tid())
00104   , acq_count(psanaobj.acq_count())
00105   , op_code(psanaobj.op_code())
00106   , quad(psanaobj.quad())
00107   , seq_count(psanaobj.seq_count())
00108   , ticks(psanaobj.ticks())
00109   , fiducials(psanaobj.fiducials())
00110   , frame_type(psanaobj.frame_type())
00111 {
00112   ndarray<const uint16_t, 1> sb_temp = psanaobj.sb_temp();
00113   std::copy(sb_temp.begin(), sb_temp.end(), this->sb_temp);
00114 }
00115 
00116 uint32_t
00117 ElementV1_v0::virtual_channel() const {
00118   if (not m_ds_element) read_ds_element();
00119   return uint32_t(m_ds_element->virtual_channel);
00120 }
00121 
00122 uint32_t
00123 ElementV1_v0::lane() const {
00124   if (not m_ds_element) read_ds_element();
00125   return uint32_t(m_ds_element->lane);
00126 }
00127 
00128 uint32_t
00129 ElementV1_v0::tid() const {
00130   if (not m_ds_element) read_ds_element();
00131   return uint32_t(m_ds_element->tid);
00132 }
00133 
00134 uint32_t
00135 ElementV1_v0::acq_count() const {
00136   if (not m_ds_element) read_ds_element();
00137   return uint32_t(m_ds_element->acq_count);
00138 }
00139 
00140 uint32_t
00141 ElementV1_v0::op_code() const {
00142   if (not m_ds_element) read_ds_element();
00143   return uint32_t(m_ds_element->op_code);
00144 }
00145 
00146 uint32_t
00147 ElementV1_v0::quad() const {
00148   if (not m_ds_element) read_ds_element();
00149   return uint32_t(m_ds_element->quad);
00150 }
00151 
00152 uint32_t
00153 ElementV1_v0::seq_count() const {
00154   if (not m_ds_element) read_ds_element();
00155   return uint32_t(m_ds_element->seq_count);
00156 }
00157 
00158 uint32_t
00159 ElementV1_v0::ticks() const {
00160   if (not m_ds_element) read_ds_element();
00161   return uint32_t(m_ds_element->ticks);
00162 }
00163 
00164 uint32_t
00165 ElementV1_v0::fiducials() const {
00166   if (not m_ds_element) read_ds_element();
00167   return uint32_t(m_ds_element->fiducials);
00168 }
00169 
00170 ndarray<const uint16_t, 1>
00171 ElementV1_v0::sb_temp() const {
00172   if (not m_ds_element) read_ds_element();
00173   boost::shared_ptr<uint16_t> ptr(m_ds_element, m_ds_element->sb_temp);
00174   return make_ndarray(ptr, Nsbtemp);
00175 }
00176 
00177 uint32_t
00178 ElementV1_v0::frame_type() const {
00179   if (not m_ds_element) read_ds_element();
00180   return uint32_t(m_ds_element->frame_type);
00181 }
00182 
00183 ndarray<const int16_t, 3>
00184 ElementV1_v0::data() const {
00185   if (m_ds_data.empty()) read_ds_data();
00186   return m_ds_data;
00187 }
00188 
00189 float
00190 ElementV1_v0::common_mode(uint32_t section) const{
00191   if (m_ds_cm.empty()) read_ds_cm();
00192   return m_ds_cm[section];
00193 }
00194 
00195 void
00196 ElementV1_v0::read_ds_element() const {
00197   m_ds_element = hdf5pp::Utils::readGroup<CsPad2x2::ns_ElementV1_v0::dataset_element>(m_group, "element", m_idx);
00198 }
00199 
00200 void
00201 ElementV1_v0::read_ds_data() const {
00202   m_ds_data = hdf5pp::Utils::readNdarray<int16_t, 3>(m_group, "data", m_idx);
00203 }
00204 
00205 void
00206 ElementV1_v0::read_ds_cm() const {
00207   if (m_group.hasChild("common_mode")) {
00208     m_ds_cm = hdf5pp::Utils::readNdarray<float, 1>(m_group, "common_mode", m_idx);
00209   } else {
00210     // if dataset is missing make all-zeros array
00211     m_ds_cm = make_ndarray<float>(2);
00212     std::fill(m_ds_cm.begin(), m_ds_cm.end(), 0.f);
00213   }
00214 }
00215 
00216 void make_datasets_ElementV1_v0(const Psana::CsPad2x2::ElementV1& obj,
00217       hdf5pp::Group group, const ChunkPolicy& chunkPolicy, int deflate, bool shuffle)
00218 {
00219   {
00220     hdf5pp::Type dstype = hdf5pp::TypeTraits<ns_ElementV1_v0::dataset_element>::stored_type();
00221     hdf5pp::Utils::createDataset(group, "element", dstype, chunkPolicy.chunkSize(dstype), chunkPolicy.chunkCacheSize(dstype), deflate, shuffle);
00222   }
00223   {
00224     hsize_t dims[3] = {Psana::CsPad2x2::ColumnsPerASIC, Psana::CsPad2x2::MaxRowsPerASIC*2, 2};
00225     hdf5pp::Type dstype = hdf5pp::ArrayType::arrayType(hdf5pp::TypeTraits<int16_t>::stored_type(), 3, dims);
00226     hdf5pp::Utils::createDataset(group, "data", dstype, chunkPolicy.chunkSize(dstype), chunkPolicy.chunkCacheSize(dstype), deflate, shuffle);
00227   }
00228   {
00229     hdf5pp::Type dstype = hdf5pp::ArrayType::arrayType(hdf5pp::TypeTraits<float>::stored_type(), 2);
00230     hdf5pp::Utils::createDataset(group, "common_mode", dstype, chunkPolicy.chunkSize(dstype), chunkPolicy.chunkCacheSize(dstype), deflate, shuffle);
00231   }
00232 }
00233 
00234 void store_ElementV1_v0(const Psana::CsPad2x2::ElementV1* obj, hdf5pp::Group group, long index, bool append)
00235 {
00236   if (not obj) {
00237     if (append) {
00238       hdf5pp::Utils::resizeDataset(group, "element", index < 0 ? index : index + 1);
00239       hdf5pp::Utils::resizeDataset(group, "data", index < 0 ? index : index + 1);
00240       hdf5pp::Utils::resizeDataset(group, "common_mode", index < 0 ? index : index + 1);
00241     }
00242     return;
00243   }
00244 
00245   {
00246     ns_ElementV1_v0::dataset_element data(*obj);
00247     if (append) {
00248       hdf5pp::Utils::storeAt(group, "element", data, index);
00249     } else {
00250       hdf5pp::Utils::storeScalar(group, "element", data);
00251     }
00252   }
00253   {
00254     if (append) {
00255       hdf5pp::Utils::storeNDArrayAt(group, "data", obj->data(), index);
00256     } else {
00257       hdf5pp::Utils::storeNDArray(group, "data", obj->data());
00258     }
00259   }
00260   {
00261     ndarray<float, 1> data = make_ndarray<float>(2);
00262     data[0] = obj->common_mode(0);
00263     data[1] = obj->common_mode(1);
00264     if (append) {
00265       hdf5pp::Utils::storeNDArrayAt(group, "common_mode", data, index);
00266     } else {
00267       hdf5pp::Utils::storeNDArray(group, "common_mode", data);
00268     }
00269   }
00270 }
00271 
00272 } // namespace CsPad2x2
00273 } // namespace psddl_hdf2psana

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7