text:
///////////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2008-2012  Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
//
//  See accompanying file COPYING.TXT file for licensing details.
//
///////////////////////////////////////////////////////////////////////////////
#define CPPCMS_SOURCE
#include "winservice.h"
#include <booster/nowide/convert.h>
#include <booster/system_error.h>
#include <cppcms/cppcms_error.h>

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include <windows.h>
#include <winsvc.h>
#include <process.h>
#include <booster/function.h>
#include <booster/log.h>

namespace cppcms {
namespace impl {

winservice::winservice()
{
}

winservice::~winservice()
{
}

winservice &winservice::instance()
{
	static winservice inst;
	return inst;
}

void winservice::uninstall()
{
	std::wstring name = booster::nowide::convert(settings_.get<std::string>("winservice.name"));

	SC_HANDLE schm = OpenSCManagerW(0,0,SC_MANAGER_ALL_ACCESS);
	if(!schm) {
		throw booster::system::system_error(
			GetLastError(),
			booster::system::windows_category,
			"Failed to open sevice imager");
	}

	SC_HANDLE service_handle = OpenServiceW(schm,name.c_str(),DELETE);
	if(service_handle == NULL) {
		booster::system::error_code e(GetLastError(),booster::system::windows_category);
		CloseServiceHandle(schm);
		throw booster::system::system_error(e,"Failed to open the service");
	}
	if(!DeleteService(service_handle)) {
		booster::system::error_code e(GetLastError(),booster::system::windows_category);
		CloseServiceHandle(service_handle);
		CloseServiceHandle(schm);
		throw booster::system::system_error(e,"Failed to delete the service");
	}
	CloseServiceHandle(service_handle);
	CloseServiceHandle(schm);
	std::cout << "The service uninstalled sucessefully" << std::endl;
}

void winservice::install()
{
	std::wstring name = booster::nowide::convert(settings_.get<std::string>("winservice.name"));
	std::wstring display_name = booster::nowide::convert(settings_.get<std::string>("winservice.display_name"));
	std::string start_type = settings_.get("winservice.start","auto");
	std::wstring cmd_line;

	std::wstring user_name,password;
	wchar_t const *cuser_name=0,*cpassword=0;
	if(!settings_.find("winservice.username").is_undefined()) {
		user_name = booster::nowide::convert(settings_.get<std::string>("winservice.username"));
		cuser_name = user_name.c_str();
	}
	if(!settings_.find("winservice.password").is_undefined()) {
		password = booster::nowide::convert(settings_.get<std::string>("winservice.password"));
		cpassword = password.c_str();
	}

	wchar_t exe[ MAX_PATH + 1];
	if(GetModuleFileNameW(0,exe,MAX_PATH+1) == 0) {
		booster::system::error_code e(GetLastError(),booster::system::windows_category);
		throw booster::system::system_error(e,"Failed to get exe name");
	}
	cmd_line = L"\"";
	cmd_line +=exe;
	cmd_line +=L"\"";
	bool found = false;

	for(size_t i=1;i<args_.size();i++) {
		std::wstring parameter = booster::nowide::convert(args_[i]);
		if(parameter==L"--winservice-mode=install") {
			parameter = L"--winservice-mode=run";
			found = true;
		}
		cmd_line+=L" \"";
		cmd_line+=parameter;
		cmd_line+=L"\"";
	}
	if(!found) {
		throw cppcms_error("Parameter --winservice-mode=install is not provided via command line!");
	}

	BOOSTER_DEBUG("cppcms") << "Installing with parameters" << booster::nowide::convert(cmd_line);

	DWORD start_type_flag = 0;
	if(start_type == "auto")
		start_type_flag= SERVICE_AUTO_START;
	else if(start_type == "demand")
		start_type_flag= SERVICE_DEMAND_START;
	else
		throw cppcms_error("Parameter winservice.mode should be one of auto or demand");

	SC_HANDLE schm = OpenSCManagerW(0,0,SC_MANAGER_ALL_ACCESS);
	if(!schm) {
		booster::system::error_code e(GetLastError(),booster::system::windows_category);
		throw booster::system::system_error(e,"Failed to open sevice imager");
	}

	SC_HANDLE service_handle = CreateServiceW(
		schm,
		name.c_str(),
		display_name.c_str(),
		SERVICE_ALL_ACCESS,
		SERVICE_WIN32_OWN_PROCESS,
		start_type_flag,
		SERVICE_ERROR_NORMAL,
		cmd_line.c_str(),
		0, // load order group
		0, // tagid
		0, // dependencies
		cuser_name,
		cpassword
	);

	if(service_handle == NULL) {
		booster::system::error_code e(GetLastError(),booster::system::windows_category);
		CloseServiceHandle(schm);
		throw booster::system::system_error(e,"Failed to install service");
	}
	CloseServiceHandle(service_handle);
	CloseServiceHandle(schm);
	std::cout << "The service installed sucessefully" << std::endl;
}

namespace {
	SERVICE_STATUS_HANDLE status_handle;
	SERVICE_STATUS status;

	void WINAPI win_service_handler_proc(DWORD code)
	{
		if(code == SERVICE_CONTROL_SHUTDOWN  || code == SERVICE_CONTROL_STOP) {
			status.dwCurrentState = SERVICE_STOP_PENDING;
			status.dwControlsAccepted = 0;
			status.dwWaitHint = 10000;
			SetServiceStatus(status_handle,&status);
			winservice::instance().stop();
			return;
		}
		SetServiceStatus(status_handle,&status);

	}
	void WINAPI win_service_main(DWORD,wchar_t **)
	{
		status_handle = RegisterServiceCtrlHandlerW(L"",win_service_handler_proc);
		if(status_handle==0) {
			booster::system::error_code e(GetLastError(),booster::system::windows_category);
			BOOSTER_ERROR("cppcms") << "Failed to register windows service handle:" << e.message();
			return;
		}
		status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
		try {
			status.dwWaitHint = 10000;
			status.dwCurrentState = SERVICE_START_PENDING;
			status.dwControlsAccepted = (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN);
			SetServiceStatus(status_handle,&status);

			winservice::instance().prepare();

			status.dwWaitHint = 0;
			status.dwCurrentState = SERVICE_RUNNING;
			SetServiceStatus(status_handle,&status);

			winservice::instance().exec();

		}
		catch(std::exception const &e ){
			BOOSTER_ERROR("cppcms") << "Main loop stopped:" << e.what() << booster::trace(e);
			status.dwWin32ExitCode = 1;
		}
		catch(...) {
			BOOSTER_ERROR("cppcms") << "Main loop stopped for unknown exception";
			status.dwWin32ExitCode = 1;
		}

		status.dwCurrentState = SERVICE_STOPPED;
		status.dwWaitHint = 0;
		SetServiceStatus(status_handle,&status);
		return;

	}
} // anonymous

void winservice::service()
{
	static wchar_t empty_wide_string = 0;
	SERVICE_TABLE_ENTRYW entry[2] = {
		{ &empty_wide_string ,win_service_main },
		{ 0,0 }
	};
	if(!StartServiceCtrlDispatcherW(entry)) {
		booster::system::error_code e(GetLastError(),booster::system::windows_category);
		throw booster::system::system_error(e,"Failed to start windows service");
	}
}

void winservice::run(json::value &conf,int argc,char **argv)
{
	args_.assign(argv,argv+argc);
	settings_=conf;
	std::string mode = settings_.get("winservice.mode","console");
	if(mode == "console")
		throw cppcms_error("console mode should not use winservice class");
	else if(mode == "install")
		install();
	else if(mode == "uninstall")
		uninstall();
	else if(mode == "run") {
		conf.set("service.disable_global_exit_handling",true);
		service();
	}
	else
		throw cppcms_error("Invalid option winservice.mode=" + mode);
}

} // impl
} // cppcms

ext: cpp

max_stars_repo_name: gatehouse/cppcms

max_issues_repo_name: gatehouse/cppcms

max_forks_repo_name: gatehouse/cppcms


text:
// includes
#include "predikct/motion_candidate_node.h"
#include "predikct/motion_state.h"
#include "predikct/user_prediction_node.h"
#include "predikct/reward_calculator.h"
#include <random>
#include <kdl/frames.hpp>
#include <Eigen/Eigenvalues>

namespace predikct
{

struct normal_random_variable
{
    normal_random_variable(Eigen::MatrixXd const& covar)
        : normal_random_variable(Eigen::VectorXd::Zero(covar.rows()), covar)
    {}

    normal_random_variable(Eigen::VectorXd const& mean, Eigen::MatrixXd const& covar)
        : mean(mean)
    {
        Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eigenSolver(covar);
        transform = eigenSolver.eigenvectors() * eigenSolver.eigenvalues().cwiseSqrt().asDiagonal();
    }

    Eigen::VectorXd mean;
    Eigen::MatrixXd transform;

