ATLAS Offline Software
Public Member Functions | Public Attributes | List of all members
python.MadGraphTopUpAlg.MadGraphTopUpAlg Class Reference
Inheritance diagram for python.MadGraphTopUpAlg.MadGraphTopUpAlg:
Collaboration diagram for python.MadGraphTopUpAlg.MadGraphTopUpAlg:

Public Member Functions

def __init__ (self, name="MG_TopUp", topUpSvcName="EvgenOTFTopUpSvc", threshold=50)
 
def initialize (self)
 
def execute (self)
 

Public Attributes

 topUpSvcName
 
 topUpSvc
 
 threshold
 
 njobs
 
 mode
 
 fileList
 

Detailed Description

A python-only algorithm for running more events in MadGraph

Definition at line 10 of file MadGraphTopUpAlg.py.

Constructor & Destructor Documentation

◆ __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
18  self.topUpSvc = None
19  self.threshold = threshold
20 
21  self.njobs = 1
22  if 'ATHENA_PROC_NUMBER' in os.environ:
23  self.njobs = os.environ['ATHENA_PROC_NUMBER']
24  self.mode = 0 if self.njobs==1 else 2
25  self.fileList = []
26 

Member Function Documentation

◆ execute()

def python.MadGraphTopUpAlg.MadGraphTopUpAlg.execute (   self)

Definition at line 37 of file MadGraphTopUpAlg.py.

37  def execute(self):
38  # If we did not manage to get the top up service, just get out of here
39  if self.topUpSvc is None:
40  return StatusCode.Success
41 
42  # See if it's time to make more events
43  if float(self.topUpSvc.getNPerFile()-self.topUpSvc.getNUsedSoFar())*self.topUpSvc.getEfficiency()>self.threshold:
44  # Plenty of events left - get out of here
45  return StatusCode.Success
46 
47  # Not enough events! Top it up!
48  a_dir = None
49  # Call another generate - first find out where to go
50  if os.access('madevent',os.R_OK):
51  self.msg.info( 'Found a grid pack at madevent/ - using it for generation' )
52  a_dir = 'madevent'
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
56  else:
57  a_dir = sorted( glob.glob( '*PROC*' ) )[-1]
58  self.msg.info( 'Running from process directory '+a_dir )
59 
60  currdir=os.getcwd()
61  os.chdir(a_dir)
62 
63  # Modify the random number seed - increment by 2M
64  oldcard_f = open('Cards/run_card.dat','r')
65  oldlines = oldcard_f.readlines()
66  oldcard_f.close()
67  newcard = open('Cards/run_card.dat','w')
68  for line in oldlines:
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))
74  else:
75  newcard.write(line)
76  newcard.close()
77 
78  # Do the actual generation - should we use the generate* functions in MGC_Utils directly?
79  self.msg.info( 'Started generating at '+str(time.asctime()) )
80  if self.njobs>1:
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)
83  else:
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)
86  generate.wait()
87  self.msg.info( 'Finished generating at'+str(time.asctime()) )
88 
89  # Move the events to something local...
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'
96 
97  # Make sure we have trimmed off any directory names
98  if '/' in a_new_file_name:
99  a_new_file_name = a_new_file_name.split('/')[-1]
100 
101  # Unzip the files and move them in place
102  unzip = subprocess.Popen(['gunzip','Events/OTFTopUp/unweighted_events.lhe.gz'])
103  unzip.wait()
104  shutil.move('Events/OTFTopUp/unweighted_events.lhe',currdir+'/'+a_new_file_name)
105 
106  # Go back
107  os.chdir(currdir)
108 
109  # Remove the oldest file to save disk space
110  self.fileList += [ a_new_file_name ]
111  if len(self.fileList)>2:
112  # One old file, one new file, and delete the third
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])])
116  remove_old.wait()
117 
118  # Pass the information back to the top up service
119  self.topUpSvc.newFile( a_new_file_name )
120 
121  return StatusCode.Success

◆ initialize()

def python.MadGraphTopUpAlg.MadGraphTopUpAlg.initialize (   self)

Definition at line 27 of file MadGraphTopUpAlg.py.

27  def initialize(self):
28  self.topUpSvc = getattr(svcMgr, self.topUpSvcName, None)
29  if self.topUpSvc is not None:
30  self.msg.info('Got the top up service')
31  else:
32  self.msg.warning( 'Could not get the top up service! Will be a null-op.' )
33  if self.njobs>1:
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
36 

Member Data Documentation

◆ fileList

python.MadGraphTopUpAlg.MadGraphTopUpAlg.fileList

Definition at line 25 of file MadGraphTopUpAlg.py.

◆ mode

python.MadGraphTopUpAlg.MadGraphTopUpAlg.mode

Definition at line 24 of file MadGraphTopUpAlg.py.

◆ njobs

python.MadGraphTopUpAlg.MadGraphTopUpAlg.njobs

Definition at line 21 of file MadGraphTopUpAlg.py.

◆ threshold

python.MadGraphTopUpAlg.MadGraphTopUpAlg.threshold

Definition at line 19 of file MadGraphTopUpAlg.py.

◆ topUpSvc

python.MadGraphTopUpAlg.MadGraphTopUpAlg.topUpSvc

Definition at line 18 of file MadGraphTopUpAlg.py.

◆ topUpSvcName

python.MadGraphTopUpAlg.MadGraphTopUpAlg.topUpSvcName

Definition at line 17 of file MadGraphTopUpAlg.py.


The documentation for this class was generated from the following file:
grepfile.info
info
Definition: grepfile.py:38
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
initialize
void initialize()
Definition: run_EoverP.cxx:894
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40
str
Definition: BTagTrackIpAccessor.cxx:11
error
Definition: IImpactPoint3dEstimator.h:70
readCCLHist.float
float
Definition: readCCLHist.py:83