OpenZGY/C++ API and Internals (ALPHA)
Access seismic data stored in ZGY format.
Public Types | Public Member Functions | Static Public Member Functions | List of all members
InternalZGY::DataBufferNd< T, NDim > Class Template Reference
Inheritance diagram for InternalZGY::DataBufferNd< T, NDim >:
InternalZGY::DataBuffer

Public Types

enum  { ndim = NDim }
 
typedef T value_type
 
typedef DataBufferNd< T, NDim > self_type
 
typedef std::array< std::int64_t, NDim > ndsize_t
 
- Public Types inherited from InternalZGY::DataBuffer
enum  flags_t { C_ORDERING =1, CONTIGUOUS =2, POSITIVE_STRIDE =4, DEGENERATE =8 }
 

Public Member Functions

 DataBufferNd (const self_type &)=delete
 
self_typeoperator= (const self_type &)=delete
 
 DataBufferNd (T scalar, const std::array< std::int64_t, NDim > &size)
 
 DataBufferNd (const std::array< std::int64_t, NDim > &size)
 
 DataBufferNd (const std::array< std::int64_t, NDim > &size, const std::array< std::int64_t, NDim > &stride)
 
 DataBufferNd (const std::shared_ptr< T > &data, const std::array< std::int64_t, NDim > &size)
 
 DataBufferNd (const std::shared_ptr< T > &data, const std::array< std::int64_t, NDim > &size, const std::array< std::int64_t, NDim > &stride)
 
T * data ()
 
const T * data () const
 
scalarValue () const
 
virtual bool ownsdata () const
 
bool isScalar () const override
 
bool isAllSame (const std::int64_t *used_in) const override
 
double scalarAsDouble () const override
 
RawDataType datatype () const override
 
void fill (double value) override
 Set all samples to the same value. More...
 
void clear () override
 
std::pair< double, double > range () const override
 
std::uint32_t layout () const override
 
bool is_cstride () const override
 
void check_cstride () const override
 
std::string toString () const override
 
std::shared_ptr< void > voidData () override
 
std::shared_ptr< const void > voidData () const override
 
bool contiguous () const override
 
std::int64_t allocsize () const override
 
std::int64_t totalsize () const override
 
std::int64_t itemsize () const override
 
const std::int64_t * sizeptr () const override
 
const std::int64_t * strideptr () const override
 
std::array< std::int64_t, 3 > size3d () const override
 
std::array< std::int64_t, 3 > stride3d () const override
 
const ndsize_t & safesize () const
 
const ndsize_t & safestride () const
 
std::shared_ptr< DataBufferclone () const
 
std::shared_ptr< DataBufferscaleToFloat (const std::array< double, 2 > &) override
 
std::shared_ptr< DataBufferscaleToStorage (const std::array< double, 2 > &, RawDataType) override
 
std::shared_ptr< DataBufferslice1 (int dim, std::int64_t start, std::int64_t size) const override
 Make a shallow view over the buffer, showing only part of the input. More...
 
std::shared_ptr< self_typeslice (const ndsize_t &neworig, const ndsize_t &newsize) const
 Make a shallow view over the buffer, showing only part of the input. More...
 
void copyFrom (const DataBuffer *src, const std::int64_t *srcorig, const std::int64_t *dstorig, const std::int64_t *cpyorig, const std::int64_t *cpysize)
 
- Public Member Functions inherited from InternalZGY::DataBuffer
 DataBuffer (const DataBuffer &)=delete
 
DataBufferoperator= (const DataBuffer &)=delete
 

Static Public Member Functions

static void copySubset (const ndsize_t &srcorig, const self_type &src, const ndsize_t &dstorig, self_type &dst, const ndsize_t &cpyorig, const ndsize_t &cpysize)
 
static void copySubset (const ndsize_t &srcorig, const self_type &src, const ndsize_t &dstorig, self_type &dst)
 