    Eigen::VectorXd operator()() const
    {
        static std::mt19937 gen{ std::random_device{}() };
        static std::normal_distribution<> dist;

        return mean + transform * Eigen::VectorXd{ mean.size() }.unaryExpr([&](double x) { return dist(gen); });
    }
};

MotionCandidateNode::MotionCandidateNode(TreeNode* parent, RobotModel* robot_model, boost::shared_ptr<MotionState> state, int tree_depth,
    TreeSpec* tree_spec, RewardCalculator* reward_calculator, UserModel* user_model, std::vector<double>* desired_velocity)
    : TreeNode(parent, robot_model, state, tree_depth, tree_spec, reward_calculator, user_model)
{
    desired_velocity_ = Eigen::Map<Eigen::VectorXd>(&((*desired_velocity)[0]), desired_velocity->size());
    state->CalculateJacobian(robot_model);
    candidates_generated_ = false;
    desired_velocity_raw_ = std::vector<double>(desired_velocity->size());
    desired_movement_ = std::vector<double>(desired_velocity->size());
    for(int i = 0; i < desired_velocity_raw_.size(); i++)
    {
        desired_velocity_raw_[i] = (*desired_velocity)[i];
        desired_movement_[i] = ((*desired_velocity)[i])*tree_spec_->time_window;
    }
    is_leaf_ = tree_depth >= tree_spec->tree_depth;
}

// Generate a set of set of joint motion candidates,
//  each of which leads to a User Prediction node
std::vector<boost::shared_ptr<TreeNode>> MotionCandidateNode::GenerateChildren()
{
    children_.clear();
    motion_candidates_.clear();

    //Calculate movement that satisfies desired velocity using pseudo-inverse
    Eigen::VectorXd primary_movement = state_->pseudo_inverse * desired_velocity_;

    //Generate possible movement commands for using redundant DOF within null space of pseudo-inverse
    GetNullSpace();
    //Generate null space movement around following the same null movement goals from previous timesteps with added noise sampled from a multivariate distribution with mean of previous null space motion and covariance = identity matrix
    Eigen::VectorXd base_null_eigen(state_->joint_positions.size());
    Eigen::VectorXd target_null_eigen(state_->joint_positions.size());
    Eigen::VectorXd mean_null_eigen(state_->joint_positions.size());
    bool all_zeros = true;
    for(int j = 0; j < state_->joint_positions.size(); j++)
    {
        base_null_eigen(j) = state_->null_goals[j];
        if(base_null_eigen(j) != 0.0)
        {
            all_zeros = false;
        }
    }
    // Find the mean of the last null vector and the current gradient of the manipulability index
    Eigen::Matrix<double,Eigen::Dynamic, Eigen::Dynamic> covariance = Eigen::Matrix<double,Eigen::Dynamic, Eigen::Dynamic>::Identity(state_->joint_positions.size(),state_->joint_positions.size());

    // CALCULATION OF GRADIENT OF MANIPULABILITY INDEX
    // Calculation of derivative source: https://arxiv.org/pdf/1908.02963.pdf (page 3, left column)
    // Step 1: Calculate the manipulability index
    state_->CalculateManipulability(robot_model_);
    Eigen::Matrix<double,6,Eigen::Dynamic> jac_dot;
    double k_gradient_weight = 25;
    for(int j = 0; j < state_->joint_positions.size(); j++)
    {
        // Step 2: Find the partial derivative of the Jacobian with respect to the current joint
        robot_model_->GetJacobianDot(state_->joint_positions, j, &jac_dot);
        // Steps 3 & 4: Find the trace of partial derivative of Jacobian times pseudoinverse, then multiply answer from Step 3 by Step 1 to get gradient
        target_null_eigen(j) = k_gradient_weight * state_->manipulability * ((jac_dot * state_->pseudo_inverse).trace());

        if(all_zeros)
        {
            mean_null_eigen(j) = target_null_eigen(j);
            covariance(j,j) = 0.1;
        }
        else
        {
            mean_null_eigen(j) = (base_null_eigen(j) + target_null_eigen(j)) / 2.0;
            covariance(j,j) = pow(std::abs(base_null_eigen(j) - target_null_eigen(j)), 2) / 2.0;
        }
    }

    normal_random_variable noise_sample { mean_null_eigen, covariance };

    //Generate number of children according to branching factor
    Eigen::VectorXd total_movement;
    for(int i = 0; i < tree_spec_->motion_candidate_branching_factor; i++)
    {
        Eigen::VectorXd null_movement_eigen(state_->joint_positions.size());
        if(i == 0){
            null_movement_eigen = base_null_eigen;
        } else {
            null_movement_eigen = noise_sample();
        }

        total_movement = primary_movement + null_space_*null_movement_eigen;

        //Create new motion candidate
        std::vector<double> motion_candidate;
        motion_candidate.resize(total_movement.size());
        Eigen::VectorXd::Map(&motion_candidate[0], total_movement.size()) = total_movement;
        std::vector<double> null_goals;
        null_goals.resize(null_movement_eigen.size());
        Eigen::VectorXd::Map(&null_goals[0], null_movement_eigen.size()) = null_movement_eigen;
        boost::shared_ptr<MotionState> new_motion_candidate(new MotionState(&(state_->joint_positions), &(state_->joint_velocities), &motion_candidate, &null_goals, tree_spec_->time_window, robot_model_, node_depth_ * tree_spec_->time_window));
        motion_candidates_.push_back(new_motion_candidate);
        if(!is_leaf_)
        {
            //Create new child node
            children_.push_back(boost::shared_ptr<TreeNode> (new UserPredictionNode(this, robot_model_, new_motion_candidate,
                node_depth_, tree_spec_, reward_calc_, user_model_, &desired_velocity_raw_)));
        }
    }

    candidates_generated_ = true;
    return children_;
}

double MotionCandidateNode::CalculateReward()
{
    if(!candidates_generated_)
    {
        GenerateChildren();
    }

    //Calculate ideal position after applying desired velocity
    state_->CalculatePosition(robot_model_);
    KDL::Frame ideal_position( KDL::Rotation::RPY(desired_movement_[3], desired_movement_[4], desired_movement_[5]) * state_->position.M,
        state_->position.p + KDL::Vector(desired_movement_[0], desired_movement_[1], desired_movement_[2]));

    double x, y, z, w;
    state_->position.M.GetQuaternion(x, y, z, w);
    ideal_position.M.GetQuaternion(x, y, z, w);
    double max_reward = reward_calc_->EvaluateMotionCandidate(robot_model_, state_, motion_candidates_[0], &ideal_position);
    if(!is_leaf_){
        max_reward += children_[0]->GetReward();
    }
    best_candidate_index_ = 0;
    for(int i = 1; i < motion_candidates_.size(); i++)
    {
        double new_reward = reward_calc_->EvaluateMotionCandidate(robot_model_, state_, motion_candidates_[i], &ideal_position);
        if(!is_leaf_)
        {
            new_reward += children_[i]->GetReward();
        }
        if(new_reward > max_reward)
        {
            max_reward = new_reward;
            best_candidate_index_ = i;
        }
    }
    reward_ = max_reward;

    reward_calculated_ = true;
    return reward_;
}

void MotionCandidateNode::ChooseMotionCandidate(std::vector<double>* joint_velocities, std::vector<double>* null_vector)
{
    joint_velocities->clear();
    null_vector->clear();
    if(!reward_calculated_)
    {
        CalculateReward();
    }

    for(int i = 0; i < (*motion_candidates_[best_candidate_index_]).commanded_velocities.size(); ++i)
    {
        joint_velocities->push_back((*motion_candidates_[best_candidate_index_]).commanded_velocities[i]);
        null_vector->push_back((*motion_candidates_[best_candidate_index_]).null_goals[i]);
    }
}

void MotionCandidateNode::GetBaseline(std::vector<double>* joint_velocities)
{
    joint_velocities->clear();
    state_->CalculateJacobian(robot_model_);
    Eigen::VectorXd primary_movement = state_->pseudo_inverse * desired_velocity_;

    for(int i = 0; i < primary_movement.size(); ++i)
    {
        joint_velocities->push_back(primary_movement(i));
    }
}

//--------------------------------------------------------------------------------------------------
// Linear algebra functions
void MotionCandidateNode::GetNullSpace()
{
    Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> ident = Eigen::Matrix<double,Eigen::Dynamic, Eigen::Dynamic>::Identity(state_->pseudo_inverse.rows(),state_->jacobian.cols());
    null_space_ = ident - state_->pseudo_inverse * state_->jacobian;
}

}

max_stars_repo_name: cu-ironlab/predikct

max_issues_repo_name: cu-ironlab/predikct

max_forks_repo_name: cu-ironlab/predikct


text:
//---------------------------------------------------------------------------//
//!
//! \file   tstStandardElectronPhotonRelaxationDataGenerator.cpp
//! \author Alex Robinson
//! \brief  Standard electron-photon-relaxation data generator unit tests
//!
//---------------------------------------------------------------------------//

// Std Lib Includes
#include <iostream>

// Boost Includes
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/unordered_map.hpp>

// Trilinos Includes
#include <Teuchos_UnitTestHarness.hpp>
#include <Teuchos_VerboseObject.hpp>
#include <Teuchos_RCP.hpp>
#include <Teuchos_Array.hpp>

// FRENSIE Includes
#include "DataGen_StandardElectronPhotonRelaxationDataGenerator.hpp"
#include "Data_ElectronPhotonRelaxationVolatileDataContainer.hpp"
#include "Data_ACEFileHandler.hpp"
#include "Data_ENDLFileHandler.hpp"
#include "Data_XSSEPRDataExtractor.hpp"
#include "Utility_UnitTestHarnessExtensions.hpp"

//---------------------------------------------------------------------------//
// Testing Variables
//---------------------------------------------------------------------------//

Teuchos::RCP<const DataGen::StandardElectronPhotonRelaxationDataGenerator>
  data_generator_h, data_generator_c;

Teuchos::RCP<Data::XSSEPRDataExtractor>
  h_xss_data_extractor, c_xss_data_extractor;

std::string test_h_eedl_file_name, test_c_eedl_file_name;

