DataTrack.h
1/* Distributed under the Apache License, Version 2.0.
2 See accompanying NOTICE file for details.*/
3
4#pragma once
5
6#include <iostream>
7#include <iomanip>
8class SESubstance;
10class SEFluidCircuit;
14#include "cdm/engine/SEDecimalFormat.h"
15
16class CDM_DECL DataTrack : public Loggable
17{
18protected:
19 struct CDM_DECL Element
20 {
21 size_t idx;
22 std::string name;
23 double probe=std::numeric_limits<double>::quiet_NaN();
24 std::vector<double> track;
26 };
27 typedef std::vector<Element> ElementVector;
28public:
29 DataTrack();
30 DataTrack(Logger *m_Log);
31 ~DataTrack();
32
33 void Clear();
34 void Reset();
35
36 void UseTabDelimiter() { m_Delimiter = '\t'; }
37 void UseCommaDelimiter() { m_Delimiter = ','; }
38
39 std::vector<double> const& GetTimes() const;
40 size_t NumTracks() { return m_Elements.size(); }
41
42 void SetFormatting(const std::string& name, const SEDecimalFormat& f);
43 void SetFormatting(const std::string& name, std::streamsize precision);
44 void SetDefaultFormatting(std::streamsize precision);
45
46
47 void Probe(size_t idx, double value);
48 // Returning the index of this element, use it to avoid a string lookup
49 size_t Probe(const std::string& name, double value);
50 size_t Probe(const std::string& name, double value, int i);// Append value of i to the name
51 void Probe(const SEFluidCircuit& c);
52 void Probe(const SEElectricalCircuit& c);
53 void Probe(const SEThermalCircuit& c);
54 void Probe(const SELiquidCompartmentGraph& graph);
55
56 double GetProbe(size_t idx);
57 double GetProbe(const std::string& name);
58 std::string GetProbeName(size_t idx);
59
60 void Track(size_t idx, double time, double value);
61 // Returning the index of this element, use it to avoid a string lookup
62 size_t Track(const std::string& name, double time, double value);
63 void Track(double time, const SEElectricalCircuit& circuit);
64 void Track(double time, const SEFluidCircuit& circuit);
65 void Track(double time, const SEThermalCircuit& circuit);
66 void Track(double time, const SEGasCompartmentGraph& graph, std::vector<SESubstance*>* substances = nullptr);
67 void Track(double time, const SELiquidCompartmentGraph& graph, std::vector<SESubstance*>* substances = nullptr);
68
69 // Get a specific track value at a specific time
70 double GetTrack(size_t idx, double time);
71 double GetTrack(const std::string& name, double time);
72
73 // Reads the entire file and stores contents into memory, returns the column headings
74 std::vector<std::string> ReadTrackFromFile(const char* fileName);
75 // Only Reads the column headings and returns them
76 // Holds onto the file handle for streaming line by line
77 std::vector<std::string> StreamDataFromFile(const char* fileName);
78
79 // Reads a line from the file and returns the time associated with the time
80 double StreamDataFromFile(std::vector<std::string>* headings);
81
82 // Creates the file and writes the headers to that file
83 void CreateFile(const char* fileName, std::ofstream& newFile);// TODO C++11
84 // Write all the track to a file
85 void WriteTrackToFile(const char* fileName);
86 // Writes data from the provided headings to the file, in the order things were tracked
87 void StreamTrackToFile(std::ofstream& file);
88 // Writes prob values to file in the order things were tracked
89 void StreamProbesToFile(double time, std::ofstream& file);
90
91protected:
92 Element& GetElement(size_t idx);
93 Element& GetElement(std::string const& name);
95
97 double m_LastTime = -1.0;
98 std::vector<double> m_Times;
99 std::streamsize m_DefaultPrecision = 3;
100
101 std::ifstream m_FileStream;
102};
Definition: DataTrack.h:17
size_t NumTracks()
Definition: DataTrack.h:40
std::vector< Element > ElementVector
Definition: DataTrack.h:27
std::vector< double > m_Times
Definition: DataTrack.h:98
std::ifstream m_FileStream
Definition: DataTrack.h:101
ElementVector m_Elements
Definition: DataTrack.h:94
void Track(size_t idx, double time, double value)
char m_Delimiter
Definition: DataTrack.h:96
void UseCommaDelimiter()
Definition: DataTrack.h:37
void UseTabDelimiter()
Definition: DataTrack.h:36
Definition: Logger.h:23
Definition: Logger.h:71
Definition: SEDecimalFormat.h:10
Definition: SEElectricalCircuit.h:12
Definition: SEFluidCircuit.h:12
Definition: SEGasCompartmentGraph.h:11
Definition: SELiquidCompartmentGraph.h:12
Definition: SESubstance.h:15
Definition: SEThermalCircuit.h:12
Definition: DataTrack.h:20
std::string name
Definition: DataTrack.h:22
SEDecimalFormat format
Definition: DataTrack.h:25
std::vector< double > track
Definition: DataTrack.h:24
size_t idx
Definition: DataTrack.h:21

Distributed under the Apache License, Version 2.0.

See accompanying NOTICE file for details.