AnalysisTest.sh 3.25 KB
Newer Older
1
2
3
#!/bin/sh

# Choose CMSSW version
4
cmsswvsn=CMSSW_9_0_0
5

6
# Check that scramv1 command was defined by . $CMS_PATH/cmsset_default.sh
7
which scramv1 > /dev/null 2>&1
8
9
10
sset=$?
if [ $sset -ne 0 ]
then 
Andrea Sciaba's avatar
Andrea Sciaba committed
11
12
   echo "ERROR: scramv1 not found"
   echo "summary: SCRAM_NOT_FOUND"
13
14
   exit $SAME_ERROR
fi
Andrea Sciaba's avatar
Andrea Sciaba committed
15

16
17
# Get Working Directory
current=`pwd`
Stefano Belforte's avatar
Stefano Belforte committed
18

Andrea Sciaba's avatar
Andrea Sciaba committed
19
# Set up CMSSW 
Stefano Belforte's avatar
Stefano Belforte committed
20
tmpfile=`mktemp /tmp/tmp.scram.XXXXXXXXXX`
Andrea Sciaba's avatar
Andrea Sciaba committed
21
echo "scramv1 project CMSSW $cmsswvsn ... starting"
Stefano Belforte's avatar
Stefano Belforte committed
22
scramv1 project CMSSW $cmsswvsn > $tmpfile 2>&1
23
24
25
scms=$?
if [ $scms -ne 0 ]
then
Stefano Belforte's avatar
Stefano Belforte committed
26
   cat $tmpfile
Andrea Sciaba's avatar
Andrea Sciaba committed
27
28
29
   echo "ERROR: $cmsswvsn not available"
   echo "summary: CMSSW_NOT_FOUND"
   exit $SAME_ERROR
30
31
32
33
fi
printf "scramv1 project CMSSW $cmsswvsn ... completed\n"
cd $cmsswvsn/src
export SCRAM_ARCH=`scramv1 arch`
Stefano Belforte's avatar
Stefano Belforte committed
34
eval `scramv1 runtime -sh`
Andrea Sciaba's avatar
Andrea Sciaba committed
35

36
37
# Return to working directory 
cd $current
Andrea Sciaba's avatar
Andrea Sciaba committed
38

Stefano Belforte's avatar
Stefano Belforte committed
39
# There are all files available in SAM dataset, which is at all sites
40
/bin/cat > possible-input-files <<EOI
41
42
/store/mc/SAM/GenericTTbar/AODSIM/CMSSW_9_0_0_90X_mcRun1_realistic_v4-v1/10000/28B9D1FB-8B31-E711-AA4E-0025905B85B2.root
/store/mc/SAM/GenericTTbar/AODSIM/CMSSW_9_0_0_90X_mcRun1_realistic_v4-v1/10000/887C13FB-8B31-E711-BCE7-0025905B85BA.root
43
EOI
Andrea Sciaba's avatar
Andrea Sciaba committed
44

45
nFiles=`cat possible-input-files | wc -l`
Andrea Sciaba's avatar
Andrea Sciaba committed
46
47

# Pick a random integer in [1,nFiles]
48
49
50
51
52
53
54
55
56
57
58
59
d=`date +%N|tr -d 0`
let r=d%nFiles+1

nl=0
until [ $nl -eq $r ]
do
 let nl=nl+1
 read line
done < possible-input-files

inputFile=$line
echo inputFile: $inputFile
Andrea Sciaba's avatar
Andrea Sciaba committed
60
pfn=`edmFileUtil -d $inputFile`
Andrea Sciaba's avatar
Andrea Sciaba committed
61
62
63
64
65
66
67
68
69
70
71
if [ -z "$pfn" ] ; then
   echo "WARNING: PFN not returned, using LFN" 
else
   echo PFN: $pfn
   echo $pfn | grep -q '^/'
   res=$?
   if [ $res == 0 ] ; then
      pfn="file:$pfn"
   fi
   inputFile=$pfn
fi
Andrea Sciaba's avatar
Andrea Sciaba committed
72
# Create configuration file for cmsRun following the example in
Stefano Belforte's avatar
Stefano Belforte committed
73
74
75
76
77
78
79
80
81
# http://cmslxr.fnal.gov/lxr/source/FWCore/Integration/test/testRunMergeMERGE_cfg.py#006
/bin/cat > analysis_test.py <<EOI
import FWCore.ParameterSet.Config as cms

process = cms.Process("CopyJob")
process.load("FWCore.MessageService.MessageLogger_cfi")
process.MessageLogger.cerr.FwkReport.reportEvery = 100

process.source = cms.Source("PoolSource",
Andrea Sciaba's avatar
Andrea Sciaba committed
82
     fileNames = cms.untracked.vstring("${inputFile}")
Stefano Belforte's avatar
Stefano Belforte committed
83
84
85
86
)

process.out = cms.OutputModule("PoolOutputModule",
     fileName = cms.untracked.string('myout.root'),
87
#     fastCloning = cms.untracked.bool(False),
Stefano Belforte's avatar
Stefano Belforte committed
88
89
90
     outputCommands = cms.untracked.vstring('drop *')
)
process.e = cms.EndPath(process.out)
91
EOI
Stefano Belforte's avatar
Stefano Belforte committed
92

93
# Run cmsRun
Andrea Sciaba's avatar
Andrea Sciaba committed
94
echo
Andrea Sciaba's avatar
Andrea Sciaba committed
95
echo "START TIME: `date` --> running cmsRun -j fjr.xml -p analysis_test.py"
Andrea Sciaba's avatar
Andrea Sciaba committed
96
97
echo
start=`date +%s`
98
cmsRun -j fjr.xml -p analysis_test.py 2>&1
99
srun=$?
Andrea Sciaba's avatar
Andrea Sciaba committed
100
echo "END TIME: `date`"
101
stop=`date +%s`
Andrea Sciaba's avatar
Andrea Sciaba committed
102
103
104
105
106
107
108
109
110
111
echo "ELAPSED TIME: $[ $stop - $start ] s"
echo

if [ $srun -ne 0 ] ; then
    echo ""
    echo "================= cmsRun configuration file: analysis_test.py ====================="
    echo ""
    cat analysis_test.py
    echo ""
fi
Stefano Belforte's avatar
Stefano Belforte committed
112

Stefano Belforte's avatar
Stefano Belforte committed
113
114
115
116
# Check FJR for errors
grep -q "FrameworkError " fjr.xml
sfjr=$?
if [ $sfjr -eq 0 ]
117
then
Andrea Sciaba's avatar
Andrea Sciaba committed
118
119
   echo "ERROR: FrameworkError found in FJR"
   grep "FrameworkError " fjr.xml
Stefano Belforte's avatar
Stefano Belforte committed
120
   # if possible extract error
Stefano Belforte's avatar
Stefano Belforte committed
121
   which xml_grep > /dev/null 2>1 && xml_grep FrameworkError fjr.xml
122
fi
Stefano Belforte's avatar
Stefano Belforte committed
123
124

# Check cmsRun exit status
125
if [ $srun -ne 0 -o $sfjr -eq 0 ]
126
then
Andrea Sciaba's avatar
Andrea Sciaba committed
127
128
   echo "ERROR: cmsRun failed with exit code $srun"
   echo "summary: CMSRUN_FAILED_CODE_$srun"
129
130
   exit $SAME_ERROR
fi
Stefano Belforte's avatar
Stefano Belforte committed
131

Andrea Sciaba's avatar
Andrea Sciaba committed
132
133
echo "Test succeeded"
echo "summary: OK"
134
exit $SAME_OK