// -------------------------------------------------------------------------- // #include "tdm_reaper.hpp" // -------------------------------------------------------------------------- // tdm_reaper::tdm_reaper() { } tdm_reaper::tdm_reaper(std::string tdmfile, std::string tdxfile, bool showlog): tdmfile_(tdmfile), tdxfile_(tdxfile) { // start processing tdm data model this->process_tdm(showlog); } void tdm_reaper::submit_files(std::string tdmfile, std::string tdxfile, bool showlog) { // save files tdmfile_ = tdmfile; tdxfile_ = tdxfile; // start processing tdm data model this->process_tdm(showlog); } void tdm_reaper::process_tdm(bool showlog) { // check both tdm, tdx files std::filesystem::path ptdm(tdmfile_), ptdx(tdxfile_); if ( !std::filesystem::exists(ptdm) ) { throw std::runtime_error(std::string("*.tdm file ") + tdmfile_ + " does not exist!"); } if ( !std::filesystem::exists(ptdx) ) { throw std::runtime_error(std::string("*.tdx file ") + tdxfile_ + " does not exist!"); } // set up xml-parser and load tdm-file try { // load XML document from stream std::ifstream fin(tdmfile_.c_str()); xml_result_ = xml_doc_.load(fin); fin.close(); // xml_result_ = xml_doc_.load_file(tdmfile_.c_str()); if ( showlog ) { std::cout<<"\nloading "<process_include(showlog); this->process_root(showlog); this->process_channelgroups(showlog); this->process_channels(showlog); this->process_submatrices(showlog); this->process_localcolumns(showlog); } void tdm_reaper::process_include(bool showlog) { // get XML node pugi::xml_node tdmincl = xml_doc_.child("usi:tdm").child("usi:include"); // check endianness std::string endianness(tdmincl.child("file").attribute("byteOrder").value()); endianness_ = endianness.compare("littleEndian") == 0 ? true : false; // check referenced .tdx file std::string urltdx(tdmincl.child("file").attribute("url").value()); // obtain machine's endianness int num = 1; machine_endianness_ = ( *(char*)&num == 1 ); if ( machine_endianness_ != endianness_ ) throw std::runtime_error("endianness mismatch"); if ( showlog ) { std::cout<<"\n"; std::cout<<"endianness: "<<(endianness_?"little":"big")<<"\n" <<"machine endianness: "<<(machine_endianness_?"little":"big")<<"\n" <<"url: "<(tdxblock.id_,tdxblock)); if ( showlog ) std::cout<extract_ids(tdmdataroot.child_value("channelgroups")); if ( showlog ) std::cout< pugi::xml_node tdmdata = xml_doc_.child("usi:tdm").child("usi:data"); // find all its elements for ( pugi::xml_node group = tdmdata.child("tdm_channelgroup"); group; group = group.next_sibling("tdm_channelgroup") ) { // declare new group tdm_channelgroup tdmchannelgroup; // extract properties tdmchannelgroup.id_ = group.attribute("id").value(); tdmchannelgroup.name_ = group.child_value("name"); tdmchannelgroup.description_ = group.child_value("description"); std::vector gr = this->extract_ids(group.child_value("root")); if ( gr.size() == 1 ) { tdmchannelgroup.root_ = gr.at(0); } else { throw std::runtime_error("tdm_channelgroup with out/multiple root id(s)"); } tdmchannelgroup.channels_ = this->extract_ids(group.child_value("channels")); tdmchannelgroup.submatrices_ = this->extract_ids(group.child_value("submatrices")); // add channelgroup to map tdmchannelgroups_.insert( std::pair( tdmchannelgroup.id_,tdmchannelgroup) ); if ( showlog ) std::cout< pugi::xml_node tdmdata = xml_doc_.child("usi:tdm").child("usi:data"); // find all its elements for ( pugi::xml_node channel = tdmdata.child("tdm_channel"); channel; channel = channel.next_sibling("tdm_channel") ) { // declare new channel tdm_channel tdmchannel; // extract properties tdmchannel.id_ = channel.attribute("id").value(); tdmchannel.name_ = channel.child_value("name"); tdmchannel.description_ = channel.child_value("description"); tdmchannel.unit_string_ = channel.child_value("unit_string"); tdmchannel.datatype_ = channel.child_value("datatype"); std::string chmin = channel.child_value("minimum"); chmin = chmin.empty() ? std::string("0.0") : chmin; tdmchannel.minimum_ = std::stod(chmin); std::string chmax = channel.child_value("maximum"); chmax = chmax.empty() ? std::string("0.0") : chmax; tdmchannel.maximum_ = std::stod(chmax); std::vector cg = this->extract_ids(channel.child_value("group")); if ( cg.size() == 1 ) { tdmchannel.group_ = cg.at(0); } else { throw std::runtime_error("tdm_channel with out/multiple group id(s)"); } tdmchannel.local_columns_ = this->extract_ids(channel.child_value("local_columns")); // add channel to map tdmchannels_.insert( std::pair(tdmchannel.id_,tdmchannel) ); if ( showlog ) std::cout< pugi::xml_node tdmdata = xml_doc_.child("usi:tdm").child("usi:data"); // find all its elements for ( pugi::xml_node subm = tdmdata.child("submatrix"); subm; subm = subm.next_sibling("submatrix") ) { // declare new submatrix submatrix submat; // extract properties submat.id_ = subm.attribute("id").value(); submat.name_ = subm.child_value("name"); submat.description_ = subm.child_value("description"); std::vector mid = this->extract_ids(subm.child_value("measurement")); if ( mid.size() == 1 ) { submat.measurement_ = mid.at(0); } else { throw std::runtime_error("submatrix with out/multiple measurement id(s)"); } submat.local_columns_ = this->extract_ids(subm.child_value("local_columns")); std::string numrows = subm.child_value("number_of_rows"); numrows = numrows.empty() ? std::string("0") : numrows; submat.number_of_rows_ = std::stoul(numrows); // add submatrix to map submatrices_.insert( std::pair(submat.id_,submat) ); if ( showlog ) std::cout< pugi::xml_node tdmdata = xml_doc_.child("usi:tdm").child("usi:data"); // find all its elements for ( pugi::xml_node loccol = tdmdata.child("localcolumn"); loccol; loccol = loccol.next_sibling("localcolumn") ) { // declare new localcolumn localcolumn locc; // extract properties locc.id_ = loccol.attribute("id").value(); locc.name_ = loccol.child_value("name"); locc.description_ = loccol.child_value("description"); std::vector mq = this->extract_ids(loccol.child_value("measurement_quantity")); if ( mq.size() == 1 ) { locc.measurement_quantity_ = mq.at(0); } else { throw std::runtime_error("localcolumn with out/multiple measurement quantity id(s)"); } std::vector sm = this->extract_ids(loccol.child_value("submatrix")); if ( sm.size() == 1 ) { locc.submatrix_ = sm.at(0); } else { throw std::runtime_error("localcolumn with out/multiple submatrix id(s)"); } std::string lcmin = loccol.child_value("minimum"); lcmin = lcmin.empty() ? std::string("0.0") : lcmin; locc.minimum_ = std::stod(lcmin); std::string lcmax = loccol.child_value("maximum"); lcmax = lcmax.empty() ? std::string("0.0") : lcmax; locc.maximum_ = std::stod(lcmax); locc.sequence_representation_ = loccol.child_value("sequence_representation"); // TODO // .... loccal.child_value("generation_parameters"); std::vector vl = this->extract_ids(loccol.child_value("values")); if ( vl.size() == 1 ) { locc.values_ = vl.at(0); } else { throw std::runtime_error("localcolumn with out/multiple values id(s)"); } // add localcolumn to map localcolumns_.insert( std::pair(locc.id_,locc) ); if ( showlog ) std::cout< tdm_reaper::get_channel(std::string &id) { // declare vector of channel data std::vector chn; // check for existence of required channel id (=key) if ( tdmchannels_.count(id) == 1 ) { tdm_channel chn = tdmchannels_.at(id); std::cout<