26#include <tscpp/stream.h>
40using tscpp::TypePoolStream;
41using tscpp::UnknownInputArchive;
46typedef std::numeric_limits<float>
flt;
99 void printType(T& t, std::string path =
"", std::string prefix =
"");
103 std::map<std::string, std::ofstream*> fileStreams;
104 tscpp::TypePoolStream tps;
106 std::string logFilename;
107 std::string logFilenameWithoutExtension;
108 std::string logFolderPath;
114 logFilenameWithoutExtension =
115 logFilename.substr(0, logFilename.find_last_of(
"."));
116 logFolderPath = logFilenameWithoutExtension +
"/";
124 std::function<void(T & t)> callback =
125 std::bind(&Deserializer::printType<T>,
this, std::placeholders::_1,
126 logFolderPath, logFilenameWithoutExtension);
128 tps.registerType<T>(callback);
132void Deserializer::printType(T& t, std::string path, std::string prefix)
134 static std::ofstream* stream;
135 std::string demangledTypeName = tscpp::demangle(
typeid(T).name());
140 std::regex_replace(demangledTypeName, std::regex(
"::"),
"_");
144 stream = fileStreams.at(demangledTypeName);
147 catch (std::out_of_range e)
149 stream =
new std::ofstream();
150 std::string filename = path + prefix +
"_" + demangledTypeName +
".csv";
151 std::cout <<
"Creating file " + filename << std::endl;
152 stream->open(filename);
154 if (!stream->is_open())
156 printf(
"Error opening file %s.\n", filename.c_str());
162 *stream << T::header();
165 stream->precision(flt::max_digits10);
168 fileStreams.emplace(demangledTypeName, stream);
172 if (stream->is_open())
173 t.print(std::ref(*stream));
182 mkdir(logFolderPath.c_str(), 0777);
185 if (rename(logFilename.c_str(), (logFolderPath + logFilename).c_str()))
187 std::cout << logFilename +
" does not exists." << std::endl;
192 std::ifstream file(logFolderPath + logFilename);
197 std::cout << logFolderPath + logFilename +
" does not exists."
202 tscpp::UnknownInputArchive inputArchive(file, tps);
207 inputArchive.unserialize();
209 catch (tscpp::TscppException& ex)
212 if (strcmp(ex.what(),
"eof") == 0)
217 else if (strcmp(ex.what(),
"unknown type") == 0)
219 std::string unknownTypeName = ex.name();
220 std::cout <<
"Unknown type found: " << unknownTypeName
236 for (
auto it = fileStreams.begin(); it != fileStreams.end(); it++)
Class used to deserialize the binary logs created using fedetft's logger into csv files.
void close()
Closes all the openend files.
bool deserialize()
Deserializes the provided file.
Deserializer(std::string fileName)
Initializes the deserializer with the filename provided.
void registerType()
Register a type to be deserialized.
This file includes all the types the logdecoder script will decode.
std::numeric_limits< float > flt