psddl_hdf2psana/src/evr.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: evr.cpp 9664 2015-02-23 19:00:04Z davidsch@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Hand-written supporting types for DDL-HDF5 mapping.
00007 //
00008 //------------------------------------------------------------------------
00009 
00010 //-----------------------
00011 // This Class's Header --
00012 //-----------------------
00013 #include "psddl_hdf2psana/evr.h"
00014 
00015 //-----------------
00016 // C/C++ Headers --
00017 //-----------------
00018 #include <boost/make_shared.hpp>
00019 
00020 //-------------------------------
00021 // Collaborating Class Headers --
00022 //-------------------------------
00023 #include "hdf5pp/CompoundType.h"
00024 #include "hdf5pp/EnumType.h"
00025 #include "hdf5pp/Utils.h"
00026 #include "hdf5pp/VlenType.h"
00027 
00028 //-----------------------------------------------------------------------
00029 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00030 //-----------------------------------------------------------------------
00031 
00032 //              ----------------------------------------
00033 //              -- Public Function Member Definitions --
00034 //              ----------------------------------------
00035 
00036 namespace {
00037   const int EvrDataPresentTableSize = 256;
00038 } // local namespace
00039 
00040 namespace psddl_hdf2psana {
00041 namespace EvrData {
00042 
00043 
00044 hdf5pp::Type ns_DataV3_v0_dataset_data_stored_type()
00045 {
00046   typedef ns_DataV3_v0::dataset_data DsType;
00047   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00048   hdf5pp::VlenType _array_type_fifoEvents = hdf5pp::VlenType::vlenType(hdf5pp::TypeTraits<EvrData::ns_FIFOEvent_v0::dataset_data>::stored_type());
00049   type.insert("fifoEvents", offsetof(DsType, vlen_fifoEvents), _array_type_fifoEvents);
00050   return type;
00051 }
00052 
00053 hdf5pp::Type ns_DataV3_v0::dataset_data::stored_type()
00054 {
00055   static hdf5pp::Type type = ns_DataV3_v0_dataset_data_stored_type();
00056   return type;
00057 }
00058 
00059 hdf5pp::Type ns_DataV3_v0_dataset_data_native_type()
00060 {
00061   typedef ns_DataV3_v0::dataset_data DsType;
00062   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00063   hdf5pp::VlenType _array_type_fifoEvents = hdf5pp::VlenType::vlenType(hdf5pp::TypeTraits<EvrData::ns_FIFOEvent_v0::dataset_data>::native_type());
00064   type.insert("fifoEvents", offsetof(DsType, vlen_fifoEvents), _array_type_fifoEvents);
00065   return type;
00066 }
00067 
00068 hdf5pp::Type ns_DataV3_v0::dataset_data::native_type()
00069 {
00070   static hdf5pp::Type type = ns_DataV3_v0_dataset_data_native_type();
00071   return type;
00072 }
00073 
00074 ns_DataV3_v0::dataset_data::dataset_data()
00075 {
00076   this->vlen_fifoEvents = 0;
00077   this->fifoEvents = 0;
00078 }
00079 
00080 ns_DataV3_v0::dataset_data::dataset_data(const Psana::EvrData::DataV3& psanaobj)
00081 {
00082   ndarray<const Psana::EvrData::FIFOEvent, 1> fifos = psanaobj.fifoEvents();
00083   vlen_fifoEvents = fifos.shape()[0];
00084   fifoEvents = (ns_FIFOEvent_v0::dataset_data*)malloc(sizeof(ns_FIFOEvent_v0::dataset_data)*vlen_fifoEvents);
00085   for(unsigned i = 0; i != vlen_fifoEvents; ++ i) {
00086     new (fifoEvents+i) ns_FIFOEvent_v0::dataset_data(fifos[i]);
00087   }
00088 }
00089 
00090 ns_DataV3_v0::dataset_data::~dataset_data()
00091 {
00092   free(this->fifoEvents);
00093 }
00094 
00095 ndarray<const Psana::EvrData::FIFOEvent, 1> DataV3_v0::fifoEvents() const {
00096   if (not m_ds_data) read_ds_data();
00097   if (m_ds_storage_data_fifoEvents.empty()) {
00098     unsigned shape[] = {m_ds_data->vlen_fifoEvents};
00099     ndarray<Psana::EvrData::FIFOEvent, 1> tmparr(shape);
00100     std::copy(m_ds_data->fifoEvents, m_ds_data->fifoEvents+m_ds_data->vlen_fifoEvents, tmparr.begin());
00101     m_ds_storage_data_fifoEvents = tmparr;
00102   }
00103   return m_ds_storage_data_fifoEvents;
00104 }
00105 
00106 void DataV3_v0::read_ds_data() const {
00107   // dataset name for EvrDataV3 has changed at some point from "evrData" to "data",
00108   // we need to try both here
00109   std::string dsname = "data";
00110   if (not m_group.hasChild(dsname)) dsname = "evrData";
00111   m_ds_data = hdf5pp::Utils::readGroup<EvrData::ns_DataV3_v0::dataset_data>(m_group, dsname, m_idx);
00112 }
00113 
00114 
00115 uint32_t DataV3_v0::numFifoEvents() const
00116 {
00117   if (not m_ds_data) read_ds_data();
00118   return m_ds_data->vlen_fifoEvents;
00119 }
00120 
00121 void make_datasets_DataV3_v0(const Psana::EvrData::DataV3& obj,
00122       hdf5pp::Group group, const ChunkPolicy& chunkPolicy, int deflate, bool shuffle)
00123 {
00124   {
00125     hdf5pp::Type dstype = ns_DataV3_v0::dataset_data::stored_type();
00126     hdf5pp::Utils::createDataset(group, "data", dstype, chunkPolicy.chunkSize(dstype), chunkPolicy.chunkCacheSize(dstype), deflate, shuffle);
00127   }
00128 }
00129 
00130 void store_DataV3_v0(const Psana::EvrData::DataV3* obj, hdf5pp::Group group, long index, bool append)
00131 {
00132   if (obj) {
00133     ns_DataV3_v0::dataset_data ds_data(*obj);
00134     if (append) {
00135       hdf5pp::Utils::storeAt(group, "data", ds_data, index);
00136     } else {
00137       hdf5pp::Utils::storeScalar(group, "data", ds_data);
00138     }
00139   } else if (append) {
00140     hdf5pp::Utils::resizeDataset(group, "data", index < 0 ? index : index + 1);
00141   }
00142 }
00143 
00144 /// begin DataV4
00145 
00146 hdf5pp::Type ns_DataV4_v0_dataset_data_stored_type()
00147 {
00148   typedef ns_DataV4_v0::dataset_data DsType;
00149   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00150   hdf5pp::VlenType _array_type_fifoEvents = hdf5pp::VlenType::vlenType(hdf5pp::TypeTraits<EvrData::ns_FIFOEvent_v0::dataset_data>::stored_type());
00151   type.insert("fifoEvents", offsetof(DsType, vlen_fifoEvents), _array_type_fifoEvents);
00152   return type;
00153 }
00154 
00155 hdf5pp::Type ns_DataV4_v0::dataset_data::stored_type()
00156 {
00157   static hdf5pp::Type type = ns_DataV4_v0_dataset_data_stored_type();
00158   return type;
00159 }
00160 
00161 hdf5pp::Type ns_DataV4_v0_dataset_data_native_type()
00162 {
00163   typedef ns_DataV4_v0::dataset_data DsType;
00164   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00165   hdf5pp::VlenType _array_type_fifoEvents = hdf5pp::VlenType::vlenType(hdf5pp::TypeTraits<EvrData::ns_FIFOEvent_v0::dataset_data>::native_type());
00166   type.insert("fifoEvents", offsetof(DsType, vlen_fifoEvents), _array_type_fifoEvents);
00167   return type;
00168 }
00169 
00170 hdf5pp::Type ns_DataV4_v0::dataset_data::native_type()
00171 {
00172   static hdf5pp::Type type = ns_DataV4_v0_dataset_data_native_type();
00173   return type;
00174 }
00175 
00176 ns_DataV4_v0::dataset_data::dataset_data()
00177 {
00178   this->vlen_fifoEvents = 0;
00179   this->fifoEvents = 0;
00180 }
00181 
00182 ns_DataV4_v0::dataset_data::dataset_data(const Psana::EvrData::DataV4& psanaobj)
00183 {
00184   ndarray<const Psana::EvrData::FIFOEvent, 1> fifos = psanaobj.fifoEvents();
00185   vlen_fifoEvents = fifos.shape()[0];
00186   fifoEvents = (ns_FIFOEvent_v0::dataset_data*)malloc(sizeof(ns_FIFOEvent_v0::dataset_data)*vlen_fifoEvents);
00187   for(unsigned i = 0; i != vlen_fifoEvents; ++ i) {
00188     new (fifoEvents+i) ns_FIFOEvent_v0::dataset_data(fifos[i]);
00189   }
00190 }
00191 
00192 ns_DataV4_v0::dataset_data::~dataset_data()
00193 {
00194   free(this->fifoEvents);
00195 }
00196 
00197 ndarray<const Psana::EvrData::FIFOEvent, 1> DataV4_v0::fifoEvents() const {
00198   if (not m_ds_data) read_ds_data();
00199   if (m_ds_storage_data_fifoEvents.empty()) {
00200     unsigned shape[] = {m_ds_data->vlen_fifoEvents};
00201     ndarray<Psana::EvrData::FIFOEvent, 1> tmparr(shape);
00202     std::copy(m_ds_data->fifoEvents, m_ds_data->fifoEvents+m_ds_data->vlen_fifoEvents, tmparr.begin());
00203     m_ds_storage_data_fifoEvents = tmparr;
00204   }
00205   return m_ds_storage_data_fifoEvents;
00206 }
00207 
00208 uint8_t DataV4_v0::present(uint8_t opcode) const {
00209   ndarray<const Psana::EvrData::FIFOEvent, 1> fifoEvents = this->fifoEvents();
00210   for (unsigned idx = 0; idx < this->numFifoEvents(); idx++) {
00211     if (fifoEvents[idx].eventCode() == opcode) return 1;
00212   }
00213   return 0;
00214 }
00215 
00216 void DataV4_v0::read_ds_data() const {
00217   std::string dsname = "data";
00218   m_ds_data = hdf5pp::Utils::readGroup<EvrData::ns_DataV4_v0::dataset_data>(m_group, dsname, m_idx);
00219 }
00220 
00221 
00222 uint32_t DataV4_v0::numFifoEvents() const
00223 {
00224   if (not m_ds_data) read_ds_data();
00225   return m_ds_data->vlen_fifoEvents;
00226 }
00227 
00228 void make_datasets_DataV4_v0(const Psana::EvrData::DataV4& obj,
00229       hdf5pp::Group group, const ChunkPolicy& chunkPolicy, int deflate, bool shuffle)
00230 {
00231   {
00232     hdf5pp::Type dstype = ns_DataV4_v0::dataset_data::stored_type();
00233     hdf5pp::Utils::createDataset(group, "data", dstype, chunkPolicy.chunkSize(dstype), chunkPolicy.chunkCacheSize(dstype), deflate, shuffle);
00234 
00235     // special dataset for present table
00236     hsize_t dim = EvrDataPresentTableSize;
00237     hdf5pp::Type dstype2 = hdf5pp::ArrayType::arrayType(hdf5pp::TypeTraits<uint8_t>::stored_type(), dim);
00238     hdf5pp::Utils::createDataset(group, "present", dstype2, 
00239                                  chunkPolicy.chunkSize(dstype2), 
00240                                  chunkPolicy.chunkCacheSize(dstype2), deflate, shuffle);
00241   }
00242 }
00243 
00244 void store_DataV4_v0(const Psana::EvrData::DataV4* obj, hdf5pp::Group group, long index, bool append)
00245 {
00246   if (obj) {
00247     ns_DataV4_v0::dataset_data ds_data(*obj);
00248     // make present table
00249     ndarray<uint8_t, 1> presentData = make_ndarray<uint8_t>(EvrDataPresentTableSize);
00250     for (uint16_t opcode16 = 0; opcode16 < EvrDataPresentTableSize; ++opcode16) {
00251       uint8_t opcode = uint8_t(opcode16);
00252       presentData[opcode]=obj->present(opcode);
00253     }
00254     if (append) {
00255       hdf5pp::Utils::storeAt(group, "data", ds_data, index);
00256       hdf5pp::Utils::storeNDArrayAt(group, "present", presentData, index);
00257     } else {
00258       hdf5pp::Utils::storeScalar(group, "data", ds_data);
00259     hdf5pp::Utils::storeNDArray(group, "present", presentData);
00260     }
00261   } else if (append) {
00262     hdf5pp::Utils::resizeDataset(group, "data", index < 0 ? index : index + 1);
00263     hdf5pp::Utils::resizeDataset(group, "present", index < 0 ? index : index + 1);
00264   }
00265 }
00266 
00267 
00268 /// end DataV4
00269 
00270 hdf5pp::Type ns_IOChannel_v0_dataset_data_stored_type()
00271 {
00272   typedef ns_IOChannel_v0::dataset_data DsType;
00273   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00274   type.insert("name", offsetof(DsType, name), hdf5pp::TypeTraits<const char*>::stored_type());
00275 
00276   // variable-size type for info array
00277   hdf5pp::Type infoType = hdf5pp::VlenType::vlenType ( hdf5pp::TypeTraits<Pds::ns_DetInfo_v0::dataset_data>::stored_type() );
00278 
00279   type.insert("info", offsetof(DsType, ninfo), infoType);
00280   return type;
00281 }
00282 
00283 hdf5pp::Type ns_IOChannel_v0::dataset_data::stored_type()
00284 {
00285   static hdf5pp::Type type = ns_IOChannel_v0_dataset_data_stored_type();
00286   return type;
00287 }
00288 
00289 hdf5pp::Type ns_IOChannel_v0_dataset_data_native_type()
00290 {
00291   typedef ns_IOChannel_v0::dataset_data DsType;
00292   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00293   type.insert("name", offsetof(DsType, name), hdf5pp::TypeTraits<const char*>::native_type());
00294 
00295   // variable-size type for info array
00296   hdf5pp::Type infoType = hdf5pp::VlenType::vlenType ( hdf5pp::TypeTraits<Pds::ns_DetInfo_v0::dataset_data>::native_type() );
00297 
00298   type.insert("info", offsetof(DsType, ninfo), infoType);
00299   return type;
00300 }
00301 
00302 hdf5pp::Type ns_IOChannel_v0::dataset_data::native_type()
00303 {
00304   static hdf5pp::Type type = ns_IOChannel_v0_dataset_data_native_type();
00305   return type;
00306 }
00307 
00308 ns_IOChannel_v0::dataset_data::dataset_data()
00309   : ninfo(0)
00310   , infos(0)
00311 {
00312   name[0] = '\0';
00313 }
00314 
00315 ns_IOChannel_v0::dataset_data::dataset_data(const Psana::EvrData::IOChannel& psanaobj)
00316 {
00317   strncpy(name, psanaobj.name(), NameLength);
00318   name[NameLength-1] = '\0';
00319 
00320   ndarray<const Pds::DetInfo, 1> dinfos = psanaobj.infos();
00321   ninfo = dinfos.shape()[0];
00322   infos = (Pds::ns_DetInfo_v0::dataset_data*)malloc(sizeof(Pds::ns_DetInfo_v0::dataset_data)*ninfo);
00323   for(unsigned i = 0; i != ninfo; ++ i) {
00324     new (infos+i) Pds::ns_DetInfo_v0::dataset_data(dinfos[i]);
00325   }
00326 }
00327 
00328 ns_IOChannel_v0::dataset_data::dataset_data(const dataset_data& ds)
00329 {
00330   strncpy(name, ds.name, NameLength);
00331   name[NameLength-1] = '\0';
00332 
00333   ninfo = ds.ninfo;
00334   infos = (Pds::ns_DetInfo_v0::dataset_data*)malloc(sizeof(Pds::ns_DetInfo_v0::dataset_data)*ninfo);
00335   std::copy(ds.infos, ds.infos+ninfo, infos);
00336 }
00337 
00338 ns_IOChannel_v0::dataset_data&
00339 ns_IOChannel_v0::dataset_data::operator=(const dataset_data& ds)
00340 {
00341   if (this != &ds) {
00342     free(infos);
00343 
00344     strncpy(name, ds.name, NameLength);
00345     name[NameLength-1] = '\0';
00346 
00347     ninfo = ds.ninfo;
00348     infos = (Pds::ns_DetInfo_v0::dataset_data*)malloc(sizeof(Pds::ns_DetInfo_v0::dataset_data)*ninfo);
00349     std::copy(ds.infos, ds.infos+ninfo, infos);
00350   }
00351   return *this;
00352 }
00353 
00354 ns_IOChannel_v0::dataset_data::~dataset_data()
00355 {
00356   free(infos);
00357 }
00358 
00359 ns_IOChannel_v0::dataset_data::operator Psana::EvrData::IOChannel() const
00360 {
00361   Pds::DetInfo dinfos[MaxInfos];
00362   memset(dinfos,0,MaxInfos*sizeof(Pds::DetInfo));
00363   std::copy(infos, infos+ninfo, dinfos);
00364   return Psana::EvrData::IOChannel(name, ninfo, dinfos);
00365 }
00366 
00367 boost::shared_ptr<Psana::EvrData::IOChannel>
00368 Proxy_IOChannel_v0::getTypedImpl(PSEvt::ProxyDictI* dict, const Pds::Src& source, const std::string& key)
00369 {
00370   if (not m_data) {
00371     boost::shared_ptr<EvrData::ns_IOChannel_v0::dataset_data> ds_data = hdf5pp::Utils::readGroup<EvrData::ns_IOChannel_v0::dataset_data>(m_group, "data", m_idx);
00372     m_data = boost::make_shared<PsanaType>(*ds_data);
00373   }
00374 
00375   return m_data;
00376 }
00377 
00378 
00379 
00380 
00381 hdf5pp::Type ns_IOConfigV1_v0_dataset_config_stored_type()
00382 {
00383   typedef ns_IOConfigV1_v0::dataset_config DsType;
00384   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00385   hdf5pp::EnumType<int32_t> _enum_type_conn = hdf5pp::EnumType<int32_t>::enumType();
00386   _enum_type_conn.insert("FrontPanel", Psana::EvrData::OutputMap::FrontPanel);
00387   _enum_type_conn.insert("UnivIO", Psana::EvrData::OutputMap::UnivIO);
00388   type.insert("conn", offsetof(DsType, conn), _enum_type_conn);
00389   return type;
00390 }
00391 
00392 hdf5pp::Type ns_IOConfigV1_v0::dataset_config::stored_type()
00393 {
00394   static hdf5pp::Type type = ns_IOConfigV1_v0_dataset_config_stored_type();
00395   return type;
00396 }
00397 
00398 hdf5pp::Type ns_IOConfigV1_v0_dataset_config_native_type()
00399 {
00400   typedef ns_IOConfigV1_v0::dataset_config DsType;
00401   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00402   hdf5pp::EnumType<int32_t> _enum_type_conn = hdf5pp::EnumType<int32_t>::enumType();
00403   _enum_type_conn.insert("FrontPanel", Psana::EvrData::OutputMap::FrontPanel);
00404   _enum_type_conn.insert("UnivIO", Psana::EvrData::OutputMap::UnivIO);
00405   type.insert("conn", offsetof(DsType, conn), _enum_type_conn);
00406   return type;
00407 }
00408 
00409 hdf5pp::Type ns_IOConfigV1_v0::dataset_config::native_type()
00410 {
00411   static hdf5pp::Type type = ns_IOConfigV1_v0_dataset_config_native_type();
00412   return type;
00413 }
00414 
00415 ns_IOConfigV1_v0::dataset_config::dataset_config()
00416 {
00417 }
00418 
00419 ns_IOConfigV1_v0::dataset_config::dataset_config(const Psana::EvrData::IOConfigV1& psanaobj)
00420   : conn(psanaobj.conn())
00421 {
00422 }
00423 
00424 ns_IOConfigV1_v0::dataset_config::~dataset_config()
00425 {
00426 }
00427 
00428 
00429 
00430 uint16_t IOConfigV1_v0::nchannels() const {
00431   if (not m_ds_config.get()) read_ds_channels();
00432   return m_ds_channels.shape()[0];
00433 }
00434 
00435 ndarray<const Psana::EvrData::IOChannel, 1> IOConfigV1_v0::channels() const {
00436   if (m_ds_channels.empty()) read_ds_channels();
00437   return m_ds_channels;
00438 }
00439 
00440 Psana::EvrData::OutputMap::Conn IOConfigV1_v0::conn() const {
00441   if (not m_ds_config.get()) read_ds_config();
00442   return Psana::EvrData::OutputMap::Conn(m_ds_config->conn);
00443 }
00444 
00445 void IOConfigV1_v0::read_ds_config() const {
00446   m_ds_config = hdf5pp::Utils::readGroup<EvrData::ns_IOConfigV1_v0::dataset_config>(m_group, "config", m_idx);
00447 }
00448 
00449 void IOConfigV1_v0::read_ds_channels() const {
00450   ndarray<EvrData::ns_IOChannel_v0::dataset_data, 1> arr = hdf5pp::Utils::readNdarray<EvrData::ns_IOChannel_v0::dataset_data, 1>(m_group, "channels", m_idx);
00451   ndarray<Psana::EvrData::IOChannel, 1> tmp(arr.shape());
00452   std::copy(arr.begin(), arr.end(), tmp.begin());
00453   m_ds_channels = tmp;
00454 }
00455 
00456 
00457 void make_datasets_IOConfigV1_v0(const Psana::EvrData::IOConfigV1& obj,
00458       hdf5pp::Group group, const ChunkPolicy& chunkPolicy, int deflate, bool shuffle)
00459 {
00460   {
00461     hdf5pp::Type dstype = ns_IOConfigV1_v0::dataset_config::stored_type();
00462     hdf5pp::Utils::createDataset(group, "config", dstype, chunkPolicy.chunkSize(dstype), chunkPolicy.chunkCacheSize(dstype), deflate, shuffle);
00463   }
00464   {
00465     hdf5pp::Type dstype = hdf5pp::ArrayType::arrayType(hdf5pp::TypeTraits<ns_IOChannel_v0::dataset_data>::stored_type(), obj.channels().shape()[0]);
00466     hdf5pp::Utils::createDataset(group, "channels", dstype, chunkPolicy.chunkSize(dstype), chunkPolicy.chunkCacheSize(dstype), deflate, shuffle);
00467   }
00468 }
00469 
00470 void store_IOConfigV1_v0(const Psana::EvrData::IOConfigV1* obj, hdf5pp::Group group, long index, bool append)
00471 {
00472   if (not obj) {
00473     if (append) {
00474       hdf5pp::Utils::resizeDataset(group, "config", index < 0 ? index : index + 1);
00475       hdf5pp::Utils::resizeDataset(group, "channels", index < 0 ? index : index + 1);
00476     }
00477     return;
00478   }
00479 
00480   // convert IOChannel data
00481   ndarray<const Psana::EvrData::IOChannel, 1> channels = obj->channels();
00482   ndarray<ns_IOChannel_v0::dataset_data, 1> xchannels(channels.shape());
00483   for (unsigned i = 0; i != channels.shape()[0]; ++ i) {
00484     xchannels[i] = ns_IOChannel_v0::dataset_data(channels[i]);
00485   }
00486 
00487   if (append) {
00488     hdf5pp::Utils::storeAt(group, "config", ns_IOConfigV1_v0::dataset_config(*obj), index);
00489     hdf5pp::Utils::storeNDArrayAt(group, "channels", xchannels, index);
00490   } else {
00491     hdf5pp::Utils::storeScalar(group, "config", ns_IOConfigV1_v0::dataset_config(*obj));
00492     hdf5pp::Utils::storeNDArray(group, "channels", xchannels);
00493   }
00494 
00495 }
00496 
00497 
00498 
00499 hdf5pp::Type ns_IOChannelV2_v0_dataset_data_stored_type()
00500 {
00501   typedef ns_IOChannelV2_v0::dataset_data DsType;
00502   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00503   type.insert("output", offsetof(DsType, output), hdf5pp::TypeTraits<EvrData::ns_OutputMapV2_v0::dataset_data>::stored_type());
00504   type.insert("name", offsetof(DsType, name), hdf5pp::TypeTraits<const char*>::stored_type());
00505   type.insert("ninfo", offsetof(DsType, ninfo), hdf5pp::TypeTraits<uint32_t>::stored_type());
00506   hsize_t _array_type_infos_shape[] = { 16 };
00507   hdf5pp::ArrayType _array_type_infos = hdf5pp::ArrayType::arrayType(hdf5pp::TypeTraits<Pds::ns_DetInfo_v0::dataset_data>::stored_type(), 1, _array_type_infos_shape);
00508   type.insert("infos", offsetof(DsType, infos), _array_type_infos);
00509   return type;
00510 }
00511 
00512 hdf5pp::Type ns_IOChannelV2_v0::dataset_data::stored_type()
00513 {
00514   static hdf5pp::Type type = ns_IOChannelV2_v0_dataset_data_stored_type();
00515   return type;
00516 }
00517 
00518 hdf5pp::Type ns_IOChannelV2_v0_dataset_data_native_type()
00519 {
00520   typedef ns_IOChannelV2_v0::dataset_data DsType;
00521   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00522   type.insert("output", offsetof(DsType, output), hdf5pp::TypeTraits<EvrData::ns_OutputMapV2_v0::dataset_data>::native_type());
00523   type.insert("name", offsetof(DsType, name), hdf5pp::TypeTraits<const char*>::native_type());
00524   type.insert("ninfo", offsetof(DsType, ninfo), hdf5pp::TypeTraits<uint32_t>::native_type());
00525   hsize_t _array_type_infos_shape[] = { ns_IOChannelV2_v0::dataset_data::MaxInfos };
00526   hdf5pp::ArrayType _array_type_infos = hdf5pp::ArrayType::arrayType(hdf5pp::TypeTraits<Pds::ns_DetInfo_v0::dataset_data>::native_type(), 1, _array_type_infos_shape);
00527   type.insert("infos", offsetof(DsType, infos), _array_type_infos);
00528   return type;
00529 }
00530 
00531 hdf5pp::Type ns_IOChannelV2_v0::dataset_data::native_type()
00532 {
00533   static hdf5pp::Type type = ns_IOChannelV2_v0_dataset_data_native_type();
00534   return type;
00535 }
00536 
00537 ns_IOChannelV2_v0::dataset_data::dataset_data()
00538   : name(NULL)
00539   , ninfo(0)
00540 {
00541 }
00542 
00543 ns_IOChannelV2_v0::dataset_data::dataset_data(const Psana::EvrData::IOChannelV2& psanaobj)
00544   : output(psanaobj.output())
00545   , name(NULL)
00546   , ninfo(psanaobj.ninfo())
00547 {
00548   name = strdup(psanaobj.name());
00549   {
00550     const __typeof__(psanaobj.infos())& arr = psanaobj.infos();
00551     std::copy(arr.begin(), arr.begin()+MaxInfos, infos);
00552   }
00553 }
00554 
00555 ns_IOChannelV2_v0::dataset_data::~dataset_data()
00556 {
00557 }
00558 
00559 ns_IOChannelV2_v0::dataset_data::operator Psana::EvrData::IOChannelV2() const
00560 {
00561   Pds::DetInfo dinfos[Psana::EvrData::IOChannelV2::MaxInfos];
00562   std::copy(infos, infos+ninfo, dinfos);
00563   return Psana::EvrData::IOChannelV2(Psana::EvrData::OutputMapV2(output), name, ninfo, dinfos);
00564 }
00565 
00566 
00567 hdf5pp::Type ns_IOConfigV2_v0_dataset_config_stored_type()
00568 {
00569   typedef ns_IOConfigV2_v0::dataset_config DsType;
00570   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00571   type.insert("nchannels", offsetof(DsType, nchannels), hdf5pp::TypeTraits<uint32_t>::stored_type());
00572   return type;
00573 }
00574 
00575 hdf5pp::Type ns_IOConfigV2_v0::dataset_config::stored_type()
00576 {
00577   static hdf5pp::Type type = ns_IOConfigV2_v0_dataset_config_stored_type();
00578   return type;
00579 }
00580 
00581 hdf5pp::Type ns_IOConfigV2_v0_dataset_config_native_type()
00582 {
00583   typedef ns_IOConfigV2_v0::dataset_config DsType;
00584   hdf5pp::CompoundType type = hdf5pp::CompoundType::compoundType<DsType>();
00585   type.insert("nchannels", offsetof(DsType, nchannels), hdf5pp::TypeTraits<uint32_t>::native_type());
00586   return type;
00587 }
00588 
00589 hdf5pp::Type ns_IOConfigV2_v0::dataset_config::native_type()
00590 {
00591   static hdf5pp::Type type = ns_IOConfigV2_v0_dataset_config_native_type();
00592   return type;
00593 }
00594 
00595 ns_IOConfigV2_v0::dataset_config::dataset_config()
00596 {
00597 }
00598 
00599 ns_IOConfigV2_v0::dataset_config::dataset_config(const Psana::EvrData::IOConfigV2& psanaobj)
00600   : nchannels(psanaobj.nchannels())
00601 {
00602 }
00603 
00604 ns_IOConfigV2_v0::dataset_config::~dataset_config()
00605 {
00606 }
00607 uint32_t IOConfigV2_v0::nchannels() const {
00608   if (not m_ds_config) read_ds_config();
00609   return uint32_t(m_ds_config->nchannels);
00610 }
00611 ndarray<const Psana::EvrData::IOChannelV2, 1> IOConfigV2_v0::channels() const {
00612   if (m_ds_channels.empty()) read_ds_channels();
00613   return m_ds_channels;
00614 }
00615 void IOConfigV2_v0::read_ds_config() const {
00616   m_ds_config = hdf5pp::Utils::readGroup<EvrData::ns_IOConfigV2_v0::dataset_config>(m_group, "config", m_idx);
00617 }
00618 void IOConfigV2_v0::read_ds_channels() const {
00619   ndarray<EvrData::ns_IOChannelV2_v0::dataset_data, 1> arr = hdf5pp::Utils::readNdarray<EvrData::ns_IOChannelV2_v0::dataset_data, 1>(m_group, "channels", m_idx);
00620   ndarray<Psana::EvrData::IOChannelV2, 1> tmp(arr.shape());
00621   std::copy(arr.begin(), arr.end(), tmp.begin());
00622   m_ds_channels = tmp;
00623 }
00624 
00625 void make_datasets_IOConfigV2_v0(const Psana::EvrData::IOConfigV2& obj,
00626       hdf5pp::Group group, const ChunkPolicy& chunkPolicy, int deflate, bool shuffle)
00627 {
00628   {
00629     hdf5pp::Type dstype = EvrData::ns_IOConfigV2_v0::dataset_config::stored_type();
00630     hdf5pp::Utils::createDataset(group, "config", dstype, chunkPolicy.chunkSize(dstype), chunkPolicy.chunkCacheSize(dstype), deflate, shuffle);
00631   }
00632   {
00633     typedef __typeof__(obj.channels()) PsanaArray;
00634     const PsanaArray& psana_array = obj.channels();
00635     hdf5pp::Type dstype = hdf5pp::ArrayType::arrayType(hdf5pp::TypeTraits<EvrData::ns_IOChannelV2_v0::dataset_data>::stored_type(), psana_array.shape()[0]);
00636     hdf5pp::Utils::createDataset(group, "channels", dstype, chunkPolicy.chunkSize(dstype), chunkPolicy.chunkCacheSize(dstype), deflate, shuffle);
00637   }
00638 }
00639 
00640 void store_IOConfigV2_v0(const Psana::EvrData::IOConfigV2* obj, hdf5pp::Group group, long index, bool append)
00641 {
00642   if (obj) {
00643     EvrData::ns_IOConfigV2_v0::dataset_config ds_data(*obj);
00644     if (append) {
00645       hdf5pp::Utils::storeAt(group, "config", ds_data, index);
00646     } else {
00647       hdf5pp::Utils::storeScalar(group, "config", ds_data);
00648     }
00649   } else if (append) {
00650     hdf5pp::Utils::resizeDataset(group, "config", index < 0 ? index : index + 1);
00651   }
00652   if (obj) {
00653     typedef __typeof__(obj->channels()) PsanaArray;
00654     typedef ndarray<EvrData::ns_IOChannelV2_v0::dataset_data, 1> HdfArray;
00655     PsanaArray psana_array = obj->channels();
00656     HdfArray hdf_array(psana_array.shape());
00657     HdfArray::iterator out = hdf_array.begin();
00658     for (PsanaArray::iterator it = psana_array.begin(); it != psana_array.end(); ++ it, ++ out) {
00659       *out = EvrData::ns_IOChannelV2_v0::dataset_data(*it);
00660     }
00661     if (append) {
00662       hdf5pp::Utils::storeNDArrayAt(group, "channels", hdf_array, index);
00663     } else {
00664       hdf5pp::Utils::storeNDArray(group, "channels", hdf_array);
00665     }
00666   } else if (append) {
00667     hdf5pp::Utils::resizeDataset(group, "channels", index < 0 ? index : index + 1);
00668   }
00669 
00670 }
00671 
00672 } // namespace EvrData
00673 } // namespace psddl_hdf2psana

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7