workflow_sketch.sh 5.13 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=/mnt/SSD/schnorr/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

106
107
108
  ############################
  # Phase 1: aliroot extract #
  ############################
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"
117

118
119
120
  #################################################
  # Phase 1: iteration for every event identifier #
  #################################################
121

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
122
123
124
  # Create directory where animations will be saved
  mkdir --verbose -p ${BLENDER_OUTPUT}

125
126
127
128
129
130
131
132
  # 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
133
134
135
136
137
138
      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
139

140
141
142
      ##############################
      # Phase 2: blender animate   #
      ##############################
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
143
      mv --verbose ${ALIROOT_SCRIPT_DIR}/${FILE_WITH_DATA} ${BLENDER_SCRIPT_DIR}
144
145
      pushd ${BLENDER_SCRIPT_DIR}
      for type in "BarrelCamera" "OverviewCamera" "ForwardCamera"; do
146
        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="${EVENT_UNIQUE_ID}"
147
        echo "${type} for event ${EVENT_ID} done."
148
149
      done
      popd
150
      echo "EVENT ${EVENT_ID} DONE."
151

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
152
  done
153
154
  popd

155
  # Move animation directory to local folder
156
  #mv --verbose /tmp/blender ${BLENDER_OUTPUT}
157

158
fi