-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.sh
More file actions
196 lines (169 loc) · 5.27 KB
/
utils.sh
File metadata and controls
196 lines (169 loc) · 5.27 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
verbose=0
#################
#Queues
###q_lxplus=cmscaf1nw
q_lxplus=1nw
###q_lxplus=cmscaf1nw
q_T2=localgrid@cream01
#order: name stdout submit.sh
submit_to_queue(){
if [ `working_on_lxplus` -eq 1 ]; then
bsub -q $q_lxplus -J $1 -eo $2 < $3
else
qsub -q $q_T2 -j oe -N $1 -o $2 $3
fi
}
##############################################
# Your T2 Specifics (if not on castor/lxplus)
set_T2_specifics(){
T2_LS='ls'
T2_RM='rm -r '
T2_CP='dccp -d 2'
T2_MKDIR='mkdir -p '
T2_CHMOD='chmod 0777 '
T2_FSYS='dcap://'
T2_CHECK='/pnfs/iihe/'
T2_TMP_DIR='/scratch/'
if [ $verbose -eq 1 ] ; then echo "Setting T2 specifics ..." ; fi
}
set_castor_specifics(){
T2_LS='nsls'
T2_RM='nsrm -r '
T2_CP='rfcp'
T2_EOS_CP='cmsStage'
T2_MKDIR='rfmkdir -p '
T2_CHMOD='rfchmod 0777 '
T2_FSYS='rfio://'
T2_TMP_DIR="/tmp/$USER/"
if [ $verbose -eq 1 ] ; then echo "Setting castor specifics ..." ; fi
}
set_eos_specifics(){
# alias eos='/afs/cern.ch/project/eos/installation/cms/bin/eos.select' # This doesn't work (eos cmd missing in bash?)
T2_LS='cmsLs'
T2_RM='/afs/cern.ch/project/eos/installation/cms/bin/eos.select rm -r /eos/cms' # Do not add space before next argument when using this cmd
T2_CP='cmsStage'
T2_MKDIR='/afs/cern.ch/project/eos/installation/cms/bin/eos.select mkdir -p /eos/cms' # Do not add space before next argument when using this cmd
T2_CHMOD='/afs/cern.ch/project/eos/installation/cms/bin/eos.select chmod 2777 /eos/cms' # Do not add space before next argument when using this cmd
T2_FSYS='root://eoscms//eos/cms' # Can check what needs to be added with cmsPfn /store/...
T2_TMP_DIR="/tmp/$USER"
if [ $verbose -eq 1 ] ; then echo "Setting eos specifics ..." ; fi
}
set_eos_store_specifics(){
# alias eos='/afs/cern.ch/project/eos/installation/cms/bin/eos.select' # This doesn't work (eos cmd missing in bash?)
T2_LS='cmsLs'
T2_RM='/afs/cern.ch/project/eos/installation/cms/bin/eos.select rm -r /eos/cms' # Do not add space before next argument when using this cmd
T2_CP='cmsStage'
T2_MKDIR='/afs/cern.ch/project/eos/installation/cms/bin/eos.select mkdir -p /eos/cms' # Do not add space before next argument when using this cmd
T2_CHMOD='/afs/cern.ch/project/eos/installation/cms/bin/eos.select chmod 2777 /eos/cms' # Do not add space before next argument when using this cmd
T2_FSYS='root://eoscms//eos/cms' # Can check what needs to be added with cmsPfn /store/...
T2_TMP_DIR="/tmp/$USER" ##"/store/group/dpg_tracker_pixel/comm_pixel/$USER/tmp"
if [ $verbose -eq 1 ] ; then echo "Setting eos specifics ..." ; fi
}
set_local_specifics(){
T2_LS='ls'
T2_RM='rm -r '
T2_CP='cp'
T2_MKDIR='mkdir -p '
T2_CHMOD='chmod 777 '
T2_FSYS=''
T2_TMP_DIR='/scratch/'
if [ $verbose -eq 1 ] ; then echo "Setting local specifics ..." ; fi
}
set_specifics(){
if [ $verbose -eq 1 ] ; then echo "Specifics for $1" ; fi
echo "Specifics for $1"
if [ `is_on_castor $1` -eq 1 ]; then set_castor_specifics ;
else if [ `is_on_T2 $1` -eq 1 ]; then set_T2_specifics;
else if [ `is_on_eos $1` -eq 1 ]; then set_eos_specifics;
else if [ `is_on_eos_store $1` -eq 1 ]; then set_eos_store_specifics;
else set_local_specifics ;
fi ; fi ; fi ; fi
}
is_on_castor(){
if [ `echo $1 | grep -e "/castor/cern.ch/" |wc -l` -eq 1 ];then echo 1
else echo 0
fi
}
is_on_T2(){
if [ `echo $1 | grep -e "/pnfs/iihe/" |wc -l` -eq 1 ];then echo 1
else echo 0
fi
}
is_on_eos(){
## if [ `echo $1 | grep -e "/store/caf/user/" | wc -l` -eq 1 -o `echo $1 | grep -e "/store/" | wc -l` ];then echo 1
## else echo 0
## fi
if [ `echo $1 | grep -e "/store/caf/user/" | wc -l` -eq 1 ];then echo 1
else echo 0
fi
}
is_on_eos_store(){
if [ `echo $1 | grep -e "/store/group/" | wc -l` -eq 1 ];then echo 1
else echo 0
fi
}
file_loc(){
file=$1
if [ `is_on_castor $file` -eq 1 ];then
echo "rfio://$file"
else
if [ `is_on_T2 $file` -eq 1 ];then
echo "${T2_FSYS}$file"
else if [ `is_on_eos $file` -eq 1 ];then
echo "${T2_FSYS}$file"
else
echo $file
fi ; fi
fi
}
is_file_present(){
if [ `$T2_LS $1 2>&1|grep "No such"|wc -l` -eq 1 ];then echo 0;
else echo 1;
fi
}
working_on_lxplus(){
if [ `uname -a | grep lxplus | wc -l` -gt 0 ];then echo 1
else echo 0
fi
}
is_staged(){
status=`stager_qry -M $1`
if [ `echo $status|grep -e "STAGED"|wc -l` -eq 1 ] || [ `echo $status|grep -e "CANBEMIGR"|wc -l` -eq 1 ];then
echo 1
else
if [ `echo $status|grep -e "STAGEIN"|wc -l` -eq 1 ];then
echo 0
else
stager_get -M $1 &> /dev/null
echo 0
fi
fi
}
stage_list_of_files(){
need_to_wait=0
for file in $@;do
if [ `is_on_castor $file` -eq 1 ];then
if [ `nsls $file 2>&1|grep "No such"|wc -l` -eq 1 ]; then
echo "$file is not present on /castor !!" ; continue ;
fi
if [ `is_staged $file` -eq 0 ];then
echo "File $file is being staged."
need_to_wait=1
fi
fi
done
if [ $need_to_wait -eq 1 ];then
echo "Waiting 5min before continuing !"
sleep 300
stage_list_of_files $@
fi
echo "All files are finally staged ! Moving on ..."
}
stage_dir(){
if [ $# -ne 1 ];then echo "Takes as argument only 1 castor dir." ; exit ; fi
list=""
for file in `nsls $1`;do
list="$list $1/$file"
done
stage_list_of_files $list
}