-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathsetup.sh
More file actions
173 lines (145 loc) Β· 5.61 KB
/
setup.sh
File metadata and controls
173 lines (145 loc) Β· 5.61 KB
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
#!/usr/bin/env bash
setup_hbt() {
# Runs the project setup, leading to a collection of environment variables starting with either
# - "CF_", for controlling behavior implemented by columnflow, or
# - "HBT_", for features provided by the analysis repository itself.
# Check the setup.sh in columnflow for documentation of the "CF_" variables. The purpose of all
# "HBT_" variables is documented below.
#
# The setup also handles the installation of the software stack via virtual environments, and
# optionally an interactive setup where the user can configure certain variables.
#
#
# Arguments:
# 1. The name of the setup. "default" (which is itself the default when no name is set)
# triggers a setup with good defaults, avoiding all queries to the user and the writing of
# a custom setup file. See "interactive_setup()" for more info.
#
#
# Optinally preconfigured environment variables:
# None yet.
#
#
# Variables defined by the setup and potentially required throughout the analysis:
# HBT_BASE
# The absolute analysis base directory. Used to infer file locations relative to it.
# HBT_SETUP
# A flag that is set to 1 after the setup was successful.
#
# load cf setup helpers
#
local shell_is_zsh="$( [ -z "${ZSH_VERSION}" ] && echo "false" || echo "true" )"
local this_file="$( ${shell_is_zsh} && echo "${(%):-%x}" || echo "${BASH_SOURCE[0]}" )"
local this_dir="$( cd "$( dirname "${this_file}" )" && pwd )"
local cf_base="${this_dir}/modules/columnflow"
CF_SKIP_SETUP="true" source "${cf_base}/setup.sh" "" || return "$?"
#
# prevent repeated setups
#
cf_export_bool HBT_SETUP
if ${HBT_SETUP} && ! ${CF_ON_SLURM}; then
>&2 echo "the HH -> bbtautau analysis was already succesfully setup"
>&2 echo "re-running the setup requires a new shell"
return "1"
fi
#
# prepare local variables
#
local orig="${PWD}"
local setup_name="${1:-default}"
local setup_is_default="false"
[ "${setup_name}" = "default" ] && setup_is_default="true"
# zsh options
if ${shell_is_zsh}; then
emulate -L bash
setopt globdots
fi
#
# global variables
# (HBT = hh2bbtautau, CF = columnflow)
#
# start exporting variables
export HBT_BASE="${this_dir}"
export CF_BASE="${cf_base}"
export CF_REPO_BASE="${HBT_BASE}"
export CF_REPO_BASE_ALIAS="HBT_BASE"
export CF_SETUP_NAME="${setup_name}"
# interactive setup
if ! ${CF_REMOTE_ENV}; then
cf_setup_interactive_body() {
# the flavor will be cms
export CF_FLAVOR="cms"
# query common variables
cf_setup_interactive_common_variables
# hbt specific variables
if [[ "$( hostname )" == *.desy.de ]]; then
query HBT_USE_CVMFS_SOFTWARE "Use centrally provided software on /cvmfs" "true"
if [ "${HBT_USE_CVMFS_SOFTWARE}" = "true" ]; then
export_and_save CF_CONDA_BASE "/cvmfs/cms.desy.de/columnflow/software/conda_py39"
export_and_save CF_VENV_BASE "/cvmfs/cms.desy.de/columnflow/software_hbt/venvs_py39"
fi
else
export_and_save HBT_USE_CVMFS_SOFTWARE "false"
fi
}
cf_setup_interactive "${CF_SETUP_NAME}" "${HBT_BASE}/.setups/${CF_SETUP_NAME}.sh" || return "$?"
fi
# continue the fixed setup
export CF_CONDA_BASE="${CF_CONDA_BASE:-${CF_SOFTWARE_BASE}/conda}"
export CF_VENV_BASE="${CF_VENV_BASE:-${CF_SOFTWARE_BASE}/venvs}"
export CF_CMSSW_BASE="${CF_CMSSW_BASE:-${CF_SOFTWARE_BASE}/cmssw}"
export CF_SCHEDULER_HOST="${CF_SCHEDULER_HOST:-naf-cms14.desy.de}"
export CF_SCHEDULER_PORT="${CF_SCHEDULER_PORT:-8088}"
export CF_INTERACTIVE_VENV_FILE="${CF_INTERACTIVE_VENV_FILE:-${HBT_BASE}/sandboxes/venv_hbt_dev.sh}"
if [ -z "${CF_INSPECT_SANDBOX}" ] && [ ! -z "${CF_INTERACTIVE_VENV_FILE}" ]; then
export CF_INSPECT_SANDBOX="$( basename "${CF_INTERACTIVE_VENV_FILE%.*}" )"
fi
export HBT_WLCG_RETRIES="${HBT_WLCG_RETRIES:-3}"
#
# common variables
#
cf_setup_common_variables || return "$?"
#
# minimal local software setup
#
cf_setup_software_stack "${CF_SETUP_NAME}" || return "$?"
# ammend paths that are not covered by the central cf setup
export PATH="${HBT_BASE}/bin:${PATH}"
export PYTHONPATH="${HBT_BASE}:${HBT_BASE}/modules/cmsdb:${PYTHONPATH}"
# initialze submodules
if ! ${CF_REMOTE_ENV} && [ -e "${HBT_BASE}/.git" ]; then
local m
for m in $( ls -1q "${HBT_BASE}/modules" ); do
cf_init_submodule "${HBT_BASE}" "modules/${m}"
done
fi
#
# additional common cf setup steps
#
cf_setup_post_install || return "$?"
# update the law config file to switch from mirrored to bare wlcg targets
# as local mounts are typically not available remotely
if ${CF_REMOTE_ENV}; then
sed -i -r 's/(.+\: ?)wlcg_mirrored, local_.+, ?(wlcg_[^\s]+)/\1wlcg, \2/g' "${LAW_CONFIG_FILE}"
fi
#
# finalize
#
export HBT_SETUP="true"
}
main() {
# Invokes the main action of this script, catches possible error codes and prints a message.
# run the actual setup
if setup_hbt "$@"; then
cf_color green "HH -> bbtautau analysis successfully setup"
return "0"
else
local code="$?"
cf_color red "setup failed with code ${code}"
return "${code}"
fi
}
# entry point
if [ "${HBT_SKIP_SETUP}" != "true" ]; then
main "$@"
fi