neglect empty groups

This commit is contained in:
Mario Fink 2019-05-03 14:42:59 +02:00
parent 4d31dcd32d
commit e7730c2d02
4 changed files with 24 additions and 17 deletions

View File

@ -1,9 +1,11 @@
#include "tdm_ripper.hpp" #include "tdm_ripper.hpp"
tdm_ripper::tdm_ripper(std::string tdmfile, std::string tdxfile): tdm_ripper::tdm_ripper(std::string tdmfile, std::string tdxfile, bool neglect_empty_groups):
tdmfile_(tdmfile), tdxfile_(tdxfile), num_channels_(0), num_groups_(0), tdmfile_(tdmfile), tdxfile_(tdxfile),
channel_id_(0), inc_id_(0), units_(0), channel_name_(0), group_id_(0), group_name_(0), neglect_empty_groups_(neglect_empty_groups), num_empty_groups_(0),
num_channels_(0), num_groups_(0), channel_id_(0), inc_id_(0), units_(0),
channel_name_(0), group_id_(0), group_name_(0),
num_channels_group_(0), channels_group_(0), channel_ext_(0), minmax_(0), num_channels_group_(0), channels_group_(0), channel_ext_(0), minmax_(0),
byteoffset_(0), length_(0), type_(0), external_id_(0) byteoffset_(0), length_(0), type_(0), external_id_(0)
{ {
@ -97,11 +99,15 @@ void tdm_ripper::parse_structure()
{ {
if ( std::string(anode.name()).compare("tdm_channelgroup") == 0 ) if ( std::string(anode.name()).compare("tdm_channelgroup") == 0 )
{ {
num_groups_++;
group_id_.push_back(anode.attribute("id").value());
group_name_.push_back(anode.child_value("name"));
int numchann = count_occ_string(anode.child_value("channels"),"id"); int numchann = count_occ_string(anode.child_value("channels"),"id");
num_channels_group_.push_back(numchann); if ( numchann > 0 || !neglect_empty_groups_ )
{
num_groups_++;
group_id_.push_back(anode.attribute("id").value());
group_name_.push_back(anode.child_value("name"));
num_channels_group_.push_back(numchann);
}
if ( numchann == 0 ) num_empty_groups_++;
} }
} }
@ -201,18 +207,15 @@ void tdm_ripper::parse_structure()
// std::string keyinit("usi23258"); // std::string keyinit("usi23258");
// std::cout<<"xml test "<<xml_double_sequence_[xml_values_[xml_local_columns_[keyinit]]]<<"\n\n"; // std::cout<<"xml test "<<xml_double_sequence_[xml_values_[xml_local_columns_[keyinit]]]<<"\n\n";
// check consistency of number of channelgroups // check consistency of number of channel-groups
int numgroups = count_occ_string(subtreedata.child("tdm_root").child_value("channelgroups"),"id"); int numgroups = count_occ_string(subtreedata.child("tdm_root").child_value("channelgroups"),"id");
if ( 0*numgroups == 0 ) assert( numgroups == num_groups_ ); assert( (neglect_empty_groups_ && numgroups == num_groups_+num_empty_groups_)
|| (!neglect_empty_groups_ && numgroups == num_groups_) );
// check consistency of number of channels // check consistency of number of channels
assert( num_channels_ == (int)channel_id_.size() assert( num_channels_ == (int)channel_id_.size()
&& num_channels_ == (int)channel_name_.size() && num_channels_ == (int)channel_name_.size()
&& num_channels_ == (int)channels_group_.size() ); && num_channels_ == (int)channels_group_.size() );
std::cout<<std::setw(25)<<std::left<<"number of channels:"<<std::setw(10)<<num_channels_<<"\n";
for ( int i = 0; i < num_groups_; i++ ) std::cout<<std::setw(25)<<std::left<<"group"<<std::setw(10)<<i+1<<std::setw(10)<<no_channels(i+1)<<"\n";
std::cout<<std::right<<"\n\n";
} }
void tdm_ripper::list_channels(std::ostream& gout, int width, int maxshow) void tdm_ripper::list_channels(std::ostream& gout, int width, int maxshow)

View File

@ -23,6 +23,10 @@ class tdm_ripper
// endianness (true = little, false = big) // endianness (true = little, false = big)
bool endianness_, machine_endianness_; bool endianness_, machine_endianness_;
// evtl. neglect groups with no actual channels
bool neglect_empty_groups_;
int num_empty_groups_;
// number/names/ids of channels, channelgroups and channels's assignment to groups // number/names/ids of channels, channelgroups and channels's assignment to groups
int num_channels_, num_groups_; int num_channels_, num_groups_;
std::vector<std::string> channel_id_, inc_id_, units_, channel_name_; std::vector<std::string> channel_id_, inc_id_, units_, channel_name_;
@ -56,7 +60,7 @@ class tdm_ripper
public: public:
tdm_ripper(std::string tdmfile, std::string tdxfile = ""); tdm_ripper(std::string tdmfile, std::string tdxfile = "", bool neglect_empty_groups = true);
void parse_structure(); void parse_structure();

View File

@ -43,8 +43,8 @@ int main(int argc, char* argv[])
// for ( auto el: channA ) std::cout<<el<<"\n"; // for ( auto el: channA ) std::cout<<el<<"\n";
// std::cout<<"\n\n"; // std::cout<<"\n\n";
for ( int i = 3; i < 10; i++ ) // for ( int i = 3; i < 10; i++ )
// for ( int i = 0; i < ripper.num_channels(); i++ ) for ( int i = 0; i < ripper.num_channels(); i++ )
// for ( int i = 11880; i < ripper.num_channels(); i++ ) // for ( int i = 11880; i < ripper.num_channels(); i++ )
{ {
ripper.print_channel(i+1,("data/channel_"+std::to_string(i+1)+"_" ripper.print_channel(i+1,("data/channel_"+std::to_string(i+1)+"_"

View File

@ -9,7 +9,7 @@ extensions = Extension(
library_dirs=["lib"], library_dirs=["lib"],
include_dirs=["lib"], include_dirs=["lib"],
language='c++', language='c++',
extra_compile_args=['-stdlib=libc++','-std=c++11'], extra_compile_args=['-stdlib=libc++','-std=c++11','-Wno-unused-variable'],
extra_link_args=['-stdlib=libc++','-std=c++11'], extra_link_args=['-stdlib=libc++','-std=c++11'],
) )