Ejemplo n.º 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)])
Ejemplo n.º 2
0
    def test_history(self):
        """
        Make sure history is updated properly
        """

        inserter.put_xsec('TestDataset',
                          10.0,
                          'A guess I thought of',
                          'This needs to be updated!',
                          cnf=self.cnf)

        time.sleep(2)

        inserter.put_xsec('TestDataset', 11.0, 'test', cnf=self.cnf)

        conn = MySQLdb.connect(read_default_file=self.cnf,
                               read_default_group='mysql-crosssec-reader',
                               db='cross_sections')
        curs = conn.cursor()

        curs.execute(
            'SELECT sample, cross_section, source, comments FROM xs_13TeV_history ORDER BY last_updated DESC'
        )

        self.assertEqual(curs.fetchone(), ('TestDataset', 11.0, 'test', ''))
        self.assertEqual(curs.fetchone(),
                         ('TestDataset', 10.0, 'A guess I thought of',
                          'This needs to be updated!'))

        conn.close()
Ejemplo n.º 3
0
    def test_invalid(self):
        """
        Make sure zero cross section throws InvalidDataset exception
        """

        inserter.put_xsec('Invalid', 0.0, 'test', cnf=self.cnf)
        inserter.put_xsec('Valid', 10.0, 'test', cnf=self.cnf)

        self.assertRaises(reader.InvalidDataset,
                          reader.get_xsec,
                          'Invalid',
                          cnf=self.cnf)
        self.assertRaises(reader.InvalidDataset,
                          reader.get_xsec, ['Valid', 'Invalid'],
                          cnf=self.cnf)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    def test_history_dump(self):
        """
        Test the history dump
        """

        inserter.put_xsec('TestDataset',
                          10.0,
                          'A guess I thought of',
                          'This needs to be updated!',
                          cnf=self.cnf)
        time.sleep(2)
        inserter.put_xsec('TestDataset', 11.0, 'test', cnf=self.cnf)

        history = reader.dump_history('TestDataset', cnf=self.cnf)

        self.assertEqual(history.keys(), ['TestDataset'])

        self.assertEqual(history['TestDataset'][0]['cross_section'], 11.0)
        self.assertEqual(history['TestDataset'][1]['cross_section'], 10.0)
Ejemplo n.º 7
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])
Ejemplo n.º 8
0
    def test_like(self):
        """
        Make sure that the reader.get_samples_like works correctly
        """

        self.assertFalse(reader.get_samples_like('Fake%', cnf=self.cnf))

        inserter.put_xsec('One1', 11.0, 'test', cnf=self.cnf)
        inserter.put_xsec('One2', 12.0, 'test', cnf=self.cnf)
        inserter.put_xsec('Two1', 21.0, 'test', cnf=self.cnf)
        inserter.put_xsec('Two2', 22.0, 'test', cnf=self.cnf)

        self.assertEqual(reader.get_samples_like('One%', cnf=self.cnf),
                         ['One1', 'One2'])
        self.assertEqual(
            reader.get_samples_like(['One%', 'Two%'], cnf=self.cnf),
            ['One1', 'One2', 'Two1', 'Two2'])
Ejemplo n.º 9
0
    def test_all_fields_full(self):
        """
        Just check that the date, source, and comments fields are correctly filled.
        """
        inserter.put_xsec('TestDataset',
                          10.0,
                          'test',
                          'Here is a comment',
                          cnf=self.cnf)

        conn = MySQLdb.connect(read_default_file=self.cnf,
                               read_default_group='mysql-crosssec-reader',
                               db='cross_sections')
        curs = conn.cursor()
        curs.execute(
            'SELECT sample, cross_section, last_updated, source, comments FROM xs_13TeV'
        )

        stored = curs.fetchone()

        conn.close()

        for value in stored:
            self.assertTrue(value)
Ejemplo n.º 10
0
    if len(sys.argv) < 4 or sys.argv[1] in ['-h', '--help']:
        print __doc__
        exit(0)

    # Get the comments, if there
    comments = '='.join(sys.argv.pop(1).split('=')[1:]) \
        if sys.argv[1].startswith('--comments=') else ''

    # Get the source
    source = sys.argv[1]

    # Get the samples, cross sections, and uncertainties

    samples = sys.argv[2::2]

    xs = []
    unc = []
    for xs_arg in sys.argv[3::2]:
        splitted = xs_arg.split('+-')
        xs.append(float(splitted[0]))

        if len(splitted) > 1:
            unc.append(float(splitted[1]))
        else:
            unc.append(0.0)

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

    put_xsec(samples, xs, source, comments, energy=energy, uncertainties=unc)
Ejemplo n.º 11
0
        exit(1)

    history_dump = reader.dump_history(args, energy=ENERGY)

    if not history_dump:
        print 'No history found for any of your arguments: %s' % args
        exit(2)

    values_to_change = curses.wrapper(main, history_dump)

    samples = []
    cross_sections = []
    sources = []
    commentses = []
    uncerts = []

    for sample, xs, unc, source, comments, old_xs, old_unc in values_to_change:
        print '%s: %s +- %s ===> %s +- %s' % (sample, old_xs, old_unc, xs, unc)
        samples.append(sample)
        cross_sections.append(xs)
        sources.append(source)
        commentses.append(comments)
        uncerts.append(unc)

    if not values_to_change:
        print 'No changes made.'

    else:
        inserter.put_xsec(samples, cross_sections, sources,
                          commentses, energy=ENERGY, uncertainties=uncerts)