//---------------------------------------------------------------------------//
// Tests
//---------------------------------------------------------------------------//
// Check that a data container can be populated
TEUCHOS_UNIT_TEST( StandardElectronPhotonRelaxationDataGenerator,
		   populateEPRDataContainer_h )
{
  Teuchos::RCP<Data::ENDLFileHandler> eedl_file_handler(
    new Data::ENDLFileHandler( test_h_eedl_file_name ) );

    data_generator_h.reset(
        new DataGen::StandardElectronPhotonRelaxationDataGenerator(
                h_xss_data_extractor->extractAtomicNumber(),
                h_xss_data_extractor,
                eedl_file_handler,
                0.001,
                20.0,
                1.0e-5,
                1.0e+5,
                1.0e-6,
                1e-4,
                1e-3,
                0.001,
                1e-42,
                1e-15) );

  Data::ElectronPhotonRelaxationVolatileDataContainer data_container;

  data_generator_h->populateEPRDataContainer( data_container );

  TEST_EQUALITY_CONST( data_container.getAtomicNumber(), 1 );
  TEST_EQUALITY_CONST( data_container.getSubshells().size(), 1 );
  TEST_ASSERT( data_container.getSubshells().count( 1 ) );
  TEST_EQUALITY_CONST( data_container.getSubshellOccupancy( 1 ), 1 );
  TEST_EQUALITY_CONST( data_container.getSubshellBindingEnergy( 1 ),
		       1.361000000000E-05 );
  TEST_ASSERT( !data_container.hasRelaxationData() );
  TEST_ASSERT( !data_container.hasSubshellRelaxationData( 1 ) );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(1).size(),
		       63 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(1).front(),
		       -1.0 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(1).back(),
		       1.0 );
  TEST_EQUALITY_CONST( data_container.getComptonProfile(1).size(), 63 );
  TEST_FLOATING_EQUALITY( data_container.getComptonProfile(1).front(),
			  2.22639295466368597e-09,
			  1e-15 );
  TEST_FLOATING_EQUALITY( data_container.getComptonProfile(1).back(),
			  2.22639295466368597e-09,
			  1e-15 );
  TEST_EQUALITY_CONST(data_container.getOccupationNumberMomentumGrid(1).size(),
		      409 );
  TEST_EQUALITY_CONST(
		     data_container.getOccupationNumberMomentumGrid(1).front(),
		     -1.00000000000000000e+00 );
  TEST_EQUALITY_CONST(data_container.getOccupationNumberMomentumGrid(1).back(),
		      1.00000000000000000e+00 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(1).size(), 409 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(1).front(),
		       0.00000000000000000e+00 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(1).back(),
		       1.00000000000000000e+00 );
  TEST_EQUALITY_CONST(
	data_container.getWallerHartreeScatteringFunctionMomentumGrid().size(),
	365 );
  TEST_EQUALITY_CONST(
       data_container.getWallerHartreeScatteringFunctionMomentumGrid().front(),
       0.0 );
  TEST_FLOATING_EQUALITY(
	data_container.getWallerHartreeScatteringFunctionMomentumGrid().back(),
	1.0e+17,
	1e-15 );
  TEST_EQUALITY_CONST(
		    data_container.getWallerHartreeScatteringFunction().size(),
		    365 );
  TEST_EQUALITY_CONST(
		   data_container.getWallerHartreeScatteringFunction().front(),
		   0.0 );
  TEST_EQUALITY_CONST(
		    data_container.getWallerHartreeScatteringFunction().back(),
		    1.0 );
  TEST_EQUALITY_CONST(
	  data_container.getWallerHartreeAtomicFormFactorMomentumGrid().size(),
	  1583 );
  TEST_EQUALITY_CONST(
	 data_container.getWallerHartreeAtomicFormFactorMomentumGrid().front(),
	 0.0 );
  TEST_FLOATING_EQUALITY(
	  data_container.getWallerHartreeAtomicFormFactorMomentumGrid().back(),
	  1.0e+17,
	  1e-15 );
  TEST_EQUALITY_CONST(data_container.getWallerHartreeAtomicFormFactor().size(),
		      1583 );
  TEST_FLOATING_EQUALITY(
		     data_container.getWallerHartreeAtomicFormFactor().front(),
		     1.0e+00,
		     1e-15 );
  TEST_FLOATING_EQUALITY(
		      data_container.getWallerHartreeAtomicFormFactor().back(),
		      8.18290000000000004e-39,
		      1e-15 );
  TEST_EQUALITY_CONST( data_container.getPhotonEnergyGrid().size(), 727 );
  TEST_FLOATING_EQUALITY( data_container.getPhotonEnergyGrid().front(),
			  1.0e-03,
			  1e-15 );
  TEST_FLOATING_EQUALITY( data_container.getPhotonEnergyGrid().back(),
			  2.0e+01,
			  1e-15 );
  TEST_EQUALITY_CONST( data_container.getAveragePhotonHeatingNumbers().size(),
		       727 );
  TEST_FLOATING_EQUALITY(
		       data_container.getAveragePhotonHeatingNumbers().front(),
		       9.44850385307779940e-04,
		       1e-15 );
  TEST_FLOATING_EQUALITY(
			data_container.getAveragePhotonHeatingNumbers().back(),
			1.52602263568998424e+01,
			1e-15 );
  TEST_EQUALITY_CONST(
		data_container.getWallerHartreeIncoherentCrossSection().size(),
		727 );
  TEST_FLOATING_EQUALITY(
	       data_container.getWallerHartreeIncoherentCrossSection().front(),
	       8.43429999999524560e-02,
	       1e-15 );
  TEST_FLOATING_EQUALITY(
	       data_container.getWallerHartreeIncoherentCrossSection().back(),
	       3.02353826681303964e-02,
	       1e-15 );
  TEST_EQUALITY_CONST(
   data_container.getWallerHartreeIncoherentCrossSectionThresholdEnergyIndex(),
   0 );
  TEST_EQUALITY_CONST(
		data_container.getImpulseApproxIncoherentCrossSection().size(),
		727 );
  TEST_FLOATING_EQUALITY(
	       data_container.getImpulseApproxIncoherentCrossSection().front(),
	       2.31173954978115201e-02,
	       1e-15 );
  TEST_FLOATING_EQUALITY(
	        data_container.getImpulseApproxIncoherentCrossSection().back(),
		3.02498575770965353e-02,
		1e-15 );
  TEST_EQUALITY_CONST(
   data_container.getImpulseApproxIncoherentCrossSectionThresholdEnergyIndex(),
   0 );
  TEST_EQUALITY_CONST(
       data_container.getImpulseApproxSubshellIncoherentCrossSection(1).size(),
       727 );
  TEST_FLOATING_EQUALITY(
      data_container.getImpulseApproxSubshellIncoherentCrossSection(1).front(),
      2.31173954978115201e-02,
      1e-15 );
  TEST_FLOATING_EQUALITY(
       data_container.getImpulseApproxSubshellIncoherentCrossSection(1).back(),
       3.02498575770965353e-02,
       1e-15 );
  TEST_EQUALITY_CONST( data_container.getImpulseApproxSubshellIncoherentCrossSectionThresholdEnergyIndex(1),
		       0 );
  TEST_EQUALITY_CONST(
		  data_container.getWallerHartreeCoherentCrossSection().size(),
		  727 );
  TEST_FLOATING_EQUALITY(
		 data_container.getWallerHartreeCoherentCrossSection().front(),
		 5.81790484064093394e-01,
		 1e-15 );
  TEST_FLOATING_EQUALITY(
		 data_container.getWallerHartreeCoherentCrossSection().back(),
		 1.15654029975768264e-08,
		 1e-15 );
  TEST_EQUALITY_CONST(
     data_container.getWallerHartreeCoherentCrossSectionThresholdEnergyIndex(),
     0 );
  TEST_EQUALITY_CONST( data_container.getPairProductionCrossSection().size(),
		       296 );
  TEST_EQUALITY_CONST( data_container.getPairProductionCrossSection().front(),
		       1.00971567358274950e-10 );
  TEST_EQUALITY_CONST( data_container.getPairProductionCrossSection().back(),
		       5.65100000000240063e-03 );
  TEST_EQUALITY_CONST(
	    data_container.getPairProductionCrossSectionThresholdEnergyIndex(),
	    431 );
  TEST_EQUALITY_CONST( data_container.getPhotoelectricCrossSection().size(),
		       727 );
  TEST_EQUALITY_CONST( data_container.getPhotoelectricCrossSection().front(),
		       1.14084154957847943e+01 );
  TEST_EQUALITY_CONST( data_container.getPhotoelectricCrossSection().back(),
		       4.05895811339709049e-11 );
  TEST_EQUALITY_CONST(
	     data_container.getPhotoelectricCrossSectionThresholdEnergyIndex(),
	     0 );
  TEST_EQUALITY_CONST(
		 data_container.getSubshellPhotoelectricCrossSection(1).size(),
		 727 );
  TEST_EQUALITY_CONST(
		data_container.getSubshellPhotoelectricCrossSection(1).front(),
		1.14084154957847943e+01 );
  TEST_EQUALITY_CONST(
		 data_container.getSubshellPhotoelectricCrossSection(1).back(),
		 4.05895811339709049e-11 );
  TEST_EQUALITY_CONST(
    data_container.getSubshellPhotoelectricCrossSectionThresholdEnergyIndex(1),
    0 );
  TEST_EQUALITY_CONST(
		     data_container.getWallerHartreeTotalCrossSection().size(),
		     727 );
  TEST_EQUALITY_CONST(
		    data_container.getWallerHartreeTotalCrossSection().front(),
		    1.20745489798488403e+01 );
  TEST_EQUALITY_CONST(
		     data_container.getWallerHartreeTotalCrossSection().back(),
		     3.58863942741253703e-02 );
  TEST_EQUALITY_CONST(
		     data_container.getImpulseApproxTotalCrossSection().size(),
		     727 );
  TEST_EQUALITY_CONST(
		    data_container.getImpulseApproxTotalCrossSection().front(),
		    1.20133233753466993e+01 );
  TEST_EQUALITY_CONST(
		     data_container.getImpulseApproxTotalCrossSection().back(),
		     3.59008691830915092e-02 );

  std::vector<double> energy_grid = data_container.getElectronEnergyGrid();
  TEST_EQUALITY_CONST( energy_grid.front(), 1.0e-5 );
  TEST_EQUALITY_CONST( energy_grid.back(), 1.0e+5 );
  TEST_EQUALITY_CONST( energy_grid.size(), 728 );

  TEST_EQUALITY_CONST( data_container.getCutoffAngle(), 1.0e-6 );

  // Check the elastic data
  unsigned threshold =
    data_container.getCutoffElasticCrossSectionThresholdEnergyIndex();

  TEST_EQUALITY_CONST( threshold, 0 );

  std::vector<double> cross_section =
    data_container.getCutoffElasticCrossSection();

  TEST_EQUALITY_CONST( cross_section.front(), 2.74896e+8 );
  TEST_FLOATING_EQUALITY( cross_section.back(), 1.31176e-5, 1e-15 );
  TEST_EQUALITY_CONST( cross_section.size(), 728-threshold );

  threshold =
    data_container.getScreenedRutherfordElasticCrossSectionThresholdEnergyIndex();

  TEST_EQUALITY_CONST( threshold, 263 );

  cross_section =
    data_container.getScreenedRutherfordElasticCrossSection();

