forked from cms-tau-pog/TauMLTools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenv.sh
218 lines (199 loc) · 8.36 KB
/
env.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
# if (( $# < 1 )) ; then
# cat << EOF
# Setup environment for TauMLTools
# Usage: source env.sh mode [mode_arg_1] [mode_arg_2] ...
# Supported modes: run2 run3 phase2_112X phase2_113X lcg conda hlt
# Mode-specific arguments:
# conda
# --update [env.yaml] updates environment from env.yaml (default: tau-ml-env.yaml)
# EOF
# return 1
# fi
run_cmd() {
"$@"
local RESULT=$?
if (( $RESULT != 0 )); then
echo "Error while running '$@'"
kill -INT $$
fi
}
do_install_cmssw() {
local this_file="$( [ ! -z "$ZSH_VERSION" ] && echo "${(%):-%x}" || echo "${BASH_SOURCE[0]}" )"
local this_dir="$( cd "$( dirname "$this_file" )" && pwd )"
export SCRAM_ARCH=$1
local CMSSW_VER=$2
local os_version=$3
if ! [ -f "$this_dir/soft/CentOS$os_version/$CMSSW_VER/.installed" ]; then
run_cmd mkdir -p "$this_dir/soft/CentOS$os_version"
run_cmd cd "$this_dir/soft/CentOS$os_version"
run_cmd source /cvmfs/cms.cern.ch/cmsset_default.sh
if [ -d $CMSSW_VER ]; then
echo "Removing incomplete $CMSSW_VER installation..."
run_cmd rm -rf $CMSSW_VER
fi
echo "Creating $CMSSW_VER area for CentOS$os_version in $PWD ..."
run_cmd scramv1 project CMSSW $CMSSW_VER
run_cmd cd $CMSSW_VER/src
run_cmd eval `scramv1 runtime -sh`
git cms-init
git cms-merge-topic silviodonato:customizeHLTFor2023 # to download customisation function for 2023 PFCluster thresholds at HLT
run_cmd mkdir TauMLTools
run_cmd cd TauMLTools
run_cmd ln -s "$this_dir/Analysis" Analysis
run_cmd ln -s "$this_dir/Core" Core
run_cmd ln -s "$this_dir/Production" Production
run_cmd scram b -j8
run_cmd touch "$this_dir/soft/CentOS$os_version/$CMSSW_VER/.installed"
fi
}
install_cmssw() {
local this_file="$( [ ! -z "$ZSH_VERSION" ] && echo "${(%):-%x}" || echo "${BASH_SOURCE[0]}" )"
local this_dir="$( cd "$( dirname "$this_file" )" && pwd )"
local scram_arch=$1
local cmssw_version=$2
local os_version=$3
local target_os_version=$4
if [[ $os_version == $target_os_version ]]; then
local env_cmd=""
local env_cmd_args=""
else
if [[ $target_os_version < 8 ]] ; then
local os_type="cc"
else
local os_type="el"
fi
local env_cmd="cmssw-$os_type$target_os_version"
if ! command -v $env_cmd &> /dev/null; then
echo "Unable to do a cross-platform installation for $cmssw_version SCRAM_ARCH=$scram_arch. $env_cmd is not available."
return 1
fi
local env_cmd_args="--command-to-run"
fi
if ! [ -f "$this_dir/soft/CentOS$target_os_version/$CMSSW_VER/.installed" ]; then
run_cmd $env_cmd $env_cmd_args /usr/bin/env -i HOME=$HOME bash "$this_file" install_cmssw $scram_arch $cmssw_version $target_os_version
fi
}
action() {
local this_file="$( [ ! -z "$ZSH_VERSION" ] && echo "${(%):-%x}" || echo "${BASH_SOURCE[0]}" )"
local this_dir="$( cd "$( dirname "$this_file" )" && pwd )"
local MODE=$1
export ANALYSIS_PATH="$this_dir"
export ANALYSIS_DATA_PATH="$ANALYSIS_PATH/data"
export X509_USER_PROXY="$ANALYSIS_DATA_PATH/voms.proxy"
export PYTHONPATH="$this_dir:$PYTHONPATH"
export LAW_HOME="$this_dir/.law"
export LAW_CONFIG_FILE="$this_dir/LawWorkflows/law.cfg"
run_cmd mkdir -p "$ANALYSIS_DATA_PATH"
local os_version=$(cat /etc/os-release | grep VERSION_ID | sed -E 's/VERSION_ID="([0-9]+).*"/\1/')
local default_cmssw_ver=CMSSW_13_0_0
export DEFAULT_CMSSW_BASE="$ANALYSIS_PATH/soft/CentOS$os_version/$default_cmssw_ver"
if [[ $MODE = *"cmssw"* ]]; then
run_cmd install_cmssw slc7_amd64_gcc11 $default_cmssw_ver $os_version 7
run_cmd install_cmssw el8_amd64_gcc11 $default_cmssw_ver $os_version 8
#for phase2
#run_cmd install_cmssw slc7_amd64_gcc900 CMSSW_11_2_5 $os_version 7
#run_cmd install_cmssw slc7_amd64_gcc900 CMSSW_11_3_0 $os_version 7
alias cmsEnv="env -i HOME=$HOME ANALYSIS_PATH=$ANALYSIS_PATH ANALYSIS_DATA_PATH=$ANALYSIS_DATA_PATH X509_USER_PROXY=$X509_USER_PROXY DEFAULT_CMSSW_BASE=$DEFAULT_CMSSW_BASE $ANALYSIS_PATH/RunKit/cmsEnv.sh"
#alias cmsEnv11_2="env -i HOME=$HOME ANALYSIS_PATH=$ANALYSIS_PATH ANALYSIS_DATA_PATH=$ANALYSIS_DATA_PATH X509_USER_PROXY=$X509_USER_PROXY DEFAULT_CMSSW_BASE=$ANALYSIS_PATH/soft/CentOS$os_version/CMSSW_11_2_5 $ANALYSIS_PATH/RunKit/cmsEnv.sh"
#alias cmsEnv11_3="env -i HOME=$HOME ANALYSIS_PATH=$ANALYSIS_PATH ANALYSIS_DATA_PATH=$ANALYSIS_DATA_PATH X509_USER_PROXY=$X509_USER_PROXY DEFAULT_CMSSW_BASE=$ANALYSIS_PATH/soft/CentOS$os_version/CMSSW_11_3_0 $ANALYSIS_PATH/RunKit/cmsEnv.sh"
fi
if [[ $MODE == *"conda"* ]]; then
local CONDA=$(which conda 2>/dev/null)
if [[ $CONDA = "" || $CONDA = "/usr/bin/conda" ]]; then
local PRIVATE_CONDA_INSTALL_DEFAULT="$ANALYSIS_PATH/soft/conda"
local PRIVATE_CONDA_INSTALL="$PRIVATE_CONDA_INSTALL_DEFAULT"
if [ -f "$PRIVATE_CONDA_INSTALL_DEFAULT.ref" ]; then
local PRIVATE_CONDA_INSTALL=$(cat "$PRIVATE_CONDA_INSTALL.ref")
fi
if ! [ -f "$PRIVATE_CONDA_INSTALL/.installed" ]; then
echo "Please select path where conda environment and packages will be installed."
if [[ $HOST = lxplus* || $HOSTNAME = lxplus* ]]; then
echo "On lxplus it is recommended to use /afs/cern.ch/work/${USER:0:1}/$USER/conda or /eos/home-${USER:0:1}/$USER/conda."
fi
printf "new or existing conda installation path (default $PRIVATE_CONDA_INSTALL_DEFAULT): "
read PRIVATE_CONDA_INSTALL
if [[ "$PRIVATE_CONDA_INSTALL" = "" ]]; then
PRIVATE_CONDA_INSTALL="$PRIVATE_CONDA_INSTALL_DEFAULT"
fi
if [[ "$PRIVATE_CONDA_INSTALL" != "$PRIVATE_CONDA_INSTALL_DEFAULT" ]]; then
echo $PRIVATE_CONDA_INSTALL > "$PRIVATE_CONDA_INSTALL_DEFAULT.ref"
else
rm -f "$PRIVATE_CONDA_INSTALL_DEFAULT.ref"
fi
if ! [ -f "$PRIVATE_CONDA_INSTALL/.installed" ]; then
if [ -d $PRIVATE_CONDA_INSTALL ]; then
printf "Incomplete private conda installation in $PRIVATE_CONDA_INSTALL. Proceed? [y/N] "
read X
if [[ $X = "y" || $X = "Y" || $X = "yes" ]]; then
run_cmd rm -rf $PRIVATE_CONDA_INSTALL
else
echo "Aborting..."
kill -INT $$
fi
fi
echo "Installing conda..."
run_cmd mkdir -p soft
run_cmd cd soft
run_cmd curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o Miniconda3-latest-Linux-x86_64.sh
run_cmd bash Miniconda3-latest-Linux-x86_64.sh -b -p "$PRIVATE_CONDA_INSTALL"
run_cmd touch "$PRIVATE_CONDA_INSTALL/.installed"
run_cmd rm Miniconda3-latest-Linux-x86_64.sh
run_cmd cd ..
fi
fi
__conda_setup="$($PRIVATE_CONDA_INSTALL/bin/conda shell.${SHELL##*/} hook)"
if (( $? == 0 )); then
eval "$__conda_setup"
else
if [ -f "$PRIVATE_CONDA_INSTALL/etc/profile.d/conda.sh" ]; then
. "$PRIVATE_CONDA_INSTALL/etc/profile.d/conda.sh"
else
export PATH="$PRIVATE_CONDA_INSTALL/bin:$PATH"
fi
fi
unset __conda_setup
fi
tau_env_found=$(conda env list | grep -E '^tau-ml .*' | wc -l)
if (( $tau_env_found != 1 )); then
echo "Creating tau-ml environment..."
run_cmd conda env create -f $ANALYSIS_PATH/tau-ml-env.yaml
fi
run_cmd conda activate tau-ml
ARG="$2"
if [[ $ARG = "--update" ]]; then
ENV_YAML="$3"
if [[ $ENV_YAML = "" ]]; then
ENV_YAML="tau-ml-env.yaml"
fi
echo "Updating conda environment from '$ENV_YAML'..."
run_cmd conda env update --file $ENV_YAML --prune
fi
local TAU_ML_LIB_DIR=$(cd $(dirname $(which python))/..; pwd)
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TAU_ML_LIB_DIR/lib
else
source /cvmfs/sft.cern.ch/lcg/views/setupViews.sh LCG_102 x86_64-centos${os_version}-gcc11-opt
for law_location in /afs/cern.ch/user/m/mrieger/public/law_sw/setup.sh /afs/desy.de/user/r/riegerma/public/law_sw/setup.sh; do
if [ -f $law_location ]; then
source $law_location
break
fi
done
fi
if [ ! -z $ZSH_VERSION ]; then
autoload bashcompinit
bashcompinit
fi
source "$( law completion )"
which eosfusebind &> /dev/null
if [ $? -eq 0 ]; then
eosfusebind -g
fi
alias run_cxx="python $ANALYSIS_PATH/Core/python/run_cxx.py"
echo "TauMLTools environment is successfully loaded."
}
if [ "X$1" = "Xinstall_cmssw" ]; then
do_install_cmssw "${@:2}"
else
action "$@"
fi