-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
configTemplates.py
316 lines (263 loc) · 10.2 KB
/
configTemplates.py
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
from alternateValidationTemplates import *
from offlineValidationTemplates import *
from geometryComparisonTemplates import *
from monteCarloValidationTemplates import *
from trackSplittingValidationTemplates import *
from zMuMuValidationTemplates import *
from TkAlExceptions import AllInOneError
######################################################################
######################################################################
### ###
### General Templates ###
### ###
######################################################################
######################################################################
######################################################################
######################################################################
conditionsTemplate="""
process.conditionsIn.oO[rcdName]Oo. = CalibTracker.Configuration.Common.PoolDBESSource_cfi.poolDBESSource.clone(
connect = cms.string('.oO[connectString]Oo.'),
toGet = cms.VPSet(cms.PSet(record = cms.string('.oO[rcdName]Oo.'),
tag = cms.string('.oO[tagName]Oo.')
)
)
)
process.prefer_conditionsIn.oO[rcdName]Oo. = cms.ESPrefer("PoolDBESSource", "conditionsIn.oO[rcdName]Oo.")
"""
######################################################################
######################################################################
#batch job execution
scriptTemplate="""
#!/bin/bash
#init
#ulimit -v 3072000
#export STAGE_SVCCLASS=cmscafuser
#save path to the LSF batch working directory (/pool/lsf)
export LSFWORKDIR=`pwd -P`
echo LSF working directory is $LSFWORKDIR
source /afs/cern.ch/cms/caf/setup.sh
eos='/afs/cern.ch/project/eos/installation/cms/bin/eos.select'
cd .oO[CMSSW_BASE]Oo./src
export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
eval `scramv1 ru -sh`
#rfmkdir -p .oO[datadir]Oo. &>! /dev/null
#remove possible result file from previous runs
previous_results=$($eos ls /store/caf/user/$USER/.oO[eosdir]Oo.)
for file in ${previous_results}
do
if [ ${file} = /store/caf/user/$USER/.oO[eosdir]Oo./.oO[outputFile]Oo. ]
then
xrdcp -f root://eoscms//eos/cms${file} root://eoscms//eos/cms${file}.bak
fi
done
if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
then
rfmkdir -p .oO[workdir]Oo.
rm -f .oO[workdir]Oo./*
cd .oO[workdir]Oo.
else
mkdir -p $LSFWORKDIR/TkAllInOneTool
cd $LSFWORKDIR/TkAllInOneTool
fi
# rm -f .oO[workdir]Oo./*
# cd .oO[workdir]Oo.
#run
pwd
df -h .
.oO[CommandLine]Oo.
echo "----"
echo "List of files in $(pwd):"
ls -ltr
echo "----"
echo ""
#retrieve
rfmkdir -p .oO[logdir]Oo. >&! /dev/null
gzip -f LOGFILE_*_.oO[name]Oo..log
find . -maxdepth 1 -name "LOGFILE*.oO[alignmentName]Oo.*" -print | xargs -I {} bash -c "rfcp {} .oO[logdir]Oo."
#copy root files to eos
$eos mkdir -p /store/caf/user/$USER/.oO[eosdir]Oo.
if [ .oO[parallelJobs]Oo. -eq 1 ]
then
root_files=$(ls --color=never -d *.oO[alignmentName]Oo.*.root)
else
root_files=$(ls --color=never -d *.oO[alignmentName]Oo._.oO[nIndex]Oo.*.root)
fi
echo ${root_files}
for file in ${root_files}
do
xrdcp -f ${file} root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo.
echo ${file}
done
#cleanup
if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
then
rm -rf .oO[workdir]Oo.
fi
echo "done."
"""
######################################################################
######################################################################
mergeTemplate="""
#!/bin/bash
eos='/afs/cern.ch/project/eos/installation/cms/bin/eos.select'
CWD=`pwd -P`
cd .oO[CMSSW_BASE]Oo./src
export SCRAM_ARCH=.oO[SCRAM_ARCH]Oo.
eval `scramv1 ru -sh`
#create results-directory and copy used configuration there
rfmkdir -p .oO[datadir]Oo.
rfcp .oO[logdir]Oo./usedConfiguration.ini .oO[datadir]Oo.
if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
then
mkdir -p .oO[workdir]Oo.
cd .oO[workdir]Oo.
else
cd $CWD
fi
echo "Working directory: $(pwd -P)"
###############################################################################
# download root files from eos
root_files=$($eos ls /store/caf/user/$USER/.oO[eosdir]Oo. \
| grep ".root$" | grep -v "result.root$")
#for file in ${root_files}
#do
# xrdcp -f root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./${file} .
# echo ${file}
#done
#run
.oO[DownloadData]Oo.
.oO[CompareAlignments]Oo.
.oO[RunExtendedOfflineValidation]Oo.
.oO[RunTrackSplitPlot]Oo.
# clean-up
# ls -l *.root
rm -f *.root
#zip stdout and stderr from the farm jobs
cd .oO[logdir]Oo.
find . -name "*.stderr" -exec gzip -f {} \;
find . -name "*.stdout" -exec gzip -f {} \;
"""
######################################################################
######################################################################
mergeParallelResults="""
.oO[copyMergeScripts]Oo.
.oO[haddLoop]Oo.
# create log file
ls -al .oO[mergeParallelFilePrefixes]Oo. > .oO[datadir]Oo./log_rootfilelist.txt
# Remove parallel job files
.oO[rmUnmerged]Oo.
"""
######################################################################
######################################################################
compareAlignmentsExecution="""
#merge for .oO[validationId]Oo. if it does not exist or is not up-to-date
echo -e "\n\nComparing validations"
$eos mkdir -p /store/caf/user/$USER/.oO[eosdir]Oo./
cp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/scripts/compareFileAges.C .
root -x -q -b -l "compareFileAges.C(\\\"root://eoscms.cern.ch//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./.oO[validationId]Oo._result.root\\\", \\\".oO[compareStringsPlain]Oo.\\\")"
comparisonNeeded=${?}
if [[ ${comparisonNeeded} -eq 1 ]]
then
cp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/scripts/compareAlignments.cc .
root -x -q -b -l 'compareAlignments.cc++(\".oO[compareStrings]Oo.\")'
mv result.root .oO[validationId]Oo._result.root
xrdcp -f .oO[validationId]Oo._result.root root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo.
else
echo ".oO[validationId]Oo._result.root is up-to-date, no need to compare again."
xrdcp -f root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./.oO[validationId]Oo._result.root .
fi
"""
######################################################################
######################################################################
extendedValidationExecution="""
#run extended offline validation scripts
echo -e "\n\nRunning extended offline validation"
if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
then
rfmkdir -p .oO[workdir]Oo./ExtendedOfflineValidation_Images
else
mkdir -p ExtendedOfflineValidation_Images
fi
rfcp .oO[extendedValScriptPath]Oo. .
rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C .
root -x -b -q -l TkAlExtendedOfflineValidation.C
rfmkdir -p .oO[datadir]Oo./ExtendedOfflineValidation_Images
if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]] # check for interactive mode
then
image_files=$(ls --color=never | find .oO[workdir]Oo./ExtendedOfflineValidation_Images/ -name \*ps -o -name \*root -o -name \*png -o -name \*pdf)
echo -e "\n\nProduced plot files:"
#echo ${image_files}
ls .oO[workdir]Oo./ExtendedOfflineValidation_Images
else
image_files=$(ls --color=never | find ExtendedOfflineValidation_Images/ -name \*ps -o -name \*root -o -name \*png -o -name \*pdf)
echo -e "\n\nProduced plot files:"
#echo ${image_files}
ls ExtendedOfflineValidation_Images
fi
for image in ${image_files}
do
cp ${image} .oO[datadir]Oo./ExtendedOfflineValidation_Images
done
"""
######################################################################
######################################################################
extendedValidationTemplate="""
#include ".oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C"
void TkAlExtendedOfflineValidation()
{
// load framework lite just to find the CMSSW libs...
gSystem->Load("libFWCoreFWLite");
FWLiteEnabler::enable();
//compile the makro
//gROOT->ProcessLine(".L .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation/macros/PlotAlignmentValidation.C++");
// gROOT->ProcessLine(".L ./PlotAlignmentValidation.C++");
.oO[extendedInstantiation]Oo.
p.setOutputDir("./ExtendedOfflineValidation_Images");
p.setTreeBaseDir(".oO[OfflineTreeBaseDir]Oo.");
p.plotDMR(".oO[DMRMethod]Oo.",.oO[DMRMinimum]Oo.,".oO[DMROptions]Oo.");
p.plotSurfaceShapes(".oO[SurfaceShapes]Oo.");
p.plotChi2("root://eoscms//eos/cms/store/caf/user/$USER/.oO[eosdir]Oo./.oO[resultPlotFile]Oo._result.root");
}
"""
######################################################################
######################################################################
crabCfgTemplate="""
[CRAB]
jobtype = cmssw
scheduler = caf
use_server = 0
[CMSSW]
datasetpath = .oO[dataset]Oo.
pset = .oO[cfgFile]Oo.
total_number_of_.oO[McOrData]Oo.
number_of_jobs = .oO[numberOfJobs]Oo.
output_file = .oO[outputFile]Oo.
runselection = .oO[runRange]Oo.
lumi_mask = .oO[JSON]Oo.
[USER]
return_data = 0
copy_data = 1
storage_element = T2_CH_CERN
user_remote_dir = .oO[eosdir]Oo.
ui_working_dir = .oO[crabWorkingDir]Oo.
# script_exe = .oO[script]Oo.
# .oO[email]Oo.
[CAF]
queue = .oO[queue]Oo.
"""
######################################################################
######################################################################
### ###
### Alternate Templates ###
### ###
######################################################################
######################################################################
def alternateTemplate( templateName, alternateTemplateName ):
if not templateName in globals().keys():
msg = "unknown template to replace %s"%templateName
raise AllInOneError(msg)
if not alternateTemplateName in globals().keys():
msg = "unknown template to replace %s"%alternateTemplateName
raise AllInOneError(msg)
globals()[ templateName ] = globals()[ alternateTemplateName ]
# = eval("configTemplates.%s"%"alternateTemplate")