示例#1
0
    def test_uncertainties(self):
        """
        This is a test for the uncertainty fetching and retrieval.
        """
        # Try with relative uncertainty
        inserter.put_xsec('TestDataset',
                          50.0,
                          'test',
                          cnf=self.cnf,
                          uncertainties=0.2,
                          unc_type=inserter.REL_UNCERTAINTY)
        self.assertEqual(
            reader.get_xsec('TestDataset', cnf=self.cnf, get_uncert=True),
            (50.0, 10.0))

        # We can also put in parallel lists of uncertainties
        inserter.put_xsec(['Test1', 'Test2'], [10.0, 20.0],
                          'test',
                          cnf=self.cnf,
                          uncertainties=[2.0, 3.0])
        self.assertEqual(
            reader.get_xsec('Test1', cnf=self.cnf, get_uncert=True),
            (10.0, 2.0))
        self.assertEqual(
            reader.get_xsec('Test2', cnf=self.cnf, get_uncert=True),
            (20.0, 3.0))

        self.assertEqual(
            reader.get_xsec(['TestDataset', 'Test1', 'Test2'],
                            cnf=self.cnf,
                            get_uncert=True), [(50.0, 10.0), (10.0, 2.0),
                                               (20.0, 3.0)])
示例#2
0
    def test_update_existing(self):
        """
        Make sure that updating existing entry works
        """
        inserter.put_xsec('TestDataset',
                          10.0,
                          'A guess I thought of',
                          'This needs to be updated!',
                          cnf=self.cnf)
        self.assertEqual(reader.get_xsec('TestDataset', cnf=self.cnf), 10.0)

        time.sleep(2)

        inserter.put_xsec('TestDataset', 11.0, 'test', cnf=self.cnf)
        self.assertEqual(reader.get_xsec('TestDataset', cnf=self.cnf), 11.0)
示例#3
0
    def test_defaults(self):
        """
        This is just a test to check that inserting
        and reading under normal operations behaves
        appropriately.
        """
        # We can put in cross sections one at a time
        inserter.put_xsec('TestDataset', 45.0, 'test', cnf=self.cnf)
        self.assertEqual(reader.get_xsec('TestDataset', cnf=self.cnf), 45.0)

        # We can also put in parallel lists
        inserter.put_xsec(['Test1', 'Test2'], [10.0, 20.0],
                          'test',
                          cnf=self.cnf)
        self.assertEqual(reader.get_xsec('Test1', cnf=self.cnf), 10.0)
        self.assertEqual(reader.get_xsec('Test2', cnf=self.cnf), 20.0)

        self.assertEqual(
            reader.get_xsec(['TestDataset', 'Test1', 'Test2'], cnf=self.cnf),
            [45.0, 10.0, 20.0])
示例#4
0
    def test_other_energy(self):
        """
        This is a test to check that the non-default
        energy tables work as intended.
        """
        self.assertRaises(inserter.BadInput,
                          inserter.put_xsec,
                          'TestBadEnergy',
                          1.0,
                          'test',
                          energy=4,
                          cnf=self.cnf)

        inserter.put_xsec('TestDataset', 45.0, 'test', energy=8, cnf=self.cnf)
        self.assertEqual(
            reader.get_xsec('TestDataset', energy=8, cnf=self.cnf), 45.0)
示例#5
0
Example:

  XSECCONF=$HOME/my.cnf ENERGY=8 get_xs.py sample_i_definitely_stored_elsewhere

Author:

  Daniel Abercrombie <*****@*****.**>
"""

import os
import sys

from CrossSecDB.reader import get_xsec

if __name__ == '__main__':

    if len(sys.argv) == 1 or sys.argv[1] in ['-h', '--help']:
        print __doc__
        exit(0)

    energy = int(os.environ.get('ENERGY', 13))

    output = get_xsec(sys.argv[1:], energy=energy)

    if isinstance(output, list):
        for xs in output:
            print xs

    else:
        print output