X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=cluster_tools%2Fgate_power_merge.sh;h=8fa4cfc3b15935562fc7c5b898e22ae020f6755d;hb=f48c960aef6e0a5a4edea516b062197db009e25f;hp=2733e406a823958069c7ab1f8f9aba6ed64a677a;hpb=d4355c17de8da3c4814b9428fb6c17ec7ededbe9;p=clitk.git diff --git a/cluster_tools/gate_power_merge.sh b/cluster_tools/gate_power_merge.sh index 2733e40..8fa4cfc 100755 --- a/cluster_tools/gate_power_merge.sh +++ b/cluster_tools/gate_power_merge.sh @@ -165,7 +165,7 @@ function merge_stat { echo " ${indent}merged ${count} files" } -doseMerger="mergeDosePerEnegryFile.sh" +doseMerger="mergeDosePerEnergyFile.sh" test -x "./mergeDosePerEnergyFile.sh" && doseMerger="./mergeDosePerEnergyFile.sh" function merge_dose { @@ -196,6 +196,37 @@ function merge_dose { echo " ${indent}merged ${count} files" } +doseMerger="mergeDoseByRegions.sh" +test -x "./mergeDoseByRegions.sh" && doseMerger="./mergeDoseByRegions.sh" + +function merge_doseByRegions { + local merged="$1" + shift + echo " ${indent}entering dose merger" + echo " ${indent}merger is ${doseMerger}" + echo " ${indent}creating ${merged}" + local count=0 + start_bar $# + while test $# -gt 0 + do + local partial="$1" + shift + let count++ + + if test ! -f "${merged}" + then + update_bar ${count} "copying first partial result ${partial}" + cp "${partial}" "${merged}" + continue + fi + + update_bar ${count} "adding ${partial}" + ${doseMerger} -i "${merged}" -j "${partial}" -o "${merged}" 2> /dev/null > /dev/null || warning "error while calling ${doseMerger}" + done + end_bar + echo " ${indent}merged ${count} files" +} + txtImageMerger="clitkMergeAsciiDoseActor" test -f "./clitkMergeAsciiDoseActor" && txtImageMerger="./clitkMergeAsciiDoseActor" @@ -272,6 +303,7 @@ test -x "./clitkImageArithm" && mhdImageMerger="./clitkImageArithm" function merge_mhd_image { local merged="$1" local merged_bin="${merged%.*}.raw" + local last_character=${merged#${merged%?}} shift echo " ${indent}entering mhd image merger" echo " ${indent}merger is ${mhdImageMerger}" @@ -289,14 +321,20 @@ function merge_mhd_image { then update_bar ${count} "copying first partial result ${partial}" cp "${partial}" "${merged}" - cp "${partial_bin}" "${merged_bin%.*}.${partial_bin##*.}" + if test "$last_character" = "d" + then + cp "${partial_bin}" "${merged_bin%.*}.${partial_bin##*.}" + fi continue fi update_bar ${count} "adding ${partial}" ${mhdImageMerger} -t 0 -i "${partial}" -j "${merged}" -o "${merged}" 2> /dev/null > /dev/null || warning "error while calling ${mhdImageMerger}" - mv "${merged_bin}" "${merged_bin%.*}.${partial_bin##*.}" - sed -i "s/$(basename "${merged_bin}")/$(basename "${merged_bin%.*}.${partial_bin##*.}")/" "${merged}" + if test "$last_character" = "d" && test "${merged_bin}" != "${merged_bin%.*}.${partial_bin##*.}" + then + mv "${merged_bin}" "${merged_bin%.*}.${partial_bin##*.}" + sed -i "s/$(basename "${merged_bin}")/$(basename "${merged_bin%.*}.${partial_bin##*.}")/" "${merged}" + fi done end_bar echo " ${indent}merged ${count} files" @@ -307,21 +345,24 @@ function merge_dispatcher { local outputfile="${1:?"provide output filename"}" echo "merging ${outputfile}" - local partialoutputfiles="$(find "${rundir}" -mindepth 2 -type f -name "${outputfile}")" + local partialoutputfiles="$(find -L "${rundir}" -mindepth 2 -type f -name "${outputfile}")" local nboutputfiles="$(echo "${partialoutputfiles}" | wc -l)" if test ${nboutputdirs} -ne ${nboutputfiles} then warning "missing files" - return + if ! test "${2}" == "--force" + then + return + fi fi local firstpartialoutputfile="$(echo "${partialoutputfiles}" | head -n 1)" local firstpartialoutputextension="${firstpartialoutputfile##*.}" echo "${indent}testing file type on ${firstpartialoutputfile}" - if test "${firstpartialoutputextension}" == "hdr" && grep -qs 'INTERFILE' "${firstpartialoutputfile}" + if test "${firstpartialoutputextension}" == "hdr" && test grep -qs 'INTERFILE' "${firstpartialoutputfile}" then - echo "${indent}this is a interfile image" + echo "${indent}this is an interfile image" echo "${indent}creating mhd headers" for partialoutputfile in $partialoutputfiles; do write_mhd_header "${partialoutputfile}"; done local mhd_partialoutputfiles="$(for partialoutputfile in $partialoutputfiles; do echo "${partialoutputfile%.*}.mhd"; done)" @@ -337,13 +378,13 @@ function merge_dispatcher { if test "${firstpartialoutputextension}" == "hdr" then - echo "${indent}this is a analyse image" + echo "${indent}this is an analyse image" local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" merge_hdr_image "${mergedfile}" ${partialoutputfiles} || error "error while merging" return fi - if test "${firstpartialoutputextension}" == "mhd" + if test "${firstpartialoutputextension}" == "mhd" || test "${firstpartialoutputextension}" == "mha" then echo "${indent}this is a mhd image" local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" @@ -399,6 +440,15 @@ function merge_dispatcher { fi fi + if test "${firstpartialoutputextension}" == "txt" && grep -qs 'vol(mm3)' "${firstpartialoutputfile}" + then + echo "${indent}this is a DoseByRegions file" + local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" + merge_doseByRegions "${mergedfile}" ${partialoutputfiles} || error "error while merging" + return + fi + + if test "${firstpartialoutputextension}" == "txt" then echo "${indent}this is a non specific txt output" @@ -420,11 +470,89 @@ function merge_dispatcher { error "unknown file type" } +function merge_dispatcher_uncertainty { + local indent=" ** " + local outputfile="${1:?"provide output filename"}" + + local partialoutputfiles="$(find -L "${rundir}" -mindepth 2 -type f -name "${outputfile}")" + local nboutputfiles="$(echo "${partialoutputfiles}" | wc -l)" + if test ${nboutputdirs} -ne ${nboutputfiles} + then + warning "missing files" + if ! test "${2}" == "--force" + then + return + fi + fi + + local firstpartialoutputfile="$(echo "${partialoutputfiles}" | head -n 1)" + local firstpartialoutputextension="${firstpartialoutputfile##*.}" + + if [[ "${firstpartialoutputfile}" == *Uncertainty* ]] + then + if test "${firstpartialoutputextension}" == "mhd" || test "${firstpartialoutputextension}" == "mha" + then + echo "${indent}Uncertainty file found: ${firstpartialoutputfile}" + ## search for sum + local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")" + summed_merged_file=${mergedfile//-Uncertainty/} + if [ ! -f ${summed_merged_file} ]; + then + warning "${summed_merged_file} does not exist. Error, no uncertainty computed" + return; + fi + echo "${indent}${summed_merged_file} found" + ## search for Squared + squared_merged_file=${mergedfile//-Uncertainty/-Squared} + if [ ! -f ${squared_merged_file} ]; + then + warning "${squared_merged_file} does not exist. Error, no uncertainty computed" + return; + fi + echo "${indent}${squared_merged_file} found" + ## search for NumberOfEvent + totalEvents=0; + unamestr=`uname` + if [[ "$unamestr" == 'Darwin' ]]; then + files=$(find -L "${rundir}" -type f -regex ".*output.*[hdr|mhd|mha|root|txt]" | awk -F '/' '{ print $NF; }' | sort | uniq) + else + files=$(find -L "${rundir}" -regextype 'posix-extended' -type f -regex "${rundir}/output.*\.(hdr|mhd|mha|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) + fi + echo $files + for outputfile in ${files} + do + #echo $outputfile + if grep -q 'NumberOfEvent' "${outputdir}/${outputfile}" + then + totalEvents="$(grep "NumberOfEvents" "${outputdir}/${outputfile}" | cut -d' ' -f4)" + echo "${indent}Find the NumberOfEvent in $outputfile: ${totalEvents}" + fi + done + + if test ${totalEvents} -gt 0 + then + uncerImageMerger="clitkImageUncertainty" + test -x "./clitkImageUncertainty" && uncerImageMerger="./clitkImageUncertainty" + ${uncerImageMerger} -i ${summed_merged_file} -s ${squared_merged_file} -o ${mergedfile} -n ${totalEvents} + else + warning "${totalEvents} not positive. A at least one stat file (SimulationStatisticActor) must be provided. Error, no uncertainty computed" + return; + fi + else + error "merge_dispatcher_uncertainty does not handle ${firstpartialoutputfile} files" + fi + fi + +} + echo "!!!! this is $0 v0.3k !!!!" +echo "Usage: gate_power_merge.sh run.dir [--force]" +echo " where --force allows to merge files even if the file is missing in some output directories" rundir="${1?"provide run dir"}" +force=${2:-""} rundir="$(echo "${rundir}" | sed 's|/*$||')" -nboutputdirs="$(find "${rundir}" -mindepth 1 -type d -name 'output*' | wc -l)" +nboutputdirs="$(find "${rundir}" -mindepth 1 -type d -name 'output*' -o -type l -name 'output*' | wc -l)" test ${nboutputdirs} -gt 0 || error "no output dir found" echo "found ${nboutputdirs} partial output dirs" @@ -436,18 +564,52 @@ then fi outputdir="$(basename "${outputdir}")" echo "output dir is ${outputdir}" + test -d "${outputdir}" && rm -r "${outputdir}" mkdir "${outputdir}" -for outputfile in $(find "${rundir}" -regextype 'posix-extended' -type f -regex "${rundir}/output.*\.(hdr|mhd|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) +unamestr=`uname` +if [[ "$unamestr" == 'Darwin' ]]; then + files=$(find -L "${rundir}" -type f -regex ".*output.*[hdr|mhd|mha|root|txt]" | awk -F '/' '{ print $NF; }' | sort | uniq) +else + files=$(find -L "${rundir}" -regextype 'posix-extended' -type f -regex "${rundir}/output.*\.(hdr|mhd|mha|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) +fi +echo files $files +for outputfile in ${files} +do + merge_dispatcher "${outputfile}" "${force}" +done + +echo "" +echo "Merging done. Special case for statistical uncertainty" + +unamestr=`uname` +if [[ "$unamestr" == 'Darwin' ]]; then + files=$(find -L "${outputdir}" -type f -regex ".*[hdr|mhd|mha|root|txt]" | awk -F '/' '{ print $NF; }' | sort | uniq) +else + files=$(find -L "${outputdir}" -regextype 'posix-extended' -type f -regex "${outputdir}/.*\.(hdr|mhd|mha|root|txt)" | awk -F '/' '{ print $NF; }' | sort | uniq) +fi +echo files = $files +for outputfile in ${files} do - merge_dispatcher "${outputfile}" + merge_dispatcher_uncertainty "${outputfile}" "${force}" done +echo "compute job statistics" +python computeEnlapsedTime.py ${rundir} gate +mv "statJobs.txt" "${outputdir}/statJobs.txt" + + if [ -f "${rundir}/params.txt" ] then echo "copying params file" cp "${rundir}/params.txt" "${outputdir}/params.txt" fi +if [ -d "${rundir}/mac" ] +then + echo "copying mac folder" + cp -r "${rundir}/mac" "${outputdir}/mac" +fi + echo "these was ${warning_count} warning(s)"