//  TEST_EQUALITY_CONST( cross_section.front(), 2.5745520470700284932 );
//! \todo double check what the front cross section should be
  TEST_EQUALITY_CONST( cross_section.front(), 2.57455204707366647 );
  TEST_EQUALITY_CONST( cross_section.back(), 1.29871e+4-1.31176e-5 );
  TEST_EQUALITY_CONST( cross_section.size(), 728-threshold );

  std::vector<double> angular_grid =
    data_container.getElasticAngularEnergyGrid();

  TEST_EQUALITY_CONST( angular_grid.front(), 1.0e-5 );
  TEST_EQUALITY_CONST( angular_grid.back(), 1.0e+5 );
  TEST_EQUALITY_CONST( angular_grid.size(), 16 );

  std::vector<double> elastic_angles =
    data_container.getAnalogElasticAngles(1.0e-5);

  TEST_EQUALITY_CONST( elastic_angles.front(), 1.0e-6 );
  TEST_EQUALITY_CONST( elastic_angles.back(), 2.0 );
  TEST_EQUALITY_CONST( elastic_angles.size(), 2 );

  elastic_angles =
    data_container.getAnalogElasticAngles(1.0e+5);

  TEST_EQUALITY_CONST( elastic_angles.front(), 1.0e-6 );
  TEST_EQUALITY_CONST( elastic_angles.back(), 2.0 );
  TEST_EQUALITY_CONST( elastic_angles.size(), 96 );

  std::vector<double> elastic_pdf =
    data_container.getAnalogElasticPDF(1.0e-5);

  TEST_EQUALITY_CONST( elastic_pdf.front(), 0.5 );
  TEST_EQUALITY_CONST( elastic_pdf.back(), 0.5 );
  TEST_EQUALITY_CONST( elastic_pdf.size(), 2 );

  elastic_pdf =
    data_container.getAnalogElasticPDF(1.0e+5);

  TEST_EQUALITY_CONST( elastic_pdf.front(), 9.86945e+5 );
  TEST_EQUALITY_CONST( elastic_pdf.back(), 6.25670e-13 );
  TEST_EQUALITY_CONST( elastic_pdf.size(), 96 );

  // Check the electroionization data
  threshold =
    data_container.getElectroionizationCrossSectionThresholdEnergyIndex( 1u );

  TEST_EQUALITY_CONST( threshold, 7 );

  cross_section =
    data_container.getElectroionizationCrossSection( 1u );

//  TEST_EQUALITY_CONST( cross_section.front(), 1.26041968911917554e+06 );
//! \todo double check what the front cross section should be
  TEST_EQUALITY_CONST( cross_section.front(), 1.26041968911917577e+06 );
  TEST_EQUALITY_CONST( cross_section.back(), 8.28924e+4 );
  TEST_EQUALITY_CONST( cross_section.size(), 728-threshold );

  std::vector<double> electroionization_energy_grid =
    data_container.getElectroionizationEnergyGrid( 1u );

  TEST_EQUALITY_CONST( electroionization_energy_grid.front(), 1.36100e-5 );
  TEST_EQUALITY_CONST( electroionization_energy_grid.back(), 1.00000e+5 );
  TEST_EQUALITY_CONST( electroionization_energy_grid.size(), 8 );

  std::vector<double> electroionization_recoil_energy =
    data_container.getElectroionizationRecoilEnergy( 1u, 1.36100e-5 );

  TEST_EQUALITY_CONST( electroionization_recoil_energy.front(), 2.79866e-9 );
  TEST_EQUALITY_CONST( electroionization_recoil_energy.back(), 2.79866e-8 );
  TEST_EQUALITY_CONST( electroionization_recoil_energy.size(), 2 );

  electroionization_recoil_energy =
    data_container.getElectroionizationRecoilEnergy( 1u, 1.00000e+5 );

  TEST_EQUALITY_CONST( electroionization_recoil_energy.front(), 1.00000e-7 );
  TEST_EQUALITY_CONST( electroionization_recoil_energy.back(), 5.00000e+4 );
  TEST_EQUALITY_CONST( electroionization_recoil_energy.size(), 147 );

  std::vector<double> electroionization_recoil_pdf =
    data_container.getElectroionizationRecoilPDF( 1u, 1.36100e-5 );

  TEST_EQUALITY_CONST( electroionization_recoil_pdf.front(), 3.97015e+7 );
  TEST_EQUALITY_CONST( electroionization_recoil_pdf.back(), 3.97015e+7 );
  TEST_EQUALITY_CONST( electroionization_recoil_pdf.size(), 2 );

  electroionization_recoil_pdf =
    data_container.getElectroionizationRecoilPDF( 1u, 1.00000e+5 );

  TEST_EQUALITY_CONST( electroionization_recoil_pdf.front(), 1.61897e+5 );
  TEST_EQUALITY_CONST( electroionization_recoil_pdf.back(), 2.77550e-15 );
  TEST_EQUALITY_CONST( electroionization_recoil_pdf.size(), 147 );

  // Check the bremsstrahlung data
  threshold =
    data_container.getBremsstrahlungCrossSectionThresholdEnergyIndex();

  TEST_EQUALITY_CONST( threshold, 0 );

  cross_section =
    data_container.getBremsstrahlungCrossSection();

  TEST_EQUALITY_CONST( cross_section.front(),  2.97832e+1 );
  TEST_EQUALITY_CONST( cross_section.back(), 9.90621e-1 );
  TEST_EQUALITY_CONST( cross_section.size(), 728-threshold );

  std::vector<double> bremsstrahlung_energy_grid =
    data_container.getBremsstrahlungEnergyGrid();

  TEST_EQUALITY_CONST( bremsstrahlung_energy_grid.front(), 1.00000e-5 );
  TEST_EQUALITY_CONST( bremsstrahlung_energy_grid.back(), 1.00000e+5 );
  TEST_EQUALITY_CONST( bremsstrahlung_energy_grid.size(), 10 );

  std::vector<double> bremsstrahlung_photon_energy =
    data_container.getBremsstrahlungPhotonEnergy( 1.00000e-5 );

  TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.front(), 1.00000e-7 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.back(), 1.00000e-5 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.size(), 17 );

  bremsstrahlung_photon_energy =
    data_container.getBremsstrahlungPhotonEnergy( 1.00000e+5 );

  TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.front(), 1.00000e-7 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.back(), 1.00000e+5 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.size(), 111 );

  std::vector<double> bremsstrahlung_photon_pdf =
    data_container.getBremsstrahlungPhotonPDF( 1.00000e-5 );

  TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.front(), 2.13940e+6 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.back(), 2.12245e+4 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.size(), 17 );

  bremsstrahlung_photon_pdf =
    data_container.getBremsstrahlungPhotonPDF( 1.00000e+5 );

  TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.front(),  3.65591e+5 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.back(),  5.16344e-10 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.size(), 111 );

  // Check the atomic excitation data
  threshold =
    data_container.getAtomicExcitationCrossSectionThresholdEnergyIndex();

  TEST_EQUALITY_CONST( threshold, 7 );

  cross_section =
    data_container.getAtomicExcitationCrossSection();

  TEST_EQUALITY_CONST( cross_section.front(), 6.23029e+5 );
  TEST_EQUALITY_CONST( cross_section.back(), 8.14416e+4 );
  TEST_EQUALITY_CONST( cross_section.size(), 728-threshold );

  std::vector<double> atomic_excitation_energy_grid =
    data_container.getAtomicExcitationEnergyGrid();

  TEST_EQUALITY_CONST( atomic_excitation_energy_grid.front(), 1.36100e-5 );
  TEST_EQUALITY_CONST( atomic_excitation_energy_grid.back(), 1.00000e+5 );
  TEST_EQUALITY_CONST( atomic_excitation_energy_grid.size(), 170 );

  std::vector<double> atomic_excitation_energy_loss =
    data_container.getAtomicExcitationEnergyLoss();

  TEST_EQUALITY_CONST( atomic_excitation_energy_loss.front(), 1.36100e-5 );
  TEST_EQUALITY_CONST( atomic_excitation_energy_loss.back(), 2.10777e-5 );
  TEST_EQUALITY_CONST( atomic_excitation_energy_loss.size(), 170 );

  data_container.exportData( "test_h_epr.xml",
			     Utility::ArchivableObject::XML_ARCHIVE );
}

