From cecb53fe85ef5ebe5a191512d3fba4bb9cdc8bd1 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Thu, 21 Jan 2021 16:23:06 +0100 Subject: [PATCH] complete output format --- lib/tdm_datamodel.hpp | 274 ++++++++++++++++++++++++++++-------------- lib/tdm_reaper.cpp | 43 +++++++ lib/tdm_reaper.hpp | 3 + makefile | 2 +- src/main.cpp | 20 +-- 5 files changed, 241 insertions(+), 101 deletions(-) diff --git a/lib/tdm_datamodel.hpp b/lib/tdm_datamodel.hpp index a9d6a59..ef2a48c 100644 --- a/lib/tdm_datamodel.hpp +++ b/lib/tdm_datamodel.hpp @@ -15,6 +15,105 @@ #include #include +// -------------------------------------------------------------------------- // +// format output of info strings for terminal and file table + +class format +{ + +private: + + unsigned int width_; + bool tabular_; + bool header_; + char sep_; + std::vector> 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> columns) + { + columns_ = columns; + } + + std::string get_info() + { + std::stringstream ss; + + for ( std::vector>::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<first+std::string(":"))<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 &thestring, const char* sep = " ") +{ + std::string joined; + for ( std::vector::iterator it = thestring.begin(); + it != thestring.end(); ++it ) + { + joined += std::next(it,1) != thestring.end() ? ( *it + std::string(sep) ) : *it; + } + + return joined; +} + // -------------------------------------------------------------------------- // // tdm datatypes @@ -39,16 +138,17 @@ struct tdm_datatype { int size_; 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; - ss< 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; - ss< channels_; // referenced by id std::vector 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; - ss< local_columns_; // -> list of type "localcolumn" 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; - ss< refers to usi:data -> _sequence 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; - ss<::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 tdm_reaper::get_channel(std::string &id) { // check for existence of required channel id (=key) diff --git a/lib/tdm_reaper.hpp b/lib/tdm_reaper.hpp index 707572e..678b28a 100644 --- a/lib/tdm_reaper.hpp +++ b/lib/tdm_reaper.hpp @@ -146,6 +146,9 @@ public: return tdmroot_; } + // get full channel(group) overview + std::string get_channel_overview(format chformatter); + // get list of channelgroup ids std::vector get_channelgroup_ids() { diff --git a/makefile b/makefile index 2b16bfc..59b04bc 100644 --- a/makefile +++ b/makefile @@ -35,7 +35,7 @@ uninstall : $(INST)/$(EXE) rm $< # 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 @sed -i 's/TAGSTRING/$(GTAG)/g' $<.cpp @sed -i 's/HASHSTRING/$(GHSH)/g' $<.cpp diff --git a/src/main.cpp b/src/main.cpp index 380c247..af54ade 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -179,7 +179,7 @@ int main(int argc, char* argv[]) // declare and initialize tdm_ripper instance tdm_reaper jack; 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) { throw std::runtime_error( std::string("failed to load/parse tdm/tdx files: ") + e.what() ); @@ -191,15 +191,17 @@ int main(int argc, char* argv[]) // show some meta data of the dataset std::cout<<"\n"< chgrids = jack.get_channelgroup_ids(); - for ( auto el: chgrids ) std::cout< chids = jack.get_channel_ids(); - for ( auto el: chids ) std::cout< chgrids = jack.get_channelgroup_ids(); + // for ( auto el: chgrids ) std::cout< chids = jack.get_channel_ids(); + // for ( auto el: chids ) std::cout< chi = jack.get_channel(id); // for ( auto el: chids ) // {