workflow_sketch.sh 5.95 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
  FIRST_EVENT=0
  LAST_EVENT=$(echo "${n_events}-1" | bc)
  echo "Event identifiers are sequential from ${FIRST_EVENT} to ${LAST_EVENT}."
136

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
137
138
139
  #################################################
  # Phase 1: iteration for every event identifier #
  #################################################
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
140
  for EVENT_ID in $(seq ${FIRST_EVENT} ${LAST_EVENT}); do
141
      echo $EVENT_ID
142
143
144
145

      ###############################################
      # Phase 1: aliroot extract data from an event #
      ###############################################
146
147
      FILE_WITH_DATA="esd_detail-event_${EVENT_ID}.dat"

148
      aliroot -q -b "runAnalysis.C(${EVENT_ID})"
149
      if ! [[ -f "$FILE_WITH_DATA" ]]
150
      then
151
152
153
          echo "WARNING: aliRoot extraction for event ${EVENT_ID} went wrong."
	  echo "We are ignoring this and proceed to next event."
	  continue
Lucas Mello Schnorr's avatar
else    
Lucas Mello Schnorr committed
154
155
      else
	  echo "Extracted $FILE_WITH_DATA contains $(wc -l $FILE_WITH_DATA) lines."
156
      fi
157

158
159
160
      ##############################
      # Phase 2: blender animate   #
      ##############################
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
161
      mv --verbose ${ALIROOT_SCRIPT_DIR}/${FILE_WITH_DATA} ${BLENDER_SCRIPT_DIR}
162
163
      pushd ${BLENDER_SCRIPT_DIR}
      for type in "BarrelCamera" "OverviewCamera" "ForwardCamera"; do
164
165
        blender -noaudio --background -P animate_particles.py -- -radius=0.05 -duration=1 -camera=${type} -datafile="${FILE_WITH_DATA}" -n_event=${EVENT_ID} -simulated_t=0.02 -fps=5 -resolution=50 -stamp_note="Texto no canto"
        echo "${type} for event ${EVENT_ID} done."
166
167
      done
      popd
168
      echo "EVENT ${EVENT_ID} DONE."
169
170

    done
171
172
  popd

173
  # Move animation directory to local folder
174
  mv --verbose /tmp/blender ${BLENDER_OUTPUT}
175

176
fi