Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:13:14

0001 #!/usr/bin/bash
0002 
0003 
0004 export TargetDir="$PWD"/condorout
0005 
0006 iter=2
0007 
0008 
0009 
0010 if [ -d ${TargetDir} ]; then
0011   if [ -d ${TargetDir}/OutDir0 ]; then
0012     rm -rf ${TargetDir}/OutDir*
0013   fi
0014 else
0015   mkdir ${TargetDir}
0016 fi
0017 condor_rm bseidlitz
0018 
0019 i=0
0020 while read dir; do 
0021   li=$(printf "%04d" $i)
0022 
0023   rm inputdata.txt
0024   
0025   # creates a list of all files for a particular run
0026   for file in /sphenix/lustre01/sphnxpro/commissioning/DST_ana395_2023p007/DST_CALO*-000"$dir"-*.root
0027   do
0028 cat >>inputdata.txt<< EOF
0029 $file
0030 EOF
0031 done
0032 
0033   if [ "$iter" -eq 1 ]; then
0034     j=8
0035   else
0036     j=100
0037   fi
0038   tot_files=$( cat inputdata.txt | wc -l )
0039   echo "total files: $tot_files"
0040   rem=$(( $tot_files%$j ))
0041   files_per_job=$(( $tot_files/$j ))
0042   njob=$j
0043   if [ $rem -ne 0 ]; then
0044     files_per_job=$(( $files_per_job+1 ))
0045   fi
0046   rem2=$(( $tot_files%$files_per_job ))
0047   njob=$(( $tot_files/$files_per_job ))
0048   if [ $rem2 -ne 0 ]; then
0049     njob=$(( ($tot_files/$files_per_job)+1 ))
0050   fi
0051   echo "files per job: $files_per_job"
0052   echo "njob: $njob"
0053 
0054 
0055   for((q=0;q<$njob;q++));
0056   do
0057 
0058     mkdir ${TargetDir}/OutDir$i
0059     export WorkDir="${TargetDir}/OutDir$i"
0060     echo "WorkDir:" ${WorkDir}
0061     start_file=$(( $q*$files_per_job+1 ))
0062     end_file=$(( $start_file+$files_per_job-1 ))
0063     echo "start file: $start_file   end file: $end_file"
0064 
0065     sed -n $start_file\,${end_file}p inputdata.txt > tmp.txt
0066     mv tmp.txt ${WorkDir}/inputdata.txt
0067     
0068     pushd ${WorkDir}
0069 
0070     
0071     cp -v "$PWD"/../../CondorRun.sh CondorRunJob$li.sh
0072     cp -v "$PWD"/../../../Fun4All_EMCal_Hist.C .
0073 
0074     chmod +x CondorRunJob$li.sh
0075         
0076     
0077     cat >>ff.sub<< EOF
0078 +JobFlavour                   = "workday"
0079 transfer_input_files          = ${WorkDir}/CondorRunJob$li.sh, ${WorkDir}/input.txt
0080 Executable                    = CondorRunJob$li.sh
0081 request_memory                = 10GB
0082 Universe                      = vanilla
0083 Notification                  = Never
0084 GetEnv                        = True
0085 Priority                      = +12
0086 Output                        = condor.out
0087 Error                         = condor.err
0088 Log                           = /tmp/condor$li.log
0089 Notify_user                   = bs3402@columbia.edu
0090 
0091 Queue
0092 EOF
0093 
0094     condor_submit ff.sub
0095     popd
0096   
0097     i=$((i+1))
0098   done
0099 done < runList.txt # redirect the input of the
0100 
0101 
0102 ##################################
0103 ## the rest of this is a way of waiting for jobs to be done and then hadding which is not necessary
0104 
0105 # Set the directory where the files are located
0106 file_directory="${TargetDir}/OutDir*/DONE.root"
0107 
0108 while [ $(ls $file_directory | wc -l) -lt $((i-1)) ]; do
0109      current_file_count=$(ls $file_directory | wc -l)
0110     echo "Waiting for $((i-1)) files, currently $current_file_count"
0111     sleep 30  # Adjust the sleep duration as needed
0112 done
0113 
0114 export TargetHadd="$PWD"/combine_out
0115 
0116 if [ ! -d ${TargetHadd} ]; then
0117   mkdir ${TargetHadd}
0118 fi
0119 
0120 file_to_hadd="${TargetDir}/OutDir*/OUTHIST_iter*.root"
0121 
0122 hist_out=${TargetHadd}/out${iter}.root
0123 
0124 rm $hist_out 
0125 
0126 hadd -k $hist_out $file_to_hadd 
0127 
0128 
0129