コード例 #1
0
 def test_is_uptodate(self):
     '''check if is_update works'''
     
     
     filespath = ['/tmp/mg5/0.txt','/tmp/mg5/1.txt']
     os.system('mkdir /tmp/mg5 > /dev/null 2>&1')
     for i, path in enumerate(filespath):
         os.system('touch %s' % path)
         if i + 1 != len(filespath):
             time.sleep(1)
     
     self.assertTrue(files.is_uptodate(filespath[1], [filespath[0]]))
     self.assertFalse(files.is_uptodate(filespath[0], [filespath[1]]))
     self.assertTrue(files.is_uptodate(filespath[1], [filespath[0], \
                                                              filespath[0]]))
     
     self.assertTrue(files.is_uptodate(filespath[1], [filespath[1]]))
     self.assertTrue(files.is_uptodate(filespath[1]))
     self.assertFalse(files.is_uptodate(filespath[0]))
     self.assertFalse(files.is_uptodate('/xxx/yyyy'))
     self.assertTrue(files.is_uptodate(filespath[1], ['/tmp/mg5']))
     
     self.assertRaises(AssertionError, files.is_uptodate, \
                                                   filespath[1], '/tmp/mg5')
     
     
     
     
     
      
コード例 #2
0
    def generate_production(self):
        """production"""
        
        if os.path.exists('%s/Cards/proc_card_mg5.dat' % self.path):
            proc_path = '%s/Cards/proc_card_mg5.dat' % self.path
            if 'p p > e+ ve [QCD]' in open(proc_path).read():
                if files.is_uptodate(proc_path, min_time=self.loadtime):
                    if hasattr(self, 'cmd_line'):
                        self.cmd_line.exec_cmd('quit')
                    os.system('rm -rf %s/RunWeb' % self.path)
                    os.system('rm -rf %s/Events/run_01' % self.path)
                    os.system('rm -rf %s/Events/run_01_LO' % self.path)                        
                    self.cmd_line = NLOCmd.aMCatNLOCmdShell(me_dir= '%s' % self.path)
                    self.cmd_line.run_cmd('set automatic_html_opening False --no_save')

                    card = open('%s/Cards/run_card_default.dat' % self.path).read()
                    self.assertTrue( '10000 = nevents' in card)
                    card = card.replace('10000 = nevents', '100 = nevents')
                    open('%s/Cards/run_card_default.dat' % self.path, 'w').write(card)
                    os.system('cp  %s/Cards/run_card_default.dat %s/Cards/run_card.dat'% (self.path, self.path))
                    os.system('cp  %s/Cards/shower_card_default.dat %s/Cards/shower_card.dat'% (self.path, self.path))
                    
                    return

        cmd = os.getcwd()
        self.generate(['p p > e+ ve [QCD]'], 'loop_sm')
        self.assertEqual(cmd, os.getcwd())
        self.do('quit')
        card = open('%s/Cards/run_card_default.dat' % self.path).read()
        self.assertTrue( '10000 = nevents' in card)
        card = card.replace('10000 = nevents', '100 = nevents')
        open('%s/Cards/run_card.dat' % self.path, 'w').write(card)
コード例 #3
0
    def generate_production(self):
        """production"""
        
        if os.path.exists('%s/Cards/proc_card_mg5.dat' % self.path):
            proc_path = '%s/Cards/proc_card_mg5.dat' % self.path
            if 'p p > e+ ve [QCD]' in open(proc_path).read():
                if files.is_uptodate(proc_path, min_time=self.loadtime):
                    if hasattr(self, 'cmd_line'):
                        self.cmd_line.exec_cmd('quit')
                    os.system('rm -rf %s/RunWeb' % self.path)
                    os.system('rm -rf %s/Events/run_01' % self.path)
                    os.system('rm -rf %s/Events/run_01_LO' % self.path)                        
                    self.cmd_line = NLOCmd.aMCatNLOCmdShell(me_dir= '%s' % self.path)
                    self.cmd_line.run_cmd('set automatic_html_opening False --no_save')

                    card = open('%s/Cards/run_card_default.dat' % self.path).read()
                    self.assertTrue( '10000 = nevents' in card)
                    card = card.replace('10000 = nevents', '100 = nevents')
                    open('%s/Cards/run_card_default.dat' % self.path, 'w').write(card)
                    os.system('cp  %s/Cards/run_card_default.dat %s/Cards/run_card.dat'% (self.path, self.path))
                    os.system('cp  %s/Cards/shower_card_default.dat %s/Cards/shower_card.dat'% (self.path, self.path))
                    
                    return

        cmd = os.getcwd()
        self.generate(['p p > e+ ve [QCD]'], 'loop_sm')
        self.assertEqual(cmd, os.getcwd())
        self.do('quit')
        card = open('%s/Cards/run_card_default.dat' % self.path).read()
        self.assertTrue( '10000 = nevents' in card)
        card = card.replace('10000 = nevents', '100 = nevents')
        open('%s/Cards/run_card.dat' % self.path, 'w').write(card)
