H5DataTypes/src/CsPad2x2PixelStatusV1.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: CsPad2x2PixelStatusV1.cpp 5793 2013-03-19 18:41:33Z salnikov@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class CsPad2x2PixelStatusV1...
00007 //
00008 // Author List:
00009 //      Andy Salnikov
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "H5DataTypes/CsPad2x2PixelStatusV1.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 #include <algorithm>
00022 #include <stdexcept>
00023 
00024 //-------------------------------
00025 // Collaborating Class Headers --
00026 //-------------------------------
00027 #include "ErrSvc/Issue.h"
00028 #include "hdf5pp/ArrayType.h"
00029 #include "hdf5pp/TypeTraits.h"
00030 #include "H5DataTypes/H5DataUtils.h"
00031 #include "MsgLogger/MsgLogger.h"
00032 
00033 //-----------------------------------------------------------------------
00034 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00035 //-----------------------------------------------------------------------
00036 
00037 namespace {
00038 
00039   class BadShape: public ErrSvc::Issue {
00040   public:
00041     BadShape(const ErrSvc::Context& ctx) : ErrSvc::Issue(ctx, "Illegal shape of data array") {}
00042   };
00043 
00044 }
00045 
00046 //              ----------------------------------------
00047 //              -- Public Function Member Definitions --
00048 //              ----------------------------------------
00049 
00050 namespace H5DataTypes {
00051 
00052 //----------------
00053 // Constructors --
00054 //----------------
00055 CsPad2x2PixelStatusV1::CsPad2x2PixelStatusV1 ()
00056 {
00057   // fill all codes with zeros
00058   pdscalibdata::CsPad2x2PixelStatusV1::status_t zero=0;
00059   std::fill_n(&status[0][0][0], int(DataType::Size), zero);
00060 }
00061 
00062 CsPad2x2PixelStatusV1::CsPad2x2PixelStatusV1 (const DataType& data)
00063 {
00064   const ndarray<DataType::status_t, 3>& sdata = data.status();
00065 
00066   // verify that data shape is what we expect
00067   const unsigned* shape = sdata.shape();
00068   if (shape[0] != DataType::Columns or shape[1] != DataType::Rows or shape[2] != DataType::Sections) {
00069     throw BadShape(ERR_LOC);
00070   }
00071 
00072   const DataType::status_t* src = sdata.data();
00073   DataType::status_t* dst = &status[0][0][0];
00074   std::copy(src, src+int(DataType::Size), dst );
00075 }
00076 
00077 //--------------
00078 // Destructor --
00079 //--------------
00080 CsPad2x2PixelStatusV1::~CsPad2x2PixelStatusV1 ()
00081 {
00082 }
00083 
00084 
00085 hdf5pp::Type
00086 CsPad2x2PixelStatusV1::stored_type()
00087 {
00088   return native_type() ;
00089 }
00090 
00091 hdf5pp::Type
00092 CsPad2x2PixelStatusV1::native_type()
00093 {
00094   hsize_t dims[4] = { DataType::Columns,
00095                       DataType::Rows,
00096                       DataType::Sections};
00097   hdf5pp::ArrayType arrType =
00098     hdf5pp::ArrayType::arrayType(hdf5pp::TypeTraits<DataType::status_t>::native_type(), 3, dims) ;
00099   return arrType;
00100 }
00101 
00102 void
00103 CsPad2x2PixelStatusV1::store( const DataType& data, hdf5pp::Group grp, const std::string& fileName )
00104 {
00105   CsPad2x2PixelStatusV1 obj(data);
00106   hdf5pp::DataSet ds = storeDataObject ( obj, "pixel_status", grp ) ;
00107 
00108   // add attributes
00109   ds.createAttr<const char*>("source").store(fileName.c_str());
00110 }
00111 
00112 } // namespace H5DataTypes

Generated on 19 Dec 2016 for PSDMSoftware by  doxygen 1.4.7