Commit 8d52cfe2 authored by daniel.bub's avatar daniel.bub
Browse files

[ADD #132] add multiple types for column property

parent ed245f90
......@@ -44,4 +44,4 @@ std::string WDataType::getString()
std::string WDataType::getDefault()
{
return "default";
}
\ No newline at end of file
}
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <regex>
#include <list>
#include <string>
#include <vector>
#include <boost/lexical_cast.hpp>
......@@ -155,14 +156,17 @@ std::string WProtonData::determineColumnTypeByString( std::string cellValue )
if( std::regex_search( cellValue, regexInt ) )
{
std::cout << cellValue << "\t INT" << std::endl;
return WDataType::getInt();
}
else if( std::regex_search( cellValue, regexDouble ) )
{
std::cout << cellValue << "\t DOUBLE" << std::endl;
return WDataType::getDouble();
}
else
{
std::cout << cellValue << "\t STRING" << std::endl;
return WDataType::getString();
}
}
......@@ -186,22 +190,25 @@ bool WProtonData::checkIfDoubleColumnCanBeInteger( int columnNumber )
return true;
}
std::vector< std::string > WProtonData::getHeaderFromType( std::string typeName )
std::vector< std::string > WProtonData::getHeaderFromType( std::list< std::string > typeNames )
{
std::vector< std::string > header = m_csvHeader->at( 0 );
std::vector< std::string > columnTypes = *m_columnTypes;
std::vector< std::string > filterHeader;
if(typeName == WDataType::getDefault() )
{
return header;
}
for( size_t i = 0; i < columnTypes.size(); i++)
{
if( columnTypes[i] == typeName )
for( std::string type : typeNames )
{
filterHeader.push_back( header[i] );
if( type == WDataType::getDefault() )
{
return header;
}
if( columnTypes[ i ] == type )
{
filterHeader.push_back( header[i] );
}
}
}
......
......@@ -26,6 +26,7 @@
#define WPROTONDATA_H
#include <regex>
#include <list>
#include <map>
#include <string>
#include <vector>
......@@ -128,7 +129,7 @@ public:
* \param type Type of filter
* \return Return a vector of filtered Headers
*/
std::vector< std::string > getHeaderFromType( std::string typeName );
std::vector< std::string > getHeaderFromType( std::list< std::string > typeNames );
private:
/**
......
......@@ -69,7 +69,10 @@ WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getXwithDescr
getX(),
"Choose the column which should be used to determine the x coordinate.",
"posX",
WDataType::getDouble() );
std::list< std::string >
{
WDataType::getInt(), WDataType::getDouble()
} );
}
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getYwithDescription()
......@@ -78,7 +81,10 @@ WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getYwithDescr
getY(),
"Choose the column which should be used to determine the y coordinate.",
"posY",
WDataType::getDouble() );
std::list< std::string >
{
WDataType::getInt(), WDataType::getDouble()
} );
}
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getZwithDescription()
......@@ -87,7 +93,10 @@ WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getZwithDescr
getZ(),
"Choose the column which should be used to determine the z coordinate.",
"posZ",
WDataType::getDefault() );
std::list< std::string >
{
WDataType::getInt(), WDataType::getDouble()
} );
}
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getPDGwithDescription()
......@@ -96,7 +105,10 @@ WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getPDGwithDes
getPDG(),
"Choose the column which should be used to determine the particle data group.",
"PDGEncoding",
WDataType::getInt() );
std::list< std::string >
{
WDataType::getInt()
} );
}
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getEdepWithDescription()
......@@ -105,7 +117,10 @@ WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getEdepWithDe
getEdep(),
"Choose the column which should be used to determine the energy deposition.",
"edep",
WDataType::getDouble() );
std::list< std::string >
{
WDataType::getInt(), WDataType::getDouble()
} );
}
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getEventIdWithDescription()
......@@ -115,7 +130,10 @@ WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getEventIdWit
"Choose the column which should be used to determine the event id."
"Tracks will be drawn based on the the event id, all particles with the same event id will be connected.",
"eventID",
WDataType::getInt() );
std::list< std::string >
{
WDataType::getInt()
} );
}
WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getParentIdWithDescription()
......@@ -126,7 +144,10 @@ WSingleSelectorName::NameDescriptionSearchTyp WSingleSelectorName::getParentIdWi
"Primaries and secondaries filtering is based on that id, if a "
"particle has the parent id 0 it is a primary otherwise it is a secondary.",
"parentID",
WDataType::getInt() );
std::list< std::string >
{
WDataType::getInt()
} );
}
std::list< WSingleSelectorName::NameDescriptionSearchTyp > WSingleSelectorName::getListOfSelectorContent()
......
......@@ -44,7 +44,7 @@ public:
* 2. Desciption of single-selector,
* 3. Value that is searched for in the csv header
*/
typedef std::tuple< std::string, std::string, std::string, std::string > NameDescriptionSearchTyp;
typedef std::tuple< std::string, std::string, std::string, std::list < std::string > > NameDescriptionSearchTyp;
/**
* getter
......
......@@ -46,8 +46,8 @@ void WColumnPropertyHandler::createProperties()
m_columnSelectionGroup = m_properties->addPropertyGroup( "Select columns", "Select the columns which should be used" );
std::list< std::tuple< std::string, std::string, std::string, std::string > > names = WSingleSelectorName::getListOfSelectorContent();
for( std::tuple< std::string, std::string, std::string, std::string > selectorElement : names )
std::list< WColumnPropertyHandler::NameDescriptionSearchTyp > names = WSingleSelectorName::getListOfSelectorContent();
for( WColumnPropertyHandler::NameDescriptionSearchTyp selectorElement : names )
{
std::string columnName = std::get< 0 >( selectorElement );
......@@ -66,11 +66,11 @@ void WColumnPropertyHandler::updateProperty()
{
}
boost::shared_ptr< WItemSelection > WColumnPropertyHandler::InitializeSelectionItem( std::string typeName )
boost::shared_ptr< WItemSelection > WColumnPropertyHandler::initializeSelectionItem( std::list< std::string > typeNames )
{
boost::shared_ptr< WItemSelection > possibleSelectionsUsingTypes = WItemSelection::SPtr( new WItemSelection() );
std::vector< std::string > header = m_protonData->getHeaderFromType( typeName );
std::vector< std::string > header = m_protonData->getHeaderFromType( typeNames );
for( std::vector<std::string>::iterator colName = header.begin(); colName != header.end(); colName++ )
{
......@@ -82,7 +82,7 @@ boost::shared_ptr< WItemSelection > WColumnPropertyHandler::InitializeSelectionI
return possibleSelectionsUsingTypes;
}
int WColumnPropertyHandler::getfilterIndex( int index, std::string typeName )
int WColumnPropertyHandler::getFilterIndex( int index, std::list< std::string > typeName )
{
std::vector< std::string > headerToSearch = m_protonData->getCSVHeader()->at( 0 );
......@@ -110,23 +110,17 @@ WPropSelection WColumnPropertyHandler::addHeaderProperty( WColumnPropertyHandler
std::string columnName = std::get< 0 >( ndst );
std::string description = std::get< 1 >( ndst );
std::string defName = std::get< 2 >( ndst );
std::string type = std::get< 3 >( ndst );
std::list< std::string > type = std::get< 3 >( ndst );
int index = m_protonData->getColumnIndex( defName );
int indexSingleSelector = index < 0 ? -1 : getfilterIndex( index, type );
if( indexSingleSelector < 0 )
{
indexSingleSelector = index;
type = WDataType::getDefault();
}
int indexSingleSelector = index < 0 ? -1 : getFilterIndex( index, type );
m_protonData->setStateIndex( columnName, index );
boost::shared_ptr< WItemSelection > possibleSelectionsUsingTypes = InitializeSelectionItem( type );
boost::shared_ptr< WItemSelection > possibleSelectionsUsingTypes = initializeSelectionItem( type );
WItemSelector selector = index < 0 ? possibleSelectionsUsingTypes->getSelectorLast() :
WItemSelector selector = index < 0 ? possibleSelectionsUsingTypes->getSelectorLast() :
possibleSelectionsUsingTypes->getSelector( indexSingleSelector );
WPropSelection selection = m_columnSelectionGroup->addProperty(
......
......@@ -53,7 +53,7 @@ public:
* 2. Desciption of single-selector,
* 3. Value that is searched for in the csv header
*/
typedef std::tuple< std::string, std::string, std::string, std::string > NameDescriptionSearchTyp;
typedef std::tuple< std::string, std::string, std::string, std::list< std::string > > NameDescriptionSearchTyp;
/**
* Function variables for updating the data
......@@ -152,15 +152,15 @@ private:
* \param typeName Type of column.
* \return content of WItemSelection
*/
boost::shared_ptr< WItemSelection > InitializeSelectionItem( std::string typeName );
boost::shared_ptr< WItemSelection > initializeSelectionItem( std::list< std::string > typeName );
/**
* converts the index to the filtered index
* \param index index to search.
* \param typeName Type of column.
* \param typeName List of column types.
* \return filterd index
*/
int getfilterIndex( int index, std::string typeName );
int getFilterIndex( int index, std::list< std::string > typeName );
};
#endif // WCOLUMNPROPERTYHANDLER_H
Markdown is supported
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