fixed missing id's and index range
This commit is contained in:
parent
b4a993c27f
commit
686896dd15
@ -128,7 +128,8 @@ void tdm_ripper::parse_structure()
|
|||||||
xml_values_.insert(std::pair<std::string,std::string>(id,val));
|
xml_values_.insert(std::pair<std::string,std::string>(id,val));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( std::string(anode.name()).compare("double_sequence") == 0 )
|
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 id(anode.attribute("id").value());
|
||||||
std::string val = anode.child("values").attribute("external").value();
|
std::string val = anode.child("values").attribute("external").value();
|
||||||
@ -155,7 +156,7 @@ void tdm_ripper::parse_structure()
|
|||||||
std::string groupid(anode.child_value("group"));
|
std::string groupid(anode.child_value("group"));
|
||||||
for ( int g = 0; g < num_groups_; g++ )
|
for ( int g = 0; g < num_groups_; g++ )
|
||||||
{
|
{
|
||||||
if ( groupid.find(group_id_[g]) != std::string::npos ) channels_group_.push_back(g+1);
|
if ( groupid.find(group_id_[g]) != std::string::npos ) channels_group_.push_back(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
// obtain measurement unit of channel
|
// obtain measurement unit of channel
|
||||||
@ -198,7 +199,7 @@ void tdm_ripper::parse_structure()
|
|||||||
int extid = 1;
|
int extid = 1;
|
||||||
for ( int i = 0; i < (int)external_id_.size(); i++ )
|
for ( int i = 0; i < (int)external_id_.size(); i++ )
|
||||||
{
|
{
|
||||||
if ( external_id_[i].compare(locolvalext) == 0 ) extid = i+1;
|
if ( external_id_[i].compare(locolvalext) == 0 ) extid = i;
|
||||||
}
|
}
|
||||||
channel_ext_.push_back(extid);
|
channel_ext_.push_back(extid);
|
||||||
}
|
}
|
||||||
@ -244,16 +245,16 @@ void tdm_ripper::list_channels(std::ostream& gout, int width, int maxshow)
|
|||||||
gout<<std::setw(width)<<channel_id_[i];
|
gout<<std::setw(width)<<channel_id_[i];
|
||||||
gout<<std::setw(width)<<inc_id_[i];
|
gout<<std::setw(width)<<inc_id_[i];
|
||||||
gout<<std::setw(2*width)<<channel_name_[i];
|
gout<<std::setw(2*width)<<channel_name_[i];
|
||||||
gout<<std::setw(width)<<byteoffset_[channel_ext_[i]-1];
|
gout<<std::setw(width)<<byteoffset_[channel_ext_[i]];
|
||||||
gout<<std::setw(width)<<length_[channel_ext_[i]-1];
|
gout<<std::setw(width)<<length_[channel_ext_[i]];
|
||||||
gout<<std::setw(width)<<type_[channel_ext_[i]-1];
|
gout<<std::setw(width)<<type_[channel_ext_[i]];
|
||||||
gout<<std::setw(width)<<units_[i];
|
gout<<std::setw(width)<<units_[i];
|
||||||
gout<<std::setw(width)<<minmax_[i].first;
|
gout<<std::setw(width)<<minmax_[i].first;
|
||||||
gout<<std::setw(width)<<minmax_[i].second;
|
gout<<std::setw(width)<<minmax_[i].second;
|
||||||
gout<<std::setw(width)<<channels_group_[i];
|
gout<<std::setw(width)<<channels_group_[i];
|
||||||
gout<<std::setw(width)<<group_id_[channels_group_[i]-1];
|
gout<<std::setw(width)<<group_id_[channels_group_[i]];
|
||||||
gout<<std::setw(width)<<group_name_[channels_group_[i]-1];
|
gout<<std::setw(width)<<group_name_[channels_group_[i]];
|
||||||
gout<<std::setw(width)<<num_channels_group_[channels_group_[i]-1];
|
gout<<std::setw(width)<<num_channels_group_[channels_group_[i]];
|
||||||
gout<<"\n";
|
gout<<"\n";
|
||||||
}
|
}
|
||||||
gout<<"\n\n";
|
gout<<"\n\n";
|
||||||
@ -266,16 +267,16 @@ void tdm_ripper::list_channels(std::ostream& gout, int width, int maxshow)
|
|||||||
gout<<std::setw(width)<<channel_id_[i];
|
gout<<std::setw(width)<<channel_id_[i];
|
||||||
gout<<std::setw(width)<<inc_id_[i];
|
gout<<std::setw(width)<<inc_id_[i];
|
||||||
gout<<std::setw(2*width)<<channel_name_[i];
|
gout<<std::setw(2*width)<<channel_name_[i];
|
||||||
gout<<std::setw(width)<<byteoffset_[channel_ext_[i]-1];
|
gout<<std::setw(width)<<byteoffset_[channel_ext_[i]];
|
||||||
gout<<std::setw(width)<<length_[channel_ext_[i]-1];
|
gout<<std::setw(width)<<length_[channel_ext_[i]];
|
||||||
gout<<std::setw(width)<<type_[channel_ext_[i]-1];
|
gout<<std::setw(width)<<type_[channel_ext_[i]];
|
||||||
gout<<std::setw(width)<<units_[i];
|
gout<<std::setw(width)<<units_[i];
|
||||||
gout<<std::setw(width)<<minmax_[i].first;
|
gout<<std::setw(width)<<minmax_[i].first;
|
||||||
gout<<std::setw(width)<<minmax_[i].second;
|
gout<<std::setw(width)<<minmax_[i].second;
|
||||||
gout<<std::setw(width)<<channels_group_[i];
|
gout<<std::setw(width)<<channels_group_[i];
|
||||||
gout<<std::setw(width)<<group_id_[channels_group_[i]-1];
|
gout<<std::setw(width)<<group_id_[channels_group_[i]];
|
||||||
gout<<std::setw(width)<<group_name_[channels_group_[i]-1];
|
gout<<std::setw(width)<<group_name_[channels_group_[i]];
|
||||||
gout<<std::setw(width)<<num_channels_group_[channels_group_[i]-1];
|
gout<<std::setw(width)<<num_channels_group_[channels_group_[i]];
|
||||||
gout<<"\n";
|
gout<<"\n";
|
||||||
}
|
}
|
||||||
gout<<"\n\n";
|
gout<<"\n\n";
|
||||||
@ -445,9 +446,9 @@ double tdm_ripper::convert_double(std::vector<unsigned char> bych)
|
|||||||
std::vector<double> tdm_ripper::convert_channel(int channelid)
|
std::vector<double> tdm_ripper::convert_channel(int channelid)
|
||||||
{
|
{
|
||||||
// obtain offset, length of channel and size of datatype
|
// obtain offset, length of channel and size of datatype
|
||||||
int byteoffset = byteoffset_[channelid-1];
|
int byteoffset = byteoffset_[channelid];
|
||||||
int length = length_[channelid-1];
|
int length = length_[channelid];
|
||||||
int typesize = datatypes_[type_[channelid-1]]/CHAR_BIT;
|
int typesize = datatypes_[type_[channelid]]/CHAR_BIT;
|
||||||
|
|
||||||
// declare resulting array
|
// declare resulting array
|
||||||
std::vector<double> chann(length);
|
std::vector<double> chann(length);
|
||||||
@ -457,11 +458,11 @@ std::vector<double> tdm_ripper::convert_channel(int channelid)
|
|||||||
std::vector<unsigned char> cseg(tdxbuf_.begin()+byteoffset+i*typesize,
|
std::vector<unsigned char> cseg(tdxbuf_.begin()+byteoffset+i*typesize,
|
||||||
tdxbuf_.begin()+byteoffset+(i+1)*typesize);
|
tdxbuf_.begin()+byteoffset+(i+1)*typesize);
|
||||||
|
|
||||||
if ( type_[channelid-1].compare("eInt32Usi") == 0 )
|
if ( type_[channelid].compare("eInt32Usi") == 0 )
|
||||||
{
|
{
|
||||||
chann[i] = convert_int(cseg);
|
chann[i] = convert_int(cseg);
|
||||||
}
|
}
|
||||||
else if ( type_[channelid-1].compare("eFloat64Usi") == 0 )
|
else if ( type_[channelid].compare("eFloat64Usi") == 0 )
|
||||||
{
|
{
|
||||||
chann[i] = convert_double(cseg);
|
chann[i] = convert_double(cseg);
|
||||||
}
|
}
|
||||||
@ -476,9 +477,9 @@ std::vector<double> tdm_ripper::convert_channel(int channelid)
|
|||||||
|
|
||||||
std::vector<double> tdm_ripper::get_channel(int channelid)
|
std::vector<double> tdm_ripper::get_channel(int channelid)
|
||||||
{
|
{
|
||||||
assert( channelid > 0 && channelid <= num_channels_ && "please provide valid channel id" );
|
assert( channelid >= 0 && channelid < num_channels_ && "please provide valid channel id" );
|
||||||
|
|
||||||
std::vector<double> chann = convert_channel(channel_ext_[channelid-1]);
|
std::vector<double> chann = convert_channel(channel_ext_[channelid]);
|
||||||
|
|
||||||
// check if converted value is within expected range
|
// check if converted value is within expected range
|
||||||
// for ( int i = 0; i < (int)chann.size(); i++ )
|
// for ( int i = 0; i < (int)chann.size(); i++ )
|
||||||
@ -494,7 +495,7 @@ std::vector<double> tdm_ripper::get_channel(int channelid)
|
|||||||
|
|
||||||
void tdm_ripper::print_channel(int channelid, const char* filename, int width)
|
void tdm_ripper::print_channel(int channelid, const char* filename, int width)
|
||||||
{
|
{
|
||||||
assert( channelid > 0 && channelid <= num_channels_ && "please provide valid channel id" );
|
assert( channelid >= 0 && channelid < num_channels_ && "please provide valid channel id" );
|
||||||
|
|
||||||
std::ofstream fout(filename);
|
std::ofstream fout(filename);
|
||||||
|
|
||||||
|
@ -144,6 +144,21 @@ public:
|
|||||||
fout.close();
|
fout.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_extid(const char* filename, int width = 20)
|
||||||
|
{
|
||||||
|
std::ofstream fout(filename);
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
for ( auto extid: channel_ext_ )
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
fout<<std::setw(width)<<count;
|
||||||
|
fout<<std::setw(width)<<extid;
|
||||||
|
fout<<"\n";
|
||||||
|
}
|
||||||
|
fout.close();
|
||||||
|
}
|
||||||
|
|
||||||
// provide number of channels and group
|
// provide number of channels and group
|
||||||
const int& num_channels()
|
const int& num_channels()
|
||||||
{
|
{
|
||||||
@ -157,27 +172,27 @@ public:
|
|||||||
// get number of channels in specific group
|
// get number of channels in specific group
|
||||||
const int& no_channels(int groupid)
|
const int& no_channels(int groupid)
|
||||||
{
|
{
|
||||||
assert( groupid > 0 && groupid <= num_groups_ );
|
assert( groupid >= 0 && groupid < num_groups_ );
|
||||||
|
|
||||||
return num_channels_group_[groupid-1];
|
return num_channels_group_[groupid];
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& channel_name(int channelid)
|
const std::string& channel_name(int channelid)
|
||||||
{
|
{
|
||||||
assert( channelid > 0 && channelid <= num_channels_ );
|
assert( channelid >= 0 && channelid < num_channels_ );
|
||||||
|
|
||||||
return channel_name_[channelid-1];
|
return channel_name_[channelid];
|
||||||
}
|
}
|
||||||
|
|
||||||
// obtain overall channel id from combined group and group-specific channel id
|
// obtain overall channel id from combined group and group-specific channel id
|
||||||
int obtain_channel_id(int groupid, int channelid)
|
int obtain_channel_id(int groupid, int channelid)
|
||||||
{
|
{
|
||||||
assert( groupid > 0 && groupid <= num_groups_ );
|
assert( groupid >= 0 && groupid < num_groups_ );
|
||||||
assert( channelid > 0 && channelid <= num_channels_group_[groupid-1] );
|
assert( channelid >= 0 && channelid < num_channels_group_[groupid] );
|
||||||
|
|
||||||
// find cummulative number of channels
|
// find cummulative number of channels
|
||||||
int numsum = 0;
|
int numsum = 0;
|
||||||
for ( int i = 0; i < groupid-1; i++ )
|
for ( int i = 0; i < groupid; i++ )
|
||||||
{
|
{
|
||||||
numsum += num_channels_group_[i];
|
numsum += num_channels_group_[i];
|
||||||
}
|
}
|
||||||
@ -188,31 +203,31 @@ public:
|
|||||||
|
|
||||||
const std::string& channel_name(int groupid, int channelid)
|
const std::string& channel_name(int groupid, int channelid)
|
||||||
{
|
{
|
||||||
return channel_name_[obtain_channel_id(groupid,channelid)-1];
|
return channel_name_[obtain_channel_id(groupid,channelid)];
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& group_name(int groupid)
|
const std::string& group_name(int groupid)
|
||||||
{
|
{
|
||||||
assert( groupid > 0 && groupid <= num_channels_ );
|
assert( groupid >= 0 && groupid < num_groups_ );
|
||||||
|
|
||||||
return group_name_[groupid-1];
|
return group_name_[groupid];
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& channel_unit(int groupid, int channelid)
|
const std::string& channel_unit(int groupid, int channelid)
|
||||||
{
|
{
|
||||||
return units_[obtain_channel_id(groupid,channelid)-1];
|
return units_[obtain_channel_id(groupid,channelid)];
|
||||||
}
|
}
|
||||||
|
|
||||||
int channel_exists(int groupid, std::string channel_name)
|
int channel_exists(int groupid, std::string channel_name)
|
||||||
{
|
{
|
||||||
assert( groupid > 0 && groupid <= num_channels_ );
|
assert( groupid >= 0 && groupid < num_groups_ );
|
||||||
|
|
||||||
int channelid = 0;
|
int channelid = -1;
|
||||||
for ( int i = 0; i < num_channels_group_[groupid-1]; i++)
|
for ( int i = 0; i < num_channels_group_[groupid]; i++)
|
||||||
{
|
{
|
||||||
if ( channel_name_[obtain_channel_id(groupid,i+1)-1].compare(channel_name) == 0 )
|
if ( channel_name_[obtain_channel_id(groupid,i)].compare(channel_name) == 0 )
|
||||||
{
|
{
|
||||||
channelid = i+1;
|
channelid = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return channelid;
|
return channelid;
|
||||||
@ -240,6 +255,20 @@ public:
|
|||||||
return get_channel(obtain_channel_id(groupid,channelid));
|
return get_channel(obtain_channel_id(groupid,channelid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int channel_length(int groupid, int channelid)
|
||||||
|
{
|
||||||
|
return length_[channel_ext_[obtain_channel_id(groupid,channelid)]];
|
||||||
|
}
|
||||||
|
|
||||||
|
double get_min(int groupid, int channelid)
|
||||||
|
{
|
||||||
|
return minmax_[obtain_channel_id(groupid,channelid)].first;
|
||||||
|
}
|
||||||
|
double get_max(int groupid, int channelid)
|
||||||
|
{
|
||||||
|
return minmax_[obtain_channel_id(groupid,channelid)].second;
|
||||||
|
}
|
||||||
|
|
||||||
void print_channel(int channelid, const char* filename, int width = 15);
|
void print_channel(int channelid, const char* filename, int width = 15);
|
||||||
|
|
||||||
// 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
|
||||||
|
25
main.cpp
25
main.cpp
@ -13,20 +13,21 @@ int main(int argc, char* argv[])
|
|||||||
// ripper.list_datatypes();
|
// ripper.list_datatypes();
|
||||||
// ripper.show_structure();
|
// ripper.show_structure();
|
||||||
|
|
||||||
// ripper.print_hash_local("data/hash_table_xml_local.dat");
|
ripper.print_hash_local("data/hash_table_xml_local.dat");
|
||||||
// ripper.print_hash_values("data/hash_table_xml_value.dat");
|
ripper.print_hash_values("data/hash_table_xml_value.dat");
|
||||||
// ripper.print_hash_double("data/hash_table_xml_double.dat");
|
ripper.print_hash_double("data/hash_table_xml_double.dat");
|
||||||
|
ripper.print_extid("data/channel_ext_id.dat");
|
||||||
ripper.list_channels();
|
|
||||||
std::ofstream fout("data/list_of_channels.dat");
|
|
||||||
ripper.list_channels(fout);
|
|
||||||
fout.close();
|
|
||||||
|
|
||||||
ripper.list_groups();
|
ripper.list_groups();
|
||||||
std::ofstream gout("data/list_of_groups.dat");
|
std::ofstream gout("data/list_of_groups.dat");
|
||||||
ripper.list_groups(gout);
|
ripper.list_groups(gout);
|
||||||
gout.close();
|
gout.close();
|
||||||
|
|
||||||
|
ripper.list_channels();
|
||||||
|
std::ofstream fout("data/list_of_channels.dat");
|
||||||
|
ripper.list_channels(fout);
|
||||||
|
fout.close();
|
||||||
|
|
||||||
std::cout<<"number of channels "<<ripper.num_channels()<<"\n";
|
std::cout<<"number of channels "<<ripper.num_channels()<<"\n";
|
||||||
std::cout<<"number of groups "<<ripper.num_groups()<<"\n\n";
|
std::cout<<"number of groups "<<ripper.num_groups()<<"\n\n";
|
||||||
|
|
||||||
@ -39,16 +40,12 @@ int main(int argc, char* argv[])
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// std::vector<double> channA = ripper.get_channel(1);
|
|
||||||
// for ( auto el: channA ) std::cout<<el<<"\n";
|
|
||||||
// std::cout<<"\n\n";
|
|
||||||
|
|
||||||
// for ( int i = 3; i < 10; i++ )
|
// for ( int i = 3; i < 10; i++ )
|
||||||
for ( int i = 0; i < ripper.num_channels(); i++ )
|
for ( int i = 0; i < ripper.num_channels(); i++ )
|
||||||
// for ( int i = 11880; i < ripper.num_channels(); i++ )
|
// for ( int i = 11880; i < ripper.num_channels(); i++ )
|
||||||
{
|
{
|
||||||
ripper.print_channel(i+1,("data/channel_"+std::to_string(i+1)+"_"
|
ripper.print_channel(i,("data/channel_"+std::to_string(i+1)+"_"
|
||||||
+ripper.channel_name(i+1)+".dat").c_str());
|
+ripper.channel_name(i)+".dat").c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -24,7 +24,7 @@ cdef class pytdmripper:
|
|||||||
|
|
||||||
def no_channels(self, int groupid):
|
def no_channels(self, int groupid):
|
||||||
assert (groupid >= 0 and groupid < self.cripp.num_groups()), "index of group must be in [0,n-1]"
|
assert (groupid >= 0 and groupid < self.cripp.num_groups()), "index of group must be in [0,n-1]"
|
||||||
return self.cripp.no_channels(groupid+1)
|
return self.cripp.no_channels(groupid)
|
||||||
|
|
||||||
def num_groups(self):
|
def num_groups(self):
|
||||||
return self.cripp.num_groups()
|
return self.cripp.num_groups()
|
||||||
@ -33,19 +33,28 @@ cdef class pytdmripper:
|
|||||||
return self.cripp.num_groups()
|
return self.cripp.num_groups()
|
||||||
|
|
||||||
def channel_name(self,int groupid,int channelid):
|
def channel_name(self,int groupid,int channelid):
|
||||||
return self.cripp.channel_name(groupid+1,channelid+1).decode('utf-8')
|
return self.cripp.channel_name(groupid,channelid).decode('utf-8')
|
||||||
|
|
||||||
def channel_unit(self,int groupid,int channelid):
|
def channel_unit(self,int groupid,int channelid):
|
||||||
return (self.cripp.channel_unit(groupid+1,channelid+1))
|
return (self.cripp.channel_unit(groupid,channelid))
|
||||||
|
|
||||||
def channel_exists(self,int groupid, string channelname):
|
def channel_exists(self,int groupid, string channelname):
|
||||||
return self.cripp.channel_exists(groupid+1,channelname)
|
return self.cripp.channel_exists(groupid,channelname)
|
||||||
|
|
||||||
def get_channel(self, int channelid):
|
def get_channel(self, int channelid):
|
||||||
return np.asarray(self.cripp.get_channel(channelid))
|
return np.asarray(self.cripp.get_channel(channelid))
|
||||||
|
|
||||||
def channel(self,int groupid,int channelid):
|
def channel(self,int groupid,int channelid):
|
||||||
return self.cripp.channel(groupid+1,channelid+1)
|
return self.cripp.channel(groupid,channelid)
|
||||||
|
|
||||||
|
def channel_length(self,int groupid, int channelid):
|
||||||
|
return self.cripp.channel_length(groupid,channelid)
|
||||||
|
|
||||||
|
def get_min(self,int groupid, int channelid):
|
||||||
|
return self.cripp.get_min(groupid,channelid)
|
||||||
|
|
||||||
|
def get_max(self,int groupid, int channelid):
|
||||||
|
return self.cripp.get_max(groupid,channelid)
|
||||||
|
|
||||||
def print_channel(self, int channelid, const char* filename):
|
def print_channel(self, int channelid, const char* filename):
|
||||||
self.cripp.print_channel(channelid,filename)
|
self.cripp.print_channel(channelid,filename)
|
||||||
|
@ -21,6 +21,9 @@ cdef extern from "tdm_ripper.hpp":
|
|||||||
string channel_unit(int,int)
|
string channel_unit(int,int)
|
||||||
int channel_exists(int,string)
|
int channel_exists(int,string)
|
||||||
vector[double] get_channel(int)
|
vector[double] get_channel(int)
|
||||||
|
int channel_length(int,int)
|
||||||
|
double get_min(int,int)
|
||||||
|
double get_max(int,int)
|
||||||
vector[double] channel(int,int)
|
vector[double] channel(int,int)
|
||||||
void print_channel(int,const char*)
|
void print_channel(int,const char*)
|
||||||
# dummy method for compatibility
|
# dummy method for compatibility
|
||||||
|
Loading…
x
Reference in New Issue
Block a user