workflow_sketch.sh 5.34 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
20
21
22
23
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()
{
24
    echo "$0 <DOWNLOAD> <URL> [DEFAULT_ANIMATION]";
25
26
    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";
27
    echo "  where <DEFAULT_ANIMATION> is optional, either true or false, to indicate if the default animation should be generated";
28
    echo "  leaving <DEFAULT_ANIMATION> blank will generate custom animation from data file";
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
29
30
31
32
33
    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
34
35
36
37
38
}

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

46
47
URL=$2

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

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

66
67
68
69
70
71
72
73
74
75
######################################
# 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."

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

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

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

105
106
107
  ############################
  # Phase 1: aliroot extract #
  ############################
108
  eval $(alienv -w ${ALIENV_WORK_DIR} -a ${ALIENV_OS_SPEC} load ${ALIENV_ID})
109
  pushd ${ALIROOT_SCRIPT_DIR}
110
111
112
113
114
  # 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
115
  aliroot -q -b "runAnalysis.C"
116

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

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
121
  # Create directory where animations will be saved
122
  BLENDER_OUTPUT=$(pwd)/$UNIQUEID
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
123
124
  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   #
      ##############################
143
      pushd ${BLENDER_SCRIPT_DIR}
144
145
146
147

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

149
      for type in "BarrelCamera" "OverviewCamera" "ForwardCamera"; do
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
150
          echo "Processing ${EVENT_UNIQUE_ID} with $type Camera in blender"
151
152

          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}"
153
154
          # Move generated file to final location
          mv /tmp/blender/* ${BLENDER_OUTPUT}
Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
155
          echo "${type} for event ${EVENT_ID} done."
156
      done
157
158

      # Move processed file to final location
159
      mv $LOCAL_FILE_WITH_DATA ${BLENDER_OUTPUT}
160

161
      popd
162
      echo "EVENT ${EVENT_ID} DONE."
163

Lucas Mello Schnorr's avatar
Lucas Mello Schnorr committed
164
  done
165
166
  popd
fi