//---------------------------------------------------------------------------//
// Check that a data container can be populated
TEUCHOS_UNIT_TEST( StandardElectronPhotonRelaxationDataGenerator,
		   populateEPRDataContainer_c )
{

Teuchos::RCP<Data::ENDLFileHandler> eedl_file_handler(
    new Data::ENDLFileHandler( test_c_eedl_file_name ) );

    data_generator_c.reset(
		   new DataGen::StandardElectronPhotonRelaxationDataGenerator(
				     c_xss_data_extractor->extractAtomicNumber(),
				     c_xss_data_extractor,
                     eedl_file_handler,
				     0.001,
				     20.0,
                     1.0e-5,
                     1.0e+5,
                     1.0e-6,
				     1e-3,
				     1e-3,
				     0.001,
				     1e-32,
				     1e-16) );

  Data::ElectronPhotonRelaxationVolatileDataContainer data_container;

  data_generator_c->populateEPRDataContainer( data_container );

  TEST_EQUALITY_CONST( data_container.getAtomicNumber(), 6 );
  TEST_EQUALITY_CONST( data_container.getSubshells().size(), 4 );
  TEST_ASSERT( data_container.getSubshells().count( 1 ) );
  TEST_ASSERT( data_container.getSubshells().count( 2 ) );
  TEST_ASSERT( data_container.getSubshells().count( 3 ) );
  TEST_ASSERT( data_container.getSubshells().count( 4 ) );
  TEST_EQUALITY_CONST( data_container.getSubshellOccupancy( 1 ), 2 );
  TEST_EQUALITY_CONST( data_container.getSubshellOccupancy( 2 ), 2 );
  TEST_EQUALITY_CONST( data_container.getSubshellOccupancy( 3 ), 0.67 );
  TEST_EQUALITY_CONST( data_container.getSubshellOccupancy( 4 ), 1.33 );
  TEST_EQUALITY_CONST( data_container.getSubshellBindingEnergy( 1 ),
		       2.9101e-4 );
  TEST_EQUALITY_CONST( data_container.getSubshellBindingEnergy( 2 ),
		       1.7560e-5 );
  TEST_EQUALITY_CONST( data_container.getSubshellBindingEnergy( 3 ),
		       8.9900e-6 );
  TEST_EQUALITY_CONST( data_container.getSubshellBindingEnergy( 4 ),
		       8.9800e-6 );
  TEST_ASSERT( data_container.hasRelaxationData() );
  TEST_ASSERT( data_container.hasSubshellRelaxationData( 1 ) );
  TEST_ASSERT( !data_container.hasSubshellRelaxationData( 2 ) );
  TEST_ASSERT( !data_container.hasSubshellRelaxationData( 3 ) );
  TEST_ASSERT( !data_container.hasSubshellRelaxationData( 4 ) );
  TEST_EQUALITY_CONST( data_container.getSubshellRelaxationTransitions( 1 ),
		       8 );
  TEST_EQUALITY_CONST(
		     data_container.getSubshellRelaxationVacancies(1).size(),
		     8 );
  TEST_EQUALITY_CONST(
		data_container.getSubshellRelaxationVacancies(1).front().first,
		3 );
  TEST_EQUALITY_CONST(
	       data_container.getSubshellRelaxationVacancies(1).front().second,
	       0 );
  TEST_EQUALITY_CONST(
		 data_container.getSubshellRelaxationVacancies(1).back().first,
		 4 );
  TEST_EQUALITY_CONST(
	        data_container.getSubshellRelaxationVacancies(1).back().second,
		4 );
  TEST_EQUALITY_CONST(
		data_container.getSubshellRelaxationParticleEnergies(1).size(),
		8 );
  TEST_FLOATING_EQUALITY(
	       data_container.getSubshellRelaxationParticleEnergies(1).front(),
	       2.8202e-4,
	       1e-15 );
  TEST_FLOATING_EQUALITY(
		data_container.getSubshellRelaxationParticleEnergies(1).back(),
		2.7305e-4,
		1e-15 );
  TEST_EQUALITY_CONST(
		   data_container.getSubshellRelaxationProbabilities(1).size(),
		   8 );
  TEST_FLOATING_EQUALITY(
		  data_container.getSubshellRelaxationProbabilities(1).front(),
		  5.614877933725e-04,
		  1e-15 );
  TEST_FLOATING_EQUALITY(
		   data_container.getSubshellRelaxationProbabilities(1).back(),
		   6.32007767421e-02,
		   1e-15 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(1).size(),
		       63 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(1).front(),
		       -1.0 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(1).back(),
		       1.0 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(2).size(),
		       63 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(2).front(),
		       -1.0 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(2).back(),
		       1.0 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(3).size(),
		       63 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(3).front(),
		       -1.0 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(3).back(),
		       1.0 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(4).size(),
		       63 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(4).front(),
		       -1.0 );
  TEST_EQUALITY_CONST( data_container.getComptonProfileMomentumGrid(4).back(),
		       1.0 );
  TEST_EQUALITY_CONST( data_container.getComptonProfile(1).size(), 63 );
  TEST_FLOATING_EQUALITY( data_container.getComptonProfile(1).front(),
			  4.76097080587270975e-08,
			  1e-15 );
  TEST_FLOATING_EQUALITY( data_container.getComptonProfile(1).back(),
			  4.76097080587270975e-08,
			  1e-15 );
  TEST_EQUALITY_CONST( data_container.getComptonProfile(2).size(), 63 );
  TEST_FLOATING_EQUALITY( data_container.getComptonProfile(2).front(),
			  2.22296325751965260e-09,
			  1e-15 );
  TEST_FLOATING_EQUALITY( data_container.getComptonProfile(2).back(),
			  2.22296325751965260e-09,
			  1e-15 );
  TEST_EQUALITY_CONST( data_container.getComptonProfile(3).size(), 63 );
  TEST_FLOATING_EQUALITY( data_container.getComptonProfile(3).front(),
			  2.46239765051693239e-13,
			  1e-15 );
  TEST_FLOATING_EQUALITY( data_container.getComptonProfile(3).back(),
			  2.46239765051693239e-13,
			  1e-15 );
  TEST_EQUALITY_CONST( data_container.getComptonProfile(4).size(), 63 );
  TEST_FLOATING_EQUALITY( data_container.getComptonProfile(4).front(),
			  2.46239765051693239e-13,
			  1e-15 );
  TEST_FLOATING_EQUALITY( data_container.getComptonProfile(4).back(),
			  2.46239765051693239e-13,
			  1e-15 );
  TEST_EQUALITY_CONST(data_container.getOccupationNumberMomentumGrid(1).size(),
		      442 );
  TEST_EQUALITY_CONST(
		     data_container.getOccupationNumberMomentumGrid(1).front(),
		     -1.0 );
  TEST_EQUALITY_CONST(data_container.getOccupationNumberMomentumGrid(1).back(),
		      1.0 );
  TEST_EQUALITY_CONST(data_container.getOccupationNumberMomentumGrid(2).size(),
		      399 );
  TEST_EQUALITY_CONST(
		     data_container.getOccupationNumberMomentumGrid(2).front(),
		     -1.0 );
  TEST_EQUALITY_CONST(data_container.getOccupationNumberMomentumGrid(2).back(),
		      1.0 );
  TEST_EQUALITY_CONST(data_container.getOccupationNumberMomentumGrid(3).size(),
		      573 );
  TEST_EQUALITY_CONST(
		     data_container.getOccupationNumberMomentumGrid(3).front(),
		     -1.0 );
  TEST_EQUALITY_CONST(data_container.getOccupationNumberMomentumGrid(3).back(),
		      1.0 );
  TEST_EQUALITY_CONST(data_container.getOccupationNumberMomentumGrid(4).size(),
		      573 );
  TEST_EQUALITY_CONST(
		     data_container.getOccupationNumberMomentumGrid(4).front(),
		     -1.0 );
  TEST_EQUALITY_CONST(data_container.getOccupationNumber(4).back(),
		      1.0 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(1).size(), 442 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(1).front(),
		       0.0 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(1).back(),
		       1.0 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(2).size(), 399 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(2).front(),
		       0.0 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(2).back(),
		       1.0 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(3).size(), 573 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(3).front(),
		       0.0 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(3).back(),
		       1.0 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(4).size(), 573 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(4).front(),
		       0.0 );
  TEST_EQUALITY_CONST( data_container.getOccupationNumber(4).back(),
		       1.0 );
  TEST_EQUALITY_CONST(
	data_container.getWallerHartreeScatteringFunctionMomentumGrid().size(),
	379 );
  TEST_EQUALITY_CONST(
       data_container.getWallerHartreeScatteringFunctionMomentumGrid().front(),
       0.0 );
  TEST_EQUALITY_CONST(
	data_container.getWallerHartreeScatteringFunctionMomentumGrid().back(),
	1e17 );
  TEST_EQUALITY_CONST(
		    data_container.getWallerHartreeScatteringFunction().size(),
		    379 );
  TEST_EQUALITY_CONST(
		   data_container.getWallerHartreeScatteringFunction().front(),
		   0.0 );
  TEST_EQUALITY_CONST(
		    data_container.getWallerHartreeScatteringFunction().back(),
		    6.0 );
  TEST_EQUALITY_CONST(
	  data_container.getWallerHartreeAtomicFormFactorMomentumGrid().size(),
	  1259 );
  TEST_EQUALITY_CONST(
	 data_container.getWallerHartreeAtomicFormFactorMomentumGrid().front(),
	 0.0 );
  TEST_EQUALITY_CONST(
	  data_container.getWallerHartreeAtomicFormFactorMomentumGrid().back(),
	  1e17 );
  TEST_EQUALITY_CONST(data_container.getWallerHartreeAtomicFormFactor().size(),
		      1259 );
  TEST_EQUALITY_CONST(
		     data_container.getWallerHartreeAtomicFormFactor().front(),
		     6.0 );
  TEST_FLOATING_EQUALITY(
		      data_container.getWallerHartreeAtomicFormFactor().back(),
		      1.68099999999999989e-29,
		      1e-15 );
  TEST_EQUALITY_CONST( data_container.getPhotonEnergyGrid().size(), 775 );
  TEST_EQUALITY_CONST( data_container.getPhotonEnergyGrid().front(),
		       0.001 );
  TEST_EQUALITY_CONST( data_container.getPhotonEnergyGrid().back(),
		       20.0 );
  TEST_EQUALITY_CONST( data_container.getAveragePhotonHeatingNumbers().size(),
		       775 );
  TEST_FLOATING_EQUALITY(
		       data_container.getAveragePhotonHeatingNumbers().front(),
		       9.99436862257738331e-04,
		       1e-15 );
  TEST_FLOATING_EQUALITY(
			data_container.getAveragePhotonHeatingNumbers().back(),
			1.64023854081998266e+01,
			1e-15 );
  TEST_EQUALITY_CONST(
		data_container.getWallerHartreeIncoherentCrossSection().size(),
		775 );
  TEST_FLOATING_EQUALITY(
	       data_container.getWallerHartreeIncoherentCrossSection().front(),
	       2.52250000000042829e-01,
	       1e-15 );
  TEST_FLOATING_EQUALITY(
		data_container.getWallerHartreeIncoherentCrossSection().back(),
		1.81486137923699387e-01,
		1e-15 );
  TEST_EQUALITY_CONST(
   data_container.getWallerHartreeIncoherentCrossSectionThresholdEnergyIndex(),
   0 );
  TEST_EQUALITY_CONST(
		data_container.getImpulseApproxIncoherentCrossSection().size(),
		775 );
  TEST_FLOATING_EQUALITY(
	       data_container.getImpulseApproxIncoherentCrossSection().front(),
	       2.68987545509888737e-01,
	       1e-15 );
  TEST_FLOATING_EQUALITY(
	        data_container.getImpulseApproxIncoherentCrossSection().back(),
		1.81499083920329374e-01,
		1e-15 );
  TEST_EQUALITY_CONST(
   data_container.getImpulseApproxIncoherentCrossSectionThresholdEnergyIndex(),
   0 );
  TEST_EQUALITY_CONST(
       data_container.getImpulseApproxSubshellIncoherentCrossSection(1).size(),
       775 );
  TEST_FLOATING_EQUALITY(
      data_container.getImpulseApproxSubshellIncoherentCrossSection(1).front(),
      6.79748251620507996e-05,
      1e-15 );
  TEST_FLOATING_EQUALITY(
       data_container.getImpulseApproxSubshellIncoherentCrossSection(1).back(),
       6.04996536119432188e-02,
       1e-15 );
  TEST_EQUALITY_CONST( data_container.getImpulseApproxSubshellIncoherentCrossSectionThresholdEnergyIndex(1),
		       0 );
  TEST_EQUALITY_CONST(
       data_container.getImpulseApproxSubshellIncoherentCrossSection(2).size(),
       775 );
  TEST_FLOATING_EQUALITY(
      data_container.getImpulseApproxSubshellIncoherentCrossSection(2).front(),
      3.49837183987976100e-02,
      1e-15 );
  TEST_FLOATING_EQUALITY(
       data_container.getImpulseApproxSubshellIncoherentCrossSection(2).back(),
       6.04997151541930706e-02,
       1e-15 );
  TEST_EQUALITY_CONST( data_container.getImpulseApproxSubshellIncoherentCrossSectionThresholdEnergyIndex(2),
		       0 );
  TEST_EQUALITY_CONST(
       data_container.getImpulseApproxSubshellIncoherentCrossSection(3).size(),
       775 );
  TEST_FLOATING_EQUALITY(
      data_container.getImpulseApproxSubshellIncoherentCrossSection(3).front(),
      7.82914016886618047e-02,
      1e-15 );
  TEST_FLOATING_EQUALITY(
       data_container.getImpulseApproxSubshellIncoherentCrossSection(3).back(),
       2.02674045766546781e-02,
       1e-15 );
  TEST_EQUALITY_CONST( data_container.getImpulseApproxSubshellIncoherentCrossSectionThresholdEnergyIndex(3),
		       0 );
  TEST_EQUALITY_CONST(
       data_container.getImpulseApproxSubshellIncoherentCrossSection(4).size(),
       775 );
  TEST_FLOATING_EQUALITY(
      data_container.getImpulseApproxSubshellIncoherentCrossSection(4).front(),
      1.55644450597267281e-01,
      1e-15 );
  TEST_FLOATING_EQUALITY(
       data_container.getImpulseApproxSubshellIncoherentCrossSection(4).back(),
       4.02323105775383924e-02,
       1e-15 );
  TEST_EQUALITY_CONST( data_container.getImpulseApproxSubshellIncoherentCrossSectionThresholdEnergyIndex(4),
		       0 );
  TEST_EQUALITY_CONST(
		  data_container.getWallerHartreeCoherentCrossSection().size(),
		  775 );
  TEST_FLOATING_EQUALITY(
		 data_container.getWallerHartreeCoherentCrossSection().front(),
		 2.45600299049398139e+01,
		 1e-15 );
  TEST_FLOATING_EQUALITY(
		  data_container.getWallerHartreeCoherentCrossSection().back(),
		  1.92198769740615498e-06,
		  1e-15 );
  TEST_EQUALITY_CONST(
     data_container.getWallerHartreeCoherentCrossSectionThresholdEnergyIndex(),
     0 );
  TEST_EQUALITY_CONST( data_container.getPairProductionCrossSection().size(),
		       280 );
  TEST_FLOATING_EQUALITY(
			data_container.getPairProductionCrossSection().front(),
			3.71284984483754554e-09,
			1e-15 );
  TEST_FLOATING_EQUALITY(data_container.getPairProductionCrossSection().back(),
			 1.31849999999978429e-01,
			 1e-15 );
  TEST_EQUALITY_CONST(
	    data_container.getPairProductionCrossSectionThresholdEnergyIndex(),
	    495 );
  TEST_EQUALITY_CONST( data_container.getPhotoelectricCrossSection().size(),
		       775 );
  TEST_FLOATING_EQUALITY(data_container.getPhotoelectricCrossSection().front(),
			 4.40346567781178965e+04,
			 1e-15 );
  TEST_FLOATING_EQUALITY( data_container.getPhotoelectricCrossSection().back(),
			  4.78641586632171115e-07,
			  1e-15 );
  TEST_EQUALITY_CONST(
	     data_container.getPhotoelectricCrossSectionThresholdEnergyIndex(),
	     0 );
  TEST_EQUALITY_CONST(
		 data_container.getSubshellPhotoelectricCrossSection(1).size(),
		 775 );
  TEST_FLOATING_EQUALITY(
		data_container.getSubshellPhotoelectricCrossSection(1).front(),
		4.20106634766030475e+04,
		1e-15 );
  TEST_FLOATING_EQUALITY(
		 data_container.getSubshellPhotoelectricCrossSection(1).back(),
		 4.54467548753621960e-07,
		 1e-15 );
  TEST_EQUALITY_CONST(
    data_container.getSubshellPhotoelectricCrossSectionThresholdEnergyIndex(1),
    0 );
  TEST_EQUALITY_CONST(
		 data_container.getSubshellPhotoelectricCrossSection(2).size(),
		 775 );
  TEST_FLOATING_EQUALITY(
		data_container.getSubshellPhotoelectricCrossSection(2).front(),
		1.92946542999592748e+03,
		1e-15 );
  TEST_FLOATING_EQUALITY(
		 data_container.getSubshellPhotoelectricCrossSection(2).back(),
		 2.41672669261238441e-08,
		 1e-15 );
  TEST_EQUALITY_CONST(
    data_container.getSubshellPhotoelectricCrossSectionThresholdEnergyIndex(2),
    0 );
  TEST_EQUALITY_CONST(
		 data_container.getSubshellPhotoelectricCrossSection(3).size(),
		 775 );
  TEST_FLOATING_EQUALITY(
		data_container.getSubshellPhotoelectricCrossSection(3).front(),
		3.16445995519961478e+01,
		1e-15 );
  TEST_FLOATING_EQUALITY(
		 data_container.getSubshellPhotoelectricCrossSection(3).back(),
		 2.04871323525023182e-12,
		 1e-15 );
  TEST_EQUALITY_CONST(
    data_container.getSubshellPhotoelectricCrossSectionThresholdEnergyIndex(3),
    0 );
  TEST_EQUALITY_CONST(
		 data_container.getSubshellPhotoelectricCrossSection(4).size(),
		 775 );
  TEST_FLOATING_EQUALITY(
		data_container.getSubshellPhotoelectricCrossSection(4).front(),
		6.28832719669201197e+01,
		1e-15 );
  TEST_FLOATING_EQUALITY(
		 data_container.getSubshellPhotoelectricCrossSection(4).back(),
		 4.72223919011517413e-12,
		 1e-15 );
  TEST_EQUALITY_CONST(
    data_container.getSubshellPhotoelectricCrossSectionThresholdEnergyIndex(4),
    0 );
  TEST_EQUALITY_CONST(
		     data_container.getWallerHartreeTotalCrossSection().size(),
		     775 );
  TEST_FLOATING_EQUALITY(
		    data_container.getWallerHartreeTotalCrossSection().front(),
		    4.40594690580228344e+04,
		    1e-15 );
  TEST_FLOATING_EQUALITY(
		     data_container.getWallerHartreeTotalCrossSection().back(),
		     3.13338538552961843e-01,
		     1e-15 );
  TEST_EQUALITY_CONST(
		     data_container.getImpulseApproxTotalCrossSection().size(),
		     775 );
  TEST_FLOATING_EQUALITY(
		    data_container.getImpulseApproxTotalCrossSection().front(),
		    4.40594857955683474e+04,
		    1e-15 );
  TEST_FLOATING_EQUALITY(
		     data_container.getImpulseApproxTotalCrossSection().back(),
		     3.13351484549591885e-01,
		     1e-15 );

  std::vector<double> energy_grid = data_container.getElectronEnergyGrid();
  TEST_EQUALITY_CONST( energy_grid.front(), 1.0e-5 );
  TEST_EQUALITY_CONST( energy_grid.back(), 1.0e+5 );
  TEST_EQUALITY_CONST( energy_grid.size(), 723 );

  TEST_EQUALITY_CONST( data_container.getCutoffAngle(), 1.0e-6 );

  // Check the elastic data
  unsigned threshold =
    data_container.getCutoffElasticCrossSectionThresholdEnergyIndex();

  TEST_EQUALITY_CONST( threshold, 0 );

  std::vector<double> cross_section =
    data_container.getCutoffElasticCrossSection();

  TEST_EQUALITY_CONST( cross_section.front(), 3.06351e+9 );
  TEST_FLOATING_EQUALITY( cross_section.back(), 4.72309e-4, 1e-15 );
  TEST_EQUALITY_CONST( cross_section.size(), 723-threshold );

  threshold =
    data_container.getScreenedRutherfordElasticCrossSectionThresholdEnergyIndex();

  TEST_EQUALITY_CONST( threshold, 276 );

  cross_section =
    data_container.getScreenedRutherfordElasticCrossSection();

  TEST_EQUALITY_CONST( cross_section.front(), 1.93634596180636436e+01 );
  TEST_EQUALITY_CONST( cross_section.back(), 1.407220E+05-4.723090E-04 );
  TEST_EQUALITY_CONST( cross_section.size(), 723-threshold );

  std::vector<double> angular_grid =
    data_container.getElasticAngularEnergyGrid();

  TEST_EQUALITY_CONST( angular_grid.front(), 1.0e-5 );
  TEST_EQUALITY_CONST( angular_grid.back(), 1.0e+5 );
  TEST_EQUALITY_CONST( angular_grid.size(), 16 );

  std::vector<double> elastic_angles =
    data_container.getAnalogElasticAngles(1.0e-5);

  TEST_EQUALITY_CONST( elastic_angles.front(), 1.0e-6 );
  TEST_EQUALITY_CONST( elastic_angles.back(), 2.0 );
  TEST_EQUALITY_CONST( elastic_angles.size(), 2 );

  elastic_angles =
    data_container.getAnalogElasticAngles(1.0e+5);

  TEST_EQUALITY_CONST( elastic_angles.front(), 1.0e-6 );
  TEST_EQUALITY_CONST( elastic_angles.back(), 2.0 );
  TEST_EQUALITY_CONST( elastic_angles.size(), 96 );

  std::vector<double> elastic_pdf =
    data_container.getAnalogElasticPDF(1.0e-5);

  TEST_EQUALITY_CONST( elastic_pdf.front(), 0.5 );
  TEST_EQUALITY_CONST( elastic_pdf.back(), 0.5 );
  TEST_EQUALITY_CONST( elastic_pdf.size(), 2 );

  elastic_pdf =
    data_container.getAnalogElasticPDF(1.0e+5);

  TEST_EQUALITY_CONST( elastic_pdf.front(), 9.868670E+05 );
  TEST_EQUALITY_CONST( elastic_pdf.back(), 1.693970E-11 );
  TEST_EQUALITY_CONST( elastic_pdf.size(), 96 );

  // Check the electroionization data
  threshold =
    data_container.getElectroionizationCrossSectionThresholdEnergyIndex( 1u );

  TEST_EQUALITY_CONST( threshold, 85 );

  cross_section =
    data_container.getElectroionizationCrossSection( 1u );

  TEST_EQUALITY_CONST( cross_section.front(), 1.10703713515228592e+04 );
  TEST_EQUALITY_CONST( cross_section.back(), 1.338050E+04 );
  TEST_EQUALITY_CONST( cross_section.size(), 723-threshold );

  std::vector<double> electroionization_energy_grid =
    data_container.getElectroionizationEnergyGrid( 1u );

  TEST_EQUALITY_CONST( electroionization_energy_grid.front(), 2.910100E-04 );
  TEST_EQUALITY_CONST( electroionization_energy_grid.back(), 1.00000e+5 );
  TEST_EQUALITY_CONST( electroionization_energy_grid.size(), 7 );

  std::vector<double> electroionization_recoil_energy =
    data_container.getElectroionizationRecoilEnergy( 1u, 2.910100E-04 );

  TEST_EQUALITY_CONST( electroionization_recoil_energy.front(), 1.00000e-8 );
  TEST_EQUALITY_CONST( electroionization_recoil_energy.back(), 1.00000e-7 );
  TEST_EQUALITY_CONST( electroionization_recoil_energy.size(), 2 );

  electroionization_recoil_energy =
    data_container.getElectroionizationRecoilEnergy( 1u, 1.00000e+5 );

  TEST_EQUALITY_CONST( electroionization_recoil_energy.front(), 1.00000e-7 );
  TEST_EQUALITY_CONST( electroionization_recoil_energy.back(), 5.00000e+4 );
  TEST_EQUALITY_CONST( electroionization_recoil_energy.size(), 128 );

  std::vector<double> electroionization_recoil_pdf =
    data_container.getElectroionizationRecoilPDF( 1u, 2.910100E-04 );

  TEST_EQUALITY_CONST( electroionization_recoil_pdf.front(), 1.111110E+07 );
  TEST_EQUALITY_CONST( electroionization_recoil_pdf.back(), 1.111110E+07 );
  TEST_EQUALITY_CONST( electroionization_recoil_pdf.size(), 2 );

  electroionization_recoil_pdf =
    data_container.getElectroionizationRecoilPDF( 1u, 1.00000e+5 );

  TEST_EQUALITY_CONST( electroionization_recoil_pdf.front(), 7.358100E+03 );
  TEST_EQUALITY_CONST( electroionization_recoil_pdf.back(), 3.45597E-14 );
  TEST_EQUALITY_CONST( electroionization_recoil_pdf.size(), 128 );

  threshold =
    data_container.getElectroionizationCrossSectionThresholdEnergyIndex( 4u );

  TEST_EQUALITY_CONST( threshold, 0 );

  cross_section =
    data_container.getElectroionizationCrossSection( 4u );

  TEST_EQUALITY_CONST( cross_section.front(), 2.102930E+07 );
  TEST_EQUALITY_CONST( cross_section.back(), 2.017010E+05 );
  TEST_EQUALITY_CONST( cross_section.size(), 723-threshold );

  electroionization_energy_grid =
    data_container.getElectroionizationEnergyGrid( 4u );

  TEST_EQUALITY_CONST( electroionization_energy_grid.front(), 8.980000E-06 );
  TEST_EQUALITY_CONST( electroionization_energy_grid.back(), 1.00000e+5 );
  TEST_EQUALITY_CONST( electroionization_energy_grid.size(), 8 );

  electroionization_recoil_energy =
    data_container.getElectroionizationRecoilEnergy( 4u, 8.980000E-06 );

  TEST_EQUALITY_CONST( electroionization_recoil_energy.front(), 2.550000E-09 );
  TEST_EQUALITY_CONST( electroionization_recoil_energy.back(), 2.550000E-08 );
  TEST_EQUALITY_CONST( electroionization_recoil_energy.size(), 2 );

  electroionization_recoil_energy =
    data_container.getElectroionizationRecoilEnergy( 4u, 1.00000e+5 );

  TEST_EQUALITY_CONST( electroionization_recoil_energy.front(), 1.00000e-7 );
  TEST_EQUALITY_CONST( electroionization_recoil_energy.back(), 5.00000e+4 );
  TEST_EQUALITY_CONST( electroionization_recoil_energy.size(), 143 );

  electroionization_recoil_pdf =
    data_container.getElectroionizationRecoilPDF( 4u, 8.980000E-06 );

  TEST_EQUALITY_CONST( electroionization_recoil_pdf.front(), 4.357300E+07 );
  TEST_EQUALITY_CONST( electroionization_recoil_pdf.back(), 4.357300E+07 );
  TEST_EQUALITY_CONST( electroionization_recoil_pdf.size(), 2 );

  electroionization_recoil_pdf =
    data_container.getElectroionizationRecoilPDF( 4u, 1.00000e+5 );

  TEST_EQUALITY_CONST( electroionization_recoil_pdf.front(), 1.120930E+05 );
  TEST_EQUALITY_CONST( electroionization_recoil_pdf.back(), 1.515230E-15 );
  TEST_EQUALITY_CONST( electroionization_recoil_pdf.size(), 143 );

  // Check the bremsstrahlung data
  threshold =
    data_container.getBremsstrahlungCrossSectionThresholdEnergyIndex();

  TEST_EQUALITY_CONST( threshold, 0 );

  cross_section =
    data_container.getBremsstrahlungCrossSection();

  TEST_EQUALITY_CONST( cross_section.front(), 6.031280E+02 );
  TEST_EQUALITY_CONST( cross_section.back(), 1.697150E+01 );
  TEST_EQUALITY_CONST( cross_section.size(), 723-threshold );

  std::vector<double> bremsstrahlung_energy_grid =
    data_container.getBremsstrahlungEnergyGrid();

  TEST_EQUALITY_CONST( bremsstrahlung_energy_grid.front(), 1.00000e-5 );
  TEST_EQUALITY_CONST( bremsstrahlung_energy_grid.back(), 1.00000e+5 );
  TEST_EQUALITY_CONST( bremsstrahlung_energy_grid.size(), 9 );

  std::vector<double> bremsstrahlung_photon_energy =
    data_container.getBremsstrahlungPhotonEnergy( 1.00000e-5 );

  TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.front(), 1.00000e-7 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.back(), 1.00000e-5 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.size(), 17 );

  bremsstrahlung_photon_energy =
    data_container.getBremsstrahlungPhotonEnergy( 1.00000e+5 );

  TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.front(), 1.00000e-7 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.back(), 1.00000e+5 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_energy.size(), 105 );

  std::vector<double> bremsstrahlung_photon_pdf =
    data_container.getBremsstrahlungPhotonPDF( 1.00000e-5 );

  TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.front(), 2.134970E+06 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.back(), 2.136140E+04 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.size(), 17 );

  bremsstrahlung_photon_pdf =
    data_container.getBremsstrahlungPhotonPDF( 1.00000e+5 );

  TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.front(), 3.649330E+05 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.back(),  5.638520E-09 );
  TEST_EQUALITY_CONST( bremsstrahlung_photon_pdf.size(), 105 );

  // Check the atomic excitation data
  threshold =
    data_container.getAtomicExcitationCrossSectionThresholdEnergyIndex();

  TEST_EQUALITY_CONST( threshold, 0 );

  cross_section =
    data_container.getAtomicExcitationCrossSection();

  TEST_EQUALITY_CONST( cross_section.front(), 3.168630E+06 );
  TEST_EQUALITY_CONST( cross_section.back(), 1.198920E+05 );
  TEST_EQUALITY_CONST( cross_section.size(), 723-threshold );

  std::vector<double> atomic_excitation_energy_grid =
    data_container.getAtomicExcitationEnergyGrid();

  TEST_EQUALITY_CONST( atomic_excitation_energy_grid.front(), 1.00000e-5 );
  TEST_EQUALITY_CONST( atomic_excitation_energy_grid.back(), 1.00000e+5 );
  TEST_EQUALITY_CONST( atomic_excitation_energy_grid.size(), 181 );

  std::vector<double> atomic_excitation_energy_loss =
    data_container.getAtomicExcitationEnergyLoss();

  TEST_EQUALITY_CONST( atomic_excitation_energy_loss.front(), 9.232690E-06 );
  TEST_EQUALITY_CONST( atomic_excitation_energy_loss.back(), 1.981540E-05 );
  TEST_EQUALITY_CONST( atomic_excitation_energy_loss.size(), 181 );

  data_container.exportData( "test_c_epr.xml",
			     Utility::ArchivableObject::XML_ARCHIVE );
}

