process channelgroups

This commit is contained in:
Mario Fink 2021-01-20 10:17:36 +01:00
parent 42aa8a897f
commit 5c2c643dfe
3 changed files with 65 additions and 11 deletions

View File

@ -152,7 +152,8 @@ struct tdm_channelgroup {
std::string name_;
std::string description_;
std::string root_;
std::vector<long int> channels_; // referenced by id
std::vector<std::string> channels_; // referenced by id
std::vector<std::string> submatrices_;
const std::string get_info(int width = 20)
{

View File

@ -65,7 +65,7 @@ void tdm_reaper::process_tdm(bool showlog)
// process elements of XML
this->process_include(showlog);
this->process_root(showlog);
this->process_channelgroups(showlog);
}
void tdm_reaper::process_include(bool showlog)
@ -147,18 +147,50 @@ void tdm_reaper::process_root(bool showlog)
tdmroot_.author_ = tdmdataroot.child_value("author");
tdmroot_.timestamp_ = tdmdataroot.child_value("datetime");
// collect group identifiers by means of regex pattern "usi[0-9]+"
std::string chnlgrps = tdmdataroot.child_value("channelgroups");
std::regex regid("(usi[0-9]+)");
std::smatch usi_match;
std::sregex_iterator pos(chnlgrps.begin(), chnlgrps.end(), regid);
std::sregex_iterator end;
for ( ; pos != end; ++pos) tdmroot_.channelgroups_.push_back(pos->str());
// std::cout<<pos->str(0)<<"\n";
// collect channelgroup identifiers associated to root
tdmroot_.channelgroups_ = this->extract_ids(tdmdataroot.child_value("channelgroups"));
if ( showlog ) std::cout<<tdmroot_.get_info()<<"\n";
}
void tdm_reaper::process_channelgroups(bool showlog)
{
// get XML node <usi:data>
pugi::xml_node tdmdata = xml_doc_.child("usi:tdm").child("usi:data");
// find all its <tdm_channelgroup> 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<std::string> 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<std::string,tdm_channelgroup>(
tdmchannelgroup.id_,tdmchannelgroup) );
if ( showlog ) std::cout<<tdmchannelgroup.get_info()<<"\n";
}
if ( showlog ) std::cout<<"number of channelgroups: "<<tdmchannelgroups_.size()<<"\n\n";
}
// pugi::xml_node xmlusiincl = xml_doc_.child("usi:tdm").child("usi:include");
// pugi::xml_node xmlusidata = xml_doc_.child("usi:tdm").child("usi:data");
// pugi::xml_node xmltdmroot = xml_doc_.child("usi:tdm").child("usi:data").child("tdm_root");

View File

@ -45,6 +45,9 @@ class tdm_reaper
// tdm root
tdm_root tdmroot_;
// tdm channelgroups
std::map<std::string,tdm_channelgroup> tdmchannelgroups_;
// // number/names/ids of channels, channelgroups and channels's assignment to groups
// int num_channels_, num_groups_;
// std::vector<std::string> channel_id_, inc_id_, units_, channel_name_;
@ -80,6 +83,24 @@ class tdm_reaper
// // binary data container
// std::vector<unsigned char> tdxbuf_;
// extract list of identifiers from e.g. "#xpointer(id("usi12") id("usi13"))"
std::vector<std::string> extract_ids(std::string idstring)
{
// collect group identifiers by means of regex pattern "usi[0-9]+"
std::regex regid("(usi[0-9]+)");
// declare match instance and regex iterator (to find ALL matches)
std::smatch usi_match;
std::sregex_iterator pos(idstring.begin(), idstring.end(), regid);
std::sregex_iterator end;
// iterate through all matches
std::vector<std::string> listofids;
for ( ; pos != end; ++pos) listofids.push_back(pos->str());
return listofids;
}
public:
// encoding
@ -102,8 +123,8 @@ public:
void process_root(bool showlog);
// process/list all channels and groups
void process_channelgroups(bool showlog);
void process_channels(bool showlog);
void process_groups(bool showlog);
// void parse_structure();
//