コード例 #4
0
ファイル: import_ufo.py プロジェクト: harrypuuter/tp1
def import_full_model(model_path):
    """ a practical and efficient way to import one of those models 
        (no restriction file use)"""

    assert model_path == find_ufo_path(model_path)
            
    # Check the validity of the model
    files_list_prov = ['couplings.py','lorentz.py','parameters.py',
                       'particles.py', 'vertices.py']
    files_list = []
    for filename in files_list_prov:
        filepath = os.path.join(model_path, filename)
        if not os.path.isfile(filepath):
            raise UFOImportError,  "%s directory is not a valid UFO model: \n %s is missing" % \
                                                         (model_path, filename)
        files_list.append(filepath)
        
    # use pickle files if defined and up-to-date
    if files.is_uptodate(os.path.join(model_path, 'model.pkl'), files_list):
        try:
            model = save_load_object.load_from_file( \
                                          os.path.join(model_path, 'model.pkl'))
        except Exception, error:
            logger.info('failed to load model from pickle file. Try importing UFO from File')
        else:
            # check path is correct 
            if model.has_key('version_tag') and model.get('version_tag') == os.path.realpath(model_path) + str(misc.get_pkg_info()):
                _import_once.append(model_path)
                return model
コード例 #5
0
def import_model(model_path, mgme_dir=MG4DIR, absolute=True):
    """create a model from a MG4 model directory."""

    # Check for a valid directory
    model_path_old = model_path
    model_path = find_model_path(model_path, mgme_dir, absolute)

    files_list = [os.path.join(model_path, 'particles.dat'),\
                  os.path.join(model_path, 'interactions.dat')]

    for filepath in files_list:
        if not os.path.isfile(filepath):
            if not absolute:
                raise InvalidCmd,  "%s directory is not a valid v4 model" % \
                                                                    (model_path)
            else:
                return import_model(model_path_old, mgme_dir, False)

    # use pickle files if defined
    if files.is_uptodate(os.path.join(model_path, 'model.pkl'), files_list):
        model = save_load_object.load_from_file( \
                                          os.path.join(model_path, 'model.pkl'))
        if model.has_key('version_tag') and model.get(
                'version_tag') == os.path.realpath(model_path) + str(
                    misc.get_pkg_info()):
            return model, model_path

    model = base_objects.Model()
    model.set('particles',files.read_from_file( \
                                  os.path.join(model_path, 'particles.dat'),
                                  read_particles_v4))

    model.set('interactions',files.read_from_file( \
                                  os.path.join(model_path, 'interactions.dat'),
                                  read_interactions_v4,
                                  model['particles']))

    model.set('name', os.path.split(model_path)[-1])

    # save in a pickle files to fasten future usage
    if ReadWrite:
        try:
            save_load_object.save_to_file(
                os.path.join(model_path, 'model.pkl'), model)
        except Exception:
            logger.warning("fail to write %s. This is perfectly fine will just prevent speed boost in future load of this model" %\
                           os.path.join(model_path, 'model.pkl'))
    return model, model_path
コード例 #6
0
def import_model(model_path, mgme_dir = MG4DIR, absolute=True):
    """create a model from a MG4 model directory."""

    # Check for a valid directory
    model_path_old = model_path
    model_path = find_model_path(model_path, mgme_dir, absolute)

    files_list = [os.path.join(model_path, 'particles.dat'),\
                  os.path.join(model_path, 'interactions.dat')]
    
    for filepath in files_list:
        if not os.path.isfile(filepath):
            if not absolute:
                raise InvalidCmd,  "%s directory is not a valid v4 model" % \
                                                                    (model_path)
            else:
                return import_model(model_path_old, mgme_dir, False)
                                                                
    # use pickle files if defined
    if files.is_uptodate(os.path.join(model_path, 'model.pkl'), files_list):
        model = save_load_object.load_from_file( \
                                          os.path.join(model_path, 'model.pkl'))
        if model.has_key('version_tag') and model.get('version_tag') == os.path.realpath(model_path) + str(misc.get_pkg_info()):
            return model, model_path

    model = base_objects.Model()    
    model.set('particles',files.read_from_file( \
                                  os.path.join(model_path, 'particles.dat'),
                                  read_particles_v4))
    
    model.set('interactions',files.read_from_file( \
                                  os.path.join(model_path, 'interactions.dat'),
                                  read_interactions_v4,
                                  model['particles']))
    
    model.set('name', os.path.split(model_path)[-1])  

    # save in a pickle files to fasten future usage
    if ReadWrite:
        try:
            save_load_object.save_to_file(os.path.join(model_path, 'model.pkl'), model)
        except Exception:
            logger.warning("fail to write %s. This is perfectly fine will just prevent speed boost in future load of this model" %\
                           os.path.join(model_path, 'model.pkl'))
    return model, model_path  
