tdm data model: process tdm_root finished
This commit is contained in:
parent
c0f5346f58
commit
48ec660d2d
@ -4,8 +4,29 @@
|
|||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
tdm_reaper::tdm_reaper()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
tdm_reaper::tdm_reaper(std::string tdmfile, std::string tdxfile, bool showlog):
|
tdm_reaper::tdm_reaper(std::string tdmfile, std::string tdxfile, bool showlog):
|
||||||
tdmfile_(tdmfile), tdxfile_(tdxfile)
|
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
|
// check both tdm, tdx files
|
||||||
std::filesystem::path ptdm(tdmfile_), ptdx(tdxfile_);
|
std::filesystem::path ptdm(tdmfile_), ptdx(tdxfile_);
|
||||||
@ -43,6 +64,7 @@ tdm_reaper::tdm_reaper(std::string tdmfile, std::string tdxfile, bool showlog):
|
|||||||
|
|
||||||
// process elements of XML
|
// process elements of XML
|
||||||
this->process_include(showlog);
|
this->process_include(showlog);
|
||||||
|
this->process_root(showlog);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +77,9 @@ void tdm_reaper::process_include(bool showlog)
|
|||||||
std::string endianness(tdmincl.child("file").attribute("byteOrder").value());
|
std::string endianness(tdmincl.child("file").attribute("byteOrder").value());
|
||||||
endianness_ = endianness.compare("littleEndian") == 0 ? true : false;
|
endianness_ = endianness.compare("littleEndian") == 0 ? true : false;
|
||||||
|
|
||||||
|
// check referenced .tdx file
|
||||||
|
std::string urltdx(tdmincl.child("file").attribute("url").value());
|
||||||
|
|
||||||
// obtain machine's endianess
|
// obtain machine's endianess
|
||||||
int num = 1;
|
int num = 1;
|
||||||
machine_endianness_ = ( *(char*)&num == 1 );
|
machine_endianness_ = ( *(char*)&num == 1 );
|
||||||
@ -64,12 +89,10 @@ void tdm_reaper::process_include(bool showlog)
|
|||||||
{
|
{
|
||||||
std::cout<<"\n";
|
std::cout<<"\n";
|
||||||
std::cout<<"endianess: "<<(endianness_?"little":"big")<<"\n"
|
std::cout<<"endianess: "<<(endianness_?"little":"big")<<"\n"
|
||||||
<<"machine endianness: "<<(machine_endianness_?"little":"big")<<"\n\n";
|
<<"machine endianness: "<<(machine_endianness_?"little":"big")<<"\n"
|
||||||
|
<<"url: "<<urltdx<<"\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for existence of attributes before using
|
|
||||||
// pugi::xml_attribute attr;
|
|
||||||
|
|
||||||
// list block of massdata
|
// list block of massdata
|
||||||
for (pugi::xml_node anode: tdmincl.child("file").children())
|
for (pugi::xml_node anode: tdmincl.child("file").children())
|
||||||
{
|
{
|
||||||
@ -107,27 +130,52 @@ void tdm_reaper::process_include(bool showlog)
|
|||||||
if ( showlog ) std::cout<<tdxblock.get_info()<<"\n";
|
if ( showlog ) std::cout<<tdxblock.get_info()<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( showlog ) std::cout<<"number of blocks: "<<tdx_blocks_.size()<<"\n";
|
if ( showlog ) std::cout<<"number of blocks: "<<tdx_blocks_.size()<<"\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tdm_reaper::process_root(bool showlog)
|
||||||
|
{
|
||||||
|
// get XML node
|
||||||
|
pugi::xml_node tdmdataroot = xml_doc_.child("usi:tdm").child("usi:data")
|
||||||
|
.child("tdm_root");
|
||||||
|
|
||||||
|
// extract properties
|
||||||
|
tdmroot_.id_ = tdmdataroot.attribute("id").value();
|
||||||
|
tdmroot_.name_ = tdmdataroot.child_value("name");
|
||||||
|
tdmroot_.description_ = tdmdataroot.child_value("description");
|
||||||
|
tdmroot_.title_ = tdmdataroot.child_value("title");
|
||||||
|
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";
|
||||||
|
|
||||||
|
if ( showlog ) std::cout<<tdmroot_.get_info()<<"\n";
|
||||||
|
}
|
||||||
|
|
||||||
// pugi::xml_node xmlusiincl = xml_doc_.child("usi:tdm").child("usi:include");
|
// 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 xmlusidata = xml_doc_.child("usi:tdm").child("usi:data");
|
||||||
// pugi::xml_node xmltdmroot = xml_doc_.child("usi:tdm").child("usi:data").child("tdm_root");
|
// pugi::xml_node xmltdmroot = xml_doc_.child("usi:tdm").child("usi:data").child("tdm_root");
|
||||||
|
|
||||||
void tdm_reaper::print_channel(int idx, char const* name, int width)
|
// void tdm_reaper::print_channel(int idx, char const* name, int width)
|
||||||
{
|
// {
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void tdm_reaper::list_groups(std::ostream& out, int g, int c)
|
// void tdm_reaper::list_groups(std::ostream& out, int g, int c)
|
||||||
{
|
// {
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
void tdm_reaper::list_channels(std::ostream& out, int g, int c)
|
// void tdm_reaper::list_channels(std::ostream& out, int g, int c)
|
||||||
{
|
// {
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
#include "pugixml.hpp"
|
#include "pugixml.hpp"
|
||||||
#include "tdm_datamodel.hpp"
|
#include "tdm_datamodel.hpp"
|
||||||
@ -44,331 +45,345 @@ class tdm_reaper
|
|||||||
// tdm root
|
// tdm root
|
||||||
tdm_root tdmroot_;
|
tdm_root tdmroot_;
|
||||||
|
|
||||||
// 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_;
|
||||||
std::vector<std::string> group_id_, group_name_;
|
// std::vector<std::string> group_id_, group_name_;
|
||||||
std::vector<std::pair<std::string,std::string>> group_timestamp_;
|
// std::vector<std::pair<std::string,std::string>> group_timestamp_;
|
||||||
std::vector<int> num_channels_group_;
|
// std::vector<int> num_channels_group_;
|
||||||
std::vector<int> channels_group_;
|
// std::vector<int> channels_group_;
|
||||||
std::vector<int> channel_ext_;
|
// std::vector<int> channel_ext_;
|
||||||
|
//
|
||||||
// neglect empty groups
|
// // neglect empty groups
|
||||||
bool neglect_empty_groups_;
|
// bool neglect_empty_groups_;
|
||||||
int num_empty_groups_;
|
// int num_empty_groups_;
|
||||||
|
//
|
||||||
// minimum/maximum value in particular channel (is provided in .tdm file as float)
|
// // minimum/maximum value in particular channel (is provided in .tdm file as float)
|
||||||
std::vector<std::pair<double,double>> minmax_;
|
// std::vector<std::pair<double,double>> minmax_;
|
||||||
|
//
|
||||||
// use xpointers and ids to assign channels to byteoffsets
|
// // use xpointers and ids to assign channels to byteoffsets
|
||||||
std::map<std::string,std::string> xml_local_columns_, xml_values_, xml_double_sequence_;
|
// std::map<std::string,std::string> xml_local_columns_, xml_values_, xml_double_sequence_;
|
||||||
|
//
|
||||||
// byteoffset, length and datatype of channels
|
// // byteoffset, length and datatype of channels
|
||||||
std::vector<int> byteoffset_;
|
// std::vector<int> byteoffset_;
|
||||||
std::vector<int> length_;
|
// std::vector<int> length_;
|
||||||
std::vector<std::string> type_;
|
// std::vector<std::string> type_;
|
||||||
std::vector<std::string> external_id_;
|
// std::vector<std::string> external_id_;
|
||||||
|
//
|
||||||
// NI datatypes ( )
|
// // NI datatypes ( )
|
||||||
std::map<std::string, int> datatypes_;
|
// std::map<std::string, int> datatypes_;
|
||||||
|
//
|
||||||
// .tdm-file eventually contains some meta information (about measurement)
|
// // .tdm-file eventually contains some meta information (about measurement)
|
||||||
std::map<std::string,std::string> root_info_;
|
// std::map<std::string,std::string> root_info_;
|
||||||
std::map<std::string,std::string> meta_info_;
|
// std::map<std::string,std::string> meta_info_;
|
||||||
|
//
|
||||||
// binary data container
|
// // binary data container
|
||||||
std::vector<unsigned char> tdxbuf_;
|
// std::vector<unsigned char> tdxbuf_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// decoding
|
|
||||||
tdm_reaper(std::string tdmfile, std::string tdxfile = std::string(""), bool showlog = false);
|
|
||||||
|
|
||||||
// encoding
|
// encoding
|
||||||
tdm_reaper(std::vector<std::string> csvfile);
|
tdm_reaper(std::vector<std::string> csvfile);
|
||||||
|
|
||||||
|
// decoding
|
||||||
|
tdm_reaper();
|
||||||
|
tdm_reaper(std::string tdmfile, std::string tdxfile = std::string(""), bool showlog = false);
|
||||||
|
|
||||||
|
// provide (tdm,tdx) files
|
||||||
|
void submit_files(std::string tdmfile, std::string tdxfile = std::string(""), bool showlog = false);
|
||||||
|
|
||||||
|
// process TDM data model in tdm file
|
||||||
|
void process_tdm(bool showlog);
|
||||||
|
|
||||||
// process <usi:include> element
|
// process <usi:include> element
|
||||||
void process_include(bool showlog);
|
void process_include(bool showlog);
|
||||||
|
|
||||||
void parse_structure();
|
// extract tdm_root
|
||||||
|
void process_root(bool showlog);
|
||||||
|
|
||||||
void list_channels(std::ostream& gout = std::cout, int width = 15, int maxshow = 50);
|
// process/list all channels and groups
|
||||||
void list_groups(std::ostream& gout = std::cout, int width = 15, int maxshow = 50);
|
void process_channels(bool showlog);
|
||||||
|
void process_groups(bool showlog);
|
||||||
|
|
||||||
void show_structure();
|
// void parse_structure();
|
||||||
|
//
|
||||||
// count number of occurences of substring in string
|
// void list_channels(std::ostream& gout = std::cout, int width = 15, int maxshow = 50);
|
||||||
int count_occ_string(std::string s, std::string sub)
|
// void list_groups(std::ostream& gout = std::cout, int width = 15, int maxshow = 50);
|
||||||
{
|
//
|
||||||
int num_occs = 0;
|
// void show_structure();
|
||||||
std::string::size_type pos = 0;
|
//
|
||||||
|
// // count number of occurences of substring in string
|
||||||
while ( ( pos = s.find(sub,pos) ) != std::string::npos )
|
// int count_occ_string(std::string s, std::string sub)
|
||||||
{
|
// {
|
||||||
num_occs++;
|
// int num_occs = 0;
|
||||||
pos += sub.length();
|
// std::string::size_type pos = 0;
|
||||||
}
|
//
|
||||||
|
// while ( ( pos = s.find(sub,pos) ) != std::string::npos )
|
||||||
return num_occs;
|
// {
|
||||||
}
|
// num_occs++;
|
||||||
|
// pos += sub.length();
|
||||||
// obtain substring of 'entirestr' in between starting and stopping delimiter
|
// }
|
||||||
std::string get_str_between(std::string entirestr, std::string startlim, std::string stoplim)
|
//
|
||||||
{
|
// return num_occs;
|
||||||
std::size_t apos = entirestr.find(startlim);
|
// }
|
||||||
std::size_t bpos = entirestr.find_last_of(stoplim);
|
//
|
||||||
assert( apos != std::string::npos && bpos != std::string::npos );
|
// // obtain substring of 'entirestr' in between starting and stopping delimiter
|
||||||
return entirestr.substr(apos+startlim.length(),bpos-(apos+startlim.length()));
|
// std::string get_str_between(std::string entirestr, std::string startlim, std::string stoplim)
|
||||||
}
|
// {
|
||||||
|
// std::size_t apos = entirestr.find(startlim);
|
||||||
void print_hash_local(const char* filename, int width = 20)
|
// std::size_t bpos = entirestr.find_last_of(stoplim);
|
||||||
{
|
// assert( apos != std::string::npos && bpos != std::string::npos );
|
||||||
std::ofstream fout(filename);
|
// return entirestr.substr(apos+startlim.length(),bpos-(apos+startlim.length()));
|
||||||
|
// }
|
||||||
std::map<std::string,std::string>::iterator it;
|
//
|
||||||
int count = 0;
|
// void print_hash_local(const char* filename, int width = 20)
|
||||||
for ( it = xml_local_columns_.begin(); it != xml_local_columns_.end(); it++ )
|
// {
|
||||||
{
|
// std::ofstream fout(filename);
|
||||||
count++;
|
//
|
||||||
fout<<std::setw(width)<<count;
|
// std::map<std::string,std::string>::iterator it;
|
||||||
fout<<std::setw(width)<<it->first;
|
// int count = 0;
|
||||||
fout<<std::setw(width)<<it->second;
|
// for ( it = xml_local_columns_.begin(); it != xml_local_columns_.end(); it++ )
|
||||||
fout<<"\n";
|
// {
|
||||||
}
|
// count++;
|
||||||
fout.close();
|
// fout<<std::setw(width)<<count;
|
||||||
}
|
// fout<<std::setw(width)<<it->first;
|
||||||
|
// fout<<std::setw(width)<<it->second;
|
||||||
void print_hash_values(const char* filename, int width = 20)
|
// fout<<"\n";
|
||||||
{
|
// }
|
||||||
std::ofstream fout(filename);
|
// fout.close();
|
||||||
|
// }
|
||||||
std::map<std::string,std::string>::iterator it;
|
//
|
||||||
int count = 0;
|
// void print_hash_values(const char* filename, int width = 20)
|
||||||
for ( it = xml_values_.begin(); it != xml_values_.end(); it++ )
|
// {
|
||||||
{
|
// std::ofstream fout(filename);
|
||||||
count++;
|
//
|
||||||
fout<<std::setw(width)<<count;
|
// std::map<std::string,std::string>::iterator it;
|
||||||
fout<<std::setw(width)<<it->first;
|
// int count = 0;
|
||||||
fout<<std::setw(width)<<it->second;
|
// for ( it = xml_values_.begin(); it != xml_values_.end(); it++ )
|
||||||
fout<<"\n";
|
// {
|
||||||
}
|
// count++;
|
||||||
fout.close();
|
// fout<<std::setw(width)<<count;
|
||||||
}
|
// fout<<std::setw(width)<<it->first;
|
||||||
|
// fout<<std::setw(width)<<it->second;
|
||||||
void print_hash_double(const char* filename, int width = 20)
|
// fout<<"\n";
|
||||||
{
|
// }
|
||||||
std::ofstream fout(filename);
|
// fout.close();
|
||||||
|
// }
|
||||||
std::map<std::string,std::string>::iterator it;
|
//
|
||||||
int count = 0;
|
// void print_hash_double(const char* filename, int width = 20)
|
||||||
for ( it = xml_double_sequence_.begin(); it != xml_double_sequence_.end(); it++ )
|
// {
|
||||||
{
|
// std::ofstream fout(filename);
|
||||||
count++;
|
//
|
||||||
fout<<std::setw(width)<<count;
|
// std::map<std::string,std::string>::iterator it;
|
||||||
fout<<std::setw(width)<<it->first;
|
// int count = 0;
|
||||||
fout<<std::setw(width)<<it->second;
|
// for ( it = xml_double_sequence_.begin(); it != xml_double_sequence_.end(); it++ )
|
||||||
fout<<"\n";
|
// {
|
||||||
}
|
// count++;
|
||||||
fout.close();
|
// fout<<std::setw(width)<<count;
|
||||||
}
|
// fout<<std::setw(width)<<it->first;
|
||||||
|
// fout<<std::setw(width)<<it->second;
|
||||||
void print_extid(const char* filename, int width = 20)
|
// fout<<"\n";
|
||||||
{
|
// }
|
||||||
std::ofstream fout(filename);
|
// fout.close();
|
||||||
|
// }
|
||||||
int count = 0;
|
//
|
||||||
for ( auto extid: channel_ext_ )
|
// void print_extid(const char* filename, int width = 20)
|
||||||
{
|
// {
|
||||||
count++;
|
// std::ofstream fout(filename);
|
||||||
fout<<std::setw(width)<<count;
|
//
|
||||||
fout<<std::setw(width)<<extid;
|
// int count = 0;
|
||||||
fout<<"\n";
|
// for ( auto extid: channel_ext_ )
|
||||||
}
|
// {
|
||||||
fout.close();
|
// count++;
|
||||||
}
|
// fout<<std::setw(width)<<count;
|
||||||
|
// fout<<std::setw(width)<<extid;
|
||||||
// provide number of channels and group
|
// fout<<"\n";
|
||||||
const int& num_channels()
|
// }
|
||||||
{
|
// fout.close();
|
||||||
return num_channels_;
|
// }
|
||||||
}
|
//
|
||||||
const int& num_groups()
|
// // provide number of channels and group
|
||||||
{
|
// const int& num_channels()
|
||||||
return num_groups_;
|
// {
|
||||||
}
|
// return num_channels_;
|
||||||
|
// }
|
||||||
// get number of channels in specific group
|
// const int& num_groups()
|
||||||
const int& no_channels(int groupid)
|
// {
|
||||||
{
|
// return num_groups_;
|
||||||
assert( groupid >= 0 && groupid < num_groups_ );
|
// }
|
||||||
|
//
|
||||||
return num_channels_group_[groupid];
|
// // get number of channels in specific group
|
||||||
}
|
// const int& no_channels(int groupid)
|
||||||
|
// {
|
||||||
const std::string& channel_name(int channelid)
|
// assert( groupid >= 0 && groupid < num_groups_ );
|
||||||
{
|
//
|
||||||
assert( channelid >= 0 && channelid < num_channels_ );
|
// return num_channels_group_[groupid];
|
||||||
|
// }
|
||||||
return channel_name_[channelid];
|
//
|
||||||
}
|
// const std::string& channel_name(int channelid)
|
||||||
|
// {
|
||||||
// obtain overall channel id from combined group and group-specific channel id
|
// assert( channelid >= 0 && channelid < num_channels_ );
|
||||||
int obtain_channel_id(int groupid, int channelid)
|
//
|
||||||
{
|
// return channel_name_[channelid];
|
||||||
assert( groupid >= 0 && groupid < num_groups_ );
|
// }
|
||||||
assert( channelid >= 0 && channelid < num_channels_group_[groupid] );
|
//
|
||||||
|
// // obtain overall channel id from combined group and group-specific channel id
|
||||||
// find cummulative number of channels
|
// int obtain_channel_id(int groupid, int channelid)
|
||||||
int numsum = 0;
|
// {
|
||||||
for ( int i = 0; i < groupid; i++ )
|
// assert( groupid >= 0 && groupid < num_groups_ );
|
||||||
{
|
// assert( channelid >= 0 && channelid < num_channels_group_[groupid] );
|
||||||
numsum += num_channels_group_[i];
|
//
|
||||||
}
|
// // find cummulative number of channels
|
||||||
assert( (numsum + channelid) >= 0 );
|
// int numsum = 0;
|
||||||
assert( (numsum + channelid) <= num_channels_ );
|
// for ( int i = 0; i < groupid; i++ )
|
||||||
|
// {
|
||||||
return numsum+channelid;
|
// numsum += num_channels_group_[i];
|
||||||
}
|
// }
|
||||||
|
// assert( (numsum + channelid) >= 0 );
|
||||||
const std::string& channel_name(int groupid, int channelid)
|
// assert( (numsum + channelid) <= num_channels_ );
|
||||||
{
|
//
|
||||||
return channel_name_[obtain_channel_id(groupid,channelid)];
|
// return numsum+channelid;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
const std::string& group_name(int groupid)
|
// const std::string& channel_name(int groupid, int channelid)
|
||||||
{
|
// {
|
||||||
assert( groupid >= 0 && groupid < num_groups_ );
|
// return channel_name_[obtain_channel_id(groupid,channelid)];
|
||||||
|
// }
|
||||||
return group_name_[groupid];
|
//
|
||||||
}
|
// const std::string& group_name(int groupid)
|
||||||
|
// {
|
||||||
const std::string& channel_unit(int groupid, int channelid)
|
// assert( groupid >= 0 && groupid < num_groups_ );
|
||||||
{
|
//
|
||||||
return units_[obtain_channel_id(groupid,channelid)];
|
// return group_name_[groupid];
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
int channel_exists(int groupid, std::string channel_name)
|
// const std::string& channel_unit(int groupid, int channelid)
|
||||||
{
|
// {
|
||||||
assert( groupid >= 0 && groupid < num_groups_ );
|
// return units_[obtain_channel_id(groupid,channelid)];
|
||||||
|
// }
|
||||||
int channelid = -1;
|
//
|
||||||
for ( int i = 0; i < num_channels_group_[groupid]; i++)
|
// int channel_exists(int groupid, std::string channel_name)
|
||||||
{
|
// {
|
||||||
if ( comparestrings(channel_name_[obtain_channel_id(groupid,i)],channel_name) )
|
// assert( groupid >= 0 && groupid < num_groups_ );
|
||||||
{
|
//
|
||||||
channelid = i;
|
// int channelid = -1;
|
||||||
}
|
// for ( int i = 0; i < num_channels_group_[groupid]; i++)
|
||||||
}
|
// {
|
||||||
return channelid;
|
// if ( comparestrings(channel_name_[obtain_channel_id(groupid,i)],channel_name) )
|
||||||
}
|
// {
|
||||||
|
// channelid = i;
|
||||||
bool comparestrings(std::string s1, std::string s2, bool case_sensitive = false)
|
// }
|
||||||
{
|
// }
|
||||||
if ( case_sensitive )
|
// return channelid;
|
||||||
{
|
// }
|
||||||
return ( s1.compare(s2) == 0 );
|
//
|
||||||
}
|
// bool comparestrings(std::string s1, std::string s2, bool case_sensitive = false)
|
||||||
else
|
// {
|
||||||
{
|
// if ( case_sensitive )
|
||||||
std::transform( s1.begin(), s1.end(), s1.begin(), ::tolower);
|
// {
|
||||||
std::transform( s2.begin(), s2.end(), s2.begin(), ::tolower);
|
// return ( s1.compare(s2) == 0 );
|
||||||
return ( s1.compare(s2) == 0 );
|
// }
|
||||||
}
|
// else
|
||||||
}
|
// {
|
||||||
|
// std::transform( s1.begin(), s1.end(), s1.begin(), ::tolower);
|
||||||
// get time-stamp of channel-group in .tdm file given in unix format
|
// std::transform( s2.begin(), s2.end(), s2.begin(), ::tolower);
|
||||||
static std::string unix_timestamp(std::string unixts)
|
// return ( s1.compare(s2) == 0 );
|
||||||
{
|
// }
|
||||||
// average year of Gregorian calender
|
// }
|
||||||
const double avgdaysofyear = 365.0 + 1./4 - 1./100 + 1./400
|
//
|
||||||
- 8./24561; // gauge timestamp according to DIADEM result
|
// // get time-stamp of channel-group in .tdm file given in unix format
|
||||||
|
// static std::string unix_timestamp(std::string unixts)
|
||||||
// convert string to long int = number of seconds since 0000/01/01 00:00
|
// {
|
||||||
long int ts = atol(unixts.c_str());
|
// // average year of Gregorian calender
|
||||||
assert( ts >= 0 );
|
// const double avgdaysofyear = 365.0 + 1./4 - 1./100 + 1./400
|
||||||
|
// - 8./24561; // gauge timestamp according to DIADEM result
|
||||||
// use STL to convert timestamp (epoch usually starts on 01.01.1970)
|
//
|
||||||
std::time_t tstime = ts - 1970*avgdaysofyear*86400;
|
// // convert string to long int = number of seconds since 0000/01/01 00:00
|
||||||
|
// long int ts = atol(unixts.c_str());
|
||||||
// get rid of linebreak character and return the result
|
// assert( ts >= 0 );
|
||||||
return strtok(std::ctime(&tstime),"\n");
|
//
|
||||||
}
|
// // use STL to convert timestamp (epoch usually starts on 01.01.1970)
|
||||||
|
// std::time_t tstime = ts - 1970*avgdaysofyear*86400;
|
||||||
std::string time_stamp(int groupid, bool startstop = true)
|
//
|
||||||
{
|
// // get rid of linebreak character and return the result
|
||||||
assert( groupid >= 0 && groupid < num_groups_ );
|
// return strtok(std::ctime(&tstime),"\n");
|
||||||
|
// }
|
||||||
return startstop ? unix_timestamp(group_timestamp_[groupid].first)
|
//
|
||||||
: unix_timestamp(group_timestamp_[groupid].second);
|
// std::string time_stamp(int groupid, bool startstop = true)
|
||||||
}
|
// {
|
||||||
|
// assert( groupid >= 0 && groupid < num_groups_ );
|
||||||
void list_datatypes();
|
//
|
||||||
|
// return startstop ? unix_timestamp(group_timestamp_[groupid].first)
|
||||||
// convert array of chars to single integer or floating point double
|
// : unix_timestamp(group_timestamp_[groupid].second);
|
||||||
int convert_int(std::vector<unsigned char> bych);
|
// }
|
||||||
double convert_double(std::vector<unsigned char> bych);
|
//
|
||||||
|
// void list_datatypes();
|
||||||
// disassemble single integer or double into array of chars
|
//
|
||||||
std::vector<unsigned char> convert_int(int number);
|
// // convert array of chars to single integer or floating point double
|
||||||
std::vector<unsigned char> convert_double(double number);
|
// int convert_int(std::vector<unsigned char> bych);
|
||||||
|
// double convert_double(std::vector<unsigned char> bych);
|
||||||
// convert entire channel, i.e. expert of .tdx binary file
|
//
|
||||||
// std::vector<double> convert_channel(int byteoffset, int length, int typesize);
|
// // disassemble single integer or double into array of chars
|
||||||
std::vector<double> convert_channel(int channelid);
|
// std::vector<unsigned char> convert_int(int number);
|
||||||
|
// std::vector<unsigned char> convert_double(double number);
|
||||||
// obtain channel from overall channel id...
|
//
|
||||||
std::vector<double> get_channel(int channelid);
|
// // convert entire channel, i.e. expert of .tdx binary file
|
||||||
// ...or from group id and group-specific channel id
|
// // std::vector<double> convert_channel(int byteoffset, int length, int typesize);
|
||||||
std::vector<double> channel(int groupid, int channelid)
|
// std::vector<double> convert_channel(int channelid);
|
||||||
{
|
//
|
||||||
return get_channel(obtain_channel_id(groupid,channelid));
|
// // obtain channel from overall channel id...
|
||||||
}
|
// std::vector<double> get_channel(int channelid);
|
||||||
|
// // ...or from group id and group-specific channel id
|
||||||
int channel_length(int groupid, int channelid)
|
// std::vector<double> channel(int groupid, int channelid)
|
||||||
{
|
// {
|
||||||
return length_[channel_ext_[obtain_channel_id(groupid,channelid)]];
|
// return get_channel(obtain_channel_id(groupid,channelid));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
double get_min(int groupid, int channelid)
|
// int channel_length(int groupid, int channelid)
|
||||||
{
|
// {
|
||||||
return minmax_[obtain_channel_id(groupid,channelid)].first;
|
// return length_[channel_ext_[obtain_channel_id(groupid,channelid)]];
|
||||||
}
|
// }
|
||||||
double get_max(int groupid, int channelid)
|
//
|
||||||
{
|
// double get_min(int groupid, int channelid)
|
||||||
return minmax_[obtain_channel_id(groupid,channelid)].second;
|
// {
|
||||||
}
|
// return minmax_[obtain_channel_id(groupid,channelid)].first;
|
||||||
|
// }
|
||||||
void print_channel(int channelid, const char* filename, int width = 15);
|
// double get_max(int groupid, int channelid)
|
||||||
|
// {
|
||||||
// obtain any meta information about .tdm-file if available
|
// return minmax_[obtain_channel_id(groupid,channelid)].second;
|
||||||
std::string get_meta(std::string attribute_name)
|
// }
|
||||||
{
|
//
|
||||||
// check if key "attribute_name" actually exits
|
// void print_channel(int channelid, const char* filename, int width = 15);
|
||||||
std::map<std::string,std::string>::iterator positer = meta_info_.find(attribute_name);
|
//
|
||||||
bool ispresent = ( positer == meta_info_.end() ) ? false : true;
|
// // obtain any meta information about .tdm-file if available
|
||||||
|
// std::string get_meta(std::string attribute_name)
|
||||||
return ispresent ? meta_info_[attribute_name] : "key does not exist";
|
// {
|
||||||
}
|
// // check if key "attribute_name" actually exits
|
||||||
|
// std::map<std::string,std::string>::iterator positer = meta_info_.find(attribute_name);
|
||||||
// prepare meta information file including all available meta-data
|
// bool ispresent = ( positer == meta_info_.end() ) ? false : true;
|
||||||
void print_meta(const char* filename, std::string sep = ",")
|
//
|
||||||
{
|
// return ispresent ? meta_info_[attribute_name] : "key does not exist";
|
||||||
// open file
|
// }
|
||||||
std::ofstream fout(filename);
|
//
|
||||||
|
// // prepare meta information file including all available meta-data
|
||||||
for ( const auto& it : root_info_ )
|
// void print_meta(const char* filename, std::string sep = ",")
|
||||||
{
|
// {
|
||||||
fout<<it.first<<sep<<it.second<<"\n";
|
// // open file
|
||||||
}
|
// std::ofstream fout(filename);
|
||||||
fout<<sep<<"\n";
|
//
|
||||||
for ( const auto& it : meta_info_ )
|
// for ( const auto& it : root_info_ )
|
||||||
{
|
// {
|
||||||
fout<<it.first<<sep<<it.second<<"\n";
|
// fout<<it.first<<sep<<it.second<<"\n";
|
||||||
}
|
// }
|
||||||
|
// fout<<sep<<"\n";
|
||||||
// close down file
|
// for ( const auto& it : meta_info_ )
|
||||||
fout.close();
|
// {
|
||||||
}
|
// fout<<it.first<<sep<<it.second<<"\n";
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // close down file
|
||||||
|
// fout.close();
|
||||||
|
// }
|
||||||
|
|
||||||
// TODO add elements/methods to build .tdm and write .tdx files for your own data
|
// TODO add elements/methods to build .tdm and write .tdx files for your own data
|
||||||
// by constructing xml document tree and write data to binary .tdx
|
// by constructing xml document tree and write data to binary .tdx
|
||||||
|
@ -175,7 +175,12 @@ int main(int argc, char* argv[])
|
|||||||
// bool listchannels = cfgopts.count("listchannels") == 1 ? true : false;
|
// bool listchannels = cfgopts.count("listchannels") == 1 ? true : false;
|
||||||
|
|
||||||
// declare and initialize tdm_ripper instance
|
// declare and initialize tdm_ripper instance
|
||||||
tdm_reaper jack(cfgopts.at("tdm"),cfgopts.at("tdx"),true);
|
tdm_reaper jack;
|
||||||
|
try {
|
||||||
|
jack.submit_files(cfgopts.at("tdm"),cfgopts.at("tdx"),true);
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
throw std::runtime_error("failed to load and parse tdm/tdx files");
|
||||||
|
}
|
||||||
|
|
||||||
// print list of groups or channels to stdout
|
// print list of groups or channels to stdout
|
||||||
// if ( listgroups ) jack.list_groups();
|
// if ( listgroups ) jack.list_groups();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user