workflow_sketch.sh 7.21 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#!/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/
# alienv working directory
13
export ALIENV_WORK_DIR=/mnt/SSD/schnorr/ALICE/sw/
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
14
export ALIENV_OS_SPEC=ubuntu1604_x86-64
15
16
17
18
19
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"

##############################
20
# Command-line options       #
21
##############################
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# See the following link to understand the code below
# https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash

# saner programming env: these switches turn some bugs into errors
set -o errexit -o pipefail -o noclobber -o nounset

# -allow a command to fail with !’s side effect on errexit
# -use return value from ${PIPESTATUS[0]}, because ! hosed $?
! getopt --test > /dev/null
if [[ ${PIPESTATUS[0]} -ne 4 ]]; then
    echo 'I’m sorry, `getopt --test` failed in this environment.'
    exit 1
fi

OPTIONS=hdau:
LONGOPTS=help,download,default,url:,

# -regarding ! and PIPESTATUS see above
# -temporarily store output to be able to check for errors
# -activate quoting/enhanced mode (e.g. by writing out “--options”)
# -pass arguments only via   -- "$@"   to separate them correctly
! PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@")
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
    # e.g. return value is 1
    #  then getopt has complained about wrong arguments to stdout
    exit 2
fi
# read getopt’s output this way to handle the quoting right:
eval set -- "$PARSED"

52
53
54
55

##############################
# Parse Parameters           #
##############################
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
HELP=false
DOWNLOAD=false
DEFAULT=false
URL=-
# now enjoy the options in order and nicely split until we see --
while true; do
    case "$1" in
	-h|--help)
	    HELP=true
	    shift
	    break
	    ;;
        -d|--download)
            DOWNLOAD=true
            shift
            ;;
	-a|--default)
            DEFAULT=true
            shift
            ;;
	-u|--url)
	    URL="$2"
            shift 2
            ;;
        --)
            shift
            break
            ;;
        *)
            echo "Programming error"
            exit 3
            ;;
    esac
done

