imc_raw + imc_channels: channel extraction from blocks and environment
This commit is contained in:
parent
1596ca15b5
commit
acd55194a5
@ -4,6 +4,7 @@
|
|||||||
#define IMCCHANNEL
|
#define IMCCHANNEL
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include "imc_datatype.hpp"
|
||||||
|
|
||||||
//---------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------//
|
||||||
|
|
||||||
@ -59,25 +60,113 @@ namespace imc
|
|||||||
<<std::setw(width)<<std::left<<"NOuuid:"<<NOuuid_<<"\n";
|
<<std::setw(width)<<std::left<<"NOuuid:"<<NOuuid_<<"\n";
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get JSON info string
|
||||||
|
std::string get_json()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss<<"{"<<"\"uuid\":\""<<uuid_
|
||||||
|
<<"\",\"CBuuid\":\""<<CBuuid_
|
||||||
|
<<"\",\"CGuuid\":\""<<CGuuid_
|
||||||
|
<<"\",\"CCuuid\":\""<<CCuuid_
|
||||||
|
<<"\",\"CNuuid\":\""<<CNuuid_
|
||||||
|
<<"\",\"CDuuid\":\""<<CDuuid_
|
||||||
|
<<"\",\"CTuuid\":\""<<CTuuid_
|
||||||
|
<<"\",\"Cbuuid\":\""<<Cbuuid_
|
||||||
|
<<"\",\"CPuuid\":\""<<CPuuid_
|
||||||
|
<<"\",\"CRuuid\":\""<<CRuuid_
|
||||||
|
<<"\",\"CSuuid\":\""<<CSuuid_
|
||||||
|
<<"\",\"NTuuid\":\""<<NTuuid_
|
||||||
|
<<"\",\"NOuuid\":\""<<NOuuid_
|
||||||
|
<<"\"}";
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// actual result and (meta)data of channel
|
// given a list of numeric objects, join it into a string
|
||||||
struct channel_data
|
template<typename dt>
|
||||||
|
std::string joinvec(std::vector<dt> myvec, unsigned long int limit = 10)
|
||||||
{
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss<<"[";
|
||||||
|
if ( myvec.size() <= limit )
|
||||||
|
{
|
||||||
|
for ( dt el: myvec ) ss<<el<<",";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unsigned long int heals = (unsigned long int)(limit/2.);
|
||||||
|
for ( unsigned long int i = 0; i < heals; i++ ) ss<<myvec[i]<<",";
|
||||||
|
ss<<"...";
|
||||||
|
for ( unsigned long int i = myvec.size()-heals; i < myvec.size(); i++ )
|
||||||
|
{
|
||||||
|
ss<<myvec[i]<<",";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::string sumstr = ss.str();
|
||||||
|
if ( sumstr.size() > 1 ) sumstr.pop_back();
|
||||||
|
sumstr += std::string("]");
|
||||||
|
return sumstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// channel
|
||||||
|
struct channel
|
||||||
|
{
|
||||||
|
// associated environment of blocks and map of blocks
|
||||||
|
channel_env chnenv_;
|
||||||
|
const std::map<std::string,imc::block>* blocks_;
|
||||||
|
|
||||||
// collect meta-data of channels according to env,
|
// collect meta-data of channels according to env,
|
||||||
// just everything valueable in here
|
// just everything valueable in here
|
||||||
std::string uuid_;
|
std::string uuid_;
|
||||||
std::string name_;
|
std::string name_;
|
||||||
std::string yunit_;
|
std::string yname_, yunit_;
|
||||||
std::string xunit_;
|
imc::datatype dattyp_;
|
||||||
|
std::string xname_, xunit_;
|
||||||
std::vector<imc::datatype> ydata_;
|
std::vector<imc::datatype> ydata_;
|
||||||
std::vector<imc::datatype> xdata_;
|
std::vector<imc::datatype> xdata_;
|
||||||
|
|
||||||
// provide JSON sttring of metadata
|
// group reference the channel belongs to
|
||||||
|
std::string group_uuid_, group_name_;
|
||||||
|
|
||||||
|
// constructor takes channel's block environment
|
||||||
|
channel(channel_env chnenv, std::map<std::string,imc::block>* blocks):
|
||||||
|
chnenv_(chnenv), blocks_(blocks)
|
||||||
|
{
|
||||||
|
std::vector<imc::parameter> prms = blocks->at(chnenv_.CNuuid_).get_parameters();
|
||||||
|
name_ = blocks->at(chnenv_.CNuuid_).get_parameter(prms[6]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get info string
|
||||||
|
std::string get_info(int width = 20)
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss<<"uuid:"<<std::setw(width)<<std::left<<uuid_<<"\n"
|
||||||
|
<<"name:"<<std::setw(width)<<std::left<<name_<<"\n"
|
||||||
|
<<"yname:"<<std::setw(width)<<std::left<<yname_<<"\n"
|
||||||
|
<<"yunit:"<<std::setw(width)<<std::left<<yunit_<<"\n"
|
||||||
|
<<"xname:"<<std::setw(width)<<std::left<<xname_<<"\n"
|
||||||
|
<<"xunit:"<<std::setw(width)<<std::left<<xunit_<<"\n"
|
||||||
|
<<"group:"<<std::setw(width)<<std::left<<group_name_<<"\n"
|
||||||
|
<<"aff. blocks:"<<std::setw(width)<<std::left<<chnenv_.get_json()<<"\n";
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
// provide JSON string of metadata
|
||||||
std::string get_json()
|
std::string get_json()
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss<<""<<"\n";
|
ss<<"{"<<"\"uuid\":\""<<uuid_
|
||||||
|
<<"\",\"name\":\""<<name_
|
||||||
|
<<"\",\"yname\":\""<<yname_
|
||||||
|
<<"\",\"yunit\":\""<<yunit_
|
||||||
|
<<"\",\"xname\":\""<<xname_
|
||||||
|
<<"\",\"xunit\":\""<<xunit_
|
||||||
|
<<"\",\"group\":\""<<group_name_
|
||||||
|
<<"\",\"ydata\":\""<<imc::joinvec<imc::datatype>(ydata_)
|
||||||
|
<<"\",\"xdata\":\""<<imc::joinvec<imc::datatype>(xdata_)
|
||||||
|
<<"\",\"aff. blocks\":\""<<chnenv_.get_json()
|
||||||
|
<<"\"}";
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ namespace imc
|
|||||||
};
|
};
|
||||||
|
|
||||||
// group definition (corresponds to key CB)
|
// group definition (corresponds to key CB)
|
||||||
struct group
|
struct groupobj
|
||||||
{
|
{
|
||||||
unsigned long int group_index_;
|
unsigned long int group_index_;
|
||||||
std::string name_;
|
std::string name_;
|
||||||
@ -400,7 +400,7 @@ namespace imc
|
|||||||
};
|
};
|
||||||
|
|
||||||
// channel (corresponds to key CN)
|
// channel (corresponds to key CN)
|
||||||
struct channel
|
struct channelobj
|
||||||
{
|
{
|
||||||
unsigned long int group_index_; // corresponds to group-index in CB key
|
unsigned long int group_index_; // corresponds to group-index in CB key
|
||||||
bool index_bit_; // true = 1: digital, false = 0: analog
|
bool index_bit_; // true = 1: digital, false = 0: analog
|
||||||
@ -538,7 +538,7 @@ namespace imc {
|
|||||||
{
|
{
|
||||||
format fmt_; // 0
|
format fmt_; // 0
|
||||||
keygroup kyg_; // 1
|
keygroup kyg_; // 1
|
||||||
group grp_; // 2
|
groupobj grp_; // 2
|
||||||
text txt_; // 3
|
text txt_; // 3
|
||||||
datafield dtf_; // 4
|
datafield dtf_; // 4
|
||||||
abscissa abs_; // 5
|
abscissa abs_; // 5
|
||||||
@ -546,7 +546,7 @@ namespace imc {
|
|||||||
packaging pkg_; // 7
|
packaging pkg_; // 7
|
||||||
buffer bfr_; // 8
|
buffer bfr_; // 8
|
||||||
range rng_; // 9
|
range rng_; // 9
|
||||||
channel chn_; // 10
|
channelobj chn_; // 10
|
||||||
data dat_; // 11
|
data dat_; // 11
|
||||||
origin_data org_; // 12
|
origin_data org_; // 12
|
||||||
triggertime trt_; // 13
|
triggertime trt_; // 13
|
||||||
|
@ -33,8 +33,8 @@ namespace imc
|
|||||||
// check computational complexity for parsing blocks
|
// check computational complexity for parsing blocks
|
||||||
unsigned long int cplxcnt_;
|
unsigned long int cplxcnt_;
|
||||||
|
|
||||||
// list groups and channels with their affiliate blocks
|
// list groups and channels (including their affiliate blocks)
|
||||||
std::map<std::string,imc::channel_env> channel_envs_;
|
std::map<std::string,imc::channel> channels_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -224,11 +224,13 @@ namespace imc
|
|||||||
if ( blk.get_key().name_ == "CS" || blk.get_key().name_ == "CC"
|
if ( blk.get_key().name_ == "CS" || blk.get_key().name_ == "CC"
|
||||||
|| blk.get_key().name_ == "CG" || blk.get_key().name_ == "CB" )
|
|| blk.get_key().name_ == "CG" || blk.get_key().name_ == "CB" )
|
||||||
{
|
{
|
||||||
|
// provide UUID for channel
|
||||||
chnenv.uuid_ = chnenv.CNuuid_;
|
chnenv.uuid_ = chnenv.CNuuid_;
|
||||||
channel_envs_.insert(
|
|
||||||
std::pair<std::string,imc::channel_env>(chnenv.CNuuid_,chnenv)
|
// create channel object and add it to the map of channels
|
||||||
|
channels_.insert( std::pair<std::string,imc::channel>
|
||||||
|
(chnenv.CNuuid_,imc::channel(chnenv,&mapblocks_))
|
||||||
);
|
);
|
||||||
std::cout<<chnenv.get_info()<<"\n";
|
|
||||||
|
|
||||||
// reset channel uuid
|
// reset channel uuid
|
||||||
chnenv.CNuuid_.clear();
|
chnenv.CNuuid_.clear();
|
||||||
@ -293,6 +295,31 @@ namespace imc
|
|||||||
return cplxcnt_;
|
return cplxcnt_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get list of channels with metadata
|
||||||
|
std::vector<std::string> get_channels()
|
||||||
|
{
|
||||||
|
std::vector<std::string> chns;
|
||||||
|
for ( std::map<std::string,imc::channel>::iterator it = channels_.begin();
|
||||||
|
it != channels_.end(); ++it)
|
||||||
|
{
|
||||||
|
chns.push_back(it->second.get_json());
|
||||||
|
}
|
||||||
|
return chns;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get particular channel including data by its uuid
|
||||||
|
imc::channel get_channel(std::string uuid)
|
||||||
|
{
|
||||||
|
if ( channels_.count(uuid) )
|
||||||
|
{
|
||||||
|
return channels_.at(uuid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error(std::string("channel does not exist:") + uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// list a particular type of block
|
// list a particular type of block
|
||||||
std::vector<imc::block> list_blocks(imc::key mykey)
|
std::vector<imc::block> list_blocks(imc::key mykey)
|
||||||
{
|
{
|
||||||
|
23
src/main.cpp
23
src/main.cpp
@ -180,26 +180,11 @@ int main(int argc, char* argv[])
|
|||||||
std::cout<<"computational complexity: "<<imcraw.computational_complexity()
|
std::cout<<"computational complexity: "<<imcraw.computational_complexity()
|
||||||
<<"/"<<imcraw.buffer_size()<<"\n\n";
|
<<"/"<<imcraw.buffer_size()<<"\n\n";
|
||||||
|
|
||||||
// list specific blocks
|
// list channels
|
||||||
// std::vector<imc::block> CBblocks = imcraw.list_blocks(imc::keys.at("CB"));
|
std::cout<<"list of channels:\n";
|
||||||
// for ( auto blk: CBblocks ) std::cout<<blk.get_info()<<"\n";
|
std::vector<std::string> channels = imcraw.get_channels();
|
||||||
// std::vector<imc::block> CGblocks = imcraw.list_blocks(imc::keys.at("CG"));
|
for ( auto el: channels ) std::cout<<el<<"\n";
|
||||||
// for ( auto blk: CGblocks ) std::cout<<blk.get_info()<<"\n";
|
|
||||||
// std::vector<imc::block> CCblocks = imcraw.list_blocks(imc::keys.at("CC"));
|
|
||||||
// for ( auto blk: CCblocks ) std::cout<<blk.get_info()<<"\n";
|
|
||||||
// std::vector<imc::block> CNblocks = imcraw.list_blocks(imc::keys.at("CN"));
|
|
||||||
// for ( auto blk: CNblocks ) std::cout<<blk.get_info()<<"\n";
|
|
||||||
// std::vector<imc::block> CSblocks = imcraw.list_blocks(imc::keys.at("CS"));
|
|
||||||
// for ( auto blk: CSblocks ) std::cout<<blk.get_info()<<"\n";
|
|
||||||
// std::vector<imc::block> groups = imcraw.list_groups();
|
|
||||||
// for ( auto blk: groups ) std::cout<<blk.get_info()<<"\n";
|
|
||||||
|
|
||||||
// std::vector<std::string> channels = imcraw.list_channels();
|
|
||||||
// for ( auto chn: channels )
|
|
||||||
// {
|
|
||||||
// std::cout<<chn<<"\n";
|
|
||||||
// imc::channel_tab chtab = imcraw.get_channel(chn);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user