// -------------------------------------------------------------------------- // #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); } 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 without root id"); } 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"); tdmchannel.minimum_ = std::stod(channel.child_value("minimum")); tdmchannel.maximum_ = std::stod(channel.child_value("maximum")); 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 without group id"); } 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<