# handle non-option arguments
if [[ $# -ne 0 ]]; then
    echo "$0: non-option arguments ($#, $*) are ignored."
94
95
    echo "Remove them manually as indicated between parenthesis."
    exit
96
97
fi

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
##############################
# Usage                      #
##############################
function usage()
{
    # Using a here doc with standard out.
    cat <<-END
Usage:
------
   -h | --help
     Display this help
   -d | --download
     Download the AliESDs.root file using the provided URL
   -u | --url URL
     Provide the URL to uniquely identify a AliESDs.root dataset.
     This should be in the format provided by http://opendata.cern.ch.
     See example below.
   -a | --default
     Creates a default animation with blender.

Example:
--------
$0 --url http://opendata.cern.ch/record/1103/files/assets/alice/2010/LHC10h/000139173/ESD/0004/AliESDs.root --download

END
}
124

125
126
127
128
129
130
131
132
133
if [[ $HELP = "true" ]]; then
    usage
    exit
else
    echo "-------- Parsed parameters --------"
    echo "URL: $URL"
    echo "Download: $DOWNLOAD"
    echo "Default: $DEFAULT"
    echo "-----------------------------------"
134
135
136
137
138
139
fi

##############################
# Download Dataset           #
##############################
if [ "$DOWNLOAD" = "true" ]; then
140
141
142
143
144
    if [ -z $URL ]; then
        echo "Error. Must pass the dataset URL."
        usage
        exit
    fi
145
146
147
148
    echo "Downloading data."
    wget $URL
fi

149
150
151
152
153
154
155
156
157
158
######################################
# Established Unique ID based on URL #
######################################
UNIQUEID=$(echo $URL | sed \
			   -e "s#http://opendata.cern.ch/##" \
			   -e "s#/AliESDs.root##" \
			   -e "s#files/assets/##" \
			   -e "s#/#_#g")
echo "The unique ID is $UNIQUEID."

159
##############################
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
160
# Default synthetic animation#
161
##############################
162
if [ "$DEFAULT" = "true" ]; then
163
164
165
166
167
    echo "Preparing default animation."
    ##############################
    # Phase 1: blender animate   #
    ##############################
    pushd ${BLENDER_SCRIPT_DIR}
168
    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"
169
    popd
170
    BLENDER_OUTPUT=.
171
172
173
174
    mkdir --verbose -p ${BLENDER_OUTPUT}
    mv --verbose /tmp/blender ${BLENDER_OUTPUT}
    echo "Done."

175
176
177
##############################
# Animation from file        #
##############################
178
elif [ "$DEFAULT" = "false" ]; then
179

180
  # Verify if AliESDs.root is here
181
182
183
  ALIESD_ROOT_FILE=$(pwd)/AliESDs.root
  if ! [[ -f "$ALIESD_ROOT_FILE" ]]
  then
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
184
185
      echo "AliESDs.root not found."
      exit
186
187
  fi

188
189
190
  ############################
  # Phase 1: aliroot extract #
  ############################
191
  eval $(alienv -w ${ALIENV_WORK_DIR} -a ${ALIENV_OS_SPEC} load ${ALIENV_ID})
192
  pushd ${ALIROOT_SCRIPT_DIR}
193
194
195
196
197
  # Remove existing symbolic link
  rm --verbose AliESDs.root
  # Create a symbolic link to the actual AliESDs.root
  ln --verbose -s ${ALIESD_ROOT_FILE} AliESDs.root
  # Run the extraction tool
198
  aliroot runAnalysis.C
199

200
201
202
  #################################################
  # Phase 1: iteration for every event identifier #
  #################################################
203

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
204
  # Create directory where animations will be saved
205
  BLENDER_OUTPUT=$(pwd)/$UNIQUEID
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
206
207
  mkdir --verbose -p ${BLENDER_OUTPUT}

208
209
210
211
212
213
214
215
  # Get all extracted files
  EXTRACTED_FILES=$(ls -1 esd_detail-event_*.dat | sort --version-sort)
  for FILE_WITH_DATA in $EXTRACTED_FILES; do
      EVENT_ID=$(echo $FILE_WITH_DATA | \
		     sed -e "s#esd_detail-event_##" \
			 -e "s#\.dat##")
      EVENT_UNIQUE_ID=${UNIQUEID}_${EVENT_ID}

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
216
217
218
219
220
221
      if ! [[ -s $FILE_WITH_DATA ]]; then
	  echo "File $FILE_WITH_DATA has zero size. Ignore and continue."
	  continue
      else
	  echo "Processing ${EVENT_UNIQUE_ID} in blender"
      fi
222

223
224
225
      ##############################
      # Phase 2: blender animate   #
      ##############################
226
      pushd ${BLENDER_SCRIPT_DIR}
227
228
229
230

      LOCAL_FILE_WITH_DATA=${EVENT_UNIQUE_ID}.dat
      cp ${ALIROOT_SCRIPT_DIR}/$FILE_WITH_DATA \
	 ${BLENDER_SCRIPT_DIR}/${LOCAL_FILE_WITH_DATA}
231

232
      for type in "BarrelCamera" "OverviewCamera" "ForwardCamera"; do
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
233
          echo "Processing ${EVENT_UNIQUE_ID} with $type Camera in blender"
234
235

          blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=1 -camera=${type} -datafile="${LOCAL_FILE_WITH_DATA}" -n_event=${EVENT_ID} -simulated_t=0.01 -fps=5 -resolution=50 -stamp_note="${EVENT_UNIQUE_ID}"
236
237
          # Move generated file to final location
          mv /tmp/blender/* ${BLENDER_OUTPUT}
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
238
          echo "${type} for event ${EVENT_ID} done."
239
      done
240
241

      # Move processed file to final location
242
      mv $LOCAL_FILE_WITH_DATA ${BLENDER_OUTPUT}
243

244
      popd
245
      echo "EVENT ${EVENT_ID} DONE."
246

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
247
  done
248
249
  popd
fi