//---------------------------------------------------------------------------//
// Custom main function
//---------------------------------------------------------------------------//
int main( int argc, char** argv )
{
  std::string test_h_ace_file_name, test_h_ace_table_name;
  std::string test_c_ace_file_name, test_c_ace_table_name;

  Teuchos::CommandLineProcessor& clp = Teuchos::UnitTestRepository::getCLP();

  clp.setOption( "test_h_ace_file",
		 &test_h_ace_file_name,
		 "Test ACE file name" );
  clp.setOption( "test_h_ace_table",
		 &test_h_ace_table_name,
		 "Test ACE table name" );
  clp.setOption( "test_h_eedl_file",
		 &test_h_eedl_file_name,
		 "Test EEDL file name" );

  clp.setOption( "test_c_ace_file",
		 &test_c_ace_file_name,
		 "Test ACE file name" );
  clp.setOption( "test_c_ace_table",
		 &test_c_ace_table_name,
		 "Test ACE table name" );
  clp.setOption( "test_c_eedl_file",
		 &test_c_eedl_file_name,
		 "Test EEDL file name" );

  const Teuchos::RCP<Teuchos::FancyOStream> out =
    Teuchos::VerboseObjectBase::getDefaultOStream();

  Teuchos::CommandLineProcessor::EParseCommandLineReturn parse_return =
    clp.parse(argc,argv);

  if ( parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
    *out << "\nEnd Result: TEST FAILED" << std::endl;
    return parse_return;
  }

  {
    // Create the file handler and data extractor for hydrogen
    Teuchos::RCP<Data::ACEFileHandler> ace_file_handler(
			       new Data::ACEFileHandler( test_h_ace_file_name,
							 test_h_ace_table_name,
							 1u ) );

    h_xss_data_extractor.reset(
				new Data::XSSEPRDataExtractor(
				      ace_file_handler->getTableNXSArray(),
				      ace_file_handler->getTableJXSArray(),
				      ace_file_handler->getTableXSSArray() ) );
  }

  {
    // Create the file handler and data extractor for hydrogen
    Teuchos::RCP<Data::ACEFileHandler> ace_file_handler(
			       new Data::ACEFileHandler( test_c_ace_file_name,
							 test_c_ace_table_name,
							 1u ) );

    c_xss_data_extractor.reset(
				new Data::XSSEPRDataExtractor(
				      ace_file_handler->getTableNXSArray(),
				      ace_file_handler->getTableJXSArray(),
				      ace_file_handler->getTableXSSArray() ) );
  }

  // Run the unit tests
  Teuchos::GlobalMPISession mpiSession( &argc, &argv );

  const bool success = Teuchos::UnitTestRepository::runUnitTests( *out );

  if (success)
    *out << "\nEnd Result: TEST PASSED" << std::endl;
  else
    *out << "\nEnd Result: TEST FAILED" << std::endl;

  clp.printFinalTimerSummary(out.ptr());

  return (success ? 0 : 1);
}

