Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:10:58

0001 #!/usr/bin/env ruby
0002 # -----------------------------------------------------------------------------
0003 # 'MergeCondorFiles.rb'
0004 # Derek Anderson
0005 # 04.22.2023
0006 #
0007 # For merging files in chunks using 'hadd_files.C'.
0008 # (Ideal for condor output!)
0009 # -----------------------------------------------------------------------------
0010 
0011 # modules to use
0012 require 'fileutils'
0013 
0014 # input parameters
0015 in_path = "./condor/individual_files/pp200py8jet10run6_trksAndChargPars_2023may7/"
0016 in_pref = "outputData_CorrelatorJetTree_"
0017 in_suff = ".root"
0018 
0019 # output parameters
0020 out_pref = "correlatorJetTree.pp200py8jet10run6_trksAndChrgPars_"
0021 out_suff = ".d7m5y2023"
0022 out_root = ".root"
0023 out_list = ".list"
0024 
0025 # chunks to copy
0026 chunks = [
0027   "000",
0028   "001",
0029   "002",
0030   "003",
0031   "004",
0032   "005",
0033   "006",
0034   "007",
0035   "008",
0036   "009",
0037   "010",
0038   "011",
0039   "012",
0040   "013",
0041   "014",
0042   "015",
0043   "016",
0044   "017",
0045   "018",
0046   "019"
0047 ]
0048 
0049 # chunk labels
0050 labels = [
0051   "0000to0099",
0052   "0100to0199",
0053   "0200to0299",
0054   "0300to0399",
0055   "0400to0499",
0056   "0500to0599",
0057   "0600to0699",
0058   "0700to0799",
0059   "0800to0899",
0060   "0900to0999",
0061   "1000to1099",
0062   "1100to1199",
0063   "1200to1299",
0064   "1300to1399",
0065   "1400to1499",
0066   "1500to1599",
0067   "1600to1699",
0068   "1700to1799",
0069   "1800to1899",
0070   "1900to1999"
0071 ]
0072 
0073 # create output arrays
0074 num_chunks = chunks.size
0075 in_pattern = Array.new(num_chunks)
0076 list_files = Array.new(num_chunks)
0077 root_files = Array.new(num_chunks)
0078 
0079 # loop over chunks
0080 chunks.each_with_index do |chunk, iChunk|
0081 
0082   # create input matching pattern
0083   in_pattern[iChunk] = in_path + "/" + in_pref + chunk + "*" + in_suff
0084   in_pattern[iChunk].gsub!("//", "/")
0085   in_pattern[iChunk].gsub!("..", ".")
0086 
0087   # create output list file
0088   list_files[iChunk] = out_pref + labels[iChunk] + out_suff + out_list
0089   list_files[iChunk].gsub!("//", "/")
0090   list_files[iChunk].gsub!("..", ".")
0091 
0092   # create output root file
0093   root_files[iChunk] = out_pref + labels[iChunk] + out_suff + out_root
0094   root_files[iChunk].gsub!("//", "/")
0095   root_files[iChunk].gsub!("..", ".")
0096 
0097   # create list of files in a chunk
0098   File.open(list_files[iChunk], "w") { |list|
0099     Dir[in_pattern[iChunk]].each do |file|
0100       list.puts file
0101     end
0102   }
0103 
0104   # grab number of files to merge
0105   num_files = Dir[in_pattern[iChunk]].size
0106 
0107   # merge files
0108   system("root -b -q \'MergeFiles.C(#{num_files}, \"#{list_files[iChunk]}\", \"#{root_files[iChunk]}\")\'")
0109 
0110 # end chunk loop
0111 end
0112 
0113 # end -------------------------------------------------------------------------