A python-only algorithm for running more events in MadGraph
Definition at line 10 of file MadGraphTopUpAlg.py.
◆ __init__()
def python.MadGraphTopUpAlg.MadGraphTopUpAlg.__init__ |
( |
|
self, |
|
|
|
name = "MG_TopUp" , |
|
|
|
topUpSvcName = "EvgenOTFTopUpSvc" , |
|
|
|
threshold = 50 |
|
) |
| |
Definition at line 15 of file MadGraphTopUpAlg.py.
15 def __init__(self, name="MG_TopUp", topUpSvcName="EvgenOTFTopUpSvc", threshold=50):
16 super(MadGraphTopUpAlg,self).
__init__(name=name)
17 self.topUpSvcName = topUpSvcName
19 self.threshold = threshold
22 if 'ATHENA_CORE_NUMBER' in os.environ:
23 self.njobs = os.environ[
'ATHENA_CORE_NUMBER']
24 self.mode = 0
if self.njobs==1
else 2
◆ execute()
def python.MadGraphTopUpAlg.MadGraphTopUpAlg.execute |
( |
|
self | ) |
|
Definition at line 37 of file MadGraphTopUpAlg.py.
39 if self.topUpSvc
is None:
40 return StatusCode.Success
43 if float(self.topUpSvc.getNPerFile()-self.topUpSvc.getNUsedSoFar())*self.topUpSvc.getEfficiency()>self.threshold:
45 return StatusCode.Success
50 if os.access(
'madevent',os.R_OK):
51 self.msg.
info(
'Found a grid pack at madevent/ - using it for generation' )
53 elif len( glob.glob(
'*PROC*' ) )==0:
54 self.msg.
error(
'Need to re-run, but cannot find directory for running!' )
55 return StatusCode.Failure
57 a_dir =
sorted( glob.glob(
'*PROC*' ) )[-1]
58 self.msg.
info(
'Running from process directory '+a_dir )
64 oldcard_f =
open(
'Cards/run_card.dat',
'r')
65 oldlines = oldcard_f.readlines()
67 newcard =
open(
'Cards/run_card.dat',
'w')
69 if ' nevents ' in line:
70 newcard.write(
' %i = nevents ! Number of unweighted events requested \n'%(self.topUpSvc.getNPerFile()))
71 elif ' iseed ' in line:
72 old_seed =
int( line.split()[0] )
73 newcard.write(
' %i = iseed ! rnd seed (0=assigned automatically=default)) \n'%(old_seed+2000000))
79 self.msg.
info(
'Started generating at '+
str(time.asctime()) )
81 self.msg.
info(
'Running parallel generation. Should be nice and fast.')
82 generate = subprocess.Popen([
'bin/generate_events',
str(self.mode),
str(self.njobs),
'OTFTopUp'],stdin=subprocess.PIPE)
84 self.msg.
info(
'Running serial generation. This will take a bit more time than parallel generation.')
85 generate = subprocess.Popen([
'bin/generate_events',
'0',
'OTFTopUp'],stdin=subprocess.PIPE)
87 self.msg.
info(
'Finished generating at'+
str(time.asctime()) )
90 a_new_file_name =
'otf_lhe.events'
91 if len( glob.glob( currdir+
'/*events.[*0-9]' ) )>0:
92 a_new_file_name =
sorted( glob.glob( currdir+
'/*events.[*0-9]' ) )[-1]
93 a_new_file_name = a_new_file_name[:a_new_file_name.rfind(
'.')]+
str(
int(a_new_file_name.split(
'.')[-1])+1 )
94 elif len( glob.glob( currdir+
'/*events' ) )>0:
95 a_new_file_name =
sorted( glob.glob( currdir+
'/*events' ) )[-1]+
'.1'
98 if '/' in a_new_file_name:
99 a_new_file_name = a_new_file_name.split(
'/')[-1]
102 unzip = subprocess.Popen([
'gunzip',
'Events/OTFTopUp/unweighted_events.lhe.gz'])
104 shutil.move(
'Events/OTFTopUp/unweighted_events.lhe',currdir+
'/'+a_new_file_name)
110 self.fileList += [ a_new_file_name ]
111 if len(self.fileList)>2:
113 self.msg.
info(
'Removing old file '+self.fileList[-3])
114 if os.access( currdir+
'/'+self.fileList[-3] , os.R_OK ):
115 remove_old = subprocess.Popen([
'rm',(currdir+
'/'+self.fileList[-3])])
119 self.topUpSvc.newFile( a_new_file_name )
121 return StatusCode.Success
◆ initialize()
def python.MadGraphTopUpAlg.MadGraphTopUpAlg.initialize |
( |
|
self | ) |
|
Definition at line 27 of file MadGraphTopUpAlg.py.
28 self.topUpSvc = getattr(svcMgr, self.topUpSvcName,
None)
29 if self.topUpSvc
is not None:
30 self.msg.
info(
'Got the top up service')
32 self.msg.warning(
'Could not get the top up service! Will be a null-op.' )
34 self.msg.
info(
'Lucky you - you are running on a full node queue. Will re-configure for '+
str(self.njobs)+
' jobs.')
35 return StatusCode.Success
◆ fileList
python.MadGraphTopUpAlg.MadGraphTopUpAlg.fileList |
◆ mode
python.MadGraphTopUpAlg.MadGraphTopUpAlg.mode |
◆ njobs
python.MadGraphTopUpAlg.MadGraphTopUpAlg.njobs |
◆ threshold
python.MadGraphTopUpAlg.MadGraphTopUpAlg.threshold |
◆ topUpSvc
python.MadGraphTopUpAlg.MadGraphTopUpAlg.topUpSvc |
◆ topUpSvcName
python.MadGraphTopUpAlg.MadGraphTopUpAlg.topUpSvcName |
The documentation for this class was generated from the following file: