File indexing completed on 2025-01-30 10:30:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 require 'fileutils'
0020
0021
0022
0023
0024
0025 END {
0026
0027
0028
0029
0030 type = :gun
0031 numiter = ARGV[0]
0032 input = "forJetInitFix.e10h11pipXpim.d14m3y2024.hepmc"
0033 output = "testOutOnLocal.d22m3y2024.edm4hep.root"
0034 steerer = ARGV[2]
0035
0036
0037 in_dir = "/sphenix/user/danderson/"
0038 out_dir = "/sphenix/user/danderson/"
0039 run_dir = "/sphenix/u/danderson/eic"
0040
0041
0042 out_prefix = "testOutOnCondor"
0043 out_label = ARGV[1]
0044 out_index = "file"
0045 out_suffix = ".d22m3y2024.edm4hep.root"
0046
0047
0048
0049
0050 numevts = 1000
0051 compact = "/opt/detector/epic-nightly/share/epic/epic.xml"
0052
0053
0054 exec = "npsim"
0055 shell = "/sphenix/u/danderson/scripts/eic-shell"
0056 setup = "/opt/detector/setup.sh"
0057
0058
0059 runner = "RunDD4hepInShell.sh"
0060 simulator = "DoDD4hepSimulation.sh"
0061
0062
0063
0064 iter = 0
0065 while iter < numiter.to_i
0066
0067
0068 parser = ArgParser.new
0069 parser.configure(
0070 args: ARGV,
0071 steer: steerer,
0072 label: out_label,
0073 pref: out_prefix,
0074 suff: out_suffix,
0075 name: output,
0076 sim: simulator,
0077 run: runner,
0078 index: out_index,
0079 count: iter
0080 )
0081 parser.parse()
0082
0083
0084 handler = SimHandler.new
0085 handler.configure(
0086 outname: parser.out_name,
0087 outdir: out_dir,
0088 intype: type,
0089 infile: input,
0090 indir: in_dir,
0091 optnum: numevts,
0092 optdet: compact,
0093 optsteer: parser.out_steer,
0094 sysexec: exec,
0095 syssim: parser.out_sim,
0096 sysrun: parser.out_run,
0097 sysshell: shell,
0098 sysinit: setup,
0099 rundir: run_dir
0100 )
0101 handler.run()
0102
0103
0104 iter = iter + 1
0105
0106 end
0107
0108 }
0109
0110
0111
0112
0113
0114 class ArgParser
0115
0116
0117 attr_accessor :in_args
0118 attr_accessor :in_steer
0119 attr_accessor :in_label
0120 attr_accessor :in_pref
0121 attr_accessor :in_suff
0122 attr_accessor :in_name
0123 attr_accessor :in_sim
0124 attr_accessor :in_run
0125 attr_accessor :in_index
0126 attr_accessor :in_count
0127
0128
0129 attr_reader :out_steer
0130 attr_reader :out_label
0131 attr_reader :out_name
0132 attr_reader :out_sim
0133 attr_reader :out_run
0134
0135
0136
0137
0138
0139 def configure(
0140 args: [],
0141 steer: "",
0142 label: "",
0143 pref: "",
0144 suff: "",
0145 name: "",
0146 sim: "DoDDSim.sh",
0147 run: "RunShell.sh",
0148 index: out_num,
0149 count: iter
0150 )
0151
0152 @in_args = args
0153 @in_steer = steer
0154 @in_label = label
0155 @in_pref = pref
0156 @in_suff = suff
0157 @in_name = name
0158 @in_sim = sim
0159 @in_run = run
0160 @in_index = index
0161 @in_count = count
0162 return
0163
0164 end
0165
0166
0167
0168 def parse()
0169
0170 @out_steer = pick_steering_file()
0171 @out_label = pick_label()
0172 @out_name = construct_output_name(@out_label)
0173 @out_sim = construct_script_name(@in_sim, @out_label)
0174 @out_run = construct_script_name(@in_run, @out_label)
0175 return
0176
0177 end
0178
0179
0180
0181
0182
0183 private
0184
0185 def pick_steering_file()
0186
0187
0188 steer = ""
0189 if @in_args.empty?
0190 steer = @in_steer.clone
0191 else
0192 steer = @in_args[2].clone
0193 end
0194 return steer
0195
0196 end
0197
0198
0199
0200 def pick_label()
0201
0202
0203 label = ""
0204 if @in_args.empty?
0205 label = @in_label.clone
0206 else
0207 label = @in_args[1].clone
0208 end
0209
0210
0211 if not @in_index.nil?
0212 label = label + @in_index + @in_count.to_s
0213 end
0214 return label
0215
0216 end
0217
0218
0219
0220 def construct_output_name(label)
0221
0222
0223 name = ""
0224 if @in_args.empty?
0225 name = @in_name.clone
0226 end
0227
0228
0229
0230 if name.empty?
0231 name = @in_pref + "." + label + "." + @in_suff
0232 name.gsub!("..", ".")
0233 elsif not @in_index.nil?
0234 ending = "." + label + ".edm4hep.root"
0235 name.gsub!(".edm4hep.root", ending)
0236 name.gsub!("..", ".")
0237 end
0238 return name
0239
0240 end
0241
0242
0243
0244 def construct_script_name(input, label)
0245
0246
0247 script = input.clone
0248 if script.end_with?(".sh") and not label.empty?
0249 script.gsub!(".sh", ".#{label}.sh")
0250 end
0251 return script
0252
0253 end
0254
0255 end
0256
0257
0258
0259
0260
0261 class SimHandler
0262
0263
0264 attr_reader :out_file
0265 attr_reader :out_dir
0266 attr_reader :out_path
0267 attr_reader :in_type
0268 attr_reader :in_file
0269 attr_reader :in_dir
0270 attr_reader :in_orig
0271 attr_reader :in_path
0272 attr_reader :opt_nevt
0273 attr_reader :opt_det
0274 attr_reader :opt_steer
0275 attr_reader :sys_exec
0276 attr_reader :sys_sim
0277 attr_reader :sys_run
0278 attr_reader :sys_shell
0279 attr_reader :sys_init
0280 attr_reader :sim_path
0281 attr_reader :run_path
0282 attr_reader :run_dir
0283
0284
0285
0286
0287
0288 public
0289
0290 def configure(
0291 outname: "",
0292 outdir: "./",
0293 intype: :gun,
0294 infile: nil,
0295 indir: "./",
0296 optnum: 1,
0297 optdet: "epic.xml",
0298 optsteer: "./steer.py",
0299 sysexec: "ddsim",
0300 syssim: "DoSim.sh",
0301 sysrun: "RunShell.sh",
0302 sysshell: "~/scripts/eic-shell",
0303 sysinit: "~/scripts/initialize-eic-detectors",
0304 rundir: "./"
0305 )
0306
0307 @out_file = outname
0308 @out_dir = outdir
0309 @in_type = intype
0310 @in_file = infile
0311 @in_dir = indir
0312 @opt_nevt = optnum
0313 @opt_det = optdet
0314 @opt_steer = optsteer
0315 @sys_exec = sysexec
0316 @sys_sim = syssim
0317 @sys_run = sysrun
0318 @sys_shell = sysshell
0319 @sys_init = sysinit
0320 @run_dir = rundir
0321 return
0322
0323 end
0324
0325
0326
0327 def run()
0328
0329
0330 prepare_for_running()
0331
0332
0333 create_sim_script(@sim_path) if not File.exists?(@sim_path)
0334 create_run_script(@run_path) if not File.exists?(@run_path)
0335
0336
0337 system("#{@sys_shell} -- #{@run_path}")
0338
0339
0340 clean_up()
0341 return
0342
0343 end
0344
0345
0346
0347
0348 private
0349
0350 def prepare_for_running()
0351
0352
0353 @sim_path = @run_dir + "/" + @sys_sim
0354 @run_path = @run_dir + "/" + @sys_run
0355 @out_path = @run_dir + "/" + @out_file
0356 @sim_path.gsub!("//", "/")
0357 @run_path.gsub!("//", "/")
0358 @out_path.gsub!("//", "/")
0359 @sim_path.gsub!("..", ".")
0360 @run_path.gsub!("..", ".")
0361 @out_path.gsub!("..", ".")
0362
0363
0364 if in_type == :hepmc
0365
0366
0367 @in_orig = @in_dir + "/" + @in_file
0368 @in_path = @run_dir + "/" + @in_file
0369 @in_orig.gsub!("..", ".")
0370 @in_path.gsub!("//", "/")
0371 @in_orig.gsub!("//", "/")
0372 @in_path.gsub!("..", ".")
0373
0374
0375 if not File.exists?(@in_path)
0376 FileUtils.cp(@in_orig, @in_path)
0377 end
0378 end
0379 return
0380
0381 end
0382
0383
0384
0385 def create_sim_script(path)
0386
0387
0388 args_array = ["setup", "rundir", "steerer", "compact", "numevts", "output"]
0389 args_array << "input" if in_type == :hepmc
0390
0391
0392 args_block = ""
0393 args_array.each_with_index do |arg, iArg|
0394 args_num = iArg + 1
0395 args_block += arg
0396 args_block += "=$"
0397 args_block += "#{args_num}"
0398 args_block += "\n"
0399 end
0400
0401
0402 setup_block = ["source $setup", "cd $rundir"].join("\n")
0403 setup_block += "\n"
0404
0405
0406 command = ""
0407 if in_type == :gun
0408 command += "#{@sys_exec} --steeringFile $steerer --compactFile $compact -G -N $numevts --outputFile $output"
0409 elsif in_type == :hepmc
0410 command += "#{@sys_exec} --steeringFile $steerer --compactFile $compact -I $input -N $numevts --outputFile $output"
0411 end
0412 command += "\n"
0413
0414
0415 body = [args_block, setup_block, command].join("\n")
0416 File.write(path, body)
0417 FileUtils.chmod("u+x", path)
0418 return
0419
0420 end
0421
0422
0423
0424 def create_run_script(path)
0425
0426
0427 args_array = [@sys_init, @run_dir, @opt_steer, @opt_det, @opt_nevt, @out_path]
0428 args_array << @in_path if in_type == :hepmc
0429
0430
0431 arguments = args_array.join(" ")
0432 command = ["source", @sim_path, arguments].join(" ")
0433
0434 File.write(path, command)
0435 FileUtils.chmod("u+x", path)
0436 return
0437
0438 end
0439
0440
0441
0442 def clean_up()
0443
0444
0445 FileUtils.mv(@out_path, @out_dir)
0446
0447
0448 FileUtils.rm @sim_path
0449 FileUtils.rm @run_path
0450
0451
0452 FileUtils.rm @in_path if in_type == :hepmc
0453 return
0454
0455 end
0456
0457 end
0458
0459