From 3b31384f67a3fb62212b5550e123ea6dbeef82cb Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Thu, 21 Jan 2021 10:47:38 +0100 Subject: [PATCH] remove old implementation tdm_ripper-dev.cpp --- lib/tdm_datamodel.hpp | 66 ++--- lib/tdm_ripper-rev.cpp | 566 ----------------------------------------- src/main.cpp | 16 +- 3 files changed, 41 insertions(+), 607 deletions(-) delete mode 100644 lib/tdm_ripper-rev.cpp diff --git a/lib/tdm_datamodel.hpp b/lib/tdm_datamodel.hpp index cc3503a..a9d6a59 100644 --- a/lib/tdm_datamodel.hpp +++ b/lib/tdm_datamodel.hpp @@ -15,39 +15,6 @@ #include #include -// -------------------------------------------------------------------------- // -// block of data - -struct block { - - std::string id_; - unsigned long int byte_offset_; - unsigned long int length_; - unsigned long int block_offset_, block_size_; - std::string value_type_; - - block () { - id_ = std::string(""); - byte_offset_ = 0; - length_ = 0; - block_offset_ = 0; - block_size_ = 0; - value_type_ = std::string(""); - } - - const std::string get_info(int width = 25) - { - std::stringstream ss; - ss< tdm_datatypes = { }; +// -------------------------------------------------------------------------- // +// block of data + +struct block { + + std::string id_; + unsigned long int byte_offset_; + unsigned long int length_; + unsigned long int block_offset_, block_size_; + std::string value_type_; + + block () { + id_ = std::string(""); + byte_offset_ = 0; + length_ = 0; + block_offset_ = 0; + block_size_ = 0; + value_type_ = std::string(""); + } + + const std::string get_info(int width = 25) + { + std::stringstream ss; + ss< tdxbuf((std::istreambuf_iterator(fin)), - (std::istreambuf_iterator())); - tdxbuf_ = tdxbuf; - - if ( !suppress_status_ ) - { - std::cout<<"number of bytes in binary file: "<("name",anode.child_value("name"))); - root_info_.insert(std::pair("description",anode.child_value("description"))); - root_info_.insert(std::pair("title",anode.child_value("title"))); - root_info_.insert(std::pair("author",anode.child_value("author"))); - } - - if ( std::string(anode.name()).compare("tdm_channelgroup") == 0 ) - { - groupcount++; - - for ( pugi::xml_node mnode: anode.child("instance_attributes").children() ) - { - // preliminiary fix for Conti-TDM files since values are one arbitrary tree level above - bool pretdmfix = ( std::string(mnode.child_value()).compare("") == 0 ) ? false : true; - - if ( pretdmfix ) - { - meta_info_.insert(std::pair(mnode.attribute("name").value(),mnode.child_value())); - } - else - { - meta_info_.insert(std::pair(mnode.attribute("name").value(),mnode.child_value("s"))); - } - } - - int numchann = count_occ_string(anode.child_value("channels"),"id"); - 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); - - // get time-stamp - pugi::xml_node insatt = anode.child("instance_attributes"); - std::pair startstop; - for ( pugi::xml_node bnode: insatt.children() ) - { - assert( std::string(bnode.name()).compare("double_attribute") == 0 ); - if ( std::string(bnode.attribute("name").value()).compare("Starttime") == 0 ) - { - startstop.first = bnode.child_value(); - } - else if ( std::string(bnode.attribute("name").value()).compare("Stoptime") == 0 ) - { - startstop.second = bnode.child_value(); - } - else - { - startstop.first = ""; - startstop.second = ""; - } - } - group_timestamp_.push_back(startstop); - } - if ( numchann == 0 ) num_empty_groups_++; - } - } - - // obtain list of xpointers and ids to assign channels - for (pugi::xml_node anode: subtreedata.children()) - { - if ( std::string(anode.name()).compare("tdm_channel") == 0 ) - { - std::string id(anode.attribute("id").value()); - std::string val = get_str_between(anode.child_value("local_columns"),"\"","\""); - xml_local_columns_.insert(std::pair(id,val)); - } - - if ( std::string(anode.name()).compare("localcolumn") == 0 ) - { - std::string id(anode.attribute("id").value()); - std::string val = get_str_between(anode.child_value("values"),"\"","\""); - xml_values_.insert(std::pair(id,val)); - } - - if ( std::string(anode.name()).compare("double_sequence") == 0 - || std::string(anode.name()).compare("long_sequence") == 0 ) - { - std::string id(anode.attribute("id").value()); - std::string val = anode.child("values").attribute("external").value(); - xml_double_sequence_.insert(std::pair(id,val)); - } - } - - if ( !suppress_status_ ) - { - std::cout<<"number of pairs in\n"; - std::cout< minmaxchan(atof(anode.child_value("minimum")), - atof(anode.child_value("maximum"))); - minmax_.push_back(minmaxchan); - - // get correct assignment of channels to byteoffset, length and datatype - std::string locolvalext; - locolvalext = xml_double_sequence_[xml_values_[xml_local_columns_[anode.attribute("id").value()]]]; - - // save external id of channel and get corresponding channel index - inc_id_.push_back(locolvalext); - int extid = 1; - for ( int i = 0; i < (int)external_id_.size(); i++ ) - { - if ( external_id_[i].compare(locolvalext) == 0 ) extid = i; - } - channel_ext_.push_back(extid); - } - } - - // std::string keyinit("usi23258"); - // std::cout<<"xml test "< 3*maxshow ) - { - for ( int i = num_channels_-maxshow; i < num_channels_; i++ ) - { - gout< 3*maxshow ) - { - for ( int i = num_groups_-maxshow; i < num_groups_; i++ ) - { - gout< bych) -{ - assert( bych.size() == sizeof(int) ); - assert( endianness_ ); - - int df = 0.0; - - uint8_t *dfcast = reinterpret_cast(&df); - - for ( int i = 0; i < (int)sizeof(int); i++ ) - { - dfcast[i] = (int)bych[i]; - } - - return df; -} - -// disassemble single integer into array of chars -std::vector tdm_ripper::convert_int(int df) -{ - assert( endianness_ ); - - std::vector bych((int)sizeof(int)); - - uint8_t *dfcast = reinterpret_cast(&df); - - for ( int i = 0; i < (int)sizeof(int); i++ ) - { - bych[i] = (int)dfcast[i]; - } - - return bych; -} - -// convert array of chars to floating point double -double tdm_ripper::convert_double(std::vector bych) -{ - assert( bych.size() == sizeof(double) ); - assert( endianness_ ); - - // check for IEEE754 floating point standard - assert( std::numeric_limits::is_iec559 ); - - double df = 0.0; - - uint8_t *dfcast = reinterpret_cast(&df); - - for ( int i = 0; i < (int)sizeof(double); i++ ) - { - dfcast[i] = (int)bych[i]; - } - - return df; -} - -std::vector tdm_ripper::convert_channel(int channelid) -{ - // obtain offset, length of channel and size of datatype - int byteoffset = byteoffset_[channelid]; - int length = length_[channelid]; - int typesize = datatypes_[type_[channelid]]/CHAR_BIT; - - // declare resulting array - std::vector chann(length); - - for ( int i = 0; i < length; i++ ) - { - std::vector cseg(tdxbuf_.begin()+byteoffset+i*typesize, - tdxbuf_.begin()+byteoffset+(i+1)*typesize); - - if ( type_[channelid].compare("eInt32Usi") == 0 ) - { - chann[i] = convert_int(cseg); - } - else if ( type_[channelid].compare("eFloat64Usi") == 0 ) - { - chann[i] = convert_double(cseg); - } - else - { - assert( false && "datatype not supported!" ); - } - } - - return chann; -} - -std::vector tdm_ripper::get_channel(int channelid) -{ - assert( channelid >= 0 && channelid < num_channels_ && "please provide valid channel id" ); - - std::vector chann = convert_channel(channel_ext_[channelid]); - - // check if converted value is within expected range - for ( int i = 0; i < (int)chann.size(); i++ ) - { - assert( chann[i] >= minmax_[channelid].first - 1.0e-6 - && chann[i] <= minmax_[channelid].second + 1.0e-6 ); - } - - return chann; -} - -void tdm_ripper::print_channel(int channelid, const char* filename, int width) -{ - assert( channelid >= 0 && channelid < num_channels_ && "please provide valid channel id" ); - - std::ofstream fout(filename); - - std::vector channdat = get_channel(channelid); - for ( auto el: channdat ) fout< chi = jack.get_channel(id); + std::string id("usi15"); + std::vector chi = jack.get_channel(id); - for ( auto el: chids ) - { - std::string chfile = std::string("channel_") +el +std::string(".csv"); - jack.print_channel(el,chfile.c_str()); - } + // for ( auto el: chids ) + // { + // std::string chfile = std::string("channel_") +el +std::string(".csv"); + // jack.print_channel(el,chfile.c_str()); + // } // print list of groups or channels to stdout // if ( listgroups ) jack.list_groups();