##// END OF EJS Templates
Initial Pybind11 binding experiment working....
Initial Pybind11 binding experiment working. Can open an amda formatted file from Python and get few attributes from ScalarSeries. Loading module from python works. Embedding python interpreter also works. Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1278:d3daab81283b
r1339:98271eda8c6e
Show More
AmdaResultParser.cpp
133 lines | 3.9 KiB | text/x-c | CppLexer
/ plugins / amda / src / AmdaResultParser.cpp
Alexandre Leroux
Amda provider (3)...
r380 #include "AmdaResultParser.h"
Alexandre Leroux
Parser refactoring (5)...
r948 #include "AmdaResultParserHelper.h"
Alexandre Leroux
Amda provider (3)...
r380
#include <QFile>
Add the cmath include missing
r400 #include <cmath>
Alexandre Leroux
Amda provider (3)...
r380 Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser")
namespace {
Alexandre Leroux
Handles "Not found" error for AMDA result parser
r446 /// Message in result file when the file was not found on server
const auto FILE_NOT_FOUND_MESSAGE = QStringLiteral("Not Found");
Alexandre Leroux
Improves AMDA result parsing...
r492 /// Checks if a line is a comment line
bool isCommentLine(const QString &line)
{
return line.startsWith("#");
}
Alexandre Leroux
Parser refactoring (5)...
r948 /**
* Creates helper that will be used to read AMDA file, according to the type passed as parameter
* @param valueType the type of values expected in the AMDA file (scalars, vectors, spectrograms...)
* @return the helper created
*/
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 std::unique_ptr<IAmdaResultParserHelper> createHelper(DataSeriesType valueType)
Alexandre Leroux
Updates method for reading results according to the value type (vector or scalar)
r564 {
switch (valueType) {
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 case DataSeriesType::SCALAR:
Alexandre Leroux
Parser refactoring (5)...
r948 return std::make_unique<ScalarParserHelper>();
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 case DataSeriesType::SPECTROGRAM:
Alexandre Leroux
Spectrograms implementation (1)...
r949 return std::make_unique<SpectrogramParserHelper>();
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 case DataSeriesType::VECTOR:
Alexandre Leroux
Parser refactoring (5)...
r948 return std::make_unique<VectorParserHelper>();
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 case DataSeriesType::UNKNOWN:
Alexandre Leroux
Updates method for reading results according to the value type (vector or scalar)
r564 // Invalid case
break;
}
// Invalid cases
qCCritical(LOG_AmdaResultParser())
Alexandre Leroux
Parser refactoring (5)...
r948 << QObject::tr("Can't create helper to read result file: unsupported type");
return nullptr;
Alexandre Leroux
Updates method for reading results according to the value type (vector or scalar)
r564 }
Alexandre Leroux
Reads x-axis unit in result file
r393 /**
Alexandre Leroux
Parser refactoring (5)...
r948 * Reads properties of the stream passed as parameter
* @param helper the helper used to read properties line by line
Alexandre Leroux
Reads x-axis unit in result file
r393 * @param stream the stream to read
*/
Alexandre Leroux
Parser refactoring (5)...
r948 void readProperties(IAmdaResultParserHelper &helper, QTextStream &stream)
Alexandre Leroux
Reads x-axis unit in result file
r393 {
Alexandre Leroux
Parser refactoring (5)...
r948 // Searches properties in the comment lines (as long as the reading has not reached the data)
Alexandre Leroux
Changes way to retrieve unit
r791 // AMDA V2: while (stream.readLineInto(&line) && !line.contains(DATA_HEADER_REGEX)) {
Alexandre Leroux
Parser refactoring (5)...
r948 QString line{};
Alexandre Leroux
Changes way to retrieve unit
r791 while (stream.readLineInto(&line) && isCommentLine(line)) {
Alexandre Leroux
Parser refactoring (5)...
r948 helper.readPropertyLine(line);
Alexandre Leroux
Reads x-axis unit in result file
r393 }
}
Alexandre Leroux
Improves controls when reading results
r394 /**
Alexandre Leroux
Parser refactoring (5)...
r948 * Reads results of the stream passed as parameter
* @param helper the helper used to read results line by line
Alexandre Leroux
Improves controls when reading results
r394 * @param stream the stream to read
*/
Alexandre Leroux
Parser refactoring (5)...
r948 void readResults(IAmdaResultParserHelper &helper, QTextStream &stream)
Alexandre Leroux
Improves controls when reading results
r394 {
QString line{};
Alexandre Leroux
Improves AMDA result parsing...
r492
Alexandre Leroux
- Changes the way to retrieve unit in AMDA result file: The generated header in the result file differs from the first version...
r775 // Skip comment lines
while (stream.readLineInto(&line) && isCommentLine(line)) {
}
if (!stream.atEnd()) {
do {
Alexandre Leroux
Parser refactoring (5)...
r948 helper.readResultLine(line);
Alexandre Leroux
- Changes the way to retrieve unit in AMDA result file: The generated header in the result file differs from the first version...
r775 } while (stream.readLineInto(&line));
Alexandre Leroux
Improves controls when reading results
r394 }
}
Alexandre Leroux
Amda provider (3)...
r380 } // namespace
Alexandre Leroux
Creates enum that represents the value types that can be read in AMDA...
r563 std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath,
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 DataSeriesType type) noexcept
Alexandre Leroux
Amda provider (3)...
r380 {
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 if (type == DataSeriesType::UNKNOWN) {
Alexandre Leroux
Creates enum that represents the value types that can be read in AMDA...
r563 qCCritical(LOG_AmdaResultParser())
<< QObject::tr("Can't retrieve AMDA data: the type of values to be read is unknown");
return nullptr;
}
Alexandre Leroux
Amda provider (3)...
r380 QFile file{filePath};
if (!file.open(QFile::ReadOnly | QIODevice::Text)) {
qCCritical(LOG_AmdaResultParser())
<< QObject::tr("Can't retrieve AMDA data from file %1: %2")
.arg(filePath, file.errorString());
return nullptr;
}
QTextStream stream{&file};
Alexandre Leroux
Handles "Not found" error for AMDA result parser
r446 // Checks if the file was found on the server
auto firstLine = stream.readLine();
if (firstLine.compare(FILE_NOT_FOUND_MESSAGE) == 0) {
qCCritical(LOG_AmdaResultParser())
<< QObject::tr("Can't retrieve AMDA data from file %1: file was not found on server")
.arg(filePath);
return nullptr;
}
Alexandre Leroux
Move the AMDA data type to a type accessible from core
r1278 auto helper = createHelper(type);
Alexandre Leroux
Parser refactoring (5)...
r948 Q_ASSERT(helper != nullptr);
Alexandre Leroux
Reads x-axis unit in result file
r393
Alexandre Leroux
Parser refactoring (5)...
r948 // Reads header file to retrieve properties
Alexandre Leroux
Changes way to retrieve unit
r791 stream.seek(0); // returns to the beginning of the file
Alexandre Leroux
Parser refactoring (5)...
r948 readProperties(*helper, stream);
Alexandre Leroux
Updates method for reading results according to the value type (vector or scalar)
r564
Alexandre Leroux
Parser refactoring (5)...
r948 // Checks properties
if (helper->checkProperties()) {
// Reads results
// AMDA V2: remove line
stream.seek(0); // returns to the beginning of the file
readResults(*helper, stream);
Alexandre Leroux
Amda provider (3)...
r380
Alexandre Leroux
Parser refactoring (5)...
r948 // Creates data series
return helper->createSeries();
}
else {
return nullptr;
}
Alexandre Leroux
Amda provider (3)...
r380 }