21class DataLoggerInterface {
23 std::map<String, CPS::AttributeBase::Ptr> mAttributes;
26 typedef std::shared_ptr<DataLoggerInterface> Ptr;
27 typedef std::vector<DataLoggerInterface::Ptr> List;
29 DataLoggerInterface() : mAttributes(){};
31 virtual ~DataLoggerInterface() =
default;
34 virtual void start() = 0;
36 virtual void stop() = 0;
38 virtual void logAttribute(
const String &name, CPS::AttributeBase::Ptr attr,
39 UInt rowsMax = 0, UInt colsMax = 0) {
42 mAttributes[name] = attrReal;
43 }
else if (
auto attrComp =
46 mAttributes[name +
".re"] = attrComp->deriveReal();
47 mAttributes[name +
".im"] = attrComp->deriveImag();
50 mAttributes[name] = attrInt;
51 }
else if (
auto attrMatrix =
54 UInt rows =
static_cast<UInt
>((**attrMatrix).rows());
55 UInt cols =
static_cast<UInt
>((**attrMatrix).cols());
56 if (rowsMax == 0 || rowsMax > rows)
58 if (colsMax == 0 || colsMax > cols)
60 if (rows == 1 && cols == 1) {
61 mAttributes[name] = attrMatrix->deriveCoeff<Real>(0, 0);
62 }
else if (cols == 1) {
63 for (UInt k = 0; k < rowsMax; ++k) {
64 mAttributes[name +
"_" + std::to_string(k)] =
65 attrMatrix->deriveCoeff<Real>(k, 0);
68 for (UInt k = 0; k < rowsMax; ++k) {
69 for (UInt l = 0; l < colsMax; ++l) {
70 mAttributes[name +
"_" + std::to_string(k) +
"_" +
72 attrMatrix->deriveCoeff<Real>(k, l);
76 }
else if (
auto attrMatrix =
79 UInt rows =
static_cast<UInt
>((**attrMatrix).rows());
80 UInt cols =
static_cast<UInt
>((**attrMatrix).cols());
81 if (rowsMax == 0 || rowsMax > rows)
83 if (colsMax == 0 || colsMax > cols)
85 if (rows == 1 && cols == 1) {
86 mAttributes[name +
".re"] =
87 attrMatrix->deriveCoeff<Complex>(0, 0)->deriveReal();
88 mAttributes[name +
".im"] =
89 attrMatrix->deriveCoeff<Complex>(0, 0)->deriveImag();
90 }
else if (cols == 1) {
91 for (UInt k = 0; k < rowsMax; ++k) {
92 mAttributes[name +
"_" + std::to_string(k) +
".re"] =
93 attrMatrix->deriveCoeff<Complex>(k, 0)->deriveReal();
94 mAttributes[name +
"_" + std::to_string(k) +
".im"] =
95 attrMatrix->deriveCoeff<Complex>(k, 0)->deriveImag();
98 for (UInt k = 0; k < rowsMax; ++k) {
99 for (UInt l = 0; l < colsMax; ++l) {
100 mAttributes[name +
"_" + std::to_string(k) +
"_" +
101 std::to_string(l) +
".re"] =
102 attrMatrix->deriveCoeff<Complex>(k, l)->deriveReal();
103 mAttributes[name +
"_" + std::to_string(k) +
"_" +
104 std::to_string(l) +
".im"] =
105 attrMatrix->deriveCoeff<Complex>(k, l)->deriveImag();
110 throw std::runtime_error(
111 "DataLoggerInterface: Unknown attribute type for attribute " + name);
118 CPS::AttributeBase::Ptr attr) {
119 if (
auto attrMatrix =
121 if ((**attrMatrix).rows() == 1 && (**attrMatrix).cols() == 1) {
122 logAttribute(name[0], attrMatrix->deriveCoeff<CPS::Real>(0, 0));
123 }
else if ((**attrMatrix).cols() == 1) {
124 for (UInt k = 0; k < (**attrMatrix).rows(); ++k) {
125 logAttribute(name[k], attrMatrix->deriveCoeff<CPS::Real>(k, 0));
128 for (UInt k = 0; k < (**attrMatrix).rows(); ++k) {
129 for (UInt l = 0; l < (**attrMatrix).cols(); ++l) {
130 logAttribute(name[k * (**attrMatrix).cols() + l],
131 attrMatrix->deriveCoeff<CPS::Real>(k, l));
135 }
else if (
auto attrMatrix =
138 if ((**attrMatrix).rows() == 1 && (**attrMatrix).cols() == 1) {
139 logAttribute(name[0], attrMatrix->deriveCoeff<CPS::Complex>(0, 0));
140 }
else if ((**attrMatrix).cols() == 1) {
141 for (UInt k = 0; k < (**attrMatrix).rows(); ++k) {
142 logAttribute(name[k], attrMatrix->deriveCoeff<CPS::Complex>(k, 0));
145 for (UInt k = 0; k < (**attrMatrix).rows(); ++k) {
146 for (UInt l = 0; l < (**attrMatrix).cols(); ++l) {
147 logAttribute(name[k * (**attrMatrix).cols() + l],
148 attrMatrix->deriveCoeff<CPS::Complex>(k, l));
155 virtual void log(Real time, Int timeStepCount) = 0;
157 virtual CPS::Task::Ptr getTask() = 0;