Skip to content
This repository was archived by the owner on Jul 8, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion madgraph_gridpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MadgraphGridpack(Gridpack):

def prepare_default_card(self):
"""
Copy default cards to local directory
Copy default cards to local directory : proc_card.dat and madspin_card.dat
"""
cards_path = self.get_cards_path()
job_files_path = self.get_job_files_path()
Expand All @@ -17,6 +17,26 @@ def prepare_default_card(self):
if glob.glob(f'{cards_path}/*_cuts.f'):
os.system(f'cp {cards_path}/*_cuts.f {job_files_path}')


def get_proc_card(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't do anything in madgraph_gridpack.py. It's only for main.py:get_proc_card web api purposes

"""
Read proc card
Glue madspin card if it exists
"""
if glob.glob(f'{cards_path}/*_proc_card.dat'):
with open(f'{cards_path}/*_proc_card.dat') as input_file:
proc_card = input_file.read()
else:
raise Exception(f'Could not find {cards_path} as process card')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proc card should always exist


if glob.glob(f'{cards_path}/*_madspin_card.dat'):
with open(f'{cards_path}/*_madpsin_card.dat') as input_file:
proc_card += '\n\n\n\n\n\n#### madspin_card.dat\n'
proc_card += input_file.read()

return proc_card

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

madspin card depends on situation, add #### banner to split proc_card and madspin_card.dat parts


def get_run_card(self):
"""
Get cards from "Template" directory and customize them
Expand Down
29 changes: 22 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,19 @@ def get_gridpacks():
return output_text([gridpacks, count])


@app.route('/api/get_fragment/<string:gridpack_id>')
def get_fragment(gridpack_id):
@app.route('/api/get_proc_card/<string:gridpack_id>')
def get_proc_card(gridpack_id):
"""
API to get gridpack's fragment
API to get gridpack's proc card
"""
database = Database()
gridpack_json = database.get_gridpack(gridpack_id)
if not gridpack_json:
return output_text({'message': 'Gridpack not found'}, code=404)

gridpack = Gridpack.make(gridpack_json)
fragment_builder = FragmentBuilder()
fragment = fragment_builder.build_fragment(gridpack)

return output_text(fragment, headers={'Content-Type': 'text/plain'})
content = gridpack.get_proc_card()
return output_text(content, headers={'Content-Type': 'text/plain'})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are proc_card reading part from madgraph_gridpack.get_proc_card()



@app.route('/api/get_run_card/<string:gridpack_id>')
Expand Down Expand Up @@ -305,6 +303,23 @@ def get_customize_card(gridpack_id):
return output_text(content, headers={'Content-Type': 'text/plain'})


@app.route('/api/get_fragment/<string:gridpack_id>')
def get_fragment(gridpack_id):
"""
API to get gridpack's fragment
"""
database = Database()
gridpack_json = database.get_gridpack(gridpack_id)
if not gridpack_json:
return output_text({'message': 'Gridpack not found'}, code=404)

gridpack = Gridpack.make(gridpack_json)
fragment_builder = FragmentBuilder()
fragment = fragment_builder.build_fragment(gridpack)

return output_text(fragment, headers={'Content-Type': 'text/plain'})


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this i didn't really touch other than copy pasting to this other lines

def user_info_dict():
"""
Get user name, login, email and authorized flag from request headers
Expand Down
44 changes: 25 additions & 19 deletions powheg_gridpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ class PowhegGridpack(Gridpack):

def get_run_card(self):
"""
Get cards from "Template" directory and customize them
Get cards from "ModelParams" directory and customize them
Glue them together
Get cards from "Template" directory and customize them (run card)
"""
dataset_dict = self.get_dataset_dict()
campaign_dict = self.get_campaign_dict()
Expand All @@ -24,6 +22,14 @@ def get_run_card(self):
dataset_dict.get('template_user', []),
template_vars)

return run_card

def get_customize_card(self)
"""
Get cards from "ModelParams" directory and customize them (customize card)
"""
dataset_dict = self.get_dataset_dict()
campaign_dict = self.get_campaign_dict()
model_params_path = self.get_model_params_path()
model_params_name = dataset_dict['model_params']
model_params_vars = dataset_dict.get('model_params_vars', [])
Expand All @@ -33,21 +39,21 @@ def get_run_card(self):
dataset_dict.get('model_params_user', []),
model_params_vars)

return run_card + '\n' + customize_card
return customize_card
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run card and customize card are split into two now (for better api displays)


def prepare_run_card(self):
def prepare_input_card(self):
"""
Get run card and write it to job files dir
Get run card and customize card, glue them together into input card and write it to job files dir
"""
job_files_path = self.get_job_files_path()
output_file_name = os.path.join(job_files_path, 'powheg.input')
run_card = self.get_run_card()
self.logger.debug('Writing customized run card %s', output_file_name)
self.logger.debug(run_card)
input_card = self.get_run_card() + '\n\n\n\n' + self.get_customize_card()
self.logger.debug('Writing customized input card %s', output_file_name)
self.logger.debug(input_card)
with open(output_file_name, 'w') as output_file:
output_file.write(run_card)
output_file.write(input_card)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename run_card to input_card following powheg input convention powheg.input
Here run_card and customize_card are read, glued, and written to powheg.input


def get_customize_card(self):
def get_proc_card(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply rename

"""
Create card with just the process name for proper Powheg gridpack
production
Expand All @@ -56,25 +62,25 @@ def get_customize_card(self):
template_name = dataset_dict['template']
return template_name.split('.', 1)[0]

def prepare_customize_card(self):
def prepare_proc_card(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simply renamed

"""
Get customize card and write it to job files dir
Get proc card and write it to job files dir
"""
job_files_path = self.get_job_files_path()
output_file_name = os.path.join(job_files_path, 'process.dat')
customize_card = self.get_customize_card()
self.logger.debug('Writing customized card %s', output_file_name)
self.logger.debug(customize_card)
proc_card = self.get_proc_card()
self.logger.debug('Writing proc card %s', output_file_name)
self.logger.debug(proc_card)
with open(output_file_name, 'w') as output_file:
output_file.write(customize_card)
output_file.write(proc_card)

def prepare_job_archive(self):
"""
Make an archive with all necessary job files
"""
job_files_path = self.get_job_files_path()
pathlib.Path(job_files_path).mkdir(parents=True, exist_ok=True)
self.prepare_run_card()
self.prepare_customize_card()
self.prepare_input_card()
self.prepare_proc_card()
local_dir = self.local_dir()
os.system(f'tar -czvf {local_dir}/input_files.tar.gz -C {local_dir} input_files')