complete output format
This commit is contained in:
parent
3b31384f67
commit
cecb53fe85
@ -15,6 +15,105 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
// format output of info strings for terminal and file table
|
||||||
|
|
||||||
|
class format
|
||||||
|
{
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
unsigned int width_;
|
||||||
|
bool tabular_;
|
||||||
|
bool header_;
|
||||||
|
char sep_;
|
||||||
|
std::vector<std::pair<std::string,std::string>> columns_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
format(int width = 25, bool tabular = false, bool header = false, char sep = ' '):
|
||||||
|
width_(width), tabular_(tabular), header_(header), sep_(sep)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_width(int width)
|
||||||
|
{
|
||||||
|
width_ = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_tabular(bool tabular)
|
||||||
|
{
|
||||||
|
tabular_ = tabular;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_header(bool header)
|
||||||
|
{
|
||||||
|
header_ = header;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_sep(char sep)
|
||||||
|
{
|
||||||
|
sep_ = sep;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_columns(std::vector<std::pair<std::string,std::string>> columns)
|
||||||
|
{
|
||||||
|
columns_ = columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string get_info()
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
for ( std::vector<std::pair<std::string,std::string>>::iterator it = columns_.begin();
|
||||||
|
it != columns_.end(); ++it )
|
||||||
|
{
|
||||||
|
if ( tabular_ )
|
||||||
|
{
|
||||||
|
// header or body of table
|
||||||
|
std::string entry = header_? it->first : it->second;
|
||||||
|
|
||||||
|
// make broad aligned columns for human reader
|
||||||
|
if ( sep_ == ' ' )
|
||||||
|
{
|
||||||
|
entry = entry.size() > width_-2 ? entry.substr(0,width_-2) : entry;
|
||||||
|
// if ( it == columns_.begin() && !header_ ) ss<<" ";
|
||||||
|
ss<<std::setw(width_)<<std::left<<entry;
|
||||||
|
}
|
||||||
|
// make compressed csv like columns
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ss<<entry;
|
||||||
|
if ( std::next(it,1) != columns_.end() ) ss<<sep_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ss<<std::setw(width_)<<std::left<<(it->first+std::string(":"))<<it->second<<"\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// define default formatter
|
||||||
|
static format defformat(25,false,false,',');
|
||||||
|
|
||||||
|
// join a list of strings
|
||||||
|
static std::string join_strings(std::vector<std::string> &thestring, const char* sep = " ")
|
||||||
|
{
|
||||||
|
std::string joined;
|
||||||
|
for ( std::vector<std::string>::iterator it = thestring.begin();
|
||||||
|
it != thestring.end(); ++it )
|
||||||
|
{
|
||||||
|
joined += std::next(it,1) != thestring.end() ? ( *it + std::string(sep) ) : *it;
|
||||||
|
}
|
||||||
|
|
||||||
|
return joined;
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
// tdm datatypes
|
// tdm datatypes
|
||||||
|
|
||||||
@ -39,16 +138,17 @@ struct tdm_datatype {
|
|||||||
int size_;
|
int size_;
|
||||||
std::string description_;
|
std::string description_;
|
||||||
|
|
||||||
const std::string get_info(int width = 25)
|
const std::string get_info() { return get_info(defformat); }
|
||||||
|
const std::string get_info(format& formatter)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
formatter.set_columns( { std::make_pair("name",name_),
|
||||||
ss<<std::setw(width)<<std::left<<"name:"<<name_<<"\n"
|
std::make_pair("channel_datatype",channel_datatype_),
|
||||||
<<std::setw(width)<<std::left<<"channel_datatype:"<<channel_datatype_<<"\n"
|
std::make_pair("name",name_),
|
||||||
<<std::setw(width)<<std::left<<"numeric:"<<numeric_<<"\n"
|
std::make_pair("value_sequence",value_sequence_),
|
||||||
<<std::setw(width)<<std::left<<"value_sequence:"<<value_sequence_<<"\n"
|
std::make_pair("size",std::to_string(size_)),
|
||||||
<<std::setw(width)<<std::left<<"size:"<<size_<<"\n"
|
std::make_pair("description",description_) } );
|
||||||
<<std::setw(width)<<std::left<<"description:"<<description_<<"\n";
|
|
||||||
return ss.str();
|
return formatter.get_info();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -88,17 +188,19 @@ struct block {
|
|||||||
value_type_ = std::string("");
|
value_type_ = std::string("");
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string get_info(int width = 25)
|
const std::string get_info() { return get_info(defformat); }
|
||||||
|
const std::string get_info(format& formatter)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
formatter.set_columns({ std::make_pair("block-id",id_),
|
||||||
ss<<std::setw(width)<<std::left<<"id:"<<id_<<"\n"
|
std::make_pair("byteOffset",std::to_string(byte_offset_)),
|
||||||
<<std::setw(width)<<std::left<<"byteOffset:"<<std::to_string(byte_offset_)<<"\n"
|
std::make_pair("length",std::to_string(length_)),
|
||||||
<<std::setw(width)<<std::left<<"length:"<<std::to_string(length_)<<"\n"
|
std::make_pair("blockOffset",std::to_string(block_offset_)),
|
||||||
<<std::setw(width)<<std::left<<"blockOffset:"<<std::to_string(block_offset_)<<"\n"
|
std::make_pair("blockSize",std::to_string(block_size_)),
|
||||||
<<std::setw(width)<<std::left<<"blockSize:"<<std::to_string(block_size_)<<"\n"
|
std::make_pair("valueType",value_type_) });
|
||||||
<<std::setw(width)<<std::left<<"valueType:"<<value_type_<<"\n";
|
|
||||||
return ss.str();
|
return formatter.get_info();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
@ -134,21 +236,20 @@ struct tdm_root {
|
|||||||
|
|
||||||
std::vector<std::string> channelgroups_;
|
std::vector<std::string> channelgroups_;
|
||||||
|
|
||||||
const std::string get_info(int width = 25)
|
const std::string get_info() { return get_info(defformat); }
|
||||||
|
const std::string get_info(format& formatter)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
formatter.set_columns({ std::make_pair("root-id",id_),
|
||||||
ss<<std::setw(width)<<std::left<<"id:"<<id_<<"\n"
|
std::make_pair("name",name_),
|
||||||
<<std::setw(width)<<std::left<<"name:"<<name_<<"\n"
|
std::make_pair("description",description_),
|
||||||
<<std::setw(width)<<std::left<<"description:"<<description_<<"\n"
|
std::make_pair("title",title_),
|
||||||
<<std::setw(width)<<std::left<<"title:"<<title_<<"\n"
|
std::make_pair("author",author_),
|
||||||
<<std::setw(width)<<std::left<<"author:"<<author_<<"\n"
|
std::make_pair("timestamp",timestamp_),
|
||||||
<<std::setw(width)<<std::left<<"timestamp:"<<timestamp_<<"\n"
|
std::make_pair("channelgroups",join_strings(channelgroups_)) });
|
||||||
<<std::setw(width)<<std::left<<"channelgroups:";
|
|
||||||
for ( auto el: channelgroups_ ) ss<<el<<",";
|
return formatter.get_info();
|
||||||
std::string infostr = ss.str();
|
|
||||||
infostr.pop_back();
|
|
||||||
return ( infostr + std::string("\n") );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
@ -165,25 +266,19 @@ struct tdm_channelgroup {
|
|||||||
std::vector<std::string> channels_; // referenced by id
|
std::vector<std::string> channels_; // referenced by id
|
||||||
std::vector<std::string> submatrices_;
|
std::vector<std::string> submatrices_;
|
||||||
|
|
||||||
const std::string get_info(int width = 25)
|
const std::string get_info() { return get_info(defformat); }
|
||||||
|
const std::string get_info(format& formatter)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
formatter.set_columns({ std::make_pair("group-id",id_),
|
||||||
ss<<std::setw(width)<<std::left<<"id:"<<id_<<"\n"
|
std::make_pair("name",name_),
|
||||||
<<std::setw(width)<<std::left<<"name:"<<name_<<"\n"
|
std::make_pair("description",description_),
|
||||||
<<std::setw(width)<<std::left<<"description:"<<description_<<"\n"
|
std::make_pair("root",root_),
|
||||||
<<std::setw(width)<<std::left<<"root:"<<root_<<"\n"
|
std::make_pair("channels",join_strings(channels_)),
|
||||||
<<std::setw(width)<<std::left<<"channels:";
|
std::make_pair("submatrices",join_strings(submatrices_)) });
|
||||||
for ( auto el: channels_ ) ss<<el<<",";
|
|
||||||
std::string infostr = ss.str();
|
return formatter.get_info();
|
||||||
infostr.pop_back();
|
|
||||||
ss.str(std::string());
|
|
||||||
ss<<infostr<<"\n"
|
|
||||||
<<std::setw(width)<<std::left<<"submatrices:";
|
|
||||||
for ( auto el: submatrices_ ) ss<<el<<",";
|
|
||||||
infostr = ss.str();
|
|
||||||
infostr.pop_back();
|
|
||||||
return ( infostr + std::string("\n") );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
@ -224,23 +319,22 @@ struct tdm_channel {
|
|||||||
// TODO
|
// TODO
|
||||||
waveform_channel wf_channel_;
|
waveform_channel wf_channel_;
|
||||||
|
|
||||||
const std::string get_info(int width = 25)
|
const std::string get_info() { return get_info(defformat); }
|
||||||
|
const std::string get_info(format& formatter)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
formatter.set_columns({ std::make_pair("channel-id",id_),
|
||||||
ss<<std::setw(width)<<std::left<<"id:"<<id_<<"\n"
|
std::make_pair("name",name_),
|
||||||
<<std::setw(width)<<std::left<<"name:"<<name_<<"\n"
|
std::make_pair("description",description_),
|
||||||
<<std::setw(width)<<std::left<<"description:"<<description_<<"\n"
|
std::make_pair("unit_string",unit_string_),
|
||||||
<<std::setw(width)<<std::left<<"unit_string:"<<unit_string_<<"\n"
|
std::make_pair("datatype",datatype_),
|
||||||
<<std::setw(width)<<std::left<<"datatype:"<<datatype_<<"\n"
|
std::make_pair("minimum",std::to_string(minimum_)),
|
||||||
<<std::setw(width)<<std::left<<"minimum:"<<std::to_string(minimum_)<<"\n"
|
std::make_pair("maximum",std::to_string(maximum_)),
|
||||||
<<std::setw(width)<<std::left<<"maximum:"<<std::to_string(maximum_)<<"\n"
|
std::make_pair("group",group_),
|
||||||
<<std::setw(width)<<std::left<<"group:"<<group_<<"\n"
|
std::make_pair("local_columns",join_strings(local_columns_)) });
|
||||||
<<std::setw(width)<<std::left<<"local_columns:";
|
|
||||||
for ( auto el: local_columns_ ) ss<<el<<",";
|
return formatter.get_info();
|
||||||
std::string infostr = ss.str();
|
|
||||||
infostr.pop_back();
|
|
||||||
return ( infostr + std::string("\n") );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
@ -257,20 +351,19 @@ struct submatrix {
|
|||||||
std::vector<std::string> local_columns_; // -> list of type "localcolumn"
|
std::vector<std::string> local_columns_; // -> list of type "localcolumn"
|
||||||
unsigned long int number_of_rows_; // -> number of values in channels
|
unsigned long int number_of_rows_; // -> number of values in channels
|
||||||
|
|
||||||
const std::string get_info(int width = 25)
|
const std::string get_info() { return get_info(defformat); }
|
||||||
|
const std::string get_info(format& formatter)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
formatter.set_columns({ std::make_pair("id",id_),
|
||||||
ss<<std::setw(width)<<std::left<<"id:"<<id_<<"\n"
|
std::make_pair("name",name_),
|
||||||
<<std::setw(width)<<std::left<<"name:"<<name_<<"\n"
|
std::make_pair("description",description_),
|
||||||
<<std::setw(width)<<std::left<<"description:"<<description_<<"\n"
|
std::make_pair("measurement",measurement_),
|
||||||
<<std::setw(width)<<std::left<<"measurement:"<<measurement_<<"\n"
|
std::make_pair("local_columns",join_strings(local_columns_)),
|
||||||
<<std::setw(width)<<std::left<<"number_of_rows:"<<number_of_rows_<<"\n"
|
std::make_pair("number_of_rows",std::to_string(number_of_rows_)) });
|
||||||
<<std::setw(width)<<std::left<<"local_columns:";
|
|
||||||
for ( auto el: local_columns_ ) ss<<el<<",";
|
return formatter.get_info();
|
||||||
std::string infostr = ss.str();
|
|
||||||
infostr.pop_back();
|
|
||||||
return ( infostr + std::string("\n") );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
@ -303,24 +396,23 @@ struct localcolumn {
|
|||||||
std::string values_; // -> refers to usi:data -> _sequence
|
std::string values_; // -> refers to usi:data -> _sequence
|
||||||
std::string external_id_;
|
std::string external_id_;
|
||||||
|
|
||||||
const std::string get_info(int width = 25)
|
const std::string get_info() { return get_info(defformat); }
|
||||||
|
const std::string get_info(format& formatter)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
formatter.set_columns({ std::make_pair("id",id_),
|
||||||
ss<<std::setw(width)<<std::left<<"id:"<<id_<<"\n"
|
std::make_pair("name",name_),
|
||||||
<<std::setw(width)<<std::left<<"name:"<<name_<<"\n"
|
std::make_pair("description",description_),
|
||||||
<<std::setw(width)<<std::left<<"description:"<<description_<<"\n"
|
std::make_pair("measurement_quantity",measurement_quantity_),
|
||||||
<<std::setw(width)<<std::left<<"measurement_quantity:"<<measurement_quantity_<<"\n"
|
std::make_pair("submatrix_",submatrix_),
|
||||||
<<std::setw(width)<<std::left<<"submatrix_:"<<submatrix_<<"\n"
|
std::make_pair("minimum",std::to_string(minimum_)),
|
||||||
<<std::setw(width)<<std::left<<"minimum:"<<std::to_string(minimum_)<<"\n"
|
std::make_pair("maximum",std::to_string(maximum_)),
|
||||||
<<std::setw(width)<<std::left<<"maximum:"<<std::to_string(maximum_)<<"\n"
|
std::make_pair("sequence_representation",sequence_representation_),
|
||||||
<<std::setw(width)<<std::left<<"sequence_representation:"<<sequence_representation_<<"\n"
|
std::make_pair("values",values_),
|
||||||
// TODO
|
std::make_pair("external",external_id_) });
|
||||||
// <<std::setw(width)<<std::left<<"generation_parameters_:"<<"{"<<generation_parameters_[0]
|
|
||||||
// <<","<<generation_parameters_[1]<<"}"<<"\n"
|
return formatter.get_info();
|
||||||
<<std::setw(width)<<std::left<<"values:"<<values_<<"\n"
|
|
||||||
<<std::setw(width)<<std::left<<"external:"<<external_id_<<"\n";
|
|
||||||
return ss.str();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -393,6 +393,49 @@ void tdm_reaper::process_localcolumns(bool showlog)
|
|||||||
|
|
||||||
// -------------------------------------------------------------------------- //
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
std::string tdm_reaper::get_channel_overview(format chformatter)
|
||||||
|
{
|
||||||
|
// declare format instance
|
||||||
|
// format chformatter(15,false,false,' ');
|
||||||
|
|
||||||
|
// summarize all output in single string
|
||||||
|
std::string channels_summary;
|
||||||
|
|
||||||
|
// set tabular mode of formatter
|
||||||
|
chformatter.set_tabular(true);
|
||||||
|
|
||||||
|
// compose header
|
||||||
|
chformatter.set_header(true);
|
||||||
|
tdm_channelgroup grp;
|
||||||
|
channels_summary += grp.get_info(chformatter);
|
||||||
|
tdm_channel chn;
|
||||||
|
channels_summary += chn.get_info(chformatter);
|
||||||
|
std::string rule; // = std::string("#");
|
||||||
|
for ( unsigned long int i = 0; i < channels_summary.size(); i++ )
|
||||||
|
{
|
||||||
|
rule += std::string("-");
|
||||||
|
}
|
||||||
|
// rule += std::string("#");
|
||||||
|
channels_summary = // std::string("# ") +
|
||||||
|
channels_summary + std::string("\n") + rule + std::string("\n");
|
||||||
|
|
||||||
|
chformatter.set_header(false);
|
||||||
|
for (std::map<std::string,tdm_channel>::iterator it=tdmchannels_.begin();
|
||||||
|
it!=tdmchannels_.end(); ++it)
|
||||||
|
{
|
||||||
|
// get corresponding group
|
||||||
|
tdm_channelgroup grp = tdmchannelgroups_.at(it->second.group_);
|
||||||
|
channels_summary += grp.get_info(chformatter);
|
||||||
|
// ...and actual channel
|
||||||
|
channels_summary += it->second.get_info(chformatter);
|
||||||
|
channels_summary += std::string("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return channels_summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
std::vector<double> tdm_reaper::get_channel(std::string &id)
|
std::vector<double> tdm_reaper::get_channel(std::string &id)
|
||||||
{
|
{
|
||||||
// check for existence of required channel id (=key)
|
// check for existence of required channel id (=key)
|
||||||
|
@ -146,6 +146,9 @@ public:
|
|||||||
return tdmroot_;
|
return tdmroot_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get full channel(group) overview
|
||||||
|
std::string get_channel_overview(format chformatter);
|
||||||
|
|
||||||
// get list of channelgroup ids
|
// get list of channelgroup ids
|
||||||
std::vector<std::string> get_channelgroup_ids()
|
std::vector<std::string> get_channelgroup_ids()
|
||||||
{
|
{
|
||||||
|
2
makefile
2
makefile
@ -35,7 +35,7 @@ uninstall : $(INST)/$(EXE)
|
|||||||
rm $<
|
rm $<
|
||||||
|
|
||||||
# build main.cpp object file and include git version/commit tag
|
# build main.cpp object file and include git version/commit tag
|
||||||
main.o : src/main.cpp lib/$(SRC).hpp
|
main.o : src/main.cpp lib/$(SRC).hpp lib/tdm_datamodel.hpp
|
||||||
@cp $< $<.cpp
|
@cp $< $<.cpp
|
||||||
@sed -i 's/TAGSTRING/$(GTAG)/g' $<.cpp
|
@sed -i 's/TAGSTRING/$(GTAG)/g' $<.cpp
|
||||||
@sed -i 's/HASHSTRING/$(GHSH)/g' $<.cpp
|
@sed -i 's/HASHSTRING/$(GHSH)/g' $<.cpp
|
||||||
|
20
src/main.cpp
20
src/main.cpp
@ -179,7 +179,7 @@ int main(int argc, char* argv[])
|
|||||||
// declare and initialize tdm_ripper instance
|
// declare and initialize tdm_ripper instance
|
||||||
tdm_reaper jack;
|
tdm_reaper jack;
|
||||||
try {
|
try {
|
||||||
jack.submit_files(cfgopts.at("tdm"),cfgopts.at("tdx"),false);
|
jack.submit_files(cfgopts.at("tdm"),cfgopts.at("tdx"),true);
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
throw std::runtime_error( std::string("failed to load/parse tdm/tdx files: ")
|
throw std::runtime_error( std::string("failed to load/parse tdm/tdx files: ")
|
||||||
+ e.what() );
|
+ e.what() );
|
||||||
@ -191,15 +191,17 @@ int main(int argc, char* argv[])
|
|||||||
// show some meta data of the dataset
|
// show some meta data of the dataset
|
||||||
std::cout<<"\n"<<jack.get_root().get_info()<<"\n\n";
|
std::cout<<"\n"<<jack.get_root().get_info()<<"\n\n";
|
||||||
|
|
||||||
std::vector<std::string> chgrids = jack.get_channelgroup_ids();
|
// get complete channel overview
|
||||||
for ( auto el: chgrids ) std::cout<<el<<",";
|
format chformatter(14,false,false,' ');
|
||||||
std::cout<<"\n";
|
std::cout<<jack.get_channel_overview(chformatter)<<"\n";
|
||||||
std::vector<std::string> chids = jack.get_channel_ids();
|
|
||||||
for ( auto el: chids ) std::cout<<el<<",";
|
// std::vector<std::string> chgrids = jack.get_channelgroup_ids();
|
||||||
std::cout<<"\n\n";
|
// for ( auto el: chgrids ) std::cout<<el<<",";
|
||||||
|
// std::cout<<"\n";
|
||||||
|
// std::vector<std::string> chids = jack.get_channel_ids();
|
||||||
|
// for ( auto el: chids ) std::cout<<el<<",";
|
||||||
|
// std::cout<<"\n\n";
|
||||||
|
|
||||||
std::string id("usi15");
|
|
||||||
std::vector<double> chi = jack.get_channel(id);
|
|
||||||
|
|
||||||
// for ( auto el: chids )
|
// for ( auto el: chids )
|
||||||
// {
|
// {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user