summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFrédéric-Emmanuel Picca <picca@debian.org>2018-09-07 10:20:09 +0200
committerFrédéric-Emmanuel Picca <picca@debian.org>2018-09-07 10:20:09 +0200
commitbb00cdb6f8a280e7eca43656ab9e32bf173e9fa0 (patch)
tree2e4d981bc565dfe663a3cd2875b2eb8ad268177f /src
parent81cf0d0f35267847ba3e05382d1239baf6c8ebaa (diff)
New upstream version 1.1.6
Diffstat (limited to 'src')
-rw-r--r--src/fisx_detector.cpp35
-rw-r--r--src/fisx_detector.h7
-rw-r--r--src/fisx_element.cpp57
-rw-r--r--src/fisx_element.h4
-rw-r--r--src/fisx_elements.cpp28
-rw-r--r--src/fisx_math.cpp4
-rw-r--r--src/fisx_multilayer.cpp6
-rw-r--r--src/fisx_simpleini.cpp8
-rw-r--r--src/fisx_version.h2
-rw-r--r--src/fisx_xrf.cpp3
-rw-r--r--src/fisx_xrf.h4
-rw-r--r--src/fisx_xrfconfig.cpp11
12 files changed, 108 insertions, 61 deletions
diff --git a/src/fisx_detector.cpp b/src/fisx_detector.cpp
index 5133f6c..ab4c8fa 100644
--- a/src/fisx_detector.cpp
+++ b/src/fisx_detector.cpp
@@ -2,7 +2,7 @@
#
# The fisx library for X-Ray Fluorescence
#
-# Copyright (c) 2014-2016 European Synchrotron Radiation Facility
+# Copyright (c) 2014-2018 European Synchrotron Radiation Facility
#
# This file is part of the fisx X-ray developed by V.A. Sole
#
@@ -130,22 +130,29 @@ std::map<std::string, std::map<std::string, double> > Detector::getEscape(const
const std::string & label,
const int & update)
{
- if (update != 0)
- this->escapePeakCache.clear();
- if (false) //(label.size())
+ // To implement a cache at the detector level does not work because the same
+ // detector can use different elementsLibrary instances and to use different
+ // labels to identify them does not seem a good idea.
+ // It is preferable to fill the cache at the elements library level
+ if (label.size())
{
- if (this->escapePeakCache.find(label) == this->escapePeakCache.end())
+ if (update != 0)
+ this->escapePeakCache.clear();
+ if (this->escapePeakCache.find(label) != this->escapePeakCache.end())
{
- // calculate it
- this->escapePeakCache[label] = elementsLibrary.getEscape(this->getComposition(elementsLibrary), \
- energy, \
- this->escapePeakEnergyThreshold, \
- this->escapePeakIntensityThreshold, \
- this->escapePeakNThreshold, \
- this->escapePeakAlphaIn,
- 0);
+ if (this->escapePeakCache[label].find(energy) != this->escapePeakCache[label].end())
+ {
+ return this->escapePeakCache[label][energy];
+ }
}
- return this->escapePeakCache[label];
+ this->escapePeakCache[label][energy] = elementsLibrary.getEscape(this->getComposition(elementsLibrary), \
+ energy, \
+ this->escapePeakEnergyThreshold, \
+ this->escapePeakIntensityThreshold, \
+ this->escapePeakNThreshold, \
+ this->escapePeakAlphaIn,
+ 0);
+ return this->escapePeakCache[label][energy];
}
else
{
diff --git a/src/fisx_detector.h b/src/fisx_detector.h
index cf95926..5008893 100644
--- a/src/fisx_detector.h
+++ b/src/fisx_detector.h
@@ -2,7 +2,7 @@
#
# The fisx library for X-Ray Fluorescence
#
-# Copyright (c) 2014-2016 European Synchrotron Radiation Facility
+# Copyright (c) 2014-2018 European Synchrotron Radiation Facility
#
# This file is part of the fisx X-ray developed by V.A. Sole
#
@@ -104,12 +104,13 @@ public:
Returns escape peak energy and rate per detected photon of given energy.
The optional arguments label and update serve for caching purposes.
+ To make use of the cache, the label must not be empty (it should be used to identify the elementsLibrary)
+ and update must be set to 0 because if it is set to 1 it will systematically empty the cascade cache.
*/
std::map<std::string, std::map<std::string, double> > getEscape(const double & energy, \
const Elements & elementsLibrary, \
const std::string & label = "", \
const int & update = 1);
-
void setMinimumEscapePeakEnergy(const double & energy);
void setMinimumEscapePeakIntensity(const double & intensity);
void setMaximumNumberOfEscapePeaks(const int & nPeaks);
@@ -122,7 +123,7 @@ private:
double escapePeakIntensityThreshold;
int escapePeakNThreshold;
double escapePeakAlphaIn;
- std::map< std::string, std::map<std::string, std::map<std::string, double> > > escapePeakCache;
+ std::map< std::string, std::map< double, std::map<std::string, std::map<std::string, double> > > >escapePeakCache;
// TODO: Calibration, fano, noise, and so on.
};
diff --git a/src/fisx_element.cpp b/src/fisx_element.cpp
index 44f411c..1f66526 100644
--- a/src/fisx_element.cpp
+++ b/src/fisx_element.cpp
@@ -2,7 +2,7 @@
#
# The fisx library for X-Ray Fluorescence
#
-# Copyright (c) 2014-2017 European Synchrotron Radiation Facility
+# Copyright (c) 2014-2018 European Synchrotron Radiation Facility
#
# This file is part of the fisx X-ray developed by V.A. Sole
#
@@ -533,6 +533,7 @@ std::map<std::string, std::pair<double, int> > \
}
}
+ /*
if (false)
{
for (result_it = result.begin(); result_it != result.end(); ++result_it)
@@ -542,6 +543,7 @@ std::map<std::string, std::pair<double, int> > \
std::cout << this->name << " Found shell " << key << " at " << energy << std::endl;
}
}
+ */
return result;
}
@@ -1280,10 +1282,9 @@ Element::getXRayLinesFromVacancyDistribution(const std::map<std::string, double>
if (cacheKey == cascadeCache.end())
{
std::cout << this->name << " Error processing vacancy on shell " << c_it->first << std::endl;
- throw std::runtime_error("Vacancy on a shell not present in the cache!");
+ throw std::runtime_error("Vacancy in a shell not present in the cache!");
// the above is not good, there can be no emission following a vacancy (rate too low)
// it seems to be triggered by As L1 vacancies
- continue;
}
for(std::map<std::string, std::map<std::string, double> >::const_iterator rayIt = \
cacheKey->second.begin(); rayIt != cacheKey->second.end(); ++rayIt)
@@ -1657,6 +1658,7 @@ void Element::clearCache()
void Element::fillCache(const std::vector<double> & energy)
{
std::vector<double>::size_type i, maxSize;
+ int status;
this->clearCache();
@@ -1668,31 +1670,58 @@ void Element::fillCache(const std::vector<double> & energy)
{
maxSize = this->cacheMaximumSize;
}
- for (i = 0; i < maxSize; i++)
+ status = this->isCacheEnabled();
+ try
{
- this->muCache[energy[i]] = this->getMassAttenuationCoefficients(energy[i]);
- this->excitationFactorsCache[energy[i]] = this->getPhotoelectricExcitationFactors(energy[i], 1.0);
+ // This is necessary because clang pushes return value optimization to the limit
+ // and creates the key into muCache prior to call getMassAttenuationCoefficients
+ this->setCacheEnabled(0);
+ for (i = 0; i < maxSize; i++)
+ {
+ this->muCache[energy[i]] = this->getMassAttenuationCoefficients(energy[i]);
+ this->excitationFactorsCache[energy[i]] = this->getPhotoelectricExcitationFactors(energy[i], 1.0);
+ }
+ this->setCacheEnabled(status);
+ }
+ catch(...)
+ {
+ this->setCacheEnabled(status);
+ throw;
}
}
void Element::updateCache(const std::vector< double> & energy)
{
std::vector<double>::size_type i, eSize;
+ int status;
+ // This is necessary because clang pushes return value optimization to the limit
+ // and creates the key into muCache prior to call getMassAttenuationCoefficients
+ status = this->isCacheEnabled();
+ this->setCacheEnabled(0);
eSize = energy.size();
- for (i = 0; i < eSize; i++)
+ try
{
- if (this->muCache.size() < this->cacheMaximumSize)
+ for (i = 0; i < eSize; i++)
{
- if (this->muCache.find(energy[i]) == this->muCache.end())
- {
- this->muCache[energy[i]] = this->getMassAttenuationCoefficients(energy[i]);
- }
- if (this->excitationFactorsCache.find(energy[i]) == this->excitationFactorsCache.end())
+ if (this->muCache.size() < this->cacheMaximumSize)
{
- this->excitationFactorsCache[energy[i]] = this->getPhotoelectricExcitationFactors(energy[i], 1.0);
+ if (this->muCache.find(energy[i]) == this->muCache.end())
+ {
+ this->muCache[energy[i]] = this->getMassAttenuationCoefficients(energy[i]);
+ }
+ if (this->excitationFactorsCache.find(energy[i]) == this->excitationFactorsCache.end())
+ {
+ this->excitationFactorsCache[energy[i]] = this->getPhotoelectricExcitationFactors(energy[i], 1.0);
+ }
}
}
+ this->setCacheEnabled(status);
+ }
+ catch(...)
+ {
+ this->setCacheEnabled(status);
+ throw;
}
if (this->muCache.size() >= this->cacheMaximumSize)
{
diff --git a/src/fisx_element.h b/src/fisx_element.h
index 99a8322..388b32b 100644
--- a/src/fisx_element.h
+++ b/src/fisx_element.h
@@ -2,7 +2,7 @@
#
# The fisx library for X-Ray Fluorescence
#
-# Copyright (c) 2014-2016 European Synchrotron Radiation Facility
+# Copyright (c) 2014-2018 European Synchrotron Radiation Facility
#
# This file is part of the fisx X-ray developed by V.A. Sole
#
@@ -370,7 +370,7 @@ private:
std::map<std::string, std::vector<double> > muPartialPhotoelectricValue;
// A cache for storing calculations
- static const int cacheMaximumSize = 10000;
+ static const unsigned int cacheMaximumSize = 10000;
bool calculationCacheEnabledFlag;
std::map< double, std::map< std::string, double> > muCache;
std::map< double, std::map<std::string, std::map<std::string, double> > > excitationFactorsCache;
diff --git a/src/fisx_elements.cpp b/src/fisx_elements.cpp
index dbbfcc8..a7e9080 100644
--- a/src/fisx_elements.cpp
+++ b/src/fisx_elements.cpp
@@ -2,7 +2,7 @@
#
# The fisx library for X-Ray Fluorescence
#
-# Copyright (c) 2014-2017 European Synchrotron Radiation Facility
+# Copyright (c) 2014-2018 European Synchrotron Radiation Facility
#
# This file is part of the fisx X-ray developed by V.A. Sole
#
@@ -810,7 +810,7 @@ void Elements::setMassAttenuationCoefficients(const std::string & name,
shell = shellList[shellIndex];
if (extractedEdgeEnergies.find(shell) != extractedEdgeEnergies.end())
{
- if ((i - j - 1) == extractedEdgeEnergies[shell].second)
+ if ((i - j - 1) == static_cast<unsigned int>(extractedEdgeEnergies[shell].second))
{
// We are just above an edge according to the input mass attenuation coefficients
// We have to check if that energy is compatible with the binding energy.
@@ -1550,6 +1550,7 @@ std::map<std::string, double> Elements::parseFormula(const std::string & formula
}
// look for parenthesis
+ parsingKey = false;
spacesPresent = false;
for(i=0; i < formula.size(); i++)
{
@@ -1918,14 +1919,6 @@ std::map<std::string,std::map<std::string, double> > Elements::getEscape( \
// std::cout << "USING CACHE" << energy << std::endl;
return it->second;
}
- else
- {
- // std::cout << "ENERGY NOT THERE" << energy << std::endl;
- }
- }
- else
- {
- // std::cout << "NOT COMPATIBLE" << std::endl;
}
if (alphaIn == 90.)
@@ -1942,7 +1935,16 @@ std::map<std::string,std::map<std::string, double> > Elements::getEscape( \
result.clear();
if (thickness > 0.0)
+ {
intrinsicEfficiency = (1.0 - std::exp(-muIncident * thickness / sinAlphaIn));
+ }
+ else
+ {
+ // this is just to get rid of a not very clever non-initialized warning because
+ // if thickness is not bigger than 0.0 intrinsicEfficiency will not be used in
+ // any case.
+ intrinsicEfficiency = 1.0;
+ }
for (c_it = composition.begin(); c_it != composition.end(); c_it++)
{
element = c_it->first;
@@ -1951,15 +1953,15 @@ std::map<std::string,std::map<std::string, double> > Elements::getEscape( \
std::map<std::string, std::map<std::string, double> >::const_iterator it;
std::map<std::string, double>::const_iterator mapIt;
// factor uses mu["shell photoelectric"] / mu["total photoelectric"]
- double factor;
+ // double factor;
// rate uses mu["shell photoelectric"]
// It is the product factor * mu["total photoelectric"]
double rate;
double fluorescentEnergy;
for ( it = excitationFactors.begin(); it != excitationFactors.end(); ++it)
{
- mapIt = it->second.find("factor");
- factor = mapIt->second;
+ // mapIt = it->second.find("factor");
+ // factor = mapIt->second;
mapIt = it->second.find("rate");
rate = mapIt->second;
mapIt = it->second.find("energy");
diff --git a/src/fisx_math.cpp b/src/fisx_math.cpp
index 6cf28bb..7294479 100644
--- a/src/fisx_math.cpp
+++ b/src/fisx_math.cpp
@@ -2,7 +2,7 @@
#
# The fisx library for X-Ray Fluorescence
#
-# Copyright (c) 2014-2016 European Synchrotron Radiation Facility
+# Copyright (c) 2014-2018 European Synchrotron Radiation Facility
#
# This file is part of the fisx X-ray developed by V.A. Sole
#
@@ -315,7 +315,7 @@ double Math::deBoerL0(const double & mu1, const double & mu2, const double & muj
double Math::deBoerX(const double & p, const double & q, const double & d1, const double & d2, \
const double & mu1j, const double & mu2j, const double & mubj_dt)
{
- if(false)
+ if ((false))
{
double result;
result = Math::deBoerV(p, q, d1, d2, mu1j, mu2j, mubj_dt) - \
diff --git a/src/fisx_multilayer.cpp b/src/fisx_multilayer.cpp
index b29a8e8..124b967 100644
--- a/src/fisx_multilayer.cpp
+++ b/src/fisx_multilayer.cpp
@@ -2,7 +2,7 @@
#
# The fisx library for X-Ray Fluorescence
#
-# Copyright (c) 2014-2017 European Synchrotron Radiation Facility
+# Copyright (c) 2014-2018 European Synchrotron Radiation Facility
#
# This file is part of the fisx X-ray developed by V.A. Sole
#
@@ -519,7 +519,8 @@ std::map<std::string, std::map<int, std::map<std::string, std::map<std::string,
//std::cout << c_it->first << "primary = " << result[c_it->first]["primary"] << std::endl;
//std::cout << c_it->first << "energy = " << result[c_it->first]["energy"] << std::endl;
//std::cout << c_it->first << "mu_1_i = " << result[c_it->first]["mu_1_i"] << std::endl;
- if (false && (c_it->first == "KL2") && (iLayer == 0))
+ /*
+ if ((c_it->first == "KL2") && (iLayer == 0))
{
std::cout << c_it->first << "efficiency = " << result[c_it->first]["efficiency"] << std::endl;
std::cout << c_it->first << "primary = " << result[c_it->first]["primary"] << std::endl;
@@ -532,6 +533,7 @@ std::map<std::string, std::map<int, std::map<std::string, std::map<std::string,
std::cout << c_it->first << "mu_1_lambda/sinALphain = " << mu_1_lambda / sinAlphaIn<< std::endl;
std::cout << c_it->first << "mu_1_i/sinALphaOut = " << mu_1_i / sinAlphaOut<< std::endl;
}
+ */
}
if (secondary > 0)
diff --git a/src/fisx_simpleini.cpp b/src/fisx_simpleini.cpp
index ad5d9be..e2a92e7 100644
--- a/src/fisx_simpleini.cpp
+++ b/src/fisx_simpleini.cpp
@@ -2,7 +2,7 @@
#
# The fisx library for X-Ray Fluorescence
#
-# Copyright (c) 2014-2016 European Synchrotron Radiation Facility
+# Copyright (c) 2014-2018 European Synchrotron Radiation Facility
#
# This file is part of the fisx X-ray developed by V.A. Sole
#
@@ -66,8 +66,14 @@ void SimpleIni::readFileName(std::string fileName)
std::ifstream fileInstance(fileName.c_str(), std::ios::in | std::ios::binary);
std::string msg;
+ if (!fileInstance.good())
+ {
+ msg = "File <" + fileName + "> mot accessible";
+ throw std::ios_base::failure(msg);;
+ }
this->sections.clear();
this->sectionPositions.clear();
+ p0 = 0;
position = 0;
numberOfLines = -1;
while (std::getline(fileInstance, line))
diff --git a/src/fisx_version.h b/src/fisx_version.h
index 18a02f9..de08169 100644
--- a/src/fisx_version.h
+++ b/src/fisx_version.h
@@ -29,7 +29,7 @@
#define FISX_VERSION_H
#include <string>
-#define FISX_VERSION_STR "1.1.5"
+#define FISX_VERSION_STR "1.1.6"
namespace fisx
{
diff --git a/src/fisx_xrf.cpp b/src/fisx_xrf.cpp
index b7e45e9..70dd299 100644
--- a/src/fisx_xrf.cpp
+++ b/src/fisx_xrf.cpp
@@ -2,7 +2,7 @@
#
# The fisx library for X-Ray Fluorescence
#
-# Copyright (c) 2014-2016 European Synchrotron Radiation Facility
+# Copyright (c) 2014-2018 European Synchrotron Radiation Facility
#
# This file is part of the fisx X-ray developed by V.A. Sole
#
@@ -192,7 +192,6 @@ std::map<std::string, std::map<int, std::map<std::string, std::map<std::string,
std::vector<std::string> elementList;
std::vector<std::string> familyList;
std::vector<int> layerList;
- std::vector<std::string>::size_type i;
std::string tmpString;
std::vector<std::string> tmpStringVector;
diff --git a/src/fisx_xrf.h b/src/fisx_xrf.h
index 438525d..2c83e65 100644
--- a/src/fisx_xrf.h
+++ b/src/fisx_xrf.h
@@ -2,7 +2,7 @@
#
# The fisx library for X-Ray Fluorescence
#
-# Copyright (c) 2014-2016 European Synchrotron Radiation Facility
+# Copyright (c) 2014-2018 European Synchrotron Radiation Facility
#
# This file is part of the fisx X-ray developed by V.A. Sole
#
@@ -135,7 +135,7 @@ public:
/*!
Set the reference layer. The detector distance is measured from the reference layer surface.
- If not specified, the lauer closest to the detector
+ If not specified, the layer closest to the detector
*/
void setReferenceLayer(const int & index);
void setRefenceLayer(const std::string & name);
diff --git a/src/fisx_xrfconfig.cpp b/src/fisx_xrfconfig.cpp
index ba2fdaa..7be5867 100644
--- a/src/fisx_xrfconfig.cpp
+++ b/src/fisx_xrfconfig.cpp
@@ -2,7 +2,7 @@
#
# The fisx library for X-Ray Fluorescence
#
-# Copyright (c) 2014-2016 European Synchrotron Radiation Facility
+# Copyright (c) 2014-2018 European Synchrotron Radiation Facility
#
# This file is part of the fisx X-ray developed by V.A. Sole
#
@@ -65,12 +65,14 @@ void XRFConfig::readConfigurationFromFile(const std::string & fileName)
std::vector<std::string> splitString;
Material material;
Layer layer;
- bool fisxFile;
long counter;
bool multilayerSample;
double value;
+
// find out if it is a fix or a PyMca configuration file
+ /* This not needed since a fisx file format is not defined yet
+ bool fisxFile;
sectionContents.clear();
sectionContents = iniFile.readSection("fisx", false);
fisxFile = true;
@@ -78,11 +80,10 @@ void XRFConfig::readConfigurationFromFile(const std::string & fileName)
{
fisxFile = false;
}
- /*
if (fisxFile)
{
std::cout << "Not implemented" << std::endl;
- return;
+ throw std::invalid_argument("Only PyMca configuration files supported.");
}
*/
@@ -98,7 +99,7 @@ void XRFConfig::readConfigurationFromFile(const std::string & fileName)
sectionContents = iniFile.readSection("result.config", false);
if(!sectionContents.size())
{
- throw std::invalid_argument("File not recognized as a fisx or PyMca configuration file.");
+ throw std::invalid_argument("File not recognized as a PyMca configuration file.");
}
std::cout << "fit result file" << std::endl;
}