32 #ifndef NIDAS_CORE_SAMPLET_H
33 #define NIDAS_CORE_SAMPLET_H
49 namespace nidas {
namespace core {
75 #define GET_SAMPLE_TYPE(tid) ((tid) >> 26)
76 #define SET_SAMPLE_TYPE(tid,val) (((tid) & 0x03ffffff) | ((unsigned int)(val) << 26))
78 #define GET_FULL_ID(tid) ((tid) & 0x03ffffff)
79 #define SET_FULL_ID(tid,val) (((tid) & 0xfc000000) | ((val) & 0x03ffffff))
81 #define GET_DSM_ID(tid) (((tid) & 0x03ff0000) >> 16)
82 #define SET_DSM_ID(tid,val) (((tid) & 0xfc00ffff) | (((unsigned int)(val) & 0x3ff) << 16))
84 #define GET_SPS_ID(tid) ((tid) & 0xffff)
85 #define GET_SHORT_ID(tid) ((tid) & 0xffff)
87 #define SET_SPS_ID(tid,val) (((tid) & 0xffff0000) | ((val) & 0xffff))
88 #define SET_SHORT_ID(tid,val) (((tid) & 0xffff0000) | ((val) & 0xffff))
94 #define MUTEX_PROTECT_REF_COUNTS
303 virtual void setDataValue(
unsigned int i,
double val) = 0;
309 virtual void setDataValue(
unsigned int i,
float val) = 0;
340 #ifdef USE_ATOMIC_REF_COUNT
343 #ifdef MUTEX_PROTECT_REF_COUNTS
347 #ifdef MUTEX_PROTECT_REF_COUNTS
367 #ifdef MUTEX_PROTECT_REF_COUNTS
376 #ifndef PROTECT_NSAMPLES
378 #ifdef ENABLE_VALGRIND
382 friend class InitValgrind;
392 template <
class DataT>
464 return (
double)
_data[i];
472 _data[i] = (DataT)val;
480 _data[i] = (DataT)val;
503 _data =
new DataT[val];
518 DataT* newdata =
new DataT[val];
614 namespace nidas {
namespace core {
631 template <
class DataT>
635 #ifdef USE_ATOMIC_REF_COUNT
637 int rc = __sync_sub_and_fetch(&_refCount,1);
642 #ifdef MUTEX_PROTECT_REF_COUNTS
645 bool ref0 = --_refCount == 0;
646 assert(_refCount >= 0);
647 #ifdef MUTEX_PROTECT_REF_COUNTS
unsigned int getAllocLength() const
Get number of elements allocated in data portion of sample.
Definition: Sample.h:486
SampleType * getSample(unsigned int len)
Get a sample of at least len elements from the pool.
Definition: SamplePool.h:258
virtual void * getVoidDataPtr()=0
Get a void* pointer to the data portion of the sample.
const void * getHeaderPtr() const
Get a pointer to the header portion of the sample.
Definition: Sample.h:281
void reallocateData(unsigned int val)
Re-allocate data, space, keeping contents.
Definition: Sample.h:513
#define GET_DSM_ID(tid)
Definition: Sample.h:81
void putSample(const SampleType *)
Return a sample to the pool.
Definition: SamplePool.h:346
sampleType
Definition: sample_type_traits.h:30
sampleType getSampleType(T *)
Definition: sample_type_traits.h:111
void freeReference() const
Decrement the reference count for this sample.
Definition: Sample.h:632
Definition: sample_type_traits.h:31
#define SET_DSM_ID(tid, val)
Definition: Sample.h:82
unsigned int dsm_sample_id_t
Definition: Sample.h:63
SampleT()
Definition: Sample.h:415
#define GET_FULL_ID(tid)
Definition: Sample.h:78
unsigned int getAllocByteLength() const
Get number of bytes allocated in data portion of sample.
Definition: Sample.h:491
virtual void freeReference() const =0
Decrement the reference count for this sample.
unsigned int maxValue(unsigned short)
maxValue is an overloaded function returning the maximum value of its integer argument.
Definition: sample_type_traits.h:10
long long dsm_time_t
Posix time in microseconds, the number of non-leap microseconds since 1970 Jan 1 00:00 UTC...
Definition: Sample.h:61
#define SET_FULL_ID(tid, val)
Definition: Sample.h:79
nidas::util::Mutex _refLock
Definition: Sample.h:368
virtual unsigned int getDataLength() const =0
Get the number of elements in data portion of sample.
const float floatNAN
Value of a float NAN for general use.
Definition: Sample.cc:31
void allocateData(unsigned int val)
Allocate data.
Definition: Sample.h:497
const double doubleNAN
Definition: Sample.cc:33
virtual unsigned int getAllocLength() const =0
Get number of elements allocated in data portion of sample.
DataT * _data
Pointer to the actual data.
Definition: Sample.h:584
dsm_sample_id_t getRawId() const
Definition: Sample.h:228
void setId(dsm_sample_id_t val)
Set the id portion of the sample header.
Definition: Sample.h:212
unsigned int _allocLen
Number of bytes allocated in data.
Definition: Sample.h:589
virtual void reallocateData(unsigned int val)=0
Re-allocate a number of bytes of data, saving old contents.
virtual ~Sample()
Definition: Sample.h:198
virtual unsigned int getAllocByteLength() const =0
Get number of bytes allocated in data portion of sample.
void setDataValue(unsigned int i, double val)
Implementation of virtual method.
Definition: Sample.h:470
virtual const void * getConstVoidDataPtr() const =0
Get a const void* pointer to the data portion of the sample.
void setTimeTag(dsm_time_t val)
Definition: Sample.h:200
void setDataLength(unsigned int val)
Set the number of elements of type DataT in data.
Definition: Sample.h:436
unsigned int getHeaderLength() const
Number of bytes in header.
Definition: Sample.h:276
dsm_time_t getTimeTag() const
Time-tag in non-leap microseconds since Jan 1, 1970 00:00 GMT.
Definition: Sample.h:205
dsm_sample_id_t getId() const
Get the id portion of the sample header.
Definition: Sample.h:217
Definition: SampleLengthException.h:35
void setDataValue(unsigned int i, float val)
Implementation of virtual method.
Definition: Sample.h:478
void setRawId(dsm_sample_id_t val)
Set the full, raw id portion of the sample header.
Definition: Sample.h:226
unsigned int getDSMId() const
Get the DSM (data system) id portion of the sample header.
Definition: Sample.h:251
#define GET_SAMPLE_TYPE(tid)
macros to get and set fields of the tid member of a Sample.
Definition: Sample.h:75
void setSpSId(unsigned int val)
Set the short id portion of the sample header, containing the sensor + sample ids.
Definition: Sample.h:235
virtual sampleType getType() const =0
Get the type of the sample.
A typed Sample, with data of type DataT.
Definition: Sample.h:393
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition: Sample.cc:70
void lock()
Lock the Mutex.
Definition: ThreadSupport.h:206
unsigned int getSpSId() const
Get the short id portion of the sample header.
Definition: Sample.h:241
int len
Definition: sing.cc:934
Interface to a data sample.
Definition: Sample.h:189
void holdReference() const
Increment the reference count for this sample.
Definition: Sample.h:339
DataT * getDataPtr()
Definition: Sample.h:455
const DataT * getConstDataPtr() const
Definition: Sample.h:457
virtual double getDataValue(unsigned int i) const =0
Get the numeric value of data element i.
double getDataValue(unsigned int i) const
Implementation of virtual method.
Definition: Sample.h:462
unsigned int getDataByteLength() const
Get the number of bytes in data portion of sample.
Definition: Sample.h:256
sampleType getType() const
Get the type of the sample.
Definition: Sample.h:422
int _refCount
The reference count.
Definition: Sample.h:365
SampleHeader _header
Definition: Sample.h:360
static int sizeofDataType()
Definition: Sample.h:526
~SampleT()
Definition: Sample.h:420
A class which wraps a numeric value and guards operations on it with a Mutex.
Definition: MutexCount.h:30
unsigned int dsm_sample_length_t
length of data portion of sample.
Definition: types.h:51
A pool of Samples.
Definition: SamplePool.h:98
virtual void allocateData(unsigned int val)=0
Allocate a number of bytes of data.
static unsigned int getMaxDataLength()
Maximum number of elements in data.
Definition: Sample.h:447
virtual void setDataValue(unsigned int i, double val)=0
Set the value of data element i to a double.
void * getVoidDataPtr()
Get a void* pointer to the data portion of the sample.
Definition: Sample.h:452
#define GET_SPS_ID(tid)
Definition: Sample.h:84
static int _nsamps
Global count of the number of samples in use by a process.
Definition: Sample.h:377
Sample(sampleType t=CHAR_ST)
Definition: Sample.h:192
const void * getConstVoidDataPtr() const
Get a const void* pointer to the data portion of the sample.
Definition: Sample.h:453
A C++ wrapper for a POSIX mutex.
Definition: ThreadSupport.h:154
#define SET_SPS_ID(tid, val)
Definition: Sample.h:87
SampleT & operator=(const SampleT &)
No assignment.
void setDSMId(unsigned int val)
Set the DSM (data system) id portion of the sample header.
Definition: Sample.h:246
virtual void setDataLength(unsigned int val)=0
Set the number of elements in data portion of sample.
unsigned int getDataLength() const
Get number of elements of type DataT in data.
Definition: Sample.h:427
Definition: sample_type_traits.h:45
void unlock()
Unlock the Mutex.
Definition: ThreadSupport.h:218