Commit f3433bd3 authored by Oliver Bock's avatar Oliver Bock
Browse files

- Added new parameter (XML vs. binary storage)

- Display warning/confirmation in case the user wants XML for over 100.000 records

git-svn-id: https://svn.origo.ethz.ch/fidelity@22 53d1999f-d1a8-4366-aa61-588fded17473
parent 61118fb4
......@@ -35,6 +35,7 @@ DataStorage::~DataStorage()
delete m_Channel1Label;
delete m_Channel1Unit;
delete m_EnableChannel2;
delete m_EnableBinaryStorage;
delete m_Channel2Label;
delete m_Channel2Unit;
delete m_OutputDescription;
......@@ -132,7 +133,6 @@ void DataStorage::initAttributes()
m_OutputDescription->setValue("Fidelity Output Data");
// Add new parameter to parameter table
m_ParamTable->insert(m_OutputDescription->Identifier(), m_OutputDescription);
m_EnableChannel2 = new Parameter<bool>();
m_EnableChannel2->setIdentifier("enable-channel2");
......@@ -145,6 +145,17 @@ void DataStorage::initAttributes()
// add new parameter to parameter table
m_ParamTable->insert(m_EnableChannel2->Identifier(), m_EnableChannel2);
m_EnableBinaryStorage = new Parameter<bool>();
m_EnableBinaryStorage->setIdentifier("enable-binary-storage");
m_EnableBinaryStorage->setLabel("Enable Binary Storage");
m_EnableBinaryStorage->setUnit("");
m_EnableBinaryStorage->setDescription("This flag defines whether the output is stored as binary data (default). Disable this flag to use XML (VOTable's TABLEDATA) output.");
m_EnableBinaryStorage->setType(ConstantParameter);
m_EnableBinaryStorage->setExposeToParent(true);
m_EnableBinaryStorage->setValue(true);
// add new parameter to parameter table
m_ParamTable->insert(m_EnableBinaryStorage->Identifier(), m_EnableBinaryStorage);
// Set the control nodes
m_ControlNode1 = new ControlNode<double>();
......@@ -230,6 +241,7 @@ void DataStorage::post()
void DataStorage::finalise()
{
const bool channel2Enabled = m_EnableChannel2->Value();
bool binaryStorageEnabled = m_EnableBinaryStorage->Value();
VOTableRoot xml;
VOResource resource;
......@@ -293,41 +305,25 @@ void DataStorage::finalise()
table.setData(&data);
unsigned long size = m_TimeStorage->size();
/**
* For the number of rows being less than 1000 the TABLEDATA format will be used.
* The data is then placed inside the *.fdx (Fidelity Data XML) file.
* Any number exceeding this limit will produce a BINARY representation with the
* data being stored in a extra *.fdb (Fidelity Data Binary) file
*/
if (size < 1000) {
tableData.TRList()->reserve(size);
tableData.TRList()->fill(NULL, size);
tableData.TRList()->squeeze();
data.setTableData(&tableData);
for (unsigned long i = 0;i < size; i++) {
QPointer<VOTR> row = new VOTR();
QPointer<VOTD> col1 = new VOTD();
QPointer<VOTD> col2 = new VOTD();
QPointer<VOTD> col3 = new VOTD();
col1->setContent(QString::number(m_TimeStorage->at(i), 'E', 8));
col2->setContent(QString::number(m_DataStorage1->at(i), 'E', 8));
row->TDList()->append(col1);
row->TDList()->append(col2);
if(channel2Enabled) {
col3->setContent(QString::number(m_DataStorage2->at(i), 'E', 8));
row->TDList()->append(col3);
}
(*tableData.TRList())[i] = row;
// ask for confirmation if TABLEDATA to be used for large amount of records
if (!binaryStorageEnabled && size > 100000) {
if (QMessageBox::warning(
QApplication::activeWindow(),
"Fidelity",
"Warning: you are about to store "+QString::number(size)+" records in plain XML.\n" +
"This will lead to high (or even critical) memory and disk space usage! " +
"It is thus highly recommended to use binary storage!\n\n" +
"Do you want to use binary storage instead?",
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes
) == QMessageBox::Yes) {
binaryStorageEnabled = true;
}
}
else {
if (binaryStorageEnabled) {
data.setBinary(&binary);
binary.setStream(&stream);
stream.setHREF("file://" + fileData.fileName());
......@@ -352,6 +348,32 @@ void DataStorage::finalise()
fileData.close();
}
}
else {
tableData.TRList()->reserve(size);
tableData.TRList()->fill(NULL, size);
tableData.TRList()->squeeze();
data.setTableData(&tableData);
for (unsigned long i = 0;i < size; i++) {
QPointer<VOTR> row = new VOTR();
QPointer<VOTD> col1 = new VOTD();
QPointer<VOTD> col2 = new VOTD();
QPointer<VOTD> col3 = new VOTD();
col1->setContent(QString::number(m_TimeStorage->at(i), 'E', 8));
col2->setContent(QString::number(m_DataStorage1->at(i), 'E', 8));
row->TDList()->append(col1);
row->TDList()->append(col2);
if(channel2Enabled) {
col3->setContent(QString::number(m_DataStorage2->at(i), 'E', 8));
row->TDList()->append(col3);
}
(*tableData.TRList())[i] = row;
}
}
QDomDocument* doc = xml.buildXml();
......
......@@ -27,6 +27,7 @@
#include <QTextStream>
#include <QDataStream>
#include <QPointer>
#include <QMessageBox>
#include <complex>
......@@ -64,7 +65,9 @@ namespace Fidelity {
* <tr><td>output-path</td> <td>&nbsp;</td> <td>File system path (without filename!) where
* the output files should be written to</td></tr>
* <tr><td>enable-channel2</td> <td>&nbsp;</td> <td>Enable the second data channel (control node).<br>
* <i>Note: leads to higher memory and CPU time consumption!</i></td></tr>
* <i>Note: leads to higher memory and CPU time consumption!</i></td></tr>
* <tr><td>enable-binary-storage</td> <td>&nbsp;</td> <td>This flag defines whether the output is stored as binary data (default).<br>
* Disable this flag to use XML (VOTable's TABLEDATA) output.</td></tr>
* </table>
* <br>
* Beam nodes:
......@@ -179,6 +182,12 @@ private:
* This flag defines whether the second data channel is enabled.
*/
Parameter<bool>* m_EnableChannel2;
/**
* This flag defines whether the output is stored as binary data (default).<br>
* Disable this flag to use XML (VOTable's TABLEDATA) output.
*/
Parameter<bool>* m_EnableBinaryStorage;
/**
* The first input control node of the data storage.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment