ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/HiggsAnalysis/EarlyDataStudy/scripts/heds.sh
Revision: 1.2
Committed: Thu May 6 17:55:14 2010 UTC (14 years, 11 months ago) by mangano
Content type: application/x-sh
Branch: MAIN
Changes since 1.1: +15 -14 lines
Log Message:
change destination folder for WWW pages

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