workflow_sketch.sh 6.25 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
69
70
71
72
73
74
75
76
77
######################################
# 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."

78
##############################
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
79
# Default synthetic animation#
80
##############################
81
82
83
84
85
86
if [ "$DEFAULT_ANIMATION" = "true" ]; then
    echo "Preparing default animation."
    ##############################
    # Phase 1: blender animate   #
    ##############################
    pushd ${BLENDER_SCRIPT_DIR}
87
    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"
88
89
90
91
92
    popd
    mkdir --verbose -p ${BLENDER_OUTPUT}
    mv --verbose /tmp/blender ${BLENDER_OUTPUT}
    echo "Done."

93
94
95
##############################
# Animation from file        #
##############################
96
elif [ "$DEFAULT_ANIMATION" = "false" ]; then
97

98
  # Verify if AliESDs.root is here
99
100
101
  ALIESD_ROOT_FILE=$(pwd)/AliESDs.root
  if ! [[ -f "$ALIESD_ROOT_FILE" ]]
  then
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
102
103
      echo "AliESDs.root not found."
      exit
104
105
  fi

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
106
107
108
  #############################################
  # Phase 1: aliroot extract number of events #
  #############################################
109
  eval $(alienv -w ${ALIENV_WORK_DIR} -a ${ALIENV_OS_SPEC} load ${ALIENV_ID})
110
  pushd ${ALIROOT_SCRIPT_DIR}
111
112
113
114
115
  # 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
116
  aliroot -q -b "runAnalysis.C(-1)"
117

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
118
119
120
  #############################################
  # Phase 1: check number of events           #
  #############################################
121
122
  # Check if events_number.dat file exists
  FILE_WITH_NUMBER_OF_EVENTS=events_number.dat
123
  FILE_WITH_DATA=esd-detail.dat
124
125
126
127
128
129
  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
130
131
132
133
134
  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}."
135
  fi
136
137
  # Erase output txt files
  rm -f ${FILE_WITH_NUMBER_OF_EVENTS}
138
  rm -f ${FILE_WITH_DATA}
139

140
141
142
  FIRST_EVENT=0
  LAST_EVENT=$(echo "${n_events}-1" | bc)
  echo "Event identifiers are sequential from ${FIRST_EVENT} to ${LAST_EVENT}."
143

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
144
145
146
  # Create directory where animations will be saved
  mkdir --verbose -p ${BLENDER_OUTPUT}

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
147
148
149
  #################################################
  # Phase 1: iteration for every event identifier #
  #################################################
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
150
  for EVENT_ID in $(seq ${FIRST_EVENT} ${LAST_EVENT}); do
151
      echo $EVENT_ID
152
153
154
155

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

158
      aliroot -q -b "runAnalysis.C(${EVENT_ID})"
159
      if ! [[ -f "$FILE_WITH_DATA" ]]
160
      then
161
162
163
          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
164
165
      else
	  echo "Extracted $FILE_WITH_DATA contains $(wc -l $FILE_WITH_DATA) lines."
166
      fi
167

168
169
170
      ##############################
      # Phase 2: blender animate   #
      ##############################
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
171
      mv --verbose ${ALIROOT_SCRIPT_DIR}/${FILE_WITH_DATA} ${BLENDER_SCRIPT_DIR}
172
173
      pushd ${BLENDER_SCRIPT_DIR}
      for type in "BarrelCamera" "OverviewCamera" "ForwardCamera"; do
174
175
        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."
176
177
      done
      popd
178
      echo "EVENT ${EVENT_ID} DONE."
179
180

    done
181
182
  popd

183
  # Move animation directory to local folder
184
  mv --verbose /tmp/blender ${BLENDER_OUTPUT}
185

186
fi