~maddevelopers/mg5amcnlo/2.7.0

« back to all changes in this revision

Viewing changes to madgraph/interface/madevent_interface.py

  • Committer: olivier-mattelaer
  • Date: 2019-12-11 11:49:05 UTC
  • Revision ID: olivier-mattelaer-20191211114905-o4anvwc4iva817kg
py8 optimization

Show diffs side-by-side

added added

removed removed

Lines of Context:
3941
3941
        tag = self.run_tag
3942
3942
        
3943
3943
        PY8_Card.subruns[0].systemSet('Beams:LHEF',"unweighted_events.lhe.gz")
3944
 
 
3945
 
        if PY8_Card['HEPMCoutput:file']=='auto':
 
3944
        if PY8_Card['HEPMCoutput:file'] in ['auto', 'autoremove']:
 
3945
            if PY8_Card['HEPMCoutput:file'] == 'autoremove':
 
3946
                self.to_store.append('nopy8')
 
3947
            elif 'nopy8' in self.to_store:
 
3948
                self.to_store.remove('nopy8')
3946
3949
            HepMC_event_output = pjoin(self.me_dir,'Events', self.run_name,
3947
3950
                                                  '%s_pythia8_events.hepmc'%tag)
3948
3951
            PY8_Card.MadGraphSet('HEPMCoutput:file','%s_pythia8_events.hepmc'%tag, force=True)
4657
4660
                        ######################################################################
4658
4661
                        for hepmc_file in all_hepmc_files:
4659
4662
                            # Remove in an efficient way the starting and trailing HEPMC tags
4660
 
                            if sys.platform == 'darwin':
 
4663
                            # check for support of negative argument in head
 
4664
                            pid = os.system('head -n -1 %s &> /dev/null' % __file__)
 
4665
                            if pid == 0:
 
4666
                                os.system('head -n -1 %s | tail -n +%d > %s/tmpfile' % 
 
4667
                                          (hepmc_file, n_head, os.path.dirname(hepmc_file)))
 
4668
                                misc.call(['mv', 'tmp', os.path.basename(hepmc_file)], cwd=os.path.dirname(hepmc_file))
 
4669
                            elif sys.platform == 'darwin':
4661
4670
                                # sed on MAC has slightly different synthax than on
4662
4671
                                os.system(' '.join(['sed','-i',"''","'%s;$d'"%
4663
4672
                                        (';'.join('%id'%(i+1) for i in range(n_head))),hepmc_file]))          
4664
4673
                            else:
 
4674
                                
 
4675
                                
 
4676
                                os.system('head -n -1')
 
4677
                                os.system(' '.join(['head','-n','-1',hepmc_file,'|','tail','-n','+'+str(n_head),'>','tmpfile']))
 
4678
                                os.system(' '.join(['mv','tmpfile',hepmc_file]))
 
4679
                                
4665
4680
                                # other UNIX systems 
4666
4681
                                os.system(' '.join(['sed','-i']+["-e '%id'"%(i+1) for i in range(n_head)]+
4667
4682
                                                                            ["-e '$d'",hepmc_file]))
5329
5344
            misc.gzip(pjoin(p,'pythia_events.hep'), 
5330
5345
                      stdout=pjoin(p, str(n),'%s_pythia_events.hep' % t))
5331
5346
 
5332
 
        if 'pythia8' in self.to_store:            
 
5347
        if 'pythia8' in self.to_store:
5333
5348
            p = pjoin(self.me_dir,'Events')
5334
5349
            n = self.run_name
5335
5350
            t = tag
5336
5351
            file_path = pjoin(p, n ,'%s_pythia8_events.hepmc'%t)
5337
5352
            self.to_store.remove('pythia8')
5338
5353
            if os.path.isfile(file_path):
5339
 
                self.update_status('Storing Pythia8 files of previous run', 
5340
 
                                                     level='pythia', error=True)
5341
 
                misc.gzip(file_path,stdout=file_path)
 
5354
                if 'nopy8' in self.to_store:
 
5355
                    os.remove(file_path)
 
5356
                else:   
 
5357
                    self.update_status('Storing Pythia8 files of previous run', 
 
5358
                                                         level='pythia', error=True)
 
5359
                    misc.gzip(file_path,stdout=file_path)
5342
5360
    
5343
5361
        self.update_status('Done', level='pythia',makehtml=False,error=True)
5344
5362
        self.results.save()