static std::shared_ptr< DataBuffers_scaleToFloat (const DataBuffer *, const std::array< double, 2 > &)
 
static std::shared_ptr< DataBuffers_scaleFromFloat (const DataBuffer *, const std::array< double, 2 > &)
 
- Static Public Member Functions inherited from InternalZGY::DataBuffer
static std::shared_ptr< DataBuffermakeDataBuffer3d (void *raw, std::int64_t nbytes, const std::array< std::int64_t, 3 > &size, RawDataType dtype)
 

Member Function Documentation

◆ clear()

template<typename T , int NDim>
void InternalZGY::DataBufferNd< T, NDim >::clear
overridevirtual

Make the buffer empty. Size and stride are unchanged but the data will be nullptr. This will cause an access violation if trying to read or write data. The reason this is useful is that _data might point to something that is not reference counted by our smart pointer. The pointer's deleter is then a no-op. clear() should be called if we can no longer trust that the pointer is valid. A reproducible null pointer exception is way better than random crashes.

Implements InternalZGY::DataBuffer.

◆ clone()

template<typename T , int NDim>
std::shared_ptr< DataBuffer > InternalZGY::DataBufferNd< T, NDim >::clone
virtual

Make a deep copy of the buffer. Works both for scalars and normal buffers. TODO-Low: consider making the buffer contiguous.

Implements InternalZGY::DataBuffer.

◆ copyFrom()

template<typename T , int NDim>
void InternalZGY::DataBufferNd< T, NDim >::copyFrom ( const DataBuffer src,
const std::int64_t *  srcorig,
const std::int64_t *  dstorig,
const std::int64_t *  cpyorig,
const std::int64_t *  cpysize 
)
virtual

Corresponds to openzgy.impl._partialCopy(). To make templates work better the C++ version is an instance method with 'this' as destination.

Implements InternalZGY::DataBuffer.

◆ fill()

template<typename T , int NDim>
void InternalZGY::DataBufferNd< T, NDim >::fill ( double  value)
overridevirtual

Set all samples to the same value.

The value is passed as a float and will be cast to the correct type. There is NO check for overflow.

Some optimizing is attempted because gprof claims that (a) calling this function amounts to 50% of the read overhead, and (b) memset, if possible, would reduce that time significantly. I suspect that both of those numbers are false. An ad-hoc Timer reports 10% in both cases. But just in case I am wrong I have added the optimization.

Using memset is possible if the value to be set is zero (the common case for float cubes) and if the sample size is 1 (all int8 cubes). Int16 cubes are less likely to benefit.

Implements InternalZGY::DataBuffer.

◆ s_scaleFromFloat()

template<typename T , int NDim>
std::shared_ptr< DataBuffer > InternalZGY::DataBufferNd< T, NDim >::s_scaleFromFloat ( const DataBuffer in,
const std::array< double, 2 > &  factors 
)
static

See s_scaleToFloat() for details.

◆ s_scaleToFloat()

template<typename T , int NDim>
std::shared_ptr< DataBuffer > InternalZGY::DataBufferNd< T, NDim >::s_scaleToFloat ( const DataBuffer in,
const std::array< double, 2 > &  factors 
)
static

Copy the input DataBuffer into a newly allocated buffer of float. The input is assumed to have been read from a ZGY file, so this function will also apply the storage to float transform.

If the buffer is already floating point then it needs neither type conversion nor scaling and the function will return an empty pointer. Note that it does not return its input argument, because the input is a plain pointer and I don't want to mess with std::enable_shared_from_this.

Note that both s_scaleToFloat and s_scaleFromFloat are private static methods that are templated on the integral type. This means that s_scaleToFloat is templated on the input type and s_scaleFromFloat is templated on the desired target type. The public interface is in the virtual scaleToFloat() and scaleToStorage() methods.

If the buffer is non contiguous the contents of the padding area is unspecified. It might be garbage or values converted from the input. This violates the principle of least surprise but is likely harmless.

