reduce computational complexity
This commit is contained in:
parent
79c1b19e33
commit
e952764e4f
@ -13,7 +13,7 @@
|
||||
|
||||
namespace imc
|
||||
{
|
||||
// define "magic bytes" announcing start/end of blocks and separation within
|
||||
// define "magic bytes" announcing start/end of blocks and separation of parameters within
|
||||
const unsigned char ch_bgn_ = 0x7c, ch_end_ = 0x3b, ch_sep_ = 0x2c;
|
||||
|
||||
// single parameter (in a block) is determined by offset of its first/last byte
|
||||
|
@ -1,48 +0,0 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef IMCMETA
|
||||
#define IMCMETA
|
||||
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
namespace imc
|
||||
{
|
||||
struct info
|
||||
{
|
||||
// timestamp of measurement
|
||||
std::string timestamp_;
|
||||
bool valid_;
|
||||
|
||||
// device and software
|
||||
std::string origin_;
|
||||
};
|
||||
|
||||
struct abscissa
|
||||
{
|
||||
// name of entity
|
||||
std::string name_;
|
||||
|
||||
// its unit
|
||||
std::string unit_;
|
||||
};
|
||||
|
||||
struct channel
|
||||
{
|
||||
// name of channel
|
||||
std::string name_;
|
||||
|
||||
// unit of channel's measurement entity
|
||||
std::string unit_;
|
||||
|
||||
// datatype of channel
|
||||
imc::datatype daty_;
|
||||
|
||||
// entity measurement depends on, i.e. channel's abscissa (mostly time)
|
||||
abscissa channel_xaxis_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------//
|
84
lib/imc_objects.hpp
Normal file
84
lib/imc_objects.hpp
Normal file
@ -0,0 +1,84 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#ifndef IMCOBJECTS
|
||||
#define IMCOBJECTS
|
||||
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
namespace imc
|
||||
{
|
||||
// start of group of keys (corresponds to key CK)
|
||||
struct group_keys
|
||||
{
|
||||
int version_;
|
||||
int length_;
|
||||
bool closed_; // corresponds to true = 1 and false = 0 in file
|
||||
|
||||
// get info string
|
||||
std::string get_info(int width = 20)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss<<std::setw(width)<<std::left<<"version:"<<version_<<"\n"
|
||||
<<std::setw(width)<<std::left<<"length:"<<length_<<"\n"
|
||||
<<std::setw(width)<<std::left<<"closed:"<<(closed_?"yes":"no")<<"\n";
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
// origin of data (corresponds to key NO)
|
||||
struct origin_data
|
||||
{
|
||||
bool origin_; // corresponds to true = 1 ("verrechnet") and false = 0 ("Original")
|
||||
std::string generator_;
|
||||
bool comment_;
|
||||
|
||||
// get info string
|
||||
std::string get_info(int width = 20)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss<<std::setw(width)<<std::left<<"origin:"<<(origin_?"verrechnet":"Original")<<"\n"
|
||||
<<std::setw(width)<<std::left<<"generator:"<<generator_<<"\n"
|
||||
<<std::setw(width)<<std::left<<"comment_:"<<comment_<<"\n";
|
||||
return ss.str();
|
||||
}
|
||||
};
|
||||
|
||||
struct info
|
||||
{
|
||||
// timestamp of measurement
|
||||
std::string timestamp_;
|
||||
bool valid_;
|
||||
|
||||
// device and software
|
||||
std::string origin_;
|
||||
};
|
||||
|
||||
struct abscissa
|
||||
{
|
||||
// name of entity
|
||||
std::string name_;
|
||||
|
||||
// its unit
|
||||
std::string unit_;
|
||||
};
|
||||
|
||||
struct channel
|
||||
{
|
||||
// name of channel
|
||||
std::string name_;
|
||||
|
||||
// unit of channel's measurement entity
|
||||
std::string unit_;
|
||||
|
||||
// datatype of channel
|
||||
imc::datatype daty_;
|
||||
|
||||
// entity measurement depends on, i.e. channel's abscissa (mostly time)
|
||||
abscissa channel_xaxis_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//---------------------------------------------------------------------------//
|
@ -10,7 +10,7 @@
|
||||
#include "imc_key.hpp"
|
||||
#include "imc_block.hpp"
|
||||
#include "imc_datatype.hpp"
|
||||
#include "imc_meta.hpp"
|
||||
#include "imc_objects.hpp"
|
||||
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
@ -27,6 +27,9 @@ namespace imc
|
||||
// list of imc-blocks
|
||||
std::vector<block> rawblocks_;
|
||||
|
||||
// check computational complexity for parsing blocks
|
||||
unsigned long int cplxcnt_;
|
||||
|
||||
// collect meta-information, channel definition, etc.
|
||||
imc::info imcinfo_;
|
||||
imc::channel imcchannel_;
|
||||
@ -36,17 +39,20 @@ namespace imc
|
||||
|
||||
// constructor
|
||||
raw() {};
|
||||
raw(std::string raw_file): raw_file_(raw_file) { this->parse_blocks(); };
|
||||
raw(std::string raw_file): raw_file_(raw_file) { set_file(raw_file); };
|
||||
|
||||
// provide new raw-file
|
||||
void set_file(std::string raw_file)
|
||||
{
|
||||
raw_file_ = raw_file;
|
||||
this->fill_buffer();
|
||||
this->parse_blocks();
|
||||
}
|
||||
|
||||
// list all blocks in buffer
|
||||
void parse_blocks()
|
||||
private:
|
||||
|
||||
// open file and stream data into buffer
|
||||
void fill_buffer()
|
||||
{
|
||||
// open file and put data in buffer
|
||||
try {
|
||||
@ -61,11 +67,20 @@ namespace imc
|
||||
std::string("failed to open raw-file and stream data in buffer: ") + e.what()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// parse all raw blocks in buffer
|
||||
void parse_blocks()
|
||||
{
|
||||
// reset counter to identify computational complexity
|
||||
cplxcnt_ = 0;
|
||||
|
||||
// start parsing raw-blocks in buffer
|
||||
for ( std::vector<unsigned char>::iterator it=buffer_.begin();
|
||||
it!=buffer_.end(); ++it )
|
||||
{
|
||||
cplxcnt_++;
|
||||
|
||||
// check for "magic byte"
|
||||
if ( *it == ch_bgn_ )
|
||||
{
|
||||
@ -110,6 +125,12 @@ namespace imc
|
||||
|
||||
// add block to list
|
||||
rawblocks_.push_back(blk);
|
||||
|
||||
// skip the remaining block according to its length
|
||||
if ( it-buffer_.begin()+length < buffer_.size() )
|
||||
{
|
||||
std::advance(it,length);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -146,12 +167,26 @@ namespace imc
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
// provide buffer size
|
||||
unsigned long int buffer_size()
|
||||
{
|
||||
return buffer_.size();
|
||||
}
|
||||
|
||||
// get blocks
|
||||
std::vector<imc::block>& blocks()
|
||||
{
|
||||
return rawblocks_;
|
||||
}
|
||||
|
||||
// get computational complexity
|
||||
unsigned long int& computational_complexity()
|
||||
{
|
||||
return cplxcnt_;
|
||||
}
|
||||
|
||||
// collect meta data
|
||||
void parse_meta()
|
||||
{
|
||||
|
@ -178,6 +178,9 @@ int main(int argc, char* argv[])
|
||||
// if ( blk.get_key() == std::string("CR") )
|
||||
// for ( auto prm: blk.get_parameters() ) std::cout<<prm.get_info()<<"\n";
|
||||
}
|
||||
std::cout<<"number of blocks: "<<imcraw.blocks().size()<<"\n";
|
||||
std::cout<<"computational complexity: "<<imcraw.computational_complexity()
|
||||
<<"/"<<imcraw.buffer_size()<<"\n";
|
||||
}
|
||||
|
||||
// for ( std::map<std::string,imc::key>::iterator it = imc::keys.begin();
|
||||
|
Loading…
x
Reference in New Issue
Block a user