ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/HiggsAnalysis/EarlyDataStudy/scripts/heds.sh
Revision: 1.1
Committed: Thu May 6 15:14:20 2010 UTC (14 years, 11 months ago) by mangano
Content type: application/x-sh
Branch: MAIN
Log Message:
first commit

File Contents

# User Rev Content
1 mangano 1.1 #!/bin/bash
2    
3     ######################################################
4     # heds 0 (create new directories)
5     # heds 1 (query runregistry)
6     # heds 2 (create crab task)
7     # heds 3 (get and publish jobs)
8     # heds 4 (create all the html tables and store logs)
9     # heds 5* (event display stuff)
10     ######################################################
11    
12     choice=$1
13    
14     dailySkim=$HEDS_NAMEPREFIX$HEDS_LABEL-v$HEDS_TASKATTEMPT
15    
16    
17    
18     case $choice in
19     0)
20     echo "=== you selected option 0. Setting up directories and one-time things ==="
21     echo ""
22    
23     if [ -d $HEDS_LOCALSTORE ]
24     then echo "directory " $HEDS_LOCALSTORE "already exists"
25     else
26     echo "making " $HEDS_LOCALSTORE " directory"
27     mkdir -p $HEDS_LOCALSTORE
28     fi
29    
30     if [ -d $HEDS_FINALAREA/logs.SkimV$HEDS_SKIMVERSION ]
31     then echo "directory " $HEDS_FINALAREA/logs.SkimV$HEDS_SKIMVERSION "already exists"
32     else
33     echo "making " $HEDS_FINALAREA/logs.SkimV$HEDS_SKIMVERSION " directory"
34     mkdir -p $HEDS_FINALAREA/logs.SkimV$HEDS_SKIMVERSION
35     fi
36     nsls -d $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION >& tmp
37     check=`cat tmp |grep "No such" |wc -w`
38     rm tmp
39     if [ $check == 0 ]
40     then echo "directory " $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION "already exists"
41     else
42     echo "making " $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION " directory"
43     rfmkdir -p $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION
44     fi
45     ;;
46    
47     1)
48     echo "=== you selected option 1. Querying RunRegistry, select good runs and submit crab jobs ==="
49     echo ""
50    
51     dateForDbsSearch=`echo $HEDS_LABEL|awk -F\. '{print $3"-"$2"-"$1}'`
52     echo "dateForDbsSearch: " $dateForDbsSearch
53     dbs search --query="find run where dataset=$HEDS_INPUTDATASET and run.createdate=$dateForDbsSearch" \
54     > tmpRunList.txt
55     lastRun=`cat tmpRunList.txt |grep [0-9][0-9][0-9][0-9][0-9][0-9] |head -n1`
56     firstRun=`cat tmpRunList.txt|tail -n1`
57     rm tmpRunList.txt
58     #TO BE FIXED: add a protection for when there are no runs
59     echo "first,last runs: " $firstRun $lastRun
60    
61    
62     runselection="runselection="
63     cat $HEDSPATH/scripts/runreg.cfg | sed s/SET_RUNMIN/$firstRun/ | \
64     sed s/SET_RUNMAX/$lastRun/ > runreg.cfg
65     python $HEDSPATH/scripts/runregparse.py > tmp.log
66     rm runreg.cfg
67     echo "here we have the good run list"
68    
69     IFS=$'\n'
70     found=0
71     lastGoodRun=0
72     for line in $(cat tmp.log);
73     do
74     if [ $found == 0 ]
75     then
76     found=`echo $line |grep lumisToProcess|wc |awk '{print $1}'`
77     continue;
78     fi
79     if [ $line == ")" ]
80     then
81     break;
82     fi
83     thisRun=`echo $line | sed s/\'//g | sed s/,//g |awk -F: '{print $1}'`
84     if [ $thisRun != $lastGoodRun ]
85     then
86     runselection=$runselection$thisRun\,
87     fi
88     lastGoodRun=$thisRun
89     done
90     #echo "========= THE FOLLOWING LINE TO YOUR crab.cfg FILE ========="
91     echo $runselection
92     #echo "================================================================"
93     echo $runselection > $HEDS_LABEL.runselection
94     echo $firstRun-$lastRun > $HEDS_LABEL.runinterval
95     rm tmp.log
96    
97     check=`echo $runselection | sed s/runselection=// |wc -w`
98    
99     if [ $check == 0 ]
100     then
101     echo "No good runs have been selected. No CRAB cfg will be created."
102     else
103     echo "Some good runs have been selected. CRAB cfg will be created."
104     cat $HEDSPATH/scripts/crab.template.cfg |sed "s#SET_DATASET#$HEDS_INPUTDATASET#" | \
105     sed "s#SET_REMOTEDIR#$HEDS_USERID/HEDS#" | \
106     sed "s#SET_T2#$HEDS_T2SITE#" | \
107     sed "s/SET_RUNSELECTION/$runselection/" > tmp.cfg
108     pset=$HEDSPATH/python/earlyDataInterestingEvents_cfg.py
109     echo "pset: " $pset
110     cat tmp.cfg |sed s#SET_PSET#$pset# | sed "s#SET_TASK_NAME#$dailySkim#" > tmp2.cfg; rm tmp.cfg
111     mv tmp2.cfg $HEDS_LABEL.crab.cfg
112     fi
113     ;;
114     2)
115     echo "creating and submitting CRAB jobs for " $dailySkim
116     if [ -e $HEDS_LABEL.crab.cfg ]
117     then
118     crab -create -submit -cfg $HEDS_LABEL.crab.cfg
119     if ((! $?)); then rm $HEDS_LABEL.crab.cfg; fi
120     else
121     echo "ERROR: " $HEDS_LABEL.crab.cfg " doesn't exist"
122     fi
123     ;;
124     3)
125     echo "getting output and publishing crab jobs"
126     crab -status -c $dailySkim
127     crab -get -c $dailySkim
128     crab -status -c $dailySkim
129     crab -publish -c $dailySkim
130     ;;
131    
132    
133     4)
134     echo "option 4 "
135     if [ -d $dailySkim ] #the crab job was run on at least 1 run
136     then
137     heds 4a
138     heds 4b
139     heds 4c
140     heds 4d
141     heds 4e
142     heds 4f
143     heds 4g
144     heds 4h
145     heds 4i
146     else
147     echo "copying only the log files about runs and selected-runs"
148     heds 4g
149     fi
150     ;;
151    
152     4a)
153     ###
154     echo "...copying log files"
155     if [ ! -d $HEDS_LOCALSTORE/$dailySkim/logs ]; then
156     mkdir -p $HEDS_LOCALSTORE/$dailySkim/logs
157     fi
158     cp $dailySkim/res/*.std* $HEDS_LOCALSTORE/$dailySkim/logs
159     if (($?)); then
160     echo "ERROR: failed to copy log files in " $HEDS_LOCALSTORE/$dailySkim/logs;
161     else
162     echo "copied all logs file in " $HEDS_LOCALSTORE/$dailySkim/logs
163     fi
164    
165     ###
166     tarName=$HEDS_LABEL.log.tgz
167     cd $HEDS_LOCALSTORE/$dailySkim/logs/
168     if (($?));then
169     echo "ERROR: failed to go to " $HEDS_LOCALSTORE/$dailySkim/logs/
170     else
171     echo "compriming log files and copying " $tarName "them to castor"
172     tar czvf $tarName *.std*
173     rfcp $tarName $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION
174     cd -
175     fi
176     ;;
177    
178     4b)
179     ###
180     echo "....creating skimReport"
181     logName=$HEDS_LABEL.log
182     $HEDSPATH/scripts/skimreport $HEDS_LOCALSTORE/$dailySkim/logs/*.stdout > $logName
183     mv $logName $HEDS_FINALAREA/logs.SkimV$HEDS_SKIMVERSION
184     ;;
185    
186     4c)
187     ###
188     echo "...coping files from the T2's SE"
189     echo "dataset to retreive: " $dailySkim
190     dbs search --url=https://cmsdbsprod.cern.ch:8443/cms_dbs_ph_analysis_02_writer/servlet/DBSServlet \
191     ## --query="find file,site where dataset=*HiggsSimpleSkimV3_18.04.2010-v1*" |grep .root >listFiles
192     --query="find file,site where dataset=*$dailySkim*" |grep .root >listFiles
193    
194     IFS=$'\n'
195     for j in $(cat listFiles)
196     do
197     echo "going to copy file: $j"
198     #fileName=`echo $j |awk '{print$1}'| awk -FHiggsSimpleSkimV3_18.04.2010-v1/ '{print $2}' | awk -F/ '{print $2}'`
199     fileName=`echo $j |awk '{print$1}'| awk -F$dailySkim/ '{print $2}' | awk -F/ '{print $2}'`
200    
201     storage_elem=`echo $j |awk '{print $2}'`
202     remote_path=`echo $j|awk '{print $1}'`
203     #echo "going to execute: " "lcg-cp -b -D srmv2 srm://$storage_elem:$HEDS_STORAGEPORT$HEDS_STORAGEPATH$remote_path file://$HEDS_LOCALSTORE/$dailySkim/$fileName"
204     lcg-cp -b -D srmv2 srm://$storage_elem:$HEDS_STORAGEPORT$HEDS_STORAGEPATH$remote_path file://$HEDS_LOCALSTORE/$dailySkim/$fileName
205     done
206     rm listFiles
207     nFiles=`ls $HEDS_LOCALSTORE/$dailySkim/*.root|wc -l`
208     nJobs=`ls $HEDS_LOCALSTORE/$dailySkim/logs/CMSSW_*.stdout |wc -l`
209    
210     ### TO BE FIXED!! this check isn't valid if some job selects zero events (no file is created)
211     #if [ $nFiles == $nJobs ]
212     #then
213     # echo "GOOD: #files copied from hadoop matches #jobs in the CRAB task"
214     #else
215     # echo "ERROR: #files in hadoop doesn't match #jobs in the CRAB task"
216     # exit
217     #fi
218     ;;
219    
220     4d)
221     ###
222     echo "... merging files"
223     cp $HEDSPATH/scripts/prepareMerging.sh $HEDS_LOCALSTORE/$dailySkim
224     cp $HEDSPATH/scripts/merge.py $HEDS_LOCALSTORE/$dailySkim
225     cd $HEDS_LOCALSTORE/$dailySkim
226    
227     ./prepareMerging.sh
228     numberFilesToMerge=`ls *.root|wc -l`
229     echo "numberFilesToMerge: " $numberFilesToMerge
230     cmsRun merge.py >& merging.log
231     cd -
232     ;;
233    
234     4e)
235     ###
236     echo "... storing merged files"
237     mergedName=$HEDS_LABEL.root
238     mergedName=merged_$mergedName
239     echo "mergedName: " $mergedName
240     cd $HEDS_LOCALSTORE/$dailySkim
241     if ((! $?)); then
242     mv merged.root ../$mergedName
243     echo "going to copy the merged file into: " $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION
244     rfcp ../$mergedName $HEDS_CASTORFOLDER/skimV$HEDS_SKIMVERSION/
245     cd -
246     fi
247     ;;
248    
249     4f)
250     ###
251     echo "... prepare detailed list of skimmed events"
252     cp $HEDSPATH/scripts/listSkimmedEvent.C $HEDS_LOCALSTORE
253     cd $HEDS_LOCALSTORE
254     root.exe -b -q "listSkimmedEvent.C+(\"$HEDS_LABEL\")"
255     listSkimmedEventsPath=$HEDS_FINALAREA/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.listSkimmedEvents
256     if [ ! -d $listSkimmedEventsPath ]
257     then
258     mkdir $listSkimmedEventsPath
259     fi
260     listDetailedLogs=`ls $HEDS_LABEL*`
261     for j in $listDetailedLogs
262     do
263     echo "preparing log " $j
264     # sort entries by date
265     cat $j |sort -k7 > tmp
266     mv tmp $j
267     mv $j $listSkimmedEventsPath
268     done
269     cd -
270     ;;
271    
272     4g)
273     ###
274     echo "... copying logs about run selection"
275     mv $HEDS_LABEL.runselection $HEDS_FINALAREA/logs.SkimV$HEDS_SKIMVERSION
276     mv $HEDS_LABEL.runinterval $HEDS_FINALAREA/logs.SkimV$HEDS_SKIMVERSION
277     ;;
278    
279     4h)
280     ###
281     echo "... preparing detailed event summary"
282     input=$HEDS_LOCALSTORE/merged_$HEDS_LABEL.root
283     echo "input: " $input
284     sed s#INPUT#$input# $HEDSPATH/scripts/dumpEvent.py > dumpEvent.py
285     cmsRun dumpEvent.py >& $HEDS_LABEL.dumperLog
286     $HEDSPATH/scripts/parseDumperOutput.sh 1 >& $HEDS_LABEL.dump
287     $HEDSPATH/scripts/parseDumperOutput.sh 2
288     rm dumpEvent.py
289     rm $HEDS_LABEL.dumperLog
290     rm $HEDS_LABEL.dump
291     ;;
292     4i)
293     ###
294     echo "... preparing html tables"
295     if [ ! -e $HEDS_FINALAREA/logs.SkimV$HEDS_SKIMVERSION/FirstPage.php ];then
296     echo "create first version of FirstTable.sh"
297     $HEDSPATH/scripts/editFirstTable.sh create
298     fi
299     $HEDSPATH/scripts/createTableSkimDetails.sh add
300     $HEDSPATH/scripts/createTableSkimSummary.sh
301     $HEDSPATH/scripts/editFirstTable.sh add below
302     ;;
303     5a)
304     echo ".... preparing event display server"
305     mkdir $HEDS_LABEL.shots
306     port=3005
307     $HEDSPATH/scripts/eventDisplayServer.sh $port &
308     ;;
309     5b)
310     echo "getting snapshots"
311     port=3005
312     file=$HEDS_LOCALSTORE/merged_$HEDS_LABEL.root
313     echo "$file" | nc -w 10 localhost $port
314     ;;
315     5c)
316     echo "moving snapshots"
317     mv $HEDS_LABEL.shots $HEDS_FINALAREA/logs.SkimV$HEDS_SKIMVERSION/
318     cp $HEDSPATH/scripts/indexFileForDetailedSnapShots.php \
319     $HEDS_FINALAREA/logs.SkimV$HEDS_SKIMVERSION/$HEDS_LABEL.shots/index.php
320     ;;
321    
322    
323     ##################### after the crab part is done ###################
324     99) echo "Doing bakcup of $HEDS_FINALAREA"
325     date=`date +%k\.%M\.%S_%e\.%m\.%Y`
326     fileName="HiggsIES.BAK."$date".tgz"
327     echo "file name: " $fileName
328     tar -czvf $fileName $HEDS_FINALAREA
329     mv $fileName $HEDS_FINALAREA/..
330     ;;
331    
332    
333     *)
334     echo "option not defined"
335     ;;
336     esac