TODO-Low: Should I try to combine the type conversion and scaling done here with the functionality of copySubset? This might allow skipping one temporary buffer but I don't know how easy it will be for the bulk access to make use of it.

◆ scaleToFloat()

template<typename T , int NDim>
std::shared_ptr< DataBuffer > InternalZGY::DataBufferNd< T, NDim >::scaleToFloat ( const std::array< double, 2 > &  )
overridevirtual

Convert DataBufferNd<T,N> to DataBufferNd<float,N>, hiding leaf types.

Implements InternalZGY::DataBuffer.

◆ scaleToStorage()

template<typename T , int NDim>
std::shared_ptr< DataBuffer > InternalZGY::DataBufferNd< T, NDim >::scaleToStorage ( const std::array< double, 2 > &  ,
RawDataType   
)
overridevirtual

Convert DataBufferNd<float,N> to DataBufferNd<T,N>, hiding leaf types.

Implements InternalZGY::DataBuffer.

◆ size3d()

template<typename T , int NDim>
std::array< std::int64_t, 3 > InternalZGY::DataBufferNd< T, NDim >::size3d
overridevirtual

Return the size of the buffer, assuming it is 3d. Which it almost always is. As a code smell this suggests that DataBuffer maybe shouldn't have been templated on NDim in the first place. Or have NDim as a regular varable. If fewer than 3 dimensions exist then the first index or indices are treated as size=1, stride=0. If more then 3 dimensions only the last 3 will be returned. Which is probably not very useful.

Implements InternalZGY::DataBuffer.

◆ sizeptr()

template<typename T , int NDim>
const std::int64_t * InternalZGY::DataBufferNd< T, NDim >::sizeptr
overridevirtual

Return the size of the buffer, as a pointer to the first dimension. This is unsafe since the compiler cannot check the length. This function is meant for internal use in this file. Used by CopySubset and CopySize. TODO-Low consider making those friends so that this method can be declared private or inlined.

Implements InternalZGY::DataBuffer.

◆ slice()

template<typename T , int NDim>
std::shared_ptr< DataBufferNd< T, NDim > > InternalZGY::DataBufferNd< T, NDim >::slice ( const ndsize_t &  neworig,
const ndsize_t &  newsize 
) const

Make a shallow view over the buffer, showing only part of the input.

If the input is contiguous and the slicing is done only on the slowest varying dimension then the result will be contiguous as well.

TODO-Worry: Much of the code using class DataBuffer assumes contiguous buffers without stating this explicitly.

◆ slice1()

template<typename T , int NDim>
std::shared_ptr< DataBuffer > InternalZGY::DataBufferNd< T, NDim >::slice1 ( int  dim,
std::int64_t  start,
std::int64_t  size 
) const
overridevirtual

Make a shallow view over the buffer, showing only part of the input.

If the input is contiguous and the slicing is done only on the slowest varying dimension then the result will be contiguous as well.

TODO-Worry: Much of the code using class DataBuffer assumes contiguous buffers without stating this explicitly.

The slice1() function signature allows just one dimension to change at a time. This corresponds to how the method is used in OpenZGY. It also makes it possible to declare the method virtual in class DataBuffer. Yet another place I regret templating on NDim.

Implements InternalZGY::DataBuffer.

◆ stride3d()

template<typename T , int NDim>
std::array< std::int64_t, 3 > InternalZGY::DataBufferNd< T, NDim >::stride3d
overridevirtual

Return the layout of the buffer, assuming it is 3d. See size3d().

Implements InternalZGY::DataBuffer.

◆ strideptr()

template<typename T , int NDim>
const std::int64_t * InternalZGY::DataBufferNd< T, NDim >::strideptr
overridevirtual

Return the layout of the buffer, assuming it is 3d. See sizeptr().

Implements InternalZGY::DataBuffer.


The documentation for this class was generated from the following files: