11"""LHCb command for bookkeeping report file generation based on the XMLSummary and the XML catalog."""
22
3+ import copy
34import logging
45import os
56from typing import Any , Dict
1920from dirac_cwl .core .exceptions import WorkflowProcessingException
2021
2122from .core import PostProcessCommand
22- from .workflow_commons import StepStatus , WorkflowCommons
23+ from .workflow_commons import Step , StepStatus , WorkflowCommons
2324
2425logger = logging .getLogger (__name__ )
2526
@@ -34,29 +35,40 @@ def _execute(self, job_path: os.PathLike, workflow_commons: WorkflowCommons, **k
3435 :param workflow_commons: WorkflowCommons object
3536 :param kwargs: Additional keyword arguments.
3637 """
37- # Obtain Workflow Commons
38- if workflow_commons .step_status == StepStatus .Failed :
39- return
38+ for step in workflow_commons . steps :
39+ if workflow_commons .step_status == StepStatus .Failed :
40+ return
4041
42+ self ._execute_for_step (job_path , workflow_commons , step , ** kwargs )
43+
44+ def _execute_for_step (self , job_path : os .PathLike , workflow_commons : WorkflowCommons , step_commons : Step , ** kwargs ):
4145 # Setup variables
4246 cpu_times : Dict [str , Any ] = {}
43- if workflow_commons .start_time :
44- cpu_times ["StartTime" ] = workflow_commons .start_time
45- if workflow_commons .start_stats :
46- cpu_times ["StartStats" ] = workflow_commons .start_stats
47+ if step_commons .start_time :
48+ cpu_times ["StartTime" ] = step_commons .start_time
49+ if step_commons .start_stats :
50+ cpu_times ["StartStats" ] = step_commons .start_stats
4751
4852 exectime , cputime = getStepCPUTimes (cpu_times )
4953
50- number_of_processors = getNumberOfProcessorsToUse (
51- workflow_commons .job_id ,
52- workflow_commons .max_number_of_processors ,
53- )
54+ number_of_processors = workflow_commons .number_of_processors
55+
56+ if (step_commons .multicore and workflow_commons .multicore ) or (
57+ workflow_commons .job_type .lower () == "user" and workflow_commons .max_number_of_processors
58+ ):
59+ number_of_processors = getNumberOfProcessorsToUse (
60+ workflow_commons .job_id ,
61+ workflow_commons .max_number_of_processors ,
62+ )
63+
64+ all_outputs = copy .deepcopy (step_commons .outputs )
65+ all_outputs .extend (step_commons .outputs )
5466
5567 parameters = {
5668 "PRODUCTION_ID" : workflow_commons .production_id ,
5769 "JOB_ID" : workflow_commons .prod_job_id ,
5870 "configVersion" : workflow_commons .config_version ,
59- "outputList" : workflow_commons . outputs ,
71+ "outputList" : all_outputs ,
6072 "configName" : workflow_commons .config_name ,
6173 "outputDataFileMask" : workflow_commons .output_data_file_mask ,
6274 }
@@ -79,16 +91,16 @@ def _execute(self, job_path: os.PathLike, workflow_commons: WorkflowCommons, **k
7991
8092 bk_lfns = production_lfns_dict ["BookkeepingLFNs" ]
8193
82- ldate , ltime , ldatestart , ltimestart = _process_time (workflow_commons .start_time )
94+ ldate , ltime , ldatestart , ltimestart = _process_time (step_commons .start_time )
8395
8496 # Obtain XMLSummary
85- if not workflow_commons .xf_o :
86- workflow_commons .xf_o = _generate_xml_object (
87- workflow_commons .cleaned_application_name ,
97+ if not step_commons .xf_o :
98+ step_commons .xf_o = _generate_xml_object (
99+ step_commons .cleaned_application_name ,
88100 workflow_commons .production_id ,
89101 workflow_commons .prod_job_id ,
90- workflow_commons . step_number ,
91- workflow_commons . step_id ,
102+ step_commons . number ,
103+ step_commons . id ,
92104 )
93105
94106 info_dict = {
@@ -99,9 +111,9 @@ def _execute(self, job_path: os.PathLike, workflow_commons: WorkflowCommons, **k
99111 "jobID" : workflow_commons .job_id ,
100112 "siteName" : workflow_commons .site_name ,
101113 "jobType" : workflow_commons .job_type ,
102- "applicationName" : workflow_commons .application_name ,
103- "applicationVersion" : workflow_commons .application_version ,
104- "numberOfEvents" : workflow_commons .number_of_events ,
114+ "applicationName" : step_commons .application_name ,
115+ "applicationVersion" : step_commons .application_version ,
116+ "numberOfEvents" : step_commons .number_of_events ,
105117 }
106118
107119 # Generate job_info object
@@ -111,37 +123,40 @@ def _execute(self, job_path: os.PathLike, workflow_commons: WorkflowCommons, **k
111123 ltimestart ,
112124 ldate ,
113125 ltime ,
114- workflow_commons .xf_o ,
115- workflow_commons .inputs ,
116- workflow_commons . step_id ,
117- workflow_commons . bk_step_id ,
126+ step_commons .xf_o ,
127+ step_commons .inputs ,
128+ step_commons . id ,
129+ step_commons . bk_id ,
118130 workflow_commons .bk_client ,
119131 workflow_commons .config_name ,
120132 workflow_commons .config_version ,
121133 )
122134
123135 # Add input files to job_info
124- _generateInputFiles (job_info , bk_lfns , workflow_commons .inputs )
136+ _generateInputFiles (job_info , bk_lfns , step_commons .inputs )
125137
126138 # Add output files to job_info
127139 _generateOutputFiles (
128140 job_info ,
129141 bk_lfns ,
130- workflow_commons .event_type ,
131- workflow_commons .application_name ,
132- workflow_commons .xf_o ,
133- workflow_commons .outputs ,
134- workflow_commons .inputs ,
142+ step_commons .event_type ,
143+ step_commons .application_name ,
144+ step_commons .xf_o ,
145+ step_commons .outputs ,
146+ step_commons .inputs ,
147+ step_commons .size ,
148+ step_commons .md5 ,
149+ step_commons .guid ,
135150 )
136151
137152 # Generate SimulationConditions
138- if workflow_commons .application_name == "Gauss" :
153+ if step_commons .application_name == "Gauss" :
139154 job_info .simulation_condition = workflow_commons .sim_description
140155
141156 # Convert job_info object to XML
142157 doc = job_info .to_xml ()
143158
144159 # Write to file
145- bfilename = f"bookkeeping_{ workflow_commons . step_id } .xml"
160+ bfilename = f"bookkeeping_{ step_commons . id } .xml"
146161 with open (bfilename , "wb" ) as bfile :
147162 bfile .write (doc )
0 commit comments