Beispiel #1
0
    def test_PY8Card_basic(self):
        """ Basic consistency check of a read-write of the default card."""

        pythia8_card_out = bannermod.PY8Card()
        out = StringIO.StringIO()
        pythia8_card_out.write(out, self.basic_PY8_template)
        #       misc.sprint('WRITTEN:',out.getvalue())

        pythia8_card_read = bannermod.PY8Card()
        # Rewind
        out.seek(0)
        pythia8_card_read.read(out)
        self.assertEqual(pythia8_card_out, pythia8_card_read)

        return

        # Below are some debug lines, comment the above return to run them
        # ==========
        # Keep the following if you want to print out all parameters with
        # print_only_visible=False
        pythia8_card_read.system_set = set(
            [k.lower() for k in pythia8_card_read.keys()])
        for subrunID in pythia8_card_read.subruns.keys():
            pythia8_card_read.subruns[subrunID].system_set = \
              set([k.lower() for k in pythia8_card_read.subruns[subrunID].keys()])
        # ==========

        out = StringIO.StringIO()
        pythia8_card_read.write(out, self.basic_PY8_template)
        misc.sprint('READ:', out.getvalue())
        out = StringIO.StringIO()
        pythia8_card_read.write(out,
                                self.basic_PY8_template,
                                print_only_visible=True)
        misc.sprint('Only visible:', out.getvalue())
Beispiel #2
0
    def test_PY8Card_with_subruns(self):
        """ Basic consistency check of a read-write of the default card."""

        default_PY8Card = bannermod.PY8Card(self.basic_PY8_template)

        template_with_subruns = self.basic_PY8_template + \
"""
Main:subrun=0
! My Run 0
blabla=2
Main:numberOfEvents      = 0
Main:subrun=7
! My Run 7
Main:numberOfEvents      = 73
Beams:LHEF='events_miaou.lhe.gz'
Main:subrun=12
! My other Run 
Main:numberOfEvents      = 120
bloublou=kramoisi
Beams:LHEF='events_ouaf.lhe.gz'
"""
        modified_PY8Card = bannermod.PY8Card(template_with_subruns)

        # Add the corresponding features to the default PY8 card
        default_PY8Card.subruns[0].add_param('blabla', '2')
        default_PY8Card.subruns[0]['Main:numberOfEvents'] = 0
        PY8SubRun7 = bannermod.PY8SubRun(subrun_id=7)
        PY8SubRun7['Beams:LHEF'] = 'events_miaou.lhe.gz'
        PY8SubRun7['Main:numberOfEvents'] = 73
        default_PY8Card.add_subrun(PY8SubRun7)
        PY8SubRun12 = bannermod.PY8SubRun(subrun_id=12)
        PY8SubRun12['Beams:LHEF'] = 'events_ouaf.lhe.gz'
        PY8SubRun12['Main:numberOfEvents'] = 120
        PY8SubRun12.add_param('bloublou', 'kramoisi')
        default_PY8Card.add_subrun(PY8SubRun12)
        self.assertEqual(default_PY8Card, modified_PY8Card)

        # Now write the card
        out = StringIO.StringIO()
        modified_PY8Card.write(out, self.basic_PY8_template)
        out.seek(0)
        read_PY8Card = bannermod.PY8Card(out)
        self.assertEqual(modified_PY8Card, read_PY8Card)

        # Now write the card, and write all parameters, including hidden ones.
        # We force that by setting them 'system_set'
        modified_PY8Card.system_set = set(
            [k.lower() for k in modified_PY8Card.keys()])
        for subrunID in modified_PY8Card.subruns.keys():
            modified_PY8Card.subruns[subrunID].system_set = \
              set([k.lower() for k in modified_PY8Card.subruns[subrunID].keys()])
        out = StringIO.StringIO()
        modified_PY8Card.write(out, self.basic_PY8_template)
        out.seek(0)
        read_PY8Card = bannermod.PY8Card(out)
        self.assertEqual(modified_PY8Card, read_PY8Card)