//---------------------------------------------------------------------------//
// end tstStandardElectronPhotonRelaxationDataGenerator.cpp
//---------------------------------------------------------------------------//


text:
// Copyright (C) 2012-2013 Vicente Botet
//  Copyright (c) 2013 Agustin Berge
//
//  Distributed under the Boost Software License, Version 1.0. (See
//  accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)

#include <hpx/hpx_init.hpp>
#include <hpx/include/threads.hpp>
#include <hpx/include/threadmanager.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/util/lightweight_test.hpp>

#include <utility>
#include <memory>
#include <string>

#include <boost/assign.hpp>
#include <boost/move/move.hpp>

///////////////////////////////////////////////////////////////////////////////
int p1()
{
    hpx::this_thread::sleep_for(boost::chrono::milliseconds(500));
    return 1;
}

int p2(hpx::lcos::future<int> f)
{
    HPX_TEST(f.valid());
    int i = f.get();
    hpx::this_thread::sleep_for(boost::chrono::milliseconds(500));
    return 2 * i;
}

void p3(hpx::lcos::future<int> f)
{
    HPX_TEST(f.valid());
    int i = f.get();
    (void)i;
    hpx::this_thread::sleep_for(boost::chrono::milliseconds(500));
    return;
}

hpx::lcos::future<int> p4(hpx::lcos::future<int> f)
{
    return hpx::async(p2, boost::move(f));
}

