DataFile.hpp
DataFile objects use DataNode objects to dynamically fill out file contents.
Functions
-
template<typename CONTAINER>
ContainerDataFile<CONTAINER> MakeContainerDataFile(std::function<CONTAINER(void)> fun, const std::string &filename, const std::string &b = "", const std::string &s = ",", const std::string &e = "\n") Convenience function for building a container data file.
- Parameters:
fun – is the function to call to update the container
filename – is the name of the file to output to
b – character to print at the beggininning of each line
s – delimeter (i.e. what character to print between entries on each line)
e – character to print at the end of each line
-
class DataFile
- #include <DataFile.hpp>
Keep track of everything associated with periodically printing data to a file. Maintain a set of functions for calculating the desired measurements at each point in time that they are required. It also handles the formating of the file.
Subclassed by ContainerDataFile< CONTAINER >
Public Functions
-
inline DataFile(const std::string &in_filename, const std::string &b = "", const std::string &s = ",", const std::string &e = "\n")
-
inline DataFile(std::ostream &in_os, const std::string &b = "", const std::string &s = ",", const std::string &e = "\n")
-
inline virtual ~DataFile()
-
inline const std::string &GetLineBegin() const
Returns the string that is printed at the beginning of each line.
-
inline const std::string &GetSpacer() const
Returns the string that is printed between elements on each line (i.e. the delimeter).
-
inline const std::string &GetLineEnd() const
Returns the string that is printed at the end of each line.
-
inline void SetTiming(time_fun_t fun)
Provide a timing function with a bool(size_t update) signature. The timing function is called with the update, and returns a bool to indicate if files should print this update.
-
inline void SetTimingOnce(size_t print_time)
Setup this file to print only once, at the specified update. Note that this timing function can be replaced at any time, even after being triggered.
- Parameters:
print_time – The update the file should print at
-
inline void SetTimingRepeat(size_t step)
Setup this file to print every ‘step’ updates.
-
inline void SetTimingRange(size_t first, size_t step, size_t last)
Setup this file to print only in a specified time range, and a given frequency (step).
-
inline void SetLineBegin(const std::string &_in)
Print a string at the beginning of each line.
- Parameters:
_in – the string to print
-
inline void SetSpacer(const std::string &_in)
Print a string between elements.
- Parameters:
_in – the string (i.e. the delimeter).
-
inline void SetLineEnd(const std::string &_in)
Print a string at the end of each line.
- Parameters:
_in – the string to print
-
inline void SetupLine(const std::string &b, const std::string &s, const std::string &e)
Set line begin, delimeter, and line end characters.
- Parameters:
b – line-begin character.
s – column delimeter
e – line end character
-
inline virtual void PrintHeaderKeys()
Print a header containing the name of each column.
-
inline virtual void PrintHeaderComment(const std::string &cstart = "# ")
Print a header containing comments describing all of the columns.
-
inline virtual void Update()
Run all of the functions and print the results as a new line in the file.
-
inline virtual void Update(size_t update)
If Update is called with an update number, the full version of update is called only if the update value passes the timing function (that is, the timing function returns true).
- Parameters:
update – the current time step
-
inline void AddPreFun(pre_fun_t fun)
Add a function to run before each time data is calculated. You can add as many functions as you want.
- Parameters:
fun – the function to add
-
inline size_t Add(const std::function<void(std::ostream&)> &fun, const std::string &key, const std::string &desc)
Generic function for adding a column to the DataFile. In practice, you probably want to call one of the more specific ones.
- Parameters:
fun – function to call to get the value to print
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)
-
template<typename T>
inline size_t AddFun(const std::function<T()> &fun, const std::string &key = "", const std::string &desc = "") Add a function that returns a value to be printed to the file.
- Parameters:
fun – function to call to get the value to print
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)
-
template<typename T>
inline size_t AddVar(const T &var, const std::string &key = "", const std::string &desc = "") Add a function that always prints the current value of
var
.- Parameters:
var – variable to print value of
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddCurrent(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the current value from the DataNode
node
. Requires thatnode
have thedata::Current
modifier.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddMean(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the mean value from the DataNode
node
. Requires thatnode
have thedata::Range
ordata::FullRange
modifier.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated? template <typename VAL_TYPE, data… MODS>
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddMedian(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the median value from the DataNode
node
. Requires thatnode
have thedata::Range
ordata::FullRange
modifier.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddPercentile(DataNode<VAL_TYPE, MODS...> &node, const double pct = 100.0, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the Percentile value from the DataNode
node
. Requires thatnode
have thedata::Range
ordata::FullRange
modifier.- Parameters:
node – DataNode to get data from
pct – the percentile value to return
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddTotal(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the total value from the DataNode
node
. Requires thatnode
have thedata::Range
ordata::FullRange
modifier.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddMin(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the minimum value from the DataNode
node
. Requires thatnode
have thedata::Range
ordata::FullRange
modifier.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddMax(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the maximum value from the DataNode
node
. Requires thatnode
have thedata::Range
ordata::FullRange
modifier.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddVariance(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the variance from the DataNode
node
Requires thatnode
have thedata::Stats
ordata::FullStats
modifier.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddStandardDeviation(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the standard deviation from the DataNode
node
Requires thatnode
have thedata::Stats
ordata::FullStats
modifier.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddSkew(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the skewness from the DataNode
node
Requires thatnode
have thedata::Stats
ordata::FullStats
modifier.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddKurtosis(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the kurtosis from the DataNode
node
Requires thatnode
have thedata::Stats
ordata::FullStats
modifier.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline void AddStats(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add multiple functions that pull common stats measurements (mean, variance, min, and max) from the DataNode
node
. Requires thatnode
have thedata::Stats
ordata::FullStats
modifier.key
anddesc
will have the name of the stat appended to the beginning. Note: excludes standard deviation, because it is easily calculated from variance Note: Settingpull
and/orreset
to true only pulls on first statistic calculated and only resets on the last. Otherwise there would be a risk of data loss or at least massive replication of computational effort. Even still, think carefully before setting either of these to true when you’re drawing varied information from the same node.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline void AddAllStats(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add multiple functions that pull all stats measurements (mean, variance, min, max, skew, and kurtosis) from the DataNode
node
Requires thatnode
have thedata::Stats
ordata::FullStats
modifier.key
anddesc
will have the name of the stat appended to the beginning. Note: excludes standard deviation, because it is easily calculated from variance Note: Settingpull
and/orreset
to true only pulls on first statistic calculated and only resets on the last. Otherwise there would be a risk of data loss or at least massive replication of computational effort. Even still, think carefully before setting either of these to true when you’re drawing varied information from the same node.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddHistBin(DataNode<VAL_TYPE, MODS...> &node, size_t bin_id, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the count of the
bin_id
‘th bin of the histogram fromnode
. Requires thatnode
have thedata::Histogram
modifier and at leastbin_id
bins.- Parameters:
node – DataNode to get data from
bin_id – id of bin to log data from (0-indexed)
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline void AddAllHistBins(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a set of functions that always pull the count of each bin of the histogram from
node
. Requires thatnode
have thedata::Histogram
modifier. Note: Settingpull
and/orreset
to true only pulls on first statistic calculated and only resets on the last. Otherwise there would be a risk of data loss or at least massive replication of computational effort. Even still, think carefully before setting either of these to true when you’re drawing varied information from the same node.- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
-
template<typename VAL_TYPE, data... MODS>
inline size_t AddInferiority(DataNode<VAL_TYPE, MODS...> &node, const std::string &key = "", const std::string &desc = "", const bool &reset = false, const bool &pull = false) Add a function that always pulls the inferiority (mean divided by max) from the specified DataNode. Requires that node have the data::Range or data::FullRange modifier.
- Parameters:
node – DataNode to get data from
key – Keyword associated with this column (gets used as a column name for this data)
desc – Full description of this data (used by
PrintHeaderComment
)reset – If this parameter is set true, we will call Reset on that DataNode after pulling the current value from the node
pull – Should the node pull data before this statistic is calculated?
Protected Types
Protected Attributes
-
FunctionSet<void()> pre_funs
Set of functions to call before calculating data.
-
time_fun_t timing_fun
Function to determine updates to print on (default: all)
-
inline DataFile(const std::string &in_filename, const std::string &b = "", const std::string &s = ",", const std::string &e = "\n")
-
template<typename CONTAINER>
class ContainerDataFile : public DataFile - #include <DataFile.hpp>
Sometimes you may want a data file where a set of functions is run on every item in a container every time you write to the file. ContainerDataFiles do that.
Note: CONTAINER type can be a pointer to a container and the datafile will handle dereferencing it appropriately.
Public Functions
-
inline ~ContainerDataFile()
-
inline void SetUpdateContainerFun(const fun_update_container_t fun)
Tell this file what function to run to update the contents of the container that data is being calculated on.
-
inline virtual void PrintHeaderKeys() override
Print a header containing the name of each column.
-
inline virtual void PrintHeaderComment(const std::string &cstart = "# ") override
Print a header containing comments describing all of the columns.
-
inline const container_t GetCurrentRows() const
-
inline virtual void Update() override
Run all of the functions and print the results as a new line in the file.
-
inline virtual void Update(size_t update) override
Update the file with an additional set of lines.
-
inline size_t Add(const std::function<void(std::ostream&, data_t)> &fun, const std::string &key, const std::string &desc)
If a function takes an ostream, pass in the correct one. Generic function for adding a column to the DataFile. In practice, you probably want to call one of the more specific ones.
Protected Types
-
using raw_container_t = typename remove_ptr_type<container_t>::type
-
using data_t = typename raw_container_t::value_type
-
using fun_update_container_t = std::function<container_t(void)>
Protected Attributes
-
fun_update_container_t update_container_fun
-
container_t current_rows
-
FunctionSet<container_fun_t> container_funs
-
inline ~ContainerDataFile()