gauge timestamp and use optional .tdx path in cython
This commit is contained in:
parent
964cf461a7
commit
161541f4c6
@ -6,8 +6,9 @@ tdmpath = b"samples/SineData.tdm"
|
||||
tdxpath = b"samples/SineData.tdx"
|
||||
|
||||
# create instance of ripper class
|
||||
RP = tdm_ripper.pytdmripper(tdmpath)
|
||||
RP = tdm_ripper.pytdmripper(b"/Users/mariofink/git/Conti_HBS/data_science/python/features/tdm_tmp_slow/75_1/Messung.tdm")
|
||||
# RP = tdm_ripper.pytdmripper(tdmpath)
|
||||
RP = tdm_ripper.pytdmripper(tdmpath,tdxpath)
|
||||
# RP = tdm_ripper.pytdmripper(b"/Users/mariofink/git/Conti_HBS/data_science/python/features/tdm_tmp_slow/75_1/Messung.tdm")
|
||||
|
||||
# provide overview of available channels
|
||||
RP.show_channels()
|
||||
@ -19,7 +20,7 @@ for i in range(0,RP.num_groups()):
|
||||
print(str(i+1).rjust(10)+str(RP.no_channels(i)).rjust(10))
|
||||
|
||||
# print particular channel to file
|
||||
# RP.print_channel(1,b"SineData_extract.dat")
|
||||
RP.print_channel(1,b"SineData_extract.dat")
|
||||
|
||||
# extract channel and return it to numpy array
|
||||
# channels = RP.get_channel(1)
|
||||
|
@ -61,6 +61,10 @@ tdm_ripper::tdm_ripper(std::string tdmfile, std::string tdxfile, bool neglect_em
|
||||
|
||||
// open .tdx and stream all binary data into vector
|
||||
std::ifstream fin(tdxfile_.c_str(),std::ifstream::binary);
|
||||
assert( fin.good() && "failed to open .tdx-file" );
|
||||
if ( !fin.good() ) std::cout<<"failed to open .tdx-file\n\n";
|
||||
// assert( errno == 0 );
|
||||
// std::cout<<"error code "<<strerror(errno)<<"\n\n";
|
||||
std::vector<unsigned char> tdxbuf((std::istreambuf_iterator<char>(fin)),
|
||||
(std::istreambuf_iterator<char>()));
|
||||
tdxbuf_ = tdxbuf;
|
||||
@ -123,7 +127,8 @@ void tdm_ripper::parse_structure()
|
||||
}
|
||||
else
|
||||
{
|
||||
assert ( false && "unexpected attribute name" );
|
||||
startstop.first = "";
|
||||
startstop.second = "";
|
||||
}
|
||||
}
|
||||
group_timestamp_.push_back(startstop);
|
||||
@ -306,14 +311,17 @@ void tdm_ripper::list_channels(std::ostream& gout, int width, int maxshow)
|
||||
|
||||
void tdm_ripper::list_groups(std::ostream& gout, int width, int maxshow)
|
||||
{
|
||||
// if present, show timestamps
|
||||
bool showts = ( group_timestamp_[0].first.compare("") != 0 );
|
||||
|
||||
gout<<std::setw(width)<<"group";
|
||||
gout<<std::setw(width)<<"group id";
|
||||
gout<<std::setw(width)<<"group name";
|
||||
gout<<std::setw(width)<<"num channels";
|
||||
gout<<std::setw(2*width)<<"start time";
|
||||
gout<<std::setw(2*width)<<"stop time";
|
||||
if ( showts ) gout<<std::setw(2*width)<<"start time";
|
||||
if ( showts ) gout<<std::setw(2*width)<<"stop time";
|
||||
gout<<"\n";
|
||||
gout<<std::setfill('-')<<std::setw(8*width+1)<<"\n";
|
||||
gout<<std::setfill('-')<<(showts?std::setw(8*width+1):std::setw(4*width+1))<<"\n";
|
||||
gout<<std::setfill(' ');
|
||||
|
||||
for ( int i = 0; i < num_groups_ && i < maxshow; i++ )
|
||||
@ -322,8 +330,8 @@ void tdm_ripper::list_groups(std::ostream& gout, int width, int maxshow)
|
||||
gout<<std::setw(width)<<group_id_[i];
|
||||
gout<<std::setw(width)<<group_name_[i];
|
||||
gout<<std::setw(width)<<num_channels_group_[i];
|
||||
gout<<std::setw(2*width)<<time_stamp(i,true);
|
||||
gout<<std::setw(2*width)<<time_stamp(i,false);
|
||||
if ( showts ) gout<<std::setw(2*width)<<time_stamp(i,true);
|
||||
if ( showts ) gout<<std::setw(2*width)<<time_stamp(i,false);
|
||||
gout<<"\n";
|
||||
}
|
||||
gout<<"\n\n";
|
||||
@ -336,8 +344,8 @@ void tdm_ripper::list_groups(std::ostream& gout, int width, int maxshow)
|
||||
gout<<std::setw(width)<<group_id_[i];
|
||||
gout<<std::setw(width)<<group_name_[i];
|
||||
gout<<std::setw(width)<<num_channels_group_[i];
|
||||
gout<<std::setw(2*width)<<time_stamp(i,true);
|
||||
gout<<std::setw(2*width)<<time_stamp(i,false);
|
||||
if ( showts ) gout<<std::setw(2*width)<<time_stamp(i,true);
|
||||
if ( showts ) gout<<std::setw(2*width)<<time_stamp(i,false);
|
||||
gout<<"\n";
|
||||
}
|
||||
gout<<"\n\n";
|
||||
|
@ -249,14 +249,15 @@ public:
|
||||
}
|
||||
|
||||
// evtl. get group time_stamp of .tdm file given in unix format
|
||||
std::string unix_timestamp(std::string unixts)
|
||||
static std::string unix_timestamp(std::string unixts)
|
||||
{
|
||||
// average year of Gregorian calender
|
||||
const double avgdaysofyear = 365 + 1./4 - 1./100 + 1./400;
|
||||
const double avgdaysofyear = 365.0 + 1./4 - 1./100 + 1./400
|
||||
- 8./24561; // gauge timestamp according to DIADEM result
|
||||
|
||||
// convert string to long int = number of second since 0000/01/01 00:00
|
||||
long int ts = atol(unixts.c_str());
|
||||
assert( ts > 0 );
|
||||
assert( ts >= 0 );
|
||||
|
||||
// use STL to convert timestamp (epoch usually starts from 01.01.1970)
|
||||
std::time_t tstime = ts - 1970*avgdaysofyear*86400;
|
||||
|
5
main.cpp
5
main.cpp
@ -28,6 +28,11 @@ int main(int argc, char* argv[])
|
||||
ripper.list_channels(fout);
|
||||
fout.close();
|
||||
|
||||
// long int nsa = 6.3636349745e10; // expected result: 22.07.2016, 19:49:05
|
||||
// long int nsb = 6.3636350456e10;
|
||||
// std::string ts = std::to_string(nsa);
|
||||
// std::cout<<ripper.unix_timestamp(ts)<<"\n";
|
||||
|
||||
std::cout<<"number of channels "<<ripper.num_channels()<<"\n";
|
||||
std::cout<<"number of groups "<<ripper.num_groups()<<"\n\n";
|
||||
|
||||
|
@ -7,8 +7,8 @@ cdef class pytdmripper:
|
||||
# pointer to C++ instance (since there's no nullary constructor)
|
||||
cdef tdm_ripper *cripp
|
||||
|
||||
def __cinit__(self, string tdmfile):
|
||||
self.cripp = new tdm_ripper(tdmfile)
|
||||
def __cinit__(self, string tdmfile, string tdxfile = b""):
|
||||
self.cripp = new tdm_ripper(tdmfile,tdxfile)
|
||||
|
||||
def __dealloc__(self):
|
||||
del self.cripp
|
||||
|
@ -11,7 +11,7 @@ cdef extern from "tdm_ripper.cpp":
|
||||
|
||||
cdef extern from "tdm_ripper.hpp":
|
||||
cdef cppclass tdm_ripper:
|
||||
tdm_ripper(string) except +
|
||||
tdm_ripper(string,string) except +
|
||||
void list_channels()
|
||||
void list_groups()
|
||||
int num_channels()
|
||||
|
Loading…
x
Reference in New Issue
Block a user