コード例 #7
0
 def test_is_uptodate(self):
     '''check if is_update works'''
     
     
     filespath = ['/tmp/mg5/0.txt','/tmp/mg5/1.txt']
     os.system('mkdir /tmp/mg5 > /dev/null 2>&1')
     for i, path in enumerate(filespath):
         os.system('touch %s' % path)
         if i + 1 != len(filespath):
             time.sleep(1)
     
     self.assertTrue(files.is_uptodate(filespath[1], [filespath[0]]))
     self.assertFalse(files.is_uptodate(filespath[0], [filespath[1]]))
     self.assertTrue(files.is_uptodate(filespath[1], [filespath[0], \
                                                              filespath[0]]))
     
     self.assertTrue(files.is_uptodate(filespath[1], [filespath[1]]))
     self.assertTrue(files.is_uptodate(filespath[1]))
     self.assertFalse(files.is_uptodate(filespath[0]))
     self.assertFalse(files.is_uptodate('/xxx/yyyy'))
     self.assertTrue(files.is_uptodate(filespath[1], ['/tmp/mg5']))
     
     self.assertRaises(AssertionError, files.is_uptodate, \
                                                   filespath[1], '/tmp/mg5')
コード例 #8
0
ファイル: import_v4.py プロジェクト: cirslinger/Rutgers
def import_model(model_path, mgme_dir = MG4DIR):
    """create a model from a MG4 model directory."""

    # Check for a valid directory
    model_path = find_model_path(model_path, mgme_dir)

    files_list = [os.path.join(model_path, 'particles.dat'),\
                  os.path.join(model_path, 'interactions.dat')]
    
    for filepath in files_list:
        if not os.path.isfile(filepath):
            raise InvalidCmd,  "%s directory is not a valid v4 model" % \
                                                                    (model_path)
                                                                
    # use pickle files if defined
    if files.is_uptodate(os.path.join(model_path, 'model.pkl'), files_list):
        model = save_load_object.load_from_file( \
                                          os.path.join(model_path, 'model.pkl'))
        if model.has_key('version_tag') and model.get('version_tag') == os.path.realpath(model_path) + str(misc.get_pkg_info()):
            return model, model_path

    model = base_objects.Model()    
    model.set('particles',files.read_from_file( \
                                  os.path.join(model_path, 'particles.dat'),
                                  read_particles_v4))
    
    model.set('interactions',files.read_from_file( \
                                  os.path.join(model_path, 'interactions.dat'),
                                  read_interactions_v4,
                                  model['particles']))
    
    model.set('name', os.path.split(model_path)[-1])  

    # save in a pickle files to fasten future usage
    save_load_object.save_to_file(os.path.join(model_path, 'model.pkl'), model)
    
    return model, model_path  
コード例 #9
0
        else:
            raise

    files_list = [os.path.join(model_path, 'particles.dat'),\
                  os.path.join(model_path, 'interactions.dat')]

    for filepath in files_list:
        if not os.path.isfile(filepath):
            if not absolute:
                raise InvalidCmd,  "%s directory is not a valid v4 model" % \
                                                                    (model_path)
            else:
                return import_model(model_path_old, mgme_dir, False)

    # use pickle files if defined
    if files.is_uptodate(os.path.join(model_path, 'model.pkl'), files_list):
        model = save_load_object.load_from_file( \
                                          os.path.join(model_path, 'model.pkl'))
        if model.has_key('version_tag') and model.get(
                'version_tag') == os.path.realpath(model_path) + str(
                    misc.get_pkg_info()):
            return model, model_path

    model = base_objects.Model()
    model.set('particles',files.read_from_file( \
                                  os.path.join(model_path, 'particles.dat'),
                                  read_particles_v4))

    model.set('interactions',files.read_from_file( \
                                  os.path.join(model_path, 'interactions.dat'),
                                  read_interactions_v4,