@@ -98,26 +98,19 @@ def main(configuration_file,
9898 output_path ,
9999 clean_delphes_files ,
100100 create_luts ,
101- turn_off_vertexing ):
101+ turn_off_vertexing ,
102+ append_production ):
103+ arguments = locals ()
102104 global verbose_mode
103105 verbose_mode = verbose
104106 parser = configparser .RawConfigParser ()
105107 parser .read (configuration_file )
106108
107109 run_cmd ("./clean.sh > /dev/null 2>&1" , check_status = False )
108110 # Dictionary of fetched options
109- running_options = {
110- "ARG configuration_file" : configuration_file ,
111- "ARG config_entry" : config_entry ,
112- "ARG njobs" : njobs ,
113- "ARG nruns" : nruns ,
114- "ARG nevents" : nevents ,
115- "ARG verbose" : verbose ,
116- "ARG qa" : qa ,
117- "ARG output_path" : output_path ,
118- "ARG clean_delphes_files" : clean_delphes_files ,
119- "ARG create_luts" : create_luts
120- }
111+ running_options = {}
112+ for i in arguments :
113+ running_options ["ARG " + i ] = arguments [i ]
121114
122115 def opt (entry , require = True ):
123116 try :
@@ -211,18 +204,19 @@ def check_duplicate(option_name):
211204
212205 # Printing configuration
213206 msg (" --- running createO2tables.py" , color = bcolors .HEADER )
214- msg (" njobs =" , njobs )
215- msg (" nruns =" , nruns )
216- msg (" nevents =" , nevents )
217- msg (" lut path =" , lut_path )
207+ msg (" n. jobs =" , njobs )
208+ msg (" n. runs =" , nruns )
209+ msg (" events per run =" , nevents )
210+ msg (" tot. events =" , "{:.0e}" .format (nevents * nruns ))
211+ msg (" LUT path =" , f"'{ lut_path } '" )
218212 msg (" --- with detector configuration" , color = bcolors .HEADER )
219- msg (" bField =" , bField , "[kG]" )
213+ msg (" B field =" , bField , "[kG]" )
220214 msg (" sigmaT =" , sigmaT , "[ns]" )
221215 msg (" sigmaT0 =" , sigmaT0 , "[ns]" )
222- msg (" barrel_radius =" , barrel_radius , "[cm]" )
223- msg (" barrel_half_length =" , barrel_half_length , "[cm]" )
216+ msg (" Barrel radius =" , barrel_radius , "[cm]" )
217+ msg (" Barrel half length =" , barrel_half_length , "[cm]" )
224218 if create_luts :
225- msg (" minimum_track_radius =" , minimum_track_radius , "[cm]" )
219+ msg (" Minimum track radius =" , minimum_track_radius , "[cm]" )
226220 msg (" LUT =" , lut_tag )
227221 msg (" etaMax =" , etaMax )
228222
@@ -283,8 +277,20 @@ def set_config(config_file, config, value):
283277 "const double tof_sigmat =" , f"{ sigmaT } " "\;/" )
284278 set_config ("createO2tables.C" ,
285279 "const double tof_sigmat0 =" , f"{ sigmaT0 } " "\;/" )
286-
287280 run_list = range (nruns )
281+ if append_production :
282+ if output_path is None :
283+ fatal_msg ("Output path is not defined, cannot append" )
284+ last_preexisting_aod = [each for each in os .listdir (output_path )
285+ if each .endswith ('.root' ) and "AODRun5" in each ]
286+ if len (last_preexisting_aod ) == 0 :
287+ fatal_msg ("Appending to a non existing production" )
288+ last_preexisting_aod = sorted ([int (each .replace ("AODRun5." , "" ).replace (".root" , "" ))
289+ for each in last_preexisting_aod ])[- 1 ] + 1
290+ msg (f" Appending to production with { last_preexisting_aod } AODs" ,
291+ color = bcolors .BWARNING )
292+ run_list = range (last_preexisting_aod ,
293+ last_preexisting_aod + nruns )
288294
289295 def configure_run (run_number ):
290296 # Create executable that runs Generation, Delphes and analysis
@@ -422,11 +428,28 @@ def write_config(entry, prefix=""):
422428 if "ARG" not in i :
423429 write_config (i , prefix = " * " )
424430
431+ output_size = sum (os .path .getsize (os .path .join (output_path , f ))
432+ for f in os .listdir (output_path )
433+ if os .path .isfile (os .path .join (output_path , f )))
434+ f .write ("\n ## Size of the ouput ##\n " )
435+ f .write (f" - { output_size } bytes\n " )
436+ f .write (f" - { output_size / 1e6 } MB\n " )
437+ f .write (f" - { output_size / 1e9 } GB\n " )
425438 run_cmd ("echo >> " + summaryfile )
426439 run_cmd ("echo + DelphesO2 Version + >> " + summaryfile )
427440 run_cmd ("git rev-parse HEAD >> " + summaryfile , check_status = False )
441+
428442 if os .path .normpath (output_path ) != os .getcwd ():
429- run_cmd (f"mv { summaryfile } { output_path } " )
443+ if append_production :
444+ s = os .path .join (output_path , summaryfile )
445+ run_cmd (f"echo '' >> { s } " )
446+ run_cmd (f"echo ' **' >> { s } " )
447+ run_cmd (f"echo 'Appended production' >> { s } " )
448+ run_cmd (f"echo ' **' >> { s } " )
449+ run_cmd (f"echo '' >> { s } " )
450+ run_cmd (f"cat { summaryfile } >> { s } " )
451+ else :
452+ run_cmd (f"mv { summaryfile } { output_path } " )
430453
431454 if qa :
432455 msg (" --- running test analysis" , color = bcolors .HEADER )
@@ -441,7 +464,7 @@ def write_config(entry, prefix=""):
441464 parser .add_argument ("--entry" , "-e" , type = str ,
442465 default = "DEFAULT" ,
443466 help = "Entry in the configuration file, e.g. the INEL or CCBAR entries in the configuration file." )
444- parser .add_argument ("--output-path" , "-o" , type = str ,
467+ parser .add_argument ("--output-path" , "--output_path" , "- o" , type = str ,
445468 default = None ,
446469 help = "Output path, by default the current path is used as output." )
447470 parser .add_argument ("--njobs" , "-j" , type = int ,
@@ -463,10 +486,18 @@ def write_config(entry, prefix=""):
463486 parser .add_argument ("--no-vertexing" ,
464487 action = "store_true" ,
465488 help = "Option turning off the vertexing." )
489+ parser .add_argument ("--append" , "-a" ,
490+ action = "store_true" ,
491+ help = "Option to append the results instead of starting over by shifting the AOD indexing. N.B. the user is responsible of the compatibility between appended AODs. Only works in conjuction by specifying an output path (option '-o')" )
466492 parser .add_argument ("--use-preexisting-luts" , "-l" ,
467493 action = "store_true" ,
468494 help = "Option to use preexisting LUTs instead of creating new ones, in this case LUTs with the requested tag are fetched from the LUT path. By default new LUTs are created at each run." )
469495 args = parser .parse_args ()
496+ # Check arguments
497+ if args .append and args .output_path is None :
498+ fatal_msg (
499+ "Asked to append production but did not specify output path (option '-o')" )
500+
470501 main (configuration_file = args .configuration_file ,
471502 config_entry = args .entry ,
472503 njobs = args .njobs ,
@@ -477,4 +508,5 @@ def write_config(entry, prefix=""):
477508 clean_delphes_files = args .clean_delphes ,
478509 qa = args .qa ,
479510 create_luts = not args .use_preexisting_luts ,
480- turn_off_vertexing = args .no_vertexing )
511+ turn_off_vertexing = args .no_vertexing ,
512+ append_production = args .append )
0 commit comments