workflow_sketch.sh 5.4 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
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
16
export ALIENV_OS_SPEC=ubuntu1604_x86-64
17
18
19
20
21
22
23
24
25
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()
{
26
    echo "$0 <DOWNLOAD> <URL> [DEFAULT_ANIMATION]";
27
28
    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";
29
    echo "  where <DEFAULT_ANIMATION> is optional, either true or false, to indicate if the default animation should be generated";
30
    echo "  leaving <DEFAULT_ANIMATION> blank will generate custom animation from data file";
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
31
32
33
34
35
    echo
    echo
    echo "Usage example:"
    echo "./$0 true http://opendata.cern.ch/record/1103/files/assets/alice/2010/LHC10h/000139173/ESD/0004/AliESDs.root false"
    echo
36
37
38
39
40
}

##############################
# Parse Parameters           #
##############################
41
DOWNLOAD=$1
42
43
44
45
46
47
if [ -z $DOWNLOAD ]; then
    echo "Error. Must explicitely inform whether to download the dataset or not."
    usage
    exit
fi

48
49
URL=$2

50
51
52
53
54
55
56
57
58
DEFAULT_ANIMATION=$3
if [ -z $DEFAULT_ANIMATION ]; then
    DEFAULT_ANIMATION="false"
fi

##############################
# Download Dataset           #
##############################
if [ "$DOWNLOAD" = "true" ]; then
59
60
61
62
63
    if [ -z $URL ]; then
        echo "Error. Must pass the dataset URL."
        usage
        exit
    fi
64
65
66
67
    echo "Downloading data."
    wget $URL
fi

68
##############################
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
69
# Default synthetic animation#
70
##############################
71
72
73
74
75
76
if [ "$DEFAULT_ANIMATION" = "true" ]; then
    echo "Preparing default animation."
    ##############################
    # Phase 1: blender animate   #
    ##############################
    pushd ${BLENDER_SCRIPT_DIR}
77
    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"
78
79
80
81
82
    popd
    mkdir --verbose -p ${BLENDER_OUTPUT}
    mv --verbose /tmp/blender ${BLENDER_OUTPUT}
    echo "Done."

83
84
85
##############################
# Animation from file        #
##############################
86
elif [ "$DEFAULT_ANIMATION" = "false" ]; then
87

88
  # Verify if AliESDs.root is here
89
90
91
  ALIESD_ROOT_FILE=$(pwd)/AliESDs.root
  if ! [[ -f "$ALIESD_ROOT_FILE" ]]
  then
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
92
93
      echo "AliESDs.root not found."
      exit
94
95
96
  fi

  # Create directory where animations will be saved
97
  mkdir --verbose -p ${BLENDER_OUTPUT}
98

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
99
100
101
  #############################################
  # Phase 1: aliroot extract number of events #
  #############################################
102
  eval $(alienv -w ${ALIENV_WORK_DIR} -a ${ALIENV_OS_SPEC} load ${ALIENV_ID})
103
  pushd ${ALIROOT_SCRIPT_DIR}
104
105
106
107
108
  # 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
109
  aliroot -q -b "runAnalysis.C(-1)"
110

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
111
112
113
  #############################################
  # Phase 1: check number of events           #
  #############################################
114
115
  # Check if events_number.dat file exists
  FILE_WITH_NUMBER_OF_EVENTS=events_number.dat
116
  FILE_WITH_DATA=esd-detail.dat
117
118
119
120
121
122
  if ! [[ -e ${FILE_WITH_NUMBER_OF_EVENTS} ]]; then
      echo "File $FILE_WITH_NUMBER_OF_EVENTS does not exist. Abort."
      exit
  fi

  n_events=$(cat ${FILE_WITH_NUMBER_OF_EVENTS}) # stores number of events in ESD file
123
124
125
126
127
  if ! [[ "$n_events" =~ ^[0-9]+$ ]]; then # verifies whether n_events is an integer
      echo "Failed to extract number of events from file."
      exit
  else
      echo "The number of events in the file is ${n_events}."
128
  fi
129
130
  # Erase output txt files
  rm -f ${FILE_WITH_NUMBER_OF_EVENTS}
131
  rm -f ${FILE_WITH_DATA}
132

133
134
135
136
  FIRST_EVENT=0
  LAST_EVENT=$(echo "${n_events}-1" | bc)
  echo "Event identifiers are sequential from ${FIRST_EVENT} to ${LAST_EVENT}."
  
137
  exit
138

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
139
  for ((i=0; i<n_events; i++)); do
140

141
      aliroot -q -b "runAnalysis.C($i)"
142
143
144
145
146
      ESD_DETAIL=${ALIROOT_SCRIPT_DIR}/esd-detail.dat
      if ! [[ -f "$ESD_DETAIL" ]]
      then
        echo "ERROR: aliRoot analysis on event $i went wrong."
      fi
147

148
149
150
      ##############################
      # Phase 2: blender animate   #
      ##############################
151
152
153
      mv --verbose ${ALIROOT_SCRIPT_DIR}/esd-detail.dat ${BLENDER_SCRIPT_DIR}
      pushd ${BLENDER_SCRIPT_DIR}
      for type in "BarrelCamera" "OverviewCamera" "ForwardCamera"; do
154
        blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=1 -camera=${type} -datafile="${FILE_WITH_DATA}" -n_event=$i -simulated_t=0.02 -fps=5 -resolution=50 -stamp_note="Texto no canto"
155
156
157
158
159
160
        echo "${type} for event $i done."
      done
      popd
      echo "EVENT $i DONE."

    done
161
162
  popd

163
  # Move animation directory to local folder
164
  mv --verbose /tmp/blender ${BLENDER_OUTPUT}
165

166
fi