///////////////////////////////////////////////////////////////////////////////
void test_return_int()
{
    hpx::lcos::future<int> f1 = hpx::async(hpx::launch::async, &p1);
    HPX_TEST(f1.valid());
    hpx::lcos::future<int> f2 = f1.then(&p2);
    HPX_TEST(f2.valid());
    try {
        HPX_TEST(f2.get()==2);
    }
    catch (hpx::exception const& /*ex*/) {
        HPX_TEST(false);
    }
    catch (...) {
        HPX_TEST(false);
    }
}

///////////////////////////////////////////////////////////////////////////////
void test_return_void()
{
    hpx::lcos::future<int> f1 = hpx::async(hpx::launch::async, &p1);
    HPX_TEST(f1.valid());
    hpx::lcos::future<void> f2 = f1.then(&p3);
    HPX_TEST(f2.valid());
    try {
        f2.wait();
    }
    catch (hpx::exception const& /*ex*/) {
        HPX_TEST(false);
    }
    catch (...) {
        HPX_TEST(false);
    }
}

///////////////////////////////////////////////////////////////////////////////
void test_implicit_unwrapping()
{
    hpx::lcos::future<int> f1 = hpx::async(hpx::launch::async, &p1);
    HPX_TEST(f1.valid());
    hpx::lcos::future<int> f2 = f1.then(&p4);
    HPX_TEST(f2.valid());
    try {
        HPX_TEST(f2.get()==2);
    }
    catch (hpx::exception const& /*ex*/) {
        HPX_TEST(false);
    }
    catch (...) {
        HPX_TEST(false);
    }
}

///////////////////////////////////////////////////////////////////////////////
void test_simple_then()
{
    hpx::lcos::future<int> f2 = hpx::async(p1).then(&p2);
    HPX_TEST(f2.get()==2);
}

///////////////////////////////////////////////////////////////////////////////
void test_complex_then()
{
    hpx::lcos::future<int> f1 = hpx::async(p1);
    hpx::lcos::future<int> f21 = f1.then(&p2);
    hpx::lcos::future<int> f2= f21.then(&p2);
    HPX_TEST(f2.get()==4);
}

///////////////////////////////////////////////////////////////////////////////
void test_complex_then_chain_one()
{
    hpx::lcos::future<int> f1 = hpx::async(p1);
    hpx::lcos::future<int> f2= f1.then(&p2).then(&p2);
    HPX_TEST(f2.get()==4);
}

///////////////////////////////////////////////////////////////////////////////
void test_complex_then_chain_two()
{
    hpx::lcos::future<int> f2 = hpx::async(p1).then(&p2).then(&p2);
    HPX_TEST(f2.get()==4);
}

///////////////////////////////////////////////////////////////////////////////
using boost::program_options::variables_map;
using boost::program_options::options_description;

int hpx_main(variables_map&)
{
    {
        test_return_int();
        test_return_void();
        test_implicit_unwrapping();
        test_simple_then();
        test_complex_then();
        test_complex_then_chain_one();
        test_complex_then_chain_two();
    }

    hpx::finalize();
    return hpx::util::report_errors();
}

///////////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
    // Configure application-specific options
    options_description cmdline("Usage: " HPX_APPLICATION_STRING " [options]");

    // We force this test to use several threads by default.
    using namespace boost::assign;
    std::vector<std::string> cfg;
    cfg += "hpx.os_threads=" +
        boost::lexical_cast<std::string>(hpx::threads::hardware_concurrency());

    // Initialize and run HPX
    return hpx::init(cmdline, argc, argv, cfg);
}

max_stars_repo_name: akemp/hpx

max_issues_repo_name: akemp/hpx

max_forks_repo_name: akemp/hpx


text:
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/*
 Copyright (C) 2004, 2005, 2007 StatPro Italia srl

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <quantlib-dev@lists.sf.net>. The license is also available online at
 <http://quantlib.org/license.shtml>.

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.
*/

/*! \file singleton.hpp
    \brief basic support for the singleton pattern
*/

#ifndef quantlib_singleton_hpp
#define quantlib_singleton_hpp

#include <ql/qldefines.hpp>

#ifdef QL_ENABLE_SINGLETON_THREAD_SAFE_INIT
    #if defined(QL_ENABLE_SESSIONS)
        #ifdef BOOST_MSVC
            #pragma message(\
                "Thread-safe singleton initialization not supported "  \
                "when sessions are enabled.")
        #else
            #warning \
                Thread-safe singleton initialization not supported \
                when sessions are enabled.
        #endif
    #else
        #include <boost/atomic.hpp>
        #include <boost/thread/mutex.hpp>
        #if !defined(BOOST_ATOMIC_ADDRESS_LOCK_FREE)
            #ifdef BOOST_MSVC
                #pragma message(\
                    "Thread-safe singleton initialization "  \
                    "may degrade performances.")
            #else
                #warning \
                    Thread-safe singleton initialization \
                    may degrade performances.
            #endif
        #endif
        #define QL_SINGLETON_THREAD_SAFE_INIT
    #endif
#endif

#include <ql/types.hpp>
#include <ql/shared_ptr.hpp>
#if defined(QL_PATCH_MSVC)
    #pragma managed(push, off)
#endif
#include <boost/noncopyable.hpp>
#if defined(QL_PATCH_MSVC)
    #pragma managed(pop)
#endif
#include <map>

#if (_MANAGED == 1) || (_M_CEE == 1)
// One of the Visual C++ /clr modes. In this case, the global instance
// map must be declared as a static data member of the class.
#define QL_MANAGED 1
#else
// Every other configuration. The map can be declared as a static
// variable inside the creation method.
#define QL_MANAGED 0
#endif

namespace QuantLib {

    // This allows to define a different type if needed, while keeping
    // backwards compatibility with the current implementation.
    // For instance, one might create a file threadkey.hpp with:
    //
    // #include <pthread.h>
    // #define QL_THREAD_KEY pthread_t
    //
    // and then compile QuantLib with the option -DQL_INCLUDE_FIRST=threadkey.hpp
    // to have that file included by qldefines.hpp and thus this one.
    #if defined(QL_THREAD_KEY)
    typedef QL_THREAD_KEY ThreadKey;
    #else
    typedef Integer ThreadKey;
    #endif

    #if defined(QL_ENABLE_SESSIONS)
    // definition must be provided by the user
    ThreadKey sessionId();
    #endif

    // this is required on VC++ when CLR support is enabled
    #if defined(QL_PATCH_MSVC)
        #pragma managed(push, off)
    #endif

    //! Basic support for the singleton pattern.
    /*! The typical use of this class is:
        \code
        class Foo : public Singleton<Foo> {
            friend class Singleton<Foo>;
          private:
            Foo() {}
          public:
            ...
        };
        \endcode
        which, albeit sub-optimal, frees one from the concerns of
        creating and managing the unique instance and can serve later
        as a single implemementation point should synchronization
        features be added.

        \ingroup patterns
    */
    template <class T>
    class Singleton : private boost::noncopyable {
    #if (QL_MANAGED == 1) && !defined(QL_SINGLETON_THREAD_SAFE_INIT)
      private:
        static std::map<ThreadKey, ext::shared_ptr<T> > instances_;
    #endif

    #if defined(QL_SINGLETON_THREAD_SAFE_INIT)
      private:
        static boost::atomic<T*> instance_;
        static boost::mutex mutex_;
    #endif

      public:
        //! access to the unique instance
        static T& instance();
      protected:
        Singleton() = default;
    };

    // static member definitions

    #if (QL_MANAGED == 1) && !defined(QL_SINGLETON_THREAD_SAFE_INIT)
    template <class T>
    std::map<ThreadKey, ext::shared_ptr<T> > Singleton<T>::instances_;
    #endif

    #if defined(QL_SINGLETON_THREAD_SAFE_INIT)
    template <class T>  boost::atomic<T*> Singleton<T>::instance_;
    template <class T> boost::mutex Singleton<T>::mutex_;
    #endif

    // template definitions

    template <class T>
    T& Singleton<T>::instance() {

        #if (QL_MANAGED == 0) && !defined(QL_SINGLETON_THREAD_SAFE_INIT)
        static std::map<ThreadKey, ext::shared_ptr<T> > instances_;
        #endif

        // thread safe double checked locking pattern with atomic memory calls
        #if defined(QL_SINGLETON_THREAD_SAFE_INIT)

        T* instance =  instance_.load(boost::memory_order_consume);

        if (!instance) {
            boost::mutex::scoped_lock guard(mutex_);
            instance = instance_.load(boost::memory_order_consume);
            if (!instance) {
                instance = new T();
                instance_.store(instance, boost::memory_order_release);
            }
        }

        #else //this is not thread safe

        #if defined(QL_ENABLE_SESSIONS)
        ThreadKey id = sessionId();
        #else
        ThreadKey id = 0;
        #endif

        ext::shared_ptr<T>& instance = instances_[id];
        if (!instance)
            instance = ext::shared_ptr<T>(new T);

        #endif

        return *instance;
    }

    // reverts the change above
    #if defined(QL_PATCH_MSVC)
        #pragma managed(pop)
    #endif

}

#undef QL_MANAGED

#endif

ext: hpp

max_stars_repo_name: KazuhisaHirota/QuantLib

max_issues_repo_name: KazuhisaHirota/QuantLib

max_forks_repo_name: puszkarz/QuantLib