Commit f2bf10a6 authored by Breno Rilho Lemos's avatar Breno Rilho Lemos 💬
Browse files

Make Blender scenes in parallel using GNU parallel

parent 0892519c
......@@ -88,7 +88,7 @@ TPC=1
DETAILED_TPC=0
TRD=1
EMCAL=1
BLENDERSAVE=1
BLENDERSAVE=0
PICPCT=80
# now enjoy the options in order and nicely split until we see --
while true; do
......@@ -277,7 +277,7 @@ if [[ $CAMERAS != "" ]]; then
CAMERAS=$(echo $CAMERAS | sed -e 's#,#Camera #g' -e 's#$#Camera#')
fi
if [[ $MOSAIC == "true" ]]; then
if [[ $MOSAIC = "true" ]]; then
CAMERAS=$(echo "OverviewCamera BarrelCamera SideCamera ForwardCamera")
fi
......@@ -386,7 +386,7 @@ if [ "$SAMPLE" = "true" ]; then
-fps=${FPS} -resolution=${RESOLUTION} -transparency=${TRANSPARENCY} \
-stamp_note="opendata.cern.ch_record_1102_alice_2010_LHC10h_000139038_ESD_0001_2" -its=${ITS}\
-tpc=${TPC} -trd=${TRD} -emcal=${EMCAL} -detailed_tpc=${DETAILED_TPC} \
-blendersave=${BLENDERSAVE} -picpct=${PICPCT} -tpc_blender_path=${BLENDER_SCRIPT_DIR} \
-blendersave=1 -picpct=${PICPCT} -tpc_blender_path=${BLENDER_SCRIPT_DIR} \
-output_path="${BLENDER_OUTPUT}"
popd
......@@ -515,17 +515,12 @@ elif [ "$SAMPLE" = "false" ]; then
EXTRACTED_FILES=$(ls -1 ${UNIQUEID}_*.dat | sort --version-sort)
for LOCAL_FILE_WITH_DATA in $EXTRACTED_FILES; do
pushd ${BLENDER_SCRIPT_DIR}
if ! grep -q "${UNIQUEID}, REMOVED UNUSED FILES" $PROGRESS_LOG; then
EVENT_ID=$(echo $LOCAL_FILE_WITH_DATA | \
sed -e "s#${UNIQUEID}_##" \
-e "s#\.dat##")
EVENT_UNIQUE_ID=${UNIQUEID}_${EVENT_ID}
for LOCAL_FILE_WITH_DATA in $EXTRACTED_FILES; do
##############################
# Phase 2: blender animate #
# Phase 2: Event selection #
##############################
NUMBER_OF_PARTICLES=$(wc -l $LOCAL_FILE_WITH_DATA | \
......@@ -537,48 +532,146 @@ elif [ "$SAMPLE" = "false" ]; then
AVERAGE_PT=$(awk 'BEGIN {ptsum=0;n=0} {ptsum+=$9;n++} END {print ptsum/n}' \
${LOCAL_FILE_WITH_DATA})
echo "File $LOCAL_FILE_WITH_DATA has $NUMBER_OF_PARTICLES particles."
echo "File $LOCAL_FILE_WITH_DATA:"
echo "Number of particles: $NUMBER_OF_PARTICLES"
echo "Average Z momentum: $AVERAGE_PZ"
echo "Average transversal momentum $AVERAGE_PT"
EVENT_COUNTER=$(more event_counter.txt)
if (( $(echo "$AVERAGE_PT >= $MIN_AVG_PT" |bc -l) )); then
if (( $(echo "$AVERAGE_PZ >= $MIN_AVG_PZ" |bc -l) )); then
if [[ $NUMBER_OF_PARTICLES -le $MAX_PARTICLES && $NUMBER_OF_PARTICLES \
-ge $MIN_PARTICLES && $EVENT_COUNTER -lt $N_OF_EVENTS ]]; then
######################################################################
# Remove text data of files for events that will not be animated: #
######################################################################
if (( $(echo "$AVERAGE_PT < $MIN_AVG_PT" |bc -l) )); then
if ! grep -q "${UNIQUEID}, ${EVENT_ID}, SCENE, FINISHED" $PROGRESS_LOG; then
echo "Average Transversal Momentum too low (minimum accepted is $MIN_AVG_PT). Deleting data text file."
echo "Processing ${EVENT_UNIQUE_ID} ($NUMBER_OF_PARTICLES tracks) in Blender"
# Remove non-processed files
rm -f $LOCAL_FILE_WITH_DATA
echo "Processing ${EVENT_UNIQUE_ID} in Blender"
elif (( $(echo "$AVERAGE_PZ < $MIN_AVG_PZ" |bc -l) )); then
timestamp "${UNIQUEID}, ${EVENT_ID}, SCENE, STARTING, $NUMBER_OF_PARTICLES" >> $PROGRESS_LOG
blender -noaudio --background -P animate_particles.py -- -radius=0.05 \
-duration=${DURATION} -datafile="${LOCAL_FILE_WITH_DATA}"\
-n_event=${EVENT_ID} -simulated_t=0.03 -fps=${FPS} -resolution=${RESOLUTION}\
-transparency=${TRANSPARENCY} -stamp_note="${EVENT_UNIQUE_ID}" -its=${ITS}\
echo "Average Z Momentum too low (minimum accepted is $MIN_AVG_PZ). Deleting data text file."
# Remove non-processed files
rm -f $LOCAL_FILE_WITH_DATA
elif [[ $NUMBER_OF_PARTICLES -lt $MIN_PARTICLES ]]; then
echo "Too little particles (minimum accepted is $MIN_PARTICLES). Deleting data text file."
# Remove non-processed files
rm -f $LOCAL_FILE_WITH_DATA
elif [[ $NUMBER_OF_PARTICLES -gt $MAX_PARTICLES ]]; then
echo "Too many particles (maximum accepted is $MAX_PARTICLES). Deleting data text file."
# Remove non-processed files
rm -f $LOCAL_FILE_WITH_DATA
elif [[ $EVENT_COUNTER -ge $N_OF_EVENTS ]]; then
echo "Numbers of events set to be animated has already been reached. Deleting data text file."
# Remove non-processed files
rm -f $LOCAL_FILE_WITH_DATA
else
# Increment event counter
EVENT_COUNTER=$EVENT_COUNTER+1
rm -f event_counter.txt
echo "$EVENT_COUNTER" > event_counter.txt
echo "This event will be animated. Continue."
fi
echo " " # Skip line to make it neat
done
timestamp "${UNIQUEID}, REMOVED UNUSED FILES" >> $PROGRESS_LOG
fi
# Remove event counter file
rm -f event_counter.txt
# Now the list of extracted files shall only include events we want to animate
EXTRACTED_FILES=$(ls -1 ${UNIQUEID}_*.dat | sort --version-sort)
################################################
# Create script so we can use GNU parallel #
# to create multiple Blender scenes #
################################################
if ! grep -q "${UNIQUEID}, PREPARED TO MAKE SCENES IN PARALLEL" $PROGRESS_LOG; then
rm -f scene-making
for LOCAL_FILE_WITH_DATA in $EXTRACTED_FILES; do
EVENT_ID=$(echo $LOCAL_FILE_WITH_DATA | \
sed -e "s#${UNIQUEID}_##" \
-e "s#\.dat##")
EVENT_UNIQUE_ID=${UNIQUEID}_${EVENT_ID}
# echo 'blender animate_particles.py' > scene-making
echo blender -noaudio --background -P animate_particles.py -- -radius=0.05 \
-duration=${DURATION} -datafile=\'${LOCAL_FILE_WITH_DATA}\' \
-n_event=${EVENT_ID} -simulated_t=0.03 -fps=${FPS} -resolution=${RESOLUTION} \
-transparency=${TRANSPARENCY} -stamp_note=\'${EVENT_UNIQUE_ID}\' -its=${ITS} \
-tpc=${TPC} -trd=${TRD} -emcal=${EMCAL} -detailed_tpc=${DETAILED_TPC} \
-blendersave=${BLENDERSAVE} -picpct=${PICPCT} -tpc_blender_path=${BLENDER_SCRIPT_DIR}\
-output_path="${BLENDER_OUTPUT}"
timestamp "${UNIQUEID}, ${EVENT_ID}, SCENE, FINISHED, $NUMBER_OF_PARTICLES" >> $PROGRESS_LOG
-blendersave=1 -picpct=${PICPCT} -tpc_blender_path=${BLENDER_SCRIPT_DIR} \
-output_path=\'${BLENDER_OUTPUT}\' >> scene-making
done
timestamp "${UNIQUEID}, PREPARED TO MAKE SCENES IN PARALLEL" >> $PROGRESS_LOG
fi
###################################
# Make Blender scenes in parallel #
###################################
if ! grep -q "${UNIQUEID}, PARALLEL, SCENES, FINISHED" $PROGRESS_LOG; then
parallel --jobs $N_OF_EVENTS < scene-making
timestamp "${UNIQUEID}, PARALLEL, SCENES, FINISHED" >> $PROGRESS_LOG
fi
rm -f scene-making
#####################################
# Render scenes in selected cameras #
#####################################
for LOCAL_FILE_WITH_DATA in $EXTRACTED_FILES; do
EVENT_ID=$(echo $LOCAL_FILE_WITH_DATA | \
sed -e "s#${UNIQUEID}_##" \
-e "s#\.dat##")
EVENT_UNIQUE_ID=${UNIQUEID}_${EVENT_ID}
NUMBER_OF_PARTICLES=$(wc -l $LOCAL_FILE_WITH_DATA | \
awk '{ print $1 }')
for type in $CAMERAS; do
if ! grep -q "${UNIQUEID}, ${EVENT_ID}, ${type}, FINISHED" $PROGRESS_LOG; then
timestamp "${UNIQUEID}, ${EVENT_ID}, ${type}, STARTING, $NUMBER_OF_PARTICLES" >> $PROGRESS_LOG
blender -noaudio --background -P render.py -- -cam ${type} -datafile\
"${LOCAL_FILE_WITH_DATA}" -n_event ${EVENT_ID} -pic_pct ${PICPCT} -output_path "${BLENDER_OUTPUT}"
timestamp "${UNIQUEID}, ${EVENT_ID}, ${type}, FINISHED, $NUMBER_OF_PARTICLES" >> $PROGRESS_LOG
fi
done
########################
# Make mosaic 2x2 clip #
########################
if [ "$MOSAIC" = "true" ]; then
if ! grep -q "${UNIQUEID}, ${EVENT_ID}, MOSAIC, FINISHED" $PROGRESS_LOG; then
......@@ -608,54 +701,30 @@ elif [ "$SAMPLE" = "false" ]; then
fi
#######################################################
# Move text data files to where animations are stored #
#######################################################
if ! grep -q "${UNIQUEID}, ${EVENT_ID}, TEXT DATA MOVED to final location" $PROGRESS_LOG; then
# Move processed file to final location
mv $LOCAL_FILE_WITH_DATA ${BLENDER_OUTPUT}/$LOCAL_FILE_WITH_DATA
timestamp "${UNIQUEID}, ${EVENT_ID}, TEXT DATA MOVED to final location" >> $PROGRESS_LOG
fi
echo "EVENT ${EVENT_UNIQUE_ID} DONE with FILE $LOCAL_FILE_WITH_DATA."
# Increment event counter
EVENT_COUNTER=$EVENT_COUNTER+1
rm -f event_counter.txt
echo "$EVENT_COUNTER" > event_counter.txt
else
if [[ $NUMBER_OF_PARTICLES -lt $MIN_PARTICLES ]]; then
echo "Too little particles (minimum accepted is $MIN_PARTICLES). Continue."
elif [[ $NUMBER_OF_PARTICLES -gt $MAX_PARTICLES ]]; then
echo "Too many particles (maximum accepted is $MAX_PARTICLES). Continue."
elif [[ $EVENT_COUNTER -ge $N_OF_EVENTS ]]; then
echo "Numbers of events set to be animated has already been reached. Continue."
fi
# Remove non-processed files
rm -f $LOCAL_FILE_WITH_DATA
fi
else
echo "Average Z Momentum too low (minimum accepted is $MIN_AVG_PZ). Continue."
# Remove non-processed files
rm -f $LOCAL_FILE_WITH_DATA
fi
else
echo "Average Transversal Momentum too low (minimum accepted is $MIN_AVG_PT). Continue."
# Remove non-processed files
rm -f $LOCAL_FILE_WITH_DATA
fi
popd
echo "EVENT ${EVENT_UNIQUE_ID} DONE with FILE $LOCAL_FILE_WITH_DATA."
done
popd
# Remove event counter file
pushd ${BLENDER_SCRIPT_DIR}
rm -f event_counter.txt
########################
# Remove blender files #
########################
if [[ $BLENDERSAVE = 0 ]]; then
pushd ${BLENDER_OUTPUT}
rm -f *.blend
popd
fi
fi
timestamp "${UNIQUEID}, JOB FINISHED" >> $PROGRESS_LOG
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment