Commit ae1e8599 authored by Hung Dang-Quoc's avatar Hung Dang-Quoc
Browse files

Merge remote-tracking branch...

Merge remote-tracking branch 'origin/top2021s3/set_n_select_pdg_particle_names' into top2021s3/#60_support_new_csv_dataset_test

# Conflicts:
#	src/modules/filterProtonData/propertyHandler/WMFilterPropertyHandler.cpp
#	src/modules/filterProtonData/propertyHandler/WMFilterPropertyHandler.h
parents 8271f9e9 94bfb867
......@@ -43,6 +43,7 @@ void WMFilterPropertyHandler::createProperties()
createCheckBoxForPrimaryAndSecondary();
createMultiSelectionForPDG();
createPropToSetParticleNames();
updateProperty();
}
......@@ -150,7 +151,7 @@ void WMFilterPropertyHandler::updateSelectedPDGTypes()
bool WMFilterPropertyHandler::isPDGTypeSelected( int pdgType )
{
WItemSelector selectedItems = m_multiSelection->get( true );
for( size_t i = 0; i < selectedItems.size(); ++i )
{
if(getPdgFromName( selectedItems.at( i )->getName()) == pdgType)
......@@ -183,6 +184,8 @@ void WMFilterPropertyHandler::updateCheckboxProperty( WPropertyBase::SPtr proper
void WMFilterPropertyHandler::createPDGMap( std::string path )
{
m_PdgParticelNamePath= path;
std::fstream pdgSignFile;
std::string dataRow;
bool firstLine = true;
......@@ -198,7 +201,7 @@ void WMFilterPropertyHandler::createPDGMap( std::string path )
while( std::getline( pdgSignFile, dataRow ) )
{
if(firstLine)
if( firstLine )
{
firstLine = false;
continue;
......@@ -237,7 +240,7 @@ int WMFilterPropertyHandler::getPdgFromName( std::string particleName )
std::regex regexp( "[-+0-9]+" );
std::smatch m;
std::regex_search( particleName, m, regexp );
return std::stoi(m[0]);
return std::stoi( m[0] );
}
}
......@@ -250,3 +253,42 @@ WPropBool WMFilterPropertyHandler::getShowSecondaries()
{
return m_showSecondaries;
}
void WMFilterPropertyHandler::changePdgBiMap( int pdg, std::string newParticleName )
{
BM_PDG::right_iterator pdg_iter = m_PdgNamesByID.right.find( pdg );
if( pdg_iter != m_PdgNamesByID.right.end() )
{
bool success_replace = m_PdgNamesByID.right.replace_data( pdg_iter, newParticleName );
if( !success_replace )
{
throw WException( "Fail to replace new particle name" );
}
}
else //unknown particle
{
m_PdgNamesByID.insert( PdgElement( newParticleName, pdg ) );
}
writePdgMapInParticleNameFile();
}
void WMFilterPropertyHandler::writePdgMapInParticleNameFile()
{
std::ofstream pdgSignFile;
pdgSignFile.open( m_PdgParticelNamePath, std::ios_base::out | std::ios::trunc );
if( !pdgSignFile.is_open() )
{
throw WException( "File could not be opened!" );
}
for( auto pdgNameIterator = m_PdgNamesByID.begin(); pdgNameIterator != m_PdgNamesByID.end(); ++pdgNameIterator )
{
pdgSignFile << pdgNameIterator->left << " " << pdgNameIterator->right << "\n";
}
m_saveButton->set( WPVBaseTypes::PV_TRIGGER_READY, false );
pdgSignFile.close();
}
......@@ -132,9 +132,20 @@ private:
/**
* update the m_selectedPDGTypes
*
* \param property contains reference to the property which called updateProperty()
*
*/
void updateSelectedPDGTypes();
/**
* event of the save button in the rename pdg subgroup
*
* \param property contains reference to the property which called updateProperty()
*
*/
void saveRenameParticleButtonClick( WPropertyBase::SPtr property );
/**
* create the Checkbox for primaries and secondaries
*/
......@@ -175,6 +186,20 @@ private:
*/
int getPdgFromName( std::string particleName );
/**
* write the BiMap in the Pdg particle name file
*/
void writePdgMapInParticleNameFile();
/**
* set or replace a particlename and pdg in the bimap
*
* \param pdg pdg number of a selected particle name
* \param newParticleName new particlename of a pdg number
* \throws WException
*/
void changePdgBiMap( int pdg, std::string newParticleName );
/**
* A Map of the PDG and their names
*/
......@@ -190,7 +215,7 @@ private:
*/
std::vector < int > m_pdgTypes;
/**
/**
* Property group for filtering options
*/
WPropGroup m_filteringGroup;
......@@ -214,6 +239,26 @@ private:
* vector of the options of PDG
*/
std::vector < int > m_selectedPDGTypes;
/**
* A string for the new particle name
*/
WPropString m_aString;
/**
* A trigger for the save button to save changes
*/
WPropTrigger m_saveButton;
/**
* A property to select one pdg to change
*/
WPropSelection m_PdgForRenameSelection;
/**
* a string of the share folder path of particle proton module
*/
std::string m_PdgParticelNamePath;
};
#endif // WMFILTERPROPERTYHANDLER_H
......@@ -21,7 +21,7 @@ antilambda 3122
pion- -211
pion+ 211
pion0 111
kaon-, 321
kaon- 321
kaon+ 321
kaon0 311
kaon0L 130
......
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