adjusted python interface

This commit is contained in:
Mario Fink
2019-05-03 13:00:23 +02:00
parent 89dc943dce
commit 4d31dcd32d
5 changed files with 121 additions and 20 deletions

View File

@@ -279,6 +279,40 @@ void tdm_ripper::list_channels(std::ostream& gout, int width, int maxshow)
}
}
void tdm_ripper::list_groups(std::ostream& gout, int width, int maxshow)
{
gout<<std::setw(width)<<"group";
gout<<std::setw(width)<<"group id";
gout<<std::setw(width)<<"group name";
gout<<std::setw(width)<<"num channels";
gout<<"\n";
gout<<std::setfill('-')<<std::setw(4*width+1)<<"\n";
gout<<std::setfill(' ');
for ( int i = 0; i < num_groups_ && i < maxshow; i++ )
{
gout<<std::setw(width)<<i+1;
gout<<std::setw(width)<<group_id_[i];
gout<<std::setw(width)<<group_name_[i];
gout<<std::setw(width)<<num_channels_group_[i];
gout<<"\n";
}
gout<<"\n\n";
if ( num_channels_ > maxshow )
{
for ( int i = num_groups_-maxshow; i < num_channels_; i++ )
{
gout<<std::setw(width)<<i+1;
gout<<std::setw(width)<<group_id_[i];
gout<<std::setw(width)<<group_name_[i];
gout<<std::setw(width)<<num_channels_group_[i];
gout<<"\n";
}
gout<<"\n\n";
}
}
void tdm_ripper::show_structure()
{
int width = 25;
@@ -444,11 +478,13 @@ std::vector<double> tdm_ripper::get_channel(int channelid)
std::vector<double> chann = convert_channel(channel_ext_[channelid-1]);
// check if converted value is within expected range
for ( int i = 0; i < (int)chann.size(); i++ )
{
assert( chann[i] >= minmax_[channelid-1].first - 1.0e-10
&& chann[i] <= minmax_[channelid-1].second + 1.0e-10 );
}
// for ( int i = 0; i < (int)chann.size(); i++ )
// {
// if ( chann[i] < minmax_[channelid-1].first
// || chann[i] > minmax_[channelid-1].second ) std::cout<<std::setw(20)<<chann[i]<<std::setw(20)<<minmax_[channelid-1].first<<std::setw(20)<<minmax_[channelid-1].second<<"\n";
// assert( chann[i] >= minmax_[channelid-1].first - 1.0e-6
// && chann[i] <= minmax_[channelid-1].second + 1.0e-6 );
// }
return chann;
}

View File

@@ -61,6 +61,7 @@ public:
void parse_structure();
void list_channels(std::ostream& gout = std::cout, int width = 15, int maxshow = 50);
void list_groups(std::ostream& gout = std::cout, int width = 15, int maxshow = 50);
void show_structure();
@@ -148,9 +149,11 @@ public:
{
return num_groups_;
}
// get number of channels in specific group
const int& no_channels(int groupid)
{
assert( groupid > 0 && groupid <= num_channels_ );
assert( groupid > 0 && groupid <= num_groups_ );
return num_channels_group_[groupid-1];
}
@@ -162,6 +165,28 @@ public:
return channel_name_[channelid-1];
}
// obtain overall channel id from combined group and group-specific channel id
int obtain_channel_id(int groupid, int channelid)
{
assert( groupid > 0 && groupid <= num_groups_ );
assert( channelid > 0 && channelid <= num_channels_group_[groupid-1] );
// find cummulative number of channels
int numsum = 0;
for ( int i = 0; i < groupid-1; i++ )
{
numsum += num_channels_group_[i];
}
assert( (numsum + channelid) > 0 && (numsum + channelid) <= num_channels_ );
return numsum+channelid;
}
const std::string& channel_name(int groupid, int channelid)
{
return channel_name_[obtain_channel_id(groupid,channelid)-1];
}
const std::string& group_name(int groupid)
{
assert( groupid > 0 && groupid <= num_channels_ );
@@ -169,6 +194,11 @@ public:
return group_name_[groupid-1];
}
const std::string& channel_unit(int groupid, int channelid)
{
return units_[obtain_channel_id(groupid,channelid)-1];
}
void list_datatypes();
// convert array of chars to single integer or floating point double
@@ -183,7 +213,13 @@ public:
// std::vector<double> convert_channel(int byteoffset, int length, int typesize);
std::vector<double> convert_channel(int channelid);
// obtain channel from overall channel id...
std::vector<double> get_channel(int channelid);
// ...or from group id and group-specific channel id
std::vector<double> channel(int groupid, int channelid)
{
return get_channel(obtain_channel_id(groupid,channelid));
}
void print_channel(int channelid, const char* filename, int width = 15);