workflow_sketch.sh 4.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash

##############################
# Configurations             #
##############################
# Put aliBuild in the PATH env var
export PATH="/mnt/SSD/schnorr/python/bin:$PATH"
# Directory where runAnalysis.C is placed
export ALIROOT_SCRIPT_DIR=$(pwd)/aliRoot/
# Directory where blender scripts are
export BLENDER_SCRIPT_DIR=$(pwd)/animate/
# Directory where output animations should be placed
export BLENDER_OUTPUT=$(pwd)/output/
# alienv working directory
15
export ALIENV_WORK_DIR=/home/tropos/alice/sw
16
17
18
19
20
21
22
23
24
export ALIENV_ID=AliPhysics/latest-aliroot5-user
# Put blender 2.79b in the PATH env var
export PATH="/home/schnorr/install/blender-2.79-linux-glibc219-x86_64/:$PATH"

##############################
# Usage                      #
##############################
function usage()
{
25
    echo "$0 <DOWNLOAD> <URL> [DEFAULT_ANIMATION]";
26
27
    echo "  where <URL> is a URL to uniquely identify a dataset";
    echo "  where <DOWNLOAD> is true or false, indicate whether the dataset should be downloaded";
28
    echo "  where <DEFAULT_ANIMATION> is optional, either true or false, to indicate if the default animation should be generated";
29
    echo "  leaving <DEFAULT_ANIMATION> blank will generate custom animation from data file";
30
31
32
33
34
}

##############################
# Parse Parameters           #
##############################
35
DOWNLOAD=$1
36
37
38
39
40
41
if [ -z $DOWNLOAD ]; then
    echo "Error. Must explicitely inform whether to download the dataset or not."
    usage
    exit
fi

42
43
URL=$2

44
45
46
47
48
49
50
51
52
DEFAULT_ANIMATION=$3
if [ -z $DEFAULT_ANIMATION ]; then
    DEFAULT_ANIMATION="false"
fi

##############################
# Download Dataset           #
##############################
if [ "$DOWNLOAD" = "true" ]; then
53
54
55
56
57
    if [ -z $URL ]; then
        echo "Error. Must pass the dataset URL."
        usage
        exit
    fi
58
59
60
61
    echo "Downloading data."
    wget $URL
fi

62
63
64
##############################
# Default animation          #
##############################
65
66
67
68
69
70
if [ "$DEFAULT_ANIMATION" = "true" ]; then
    echo "Preparing default animation."
    ##############################
    # Phase 1: blender animate   #
    ##############################
    pushd ${BLENDER_SCRIPT_DIR}
71
    blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=2 -camera="OverviewCamera" -datafile="d-esd-detail.dat" -simulated_t=0.02 -fps=5 -resolution=100 -stamp_note="Texto no canto"
72
73
74
75
76
77
    popd
    mkdir --verbose -p ${BLENDER_OUTPUT}
    mv --verbose /tmp/blender ${BLENDER_OUTPUT}
    echo "Done."
fi

78
79
80
##############################
# Animation from file        #
##############################
81
if [ "$DEFAULT_ANIMATION" = "false" ]; then
82

83
  # Verify if AliESDs.root is here
84
85
86
87
88
89
90
91
  ALIESD_ROOT_FILE=$(pwd)/AliESDs.root
  if ! [[ -f "$ALIESD_ROOT_FILE" ]]
  then
  	echo "AliESDs.root not found."
    exit
  fi

  # Create directory where animations will be saved
92
  mkdir --verbose -p ${BLENDER_OUTPUT}
93
94

  # Move ESD file to aliRoot directory
95
  mv --verbose $(pwd)/AliESDs.root ${ALIROOT_SCRIPT_DIR}
96

97
98
99
100
101
  ##############################
  # Phase 1: aliroot extract   #
  ##############################
  eval $(alienv -w /home/tropos/alice/sw -a ubuntu1804_x86-64 load ${ALIENV_ID}) #-w ${ALIENV_WORK_DIR} -a ubuntu1604_x86-64 load ${ALIENV_ID})
  pushd ${ALIROOT_SCRIPT_DIR}
102
  aliroot -q -b "runAnalysis.C(-1)"
103

104
  ls -lh events_number.dat
105
106
107
108
109
110
111
  n_events=`more events_number.dat` # stores number of events in ESD file
  if ! [[ "$n_events" =~ ^[0-9]+$ ]] # verifies whether n_events is an integer
      then
          echo "Failed to extract number of events from file."
  				exit
  fi

112
113
  for ((i=0; i<n_events; i++))
    do
114

115
      aliroot -q -b "runAnalysis.C($i)"
116
117
118
119
120
      ESD_DETAIL=${ALIROOT_SCRIPT_DIR}/esd-detail.dat
      if ! [[ -f "$ESD_DETAIL" ]]
      then
        echo "ERROR: aliRoot analysis on event $i went wrong."
      fi
121

122
123
124
      ##############################
      # Phase 2: blender animate   #
      ##############################
125
126
127
128
129
130
131
132
133
134
      mv --verbose ${ALIROOT_SCRIPT_DIR}/esd-detail.dat ${BLENDER_SCRIPT_DIR}
      pushd ${BLENDER_SCRIPT_DIR}
      for type in "BarrelCamera" "OverviewCamera" "ForwardCamera"; do
        blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=1 -camera=${type} -datafile="esd-detail.dat" -n_event=$i -simulated_t=0.02 -fps=5 -resolution=50 -stamp_note="Texto no canto"
        echo "${type} for event $i done."
      done
      popd
      echo "EVENT $i DONE."

    done
135
136
  popd

137
  # Move animation directory to local folder
138
  mv --verbose /tmp/blender ${BLENDER_OUTPUT}
139

140
fi