Skip to content
Snippets Groups Projects
Commit eee36411 authored by Jonathan Hanks's avatar Jonathan Hanks
Browse files

Extending the testing of daqd with 16bit ints.

parent 98f6cb2d
No related branches found
No related tags found
No related merge requests found
......@@ -240,12 +240,20 @@ public:
size_t mid_channel_num =
mid_data_bytes / ( sizeof( float ) * mid_rate );
size_t slow_channel_num = slow_data_bytes / ( sizeof( float ) * 16 );
size_t channel_num = fast_channel_num + slow_channel_num;
size_t slow_16i_channel_num = 0;
if ( slow_channel_num > 2 )
{
slow_channel_num -= 1;
slow_16i_channel_num = 2;
}
size_t channel_num = fast_channel_num + mid_channel_num +
slow_channel_num + slow_16i_channel_num;
generators_.reserve( channel_num );
tp_generators_.reserve( tp_table_.size( ) );
size_t mid_channel_boundary = fast_channel_num + mid_channel_num;
size_t slow_channel_boundary = mid_channel_boundary + slow_channel_num;
ChNumDb chDb;
ChNumDb tpDb;
......@@ -272,7 +280,7 @@ public:
SimChannel( ss.str( ), 2, mid_rate, chnum ),
( i + dcu_id_ ) % 21 ) ) );
}
for ( size_t i = mid_channel_boundary; i < channel_num; ++i )
for ( size_t i = mid_channel_boundary; i < slow_channel_boundary; ++i )
{
int chnum = chDb.next( 4 );
......@@ -283,6 +291,17 @@ public:
SimChannel( ss.str( ), 2, 16, chnum ),
( i + dcu_id_ ) % 21 ) ) );
}
for ( size_t i = slow_channel_boundary; i < channel_num; ++i )
{
int chnum = chDb.next( 4 );
std::ostringstream ss;
ss << name_ << "-" << i;
generators_.push_back(
GeneratorPtr( new Generators::GPSMod30kSecWithOffset< short >(
SimChannel( ss.str( ), 1, 16, chnum ),
( i + dcu_id_ ) % 21 ) ) );
}
for ( size_t i = 0; i < tp_table_.size( ); ++i )
{
......
......@@ -132,6 +132,28 @@ get_nds_channels( Config& cfg )
NDS::channel_predicate( "*", NDS::channel::CHANNEL_TYPE_ONLINE ) );
}
bool
is_16bit_int_channel( const NDS::channel& ch )
{
return ch.DataType( ) == NDS::channel::DATA_TYPE_INT16;
}
void
add_16bit_int_channel( const NDS::channels_type& channels,
std::vector< int >& indexes )
{
for ( int i = 0; i < channels.size( ); ++i )
{
if ( is_16bit_int_channel( channels[ i ] ) &&
std::find( indexes.begin( ), indexes.end( ), i ) ==
indexes.end( ) )
{
indexes.push_back( i );
break;
}
}
}
std::vector< GeneratorPtr >
load_generators( Config& cfg )
{
......@@ -147,7 +169,13 @@ load_generators( Config& cfg )
<< cfg.seed << "\n";
std::vector< int > indexes{};
indexes.reserve( cfg.random_channels );
for ( int i = 0; i < cfg.random_channels; ++i )
add_16bit_int_channel( channels, indexes );
add_16bit_int_channel( channels, indexes );
for ( int i = 0; i < indexes.size( ); ++i )
{
cfg.channels.push_back( channels[ indexes[ i ] ].Name( ) );
}
for ( int i = indexes.size( ); i < cfg.random_channels; ++i )
{
int index = 0;
do
......@@ -195,6 +223,10 @@ main( int argc, char* argv[] )
std::vector< std::shared_ptr< NDS::buffers_type > > data_from_nds;
NDS::parameters params(
cfg.hostname, cfg.port, NDS::connection::PROTOCOL_ONE );
std::cout << "Requesting data from " << cfg.gps << " to " << cfg.gps + 1
<< "\n";
auto stream = NDS::iterate(
params, NDS::request_period( cfg.gps, cfg.gps + 1 ), cfg.channels );
for ( const auto& bufs : stream )
......
......@@ -21,21 +21,32 @@ class SimChannel
{
private:
std::string name_;
int chtype_;
int rate_;
int chnum_;
int dcuid_;
int chtype_;
int rate_;
int chnum_;
int dcuid_;
public:
SimChannel(): name_(""), chtype_(0), rate_(0), chnum_(0), dcuid_(0) {}
SimChannel(std::string name, int chtype, int rate, int chnum, int dcuid=0):
name_(name), chtype_(chtype), rate_(rate), chnum_(chnum), dcuid_(dcuid) {}
SimChannel(const SimChannel& other):
name_(other.name_), chtype_(other.chtype_), rate_(other.rate_),
chnum_(other.chnum_), dcuid_(other.dcuid_) {}
SimChannel& operator=(const SimChannel& other)
SimChannel( )
: name_( "" ), chtype_( 0 ), rate_( 0 ), chnum_( 0 ), dcuid_( 0 )
{
}
SimChannel(
std::string name, int chtype, int rate, int chnum, int dcuid = 0 )
: name_( name ), chtype_( chtype ), rate_( rate ), chnum_( chnum ),
dcuid_( dcuid )
{
}
SimChannel( const SimChannel& other )
: name_( other.name_ ), chtype_( other.chtype_ ), rate_( other.rate_ ),
chnum_( other.chnum_ ), dcuid_( other.dcuid_ )
{
}
SimChannel&
operator=( const SimChannel& other )
{
if (this != &other)
if ( this != &other )
{
name_ = other.name_;
chtype_ = other.chtype_;
......@@ -46,256 +57,349 @@ public:
return *this;
}
int data_type() const { return chtype_; }
int data_rate() const { return rate_; }
int channel_num() const { return chnum_; }
int dcuid() const { return dcuid_; }
int
data_type( ) const
{
return chtype_;
}
int
data_rate( ) const
{
return rate_;
}
int
channel_num( ) const
{
return chnum_;
}
int
dcuid( ) const
{
return dcuid_;
}
const std::string& name() const { return name_; }
const std::string&
name( ) const
{
return name_;
}
};
class Generator
{
protected:
virtual const std::string& channel_base_name() const = 0;
virtual const std::string& channel_base_name( ) const = 0;
virtual std::string
other_params( ) const
{
return "";
}
virtual std::string other_params() const { return ""; }
public:
virtual std::string generator_name() const = 0;
virtual std::string full_channel_name() const
virtual std::string generator_name( ) const = 0;
virtual std::string
full_channel_name( ) const
{
std::ostringstream os;
os << channel_base_name() << "--" << generator_name() << other_params() << "--" << data_type() << "--" << data_rate();
return os.str();
os << channel_base_name( ) << "--" << generator_name( )
<< other_params( ) << "--" << data_type( ) << "--" << data_rate( );
return os.str( );
}
virtual size_t bytes_per_sec() const = 0;
virtual size_t bytes_per_sec( ) const = 0;
virtual char* generate(int gps_sec, int gps_nano, char *out) = 0;
virtual char* generate( int gps_sec, int gps_nano, char* out ) = 0;
virtual void output_ini_entry(std::ostream& os) = 0;
virtual void output_par_entry(std::ostream& os) = 0;
virtual void output_ini_entry( std::ostream& os ) = 0;
virtual void output_par_entry( std::ostream& os ) = 0;
virtual int data_type() const = 0;
virtual int data_rate() const = 0;
virtual int data_type( ) const = 0;
virtual int data_rate( ) const = 0;
};
typedef std::tr1::shared_ptr<Generator> GeneratorPtr;
typedef std::tr1::shared_ptr< Generator > GeneratorPtr;
namespace Generators {
class SimChannelGenerator : public Generator {
namespace Generators
{
class SimChannelGenerator : public Generator
{
protected:
SimChannel ch_;
virtual const std::string& channel_base_name() const { return ch_.name(); };
virtual const std::string&
channel_base_name( ) const
{
return ch_.name( );
};
public:
SimChannelGenerator(const SimChannel& ch):
ch_(ch) {}
SimChannelGenerator( const SimChannel& ch ) : ch_( ch )
{
}
virtual size_t bytes_per_sec() const
virtual size_t
bytes_per_sec( ) const
{
if (ch_.data_type() != 2 && ch_.data_type() != 4)
throw std::runtime_error("Unsupported type");
return ch_.data_rate()*4;
return data_type_size( static_cast< short >( ch_.data_type( ) ) ) *
ch_.data_rate( );
}
virtual void output_ini_entry(std::ostream& os)
virtual void
output_ini_entry( std::ostream& os )
{
os << "[" << full_channel_name() << "]\n";
os << "datarate=" << data_rate() << "\n";
os << "datatype=" << data_type() << "\n";
os << "chnnum=" << ch_.channel_num() << "\n";
os << "[" << full_channel_name( ) << "]\n";
os << "datarate=" << data_rate( ) << "\n";
os << "datatype=" << data_type( ) << "\n";
os << "chnnum=" << ch_.channel_num( ) << "\n";
}
virtual void output_par_entry(std::ostream& os)
virtual void
output_par_entry( std::ostream& os )
{
if (data_rate() != 2048)
throw std::runtime_error("Cannot generate a par entry for a non 2k channel right now");
if (data_type() != 4)
throw std::runtime_error("Cannot generate a par entry for a non float channel");
os << "[" << full_channel_name() << "]\n";
if ( data_rate( ) != 2048 )
throw std::runtime_error( "Cannot generate a par entry for a "
"non 2k channel right now" );
if ( data_type( ) != 4 )
throw std::runtime_error(
"Cannot generate a par entry for a non float channel" );
os << "[" << full_channel_name( ) << "]\n";
os << "ifoid = 1\n";
os << "rmid = " << ch_.dcuid() << "\n";
os << "rmid = " << ch_.dcuid( ) << "\n";
os << "dcuid = " << 16 << "\n";
os << "chnnum = " << ch_.channel_num() << "\n";
os << "datatype = " << data_type() << "\n";
os << "datarate = " << data_rate() << "\n";
os << "chnnum = " << ch_.channel_num( ) << "\n";
os << "datatype = " << data_type( ) << "\n";
os << "datarate = " << data_rate( ) << "\n";
}
virtual int data_type() const { return ch_.data_type(); };
virtual int data_rate() const { return ch_.data_rate(); };
virtual int
data_type( ) const
{
return ch_.data_type( );
};
virtual int
data_rate( ) const
{
return ch_.data_rate( );
};
};
class GPSSecondGenerator: public SimChannelGenerator
class GPSSecondGenerator : public SimChannelGenerator
{
public:
GPSSecondGenerator(const SimChannel& ch):
SimChannelGenerator(ch) {}
GPSSecondGenerator( const SimChannel& ch ) : SimChannelGenerator( ch )
{
}
std::string generator_name() const { return "gpssec"; }
std::string
generator_name( ) const
{
return "gpssec";
}
char* generate(int gps_sec, int gps_nano, char* out)
char*
generate( int gps_sec, int gps_nano, char* out )
{
int rate = data_rate() / 16;
int *out_ = reinterpret_cast<int*>(out);
for (int i = 0; i < rate; ++i)
int rate = data_rate( ) / 16;
int* out_ = reinterpret_cast< int* >( out );
for ( int i = 0; i < rate; ++i )
{
*out_ = gps_sec;
++out_;
}
return reinterpret_cast<char*>(out_);
return reinterpret_cast< char* >( out_ );
}
};
template <typename T>
class GPSSecondWithOffset: public SimChannelGenerator
template < typename T >
class GPSSecondWithOffset : public SimChannelGenerator
{
int offset_;
public:
GPSSecondWithOffset(const SimChannel& ch, int offset):
SimChannelGenerator(ch), offset_(offset) {}
GPSSecondWithOffset( const SimChannel& ch, int offset )
: SimChannelGenerator( ch ), offset_( offset )
{
}
std::string generator_name() const { return "gpssoff1p"; }
std::string
generator_name( ) const
{
return "gpssoff1p";
}
std::string other_params() const
std::string
other_params( ) const
{
std::ostringstream os;
os << "--" << offset_;
return os.str();
return os.str( );
}
char* generate(int gps_sec, int gps_nano, char* out)
char*
generate( int gps_sec, int gps_nano, char* out )
{
int rate = data_rate() / 16;
T *out_ = reinterpret_cast<T*>(out);
for (int i = 0; i < rate; ++i)
int rate = data_rate( ) / 16;
T* out_ = reinterpret_cast< T* >( out );
for ( int i = 0; i < rate; ++i )
{
*out_ = static_cast<T>(gps_sec + offset_);
*out_ = static_cast< T >( gps_sec + offset_ );
++out_;
}
return reinterpret_cast<char*>(out_);
return reinterpret_cast< char* >( out_ );
}
};
template <typename T>
class GPSMod100kSecWithOffset: public SimChannelGenerator
template < typename T >
class GPSMod100kSecWithOffset : public SimChannelGenerator
{
int offset_;
public:
GPSMod100kSecWithOffset(const SimChannel& ch, int offset):
SimChannelGenerator(ch), offset_(offset) {}
GPSMod100kSecWithOffset( const SimChannel& ch, int offset )
: SimChannelGenerator( ch ), offset_( offset )
{
}
std::string generator_name() const { return "gpssmd100koff1p"; }
std::string
generator_name( ) const
{
return "gpssmd100koff1p";
}
std::string other_params() const
std::string
other_params( ) const
{
std::ostringstream os;
os << "--" << offset_;
return os.str();
return os.str( );
}
char* generate(int gps_sec, int gps_nano, char* out)
char*
generate( int gps_sec, int gps_nano, char* out )
{
int rate = data_rate() / 16;
T *out_ = reinterpret_cast<T*>(out);
for (int i = 0; i < rate; ++i)
int rate = data_rate( ) / 16;
T* out_ = reinterpret_cast< T* >( out );
for ( int i = 0; i < rate; ++i )
{
*out_ = static_cast<T>((gps_sec%100000) + offset_);
*out_ = static_cast< T >( ( gps_sec % 100000 ) + offset_ );
++out_;
}
return reinterpret_cast<char*>(out_);
return reinterpret_cast< char* >( out_ );
}
};
template <typename T>
class GPSMod30kSecWithOffset: public SimChannelGenerator
template < typename T >
class GPSMod30kSecWithOffset : public SimChannelGenerator
{
int offset_;
public:
GPSMod30kSecWithOffset(const SimChannel& ch, int offset):
SimChannelGenerator(ch), offset_(offset) {}
GPSMod30kSecWithOffset( const SimChannel& ch, int offset )
: SimChannelGenerator( ch ), offset_( offset )
{
}
std::string generator_name() const { return "gpssmd30koff1p"; }
std::string
generator_name( ) const
{
return "gpssmd30koff1p";
}
std::string other_params() const
std::string
other_params( ) const
{
std::ostringstream os;
os << "--" << offset_;
return os.str();
return os.str( );
}
char* generate(int gps_sec, int gps_nano, char* out)
char*
generate( int gps_sec, int gps_nano, char* out )
{
int rate = data_rate() / 16;
T *out_ = reinterpret_cast<T*>(out);
for (int i = 0; i < rate; ++i)
int rate = data_rate( ) / 16;
T* out_ = reinterpret_cast< T* >( out );
for ( int i = 0; i < rate; ++i )
{
*out_ = static_cast<T>((gps_sec%30000) + offset_);
*out_ = static_cast< T >( ( gps_sec % 30000 ) + offset_ );
++out_;
}
return reinterpret_cast<char*>(out_);
return reinterpret_cast< char* >( out_ );
}
};
template <typename T>
class StaticValue: public SimChannelGenerator
template < typename T >
class StaticValue : public SimChannelGenerator
{
T value_;
public:
StaticValue(const SimChannel& ch, T value):
SimChannelGenerator(ch), value_(value) {}
StaticValue( const SimChannel& ch, T value )
: SimChannelGenerator( ch ), value_( value )
{
}
std::string generator_name() const { return "static"; }
std::string
generator_name( ) const
{
return "static";
}
std::string other_params() const
std::string
other_params( ) const
{
std::ostringstream os;
os << "--" << value_;
return os.str();
return os.str( );
}
char* generate(int gps_sec, int gps_nano, char* out)
char*
generate( int gps_sec, int gps_nano, char* out )
{
int rate = data_rate() / 16;
T *out_ = reinterpret_cast<T*>(out);
std::fill(out_, out_ + rate, value_);
return reinterpret_cast<char*>(out_ + rate);
int rate = data_rate( ) / 16;
T* out_ = reinterpret_cast< T* >( out );
std::fill( out_, out_ + rate, value_ );
return reinterpret_cast< char* >( out_ + rate );
}
};
}
} // namespace Generators
template <template<class> class GenClass, typename... Args>
template < template < class > class GenClass, typename... Args >
GeneratorPtr
create_generic_generator(int data_type, Args&&... args)
create_generic_generator( int data_type, Args&&... args )
{
switch (static_cast<daq_data_t>(data_type))
switch ( static_cast< daq_data_t >( data_type ) )
{
case _16bit_integer:
return GeneratorPtr(new GenClass<std::int16_t>(std::forward<Args>(args)...));
case _32bit_integer:
return GeneratorPtr(new GenClass<std::int32_t>(std::forward<Args>(args)...));
case _64bit_integer:
return GeneratorPtr(new GenClass<std::int64_t>(std::forward<Args>(args)...));
case _32bit_float:
return GeneratorPtr(new GenClass<float>(std::forward<Args>(args)...));
case _64bit_double:
return GeneratorPtr(new GenClass<double>(std::forward<Args>(args)...));
case _32bit_complex:
break;
case _32bit_uint:
return GeneratorPtr(new GenClass<std::uint32_t>(std::forward<Args>(args)...));
default:
break;
case _16bit_integer:
return GeneratorPtr(
new GenClass< std::int16_t >( std::forward< Args >( args )... ) );
case _32bit_integer:
return GeneratorPtr(
new GenClass< std::int32_t >( std::forward< Args >( args )... ) );
case _64bit_integer:
return GeneratorPtr(
new GenClass< std::int64_t >( std::forward< Args >( args )... ) );
case _32bit_float:
return GeneratorPtr(
new GenClass< float >( std::forward< Args >( args )... ) );
case _64bit_double:
return GeneratorPtr(
new GenClass< double >( std::forward< Args >( args )... ) );
case _32bit_complex:
break;
case _32bit_uint:
return GeneratorPtr(
new GenClass< std::uint32_t >( std::forward< Args >( args )... ) );
default:
break;
}
throw std::runtime_error("Unknown data type found, cannot create a generator");
throw std::runtime_error(
"Unknown data type found, cannot create a generator" );
}
GeneratorPtr
create_generator(const std::string& generator, const SimChannel& ch);
GeneratorPtr create_generator( const std::string& generator,
const SimChannel& ch );
GeneratorPtr
create_generator(const std::string& channel_name);
GeneratorPtr create_generator( const std::string& channel_name );
#endif //DAQD_FE_STREAM_GENERATOR_HH
#endif // DAQD_FE_STREAM_GENERATOR_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment